@runeditrun/rer 0.2.73 → 0.2.75

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.
Files changed (47) hide show
  1. package/cli/contract.mjs +1 -1
  2. package/cli/export.mjs +1 -1
  3. package/cli/parse.mjs +1 -0
  4. package/cli/portability-worker.mjs +6 -7
  5. package/cli/release.mjs +9 -0
  6. package/cli/site-check.mjs +4 -2
  7. package/cli/site-prepare.mjs +6 -0
  8. package/cli/site-render.mjs +7 -1
  9. package/cli/site-runtime.mjs +55 -0
  10. package/cli/site.mjs +45 -17
  11. package/global/CHANGELOG.md +13 -0
  12. package/modules/container/build.mjs +2 -1
  13. package/modules/deploy-kit/README.md +47 -2
  14. package/modules/deploy-kit/owner-cli.mjs +2 -1
  15. package/modules/deploy-kit/site-readback.mjs +12 -2
  16. package/modules/deploy-kit/site-runtime.mjs +33 -0
  17. package/modules/deploy-kit/site.mjs +27 -8
  18. package/modules/operator-auth/scheduled/definition.mjs +3 -1
  19. package/modules/operator-auth/scheduled/expiry.mjs +2 -2
  20. package/modules/operator-auth/scheduled/fence.mjs +2 -1
  21. package/modules/operator-auth/scheduled/runner.mjs +13 -5
  22. package/modules/portability/README.md +27 -8
  23. package/modules/portability/backfills.mjs +22 -14
  24. package/modules/portability/bridge.mjs +9 -6
  25. package/modules/portability/migration-sql.mjs +8 -0
  26. package/modules/portability/migration-statements.mjs +22 -17
  27. package/modules/portability/rebuilds.mjs +106 -0
  28. package/modules/portability/replay-views.mjs +35 -0
  29. package/modules/release/produce.mjs +5 -3
  30. package/modules/release/publication-scan.mjs +5 -4
  31. package/modules/site/docs-search/SearchField.tsx +18 -0
  32. package/modules/site/docs-search/artifacts.mjs +54 -0
  33. package/modules/site/docs-search/client.ts +194 -0
  34. package/modules/site/docs-search/index-build.mjs +63 -0
  35. package/modules/site/docs-search/retrieve.ts +16 -0
  36. package/modules/site/docs-search/search.css +19 -0
  37. package/modules/site/docs-search/sections.ts +24 -0
  38. package/modules/site/docs-search/types.ts +14 -0
  39. package/modules/site/docs-search/worker.ts +39 -0
  40. package/package.json +1 -1
  41. package/scripts/publish-check/README.md +6 -1
  42. package/scripts/publish-check/cli.py +8 -4
  43. package/scripts/publish-check/history_hydration.py +4 -1
  44. package/scripts/publish-check/slots.py +67 -0
  45. package/scripts/publish-check/timeout.json +1 -0
  46. package/scripts/publish-check/timeout.mjs +14 -0
  47. package/scripts/publish-check.mjs +18 -5
package/cli/contract.mjs CHANGED
@@ -26,5 +26,5 @@ export const demoVerb = Object.freeze({ flags: [...commonFlags, '--port', '--hos
26
26
  // sign the owner in to, so no seed declares it and check does not ask for it.
27
27
  export const signinVerb = Object.freeze({ flags: [...commonFlags, '--environment', '--env-file'], effects: 'A one-time sign-in link for the hosted owner, without mail. Uses the Cloudflare credentials that deployed --environment (default production; from the environment or --env-file) to write a single-use grant for the recorded owner into that deployment\'s auth database, then prints the link once to this terminal; it is never saved. The link works once, only for that owner, expires within 15 minutes, and its use is recorded in the owner\'s audit log. Signed in this way, the owner can correct a wrong email in settings.' });
28
28
  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]));
29
- export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--verify-workflow', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
29
+ 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'];
30
30
  export const requiredHooks = ['preview', 'dependencies', 'build', 'migrate', 'start', 'health', 'owner', 'signIn', 'verify', 'deploy', 'portability', 'state', 'settings', 'input'];
package/cli/export.mjs CHANGED
@@ -6,7 +6,7 @@ import { cliVersion } from './version.mjs';
6
6
 
7
7
  // Copy whole maintained source/tooling directories. Python publication scans
