@runeditrun/rer 0.2.85 → 0.2.87
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 +138 -29
- package/cli/README.md +61 -1
- package/cli/agent-bindings.mjs +25 -0
- package/cli/agent-door.mjs +145 -0
- package/cli/agent-fixtures.mjs +16 -0
- package/cli/agent-journey-fixtures.mjs +17 -0
- package/cli/agent-mail.mjs +54 -0
- package/cli/agent-network.mjs +64 -0
- package/cli/agent-reviewers.mjs +110 -0
- package/cli/agent-rpc.mjs +23 -0
- package/cli/agent-secrets.mjs +23 -0
- package/cli/agent-sponsors.mjs +43 -0
- package/cli/agent-surface.mjs +34 -0
- package/cli/agent-verifier.mjs +31 -0
- package/cli/agent-webhooks.mjs +19 -0
- package/cli/authoring.mjs +2 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +3 -1
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +23 -5
- package/cli/business/connect.mjs +19 -7
- package/cli/business/detector.mjs +4 -1
- package/cli/business/device.mjs +13 -0
- package/cli/business/export-inputs.mjs +69 -0
- package/cli/business/export-task.mjs +17 -0
- package/cli/business/invocation.mjs +8 -1
- package/cli/business/keychain.mjs +8 -1
- package/cli/business/lease.mjs +11 -1
- package/cli/business/local-commands.mjs +79 -31
- package/cli/business/outbound.mjs +9 -4
- package/cli/business/parsers-config.mjs +8 -7
- package/cli/business/parsers-syntax.mjs +7 -3
- package/cli/business/permissions.mjs +2 -0
- package/cli/business/questions.mjs +89 -9
- package/cli/business/setup-command.mjs +49 -0
- package/cli/business/setup-company.json +15 -0
- package/cli/business/setup-demo.mjs +95 -0
- package/cli/business/state.mjs +44 -10
- package/cli/business/supervisor.mjs +94 -35
- package/cli/business/vendor-door.mjs +230 -0
- package/cli/business/vendors/README.md +29 -3
- package/cli/business/vendors/common.mjs +8 -6
- package/cli/business/vendors/index.mjs +22 -11
- package/cli/business/vendors/sorry.mjs +106 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +4 -1
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +89 -0
- package/cli/door-clauses.mjs +157 -0
- package/cli/export.mjs +17 -4
- package/cli/hosted-output.mjs +31 -8
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +3 -1
- package/cli/main.mjs +1 -0
- package/cli/managed-data-schema.mjs +14 -1
- package/cli/managed-data.mjs +8 -4
- package/cli/portability-empty.mjs +6 -0
- package/cli/portability-migrations.mjs +26 -4
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +1 -0
- package/cli/production-auth.mjs +2 -2
- package/cli/production-mail.mjs +19 -3
- package/cli/server-registry.mjs +2 -0
- package/edition-authoring/archive-source.mjs +65 -0
- package/edition-authoring/base-copies.mjs +108 -21
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/copy-namespaces.mjs +28 -0
- package/edition-authoring/edition-migrations.mjs +7 -3
- package/edition-authoring/files.mjs +2 -1
- package/edition-authoring/module-closure.mjs +58 -27
- package/edition-authoring/module-edges.mjs +13 -2
- package/edition-authoring/workflow-copies.mjs +1 -1
- package/edition-authoring/workflow-scripts.mjs +12 -3
- package/foundation/runtime/contract-docs.mjs +220 -32
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/global/CHANGELOG.md +151 -0
- package/global/README.md +138 -29
- package/global/door/command.mjs +3 -1
- package/global/main.mjs +1 -1
- package/modules/agent-door/CLAUSES.md +215 -0
- package/modules/agent-door/conformance/audit-pages.mjs +11 -0
- package/modules/agent-door/conformance/audit-rows.mjs +20 -0
- package/modules/agent-door/conformance/audit.mjs +63 -0
- package/modules/agent-door/conformance/authority.d.mts +2 -0
- package/modules/agent-door/conformance/authority.mjs +17 -0
- package/modules/agent-door/conformance/crypto.mjs +36 -0
- package/modules/agent-door/conformance/discovery.mjs +61 -0
- package/modules/agent-door/conformance/fixtures.mjs +41 -0
- package/modules/agent-door/conformance/index.mjs +41 -0
- package/modules/agent-door/conformance/injection.mjs +24 -0
- package/modules/agent-door/conformance/invocation.mjs +33 -0
- package/modules/agent-door/conformance/journey.mjs +117 -0
- package/modules/agent-door/conformance/narrowing.d.mts +2 -0
- package/modules/agent-door/conformance/narrowing.mjs +29 -0
- package/modules/agent-door/conformance/negative.mjs +48 -0
- package/modules/agent-door/conformance/network-modules.mjs +86 -0
- package/modules/agent-door/conformance/network-runtime.mjs +46 -0
- package/modules/agent-door/conformance/policy-phases.mjs +83 -0
- package/modules/agent-door/conformance/protocol.mjs +153 -0
- package/modules/agent-door/conformance/replay.mjs +39 -0
- package/modules/agent-door/conformance/schema.mjs +71 -0
- package/modules/agent-door/conformance/security.mjs +34 -0
- package/modules/agent-door/conformance/sponsors.mjs +68 -0
- package/modules/agent-door/conformance/step-hooks.mjs +4 -0
- package/modules/agent-door/conformance/surface.mjs +92 -0
- package/modules/agent-door/conformance/target.mjs +19 -0
- package/modules/agent-door/conformance/tool-name.d.mts +1 -0
- package/modules/agent-door/conformance/tool-name.mjs +7 -0
- package/modules/agent-door/conformance/webhooks.mjs +31 -0
- package/modules/container/image-variables.mjs +8 -2
- package/modules/delivery-producer/mail.mjs +20 -0
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/ownership.mjs +39 -0
- package/modules/demo-host/plan.mjs +2 -1
- package/modules/demo-host/remove.mjs +6 -1
- package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
- package/modules/import-kit/schema/importers.schema.json +107 -0
- package/modules/import-kit/src/door/ADOPTING.md +20 -0
- package/modules/import-kit/src/door/README.md +2 -1
- package/modules/import-kit/src/door/admission.ts +5 -3
- package/modules/import-kit/src/door/archive.ts +5 -2
- package/modules/import-kit/src/door/authority.ts +1 -0
- package/modules/import-kit/src/door/grants.ts +1 -1
- package/modules/import-kit/src/door/handler.ts +14 -8
- package/modules/import-kit/src/door/index.ts +1 -1
- package/modules/import-kit/src/door/jobs.ts +40 -0
- package/modules/import-kit/src/door/operator.ts +3 -3
- package/modules/import-kit/src/door/planning.ts +10 -6
- package/modules/import-kit/src/door/protocol.ts +2 -2
- package/modules/import-kit/src/door/raw.ts +25 -0
- package/modules/import-kit/src/door/refusals.ts +1 -0
- package/modules/import-kit/src/door/types.ts +26 -6
- package/modules/import-kit/src/receipt/encoding.ts +37 -0
- package/modules/import-kit/src/receipt/index.ts +69 -0
- package/modules/import-kit/src/receipt/policy.ts +24 -0
- package/modules/import-kit/src/receipt/types.ts +64 -0
- package/modules/import-kit/src/receipt/uri.ts +45 -0
- package/modules/import-kit/src/receipt/validation.ts +87 -0
- package/modules/import-kit/src/status/encoding.ts +13 -0
- package/modules/import-kit/src/status/evidence.ts +218 -0
- package/modules/import-kit/src/status/index.ts +56 -0
- package/modules/import-kit/src/status/schema.ts +208 -0
- package/modules/import-kit/src/status/types.ts +86 -0
- package/modules/operator-auth/accounts/delegated.mjs +48 -0
- package/modules/operator-auth/index.d.mts +7 -0
- package/modules/operator-auth/service.mjs +2 -0
- package/modules/portability/README.md +37 -13
- package/modules/portability/bridge.mjs +22 -2
- package/modules/portability/catalogue.mjs +12 -2
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/import.mjs +14 -7
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/cli/business/opt-ins.mjs +0 -37
|
@@ -22,10 +22,12 @@ export async function deployOwnerInput({ root, adapter, setupSeed, options, sign
|
|
|
22
22
|
}
|
|
23
23
|
const advice = 'Deploy needs your owner name; run rer deploy --owner-name "Your name" (or rer setup --owner-name "Your name"). Nothing was uploaded.';
|
|
24
24
|
if (!displayName?.trim()) {
|
|
25
|
+
// A local plan never bootstraps an owner or asks for their name.
|
|
26
|
+
if (options.dryRun) return { input };
|
|
25
27
|
// A recorded bootstrap keeps its owner; resolving inputs needs no provider read.
|
|
26
28
|
const held = (await heldDeployments(root)).find(item => item.environment === (options.environment ?? 'production'));
|
|
27
29
|
if (['claimed', 'kept'].includes(held?.record.ownerClaim?.outcome)) return { input };
|
|
28
|
-
if (options.
|
|
30
|
+
if (options.nonInteractive || options.json || !process.stdin.isTTY) throw missing(advice);
|
|
29
31
|
const prompt = createInterface({ input: process.stdin, output: process.stderr });
|
|
30
32
|
const closed = new Promise((_, reject) => prompt.once('close', () => reject(missing(advice))));
|
|
31
33
|
try { displayName = await Promise.race([prompt.question('Your name (hosted owner): ', { signal }), closed]); }
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { contained } from './project.mjs';
|
|
3
|
+
import { deployConfigPaths } from './deploy-config.mjs';
|
|
4
|
+
import { parseJsonc } from './jsonc.mjs';
|
|
5
|
+
import { comments } from './business/parsers-syntax.mjs';
|
|
6
|
+
import { tomlEntries } from './business/parsers-config.mjs';
|
|
7
|
+
import { imageVariableSecrets } from '../modules/container/image-variables.mjs';
|
|
8
|
+
import { publicMailSender, validateMailSenders } from '../modules/delivery-producer/mail.mjs';
|
|
9
|
+
import { deliveryDeclarationSources } from './delivery-declarations.mjs';
|
|
10
|
+
|
|
11
|
+
const id = 'deploy.vars-secrets';
|
|
12
|
+
const lineAt = (source, offset) => source.slice(0, offset).split('\n').length;
|
|
13
|
+
const variablePath = path => path[0] === 'vars' && path.length === 2 ||
|
|
14
|
+
path[0] === 'env' && path[2] === 'vars' && path.length === 4;
|
|
15
|
+
|
|
16
|
+
async function sourceFile(root, path) {
|
|
17
|
+
try { return await readFile(await contained(root, path, { optional: true }), 'utf8'); }
|
|
18
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function variableEntries(root, path) {
|
|
22
|
+
const source = await sourceFile(root, path);
|
|
23
|
+
if (source === null) return [];
|
|
24
|
+
const entries = [];
|
|
25
|
+
let config;
|
|
26
|
+
try {
|
|
27
|
+
if (path.endsWith('.toml')) entries.push(...tomlEntries(comments(source).clean, { locations: true }));
|
|
28
|
+
else config = parseJsonc(source, (path, offset) => entries.push({ path, offset }));
|
|
29
|
+
} catch (error) { throw Error(`${path}: ${error.message}`); }
|
|
30
|
+
return entries.filter(entry => variablePath(entry.path)).map(entry => ({
|
|
31
|
+
binding: entry.path.at(-1),
|
|
32
|
+
value: config ? entry.path.reduce((value, key) => value?.[key], config) : entry.value,
|
|
33
|
+
source: `${path}:${lineAt(source, entry.offset)} (${entry.path.join('.')})`,
|
|
34
|
+
location: `${path}:${lineAt(source, entry.offset)} (${entry.path.slice(0, -1).join('.')})`,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Source defaults participate in the same sender check as deploy inputs. */
|
|
39
|
+
export async function sourceMailSenders(root, adapter) {
|
|
40
|
+
const senders = [];
|
|
41
|
+
for (const path of deployConfigPaths(adapter)) {
|
|
42
|
+
for (const entry of await variableEntries(root, path)) if (entry.binding === 'MAIL_FROM') senders.push(entry);
|
|
43
|
+
}
|
|
44
|
+
return senders;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Reuse the image builder's JSONC reader and binding comparison. Source checks
|
|
48
|
+
// reject secret placeholders before a build normalizes them. Managed MAIL_FROM
|
|
49
|
+
// is a public input even when the deploy adapter supplies it through secrets.
|
|
50
|
+
export async function deployVariableClause(root, adapter) {
|
|
51
|
+
try {
|
|
52
|
+
const declarationPath = adapter?.deploy?.declaration ?? 'deploy.json';
|
|
53
|
+
const declarationSource = await sourceFile(root, declarationPath);
|
|
54
|
+
if (declarationSource === null) return { id, ok: true };
|
|
55
|
+
const secretLocations = new Map();
|
|
56
|
+
const declaration = parseJsonc(declarationSource, (path, offset) => {
|
|
57
|
+
if (path.length === 3 && path[0] === 'secrets' && path[2] === 'binding') secretLocations.set(path[1], lineAt(declarationSource, offset));
|
|
58
|
+
});
|
|
59
|
+
// deploy.json uses strict JSON in both native and container builds.
|
|
60
|
+
try { JSON.parse(declarationSource); } catch { throw Error(`${declarationPath}: invalid JSON declaration.`); }
|
|
61
|
+
const secrets = declaration.secrets ?? [];
|
|
62
|
+
if (!Array.isArray(secrets) || secrets.some(secret => typeof secret?.binding !== 'string')) throw Error(`${declarationPath}: secrets must be an array of binding declarations.`);
|
|
63
|
+
const senders = [{ source: `${declarationPath} vars.MAIL_FROM`, value: declaration.vars?.MAIL_FROM }];
|
|
64
|
+
let publicSender = false, privateSender = false;
|
|
65
|
+
for (const [path, select] of deliveryDeclarationSources) {
|
|
66
|
+
const source = await sourceFile(root, path);
|
|
67
|
+
if (source === null) continue;
|
|
68
|
+
const spec = select(JSON.parse(source));
|
|
69
|
+
if (!spec) continue;
|
|
70
|
+
publicSender ||= publicMailSender(spec);
|
|
71
|
+
privateSender ||= [...(spec.secretNames ?? []), ...(spec.optionalSecretNames ?? [])].includes('MAIL_FROM');
|
|
72
|
+
senders.push({ source: `${path} publicVariables.MAIL_FROM`, value: spec.publicVariables?.MAIL_FROM });
|
|
73
|
+
}
|
|
74
|
+
const overlaps = [];
|
|
75
|
+
for (const path of deployConfigPaths(adapter)) {
|
|
76
|
+
for (const entry of await variableEntries(root, path)) {
|
|
77
|
+
const { binding, value } = entry;
|
|
78
|
+
if (binding === 'MAIL_FROM') senders.push(entry);
|
|
79
|
+
const matched = new Set(imageVariableSecrets({ [binding]: value }, secrets).map(secret => secret.binding));
|
|
80
|
+
if (!matched.has(binding)) continue;
|
|
81
|
+
if (binding === 'MAIL_FROM' && publicSender && !privateSender) continue;
|
|
82
|
+
for (const [index, secret] of secrets.entries()) if (secret.binding === binding) overlaps.push(
|
|
83
|
+
`${binding}: ${entry.location} and ${declarationPath}:${secretLocations.get(index)} (secrets)`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
validateMailSenders(senders);
|
|
87
|
+
return overlaps.length ? { id, ok: false, message: overlaps.join('\n') + '\nremove it from wrangler vars; the deploy sets it as a secret' } : { id, ok: true };
|
|
88
|
+
} catch (error) { return { id, ok: false, message: error.message }; }
|
|
89
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { resolve, relative, isAbsolute } from 'node:path';
|
|
5
|
+
import { parseContract } from '../foundation/runtime/seed-contract.mjs';
|
|
6
|
+
import { RerError } from './errors.mjs';
|
|
7
|
+
|
|
8
|
+
export const clausesHelp = `Usage: rer door clauses (--write | --check) [--cwd DIR]
|
|
9
|
+
|
|
10
|
+
Synchronize BASE-AGENT-001 through BASE-AGENT-013 in CONTRACT.md.
|
|
11
|
+
--write adds or updates Base's requirements, preserving existing status,
|
|
12
|
+
evidence and gaps, then runs the seed's contract-docs write and check.
|
|
13
|
+
--check is read-only and names missing or stale clauses (exit 1).
|
|
14
|
+
Seed-owned clauses and the judged revision stay unchanged. Newly added clauses
|
|
15
|
+
start missing. Regenerate the seed's source lock last, before committing.
|
|
16
|
+
`;
|
|
17
|
+
const fail = message => { throw new RerError('agent_clauses_invalid', message, 1); };
|
|
18
|
+
const read = file => readFileSync(file, 'utf8');
|
|
19
|
+
const area = '### Agent surface (Base-delivered)';
|
|
20
|
+
|
|
21
|
+
// Directory records deliver new non-code files on refresh, too. A recorded
|
|
22
|
+
// clause copy selects its immutable text; older runtime pins without this file
|
|
23
|
+
// can still sync their contract using the CLI's independently delivered source.
|
|
24
|
+
function canonical(root) {
|
|
25
|
+
const record = resolve(root, 'base-copies.json');
|
|
26
|
+
if (existsSync(record)) {
|
|
27
|
+
const origin = 'modules/agent-door/CLAUSES.md';
|
|
28
|
+
const candidates = JSON.parse(read(record)).copies?.filter(copy => origin === copy.originPath || origin.startsWith(copy.originPath + '/')) ?? [];
|
|
29
|
+
if (candidates.length > 1) fail('Overlapping agent-door copy records; repair base-copies.json first.');
|
|
30
|
+
if (candidates.length) {
|
|
31
|
+
const copy = candidates[0], name = copy.path + origin.slice(copy.originPath.length), file = resolve(root, name);
|
|
32
|
+
const inside = relative(root, file);
|
|
33
|
+
if (isAbsolute(inside) || inside === '..' || inside.startsWith('../')) fail('Agent clause copy must stay inside this seed.');
|
|
34
|
+
if (!copy.files?.[name]) return read(new URL('../modules/agent-door/CLAUSES.md', import.meta.url));
|
|
35
|
+
if (!existsSync(file)) fail(`Restore the recorded agent clause source ${name} before syncing.`);
|
|
36
|
+
const bytes = readFileSync(file);
|
|
37
|
+
if (createHash('sha256').update(bytes).digest('hex') !== copy.files[name]) fail(`Recorded agent clause source ${name} has local edits; restore or refresh it first.`);
|
|
38
|
+
return bytes.toString('utf8');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return read(new URL('../modules/agent-door/CLAUSES.md', import.meta.url));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function definitions(source) {
|
|
45
|
+
const blocks = [...source.matchAll(/^#### (BASE-AGENT-\d{3}) — ([^\n]+)\n([\s\S]*?)(?=^#{1,4} |$(?![\s\S]))/gm)];
|
|
46
|
+
const result = blocks.map(([, id, title, body]) => ({ id, title, text: `#### ${id} — ${title}\n${body.trimEnd()}`, row: source.split('\n').find(line => line.startsWith(`| \`${id}\` |`)) }));
|
|
47
|
+
for (const clause of result) {
|
|
48
|
+
const acceptance = clause.text.split('\n**Acceptance.**\n')[1];
|
|
49
|
+
const points = [...(acceptance ?? '').matchAll(/^(\d+)\. /gm)];
|
|
50
|
+
if (!points.length || points.length > 8 || points.some((point, index) => Number(point[1]) !== index + 1)) fail(`${clause.id} needs one to eight consecutive acceptance points in its canonical source.`);
|
|
51
|
+
}
|
|
52
|
+
const ids = Array.from({ length: 13 }, (_, i) => `BASE-AGENT-${String(i + 1).padStart(3, '0')}`);
|
|
53
|
+
if (result.map(item => item.id).join() !== ids.join() || result.some(item => !item.row)) fail('Canonical agent clauses must define BASE-AGENT-001 through 013 with initial Status rows.');
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function headings(lines) {
|
|
58
|
+
let fence;
|
|
59
|
+
return lines.flatMap((line, index) => {
|
|
60
|
+
const mark = /^\s*(`{3,}|~{3,})/.exec(line)?.[1];
|
|
61
|
+
if (mark) { if (!fence) fence = mark[0]; else if (fence === mark[0]) fence = undefined; return []; }
|
|
62
|
+
const match = !fence && /^(#{1,6}) ([^\r\n]+)/.exec(line);
|
|
63
|
+
return match ? [{ index, level: match[1].length, title: match[2] }] : [];
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// contract-docs owns summary generation. Suppress only its three derived rows
|
|
68
|
+
// for structural validation while a contract is awaiting regeneration.
|
|
69
|
+
function withoutSummary(text) {
|
|
70
|
+
return text.replace(/^(\| Clauses \| Done \| Partial \| Missing \| Total \|\r?\n[^\n]*\n)((?:\|[^\n]*\n)+)/m, (_, header, rows) => header + rows.replace(/[^\r\n]+/g, ''));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function synchronize(original, clauses) {
|
|
74
|
+
const parsed = parseContract(withoutSummary(original));
|
|
75
|
+
const lines = original.match(/[^\n]*\n|[^\n]+$/g) ?? [], outline = headings(lines);
|
|
76
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
77
|
+
const edits = [], missing = [], changed = [];
|
|
78
|
+
const target = outline.find(item => item.level === 2 && item.title === 'Target clauses');
|
|
79
|
+
if (!target) fail('CONTRACT.md needs the standard ## Target clauses section. Convert the contract before syncing.');
|
|
80
|
+
const targetEnd = outline.find(item => item.index > target.index && item.level <= 2)?.index ?? lines.length;
|
|
81
|
+
for (const clause of clauses) {
|
|
82
|
+
const old = parsed.clauses.find(item => item.id === clause.id);
|
|
83
|
+
if (!old) { missing.push(clause); changed.push(`${clause.id} missing`); continue; }
|
|
84
|
+
if (!lines[old.line - 1].startsWith('#### ') || old.kind !== 'target') fail(`${clause.id} must be a standard level-four Target clause before syncing; preserve its judgment when converting.`);
|
|
85
|
+
const start = old.line - 1, end = outline.find(item => item.index > start)?.index ?? lines.length;
|
|
86
|
+
const before = lines.slice(start, end).join(''), trailing = /\s*$/.exec(before)[0];
|
|
87
|
+
const after = clause.text.replaceAll('\n', newline) + trailing;
|
|
88
|
+
const row = lines[old.row - 1];
|
|
89
|
+
// A changed canonical title updates only the title cell, never the seed's
|
|
90
|
+
// kind, status, evidence or gap cells (or their original spacing).
|
|
91
|
+
const updatedRow = row.replace(/^(\s*\|[^|]*\|)([^|]*)(\|.*)/, (_, first, title, rest) => first + title.replace(/\S(?:[\s\S]*\S)?/, clause.title) + rest);
|
|
92
|
+
if (before !== after || row !== updatedRow) {
|
|
93
|
+
changed.push(`${clause.id} stale`);
|
|
94
|
+
edits.push({ start, end, text: after }, { start: old.row - 1, end: old.row, text: updatedRow });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (missing.length) {
|
|
98
|
+
const delivered = outline.find(item => item.index > target.index && item.index < targetEnd && lines[item.index].trimEnd() === area);
|
|
99
|
+
const agent = outline.find(item => item.index > target.index && item.index < targetEnd && item.level === 3 && item.title === 'Agent surface');
|
|
100
|
+
const at = delivered ? outline.find(item => item.index > delivered.index && item.level <= 3)?.index ?? targetEnd : agent?.index ?? targetEnd;
|
|
101
|
+
const text = (delivered ? '' : area + '\n\n') + missing.map(item => item.text).join('\n\n') + '\n\n';
|
|
102
|
+
edits.push({ start: at, end: at, text: (at && !lines[at - 1].trim() ? '' : newline) + text.replaceAll('\n', newline) });
|
|
103
|
+
const status = outline.find(item => item.level === 2 && item.title === 'Status');
|
|
104
|
+
const header = lines.findIndex((line, index) => index > status?.index && /^\| Clause \| Title \| Kind \| Status \| Evidence \| Gap \|/.test(line));
|
|
105
|
+
if (header < 0) fail('CONTRACT.md needs the standard Status clause table.');
|
|
106
|
+
let end = header + 2;
|
|
107
|
+
while (lines[end]?.trimStart().startsWith('|')) end++;
|
|
108
|
+
edits.push({ start: end, end, text: (end && !lines[end - 1].endsWith('\n') ? newline : '') + missing.map(item => item.row).join(newline) + newline });
|
|
109
|
+
}
|
|
110
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) lines.splice(edit.start, edit.end - edit.start, edit.text);
|
|
111
|
+
const text = lines.join('');
|
|
112
|
+
parseContract(withoutSummary(text));
|
|
113
|
+
return { text, changed };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function generator(root) {
|
|
117
|
+
const agents = resolve(root, 'AGENTS.md');
|
|
118
|
+
const declared = existsSync(agents) ? [...read(agents).matchAll(/^Lander-Regenerate:\s*(.+)$/gm)].map(match => match[1].trim()) : [];
|
|
119
|
+
const command = declared.find(line => /contract-docs\.mjs\s+write\b/.test(line)) ?? 'node src/base/contract-docs.mjs write';
|
|
120
|
+
if (!declared.some(line => /contract-docs\.mjs\s+write\b/.test(line)) && !existsSync(resolve(root, 'src/base/contract-docs.mjs'))) fail('No contract-docs generator found. Restore the seed\'s Lander-Regenerate contract generator before writing.');
|
|
121
|
+
return { write: command, check: command.replace(/(contract-docs\.mjs\s+)write\b/, '$1check') };
|
|
122
|
+
}
|
|
123
|
+
function generate(command, root, env) {
|
|
124
|
+
const result = spawnSync(command, { cwd: root, env, shell: true, stdio: 'inherit' });
|
|
125
|
+
if (result.error || result.status !== 0) fail(`Contract generation failed: ${command}. Inspect the diff and repair the generator before committing.`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function doorClausesCommand(args, env = process.env) {
|
|
129
|
+
if (args.includes('--help') || args.includes('-h')) { console.log(clausesHelp); return 0; }
|
|
130
|
+
let root = process.cwd(), mode;
|
|
131
|
+
try {
|
|
132
|
+
for (let i = 0; i < args.length; i++) {
|
|
133
|
+
const arg = args[i];
|
|
134
|
+
if (arg === '--cwd' && args[i + 1] && !args[i + 1].startsWith('-')) root = resolve(args[++i]);
|
|
135
|
+
else if (['--write', '--check'].includes(arg) && !mode) mode = arg;
|
|
136
|
+
else throw new RerError('invalid_arguments', clausesHelp, 2);
|
|
137
|
+
}
|
|
138
|
+
if (!mode) throw new RerError('invalid_arguments', clausesHelp, 2);
|
|
139
|
+
root = resolve(root);
|
|
140
|
+
const file = resolve(root, 'CONTRACT.md');
|
|
141
|
+
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), { text, changed } = synchronize(original, definitions(canonical(root)));
|
|
143
|
+
if (changed.length) console.log(`Agent clauses: ${changed.join(', ')}.`);
|
|
144
|
+
if (mode === '--check' && changed.length) return 1;
|
|
145
|
+
const commands = generator(root);
|
|
146
|
+
if (mode === '--write') {
|
|
147
|
+
if (text !== original) writeFileSync(file, text);
|
|
148
|
+
generate(commands.write, root, env);
|
|
149
|
+
}
|
|
150
|
+
generate(commands.check, root, env);
|
|
151
|
+
console.log(changed.length ? `Synchronized ${changed.length} Base-delivered agent clauses; existing judgments preserved. Regenerate the source lock last.` : 'Base-delivered agent clauses are current; no clause changes.');
|
|
152
|
+
return 0;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (!(error instanceof RerError)) throw error;
|
|
155
|
+
console.error(error.message); return error.exitCode;
|
|
156
|
+
}
|
|
157
|
+
}
|
package/cli/export.mjs
CHANGED
|
@@ -2,11 +2,16 @@ import { cp, mkdir, readFile, readdir, rm, writeFile, lstat } from 'node:fs/prom
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { resolve, dirname, relative } from 'node:path';
|
|
4
4
|
import { testSource } from '../composition/git-source.mjs';
|
|
5
|
-
import { cliVersion } from './version.mjs';
|
|
5
|
+
import { cliVersion, stampedVersion } from './version.mjs';
|
|
6
|
+
import { execFileSync } from 'node:child_process';
|
|
6
7
|
|
|
7
8
|
// Copy whole maintained source/tooling directories. Python publication scans
|
|
8
9
|
// load sibling modules and data dynamically; they belong in the inventory too.
|
|
9
|
-
export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/d1', 'modules/import-kit/src/door', 'modules/import-kit/src/readers', 'modules/import-kit/src/provenance/numeric-credentials.ts', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/module-closure.mjs', 'edition-authoring/edition-migrations.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/runtime-dependencies.mjs', 'edition-authoring/module-resolution.mjs', 'edition-authoring/package-target.mjs', 'edition-authoring/module-syntax.mjs', 'edition-authoring/module-edges.mjs', 'edition-authoring/vendor/babel-parser', 'edition-authoring/workflow-copies.mjs', 'edition-authoring/workflow-scripts.mjs', 'edition-authoring/vendor/yaml', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs', 'foundation/runtime/run-data.mjs', 'foundation/runtime/run-data.d.mts', 'foundation/runtime/contract-docs.mjs'];
|
|
10
|
+
export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/receipt', 'modules/import-kit/src/status', 'modules/import-kit/schema', 'modules/import-kit/src/d1', 'modules/import-kit/src/door', 'modules/import-kit/src/readers', 'modules/import-kit/src/provenance/numeric-credentials.ts', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/module-closure.mjs', 'edition-authoring/edition-migrations.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/runtime-dependencies.mjs', 'edition-authoring/module-resolution.mjs', 'edition-authoring/package-target.mjs', 'edition-authoring/module-syntax.mjs', 'edition-authoring/module-edges.mjs', 'edition-authoring/vendor/babel-parser', 'edition-authoring/workflow-copies.mjs', 'edition-authoring/workflow-scripts.mjs', 'edition-authoring/vendor/yaml', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs', 'foundation/runtime/run-data.mjs', 'foundation/runtime/run-data.d.mts', 'foundation/runtime/contract-docs.mjs'];
|
|
11
|
+
sourceRoots.push('modules/agent-door/conformance', 'modules/agent-door/CLAUSES.md');
|
|
12
|
+
sourceRoots.push('edition-authoring/archive-source.mjs');
|
|
13
|
+
sourceRoots.push('edition-authoring/copy-namespaces.mjs');
|
|
14
|
+
sourceRoots.push('foundation/runtime/contract-prose.mjs', 'foundation/runtime/contract-prose-patterns.mjs');
|
|
10
15
|
export async function inventory(base, roots = sourceRoots) {
|
|
11
16
|
const files = [];
|
|
12
17
|
async function walk(path) {
|
|
@@ -40,8 +45,16 @@ export async function exportCLI(base, destination) {
|
|
|
40
45
|
record[path] = { source: path, sha256: createHash('sha256').update(bytes).digest('hex') };
|
|
41
46
|
}
|
|
42
47
|
const onboardingFiles=Object.fromEntries(await Promise.all((await inventory(base,['onboarding'])).map(async path=>[path.slice('onboarding/'.length),{source:path,sha256:createHash('sha256').update(await readFile(resolve(base,path))).digest('hex')}])));
|
|
43
|
-
//
|
|
44
|
-
|
|
48
|
+
// The maintained reference is committed beside its exporter. Stamp its last
|
|
49
|
+
// exported source change, so committing generated copies does not invalidate
|
|
50
|
+
// their version again. Exports to other checkouts still name the exact HEAD.
|
|
51
|
+
let version;
|
|
52
|
+
if (resolve(destination) === resolve(base, 'default-seed')) {
|
|
53
|
+
const revision = execFileSync('git', ['-C', base, 'log', '-1', '--format=%H', 'HEAD', '--',
|
|
54
|
+
'global/package.json', ...files, ...Object.values(onboardingFiles).map(file => file.source)], { encoding: 'utf8' }).trim();
|
|
55
|
+
const source = JSON.parse(await readFile(resolve(base, 'global/package.json'), 'utf8'));
|
|
56
|
+
version = stampedVersion(base, source.version, revision);
|
|
57
|
+
} else version = cliVersion(base);
|
|
45
58
|
await writeFile(resolve(target, 'inventory.json'), JSON.stringify({ version: 1, ...(version ? { cliVersion: version } : {}), onboarding: '../base-onboarding', onboardingFiles, files: record }, null, 2) + '\n');
|
|
46
59
|
await writeFile(resolve(destination, 'scripts/rer.mjs'), "#!/usr/bin/env node\nimport { main } from './base-cli/cli/main.mjs';\nprocess.exitCode = await main();\n");
|
|
47
60
|
}
|
package/cli/hosted-output.mjs
CHANGED
|
@@ -9,11 +9,13 @@ 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 { shared } from './shared.mjs';
|
|
13
|
+
import { verificationRpc } from './agent-rpc.mjs';
|
|
12
14
|
|
|
13
15
|
// Serve the production build the way rer deploy hosts it (assets behind the
|
|
14
16
|
// Worker, deploy identity bound, a public https origin) on loopback, with no
|
|
15
17
|
// network or account. The ingress hands the app the hosted URL and Host.
|
|
16
|
-
const
|
|
18
|
+
export const HOSTED_ORIGIN = 'https://rer-hosted-check.invalid';
|
|
17
19
|
const ingress = `export default {fetch(request,env){const url=new URL(request.headers.get('x-rer-original-url')),headers=new Headers(request.headers);headers.delete('x-rer-original-url');headers.set('host',url.host);return env.APP.fetch(new Request(url,{method:request.method,headers,redirect:'manual',...(!['GET','HEAD'].includes(request.method)?{body:request.body}:{})}))}}`;
|
|
18
20
|
const read = async path => JSON.parse(await readFile(path, 'utf8'));
|
|
19
21
|
const optional = path => read(path).catch(error => { if (error.code === 'ENOENT') return {}; throw error; });
|
|
@@ -43,7 +45,8 @@ const links = html => [...html.matchAll(/(?:src|href)=["'](\/[^"'#?\s]+)/g)].map
|
|
|
43
45
|
|
|
44
46
|
/** The build served as rer deploy hosts it, with declared vars, origin and
|
|
45
47
|
* stand-in deploy/Managed mail secrets. `fetch(path, init)` uses the deployed origin. */
|
|
46
|
-
export async function serveHosted(root, { declaration: declarationPath = 'deploy.json' } = {}) {
|
|
48
|
+
export async function serveHosted(root, { declaration: declarationPath = 'deploy.json', bindings = {}, outboundService, rpc, workerEntrypoints = [] } = {}) {
|
|
49
|
+
const { loopbackFetch } = await shared('loopback-fetch.mjs');
|
|
47
50
|
const build = join(root, 'dist/server'), client = join(root, 'dist/client');
|
|
48
51
|
let config;
|
|
49
52
|
try { config = await read(join(build, 'wrangler.json')); }
|
|
@@ -54,20 +57,28 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
54
57
|
const manifest = await optional(join(root, 'rer-setup.json'));
|
|
55
58
|
const { Miniflare, convertV4MiniflareOptions = options => options } = await miniflareFor(root);
|
|
56
59
|
const entry = join(build, config.main);
|
|
60
|
+
const rpcServices = await verificationRpc(root, rpc, config.services);
|
|
61
|
+
const nativeWorkers = Object.fromEntries(workerEntrypoints.map((entrypoint, index) => [entrypoint, `RER_NATIVE_${index}`]));
|
|
62
|
+
const nativeBindings = Object.fromEntries(Object.entries(nativeWorkers).map(([entrypoint, binding]) => [binding, { name: 'app', entrypoint }]));
|
|
57
63
|
const modules = [entry, ...(await files(build)).map(path => join(build, path)).filter(path => path !== entry && moduleTypes[extname(path)])].map(path => ({ type: moduleTypes[extname(path)], path }));
|
|
58
64
|
const identity = { sourceSha: createHash('sha1').update(randomBytes(16)).digest('hex'), fingerprint: createHash('sha256').update(randomBytes(16)).digest('hex'), versionId: crypto.randomUUID() };
|
|
59
65
|
const secrets = Object.fromEntries((declaration.secrets ?? []).map(item => [item.binding, standIn(item, manifest.fields?.find(field => field.name === item.binding))]));
|
|
60
66
|
for (const binding of await hostedMailCredentials(root)) {
|
|
61
67
|
if (!Object.hasOwn(secrets, binding)) secrets[binding] = standIn({}, manifest.fields?.find(field => field.name === binding));
|
|
62
68
|
}
|
|
63
|
-
const mf = new Miniflare(convertV4MiniflareOptions({ host: '127.0.0.1', port: 0, cf: false, workers: [{ name: 'ingress', modules: true, script: ingress, serviceBindings: { APP: 'app' } }, {
|
|
64
|
-
name: 'app', modules, modulesRoot: build, compatibilityDate: config.compatibility_date, compatibilityFlags: config.compatibility_flags,
|
|
65
|
-
bindings: { ...config.vars, ...declaration.vars, ...secrets, ...(declaration.originVar ? { [declaration.originVar]:
|
|
66
|
-
RER_DEPLOY_SOURCE: identity.sourceSha, RER_DEPLOY_FINGERPRINT: identity.fingerprint, RER_VERSION: { id: identity.versionId, tag: '', timestamp: new Date().toISOString() } },
|
|
69
|
+
const mf = new Miniflare(convertV4MiniflareOptions({ host: '127.0.0.1', port: 0, cf: false, workers: [{ name: 'ingress', modules: true, script: ingress, serviceBindings: { APP: 'app', ...nativeBindings } }, ...rpcServices.workers, {
|
|
70
|
+
name: 'app', ...(outboundService ? { outboundService } : {}), modules, modulesRoot: build, compatibilityDate: config.compatibility_date, compatibilityFlags: config.compatibility_flags,
|
|
71
|
+
bindings: { ...config.vars, ...declaration.vars, ...secrets, ...(declaration.originVar ? { [declaration.originVar]: HOSTED_ORIGIN } : {}),
|
|
72
|
+
RER_DEPLOY_SOURCE: identity.sourceSha, RER_DEPLOY_FINGERPRINT: identity.fingerprint, RER_VERSION: { id: identity.versionId, tag: '', timestamp: new Date().toISOString() }, ...bindings },
|
|
67
73
|
d1Databases: Object.fromEntries((config.d1_databases ?? []).map(item => [item.binding, item.database_id ?? item.database_name])),
|
|
68
74
|
r2Buckets: Object.fromEntries((config.r2_buckets ?? []).map(item => [item.binding, item.bucket_name])),
|
|
69
75
|
kvNamespaces: Object.fromEntries((config.kv_namespaces ?? []).map(item => [item.binding, item.id ?? item.binding])),
|
|
70
76
|
queueProducers: Object.fromEntries((config.queues?.producers ?? []).map(item => [item.binding, item.queue])),
|
|
77
|
+
queueConsumers: Object.fromEntries((config.queues?.consumers ?? []).map(item => [item.queue, {
|
|
78
|
+
...(item.max_batch_size !== undefined ? { maxBatchSize: item.max_batch_size } : {}), ...(item.max_batch_timeout !== undefined ? { maxBatchTimeout: item.max_batch_timeout } : {}),
|
|
79
|
+
...(item.max_retries !== undefined ? { maxRetries: item.max_retries } : {}), ...(item.dead_letter_queue ? { deadLetterQueue: item.dead_letter_queue } : {}), ...(item.retry_delay !== undefined ? { retryDelay: item.retry_delay } : {}),
|
|
80
|
+
}])),
|
|
81
|
+
serviceBindings: rpcServices.serviceBindings,
|
|
71
82
|
durableObjects: Object.fromEntries((config.durable_objects?.bindings ?? []).filter(item => !item.script_name).map(item => [item.name, { className: item.class_name, useSQLite: true }])),
|
|
72
83
|
...(config.assets ? { assets: { directory: client, binding: config.assets.binding ?? 'ASSETS', routerConfig: { has_user_worker: true, invoke_user_worker_ahead_of_assets: RUN_WORKER_FIRST } } } : {}),
|
|
73
84
|
}] }));
|
|
@@ -84,8 +95,20 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
84
95
|
await migrate(await mf.getD1Database(item.binding, 'app'), withRewrites(plan, await readMigrationRewrites(root), { partial: true }));
|
|
85
96
|
}
|
|
86
97
|
} catch (error) { await mf.dispose(); throw error; }
|
|
87
|
-
return { client, identity, origin:
|
|
88
|
-
|
|
98
|
+
return { client, identity, origin: HOSTED_ORIGIN,
|
|
99
|
+
worker: async entrypoint => {
|
|
100
|
+
if (!Object.hasOwn(nativeWorkers, entrypoint)) throw new RerError('agent_invoke_invalid', 'Verification can invoke only its declared native Worker entrypoint.', 1);
|
|
101
|
+
return (await mf.getBindings('ingress'))[nativeWorkers[entrypoint]];
|
|
102
|
+
},
|
|
103
|
+
database: async binding => {
|
|
104
|
+
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);
|
|
105
|
+
const db = await mf.getD1Database(binding, 'app');
|
|
106
|
+
return { prepare(sql) {
|
|
107
|
+
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);
|
|
108
|
+
return db.prepare(sql);
|
|
109
|
+
} };
|
|
110
|
+
}, close: () => mf.dispose(),
|
|
111
|
+
fetch: (path, { headers, ...init } = {}) => loopbackFetch(loopback, { ...init, redirect: 'manual', headers: { ...headers, 'x-rer-original-url': `${HOSTED_ORIGIN}/${path}` } }) };
|
|
89
112
|
}
|
|
90
113
|
|
|
91
114
|
export async function checkHostedOutput(root, options) {
|
package/cli/inspect.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deployVariableClause } from './deploy-variables.mjs';
|
|
1
2
|
import { browserDoctor } from './browser-runtime.mjs';
|
|
2
3
|
import { dependencyDoctor } from './dependency-doctor.mjs';
|
|
3
4
|
import { inventory } from './export.mjs';
|
|
@@ -25,6 +26,7 @@ import { checkoutPlaceholderMarks } from './placeholder-mark.mjs';
|
|
|
25
26
|
import { contractStatusClauses } from './contract-status.mjs';
|
|
26
27
|
import { hostedExportCommand } from './hosted-export-command.mjs';
|
|
27
28
|
import { cloudflareCredentials } from './deploy-needs.mjs';
|
|
29
|
+
import { agentSurfaceClauses } from './agent-surface.mjs';
|
|
28
30
|
|
|
29
31
|
// cliVersion: the rer version of the code answering (absent for a vendored copy
|
|
30
32
|
// too old to record one). defaults: what a server start applies when the person
|
|
@@ -81,6 +83,8 @@ export async function check(project, explicitProfile) {
|
|
|
81
83
|
// A warning, never a failing clause: live run sites redeploy while seeds keep Base's mark.
|
|
82
84
|
let placeholderMarks = [];
|
|
83
85
|
clauses.push(...await deliveryDeclarationClauses(project.root));
|
|
86
|
+
clauses.push(await deployVariableClause(project.root, project.adapter));
|
|
87
|
+
clauses.push(...await agentSurfaceClauses(project.root));
|
|
84
88
|
for (const command of project.commands) add('SC-10.inputs.' + command.name, command.available, `Restore the declared inputs for ${command.name}.`);
|
|
85
89
|
for (const loop of project.descriptor.loops ?? []) add('SC-10.loop.' + loop.id, !loop.required || loop.enabled, `Enable the required ${loop.id} loop or correct its declaration.`);
|
|
86
90
|
if (project.profile === 'first-party' || explicitProfile === 'first-party') {
|
package/cli/jsonc.mjs
CHANGED
|
@@ -7,8 +7,8 @@ function location(text, position) {
|
|
|
7
7
|
// version's error wording. An explicit stack also handles deeply nested input.
|
|
8
8
|
// Only comments and commas accepted by the grammar are masked; offsets stay in
|
|
9
9
|
// the original source and comment removal can never join separate tokens.
|
|
10
|
-
export function parseJsonc(text) {
|
|
11
|
-
const result = text.split(''), stack = [{ kind: 'root', state: 'value' }];
|
|
10
|
+
export function parseJsonc(text, onProperty) {
|
|
11
|
+
const result = text.split(''), stack = [{ kind: 'root', state: 'value', path: [] }];
|
|
12
12
|
let index = 0;
|
|
13
13
|
const fail = (message, position = index) => {
|
|
14
14
|
throw new SyntaxError(`${position === text.length ? 'Unexpected end of JSON input' : message} at ${location(text, position)}`);
|
|
@@ -80,7 +80,10 @@ export function parseJsonc(text) {
|
|
|
80
80
|
index++; stack.pop();
|
|
81
81
|
} else if (frame.state === 'keyOrEnd') {
|
|
82
82
|
if (char !== '"') fail('Expected a property name');
|
|
83
|
-
|
|
83
|
+
const start = index; string();
|
|
84
|
+
frame.key = onProperty ? JSON.parse(text.slice(start, index)) : undefined;
|
|
85
|
+
onProperty?.([...frame.path, frame.key], start);
|
|
86
|
+
frame.state = 'colon';
|
|
84
87
|
} else if (frame.state === 'colon') {
|
|
85
88
|
if (char !== ':') fail("Expected ':' after property name");
|
|
86
89
|
index++; frame.state = 'value';
|
|
@@ -91,10 +94,11 @@ export function parseJsonc(text) {
|
|
|
91
94
|
if (text[index] === closing) result[comma] = ' ';
|
|
92
95
|
frame.state = frame.kind === 'object' ? 'keyOrEnd' : 'valueOrEnd';
|
|
93
96
|
} else {
|
|
97
|
+
const path = !onProperty ? undefined : frame.kind === 'root' ? [] : [...frame.path, frame.kind === 'array' ? frame.next++ : frame.key];
|
|
94
98
|
frame.state = frame.kind === 'root' ? 'end' : 'comma';
|
|
95
99
|
if (char === '{' || char === '[') {
|
|
96
100
|
index++;
|
|
97
|
-
stack.push({ kind: char === '{' ? 'object' : 'array', state: char === '{' ? 'keyOrEnd' : 'valueOrEnd' });
|
|
101
|
+
stack.push({ kind: char === '{' ? 'object' : 'array', state: char === '{' ? 'keyOrEnd' : 'valueOrEnd', path, next: 0 });
|
|
98
102
|
} else if (char === '"') string();
|
|
99
103
|
else if (char === '-' || digit()) number();
|
|
100
104
|
else {
|
package/cli/lifecycle.mjs
CHANGED
|
@@ -112,7 +112,9 @@ async function runLifecycle(project, options, out, deployRedaction) {
|
|
|
112
112
|
const declaration = adapter.deployDeclaration ?? adapter.deploy?.declaration;
|
|
113
113
|
const hosted = await (await import('./hosted-output.mjs')).checkHostedOutput(project.root, { declaration });
|
|
114
114
|
await store.step('Checking that page sections hydrate as separate units');
|
|
115
|
-
|
|
115
|
+
const hydration = await (await import('./hydration/check.mjs')).checkHydration(project.root, { pages: adapter.publicPages, declaration, report: lines => lines.forEach(line => store.report(line)) });
|
|
116
|
+
const agentDoor = await (await import('./agent-door.mjs')).checkAgentDoor(project.root, { declaration, setupManifest: project.setupManifest, owner: adapter.hooks?.owner, report: line => store.report(line) });
|
|
117
|
+
return { hosted, hydration, agentDoor };
|
|
116
118
|
}
|
|
117
119
|
if (['export', 'import'].includes(options.verb)) return await transfer(project, options, signal, { store, operationToken: operation.token });
|
|
118
120
|
if (options.verb === 'deploy') {
|
package/cli/main.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { check, describe, doctorSummary } from './inspect.mjs';
|
|
|
8
8
|
import { selectNodeRuntime } from './node-runtime.mjs';
|
|
9
9
|
|
|
10
10
|
export async function main(argv = process.argv.slice(2)) {
|
|
11
|
+
if (argv[0] === 'door' && argv[1] === 'clauses') return (await import('./door-clauses.mjs')).doorClausesCommand(argv.slice(2));
|
|
11
12
|
if (argv[0] === 'business') return (await import('./business/command.mjs')).businessCommand(argv.slice(1));
|
|
12
13
|
if (argv[0] === 'companion') return (await import('./companion/command.mjs')).companionCommand(argv.slice(1));
|
|
13
14
|
// Every runtime a seed's hooks start inherits this: Wrangler and the Cloudflare
|
|
@@ -24,7 +24,10 @@ export async function managedSchema(db, plan, policy, ledger) {
|
|
|
24
24
|
if (!normalized.has(object.sql)) normalized.set(object.sql, schemaSQL(object.sql));
|
|
25
25
|
return normalized.get(object.sql);
|
|
26
26
|
};
|
|
27
|
-
|
|
27
|
+
// Older native restores left engine-owned staging tables behind. They are
|
|
28
|
+
// transient copies, excluded from portability identity, not unknown product DDL.
|
|
29
|
+
const objects = source.filter(object => ['table', 'trigger', 'index', 'view'].includes(object.type)
|
|
30
|
+
&& !(object.type === 'table' && object.name.toLowerCase().startsWith('rer_portability_stage_')));
|
|
28
31
|
const retired = new Map();
|
|
29
32
|
let previous = new Map();
|
|
30
33
|
try {
|
|
@@ -37,6 +40,16 @@ export async function managedSchema(db, plan, policy, ledger) {
|
|
|
37
40
|
}
|
|
38
41
|
previous = current;
|
|
39
42
|
}
|
|
43
|
+
// A Managed dump omits derived virtual tables and their shadow storage.
|
|
44
|
+
// Install only exact policy names that the destination's own migrations
|
|
45
|
+
// establish as virtual tables. Source SQL never gains a virtual-table door.
|
|
46
|
+
const virtual = scratch.prepare('PRAGMA table_list').all().filter(table => table.type === 'virtual');
|
|
47
|
+
for (const table of virtual) if ((policy.derivedTables ?? []).includes(table.name) && !(policy.includeTables ?? []).includes(table.name)) {
|
|
48
|
+
insist(!objects.some(object => object.type === 'table' && object.name === table.name), 'managed_data_schema_incompatible', 409);
|
|
49
|
+
const target = previous.get(key({ type: 'table', name: table.name }));
|
|
50
|
+
try { await db.prepare(target.sql).run(); }
|
|
51
|
+
catch { throw new PortabilityError('managed_data_derived_refused', 409); }
|
|
52
|
+
}
|
|
40
53
|
// Native restore also installs runtime-owned bookkeeping. Derive it with
|
|
41
54
|
// the same destination helpers, never a source name or a policy wildcard.
|
|
42
55
|
const native = nativeDatabase(scratch);
|
package/cli/managed-data.mjs
CHANGED
|
@@ -26,7 +26,7 @@ export async function withManagedDataImport(context, declaration, restore) {
|
|
|
26
26
|
catch (error) {
|
|
27
27
|
if (!(error instanceof PortabilityError)) throw error;
|
|
28
28
|
const reason = error.code.startsWith('managed_data_') ? error.code : error.code.split(':').slice(0, 2).join(':');
|
|
29
|
-
throw new RerError(reason, `Managed data restore refused (${reason}). The destination has not accepted this archive
|
|
29
|
+
throw new RerError(reason, `Managed data restore refused (${reason}). The destination has not accepted this archive.${reason.startsWith('identity_table_undeclared:') ? ' Declare this table in includeTables to transfer its rows or excludeTables to omit them.' : ''}`, 4);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
async function intake(context, declaration, restore) {
|
|
@@ -55,7 +55,7 @@ async function intake(context, declaration, restore) {
|
|
|
55
55
|
check(Buffer.byteLength(sql) <= 16 * 1024 * 1024, 'oversized');
|
|
56
56
|
const statements = splitStatements(sql);
|
|
57
57
|
check(statements.length <= 10000, 'oversized');
|
|
58
|
-
const prepared = [];
|
|
58
|
+
const prepared = [[], [], []];
|
|
59
59
|
for (const statement of statements) {
|
|
60
60
|
context.signal?.throwIfAborted();
|
|
61
61
|
const tokens = sqliteTokens(statement), head = tokens.slice(0, 3).map(token => token.text.toLowerCase());
|
|
@@ -75,9 +75,13 @@ async function intake(context, declaration, restore) {
|
|
|
75
75
|
}
|
|
76
76
|
sql += statement.slice(offset);
|
|
77
77
|
check(Buffer.byteLength(sql) <= 100000, 'oversized');
|
|
78
|
-
|
|
78
|
+
// A child INSERT may precede its parent's definition in the producer's
|
|
79
|
+
// dump. Validate everything first, then create all tables in the same
|
|
80
|
+
// deferred-FK batch. Keep the remaining order, especially trigger creation.
|
|
81
|
+
const phase = head[0] === 'pragma' ? 0 : head[0] === 'create' && head[1] === 'table' ? 1 : 2;
|
|
82
|
+
prepared[phase].push(params.length ? db.prepare(sql).bind(...params) : db.prepare(sql));
|
|
79
83
|
}
|
|
80
|
-
await db.batch(prepared);
|
|
84
|
+
await db.batch(prepared.flat());
|
|
81
85
|
} catch (error) {
|
|
82
86
|
if (error instanceof PortabilityError || context.signal?.aborted) throw error;
|
|
83
87
|
check(false, 'sql_refused');
|
|
@@ -47,6 +47,12 @@ export async function emptyNativePreflight({ root, binding, policy, policyModule
|
|
|
47
47
|
const after = await Promise.all(paths.map(status));
|
|
48
48
|
insist(before.every((info, i) => info ? after[i] && ['ino', 'size', 'mtimeMs', 'ctimeMs'].every(key => info[key] === after[i][key]) : !after[i]), 'restore_state_changed', 409);
|
|
49
49
|
snapshot = new DatabaseSync(join(directory, 'database.sqlite'), { readOnly: true });
|
|
50
|
+
// Wrangler can create a D1 file before any product migrations run. Only
|
|
51
|
+
// literal SQLite/Cloudflare engine internals may exist in that empty file;
|
|
52
|
+
// policy exclusions and migration ledgers do not make other schema empty.
|
|
53
|
+
// Every existing product/foreign object still goes through the full policy
|
|
54
|
+
// and occupied-table checks before migrations can change the destination.
|
|
55
|
+
if (!snapshot.prepare("SELECT 1 FROM sqlite_master WHERE substr(lower(name),1,7) <> 'sqlite_' AND substr(lower(name),1,4) <> '_cf_' LIMIT 1").get()) return;
|
|
50
56
|
const db = { prepare(sql) { const query = snapshot.prepare(sql); let values = []; return {
|
|
51
57
|
bind(...args) { values = args; return this; },
|
|
52
58
|
async all() { return { results: query.all(...values) }; },
|
|
@@ -62,27 +62,49 @@ export async function mapMigrationLedger({root,binding='DB',platformMigrations,e
|
|
|
62
62
|
} catch(error) { throw constantRefusal(error); }
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// Older runners leave Wrangler's bookkeeping beside their authoritative hashed
|
|
66
|
+
// history. A tracked D1 ledger is another history and must agree with it.
|
|
67
|
+
async function legacyPairPreflight(db) {
|
|
68
|
+
const columns=await all(db,'PRAGMA table_info(_rer_deploy_migrations)');
|
|
69
|
+
insist(['name','sha256','state'].every(name=>columns.some(column=>column.name===name)),'migration_ledger:incompatible',409);
|
|
70
|
+
const history=await all(db,'SELECT name,sha256,state FROM _rer_deploy_migrations ORDER BY name');
|
|
71
|
+
insist(history.every(row=>row.state==='applied'),'migration_ledger:uncertain',409);
|
|
72
|
+
insist(history.every(row=>typeof row.name==='string' && typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)) && new Set(history.map(row=>row.name)).size===history.length,'migration_ledger:incompatible',409);
|
|
73
|
+
const nativeColumns=(await all(db,'PRAGMA table_info(d1_migrations)')).map(column=>column.name);
|
|
74
|
+
const tracked=nativeColumns.includes('state') || nativeColumns.includes('sha256');
|
|
75
|
+
insist(['id','name','applied_at'].every(name=>nativeColumns.includes(name)) && (!tracked || nativeColumns.includes('state') && nativeColumns.includes('sha256')),'migration_ledger:incompatible',409);
|
|
76
|
+
const native=await all(db,`SELECT name${tracked?',sha256,state':''} FROM d1_migrations ORDER BY id`);
|
|
77
|
+
insist(native.every(row=>typeof row.name==='string') && new Set(native.map(row=>row.name)).size===native.length,'migration_ledger:incompatible',409);
|
|
78
|
+
if(tracked) {
|
|
79
|
+
insist(native.every(row=>row.state==='applied'),'migration_ledger:uncertain',409);
|
|
80
|
+
insist(native.every(row=>typeof row.sha256==='string' && /^[a-f0-9]{64}$/.test(row.sha256)),'migration_ledger:incompatible',409);
|
|
81
|
+
insist(native.length===history.length && native.every((row,index)=>row.name===history[index].name && row.sha256===history[index].sha256),'migration_ledger:multiple',409);
|
|
82
|
+
} else insist(native.every(row=>history.some(prior=>prior.name===row.name)),'migration_ledger:multiple',409);
|
|
83
|
+
}
|
|
84
|
+
|
|
65
85
|
// Adapter entry point, before *any* native Wrangler apply. The caller supplies
|
|
66
86
|
// the real target binding and keeps its writers stopped through apply/transfer.
|
|
67
87
|
// This only reads: it never repairs history or creates a second ledger.
|
|
68
88
|
export async function nativeMigrationPreflight({root,db,binding='DB',platformMigrations}) {
|
|
69
89
|
const declaration=platformMigrationDeclaration(platformMigrations);
|
|
70
90
|
const tables=await all(db,`SELECT type,name FROM sqlite_master WHERE lower(name) IN (${ledgerNames.map(name=>`'${name}'`).join(',')})`);
|
|
71
|
-
|
|
91
|
+
const legacyPair=tables.length===2 && ['_rer_deploy_migrations','d1_migrations'].every(name=>tables.some(row=>row.name===name));
|
|
92
|
+
insist(tables.length<=1 || legacyPair,'migration_ledger:multiple',409);
|
|
72
93
|
insist(tables.every(row=>row.type==='table' && ledgerNames.includes(row.name)),'migration_ledger:incompatible',409);
|
|
73
|
-
const table=tables[0]?.name;
|
|
94
|
+
const table=legacyPair?'_rer_deploy_migrations':tables[0]?.name;
|
|
74
95
|
if(!table)return {nativeApply:true};
|
|
75
96
|
// This runner's history cannot authorize Wrangler to apply the same files.
|
|
76
|
-
insist(table!=='_rer_deploy_migrations','migration_ledger:runner',409);
|
|
97
|
+
insist(table!=='_rer_deploy_migrations' || legacyPair,'migration_ledger:runner',409);
|
|
77
98
|
const files=await migrationInventory(root,binding,declaration);
|
|
78
99
|
let nativeApply=false;
|
|
79
100
|
try {
|
|
101
|
+
if(legacyPair)await legacyPairPreflight(db);
|
|
80
102
|
const ledger=await destinationLedger(db),applied=matchMigrationLedger(ledger,files,declaration);
|
|
81
103
|
// Wrangler skips only literal filenames, not transfer aliases or hashes.
|
|
82
104
|
if(table==='d1_migrations')insist(ledger.every(row=>files.some(file=>file.name===row.name)),'migration_ledger:incompatible',409);
|
|
83
105
|
nativeApply=table==='d1_migrations' && files.some(file=>!applied.includes(file.name));
|
|
84
106
|
// The checkout file is named: it is the seed's own, never a ledger value.
|
|
85
|
-
if(table
|
|
107
|
+
if(table!=='d1_migrations')for(const file of files)if(!applied.includes(file.name))throw Object.assign(new PortabilityError('migration_ledger:unapplied',409),{migration:file.name});
|
|
86
108
|
} catch(error) { throw constantRefusal(error); }
|
|
87
109
|
return {nativeApply};
|
|
88
110
|
}
|