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
@@ -1,17 +1,20 @@
1
1
  // Copyright (C) 2026 Tony Aly
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- // Filesystem storage. **Development only** — §10 and §18 both say production
4
- // mandates managed object storage, because a droplet's disk is not backed up,
5
- // does not survive a rebuild, and cannot be shared by two app processes.
3
+ // Filesystem storage. The development default, and (C3.44) a supported
4
+ // production mode for a single-server install that keeps its media directory
5
+ // across updates and backs it up: the native Linux installer's
6
+ // /var/lib/freeholder/media, or the Docker recipe's named volume. What §18
7
+ // still refuses is the implicit relative directory, which lives inside the
8
+ // release or the container layer and is thrown away by a rebuild.
6
9
  //
7
- // It exists so `pnpm dev` works with no cloud account at all, and so the
8
- // adapter contract has a second implementation keeping it honest: an interface
9
- // with one implementation is just that implementation with extra steps.
10
- import { createReadStream } from "node:fs";
10
+ // One app process only: two processes on two machines cannot share it. Move
11
+ // to S3-compatible storage before scaling out (deploy/linux/README.md).
12
+ import { accessSync, constants, createReadStream, statSync } from "node:fs";
11
13
  import { mkdir, open, readFile, rm, stat, writeFile } from "node:fs/promises";
12
14
  import { dirname, join, resolve, sep } from "node:path";
13
15
  import type { StorageAdapter, StoredObject } from "@/adapters/storage/types";
14
16
  import { env } from "@/core/env";
17
+ import { localStorageMode } from "@/adapters/storage/local-mode";
15
18
 
