@runeditrun/rer 0.2.93 → 0.2.95
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 +3 -0
- package/cli/README.md +3 -0
- package/cli/agent-door.mjs +20 -10
- package/cli/agent-history-database.mjs +82 -0
- package/cli/agent-history-isolation.mjs +68 -0
- package/cli/agent-history.mjs +58 -0
- package/cli/agent-journey-fixtures.mjs +3 -3
- package/cli/agent-network.mjs +12 -6
- package/cli/authoring.mjs +1 -1
- package/cli/business/carry-files.mjs +115 -0
- package/cli/business/carry.mjs +20 -81
- package/cli/business/choices.mjs +12 -7
- package/cli/business/command.mjs +19 -0
- package/cli/business/setup-command.mjs +14 -1
- package/cli/contract.mjs +1 -1
- package/cli/door-clauses.mjs +28 -2
- package/cli/export.mjs +1 -1
- package/cli/hosted-hosts.mjs +21 -0
- package/cli/hosted-output.mjs +93 -8
- package/cli/hosted-queue-producers.mjs +43 -0
- package/cli/jsonc.mjs +1 -115
- package/cli/lifecycle.mjs +5 -0
- package/cli/local.mjs +1 -1
- package/cli/parse.mjs +1 -1
- package/cli/port.mjs +1 -2
- package/cli/portability-evidence.d.mts +5 -0
- package/cli/portability-evidence.mjs +85 -0
- package/cli/portability-migrations.mjs +3 -5
- package/edition-authoring/archive-source.mjs +86 -1
- package/edition-authoring/base-copies.mjs +15 -45
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/edition-migrations.mjs +2 -2
- package/edition-authoring/module-closure.mjs +119 -50
- package/edition-authoring/module-edges.mjs +14 -1
- package/edition-authoring/module-packages.mjs +12 -5
- package/edition-authoring/module-syntax.mjs +13 -50
- package/edition-authoring/runtime-dependencies.mjs +4 -4
- package/foundation/runtime/contract-anchor.mjs +87 -0
- package/foundation/runtime/contract-docs.mjs +20 -4
- package/global/CHANGELOG.md +74 -0
- package/global/README.md +3 -0
- package/install.sh +4 -1
- package/modules/agent-door/CLAUSES.md +12 -0
- package/modules/agent-door/conformance/audit.mjs +22 -4
- package/modules/agent-door/conformance/discovery.mjs +32 -1
- package/modules/agent-door/conformance/erasure.mjs +103 -0
- package/modules/agent-door/conformance/injection.mjs +5 -3
- package/modules/agent-door/conformance/journey.mjs +20 -2
- package/modules/agent-door/conformance/policy-phases.mjs +6 -0
- package/modules/agent-door/conformance/protocol.mjs +13 -3
- package/modules/deploy-kit/README.md +1 -1
- package/modules/deploy-kit/jsonc.mjs +115 -0
- package/modules/deploy-kit/migration-directory.mjs +16 -0
- package/modules/deploy-kit/prepare.mjs +5 -2
- package/modules/deploy-kit/templates.mjs +9 -4
- package/modules/erasure/cascade.mjs +4 -4
- package/modules/erasure/index.d.mts +1 -1
- package/modules/erasure/index.mjs +1 -1
- package/modules/import-kit/src/d1/README.md +16 -1
- package/modules/import-kit/src/d1/preserved-reverse.ts +5 -2
- package/modules/import-kit/src/d1/read-fence.ts +14 -2
- package/modules/import-kit/src/d1/reverse.ts +4 -1
- package/modules/import-kit/src/d1/sets.ts +8 -0
- package/modules/import-kit/src/d1/snapshot-text.ts +68 -0
- package/modules/import-kit/src/d1/undo-report.ts +4 -1
- package/modules/import-kit/src/door/ADOPTING.md +9 -4
- package/modules/portability/README.md +68 -10
- package/modules/portability/bookkeeping.mjs +8 -4
- package/modules/portability/catalogue.mjs +11 -1
- package/modules/portability/checkout-history.mjs +20 -0
- package/modules/portability/import.mjs +1 -1
- package/modules/portability/index.d.mts +1 -1
- package/modules/portability/library-history.mjs +2 -7
- package/modules/portability/restore-safety.mjs +6 -3
- package/modules/portability/storage.mjs +7 -1
- package/modules/portability/worker-history.d.mts +9 -0
- package/modules/portability/worker-history.mjs +29 -0
- package/onboarding/adapter.mjs +25 -13
- package/package.json +9 -1
package/cli/business/carry.mjs
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
|
-
import { chmod, mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
|
-
import { randomUUID } from 'node:crypto';
|
|
4
1
|
import { Api } from './api.mjs';
|
|
5
2
|
import { createCredentialStore } from './keychain.mjs';
|
|
6
|
-
import { credentialHandle, loadState
|
|
3
|
+
import { credentialHandle, loadState } from './state.mjs';
|
|
7
4
|
import { localCause } from './errors.mjs';
|
|
8
|
-
import {
|
|
9
|
-
|
|
5
|
+
import { carryCheckouts, firstParty, writeCarry } from './carry-files.mjs';
|
|
6
|
+
export { removeCarries } from './carry-files.mjs';
|
|
10
7
|
|
|
11
|
-
const carryPath = checkout => join(checkout, '.rer/local/business.json');
|
|
12
8
|
const launched = Symbol.for('rer.business.carry.launched');
|
|
13
9
|
|
|
14
|
-
async function readJson(path) {
|
|
15
|
-
try { return JSON.parse(await readFile(path, 'utf8')); }
|
|
16
|
-
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
17
|
-
}
|
|
18
|
-
async function atomicJson(path, value) {
|
|
19
|
-
const directory = dirname(path), temporary = join(directory, `${randomUUID()}.tmp`);
|
|
20
|
-
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
21
|
-
await chmod(directory, 0o700);
|
|
22
|
-
try {
|
|
23
|
-
await writeFile(temporary, JSON.stringify(value) + '\n', { flag: 'wx', mode: 0o600 });
|
|
24
|
-
await chmod(temporary, 0o600);
|
|
25
|
-
await rename(temporary, path);
|
|
26
|
-
} finally { await unlink(temporary).catch(error => { if (error.code !== 'ENOENT') throw error; }); }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
10
|
export function buildCarry(state, self) {
|
|
30
11
|
const business = self?.business;
|
|
31
12
|
if (!business) return null; // Older platforms have no local identity to carry.
|
|
@@ -44,65 +25,31 @@ export function buildCarry(state, self) {
|
|
|
44
25
|
logo_url: logo };
|
|
45
26
|
}
|
|
46
27
|
|
|
47
|
-
|
|
48
|
-
const root = resolve(checkout), path = carryPath(root), record = join(stateDirectory(), 'carried.json');
|
|
49
|
-
const checkouts = await readJson(record) ?? [];
|
|
50
|
-
// Record custody before the write, so disconnect can clean up even after a crash.
|
|
51
|
-
if (!checkouts.includes(root)) await atomicJson(record, [...checkouts, root]);
|
|
52
|
-
let prior;
|
|
53
|
-
try { prior = await readJson(path); } catch (error) { if (!(error instanceof SyntaxError)) throw error; }
|
|
54
|
-
const values = { ...prior };
|
|
55
|
-
delete values.refreshed_at;
|
|
56
|
-
if (Object.keys(values).length === Object.keys(carry).length && Object.keys(carry).every(key => values[key] === carry[key])) {
|
|
57
|
-
for (const [file, mode] of [[dirname(path), 0o700], [path, 0o600]]) {
|
|
58
|
-
if (((await stat(file)).mode & 0o777) !== mode) await chmod(file, mode);
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
await atomicJson(path, { ...carry, refreshed_at: new Date().toISOString() });
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function firstParty(checkout) {
|
|
67
|
-
return typeof checkout === 'string' && isAbsolute(checkout)
|
|
68
|
-
&& (await readJson(join(checkout, 'OPERATIONS.json')))?.seedContract?.profile === 'first-party';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// The same read-only registry view as the installed launcher's liveServers.
|
|
72
|
-
// Keep this reader in the exported CLI too: vendored Business commands have no global launcher files.
|
|
73
|
-
async function liveCheckouts() {
|
|
74
|
-
const registry = await readJson(join(serversDirectory(), 'state.json'));
|
|
75
|
-
const checkouts = [];
|
|
76
|
-
for (const record of registry?.running ?? []) {
|
|
77
|
-
let live = true;
|
|
78
|
-
try { live = await alive(record.owner); } catch { /* Unverifiable identities stay live, as in the registry. */ }
|
|
79
|
-
if (live) {
|
|
80
|
-
try { if (await firstParty(record.checkout)) checkouts.push(record.checkout); }
|
|
81
|
-
catch { /* A checkout with an unreadable descriptor is not a carry destination. */ }
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return [...new Set(checkouts)];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function warning(origin, error) {
|
|
28
|
+
function warning(origin, error, checkout) {
|
|
88
29
|
// Do not echo server text, response fields or transport messages: they can contain credentials.
|
|
89
30
|
const reason = error.status ? `the server refused the request (HTTP ${error.status})`
|
|
90
31
|
: error.name === 'TimeoutError' || error.name === 'AbortError' ? 'the server did not answer within 5 seconds'
|
|
91
32
|
: error.message?.startsWith('Could not reach the Business server at ') ? 'the server is unreachable'
|
|
92
33
|
: error.message === 'credential unavailable' ? 'the Business credential is unavailable in OS credential storage'
|
|
93
|
-
: localCause(error) ?? (['the response names another Business', 'the Business profile is invalid'].includes(error.message) ? error.message : 'the Business profile could not be refreshed');
|
|
94
|
-
process.stderr.write(`Business carry at ${origin}: ${reason}; keeping the local carry.\n`);
|
|
34
|
+
: localCause(error) ?? (['the response names another Business', 'the Business profile is invalid', 'the checkout is not first-party', 'the carry path is linked or not a regular file', 'the existing file is not a carry for this paired Business', 'the carry registry is invalid'].includes(error.message) ? error.message : 'the Business profile could not be refreshed');
|
|
35
|
+
process.stderr.write(`Business carry at ${origin}${checkout ? ` for ${JSON.stringify(checkout)}` : ''}: ${reason}; keeping the local carry.\n`);
|
|
95
36
|
}
|
|
96
37
|
|
|
97
|
-
export async function
|
|
38
|
+
export async function carryCheckIn(state, self) {
|
|
98
39
|
try {
|
|
40
|
+
if (!state?.origin || !state.businessId || !state.executorId || state.revoked) return;
|
|
99
41
|
const carry = buildCarry(state, self);
|
|
100
42
|
if (!carry) return;
|
|
101
|
-
const checkouts = [];
|
|
102
|
-
|
|
103
|
-
|
|
43
|
+
const checkouts = [], unchanged = [];
|
|
44
|
+
let failed = 0;
|
|
45
|
+
const refused = (error, checkout) => { failed++; warning(state.origin, error, checkout); };
|
|
46
|
+
for (const { checkout, live } of await carryCheckouts(refused)) {
|
|
47
|
+
try {
|
|
48
|
+
const changed = await writeCarry(checkout, carry, { existingOnly: !live });
|
|
49
|
+
(changed ? checkouts : unchanged).push(checkout);
|
|
50
|
+
} catch (error) { refused(error, checkout); }
|
|
104
51
|
}
|
|
105
|
-
return { name: carry.name, checkouts };
|
|
52
|
+
return { name: carry.name, checkouts, unchanged, failed };
|
|
106
53
|
} catch (error) { warning(state.origin, error); }
|
|
107
54
|
}
|
|
108
55
|
|
|
@@ -112,7 +59,7 @@ export async function refreshCarry(api, state, { checkout, signal } = {}) {
|
|
|
112
59
|
if (checkout) {
|
|
113
60
|
const carry = buildCarry(state, self);
|
|
114
61
|
if (carry) await writeCarry(checkout, carry);
|
|
115
|
-
} else await
|
|
62
|
+
} else await carryCheckIn(state, self);
|
|
116
63
|
} catch (error) { if (!signal?.aborted) warning(state.origin, error); }
|
|
117
64
|
}
|
|
118
65
|
|
|
@@ -123,14 +70,14 @@ export async function refreshCheckout(checkout) {
|
|
|
123
70
|
try {
|
|
124
71
|
if (!await firstParty(checkout)) return;
|
|
125
72
|
state = await loadState();
|
|
126
|
-
if (!state?.origin || !state.businessId || !state.executorId) return;
|
|
73
|
+
if (!state?.origin || !state.businessId || !state.executorId || state.revoked) return;
|
|
127
74
|
const credential = await createCredentialStore().get(credentialHandle(state.origin));
|
|
128
75
|
if (!credential) throw Error('credential unavailable');
|
|
129
76
|
await refreshCarry(new Api(state.origin, credential), state, { checkout });
|
|
130
77
|
} catch (error) { warning(state?.origin ?? 'the paired origin', error); }
|
|
131
78
|
}
|
|
132
79
|
|
|
133
|
-
//
|
|
80
|
+
// Reuse the supervisor's existing refresh cycle for live and previously carried apps.
|
|
134
81
|
export async function startCarryRefresh(api, state, signal) {
|
|
135
82
|
const controller = new AbortController(), combined = AbortSignal.any([signal, controller.signal]);
|
|
136
83
|
let pending = Promise.resolve(), busy = false;
|
|
@@ -141,11 +88,3 @@ export async function startCarryRefresh(api, state, signal) {
|
|
|
141
88
|
}, 60_000);
|
|
142
89
|
return async () => { clearInterval(timer); controller.abort(); await pending; };
|
|
143
90
|
}
|
|
144
|
-
|
|
145
|
-
export async function removeCarry(checkout) {
|
|
146
|
-
await unlink(carryPath(checkout)).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
147
|
-
}
|
|
148
|
-
export async function removeCarries() {
|
|
149
|
-
const recorded = await readJson(join(stateDirectory(), 'carried.json')) ?? [];
|
|
150
|
-
for (const checkout of new Set([...recorded, ...await liveCheckouts()])) await removeCarry(checkout);
|
|
151
|
-
}
|
package/cli/business/choices.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from 'node:path';
|
|
2
2
|
import { installService, removeService } from './service.mjs';
|
|
3
3
|
import { installPermissions, removePermissions } from './permissions.mjs';
|
|
4
4
|
import { saveState } from './state.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { carryCheckIn } from './carry.mjs';
|
|
6
6
|
import { businessCommand } from './invocation.mjs';
|
|
7
7
|
import { describe } from './errors.mjs';
|
|
8
8
|
|
|
@@ -55,7 +55,7 @@ export async function applyChoices(api, state, { reconnecting = false } = {}) {
|
|
|
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
57
|
catch (error) { if (![403, 404].includes(error.status)) throw error; }
|
|
58
|
-
const carried = await
|
|
58
|
+
const carried = await carryCheckIn(state, self);
|
|
59
59
|
const decided = Object.fromEntries(names.map(name => [name, typeof self?.optIns?.[name] === 'boolean' ? self.optIns[name] : null]));
|
|
60
60
|
// The agent this computer reported when it paired, as the owner's browser words its choices:
|
|
61
61
|
// the Claude Code rules apply only to Claude Code. An unknown agent (no route yet) decides nothing.
|
|
@@ -89,9 +89,14 @@ export async function applyChoices(api, state, { reconnecting = false } = {}) {
|
|
|
89
89
|
if (undecided.length) {
|
|
90
90
|
once(`undecided:${undecided.join()}`, `The owner has not chosen yet:\n${undecided.map(name => ` - ${choices[name]}\n`).join('')}They choose on this computer's row in ${state.origin}/business/${encodeURIComponent(state.businessId)}/settings; the run and next commands apply the choices at their next check-in, ${reconnecting ? 'without pairing again' : 'so connect does not need to run again'}.\n`);
|
|
91
91
|
}
|
|
92
|
-
once('choices-next-step', `After choosing this computer's
|
|
93
|
-
if (carried)
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
once('choices-next-step', `After choosing this computer's permissions in Business, run ${businessCommand('next')} to apply them and see the next task.\n`);
|
|
93
|
+
if (carried) {
|
|
94
|
+
const count = carried.checkouts.length;
|
|
95
|
+
process.stdout.write(count
|
|
96
|
+
? `Refreshed ${count} local app carry ${count === 1 ? 'file' : 'files'} for ${JSON.stringify(carried.name)}:\n${carried.checkouts.map(checkout => ` - ${join(checkout, '.rer/local/business.json')}\n`).join('')}Supporting apps apply these values when they read their carry file.\n`
|
|
97
|
+
: `No local app carry files changed for ${JSON.stringify(carried.name)}.\n`);
|
|
98
|
+
for (const checkout of carried.unchanged) process.stdout.write(`Already current: ${join(checkout, '.rer/local/business.json')}\n`);
|
|
99
|
+
if (carried.failed) process.stdout.write(`${carried.failed} local app carry ${carried.failed === 1 ? 'file could' : 'files could'} not be refreshed; see the carry warnings.\n`);
|
|
100
|
+
}
|
|
96
101
|
return { applied: lines.length, serviceInstalled };
|
|
97
102
|
}
|
package/cli/business/command.mjs
CHANGED
|
@@ -45,8 +45,27 @@ State lives in $RER_BUSINESS_STATE_DIR when set, otherwise in ~/.rer/business.
|
|
|
45
45
|
In an agent sandbox that writes only inside its working folder, use RER_BUSINESS_STATE_DIR="$PWD/.rer-business".
|
|
46
46
|
`;
|
|
47
47
|
|
|
48
|
+
const verbHelp = {
|
|
49
|
+
connect: `Usage: rer business connect [--code CODE] [--origin URL]
|
|
50
|
+
Pair this computer with Business, waiting for the owner to approve the comparison
|
|
51
|
+
number in their browser (up to the code's 10 minutes). Run again to resume.
|
|
52
|
+
|
|
53
|
+
--code CODE Pairing code created in the Business browser.
|
|
54
|
+
--origin URL Business platform address (default: https://app.runeditrun.com).
|
|
55
|
+
Without a code, prints the path to create one or resumes this computer's pairing.
|
|
56
|
+
Carries the Business name into local app files for supporting apps to read.
|
|
57
|
+
Choose this computer's permissions and background service in the browser.
|
|
58
|
+
`,
|
|
59
|
+
token: `Usage: rer business token
|
|
60
|
+
Print an MCP Authorization header object for this computer's paired Business.
|
|
61
|
+
Send this headersHelper output directly to the MCP client; it contains a credential.
|
|
62
|
+
Requires an existing pairing: rer business connect.
|
|
63
|
+
`,
|
|
64
|
+
};
|
|
65
|
+
|
|
48
66
|
export async function businessCommand(argv) {
|
|
49
67
|
if (argv[0] === 'setup') return setupCommand(argv.slice(1));
|
|
68
|
+
if (Object.hasOwn(verbHelp, argv[0]) && argv.some(arg => ['--help', '-h'].includes(arg))) { process.stdout.write(verbHelp[argv[0]]); return 0; }
|
|
50
69
|
if (!argv.length || argv[0] !== 'scan' && argv.some(arg => ['--help', '-h'].includes(arg))) { process.stdout.write(usage); return 0; }
|
|
51
70
|
if (argv[0] === 'scan') return scanCommand(argv);
|
|
52
71
|
try {
|
|
@@ -13,7 +13,20 @@ export async function setupCommand(args) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async function setup(args){
|
|
16
|
-
const usage
|
|
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.`;
|
|
17
30
|
if(args.some(arg => ['--help', '-h'].includes(arg))){process.stdout.write(usage+'\n');return;}
|
|
18
31
|
const options={};
|
|
19
32
|
for(let i=0;i<args.length;i++){
|
package/cli/contract.mjs
CHANGED
|
@@ -29,7 +29,7 @@ export const signinVerb = Object.freeze({ bootstrap: 'before', flags: [...common
|
|
|
29
29
|
// Their project-package bootstrap uses the same contract as every checkout verb.
|
|
30
30
|
export const authoringVerbs = Object.freeze({
|
|
31
31
|
'adopt-edition': {bootstrap: 'before', flags: [...commonFlags], effects: 'Add edition.json and sources.lock.json for the existing tracked local source, preserving declared project identity and existing copy/composition records. Create an empty base-copies.json only when none exists. Review and stage the new authoring inputs; no source regeneration, install setup or commit.'},
|
|
32
|
-
'refresh-base': {bootstrap: 'before', flags: [...commonFlags, '--ref', '--base', '--base-archive', '--record', '--offline', '--edition-migration'], effects: 'Consent to each declared edition edit with repeatable --edition-migration ID; refresh leaves the edit owed. Refresh recorded Base copies to --ref FULL_COMMIT, preserving acknowledged adaptations and applied migrations; announce removed singleton retirement. Deliver invoked workflow helpers atomically; adopt tracked known historical Verify templates and preserve divergent workflows with adoption notices. Acquire committed source from the declared Base repository (default https://github.com/runeditrun/base.git), or use --base CHECKOUT or --base-archive DIRECTORY with --ref FULL_COMMIT for an exported source tree. --offline requires --base and never acquires remote source. Refuse incomplete Git checkouts without changing their records. Review the diff and run edition tests before committing.'},
|
|
32
|
+
'refresh-base': {bootstrap: 'before', flags: [...commonFlags, '--ref', '--base', '--base-archive', '--from-api', '--record', '--offline', '--edition-migration'], effects: 'Consent to each declared edition edit with repeatable --edition-migration ID; refresh leaves the edit owed. Refresh recorded Base copies to --ref FULL_COMMIT, preserving acknowledged adaptations and applied migrations; announce removed singleton retirement. Deliver invoked workflow helpers atomically; adopt tracked known historical Verify templates and preserve divergent workflows with adoption notices. Acquire committed source from the declared Base repository (default https://github.com/runeditrun/base.git), or read immutable trees, blobs and ancestry through authenticated gh with --from-api, or use --base CHECKOUT or --base-archive DIRECTORY with --ref FULL_COMMIT for an exported source tree. --offline requires --base or --base-archive and never acquires remote source. Refuse incomplete Git checkouts without changing their records. Review the diff and run edition tests before committing.'},
|
|
33
33
|
});
|
|
34
34
|
export const aliases = Object.fromEntries([...Object.keys(verbs).filter(v => v !== 'install'), 'release', 'deps', 'rer'].map(name => [name, name === 'deps' ? 'install' : name === 'rer' ? null : name]));
|
|
35
35
|
export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--verify-workflow', '--scan-timeout-seconds', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
|
package/cli/door-clauses.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { resolve, relative, isAbsolute } from 'node:path';
|
|
5
|
-
import { parseContract } from '../foundation/runtime/seed-contract.mjs';
|
|
5
|
+
import { parseContract, plainText } from '../foundation/runtime/seed-contract.mjs';
|
|
6
6
|
import { RerError } from './errors.mjs';
|
|
7
7
|
|
|
8
8
|
export const clausesHelp = `Usage: rer door clauses (--write | --check) [--cwd DIR]
|
|
@@ -10,6 +10,7 @@ export const clausesHelp = `Usage: rer door clauses (--write | --check) [--cwd D
|
|
|
10
10
|
Synchronize BASE-AGENT-001 through BASE-AGENT-013 in CONTRACT.md.
|
|
11
11
|
--write adds or updates Base's requirements, preserving existing status,
|
|
12
12
|
evidence and gaps, then runs the seed's contract-docs write and check.
|
|
13
|
+
It requires a Shared duties (Base) table and skips duties listed there.
|
|
13
14
|
--check is read-only and names missing or stale clauses (exit 1).
|
|
14
15
|
Seed-owned clauses and the judged revision stay unchanged. Newly added clauses
|
|
15
16
|
start missing. Regenerate the seed's source lock last, before committing.
|
|
@@ -64,6 +65,29 @@ function headings(lines) {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
function sharedDuties(original) {
|
|
69
|
+
const lines = original.split(/\r?\n/), outline = headings(lines);
|
|
70
|
+
const cells = line => line?.trim().replace(/^\|/, '').replace(/(?<!\\)\|$/, '').split(/(?<!\\)\|/).map(cell => cell.trim());
|
|
71
|
+
const section = outline.find(item => item.level === 2 && item.title.trim() === 'Shared duties (Base)');
|
|
72
|
+
const end = section && (outline.find(item => item.index > section.index && item.level <= 2)?.index ?? lines.length);
|
|
73
|
+
let fence;
|
|
74
|
+
for (let i = (section?.index ?? lines.length) + 1; i < end; i++) {
|
|
75
|
+
const mark = /^\s*(`{3,}|~{3,})/.exec(lines[i])?.[1];
|
|
76
|
+
if (mark) { if (!fence) fence = mark[0]; else if (fence === mark[0]) fence = undefined; continue; }
|
|
77
|
+
if (fence) continue;
|
|
78
|
+
if (!lines[i].trimStart().startsWith('|')) continue;
|
|
79
|
+
const header = cells(lines[i]), divider = cells(lines[i + 1]);
|
|
80
|
+
if (plainText(header[0]) !== 'Base duty' || divider?.length !== header.length || !divider.every(cell => /^:?-{3,}:?$/.test(cell))) continue;
|
|
81
|
+
const duties = new Set();
|
|
82
|
+
for (let row = i + 2; row < end && lines[row].trimStart().startsWith('|'); row++) {
|
|
83
|
+
const id = plainText(cells(lines[row])[0]);
|
|
84
|
+
if (/^BASE-AGENT-\d{3}$/.test(id)) duties.add(id);
|
|
85
|
+
}
|
|
86
|
+
return duties;
|
|
87
|
+
}
|
|
88
|
+
fail('CONTRACT.md needs a Shared duties (Base) table with a Base duty column before --write. Add the table, then retry; no files were written.');
|
|
89
|
+
}
|
|
90
|
+
|
|
67
91
|
// contract-docs owns summary generation. Suppress only its three derived rows
|
|
68
92
|
// for structural validation while a contract is awaiting regeneration.
|
|
69
93
|
function withoutSummary(text) {
|
|
@@ -139,7 +163,9 @@ export async function doorClausesCommand(args, env = process.env) {
|
|
|
139
163
|
root = resolve(root);
|
|
140
164
|
const file = resolve(root, 'CONTRACT.md');
|
|
141
165
|
if (!existsSync(file)) fail('No CONTRACT.md found. Run rer door clauses from the seed root or pass --cwd DIR.');
|
|
142
|
-
const original = read(file)
|
|
166
|
+
const original = read(file);
|
|
167
|
+
const inherited = mode === '--write' ? sharedDuties(original) : new Set();
|
|
168
|
+
const { text, changed } = synchronize(original, definitions(canonical(root)).filter(clause => !inherited.has(clause.id)));
|
|
143
169
|
if (changed.length) console.log(`Agent clauses: ${changed.join(', ')}.`);
|
|
144
170
|
if (mode === '--check' && changed.length) return 1;
|
|
145
171
|
const commands = generator(root);
|
package/cli/export.mjs
CHANGED
|
@@ -12,7 +12,7 @@ sourceRoots.push('modules/agent-door/capabilities.mjs', 'modules/agent-door/capa
|
|
|
12
12
|
sourceRoots.push('edition-authoring/archive-source.mjs');
|
|
13
13
|
sourceRoots.push('edition-authoring/copy-namespaces.mjs');
|
|
14
14
|
sourceRoots.push('edition-authoring/module-packages.mjs');
|
|
15
|
-
sourceRoots.push('foundation/runtime/contract-prose.mjs', 'foundation/runtime/contract-prose-patterns.mjs');
|
|
15
|
+
sourceRoots.push('foundation/runtime/contract-prose.mjs', 'foundation/runtime/contract-prose-patterns.mjs', 'foundation/runtime/contract-anchor.mjs');
|
|
16
16
|
export async function inventory(base, roots = sourceRoots) {
|
|
17
17
|
const files = [];
|
|
18
18
|
async function walk(path) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RerError } from './errors.mjs';
|
|
2
|
+
|
|
3
|
+
// Admission is explicit: never infer additional hosts from arbitrary app vars.
|
|
4
|
+
// Each named binding must contain a bare canonical hostname in the selected
|
|
5
|
+
// deployment declaration, so verification and the hosted Worker agree.
|
|
6
|
+
export function hostedOrigins(declaration, bindings, primary) {
|
|
7
|
+
if (bindings === undefined) return Object.freeze([primary]);
|
|
8
|
+
const invalid = () => new RerError('agent_hosts_invalid', 'verification.publicHosts must list unique deployment variable names whose vars values are canonical hostnames.', 1);
|
|
9
|
+
if (!Array.isArray(bindings) || new Set(bindings).size !== bindings.length) throw invalid();
|
|
10
|
+
const origins = new Set([primary]);
|
|
11
|
+
for (const name of bindings) {
|
|
12
|
+
const host = declaration.vars?.[name];
|
|
13
|
+
if (typeof name !== 'string' || !/^[A-Z][A-Z0-9_]*$/.test(name) || !Object.hasOwn(declaration.vars ?? {}, name)
|
|
14
|
+
|| typeof host !== 'string' || host.length > 253 || !/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(host)) throw invalid();
|
|
15
|
+
const origin = `https://${host}`;
|
|
16
|
+
try { if (new URL(origin).hostname !== host) throw invalid(); }
|
|
17
|
+
catch { throw invalid(); }
|
|
18
|
+
origins.add(origin);
|
|
19
|
+
}
|
|
20
|
+
return Object.freeze([...origins]);
|
|
21
|
+
}
|
package/cli/hosted-output.mjs
CHANGED
|
@@ -9,8 +9,14 @@ import { migrate } from '../modules/container/migrations.mjs';
|
|
|
9
9
|
import { readMigrationRewrites, withRewrites } from '../modules/deploy-kit/migrations.mjs';
|
|
10
10
|
import { RerError } from './errors.mjs';
|
|
11
11
|
import { hostedMailCredentials } from './hosted-mail.mjs';
|
|
12
|
+
import { deliveryDeclarationSources } from './delivery-declarations.mjs';
|
|
13
|
+
import { sourcePath } from '../modules/delivery-producer/migrations.mjs';
|
|
12
14
|
import { shared } from './shared.mjs';
|
|
15
|
+
import { registerHistoryInstallation, preparationDatabase } from './agent-history-database.mjs';
|
|
13
16
|
import { verificationRpc } from './agent-rpc.mjs';
|
|
17
|
+
import { hostedOrigins } from './hosted-hosts.mjs';
|
|
18
|
+
import { preparationProducers } from './hosted-queue-producers.mjs';
|
|
19
|
+
import { FixtureDatabaseError } from '../modules/agent-door/conformance/fixtures.mjs';
|
|
14
20
|
|
|
15
21
|
// Serve the production build the way rer deploy hosts it (assets behind the
|
|
16
22
|
// Worker, deploy identity bound, a public https origin) on loopback, with no
|
|
@@ -43,9 +49,42 @@ async function miniflareFor(root) {
|
|
|
43
49
|
const standIn = (item, field) => typeof item.verifyStandIn === 'string' && item.verifyStandIn ? item.verifyStandIn : field?.kind === 'email' ? 'owner@example.com' : typeof field?.default === 'string' && field.default ? field.default : randomBytes(24).toString('hex');
|
|
44
50
|
const links = html => [...html.matchAll(/(?:src|href)=["'](\/[^"'#?\s]+)/g)].map(match => match[1].slice(1)).filter(path => !path.startsWith('/') && /\.[A-Za-z0-9]+$/.test(path));
|
|
45
51
|
|
|
52
|
+
// Verification-only runtime bindings. Never write defaults back to the source
|
|
53
|
+
// declaration or build: deploy and packaging must still require real inputs.
|
|
54
|
+
async function hostedPublicVariables(root, config, declaration, manifest) {
|
|
55
|
+
const present = value => typeof value === 'string' ? Boolean(value.trim()) : value !== undefined && value !== null;
|
|
56
|
+
const vars = { ...declaration.vars }, names = new Set([...Object.keys(config.vars ?? {}), ...Object.keys(vars)]);
|
|
57
|
+
const defaults = source => { for (const [name, value] of Object.entries(source ?? {})) if (!present(vars[name])) vars[name] = value; };
|
|
58
|
+
defaults(config.vars);
|
|
59
|
+
for (const [candidate, select] of deliveryDeclarationSources) {
|
|
60
|
+
const path = await sourcePath(root, candidate, { optional: true });
|
|
61
|
+
if (!path) continue;
|
|
62
|
+
const spec = select(JSON.parse(await readFile(path, 'utf8')));
|
|
63
|
+
if (!spec) continue;
|
|
64
|
+
for (const name of spec.publicVariableNames ?? Object.keys(spec.publicVariables ?? {})) names.add(name);
|
|
65
|
+
defaults(spec.publicVariables);
|
|
66
|
+
}
|
|
67
|
+
const { setupConditionMatches } = await shared('schema/setup-validation.mjs');
|
|
68
|
+
const fields = (manifest.fields ?? []).filter(field => field.kind !== 'secret' && names.has(field.name));
|
|
69
|
+
// A required field may depend on another public input declared after it.
|
|
70
|
+
let changed = true;
|
|
71
|
+
while (changed) {
|
|
72
|
+
changed = false;
|
|
73
|
+
for (const field of fields) {
|
|
74
|
+
if (present(vars[field.name]) || field.when && !setupConditionMatches(field.when, vars)) continue;
|
|
75
|
+
const presentation = field.presentations?.find(item => setupConditionMatches(item.when, vars));
|
|
76
|
+
if (field.presentations && !presentation || !(presentation?.required ?? field.required)) continue;
|
|
77
|
+
vars[field.name] = field.default?.trim() ? field.default : field.kind === 'url' ? `${HOSTED_ORIGIN}/`
|
|
78
|
+
: field.kind === 'select' ? field.options?.find(option => option.value)?.value || standIn({}, field) : standIn({}, field);
|
|
79
|
+
changed = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return vars;
|
|
83
|
+
}
|
|
84
|
+
|
|
46
85
|
/** The build served as rer deploy hosts it, with declared vars, origin and
|
|
47
|
-
*
|
|
48
|
-
export async function serveHosted(root, { declaration: declarationPath = 'deploy.json', bindings = {}, outboundService, rpc, workerEntrypoints = [] } = {}) {
|
|
86
|
+
* required public inputs and deploy/Managed mail secret stand-ins. `fetch(path, init)` uses the deployed origin. */
|
|
87
|
+
export async function serveHosted(root, { declaration: declarationPath = 'deploy.json', bindings = {}, outboundService, rpc, workerEntrypoints = [], publicHosts, fixturePreparation = false } = {}) {
|
|
49
88
|
const { loopbackFetch } = await shared('loopback-fetch.mjs');
|
|
50
89
|
const build = join(root, 'dist/server'), client = join(root, 'dist/client');
|
|
51
90
|
let config;
|
|
@@ -54,6 +93,7 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
54
93
|
let declaration;
|
|
55
94
|
try { declaration = await read(join(root, declarationPath)); }
|
|
56
95
|
catch { throw new RerError('hosted_output_missing', `No readable deploy declaration at ${declarationPath}. A seed whose deploy reads another file names it with the commandAdapter option deployDeclaration.`, 1); }
|
|
96
|
+
const origins = hostedOrigins(declaration, publicHosts, HOSTED_ORIGIN);
|
|
57
97
|
const manifest = await optional(join(root, 'rer-setup.json'));
|
|
58
98
|
const { Miniflare, convertV4MiniflareOptions = options => options } = await miniflareFor(root);
|
|
59
99
|
const entry = join(build, config.main);
|
|
@@ -70,9 +110,10 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
70
110
|
for (const binding of await hostedMailCredentials(root)) {
|
|
71
111
|
if (!Object.hasOwn(secrets, binding)) secrets[binding] = standIn({}, manifest.fields?.find(field => field.name === binding));
|
|
72
112
|
}
|
|
73
|
-
const
|
|
113
|
+
const publicVariables = await hostedPublicVariables(root, config, declaration, manifest);
|
|
114
|
+
const options = { host: '127.0.0.1', port: 0, cf: false, workers: [{ name: 'ingress', modules: true, script: ingress, serviceBindings: { APP: 'app', ...nativeBindings } }, ...rpcServices.workers, {
|
|
74
115
|
name: 'app', ...(outboundService ? { outboundService } : {}), modules, modulesRoot: build, compatibilityDate: config.compatibility_date, compatibilityFlags: config.compatibility_flags,
|
|
75
|
-
bindings: { ...
|
|
116
|
+
bindings: { ...publicVariables, ...secrets, ...(declaration.originVar ? { [declaration.originVar]: HOSTED_ORIGIN } : {}),
|
|
76
117
|
RER_DEPLOY_SOURCE: identity.sourceSha, RER_DEPLOY_FINGERPRINT: identity.fingerprint, RER_VERSION: { id: identity.versionId, tag: '', timestamp: new Date().toISOString() }, ...bindings },
|
|
77
118
|
d1Databases: Object.fromEntries((config.d1_databases ?? []).map(item => [item.binding, item.database_id ?? item.database_name])),
|
|
78
119
|
r2Buckets: Object.fromEntries((config.r2_buckets ?? []).map(item => [item.binding, item.bucket_name])),
|
|
@@ -85,7 +126,25 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
85
126
|
serviceBindings: rpcServices.serviceBindings,
|
|
86
127
|
durableObjects: Object.fromEntries((config.durable_objects?.bindings ?? []).filter(item => !item.script_name).map(item => [item.name, { className: item.class_name, useSQLite: true }])),
|
|
87
128
|
...(config.assets ? { assets: { directory: client, binding: config.assets.binding ?? 'ASSETS', routerConfig: { has_user_worker: true, invoke_user_worker_ahead_of_assets: RUN_WORKER_FIRST } } } : {}),
|
|
88
|
-
}] }
|
|
129
|
+
}] };
|
|
130
|
+
let preparation, producers, held = false;
|
|
131
|
+
const waiting = new Set();
|
|
132
|
+
const release = () => { held = false; for (const resume of waiting) resume(); waiting.clear(); };
|
|
133
|
+
// Install the gate before owner hooks retain any D1 handles; replacing
|
|
134
|
+
// Miniflare options later would disconnect those existing handles.
|
|
135
|
+
if (fixturePreparation) {
|
|
136
|
+
const app = options.workers.find(worker => worker.name === 'app');
|
|
137
|
+
const wrapper = join(build, '__rer_preparation.mjs');
|
|
138
|
+
const native = './' + config.main;
|
|
139
|
+
app.modules = [{ type: 'ESModule', path: wrapper, contents:
|
|
140
|
+
`import app from ${JSON.stringify(native)};export * from ${JSON.stringify(native)};export default {...app,async queue(batch,env,ctx){await env.RER_PREPARATION_QUEUE_GATE.fetch('https://queue.invalid');return app.queue(batch,env,ctx)}}` }, ...modules];
|
|
141
|
+
app.serviceBindings = { ...app.serviceBindings, RER_PREPARATION_QUEUE_GATE: async () => {
|
|
142
|
+
if (held) await new Promise(resume => waiting.add(resume));
|
|
143
|
+
return new Response(null, { status: 204 });
|
|
144
|
+
} };
|
|
145
|
+
producers = preparationProducers(options, config);
|
|
146
|
+
}
|
|
147
|
+
const mf = new Miniflare(convertV4MiniflareOptions(options));
|
|
89
148
|
let loopback;
|
|
90
149
|
try {
|
|
91
150
|
loopback = await mf.ready;
|
|
@@ -99,11 +158,32 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
99
158
|
await migrate(await mf.getD1Database(item.binding, 'app'), withRewrites(plan, await readMigrationRewrites(root), { partial: true }));
|
|
100
159
|
}
|
|
101
160
|
} catch (error) { await mf.dispose(); throw error; }
|
|
102
|
-
|
|
161
|
+
const preparedDatabase = async binding => {
|
|
162
|
+
if (!(config.d1_databases ?? []).some(item => item.binding === binding)) throw new RerError('hosted_database_invalid', new FixtureDatabaseError().message, 1);
|
|
163
|
+
return preparationDatabase(await mf.getD1Database(binding, 'app'));
|
|
164
|
+
};
|
|
165
|
+
const hosted = { client, identity, origin: HOSTED_ORIGIN, origins,
|
|
103
166
|
worker: async entrypoint => {
|
|
104
167
|
if (!Object.hasOwn(nativeWorkers, entrypoint)) throw new RerError('agent_invoke_invalid', 'Verification can invoke only its declared native Worker entrypoint.', 1);
|
|
105
168
|
return (await mf.getBindings('ingress'))[nativeWorkers[entrypoint]];
|
|
106
169
|
},
|
|
170
|
+
// Only the conformance call sites request these powers. Ordinary hosted
|
|
171
|
+
// checks and owner initialization keep their SELECT-only reader below.
|
|
172
|
+
preparation: async () => preparation ??= (async () => {
|
|
173
|
+
if (!fixturePreparation) throw new RerError('hosted_database_invalid', 'Native preparation requires a disposable conformance host.', 1);
|
|
174
|
+
return Object.freeze({
|
|
175
|
+
database: async binding => (await preparedDatabase(binding)).database,
|
|
176
|
+
scheduled: async ({ scheduledTime = Date.now() } = {}) => {
|
|
177
|
+
if (!Number.isFinite(scheduledTime)) throw new Error('Native scheduled preparation requires a finite Unix millisecond time.');
|
|
178
|
+
try {
|
|
179
|
+
const result = await (await mf.getWorker('app')).scheduled({ scheduledTime });
|
|
180
|
+
if (result.outcome !== 'ok') throw new Error();
|
|
181
|
+
}
|
|
182
|
+
catch { throw new Error('Native scheduled preparation failed; fixture values are not logged.'); }
|
|
183
|
+
},
|
|
184
|
+
queues: Object.freeze({ hold: () => { held = true; }, release, ...producers(mf) }),
|
|
185
|
+
});
|
|
186
|
+
})(),
|
|
107
187
|
database: async binding => {
|
|
108
188
|
if (!(config.d1_databases ?? []).some(item => item.binding === binding)) throw new RerError('hosted_database_invalid', 'Verification can read only a declared disposable database binding.', 1);
|
|
109
189
|
const db = await mf.getD1Database(binding, 'app');
|
|
@@ -111,8 +191,13 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
111
191
|
if (typeof sql !== 'string' || !/^\s*SELECT\b/i.test(sql) || sql.includes(';')) throw new RerError('hosted_database_invalid', 'Verification state access is read-only SELECT.', 1);
|
|
112
192
|
return db.prepare(sql);
|
|
113
193
|
} };
|
|
114
|
-
}, close: () => mf.dispose(),
|
|
115
|
-
fetch: (path, { headers, ...init } = {}) =>
|
|
194
|
+
}, close: () => { release(); return mf.dispose(); },
|
|
195
|
+
fetch: (path, { headers, origin = HOSTED_ORIGIN, ...init } = {}) => {
|
|
196
|
+
if (!origins.includes(origin)) throw new RerError('agent_door_origin', 'Agent conformance request must use a declared hosted installation origin.', 1);
|
|
197
|
+
return loopbackFetch(loopback, { ...init, redirect: 'manual', headers: { ...headers, 'x-rer-original-url': `${origin}/${path}` } });
|
|
198
|
+
} };
|
|
199
|
+
if (fixturePreparation) registerHistoryInstallation(hosted, preparedDatabase);
|
|
200
|
+
return hosted;
|
|
116
201
|
}
|
|
117
202
|
|
|
118
203
|
export async function checkHostedOutput(root, options) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { RerError } from './errors.mjs';
|
|
2
|
+
|
|
3
|
+
// Only disposable conformance hosts install these RPC producers. The native
|
|
4
|
+
// queue lives behind the fault check, so a rejected send cannot enqueue work.
|
|
5
|
+
const producer = `import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
6
|
+
let failed = false;
|
|
7
|
+
// The default control entrypoint is available only to the host. Application
|
|
8
|
+
// bindings use Producer, which exposes only the queue operations below.
|
|
9
|
+
export default { fetch(request) { failed = new URL(request.url).pathname === '/fail'; return new Response(null, { status: 204 }); } };
|
|
10
|
+
export class Producer extends WorkerEntrypoint {
|
|
11
|
+
async send(body, options) { if (failed) throw new Error('Conformance queue producer failure.'); return this.env.QUEUE.send(body, options); }
|
|
12
|
+
async sendBatch(messages, options) { if (failed) throw new Error('Conformance queue producer failure.'); return this.env.QUEUE.sendBatch(messages, options); }
|
|
13
|
+
}`;
|
|
14
|
+
|
|
15
|
+
export function preparationProducers(options, config) {
|
|
16
|
+
const app = options.workers.find(worker => worker.name === 'app');
|
|
17
|
+
const declared = new Map();
|
|
18
|
+
const validate = binding => {
|
|
19
|
+
if (!declared.has(binding)) throw new RerError('hosted_queue_invalid', 'Queue preparation requires a declared producer binding.', 1);
|
|
20
|
+
};
|
|
21
|
+
for (const [index, item] of (config.queues?.producers ?? []).entries()) {
|
|
22
|
+
const name = `rer-conformance-queue-${index}`;
|
|
23
|
+
declared.set(item.binding, name);
|
|
24
|
+
options.workers.push({ name, modules: true, script: producer, compatibilityDate: config.compatibility_date,
|
|
25
|
+
queueProducers: { QUEUE: item.queue },
|
|
26
|
+
});
|
|
27
|
+
app.serviceBindings[item.binding] = { name, entrypoint: 'Producer' };
|
|
28
|
+
}
|
|
29
|
+
app.queueProducers = {};
|
|
30
|
+
return mf => {
|
|
31
|
+
const control = async (binding, action) => {
|
|
32
|
+
const response = await (await mf.getWorker(declared.get(binding))).fetch('https://queue.invalid/' + action, { method: 'POST' });
|
|
33
|
+
if (!response.ok) throw new RerError('hosted_queue_invalid', 'Disposable queue producer control failed.', 1);
|
|
34
|
+
};
|
|
35
|
+
return Object.freeze({
|
|
36
|
+
fail: binding => { validate(binding); return control(binding, 'fail'); },
|
|
37
|
+
restore: binding => {
|
|
38
|
+
if (binding === undefined) return Promise.all([...declared.keys()].map(name => control(name, 'restore')));
|
|
39
|
+
validate(binding); return control(binding, 'restore');
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|