create-freeholder 0.2.0-beta.4 → 0.2.0-beta.6

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 (158) hide show
  1. package/dist/template/.changeset/blog-playground-content.md +4 -0
  2. package/dist/template/.changeset/blog-wordpress-structure.md +6 -0
  3. package/dist/template/.changeset/managed-preview-assistant.md +4 -0
  4. package/dist/template/.changeset/native-linux-install.md +6 -0
  5. package/dist/template/.changeset/public-beta-5.md +4 -0
  6. package/dist/template/.changeset/public-beta-6.md +4 -0
  7. package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
  8. package/dist/template/.github/workflows/release-tarballs.yml +117 -0
  9. package/dist/template/AGENTS.md +15 -2
  10. package/dist/template/Dockerfile +3 -0
  11. package/dist/template/MASTER.md +114 -11
  12. package/dist/template/README.md +1 -1
  13. package/dist/template/app/(admin)/admin/assistant/page.tsx +9 -1
  14. package/dist/template/app/(admin)/admin/blog/PostSettings.tsx +26 -0
  15. package/dist/template/app/(admin)/admin/blog/[kind]/page.tsx +53 -0
  16. package/dist/template/app/(admin)/admin/blog/actions.ts +186 -6
  17. package/dist/template/app/(admin)/admin/blog/comments/page.tsx +25 -0
  18. package/dist/template/app/(admin)/admin/blog/page.tsx +21 -5
  19. package/dist/template/app/(admin)/admin/imports/[id]/page.tsx +2 -0
  20. package/dist/template/app/(admin)/admin/pages/[id]/page.tsx +3 -0
  21. package/dist/template/app/(admin)/assistant-actions.ts +13 -6
  22. package/dist/template/app/(public)/[[...slug]]/ReaderComments.tsx +25 -0
  23. package/dist/template/app/(public)/[[...slug]]/blog-parts.tsx +153 -0
  24. package/dist/template/app/(public)/[[...slug]]/comment-actions.ts +16 -0
  25. package/dist/template/app/(public)/[[...slug]]/page.tsx +182 -18
  26. package/dist/template/app/api/chat/assistant/call/route.ts +35 -0
  27. package/dist/template/db/migrations/0061_blog_structure.sql +89 -0
  28. package/dist/template/db/migrations/0062_blog_reader_comments.sql +24 -0
  29. package/dist/template/db/migrations/meta/_journal.json +14 -0
  30. package/dist/template/deploy/README.md +26 -9
  31. package/dist/template/deploy/blog-wordpress-2026-11-07.md +146 -0
  32. package/dist/template/deploy/docker-selfhost/.env.example +11 -1
  33. package/dist/template/deploy/docker-selfhost/README.md +79 -50
  34. package/dist/template/deploy/docker-selfhost/infra/backup.sh +81 -0
  35. package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +37 -1
  36. package/dist/template/deploy/docker-selfhost/infra/compose.yml +37 -1
  37. package/dist/template/deploy/docker-selfhost/migrate.md +8 -5
  38. package/dist/template/deploy/docker-selfhost/recipe.yaml +9 -10
  39. package/dist/template/deploy/docker-selfhost/selfhost.sh +206 -0
  40. package/dist/template/deploy/docker-selfhost/verify.md +11 -4
  41. package/dist/template/deploy/f-criteria-matrix.md +89 -0
  42. package/dist/template/deploy/linux/.env.example +28 -0
  43. package/dist/template/deploy/linux/README.md +181 -0
  44. package/dist/template/deploy/linux/freeholder +655 -0
  45. package/dist/template/deploy/linux/install.sh +173 -0
  46. package/dist/template/deploy/linux/migrate.md +17 -0
  47. package/dist/template/deploy/linux/recipe.yaml +50 -0
  48. package/dist/template/deploy/linux/share/Caddyfile.template +19 -0
  49. package/dist/template/deploy/linux/share/systemd/freeholder-backup.service +13 -0
  50. package/dist/template/deploy/linux/share/systemd/freeholder-backup.timer +12 -0
  51. package/dist/template/deploy/linux/share/systemd/freeholder.service +41 -0
  52. package/dist/template/deploy/linux/verify.md +22 -0
  53. package/dist/template/deploy/managed-preview-assistant.md +99 -0
  54. package/dist/template/eslint.config.mjs +3 -1
  55. package/dist/template/gitignore.template +1 -0
  56. package/dist/template/locales/ar.json +85 -6
  57. package/dist/template/locales/en.json +83 -4
  58. package/dist/template/locales/es.json +83 -4
  59. package/dist/template/locales/fr.json +85 -6
  60. package/dist/template/next.config.ts +2 -0
  61. package/dist/template/package.json +3 -2
  62. package/dist/template/packages/cli/package.json +1 -1
  63. package/dist/template/packages/create-freeholder/package.json +1 -1
  64. package/dist/template/packages/freeholder-app/package.json +1 -1
  65. package/dist/template/packages/mobile-app/package.json +1 -1
  66. package/dist/template/packages/plugin-kit/package.json +1 -1
  67. package/dist/template/packages/sdk/package.json +1 -1
  68. package/dist/template/packages/sdk/src/generated.ts +177 -9
  69. package/dist/template/packages/sdk/src/version.ts +1 -1
  70. package/dist/template/packages/templates/package.json +1 -1
  71. package/dist/template/proxy.ts +18 -1
  72. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/NOTICE.txt +117 -0
  73. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/audio-output-processor.js +267 -0
  74. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.js +847 -0
  75. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.wasm +0 -0
  76. package/dist/template/public/managed-assistant/0.1.10/duplex-codec/encoderWorker.min.js +1 -0
  77. package/dist/template/public/managed-assistant/0.1.10/manifest.json +12 -0
  78. package/dist/template/public/managed-assistant/0.1.10/pm-ai-duplex-client.js +1376 -0
  79. package/dist/template/scripts/build-release.d.mts +4 -0
  80. package/dist/template/scripts/build-release.mjs +171 -0
  81. package/dist/template/scripts/launch-prepare.mjs +6 -3
  82. package/dist/template/scripts/license-headers.mjs +3 -0
  83. package/dist/template/scripts/recipe-matrix.sh +22 -7
  84. package/dist/template/scripts/verify-wordpress-migration.d.mts +8 -0
  85. package/dist/template/scripts/verify-wordpress-migration.mjs +105 -0
  86. package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
  87. package/dist/template/src/adapters/ai/types.ts +5 -0
  88. package/dist/template/src/adapters/paradise/assistant.ts +37 -0
  89. package/dist/template/src/adapters/paradise/http.ts +4 -3
  90. package/dist/template/src/adapters/storage/local-mode.ts +54 -0
  91. package/dist/template/src/adapters/storage/local.ts +53 -26
  92. package/dist/template/src/core/contract/json-schema.ts +8 -0
  93. package/dist/template/src/core/demo/playground-inserts.ts +29 -0
  94. package/dist/template/src/core/demo/playground-policy.ts +9 -0
  95. package/dist/template/src/core/doctor/index.ts +19 -10
  96. package/dist/template/src/core/env.ts +8 -1
  97. package/dist/template/src/core/http/csp.ts +10 -2
  98. package/dist/template/src/core/http/csrf-client.ts +10 -0
  99. package/dist/template/src/core/import/service.ts +217 -12
  100. package/dist/template/src/core/import/wordpress.ts +80 -15
  101. package/dist/template/src/core/notifications/service.ts +1 -0
  102. package/dist/template/src/core/retention/registry.ts +2 -0
  103. package/dist/template/src/core/search/registry.ts +2 -0
  104. package/dist/template/src/core/seo/feeds.ts +2 -0
  105. package/dist/template/src/core/seo/jsonld.ts +46 -2
  106. package/dist/template/src/core/seo/legacy-proxy.ts +53 -0
  107. package/dist/template/src/core/seo/meta.ts +10 -7
  108. package/dist/template/src/core/seo/service.ts +14 -1
  109. package/dist/template/src/core/update/preflight.ts +3 -2
  110. package/dist/template/src/core/update/release-declaration.json +1 -1
  111. package/dist/template/src/core/update/service.ts +7 -17
  112. package/dist/template/src/modules/assistant/contract.ts +1 -1
  113. package/dist/template/src/modules/assistant/limits.ts +3 -0
  114. package/dist/template/src/modules/assistant/preview.ts +124 -0
  115. package/dist/template/src/modules/assistant/provider.ts +7 -0
  116. package/dist/template/src/modules/assistant/service.ts +21 -5
  117. package/dist/template/src/modules/cms/blocks/PreviewAssistantCall.tsx +176 -0
  118. package/dist/template/src/modules/cms/blocks/SiteChatClient.tsx +10 -4
  119. package/dist/template/src/modules/cms/blocks/surfaces.tsx +10 -0
  120. package/dist/template/src/modules/cms/blog-comments-schema.ts +27 -0
  121. package/dist/template/src/modules/cms/blog-comments.ts +111 -0
  122. package/dist/template/src/modules/cms/blog-schema.ts +146 -0
  123. package/dist/template/src/modules/cms/blog-service.ts +999 -0
  124. package/dist/template/src/modules/cms/blog.tsx +245 -25
  125. package/dist/template/src/modules/cms/manifest.ts +7 -1
  126. package/dist/template/src/modules/cms/read.ts +18 -0
  127. package/dist/template/src/modules/cms/service.ts +22 -4
  128. package/dist/template/src/modules/cms/tables.ts +2 -0
  129. package/dist/template/src/modules/seed/launch.ts +31 -3
  130. package/dist/template/tests/browser/blog-structure.spec.ts +69 -0
  131. package/dist/template/tests/core/agent-launch.test.ts +7 -2
  132. package/dist/template/tests/core/analytics-consent.test.ts +1 -1
  133. package/dist/template/tests/core/blog-playground.test.ts +106 -0
  134. package/dist/template/tests/core/blog-structure-comments.test.ts +166 -0
  135. package/dist/template/tests/core/client-readiness-security.test.ts +3 -1
  136. package/dist/template/tests/core/csp.test.ts +1 -1
  137. package/dist/template/tests/core/deploy-recipe.test.ts +54 -4
  138. package/dist/template/tests/core/internal-services.test.ts +4 -0
  139. package/dist/template/tests/core/legacy-redirect-proxy.test.ts +59 -0
  140. package/dist/template/tests/core/linux-install.test.ts +169 -0
  141. package/dist/template/tests/core/local-storage-mode.test.ts +29 -0
  142. package/dist/template/tests/core/locale-routing.test.ts +1 -1
  143. package/dist/template/tests/core/playground-cache.test.ts +1 -1
  144. package/dist/template/tests/core/playground.test.ts +3 -3
  145. package/dist/template/tests/core/preview-assistant-call.test.ts +88 -0
  146. package/dist/template/tests/core/private-preview-webhooks.test.ts +1 -1
  147. package/dist/template/tests/core/private-preview.test.ts +1 -1
  148. package/dist/template/tests/core/proxy-locale.test.ts +1 -1
  149. package/dist/template/tests/core/sdk-schema.test.ts +20 -0
  150. package/dist/template/tests/core/seo.test.ts +1 -1
  151. package/dist/template/tests/core/site-chat-client.test.ts +50 -0
  152. package/dist/template/tests/core/storage.test.ts +38 -2
  153. package/dist/template/tests/core/wordpress-import-flow.test.ts +81 -18
  154. package/dist/template/tests/core/wordpress-import.test.ts +25 -12
  155. package/dist/template/tests/core/wordpress-migration-verification.test.ts +37 -0
  156. package/dist/template/tests/modules/preview-assistant.test.ts +164 -0
  157. package/dist/template-manifest.json +490 -175
  158. package/package.json +1 -1