16
19
  export interface LocalConfig {
17
20
  /** Directory to write under. Created on demand. */
@@ -22,21 +25,41 @@ export interface LocalConfig {
22
25
 
23
26
  /**
24
27
  * §18's storage mandate, enforced rather than documented: media is the least
25
- * recoverable asset a business has, and a droplet's disk is not backed up, does
26
- * not survive a rebuild, and cannot be shared by two processes. A dead box must
27
- * never be able to take the photo archive with it.
28
+ * recoverable asset a business has. A production instance may keep it on
29
+ * local disk only in a directory it names explicitly (an absolute
30
+ * LOCAL_STORAGE_ROOT), which the self-host recipes keep across updates and
31
+ * include in the nightly backup. That directory must already exist: creating
32
+ * it on demand would quietly write to the container layer when a volume was
33
+ * forgotten.
28
34
  *
29
- * The override exists because a self-hoster who genuinely means it should not
30
- * be locked out of their own software — and it is named to be embarrassing in
31
- * a config review, which is the point.
35
+ * The legacy override remains for an implicit directory, and it is still
36
+ * named to be embarrassing in a config review.
32
37
  */
33
- function refuseInProduction(): void {
38
+ function refuseInProduction(root: string): void {
34
39
  // Through env() like everything else: a guard that decides for itself what
35
40
  // production means can disagree with the platform that configured it, and
36
41
  // the disagreement is only discovered by losing an owner's media.
37
- const { NODE_ENV, FREEHOLDER_UNSAFE_LOCAL_STORAGE } = env();
38
- if (NODE_ENV !== "production") return;
39
- if (FREEHOLDER_UNSAFE_LOCAL_STORAGE === "1") {
42
+ const current = env();
43
+ const mode = localStorageMode(current);
44
+ if (mode === "development") return;
45
+ if (mode === "persistent") {
46
+ let directory = false;
47
+ try {
48
+ directory = statSync(/* turbopackIgnore: true */ root).isDirectory();
49
+ accessSync(/* turbopackIgnore: true */ root, constants.W_OK);
50
+ } catch {
51
+ directory = false;
52
+ }
53
+ if (!directory) {
54
+ throw new Error(
55
+ `LOCAL_STORAGE_ROOT (${root}) must be an existing directory this ` +
56
+ "process can write. Create it on persistent disk (the self-host " +
57
+ "installers do), or mount the recipe's media volume there.",
58
+ );
59
+ }
60
+ return;
61
+ }
62
+ if (mode === "unsafe") {
40
63
  console.warn(
41
64
  "[storage] Using local disk in production because " +
42
65
  "FREEHOLDER_UNSAFE_LOCAL_STORAGE=1. Uploaded media will be lost if " +
@@ -45,20 +68,22 @@ function refuseInProduction(): void {
45
68
  return;
46
69
  }
47
70
  throw new Error(
48
- "Storage is set to \"local\", which is for development only: media on a " +
49
- "server's own disk is not backed up and does not survive a rebuild " +
50
- "(MASTER.md §18).\n" +
51
- "Set adapters.storage to \"s3\" in freeholder.config.ts and configure " +
52
- "S3_* in the environment — DigitalOcean Spaces, Cloudflare R2, MinIO and " +
53
- "AWS all work.\n" +
54
- "If you truly intend to keep media on this machine's disk, set " +
71
+ "Storage is set to \"local\" without a persistent directory. In " +
72
+ "production, local disk is for development only unless it is a " +
73
+ "directory you keep and back up (MASTER.md §18).\n" +
74
+ "Set LOCAL_STORAGE_ROOT to an absolute path on persistent disk (the " +
75
+ "self-host installers use /var/lib/freeholder/media), or set " +
76
+ "adapters.storage to \"s3\" in freeholder.config.ts and configure S3_* " +
77
+ "in the environment: DigitalOcean Spaces, Cloudflare R2, MinIO and AWS " +
78
+ "all work.\n" +
79
+ "To keep media in an implicit directory anyway, set " +
55
80
  "FREEHOLDER_UNSAFE_LOCAL_STORAGE=1.",
56
81
  );
57
82
  }
58
83
 
59
84
  export function createLocalStorage(config: LocalConfig): StorageAdapter {
60
- refuseInProduction();
61
85
  const root = resolve(config.root);
86
+ refuseInProduction(root);
62
87
 
63
88
  /**
64
89
  * A key is attacker-influenced (it derives from an uploaded filename), so
@@ -78,7 +103,9 @@ export function createLocalStorage(config: LocalConfig): StorageAdapter {
78
103
 
79
104
  return {
80
105
  id: "local",
81
- isPublic: true,
106
+ // Objects are served by the app's /media route, which re-checks the
107
+ // object inventory on every request; nothing reaches them directly.
108
+ isPublic: false,
82
109
 
83
110
  async put(key, body, contentType): Promise<StoredObject> {
84
111
  const target = pathFor(key);
@@ -31,6 +31,14 @@ export function toContractJsonSchema(
31
31
  },
32
32
  });
33
33
  const { $schema: _ignored, ...rest } = json as Record<string, unknown>;
34
+ // An object-only action union is still an object input. Preserve the
35
+ // canonical alternatives while giving object-only transports (MCP) an
36
+ // explicit root type; otherwise they erase every branch as non-object.
37
+ const alternatives = rest.oneOf ?? rest.anyOf;
38
+ if (!rest.type && Array.isArray(alternatives) && alternatives.length > 0
39
+ && alternatives.every(value => value && typeof value === "object" && (value as { type?: unknown }).type === "object")) {
40
+ return { type: "object", ...rest };
41
+ }
34
42
  return rest;
35
43
  } catch (error) {
36
44
  console.warn(`[contract] could not describe a ${io} schema`, error);
@@ -0,0 +1,29 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { sql } from "drizzle-orm";
4
+ import { env } from "@/core/env";
5
+ import { ServiceError, type Actor, type Tx } from "@/core/service";
6
+ import { PLAYGROUND_BASELINE_MODULE, PLAYGROUND_ROW_CAPS } from "./playground-policy";
7
+
8
+ /**
9
+ * Check each new row inside its owning transaction. The service kernel's
10
+ * preflight cannot see inserts already staged by another call in that same
11
+ * transaction; bulk inline creation must count them before the next insert.
12
+ * The advisory lock serializes concurrent creators without locking real sites.
13
+ */
14
+ export async function checkPlaygroundInsert(tx: Tx, actor: Actor, serviceName: string): Promise<void> {
15
+ if (env().FREEHOLDER_PLAYGROUND !== "1" || actor.kind === "system") return;
16
+ const cap = PLAYGROUND_ROW_CAPS[serviceName];
17
+ if (!cap) return;
18
+ await tx.execute(sql`select pg_advisory_xact_lock(hashtext(${`playground-cap:${cap.table}`}))`);
19
+ const [stored] = await tx.execute<{ baseline: Record<string, number> | null }>(sql`
20
+ select config->'baseline' as baseline from module_settings
21
+ where module = ${PLAYGROUND_BASELINE_MODULE}
22
+ `);
23
+ const [current] = await tx.execute<{ count: number }>(sql`
24
+ select count(*)::int as count from ${sql.identifier(cap.table)}
25
+ `);
26
+ if (Number(current?.count ?? 0) - Number(stored?.baseline?.[cap.table] ?? 0) >= cap.limit) {
27
+ throw new ServiceError("rate_limited", "This playground surface is full. Try again after the hourly reset.");
28
+ }
29
+ }
@@ -36,6 +36,8 @@ const MUTATIONS = new Set([
36
36
  "cms.updateSection", "cms.createSectionLocale", "cms.restoreRevision",
37
37
  "cms.attachLayout", "cms.detachLayout", "cms.rejoinLayout", "cms.createSection",
38
38
  "cms.saveAsSection", "cms.detachSection", "cms.deleteSection", "cms.createFromTemplate",
39
+ "cms.createPost", "cms.setPostMeta", "cms.saveTerm", "cms.deleteTerm",
40
+ "cms.saveAuthor", "cms.deleteAuthor", "cms.updateBlogSettings", "cms.moderateReaderComment",
39
41
  "forms.create", "forms.update", "forms.delete", "forms.reviewSubmission",
40
42
  "contacts.create", "contacts.update", "contacts.merge", "contacts.undoMerge",
41
43
  "catalog.createProduct", "catalog.updateProduct", "catalog.updateProductDescription",
@@ -70,6 +72,7 @@ export const PLAYGROUND_PUBLIC = [
70
72
  "catalog.applyCouponToCart", "catalog.subscribeBackInStock", "catalog.shopperCheckout", "catalog.checkoutCart",
71
73
  "messaging.startSiteChat", "messaging.postSiteChat", "messaging.endSiteChat",
72
74
  "cms.submitSiteChat", "cms.submitQuoteRequest", "cms.submitTipIntent", "cms.rateHelpArticle",
75
+ "cms.submitReaderComment",
73
76
  "share.shareVia",
74
77
  "linkinbio.follow",
75
78
  "popups.record", "popups.capture",
@@ -136,6 +139,8 @@ export const PLAYGROUND_PUBLIC_REFUSED: Readonly<Record<string, string>> = {
136
139
  "media.claimCaptureOriginal": "Uploads are refused on the bounded playground disk.",
137
140
  "media.applyCaptureOriginal": "Uploads are refused on the bounded playground disk.",
138
141
  "agents.proposeWriteGate": "Agent workers authenticate with keys the playground never issues.",
142
+ "assistant.previewCall": "Managed provider call controls are unavailable in the playground; no owner-issued preview key or media session is created.",
143
+ "assistant.saveCallCaption": "Private phase of a provider call the playground never admits.",
139
144
  "assistant.prepareAnswer": "Phase of the model-backed answer the playground refuses.",
140
145
  "assistant.applyAnswer": "Phase of the model-backed answer the playground refuses.",
141
146
  "media.upload": "Uploads are refused on the bounded playground disk.",
@@ -256,6 +261,9 @@ export interface PlaygroundRowCap {
256
261
 
257
262
  export const PLAYGROUND_ROW_CAPS: Readonly<Record<string, PlaygroundRowCap>> = {
258
263
  "cms.createPage": { table: "pages", limit: 50 },
264
+ "cms.createPost": { table: "pages", limit: 50 },
265
+ "cms.saveAuthor": { table: "blog_authors", limit: 50 },
266
+ "cms.saveTerm": { table: "blog_terms", limit: 100 },
259
267
  "cms.createFromTemplate": { table: "pages", limit: 50 },
260
268
  "linkinbio.setup": { table: "pages", limit: 50 },
261
269
  "cms.createSection": { table: "sections", limit: 100 },
@@ -281,6 +289,7 @@ export const PLAYGROUND_ROW_CAPS: Readonly<Record<string, PlaygroundRowCap>> = {
281
289
  "cms.submitSiteChat": { table: "site_chat_sessions", limit: 200 },
282
290
  "cms.submitQuoteRequest": { table: "conversations", limit: 500 },
283
291
  "cms.submitTipIntent": { table: "conversations", limit: 500 },
292
+ "cms.submitReaderComment": { table: "blog_reader_comments", limit: 200 },
284
293
  "share.shareVia": { table: "shared_links", limit: 1000 },
285
294
  "popups.record": { table: "popup_events", limit: 2000 },
286
295
  "popups.capture": { table: "popup_events", limit: 2000 },
@@ -637,7 +637,16 @@ async function checkSecurity(): Promise<Check[]> {
637
637
  const e = env();
638
638
  const checks: Check[] = [];
639
639
 
640
- if (e.NODE_ENV === "production" && e.FREEHOLDER_UNSAFE_LOCAL_STORAGE === "1") {
640
+ const { localStorageMode, describeLocalStorage } = await import("@/adapters/storage/local-mode");
641
+ const configuredStorage =
642
+ e.FREEHOLDER_STORAGE ?? (await import("../../../freeholder.config")).default.adapters.storage;
643
+ if (configuredStorage === "local" && localStorageMode(e) === "persistent") {
644
+ // C3.44: a supported single-server mode, so it is information, not a
645
+ // warning. The owner still needs to know the backup must include it.
646
+ checks.push(
647
+ ok("security.localStorage", "Media on this server", describeLocalStorage(e)),
648
+ );
649
+ } else if (e.NODE_ENV === "production" && e.FREEHOLDER_UNSAFE_LOCAL_STORAGE === "1") {
641
650
  checks.push(
642
651
  warn(
643
652
  "security.localStorage",
@@ -1081,22 +1090,24 @@ async function checkUpdateSeams(): Promise<Check[]> {
1081
1090
  ),
1082
1091
  );
1083
1092
  const storage = e.FREEHOLDER_STORAGE ?? instanceConfig.adapters.storage;
1084
- if (storage === "local" && e.NODE_ENV === "production" && e.FREEHOLDER_UNSAFE_LOCAL_STORAGE !== "1") {
1093
+ const { localStorageMode, describeLocalStorage } = await import("@/adapters/storage/local-mode");
1094
+ const mode = storage === "local" ? localStorageMode(e) : undefined;
1095
+ if (mode === "refused") {
1085
1096
  checks.push(
1086
1097
  fail(
1087
1098
  "update.seams.uploads",
1088
1099
  "Uploads seam",
1089
- "Uploads are on this machine's disk, which does not survive a rebuild.",
1090
- "Set adapters.storage to s3 or replit, or only use local disk in development.",
1100
+ describeLocalStorage(e),
1101
+ "Set LOCAL_STORAGE_ROOT to a persistent absolute directory, or set adapters.storage to s3 or replit.",
1091
1102
  ),
1092
1103
  );
1093
- } else if (storage === "local" && e.FREEHOLDER_UNSAFE_LOCAL_STORAGE === "1") {
1104
+ } else if (mode === "unsafe") {
1094
1105
  checks.push(
1095
1106
  warn(
1096
1107
  "update.seams.uploads",
1097
1108
  "Uploads seam",
1098
- "Uploads are on this machine's disk because FREEHOLDER_UNSAFE_LOCAL_STORAGE=1.",
1099
- "Move media to object storage before relying on updates to replace this instance.",
1109
+ describeLocalStorage(e),
1110
+ "Set LOCAL_STORAGE_ROOT to a directory updates keep, or move media to object storage.",
1100
1111
  ),
1101
1112
  );
1102
1113
  } else {
@@ -1104,9 +1115,7 @@ async function checkUpdateSeams(): Promise<Check[]> {
1104
1115
  ok(
1105
1116
  "update.seams.uploads",
1106
1117
  "Uploads seam",
1107
- storage === "local"
1108
- ? "Local disk storage is for development. Production must use object storage."
1109
- : `Uploads use ${storage} object storage, not instance disk.`,
1118
+ mode ? describeLocalStorage(e) : `Uploads use ${storage} object storage, not instance disk.`,
1110
1119
  ),
1111
1120
  );
1112
1121
  }
@@ -277,7 +277,12 @@ const envSchema = z.object({
277
277
  /** Replit Object Storage (§20). Discovered from the environment on Replit. */
278
278
  REPLIT_BUCKET_ID: z.string().optional(),
279
279
 
280
- /** Development only — production mandates managed object storage (§18). */
280
+ /**
281
+ * Where `local` storage writes. Defaults to `.data/media` for development.
282
+ * In production it must be an absolute directory kept across updates and
283
+ * included in backups (C3.44): `/var/lib/freeholder/media` on the native
284
+ * Linux install, the media volume in Docker. See local-mode.ts.
285
+ */
281
286
  LOCAL_STORAGE_ROOT: z.string().optional(),
282
287
 
283
288
  /**
@@ -329,6 +334,8 @@ const envSchema = z.object({
329
334
  AGENT_GATEWAY_MODEL: z.string().trim().min(1).max(200).optional(),
330
335
  /** `paradise`: purpose-bound Paradise Modern site credential (optional provider). */
331
336
  PARADISEMODERN_API_KEY: z.string().trim().min(1).optional(),
337
+ /** Exact HTTPS voice/face worker origins for managed preview calls; no wildcard. */
338
+ PARADISEMODERN_ASSISTANT_ORIGINS: z.string().optional(),
332
339
  /** `https://` only, or `http://` on a loopback host for tests and local work. */
333
340
  PARADISEMODERN_URL: z
334
341
  .string()
@@ -53,6 +53,7 @@ export interface ContentSecurityPolicyOptions {
53
53
  thirdPartyCreativeConsent?: boolean;
54
54
  /** C12.24: the site's own SFU, reachable only from group call pages. */
55
55
  callOrigins?: string[];
56
+ assistantOrigins?: string[];
56
57
  /**
57
58
  * C3.32: the chosen measurement provider's edge. The caller passes it only
58
59
  * for a visitor who explicitly allowed measurement; it is never implied by
@@ -69,6 +70,11 @@ export interface ContentSecurityPolicyOptions {
69
70
  * inline style elements: React uses bounded style attributes for bar widths
70
71
  * and image crop anchors, while every `<style>` element still needs the nonce.
71
72
  */
73
+ /** Calls are offered on Contact only, including the original path before locale rewrite. */
74
+ export function isPreviewAssistantContactPath(path: string): boolean {
75
+ return /^\/(?:[a-z]{2,3}(?:-[a-z0-9]{2,8})*\/)?contact\/?$/i.test(path);
76
+ }
77
+
72
78
  export function contentSecurityPolicy(options: ContentSecurityPolicyOptions): string {
73
79
  const media = [...new Set(options.mediaOrigins ?? [])].sort();
74
80
  const upload = options.path.startsWith("/admin")
@@ -78,6 +84,8 @@ export function contentSecurityPolicy(options: ContentSecurityPolicyOptions): st
78
84
  ? [...new Set(options.creativeOrigins ?? [])].sort()
79
85
  : [];
80
86
  const call = options.path.startsWith("/call/group/") ? [...new Set(options.callOrigins ?? [])].sort() : [];
87
+ const assistant = isPreviewAssistantContactPath(options.path) ? [...new Set(options.assistantOrigins ?? [])].sort() : [];
88
+ const assistantWasm = isPreviewAssistantContactPath(options.path) || options.path.startsWith("/managed-assistant/");
81
89
  const measurement = options.path.startsWith("/admin")
82
90
  ? []
83
91
  : [...new Set(options.measurementOrigins ?? [])].sort();
@@ -88,14 +96,14 @@ export function contentSecurityPolicy(options: ContentSecurityPolicyOptions): st
88
96
  : " 'unsafe-eval'";
89
97
  const policy = [
90
98
  "default-src 'self'",
91
- `script-src 'nonce-${options.nonce}' 'strict-dynamic' 'self'${development}${sources([...creative, ...measurement])}`,
99
+ `script-src 'nonce-${options.nonce}' 'strict-dynamic' 'self'${assistantWasm ? " 'wasm-unsafe-eval'" : ""}${development}${sources([...creative, ...measurement])}`,
92
100
  "script-src-attr 'none'",
93
101
  `style-src 'self' 'nonce-${options.nonce}'${sources(creative)}`,
94
102
  "style-src-attr 'unsafe-inline'",
95
103
  `img-src 'self' data: blob:${sources([...media, ...creative, ...measurement])}`,
96
104
  `font-src 'self' data:${sources(creative)}`,
97
105
  `media-src 'self' blob:${sources([...media, ...creative])}`,
98
- `connect-src 'self'${sources([...upload, ...creative, ...call, ...measurement])}`,
106
+ `connect-src 'self'${sources([...upload, ...creative, ...call, ...assistant, ...measurement])}`,
99
107
  `frame-src 'self'${sources(creative)}`,
100
108
  "worker-src 'self' blob:",
101
109
  "manifest-src 'self'",
@@ -0,0 +1,10 @@
1
+ // Copyright (C) 2026 Tony Aly
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /** Copy only the readable double-submit token, never an authentication cookie. */
5
+ export function browserCsrfHeaders(): Record<string, string> {
6
+ const raw = document.cookie.split(/;\s*/).find(cookie => cookie.startsWith("freeholder_csrf="))?.slice("freeholder_csrf=".length);
7
+ if (!raw) return {};
8
+ try { return { "x-csrf-token": decodeURIComponent(raw) }; }
9
+ catch { return {}; }
10
+ }