8
8
  // 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/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/files.mjs', 'foundation/runtime/seed-contract.mjs'];
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/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/files.mjs', 'foundation/runtime/seed-contract.mjs'];
10
10
  export async function inventory(base, roots = sourceRoots) {
11
11
  const files = [];
12
12
  async function walk(path) {
package/cli/parse.mjs CHANGED
@@ -17,6 +17,7 @@ export const origin = (host, port) => `http://${host === '::1' ? '[::1]' : host}
17
17
  export function parse(argv, cwd = process.cwd(), { independent = false, deferTail = false } = {}) {
18
18
  const [verb, ...args] = argv;
19
19
  if (!verb || verb === '--help') return { help: true };
20
+ // Release validates its own flags, including its integer publication scan timeout.
20
21
  if (verb === 'release') return { verb, releaseArgs: args };
21
22
  if (verb === 'archive') return { verb, archiveArgs: args };
22
23
  // rer demo is rer dev --demo.
@@ -4,7 +4,7 @@ import { readLegacyArchive } from '../modules/portability/format.mjs';
4
4
  import { recoverLegacyArchive } from '../modules/portability/legacy-files.mjs';
5
5
  import { legacyTargetState, requireLegacyEmpty } from '../modules/portability/legacy-safety.mjs';
6
6
  import { migrationReplay } from '../modules/portability/migration-history.mjs';
7
- import { splitStatements } from '../modules/portability/sql-text.mjs';
7
+ import { migrationStatements } from '../modules/portability/migration-sql.mjs';
8
8
  import { appliedMigrations as appliedMigrationNames } from '../modules/portability/bridge.mjs';
9
9
  import { join } from 'node:path';
10
10
  import { createHash } from 'node:crypto';
@@ -17,16 +17,15 @@ import { parseJsonc } from './jsonc.mjs';
17
17
  import { loadPolicy } from './portability-policy.mjs';
18
18
 
19
19
  // The migrations this installation applied, in its ledger's order, with each
20
- // file's hash, so a restore can place an older archive within them. Statements
21
- // are split at SQLite's own boundaries (sql-text.mjs), not Wrangler's: its
22
- // splitter can glue a trigger holding CASE ... END to the statements after it.
23
- async function appliedMigrations(root, db, binding) {
20
+ // file's hash, so a restore can place an older archive within them. Reproduce
21
+ // the runner's stored SQL text, then recover SQLite's statement boundaries.
22
+ async function appliedMigrations(root, db, binding, split) {
24
23
  const config = parseJsonc(await readFile(join(root, 'wrangler.jsonc'), 'utf8'));
25
24
  const directory = join(root, config.d1_databases.find(entry => entry.binding === binding).migrations_dir ?? 'migrations');
26
25
  const names = await appliedMigrationNames(db) ?? [];
27
26
  return Promise.all(names.map(async name => {
28
27
  const bytes = await readFile(join(directory, name));
29
- return { name, statements: splitStatements(bytes.toString('utf8')), sha256: createHash('sha256').update(bytes).digest('hex') };
28
+ return { name, statements: migrationStatements(bytes.toString('utf8'), split), sha256: createHash('sha256').update(bytes).digest('hex') };
30
29
  }));
31
30
  }
32
31
 
@@ -60,7 +59,7 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
60
59
  let proxy;
61
60
  try {
62
61
  proxy = await getPlatformProxy({ configPath, persist: { path: join(root, '.wrangler/state/v3') }, remoteBindings: false });
63
- const migrations=async()=>migrationReplay(await appliedMigrations(root,proxy.env[binding],binding),policy);
62
+ const migrations=async()=>migrationReplay(await appliedMigrations(root,proxy.env[binding],binding,unstable_splitSqlQuery),policy);
64
63
  const options={ db: proxy.env[binding], buckets: Object.fromEntries(Object.entries(buckets).map(([name, binding]) => [name, proxy.env[binding]])), policy, migrations };
65
64
  if(direction==='legacy-preflight') {
66
65
  await requireLegacyEmpty(options,await legacyTargetState(options.db,options.migrations));
package/cli/release.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { parseTimeoutSeconds, timeoutBounds } from '../scripts/publish-check/timeout.mjs';
2
+
1
3
  // Preserve release's accepted parser, producer, receipt and validation exits.
2
4
  const releaseHelp = `Usage: rer release --repo DIR --project PUBLISHER/NAME --repository GITHUB_URL --output NEW_DIR [FLAGS]
3
5
 
@@ -22,6 +24,9 @@ Without --tag, write a preview. This command never pushes, uploads or deploys.
22
24
  --verify-workflow NAME_OR_FILE
23
25
  Override the seed's declared GitHub verification workflow
24
26
  by name or file (case-insensitive).
27
+ --scan-timeout-seconds N
28
+ Publication scan deadline in integer seconds (1..${timeoutBounds.max}).
29
+ Omit to use the scanner default.
25
30
  --clean-history Prepare a parentless public export.
26
31
  --onto GITHUB_URL#BRANCH
27
32
  Prepare a public child of the destination's current branch;
@@ -52,6 +57,10 @@ export async function dispatchRelease(args) {
52
57
  for (let index = 0; index < args.length; index++) {
53
58
  if(args[index]==='--no-queue'){}
54
59
  else if (args[index] === '--tag') options.tag = args[index + 1]?.startsWith('v') ? args[++index] : true;
60
+ else if (args[index] === '--scan-timeout-seconds') {
61
+ try { options.scanTimeoutSeconds = parseTimeoutSeconds(args[++index], { integer: true }); }
62
+ catch (error) { throw Error(`--scan-timeout-seconds: ${error.message}`); }
63
+ }
55
64
  else if (args[index] === '--clean-history') options.cleanHistory = true;
56
65
  else if (args[index] === '--dry-run') options.dryRun = true;
57
66
  else if (args[index] === '--allow-placeholder-mark') options.allowPlaceholderMark = true;
@@ -6,6 +6,7 @@ import { privateDataScanner, decodedText } from './site-data.mjs';
6
6
  import { javascriptContent, javascriptContext } from './site-references.mjs';
7
7
  import { javascriptStrings } from './site-syntax.mjs';
8
8
  import { markupReferences, markupStrings, htmlElements, cssStrings } from './site-markup.mjs';
9
+ import { siteRuntime } from './site-runtime.mjs';
9
10
  import { refuse, RerError } from './errors.mjs';
10
11
  import { DEV_AI_MARKER, DEV_LAYER_MARKER } from './dev-identity.mjs';
11
12
 
@@ -66,7 +67,8 @@ export function servedFile(names, pathname) {
66
67
  * instance-only route, nothing fetched from another origin, no dev layer, and
67
68
  * none of the given private values (owner identity, secrets, the dev key).
68
69
  */
69
- export async function checkSite(folder, { privateValues = [], privateIdentities = [], root } = {}) {
70
+ export async function checkSite(folder, { privateValues = [], privateIdentities = [], root, runtime } = {}) {
71
+ const route = siteRuntime(runtime)?.endpoint;
70
72
  const all = await files(folder), names = new Set(all.keys());
71
73
  if (!names.has('index.html')) throw refuse('The run site has no index.html (its homepage).');
72
74
  if (!servedFile(names, '/run')) throw refuse('The run site has no /run page.');
@@ -112,7 +114,7 @@ export async function checkSite(folder, { privateValues = [], privateIdentities
112
114
  // fragment already fixes the instance path even when its tail is runtime.
113
115
  const boundary = !reference.dynamic || /[?#]/.test(url) || pathPrefix.endsWith('/');
114
116
  if (INSTANCE_ROUTES.some(route => (pathname === route && boundary) || pathname.startsWith(route + '/'))) problems.push(`${site} links to ${pathname}, which exists only on an installed instance`);
115
- else if (!reference.dynamic && !servedFile(names, safeDecode(pathname))) problems.push(`${site} links to ${pathname}, which the site does not have`);
117
+ else if (!reference.dynamic && !servedFile(names, safeDecode(pathname)) && pathname !== route) problems.push(`${site} links to ${pathname}, which the site does not have`);
116
118
  }
117
119
  }
118
120
  if (problems.length) throw refuse(`The run site has broken or out-of-site references: ${problems.slice(0, 8).join('; ')}${problems.length > 8 ? `; and ${problems.length - 8} more` : ''}.`);
@@ -0,0 +1,6 @@
1
+ // Credentialed child only of a real `rer deploy --site`. Its progress is
2
+ // captured by the command store, preserving the public CLI's JSON protocol.
3
+ import { buildSearchArtifacts } from '../modules/site/docs-search/artifacts.mjs';
4
+ const [corpus, assets, output, endpoint, compatibilityDate, domain] = process.argv.slice(2);
5
+ await buildSearchArtifacts({ corpus, assets, output, endpoint, compatibilityDate,
6
+ previousUrl: `https://${domain}/docs-search-vectors.json` }, { accountId: process.env.CLOUDFLARE_ACCOUNT_ID });
@@ -19,6 +19,7 @@ import { dirname, join, resolve, sep } from 'node:path';
19
19
  import { pathToFileURL } from 'node:url';
20
20
  import { buildClients, writeSiteAsset } from './site-client.mjs';
21
21
  import { htmlElements } from './site-markup.mjs';
22
+ import { searchCorpus } from './site-runtime.mjs';
22
23
  import { redactSiteOutput, siteBuildDiagnostic } from './site-diagnostics.mjs';
23
24
  import { ContractError, parseContract } from '../foundation/runtime/seed-contract.mjs';
24
25
 
@@ -64,7 +65,8 @@ try {
64
65
  await writeFile(join(server, 'package.json'), '{"type":"module"}\n');
65
66
  module = await import(pathToFileURL(join(server, chunk.fileName)).href);
66
67
  if (typeof module.sitePages !== 'function') fail(`${entry} must export sitePages(), returning { pages: [{ path, html }], assets: [public paths] }.`);
67
- const clientBuild = await buildClients(vite, root, output, clientJSON ? JSON.parse(clientJSON) : {}), clients = clientBuild.clients;
68
+ const options = clientJSON ? JSON.parse(clientJSON) : {};
69
+ const clientBuild = await buildClients(vite, root, output, options), clients = clientBuild.clients;
68
70
  styles = [...new Set([...styles,...clientBuild.styles])];
69
71
  const build = await module.sitePages({ styles, clients, ...(contract ? { contract } : {}) });
70
72
  if (!Array.isArray(build?.pages) || !Array.isArray(build.assets)) fail('sitePages() returns { pages, assets }.');
@@ -78,6 +80,10 @@ try {
78
80
  await mkdir(dirname(join(output, file)), { recursive: true });
79
81
  await writeFile(join(output, file), page.html);
80
82
  }
83
+ if (options.runtime) {
84
+ const pages = build.pages.map(page => ({...page, ids:new Set(htmlElements(page.html).map(element=>element.attributes.get('id')).filter(Boolean))}));
85
+ await writeFile(options.corpus, JSON.stringify(searchCorpus(pages, build.searchPages)));
86
+ }
81
87
  const publicDirectory = resolve(root, 'public');
82
88
  for (const asset of build.assets) {
83
89
  const source = typeof asset === 'string' && !asset.split('/').some(part => !part || part.startsWith('.')) && inside(publicDirectory, asset);
@@ -0,0 +1,55 @@
1
+ // The only executable site extension: Base's build-coupled docs search.
2
+ import { createHash } from 'node:crypto';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { dirname, join } from 'node:path';
5
+ import { createRequire } from 'node:module';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { invalid } from './errors.mjs';
8
+ import { contained } from './project.mjs';
9
+ import { model, pooling, searchChunks } from '../modules/site/docs-search/index-build.mjs';
10
+
11
+ const digest = bytes => createHash('sha256').update(bytes).digest('hex');
12
+ export function siteRuntime(value) {
13
+ if (value === undefined) return;
14
+ if (!value || Object.keys(value).sort().join() !== 'bindings,corpus,endpoint,module,type' || value.type !== 'docs-search' || value.module !== 'docs-search'
15
+ || JSON.stringify(value.bindings) !== '["ASSETS","AI"]' || value.endpoint !== '/docs/search'
16
+ || !/^\.rer\/(?:[a-z0-9_-]+\/)+corpus\.json$/.test(value.corpus ?? '')) throw invalid('Run site runtime must declare { type: "docs-search", module: "docs-search", bindings: ["ASSETS", "AI"], endpoint: "/docs/search", corpus: ".rer/docs-search/corpus.json" }.');
17
+ return value;
18
+ }
19
+
20
+ /** Rendered sections must point to actual published pages and exact heading ids. */
21
+ export function searchCorpus(pages, searchPages) {
22
+ if (!Array.isArray(searchPages) || !searchPages.length) throw invalid('A docs-search sitePages() must return searchPages from the same render as its pages.');
23
+ const seen = new Set();
24
+ for (const page of searchPages) {
25
+ const published = pages.find(item => item.path === page?.href);
26
+ if (!published || !(page.href === '/docs' || page.href.startsWith('/docs/')) || !Array.isArray(page.searchSections) || seen.has(page.href)) throw invalid('Docs search corpus must name unique published docs pages.');
27
+ seen.add(page.href);
28
+ for (const section of page.searchSections) {
29
+ if (!section || typeof section.anchor !== 'string' || !section.anchor || !Array.isArray(section.titlePath) || !section.titlePath.length
30
+ || !section.titlePath.every(part => typeof part === 'string' && part.trim()) || typeof section.text !== 'string') throw invalid('Invalid docs search heading section.');
31
+ // Parse the rendered tree, not source Markdown or a second crawl.
32
+ if (!published.ids.has(section.anchor)) throw invalid('Docs search heading is absent from its rendered page.');
33
+ }
34
+ }
35
+ return searchPages;
36
+ }
37
+
38
+ export async function buildSiteRuntime(project, declaration, corpus, assets, { prepare = false, domain, compatibilityDate, store, signal } = {}) {
39
+ const pages = JSON.parse(await readFile(corpus, 'utf8'));
40
+ const chunks = searchChunks(pages), corpusHash = digest(chunks.map(chunk => chunk.hash).join('\n'));
41
+ if (prepare) {
42
+ const output = await contained(project.root, dirname(declaration.corpus), { optional: true });
43
+ await store.run('Preparing docs search', process.execPath, [fileURLToPath(new URL('./site-prepare.mjs', import.meta.url)), corpus, assets, output, declaration.endpoint, compatibilityDate, domain], {cwd:project.root, signal, heavy:false});
44
+ }
45
+ const { build } = createRequire(join(project.root, 'package.json'))('esbuild');
46
+ const worker = fileURLToPath(new URL('../modules/site/docs-search/worker.ts', import.meta.url));
47
+ const contract = { endpoint: declaration.endpoint, corpusHash, model, pooling };
48
+ const bundled = await build({ absWorkingDir: dirname(worker), stdin: { contents: `import {createSearchWorker} from ${JSON.stringify(worker)};export default createSearchWorker(${JSON.stringify(contract)});`,
49
+ resolveDir: dirname(worker), sourcefile: 'site-search-entry.ts', loader: 'ts' }, bundle: true, format: 'esm', platform: 'browser', target: 'es2022', write: false });
50
+ const source = bundled.outputFiles[0].text;
51
+ return { type: declaration.type, module: declaration.module, endpoint: declaration.endpoint, bindings: declaration.bindings, model, pooling, corpusHash, source };
52
+ }
53
+
54
+ export const runtimeSummary = runtime => runtime && ({ type: runtime.type, module: runtime.module, endpoint: runtime.endpoint, bindings: runtime.bindings,
55
+ model: runtime.model, pooling: runtime.pooling, corpusHash: runtime.corpusHash, moduleDigest: digest(runtime.source) });
package/cli/site.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { readFile, rename, rm, mkdir } from 'node:fs/promises';
1
+ import { cp, readFile, rename, rm, mkdir } from 'node:fs/promises';
2
2
  import { dirname, join, relative } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { contained } from './project.mjs';
@@ -9,10 +9,11 @@ import { shared } from './shared.mjs';
9
9
  import { unpublishedIdentities } from './site-private.mjs';
10
10
  import { privateSitePaths } from './site-inputs.mjs';
11
11
  import { redactSiteText } from './site-diagnostics.mjs';
12
+ import { siteRuntime, buildSiteRuntime, runtimeSummary } from './site-runtime.mjs';
12
13
 
13
14
  // The run site: a seed's static marketing pages, /run and docs, built from
14
15
  // edition identity with no installation data. A seed opts in with
15
- // commandAdapter's `site: { entry, output, declaration, config? }`: the module
16
+ // commandAdapter's `site: { entry, output, declaration, config?, runtime? }`: the module
16
17
  // whose sitePages({ styles }) returns the pages, the ignored folder the build
17
18
  // writes, the deploy declaration naming the run site's domain, and optionally
18
19
  // the Vite config holding the plugins the site pages need.
@@ -23,6 +24,8 @@ export function declaredSite(project) {
23
24
  if (!site) throw refuse('This checkout declares no run site. A seed opts in with site: { entry, output, declaration } in its command adapter; see SEED-COMMAND-CONTRACT.md.');
24
25
  if (!relativePath(site.entry) || !relativePath(site.output) || !relativePath(site.declaration) || (site.config !== undefined && !relativePath(site.config)) || (site.clientConfig !== undefined && !relativePath(site.clientConfig)) || ['src', 'public', 'node_modules', 'migrations'].some(top => site.output === top || site.output.startsWith(top + '/'))) throw invalid('The declared run site needs relative entries/configs, an output folder outside src, public and node_modules, and a deploy declaration.');
25
26
  if (site.clients !== undefined && (!site.clients || Array.isArray(site.clients) || typeof site.clients !== 'object' || Object.entries(site.clients).some(([name, entry]) => !/^[a-z][a-z0-9-]*$/i.test(name) || !relativePath(entry)))) throw invalid('Run site clients is a map of island names to relative client entry paths.');
27
+ const runtime = siteRuntime(site.runtime);
28
+ if (runtime && (runtime.corpus.startsWith(site.output + '/') || site.output.startsWith(runtime.corpus + '/'))) throw invalid('Search corpus must be outside the published site assets.');
26
29
  return site;
27
30
  }
28
31
 
@@ -46,19 +49,20 @@ async function privateValues(project) {
46
49
  }
47
50
 
48
51
  /** Render the run site into its declared folder, check it and replace the previous build. */
49
- export async function buildSite(project, store, signal) {
52
+ export async function buildSite(project, store, signal, { prepare = false, deployment } = {}) {
50
53
  const site = declaredSite(project);
51
54
  await contained(project.root, site.entry);
52
55
  if (site.config) await contained(project.root, site.config);
53
56
  if (site.clientConfig) await contained(project.root, site.clientConfig);
54
57
  for (const entry of Object.values(site.clients ?? {})) await contained(project.root, entry);
58
+ if (site.runtime) await contained(project.root, site.runtime.corpus, { optional: true });
55
59
  const folder = await contained(project.root, site.output, { optional: true });
56
60
  await mkdir(dirname(folder), { recursive: true });
57
61
  const staging = `${folder}.building-${process.pid}`;
58
62
  await rm(staging, { recursive: true, force: true });
59
63
  try {
60
64
  await mkdir(staging);
61
- try { await store.run('Building the run site', process.execPath, [fileURLToPath(new URL('./site-render.mjs', import.meta.url)), project.root, site.entry, staging, site.config ?? '', JSON.stringify({entries:site.clients ?? {}, config:site.clientConfig, privatePaths:privateSitePaths(project.adapter)})], { cwd: project.root, signal, heavy: false }); }
65
+ try { await store.run('Building the run site', process.execPath, [fileURLToPath(new URL('./site-render.mjs', import.meta.url)), project.root, site.entry, staging, site.config ?? '', JSON.stringify({entries:site.clients ?? {}, config:site.clientConfig, privatePaths:privateSitePaths(project.adapter), ...(site.runtime ? {runtime:site.runtime, corpus:`${staging}.corpus.json`} : {})})], { cwd: project.root, signal, heavy: false }); }
62
66
  catch (error) {
63
67
  const code = await readFile(`${staging}.refusal`, 'utf8').catch(() => '');
64
68
  if (code === 'site_private_input') throw new RerError(code, 'Run site client imports a private installation file or a file outside the seed and its declared dependencies.', 4);
@@ -69,25 +73,40 @@ export async function buildSite(project, store, signal) {
69
73
  if (diagnostic) throw commandFailure(redactSiteText(diagnostic.message), diagnostic);
70
74
  throw error;
71
75
  }
72
- const checked = await checkSite(staging, {root:project.root, ...await privateValues(project)});
76
+ const privacy = await privateValues(project);
77
+ const checkOptions = {root:project.root, ...privacy, ...(site.runtime ? {runtime:site.runtime} : {})};
78
+ let checked = await checkSite(staging, checkOptions);
79
+ let runtime;
80
+ if (site.runtime) {
81
+ try { runtime = await buildSiteRuntime(project, site.runtime, `${staging}.corpus.json`, staging, { prepare, domain:deployment?.domain, compatibilityDate:deployment?.compatibilityDate, store, signal }); }
82
+ catch (error) { if (error instanceof RerError) throw error; throw new RerError('site_search_failed', 'Docs search preparation failed; publication stopped. Check the previous artifact and Workers AI availability.', 1); }
83
+ if (prepare) checked = await checkSite(staging, checkOptions);
84
+ const corpus = await contained(project.root, site.runtime.corpus, {optional:true});
85
+ await mkdir(dirname(corpus), {recursive:true});
86
+ await cp(`${staging}.corpus.json`, corpus);
87
+ }
73
88
  await rm(folder, { recursive: true, force: true });
74
89
  await rename(staging, folder);
75
- return { folder, ...checked };
76
- } finally { await Promise.all([staging, `${staging}.render`, `${staging}.refusal`].map(path => rm(path, { recursive: true, force: true }))); }
90
+ return { folder, ...checked, ...(runtime ? {runtime} : {}) };
91
+ } finally { await Promise.all([staging, `${staging}.render`, `${staging}.refusal`, `${staging}.corpus.json`].map(path => rm(path, { recursive: true, force: true }))); }
77
92
  }
78
93
 
79
- async function siteDeployment(project, options, folder) {
94
+ async function siteDeployment(project, options, folder, runtime) {
80
95
  const site = declaredSite(project), environment = options.environment ?? 'production';
81
96
  const read = async path => { try { return JSON.parse(await readFile(await contained(project.root, path), 'utf8')); } catch (error) { if (error instanceof RerError) throw error; throw invalid(`Malformed ${path}.`); } };
82
97
  const app = await read(project.adapter.deploy?.declaration ?? 'deploy.json'), declaration = await read(site.declaration);
83
98
  const { sitePlan } = await import('../modules/deploy-kit/site.mjs');
84
- try { return sitePlan({ project: app.project, environment, compatibilityDate: app.compatibilityDate, declaration, assets: folder }); }
99
+ try { return sitePlan({ project: app.project, environment, compatibilityDate: app.compatibilityDate, declaration, assets: folder, runtime }); }
85
100
  catch (error) { throw invalid(`The run site deploy declaration is invalid (${error.message}). ${site.declaration} holds {"version": 1, "domain": "<apex hostname>"}.`); }
86
101
  }
87
102
 
88
103
  /** `rer build --site` and `rer deploy --site [--dry-run]`. */
89
104
  export async function siteCommand(project, options, store, signal, out) {
90
- const built = await buildSite(project, store, signal);
105
+ const prepare = options.verb !== 'build' && !options.dryRun;
106
+ if (prepare && declaredSite(project).runtime && ['CLOUDFLARE_ACCOUNT_ID', 'CLOUDFLARE_API_TOKEN'].some(name => !process.env[name]?.trim())) throw missing('CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN are required, with the run site token permissions in the deploy-kit README.');
107
+ const declaration = declaredSite(project);
108
+ const deployment = prepare && declaration.runtime ? await siteDeployment(project, options, '/') : undefined;
109
+ const built = await buildSite(project, store, signal, {prepare, deployment});
91
110
  if (!options.json && built.references.unresolved.length) {
92
111
  out.human(`Run site references: ${built.references.unresolved.length} runtime resource target(s) could not be resolved statically:`);
93
112
  for (const {asset, kind} of built.references.unresolved) out.human(` ${asset}: ${kind}`);
@@ -96,13 +115,23 @@ export async function siteCommand(project, options, store, signal, out) {
96
115
  // Output redaction masks an inherited PWD (a credential-shaped name), so the
97
116
  // checkout-relative folder is named too.
98
117
  const path = relative(project.root, built.folder);
99
- if (!options.json) out.human(`Run site written to ${path} (${built.pages} pages, ${built.files} files): ${built.folder}`);
100
- return { site: { folder: built.folder, path, pages: built.pages, files: built.files, references:built.references } };
118
+ if (!options.json) {
119
+ out.human(`Run site written to ${path} (${built.pages} pages, ${built.files} files): ${built.folder}`);
120
+ if (built.runtime) out.human(` runtime: docs-search; endpoint ${built.runtime.endpoint}; bindings ASSETS, AI; corpus ${built.runtime.corpusHash}; vectors prepared only on a real deploy`);
121
+ }
122
+ return { site: { folder: built.folder, path, pages: built.pages, files: built.files, references:built.references, ...(built.runtime ? {runtime:runtimeSummary(built.runtime)} : {}) } };
101
123
  }
102
- const plan = await siteDeployment(project, options, built.folder);
103
- const human = [`Run site plan: site Worker ${plan.worker}, Base-generated, its only binding the assets (the app's Worker ${plan.appWorker} is not touched)`, ` assets: ${plan.assets} (${built.files} files; HTML ${plan.assetsConfig.html_handling}, not found ${plan.assetsConfig.not_found_handling}; the Worker runs first)`,
124
+ const plan = await siteDeployment(project, options, built.folder, built.runtime);
125
+ const human = [`Run site plan: site Worker ${plan.worker}, Base-generated, ${built.runtime ? 'docs-search runtime with ASSETS and AI' : 'its only binding the assets'} (the app's Worker ${plan.appWorker} is not touched)`, ` assets: ${plan.assets} (${built.files} files; HTML ${plan.assetsConfig.html_handling}, not found ${plan.assetsConfig.not_found_handling}; the Worker runs first)`,
104
126
  ` custom domains: ${plan.hostnames.join(', ')}; workers.dev off`, ...plan.redirects.map(rule => ` redirect in the Worker: ${rule.from} -> ${rule.to} (${rule.status}, keeps ${rule.keeps.join(' and ')})`)];
105
- const summary = { worker: plan.worker, appWorker: plan.appWorker, module: plan.module, bindings: plan.bindings, assets: plan.assets, files: built.files, references:built.references, domain: plan.domain, hostnames: plan.hostnames, workersDev: false, runWorkerFirst: true, assetsConfig: plan.assetsConfig, redirects: plan.redirects.map(({ from, to, status }) => ({ from, to, status })) };
127
+ const { collectFiles } = await import('../modules/deploy-kit/artifact.mjs');
128
+ const { siteFingerprint } = await import('../modules/deploy-kit/site.mjs');
129
+ const files = await collectFiles(built.folder);
130
+ const runtime = runtimeSummary(built.runtime);
131
+ if (runtime) human.push(` runtime: ${runtime.type}; module ${runtime.module}; endpoint ${runtime.endpoint}; bindings ${runtime.bindings.join(', ')}; model ${runtime.model}; pooling ${runtime.pooling}; corpus ${runtime.corpusHash}`);
132
+ const fingerprint = siteFingerprint(plan, files, {preparing:Boolean(runtime) && !prepare});
133
+ if (runtime) human.push(` fingerprint: ${fingerprint}${prepare ? '' : ' (vectors prepared only on a real deploy)'}`);
134
+ const summary = { ...(runtime ? {runtime, fingerprint, vectors:prepare ? 'prepared' : 'prepare-on-deploy'} : {}), worker: plan.worker, appWorker: plan.appWorker, module: plan.module, bindings: plan.bindings, assets: plan.assets, files: built.files, references:built.references, domain: plan.domain, hostnames: plan.hostnames, workersDev: false, runWorkerFirst: true, assetsConfig: plan.assetsConfig, redirects: plan.redirects.map(({ from, to, status }) => ({ from, to, status })) };
106
135
  if (options.dryRun) {
107
136
  if (options.json) out.event('site', summary); else for (const line of human) out.human(line);
108
137
  store.report('deploy --site: dry run complete; no deployment occurred and no provider request was made.');
@@ -112,13 +141,12 @@ export async function siteCommand(project, options, store, signal, out) {
112
141
  if (names.some(name => !process.env[name]?.trim())) throw missing('CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN are required, with the run site token permissions in the deploy-kit README.');
113
142
  if (!options.json) for (const line of human) out.human(line);
114
143
  const { cloudflare } = await import('../modules/deploy-kit/provider.mjs');
115
- const { collectFiles } = await import('../modules/deploy-kit/artifact.mjs');
116
144
  const { siteDeploy, siteReadbackSummary } = await import('../modules/deploy-kit/site.mjs');
117
145
  const environment = options.environment ?? 'production';
118
146
  try {
119
147
  const api = cloudflare({ accountId: process.env.CLOUDFLARE_ACCOUNT_ID, token: process.env.CLOUDFLARE_API_TOKEN });
120
148
  // The receipt is for the person; ownership is read from the provider, so a fresh checkout deploys too.
121
- const result = await siteDeploy({ api, plan, files: await collectFiles(built.folder), receiptPath: join(project.root, '.rer', 'deploy', `site-${environment}.json`) });
149
+ const result = await siteDeploy({ api, plan, files, receiptPath: join(project.root, '.rer', 'deploy', `site-${environment}.json`) });
122
150
  return { dryRun: false, deployed: true, origin: result.origin, site: summary };
123
151
  } catch (error) {
124
152
  if (error instanceof RerError) throw error;
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.75
4
+
5
+ - **Custom-origin owner claims use the recorded app origin (#374).** Native deployment inspection retains the configured public origin from the deployment receipt, so owner claim and status work for custom domains while the ownership guard still refuses a claim at a different origin. Existing workers.dev deployments keep their derived origin.
6
+ - **Run sites can opt into build-coupled docs search (#375).** Site builds prepare the search corpus and runtime, deploys reuse published vectors or generate them through Workers AI, and readback verifies the serving runtime with its exact AI/assets bindings. Search results link to document headings and provider failures refuse publication.
7
+
8
+ ## 0.2.74
9
+
10
+ - **Restores replay more later migrations (#359).** Archive admission and replay accept row-less targets and row-less tables (restored in the destination's definition), RAISE-only guard triggers, statements that read views, and row-preserving CHECK rebuilds, so retained archives from before those migrations restore exactly (Vector: 121 tables / 23 rows; Penny with its settings and clock replayed).
11
+ - **Publication scans share machine-wide slots (#363).** `publish-check` takes 1 of `RER_SCAN_SLOTS` (default 3) slots per machine and waits for one outside its own deadline, so concurrent scans no longer fail on the 300 s timeout under load; `rer release --scan-timeout-seconds <n>` (1-7200) forwards a longer scan deadline. Defaults are unchanged.
12
+ - **Replay schema identity splits migrations like the runner (#370).** Restore placement splits each applied migration the way the installation runner does, so a `--` comment inside a CREATE TABLE no longer makes a same-version restore refuse with `schema_mismatch`.
13
+ - **Publication scan hydration no longer races its own cleanup (#366).** The history refetch runs with `--no-auto-maintenance`, so a detached git GC cannot write into a partial clone's temporary directory while it is removed.
14
+ - **Scheduled policy door hardening (#369).** The run cap counts only a run's own action audit rows (refusals and expiries no longer use it up), a forged `policy_expired` result is recorded as a failure (only the audited sweeper expires runs), a snapshot whose id does not match its policy is refused, expired runs show as 'Expired run', and crash expiry covers every stale running run atomically with its audit row.
15
+
3
16
  ## 0.2.73
4
17
 
5
18
  - **Local dev sessions survive OAuth callbacks (#361).** The dev-gate cookie `rer_dev_gate_<port>` is now SameSite=Lax, like the session cookie it guards, so a provider's top-level redirect back to a local connector callback (Xero, Slack) carries the dev session instead of answering 401. The new `gate.admitsSession` is the dev-session check; `gate.admits` (dev sign-in, personas, one-click /signin) still refuses a cookie-only request marked `Sec-Fetch-Site: cross-site`. Only the dev gate (`rer dev`/`rer demo`) changes; production session cookies keep their SameSite.
@@ -4,6 +4,7 @@ import { createRequire } from 'node:module';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { parseJsonc } from '../../cli/jsonc.mjs';
6
6
  import { portabilityPlan } from './portability-schema.mjs';
7
+ import { migrationStatements } from '../portability/migration-sql.mjs';
7
8
  import { checkBoundary } from './boundary.mjs';
8
9
  import { localDurableObjects } from './durable-objects.mjs';
9
10
  import { readMigrationRewrites, withRewrites } from '../deploy-kit/migrations.mjs';
@@ -75,7 +76,7 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
75
76
  const rewrites = await readMigrationRewrites(root);
76
77
  const inventory = withRewrites(await containerMigrationInventory(root,{config:workerConfig,configFile}),rewrites);
77
78
  const migrations = Object.fromEntries((workerConfig.d1_databases ?? []).map(db => [db.binding,[]]));
78
- for (const {binding,...migration} of inventory) migrations[binding].push({...migration,statements:split(migration.sql)});
79
+ for (const {binding,...migration} of inventory) migrations[binding].push({...migration,statements:migrationStatements(migration.sql,split)});
79
80
  const entry = engine === 'workerd' ? 'dist/server/'+workerConfig.main : 'dist/server/index.mjs';
80
81
  await readFile(join(root,entry));
81
82
  if (engine === 'node' && workerConfig.kv_namespaces?.length) throw new Error('Node container does not support KV');
@@ -181,23 +181,68 @@ A seed's run site (`run-<seed>.com`: its marketing homepage, `/run` and docs, wr
181
181
  The domain is an apex hostname: no scheme, path, port, upper case or `www.`. The plan (`sitePlan`) names:
182
182
 
183
183
  - the Worker `<project>-<environment>--site`. Owner Worker names never contain `--`, so it can never be the installed app's Worker (`<project>-<environment>`), and a site deploy never reads or writes the app Worker or any of its resources;
184
- - its one module, `site-worker.mjs` (`SITE_WORKER`): fixed content Base generates, with no seed code. Its only binding is the assets (`ASSETS`), it runs first on every request (`run_worker_first`), and it has no secrets, no schedules and workers.dev off. A request to `www.<domain>` gets a 301 to `https://<domain>` with path and query kept; every other request is answered from the assets exactly as an assets-only Worker would answer it: the `rer build --site` folder with `html_handling: auto-trailing-slash` (`/run` serves `run.html`) and `not_found_handling: 404-page`;
184
+ - by default its one module, `site-worker.mjs` (`SITE_WORKER`): fixed content Base generates, with no seed code. Its only binding is the assets (`ASSETS`), it runs first on every request (`run_worker_first`), and it has no secrets, no schedules and workers.dev off. A request to `www.<domain>` gets a 301 to `https://<domain>` with path and query kept; every other request is answered from the assets exactly as an assets-only Worker would answer it: the `rer build --site` folder with `html_handling: auto-trailing-slash` (`/run` serves `run.html`) and `not_found_handling: 404-page`;
185
185
  - the apex as a Workers Custom Domain, and `www.<domain>` as a second Custom Domain on the same Worker, so the www host has DNS and a certificate and its requests reach the Worker's redirect.
186
186
 
187
187
  No zone ruleset is read or written. Every request now invokes the Worker: one page view costs one Worker request for the page and one per same-origin file it loads (the default seed's run site: at most 7 per uncached page view).
188
188
 
189
- `rer deploy --site --dry-run` builds the site and prints that plan (`--json`: a `site` event and a result with `dryRun: true`, `deployed: false` and the same `site` object) with no provider request and nothing written, even with `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` set. Without `--dry-run` it needs both inputs. Ownership is read from the provider alone, so a deploy from a fresh checkout (a CI runner with no `.rer/`) recognises the site it deployed before:
189
+ `rer deploy --site --dry-run` builds the site and prints that plan (`--json`: a `site` event and a result with `dryRun: true`, `deployed: false` and the same `site` object) with local build outputs but no provider request or remote write, even with `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` set. Without `--dry-run` it needs both inputs. Ownership is read from the provider alone, so a deploy from a fresh checkout (a CI runner with no `.rer/`) recognises the site it deployed before:
190
190
 
191
191
  - the Worker is the kit's when its latest deployment serves, at 100%, the Worker's newest version, and that version's message annotation is the kit's `rer-site:<fingerprint>` (every site upload sets it);
192
192
  - a Custom Domain is the kit's when its service is the kit's Worker.
193
193
 
194
194
  A read-only preflight reads the zone (it must be in this account, else `site-zone-missing`), the Worker and the zone's Custom Domains, and refuses before any write: `resource-name-collision` for a Worker of the name whose live version the kit did not upload, or for a hostname attached to another service (or to a Worker that is not the kit's); `owned-resource-replaced` for a kit Worker whose latest deployment is not the kit's upload (a dashboard rollback or a split deployment). It then uploads the assets and the site Worker, checks that the new version is live, turns workers.dev off, attaches each missing hostname, and reads the Worker and both domains back. Both post-upload Worker checks share a 90-second upload window: missing visibility or the exact preflight version waits with backoff until the upload response's version serves alone as newest with its expected fingerprint. A foreign version, changed fingerprint or split deployment refuses immediately. A timeout names the last serving/newest versions and fingerprint. A repeat attaches nothing new. `.rer/deploy/site-<environment>.json` receives a receipt for the person; it is never read. Provider propagation cases are tested against the fake Cloudflare API in `tests/site-provider.mjs`, where every zone ruleset path answers 403.
195
195
 
196
+ A seed can opt into docs search through its command adapter's `site.runtime`:
197
+
198
+ ```ts
199
+ runtime: {
200
+ type: 'docs-search', module: 'docs-search', bindings: ['ASSETS', 'AI'],
201
+ endpoint: '/docs/search', corpus: '.rer/docs-search/corpus.json',
202
+ }
203
+ ```
204
+
205
+ This selects Base's docs-search implementation rather than seed JavaScript.
206
+ The site Worker adds the query endpoint and the Workers AI binding; its asset
207
+ handling, www redirect, ownership checks and Custom Domains stay the same.
208
+ No application binding, seed-defined ownership annotation or separate Wrangler
209
+ configuration/deployment is accepted. The domain declaration is unchanged.
210
+ Without `site.runtime`, the assets-only path is unchanged.
211
+
212
+ The renderer produces `pages`, `assets` and
213
+ `searchPages: [{ href, searchSections: [{ anchor, titlePath, text }] }]` from one
214
+ `sitePages` call and writes the latter to the declared staging corpus. Build and
215
+ dry run make no provider or embedding requests. Their plan reports runtime type,
216
+ module, bindings, endpoint, model, pooling, `corpusHash`, module digest and the
217
+ deployment fingerprint; it does not claim vectors exist.
218
+
219
+ Only real deployment prepares vectors. It uses the corpus parent as its local
220
+ preparation/cache directory and always reads the previous published index from
221
+ `https://<site domain>/docs-search-vectors.json`. Model
222
+ `@cf/baai/bge-base-en-v1.5`, pooling `cls` and 768 dimensions are fixed by the
223
+ Base module. Vectors are reused by model, pooling and chunk hash with valid
224
+ matching dimensions. A previous-index 404 permits a first index; other fetch,
225
+ parse or embedding errors stop before any site publication. The same render's
226
+ assets, completed vector index and query module are then uploaded together in
227
+ one site deployment. There is no second render or separate search deployment.
228
+
229
+ The UI source is copied from `modules/site/docs-search` under the seed's chosen
230
+ source path, with `site.clients.docsSearch` naming its `client.ts`. The seed
231
+ renders `SearchField`, imports `search.css`, loads the emitted island module and
232
+ provides `--ink`, `--ink-soft`, `--rule` and `--paper`. The rendered page layout
233
+ and copy stay seed-owned. Local builds have no prepared semantic search service.
234
+
235
+ For CI, the `run-site` environment supplies `CLOUDFLARE_ACCOUNT_ID` from
236
+ `vars.CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` from
237
+ `secrets.CLOUDFLARE_API_TOKEN`. After a frozen install, run the checkout's pinned
238
+ `pnpm exec rer deploy --site`. The guarded template is `export/run-site.yml`.
239
+
196
240
  The token needs, beyond the owner-account permissions above:
197
241
 
198
242
  | Permission | Scope | Used for |
199
243
  | --- | --- | --- |
200
244
  | Workers Scripts: Edit | the account | the site Worker upload, its assets, versions and deployments, workers.dev, and Workers Custom Domains (`/workers/domains`) |
245
+ | Workers AI: Read/Edit | the account, docs-search sites only | preparing embeddings and the runtime AI binding |
201
246
  | Zone: Read | the run site zones | finding the zone by name |
202
247
  | Workers Routes: Edit | the run site zones | Workers Custom Domains, which also create their DNS records and certificates |
203
248
 
@@ -102,7 +102,8 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
102
102
  assert(live && sameDeployment(live, state.receipt.provider), 'owned-resource-replaced');
103
103
  const rows = await api.request(`/workers/scripts/${target.worker}/secrets`);
104
104
  assert(Array.isArray(rows), 'invalid-secret-list');
105
- return {ok:true, origin:target.origin, versionId:live.versionId, retiredSecrets, ownerClaim:state.ownerClaim, liveSecrets:rows.map(row => row.name)};
105
+ // Native uploaders record their configured app origin with the deployment identity.
106
+ return {ok:true, origin:state.receipt.origin ?? target.origin, versionId:live.versionId, retiredSecrets, ownerClaim:state.ownerClaim, liveSecrets:rows.map(row => row.name)};
106
107
  }
107
108
  const current = retiredSecrets.length && Array.isArray(declaration.secrets) ? {...declaration,secrets:declaration.secrets.filter(item => !retiredSecrets.includes(item?.binding))} : declaration;
108
109
  artifact ??= await ownerArtifact(root,values.product);
@@ -1,6 +1,7 @@
1
1
  import { workerSettings } from './owner.mjs';
2
2
  import { readinessAPI } from './readiness-window.mjs';
3
3
  import { assert } from './validation.mjs';
4
+ import { verifySiteRuntime } from './site-runtime.mjs';
4
5
 
5
6
  const ANNOTATION = /^rer-site:[0-9a-f]{64}$/;
6
7
  function refuse(code, worker) { return Object.assign(new Error(code), { resource: `worker:${worker}` }); }
@@ -33,7 +34,7 @@ export async function ownedSiteVersion(api, worker) {
33
34
 
34
35
  /** Only the upload response and the exact preflight version may appear while
35
36
  * Cloudflare's deployment and version reads converge. Never replay the upload. */
36
- export async function waitForSiteUpload({ api, worker, versionId, fingerprint, previous, window }) {
37
+ export async function waitForSiteUpload({ api, worker, versionId, fingerprint, previous, window, runtime, module }) {
37
38
  const bounded = readinessAPI(api, window, 'site-upload-timeout');
38
39
  const annotation = `rer-site:${fingerprint}`;
39
40
  let lastSeen = null, delay = 2000;
@@ -48,7 +49,16 @@ export async function waitForSiteUpload({ api, worker, versionId, fingerprint, p
48
49
  || lastSeen.visible && lastSeen.annotation !== expected
49
50
  || lastSeen.versionId === previous?.versionId && lastSeen.deploymentId !== previous.deploymentId)
50
51
  throw refuse('owned-resource-replaced', worker);
51
- if (lastSeen.current && lastSeen.versionId === versionId && lastSeen.annotation === annotation) return lastSeen;
52
+ if (lastSeen.current && lastSeen.versionId === versionId && lastSeen.annotation === annotation) {
53
+ if (!runtime) return lastSeen;
54
+ try {
55
+ await verifySiteRuntime(bounded, worker, versionId, runtime, module);
56
+ return lastSeen;
57
+ } catch (error) {
58
+ if (window.remaining() <= 0 || error.name === 'TimeoutError') throw timeout(error);
59
+ if (error.status !== 404) throw error;
60
+ }
61
+ }
52
62
  }
53
63
  await window.sleep(Math.min(delay, window.remaining()));
54
64
  delay = Math.min(delay * 2, 10000);
@@ -0,0 +1,33 @@
1
+ import { assert, hash } from './validation.mjs';
2
+
3
+ /** Only the immutable Base docs-search bundle may extend the site Worker. */
4
+ export function siteRuntime(runtime) {
5
+ if (runtime === undefined) return undefined;
6
+ assert(runtime && typeof runtime === 'object' && !Array.isArray(runtime)
7
+ && Object.keys(runtime).sort().join() === 'bindings,corpusHash,endpoint,model,module,pooling,source,type'
8
+ && runtime.type === 'docs-search' && runtime.module === 'docs-search' && runtime.endpoint === '/docs/search'
9
+ && Array.isArray(runtime.bindings) && runtime.bindings.join() === 'ASSETS,AI'
10
+ && typeof runtime.model === 'string' && runtime.model.trim().length > 0 && runtime.pooling === 'cls'
11
+ && typeof runtime.corpusHash === 'string' && /^[a-f0-9]{64}$/.test(runtime.corpusHash)
12
+ && typeof runtime.source === 'string' && runtime.source.length > 0, 'invalid-site-runtime');
13
+ return { ...runtime, bindings: ['ASSETS', 'AI'] };
14
+ }
15
+
16
+ export const siteRuntimeBindings = runtime => [{ type: 'assets', name: 'ASSETS' }, ...(runtime ? [{ type: 'ai', name: 'AI' }] : [])];
17
+
18
+ /** Read the exact version, never Worker-scoped settings or seed annotations.
19
+ * Source equality proves the embedded corpus/model/pooling contract, including
20
+ * its executable implementation, rather than trusting a claimed source digest. */
21
+ export async function verifySiteRuntime(api, worker, versionId, runtime, module) {
22
+ const replaced = () => Object.assign(new Error('owned-resource-replaced'), { resource: `worker:${worker}` });
23
+ const version = await api.request(`/workers/scripts/${worker}/versions/${versionId}`);
24
+ const bindings = version?.resources?.bindings;
25
+ const expected = siteRuntimeBindings(runtime);
26
+ if (version?.id !== versionId || !Array.isArray(bindings) || bindings.length !== expected.length
27
+ || expected.some(binding => bindings.filter(row => row?.name === binding.name && row.type === binding.type).length !== 1)) throw replaced();
28
+ const content = await api.workerContent(worker, versionId);
29
+ const parts = [...content.parts];
30
+ if (content.entry !== module || parts.length !== 1 || parts[0][0] !== module
31
+ || typeof parts[0][1]?.arrayBuffer !== 'function'
32
+ || hash(Buffer.from(await parts[0][1].arrayBuffer())) !== hash(runtime.source)) throw replaced();
33
+ }