@@ -0,0 +1,4 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export function releaseArch(arch?: string): "x64" | "arm64";
4
+ export function releaseName(version: string, arch?: string): string;
@@ -0,0 +1,171 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // C3.44: package a built Freeholder as a self-contained Linux release tarball
4
+ // that runs without Docker, Node or pnpm on the server.
5
+ //
6
+ // pnpm build && node scripts/build-release.mjs [--allow-dirty]
7
+ //
8
+ // The tarball holds the Next standalone server, its static assets, the
9
+ // migrations, the official Node runtime (checksum-verified against
10
+ // nodejs.org's SHASUMS256.txt), the `freeholder` operator command and the
11
+ // systemd/Caddy templates the installer writes. It is built for the machine's
12
+ // own architecture, because sharp's native binary in the standalone output is
13
+ // the build host's: linux-x64 on x64 runners, linux-arm64 on arm64 runners.
14
+ //
15
+ // Output in dist/release/: freeholder-<version>-linux-<arch>.tar.gz, its
16
+ // .sha256, and install.sh, which are the release assets the installer
17
+ // downloads.
18
+ import assert from "node:assert/strict";
19
+ import { execFileSync } from "node:child_process";
20
+ import { createHash } from "node:crypto";
21
+ import { chmod, cp, mkdir, readFile, rm, stat, writeFile, mkdtemp, readdir } from "node:fs/promises";
22
+ import { tmpdir } from "node:os";
23
+ import { join, resolve } from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+
26
+ const root = resolve(fileURLToPath(new URL("..", import.meta.url)));
27
+ const allowDirty = process.argv.includes("--allow-dirty");
28
+ const output = resolve(root, "dist", "release");
29
+ const nodeCache = resolve(root, ".tools", "node-runtime");
30
+
31
+ function run(command, args, options = {}) {
32
+ return execFileSync(command, args, { cwd: root, encoding: "utf8", ...options });
33
+ }
34
+ const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
35
+
36
+ export function releaseArch(arch = process.arch) {
37
+ if (arch === "x64") return "x64";
38
+ if (arch === "arm64") return "arm64";
39
+ throw new Error(`Release tarballs are built for x64 and arm64 Linux, not ${arch}.`);
40
+ }
41
+
42
+ export function releaseName(version, arch) {
43
+ if (!/^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/.test(version)) throw new Error(`Not a release version: ${version}`);
44
+ return `freeholder-${version}-linux-${releaseArch(arch)}`;
45
+ }
46
+
47
+ async function download(url) {
48
+ const response = await fetch(url, { redirect: "follow" });
49
+ if (!response.ok) throw new Error(`Download of ${url} failed with HTTP ${response.status}`);
50
+ return Buffer.from(await response.arrayBuffer());
51
+ }
52
+
53
+ /** The official Node binary for this release, verified and cached. */
54
+ async function nodeRuntime(version, arch) {
55
+ const name = `node-v${version}-linux-${arch}`;
56
+ const directory = resolve(nodeCache, name);
57
+ const recordPath = resolve(directory, "SOURCE.json");
58
+ try {
59
+ const record = JSON.parse(await readFile(recordPath, "utf8"));
60
+ assert.equal(record.archive, `${name}.tar.xz`);
61
+ assert.equal(record.binarySha256, sha256(await readFile(resolve(directory, "bin", "node"))));
62
+ return { directory, record };
63
+ } catch {
64
+ await rm(directory, { recursive: true, force: true });
65
+ await mkdir(nodeCache, { recursive: true });
66
+ }
67
+ const base = `https://nodejs.org/dist/v${version}`;
68
+ const archiveName = `${name}.tar.xz`;
69
+ const [archive, sums] = await Promise.all([download(`${base}/${archiveName}`), download(`${base}/SHASUMS256.txt`)]);
70
+ const line = sums.toString("utf8").split(/\r?\n/).find((entry) => entry.endsWith(` ${archiveName}`));
71
+ if (!line) throw new Error(`nodejs.org lists no checksum for ${archiveName}`);
72
+ const expected = line.split(/\s+/)[0];
73
+ assert.equal(sha256(archive), expected, "Node runtime checksum mismatch");
74
+ const temporary = await mkdtemp(join(tmpdir(), "freeholder-node-"));
75
+ try {
76
+ const archivePath = join(temporary, archiveName);
77
+ await writeFile(archivePath, archive);
78
+ run("tar", ["-xJf", archivePath, "-C", nodeCache, `${name}/bin/node`, `${name}/LICENSE`]);
79
+ } finally {
80
+ await rm(temporary, { recursive: true, force: true });
81
+ }
82
+ const record = {
83
+ version,
84
+ archive: archiveName,
85
+ archiveSha256: expected,
86
+ binarySha256: sha256(await readFile(resolve(directory, "bin", "node"))),
87
+ source: `${base}/${archiveName}`,
88
+ };
89
+ await writeFile(recordPath, `${JSON.stringify(record, null, 2)}\n`);
90
+ return { directory, record };
91
+ }
92
+
93
+ async function exists(path) {
94
+ return stat(path).then(() => true, () => false);
95
+ }
96
+
97
+ async function main() {
98
+ if (process.platform !== "linux") throw new Error("Build Linux release tarballs on Linux.");
99
+ const arch = releaseArch();
100
+ const dirty = run("git", ["status", "--porcelain"]).trim().length > 0;
101
+ if (dirty && !allowDirty) throw new Error("Refusing to package a dirty tree; commit first or pass --allow-dirty for a local test build.");
102
+ const pkg = JSON.parse(await readFile(resolve(root, "package.json"), "utf8"));
103
+ const version = pkg.version;
104
+ const commit = run("git", ["rev-parse", "HEAD"]).trim();
105
+ const nodeVersion = (await readFile(resolve(root, ".node-version"), "utf8")).trim();
106
+ const standalone = resolve(root, ".next", "standalone");
107
+ if (!(await exists(resolve(standalone, "server.js")))) throw new Error("Run pnpm build first: .next/standalone/server.js is missing.");
108
+ // sharp ships a per-architecture binary; a tarball carrying another
109
+ // machine's would fail on the first image upload, not at install.
110
+ const pnpmStore = await readdir(resolve(standalone, "node_modules", ".pnpm")).catch(() => []);
111
+ if (pnpmStore.some((entry) => entry.startsWith("sharp@")) && !pnpmStore.some((entry) => entry.startsWith(`@img+sharp-linux-${arch}@`))) {
112
+ throw new Error(`The standalone output has no sharp binary for linux-${arch}; build on a linux-${arch} machine.`);
113
+ }
114
+
115
+ const name = releaseName(version, arch);
116
+ const stage = resolve(output, name);
117
+ await rm(stage, { recursive: true, force: true });
118
+ await mkdir(resolve(stage, "app", ".next"), { recursive: true });
119
+ // The same files the Docker runtime stage copies (Dockerfile).
120
+ await cp(standalone, resolve(stage, "app"), { recursive: true, verbatimSymlinks: true });
121
+ await cp(resolve(root, ".next", "static"), resolve(stage, "app", ".next", "static"), { recursive: true });
122
+ await cp(resolve(root, "public"), resolve(stage, "app", "public"), { recursive: true });
123
+ await cp(resolve(root, "db"), resolve(stage, "app", "db"), { recursive: true });
124
+ await mkdir(resolve(stage, "app", "scripts"), { recursive: true });
125
+ await cp(resolve(root, "scripts", "owner-password.mjs"), resolve(stage, "app", "scripts", "owner-password.mjs"));
126
+ // Next writes its runtime cache here. The installer points it at a
127
+ // directory the service may write, so the release itself stays read-only.
128
+ await rm(resolve(stage, "app", ".next", "cache"), { recursive: true, force: true });
129
+
130
+ const runtime = await nodeRuntime(nodeVersion, arch);
131
+ await mkdir(resolve(stage, "runtime", "node", "bin"), { recursive: true });
132
+ await cp(resolve(runtime.directory, "bin", "node"), resolve(stage, "runtime", "node", "bin", "node"));
133
+ await cp(resolve(runtime.directory, "LICENSE"), resolve(stage, "runtime", "node", "LICENSE"));
134
+
135
+ await mkdir(resolve(stage, "bin"), { recursive: true });
136
+ await cp(resolve(root, "deploy", "linux", "freeholder"), resolve(stage, "bin", "freeholder"));
137
+ await chmod(resolve(stage, "bin", "freeholder"), 0o755);
138
+ await cp(resolve(root, "deploy", "linux", "share"), resolve(stage, "share"), { recursive: true });
139
+ await cp(resolve(root, "deploy", "linux", "install.sh"), resolve(stage, "share", "install.sh"));
140
+ await cp(resolve(root, "LICENSE"), resolve(stage, "LICENSE"));
141
+ await cp(resolve(root, "NOTICE"), resolve(stage, "NOTICE"));
142
+
143
+ const release = {
144
+ schema: "freeholder/linux-release/v1",
145
+ version,
146
+ commit,
147
+ platform: `linux-${arch}`,
148
+ node: { version: nodeVersion, source: runtime.record.source, archiveSha256: runtime.record.archiveSha256 },
149
+ };
150
+ await writeFile(resolve(stage, "RELEASE.json"), `${JSON.stringify(release, null, 2)}\n`);
151
+ await writeFile(resolve(stage, "VERSION"), `${version}\n`);
152
+
153
+ const tarball = resolve(output, `${name}.tar.gz`);
154
+ // Root-owned, sorted and dated by the commit so two builds of one commit
155
+ // differ only where the toolchain does.
156
+ const date = run("git", ["show", "-s", "--format=%cI", "HEAD"]).trim();
157
+ run("tar", ["--sort=name", `--mtime=${date}`, "--owner=0", "--group=0", "--numeric-owner", "-czf", tarball, "-C", output, name]);
158
+ const digest = sha256(await readFile(tarball));
159
+ await writeFile(`${tarball}.sha256`, `${digest} ${name}.tar.gz\n`);
160
+ await cp(resolve(root, "deploy", "linux", "install.sh"), resolve(output, "install.sh"));
161
+ await rm(stage, { recursive: true, force: true });
162
+ const bytes = (await stat(tarball)).size;
163
+ console.log(`release: ${name}.tar.gz (${(bytes / 1048576).toFixed(1)} MB) sha256 ${digest}`);
164
+ }
165
+
166
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
167
+ main().catch((error) => {
168
+ console.error(error instanceof Error ? error.message : String(error));
169
+ process.exitCode = 1;
170
+ });
171
+ }
@@ -55,7 +55,10 @@ export async function prepareLaunch({ directory = process.cwd(), target = "repli
55
55
  const inferred = target === "replit" && environment.REPLIT_DOMAINS ? `https://${environment.REPLIT_DOMAINS.split(",")[0]}` : undefined;
56
56
  const siteOrigin = publicOrigin(url ?? values.APP_URL ?? inferred ?? "http://localhost:3000");
57
57
  values.APP_URL = siteOrigin;
58
- values.FREEHOLDER_STORAGE = target === "replit" ? "replit" : "s3";
58
+ // C3.44: Docker keeps media on the recipe's volume unless the owner chose
59
+ // S3 (FREEHOLDER_STORAGE=s3 or an S3 bucket supplied).
60
+ const s3Chosen = values.FREEHOLDER_STORAGE === "s3" || Boolean(values.S3_BUCKET);
61
+ values.FREEHOLDER_STORAGE = target === "replit" ? "replit" : s3Chosen ? "s3" : "local";
59
62
  values.FREEHOLDER_SEED_DEMO ??= "0";
60
63
  const publicHttps = new URL(siteOrigin).protocol === "https:";
61
64
  // The HTTPS Compose file's Caddy requests a certificate for this name.
@@ -73,7 +76,7 @@ export async function prepareLaunch({ directory = process.cwd(), target = "repli
73
76
  const claimPath = join(privateDirectory, "claim-link.txt"); await regularFile(claimPath);
74
77
  await writeFile(claimPath, `${siteOrigin}/setup#claim=${encodeURIComponent(values.BOOTSTRAP_SECRET)}\n`, { mode: 0o600 }); await chmod(claimPath, 0o600);
75
78
  // Compose runs PostgreSQL and builds DATABASE_URL from POSTGRES_PASSWORD itself.
76
- const required = target === "replit" ? ["DATABASE_URL", "REPLIT_BUCKET_ID"] : ["S3_ENDPOINT", "S3_REGION", "S3_BUCKET", "S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"];
79
+ const required = target === "replit" ? ["DATABASE_URL", "REPLIT_BUCKET_ID"] : values.FREEHOLDER_STORAGE === "s3" ? ["S3_ENDPOINT", "S3_REGION", "S3_BUCKET", "S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"] : [];
77
80
  const composeFile = `deploy/docker-selfhost/infra/${publicHttps ? "compose.https.yml" : "compose.yml"}`;
78
81
  const startCommand = recipeStat ? `docker compose --env-file deploy/docker-selfhost/.env -f ${composeFile} up -d` : undefined;
79
82
  const missing = required.filter(name => !values[name]);
@@ -83,7 +86,7 @@ export async function prepareLaunch({ directory = process.cwd(), target = "repli
83
86
  ...(docker && startCommand ? { composeFile, startCommand } : {}),
84
87
  setupUrl: `${siteOrigin}/setup`, mcpUrl: `${siteOrigin}/api/mcp`,
85
88
  next: target === "replit" ? ["Provision Replit PostgreSQL and Object Storage using Replit Agent.", "Import the private .env into Replit Secrets; preserve these same secrets in the Deployment.", "Set APP_URL to the published HTTPS URL and rerun preparation with --url.", "Run pnpm start:replit for development; publish using the checked-in Deployment configuration.", "Open the private claim link yourself, create a passkey, and connect your assistant in /admin/connect."] : [
86
- "Create a private S3-compatible bucket and a key scoped to it, and put the S3 values in the private .env. Compose runs PostgreSQL itself.",
89
+ values.FREEHOLDER_STORAGE === "s3" ? "Put the S3 bucket values in the private .env. Compose runs PostgreSQL itself." : "Media stays on the recipe's Docker volume and is in the nightly backup; for S3 instead, set FREEHOLDER_STORAGE=s3 and the S3_* values and rerun. Compose runs PostgreSQL itself.",
87
90
  publicHttps ? `Point ${new URL(siteOrigin).hostname}'s DNS A record at this server and open ports 80 and 443; Caddy obtains the certificate itself.` : "This serves plain HTTP for local use. For a public site, rerun with --url https://YOUR-DOMAIN to use the HTTPS Compose file; passkeys need HTTPS.",
88
91
  startCommand ? `Start it from the repository root: ${startCommand}` : "Start it with deploy/docker-selfhost/README.md.",
89
92
  "Open the private claim link yourself, create a passkey, and issue your assistant's key in /admin/connect.",
@@ -21,6 +21,9 @@ const fix = process.argv.includes("--fix");
21
21
  // rewrites migrations wholesale, and any dependency change rewrites the
22
22
  // lockfile. JSON has no comment syntax at all.
23
23
  const EXEMPT = [
24
+ // Redistributed, byte-pinned Opus/MIT/BSD codecs. Their original licenses
25
+ // live beside them in NOTICE.txt; never relabel these as Freeholder code.
26
+ /^public\/managed-assistant\/0\.1\.10\/duplex-codec\//,
24
27
  /^db\/migrations\//,
25
28
  /\.json$/,
26
29
  /^next-env\.d\.ts$/,
@@ -26,6 +26,27 @@ for target in "${TARGETS[@]}"; do
26
26
  psql -h "$PGHOST" -U "$PGUSER" -d postgres -c "drop database if exists ${database}" >/dev/null
27
27
  psql -h "$PGHOST" -U "$PGUSER" -d postgres -c "create database ${database}" >/dev/null
28
28
 
29
+ # C3.44: docker-selfhost's default keeps media on a named volume at
30
+ # /var/lib/freeholder/media, so boot that target the way its Compose file
31
+ # does. Doctor's storage round trip then proves the image's volume mount
32
+ # point is writable and the production local-disk mode starts.
33
+ storage=(
34
+ -e FREEHOLDER_STORAGE=s3
35
+ -e S3_ENDPOINT=http://127.0.0.1:9000
36
+ -e S3_REGION=us-east-1
37
+ -e S3_BUCKET=freeholder-recipe-gate
38
+ -e S3_ACCESS_KEY_ID=freeholder-ci
39
+ -e S3_SECRET_ACCESS_KEY=freeholder-ci-secret
40
+ -e S3_ADDRESSING_STYLE=path
41
+ )
42
+ if [ "$target" = "docker-selfhost" ]; then
43
+ docker volume rm -f freeholder-recipe-gate-media >/dev/null 2>&1 || true
44
+ storage=(
45
+ -e FREEHOLDER_STORAGE=local
46
+ -e LOCAL_STORAGE_ROOT=/var/lib/freeholder/media
47
+ -v freeholder-recipe-gate-media:/var/lib/freeholder/media
48
+ )
49
+ fi
29
50
  docker run -d --name freeholder-recipe-gate --network host \
30
51
  -e PORT="$PORT" \
31
52
  -e NODE_ENV=production \
@@ -35,13 +56,7 @@ for target in "${TARGETS[@]}"; do
35
56
  -e CREDENTIAL_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= \
36
57
  -e DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:5432/${database}" \
37
58
  -e FREEHOLDER_SEED_DEMO=1 \
38
- -e FREEHOLDER_STORAGE=s3 \
39
- -e S3_ENDPOINT=http://127.0.0.1:9000 \
40
- -e S3_REGION=us-east-1 \
41
- -e S3_BUCKET=freeholder-recipe-gate \
42
- -e S3_ACCESS_KEY_ID=freeholder-ci \
43
- -e S3_SECRET_ACCESS_KEY=freeholder-ci-secret \
44
- -e S3_ADDRESSING_STYLE=path \
59
+ "${storage[@]}" \
45
60
  -e FREEHOLDER_RECIPE_TARGET="$target" \
46
61
  "$IMAGE" >/dev/null
47
62
 
@@ -0,0 +1,8 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export interface HtmlMetadata { title: string; canonical: string; description: string; robots: string; ogTitle: string; ogDescription: string; ogImage: string; hreflang: Record<string, string> }
4
+ export interface MigrationCheck { sourceUrl: string; requestPath: string; destinationPath: string; redirect: boolean; expected: Record<string, unknown> }
5
+ export interface MigrationPlan { sourceOrigin: string; status: string; warnings: string[]; checks: MigrationCheck[] }
6
+ export interface MigrationReport { verifiedAt: string; destinationOrigin: string; status: string; accepted: boolean; unresolved: string[]; rows: Array<MigrationCheck & { errors: string[]; warnings: string[]; sourceMeta?: HtmlMetadata; destinationMeta?: HtmlMetadata }> }
7
+ export function htmlMetadata(html: string): HtmlMetadata;
8
+ export function verifyMigration(plan: MigrationPlan, destinationOrigin: string): Promise<MigrationReport>;
@@ -0,0 +1,105 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Read-only acceptance: export imports.wordpressVerificationPlan to JSON, then
4
+ // compare the source crawl and the destination over real HTTP before cutover.
5
+ import { readFile, writeFile } from "node:fs/promises";
6
+ import { pathToFileURL } from "node:url";
7
+ import { parse } from "parse5";
8
+
9
+ export function htmlMetadata(html) {
10
+ const result = { title: "", canonical: "", description: "", robots: "", ogTitle: "", ogDescription: "", ogImage: "", hreflang: {} };
11
+ const text = node => node.nodeName === "#text" ? node.value : (node.childNodes ?? []).map(text).join("");
12
+ const visit = node => {
13
+ const attrs = Object.fromEntries((node.attrs ?? []).map(attr => [attr.name, attr.value]));
14
+ if (node.tagName === "title") result.title = text(node).trim();
15
+ if (node.tagName === "link" && attrs.rel?.split(/\s+/).includes("canonical")) result.canonical = attrs.href ?? "";
16
+ if (node.tagName === "link" && attrs.rel?.split(/\s+/).includes("alternate") && attrs.hreflang) result.hreflang[attrs.hreflang] = attrs.href ?? "";
17
+ if (node.tagName === "meta") {
18
+ const key = { description: "description", robots: "robots", "og:title": "ogTitle", "og:description": "ogDescription", "og:image": "ogImage" }[attrs.name ?? attrs.property];
19
+ if (key) result[key] = attrs.content ?? "";
20
+ }
21
+ for (const child of node.childNodes ?? []) visit(child);
22
+ };
23
+ visit(parse(html)); return result;
24
+ }
25
+
26
+ async function read(url) {
27
+ const response = await fetch(url, { redirect: "manual", signal: AbortSignal.timeout(15000), headers: { "user-agent": "Freeholder-Migration-Verification/1.0" } });
28
+ return { status: response.status, location: response.headers.get("location"), type: response.headers.get("content-type") ?? "", body: await response.text() };
29
+ }
30
+
31
+ export async function verifyMigration(plan, destinationOrigin) {
32
+ const origin = new URL(destinationOrigin);
33
+ if (!["http:", "https:"].includes(origin.protocol) || origin.username || origin.password) throw new Error("Use an HTTP(S) destination without credentials.");
34
+ const source = new URL(plan.sourceOrigin);
35
+ if (!["http:", "https:"].includes(source.protocol) || source.username || source.password) throw new Error("Use an HTTP(S) source without credentials.");
36
+ const sourceMap = new Map(plan.checks.map(check => { const url = new URL(check.sourceUrl); return [`${url.pathname.replace(/\/+$/, "") || "/"}${url.search}`, check.destinationPath]; }));
37
+ const normalize = value => {
38
+ const parsed = new URL(value, origin);
39
+ if (parsed.origin === source.origin) {
40
+ const mapped = sourceMap.get(`${parsed.pathname.replace(/\/+$/, "") || "/"}${parsed.search}`);
41
+ if (mapped) { const destination = new URL(mapped, origin); parsed.pathname = destination.pathname; parsed.search = destination.search; }
42
+ parsed.host = origin.host; parsed.protocol = origin.protocol;
43
+ }
44
+ parsed.pathname = parsed.pathname.replace(/\/+$/, "") || "/";
45
+ parsed.searchParams.sort(); return parsed.href;
46
+ };
47
+ const rows = [];
48
+ for (const check of plan.checks) {
49
+ const request = new URL(check.requestPath, origin);
50
+ const wanted = new URL(check.destinationPath, origin);
51
+ if (request.origin !== origin.origin || wanted.origin !== origin.origin) throw new Error("A destination path escaped the configured origin.");
52
+ const errors = [], warnings = [];
53
+ let response, sourceMeta, destinationMeta;
54
+ try {
55
+ response = await read(request);
56
+ if (check.redirect && response.status !== 301) errors.push(`Expected one 301, received ${response.status}.`);
57
+ if (response.status >= 300 && response.status < 400) {
58
+ const target = new URL(response.location ?? "", request);
59
+ if (normalize(target) !== normalize(wanted)) errors.push(`Unexpected redirect target: ${target.href}`);
60
+ if (target.origin !== origin.origin) throw new Error("Redirect escaped the destination origin.");
61
+ response = await read(target);
62
+ }
63
+ if (response.status !== 200) errors.push(`Final response was ${response.status}; required 200 after at most one redirect.`);
64
+ if (response.type.includes("text/html")) {
65
+ destinationMeta = htmlMetadata(response.body);
66
+ const expected = check.expected ?? {};
67
+ for (const key of ["title", "description", "ogTitle", "ogDescription"]) if (expected[key] && destinationMeta[key] !== expected[key]) errors.push(`${key} differs from the imported value.`);
68
+ const canonical = expected.canonical ? new URL(expected.canonical, origin) : wanted;
69
+ if (!destinationMeta.canonical || normalize(destinationMeta.canonical) !== normalize(canonical)) errors.push("Canonical differs from the intended destination.");
70
+ if (expected.noindex && !/\bnoindex\b/i.test(destinationMeta.robots)) errors.push("Imported noindex was lost.");
71
+ if (expected.nofollow && !/\bnofollow\b/i.test(destinationMeta.robots)) errors.push("Imported nofollow was lost.");
72
+ if (!check.redirect) {
73
+ try {
74
+ if (new URL(check.sourceUrl).origin !== source.origin) throw new Error("Source URL is outside the configured source origin.");
75
+ let old = await read(check.sourceUrl);
76
+ if (old.status >= 300 && old.status < 400 && old.location) {
77
+ const next = new URL(old.location, check.sourceUrl);
78
+ if (next.origin === source.origin) old = await read(next);
79
+ }
80
+ if (old.status !== 200 || !old.type.includes("text/html")) warnings.push(`Source metadata unavailable (${old.status}).`);
81
+ else {
82
+ sourceMeta = htmlMetadata(old.body);
83
+ for (const key of ["title", "description", "ogTitle", "ogDescription"]) if (sourceMeta[key] && sourceMeta[key] !== destinationMeta[key]) errors.push(`${key} changed from the rendered source.`);
84
+ if (sourceMeta.canonical && normalize(new URL(sourceMeta.canonical, source)) !== normalize(destinationMeta.canonical)) errors.push("Canonical changed from the rendered source.");
85
+ for (const directive of ["noindex", "nofollow"]) if (new RegExp(`\\b${directive}\\b`, "i").test(sourceMeta.robots) !== new RegExp(`\\b${directive}\\b`, "i").test(destinationMeta.robots)) errors.push(`${directive} changed from the source.`);
86
+ for (const [locale, href] of Object.entries(sourceMeta.hreflang)) if (!destinationMeta.hreflang[locale] || normalize(href) !== normalize(destinationMeta.hreflang[locale])) errors.push(`hreflang ${locale} changed or disappeared.`);
87
+ if (sourceMeta.ogImage && !destinationMeta.ogImage) errors.push("Open Graph image disappeared.");
88
+ }
89
+ } catch (error) { warnings.push(`Source comparison unavailable: ${error.message}`); }
90
+ }
91
+ }
92
+ } catch (error) { errors.push(error.message); }
93
+ rows.push({ ...check, errors, warnings, sourceMeta, destinationMeta });
94
+ }
95
+ return { verifiedAt: new Date().toISOString(), destinationOrigin: origin.origin, status: plan.status, accepted: plan.status === "published" && !plan.warnings.length && rows.every(row => !row.errors.length && !row.warnings.length), unresolved: plan.warnings, rows };
96
+ }
97
+
98
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
99
+ const [planPath, destination, outputPath] = process.argv.slice(2);
100
+ if (!planPath || !destination || !outputPath) throw new Error("Usage: node scripts/verify-wordpress-migration.mjs PLAN.json https://destination.example REPORT.json");
101
+ const report = await verifyMigration(JSON.parse(await readFile(planPath, "utf8")), destination);
102
+ await writeFile(outputPath, JSON.stringify(report, null, 2) + "\n");
103
+ console.log(`${report.rows.length} URL checks; ${report.rows.filter(row => row.errors.length).length} failed; ${report.unresolved.length} unresolved source features. Report: ${outputPath}`);
104
+ if (!report.accepted) process.exitCode = 1;
105
+ }
@@ -5,7 +5,7 @@ independent security sign-off. Three adversarial agents reviewed separate
5
5
  customer, security and platform worktrees based on main
6
6
  `4ba5daac5eeea6a2202b1b3972defed13cb325a1`; the integrating agent reviewed
7
7
  public CMS delivery and editor concurrency. C11.10 remains unchecked, and
8
- Freeholder remains `0.2.0-beta.4` in active development.
8
+ Freeholder remains `0.2.0-beta.6` in active development.
9
9
 
10
10
  ## Findings and repairs
11
11
 
@@ -11,6 +11,9 @@ export interface AiGenerationRequest {
11
11
  maxOutputTokens: number;
12
12
  responseSchema?: Record<string, unknown>;
13
13
  idempotencyKey: string;
14
+ /** Server-derived visitor binding and a reservation held by the consumer. */
15
+ visitorRef?: string;
16
+ maxChargeCents?: number;
14
17
  }
15
18
 
16
19
  export interface AiGenerationResult {
@@ -19,6 +22,8 @@ export interface AiGenerationResult {
19
22
  provider: string;
20
23
  model: string;
21
24
  usage: { inputTokens: number; outputTokens: number; totalTokens: number };
25
+ /** A managed adapter's authoritative list-price receipt, already bounded at admission. */
26
+ meteredCents?: number;
22
27
  }
23
28
 
24
29
  export interface AiAdapter {
@@ -0,0 +1,37 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Managed text uses the same transcript, guardrails and audited turn as other
4
+ // assistant providers. PM owns the quote, allowance, exact talent and SFW rules.
5
+ import type { AiAdapter } from "@/adapters/ai/types";
6
+ import { paradiseRequest } from "./http";
7
+
8
+ export function createParadiseAssistantAi(): AiAdapter {
9
+ return {
10
+ id: "paradise-assistant",
11
+ status: { family: "ai", id: "paradise-assistant", available: true, message: "Managed site assistant" },
12
+ async generate(request) {
13
+ if (!request.visitorRef || !request.maxChargeCents || request.purpose !== "site-assistant") {
14
+ throw new Error("The managed assistant requires a visitor and a reserved budget.");
15
+ }
16
+ const result = await paradiseRequest<{
17
+ text: string; model: string; metered_list_usd: number; content_mode: string;
18
+ }>("/v1/ai/assistant/text", { body: {
19
+ visitor_ref: request.visitorRef,
20
+ request_id: request.idempotencyKey,
21
+ system: request.system,
22
+ input: request.input,
23
+ max_output_tokens: Math.min(600, request.maxOutputTokens),
24
+ max_charge_usd: request.maxChargeCents / 100,
25
+ }, timeoutMs: 45000 });
26
+ const reply = result.body;
27
+ if (typeof reply.text !== "string" || !reply.text.trim() || reply.content_mode !== "sfw"
28
+ || !Number.isFinite(reply.metered_list_usd) || reply.metered_list_usd < 0
29
+ || reply.metered_list_usd > request.maxChargeCents / 100 + 1e-9) {
30
+ throw new Error("The managed assistant did not return a valid billing receipt.");
31
+ }
32
+ return { text: reply.text, provider: "paradise", model: reply.model,
33
+ usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
34
+ meteredCents: Math.ceil(reply.metered_list_usd * 100) };
35
+ },
36
+ };
37
+ }
@@ -141,7 +141,7 @@ function machineCode(body: unknown): string | undefined {
141
141
  */
142
142
  export async function paradiseRequest<T>(
143
143
  path: string,
144
- init: { method?: "GET" | "POST"; body?: unknown; timeoutMs?: number } = {},
144
+ init: { method?: "GET" | "POST" | "PATCH"; body?: unknown; timeoutMs?: number; query?: Record<string, string> } = {},
145
145
  ): Promise<ParadiseResponse<T>> {
146
146
  if (playgroundBlocksExternalDelivery(env())) {
147
147
  // Matches mail, SMS and webhooks: a public playground fails closed.
@@ -156,10 +156,11 @@ export async function paradiseRequest<T>(
156
156
  if (!site.apiKey) {
157
157
  throw new ParadiseRequestError("PARADISEMODERN_API_KEY is not set.", 0, false, "not_configured");
158
158
  }
159
- const url = paradiseUrl(site.baseUrl, path);
159
+ const url = new URL(paradiseUrl(site.baseUrl, path));
160
+ for (const [key, value] of Object.entries(init.query ?? {})) url.searchParams.set(key, value);
160
161
  let response: Response;
161
162
  try {
162
- response = await (fetchOverride ?? fetch)(url, {
163
+ response = await (fetchOverride ?? fetch)(url.href, {
163
164
  method: init.method ?? "POST",
164
165
  headers: {
165
166
  accept: "application/json",
@@ -0,0 +1,54 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // C3.44: when local-disk media is allowed, decided in one place. The storage
4
+ // adapter, Doctor, the update screen and update preflight all ask this module,
5
+ // so they cannot disagree about whether an instance's uploads are safe.
6
+ //
7
+ // The mistake §18 guards against is media written to somewhere that a rebuild
8
+ // throws away: a container's writable layer, or a relative directory inside
9
+ // the release that an update replaces. A single-server install that names an
10
+ // absolute directory it keeps across updates and includes in its nightly
11
+ // backup (the native installer's /var/lib/freeholder/media, or the Docker
12
+ // recipe's named volume) is not that mistake, so it is a supported mode.
13
+
14
+ import { isAbsolute } from "node:path";
15
+
16
+ export type LocalStorageMode =
17
+ /** Not production: local disk is the development default. */
18
+ | "development"
19
+ /** Production with an explicit absolute directory the operator keeps. */
20
+ | "persistent"
21
+ /** Production on an implicit directory, accepted only by the legacy override. */
22
+ | "unsafe"
23
+ /** Production on an implicit directory, refused. */
24
+ | "refused";
25
+
26
+ export interface LocalStorageEnvironment {
27
+ NODE_ENV: string;
28
+ LOCAL_STORAGE_ROOT?: string;
29
+ FREEHOLDER_UNSAFE_LOCAL_STORAGE?: string;
30
+ }
31
+
32
+ export function localStorageMode(e: LocalStorageEnvironment): LocalStorageMode {
33
+ if (e.NODE_ENV !== "production") return "development";
34
+ // The legacy override keeps its exact meaning, including creating the
35
+ // directory on demand: the hourly playground runs on a tmpfs /tmp/media
36
+ // that is deliberately disposable.
37
+ if (e.FREEHOLDER_UNSAFE_LOCAL_STORAGE === "1") return "unsafe";
38
+ if (e.LOCAL_STORAGE_ROOT && isAbsolute(e.LOCAL_STORAGE_ROOT)) return "persistent";
39
+ return "refused";
40
+ }
41
+
42
+ /** One sentence for Doctor and the update screen. */
43
+ export function describeLocalStorage(e: LocalStorageEnvironment): string {
44
+ switch (localStorageMode(e)) {
45
+ case "development":
46
+ return "Local disk storage is for development.";
47
+ case "persistent":
48
+ return `Uploads are on this server's disk in ${e.LOCAL_STORAGE_ROOT}, which updates keep. Include it in backups (the self-host backup does).`;
49
+ case "unsafe":
50
+ return "Uploads are on this machine's disk because FREEHOLDER_UNSAFE_LOCAL_STORAGE=1.";
51
+ case "refused":
52
+ return "Uploads are configured for local disk in production without a persistent LOCAL_STORAGE_ROOT, so a rebuild or update would lose them.";
53
+ }
54
+ }