@taprootio/site-authoring 0.41.1 → 0.55.0

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 (78) hide show
  1. package/README.md +50 -0
  2. package/examples/riverbend-wellness/settings/site-publishing-preferences.json +3 -0
  3. package/examples/riverbend-wellness/settings/taproot-styles.json +11 -0
  4. package/package.json +4 -3
  5. package/src/api.js +170 -11
  6. package/src/appearance-contract.js +278 -8
  7. package/src/authored-tag-names.js +88 -0
  8. package/src/block-flow.js +103 -1
  9. package/src/brand-color.js +39 -4
  10. package/src/breadcrumb-artwork.js +234 -0
  11. package/src/breadcrumb-separators.js +11 -0
  12. package/src/changelog.json +154 -0
  13. package/src/chrome-features.js +152 -0
  14. package/src/chrome-input.js +147 -0
  15. package/src/chrome-output.js +92 -0
  16. package/src/chrome-paint-catalog-taproot.json +52 -0
  17. package/src/chrome-report.js +173 -0
  18. package/src/cli.js +48 -17
  19. package/src/content/components.js +27 -4
  20. package/src/content/external-link.js +2 -1
  21. package/src/content/markdown.js +271 -101
  22. package/src/content/tiptap-prosemirror.ts +125 -43
  23. package/src/content/validate-document.js +4 -1
  24. package/src/content-inset.js +48 -0
  25. package/src/errors.js +1 -0
  26. package/src/espalier-shared.js +26 -0
  27. package/src/field-suggestions.js +40 -0
  28. package/src/fixture-init.js +22 -5
  29. package/src/font-catalog.js +11 -1
  30. package/src/footer-brand-inputs.js +25 -2
  31. package/src/footer-content.js +38 -0
  32. package/src/footer-contract.js +11 -0
  33. package/src/footer-cta-styles.js +6 -0
  34. package/src/footer-draft-hash.js +4 -2
  35. package/src/footer-fit.js +62 -15
  36. package/src/footer-workspace.js +60 -16
  37. package/src/header-presentation.js +16 -0
  38. package/src/latest-posts-tags.js +57 -0
  39. package/src/page-structure-checks.js +5 -0
  40. package/src/page-tag-badge-modes.js +6 -0
  41. package/src/page-tag-writes.js +158 -0
  42. package/src/page-type-tags.js +16 -0
  43. package/src/presentation-reference.js +312 -86
  44. package/src/recipe-page-options.js +22 -0
  45. package/src/recipe-step-contract.js +164 -0
  46. package/src/recipe-step-contract.json +65 -0
  47. package/src/reference-help.js +164 -78
  48. package/src/session.js +39 -24
  49. package/src/setting-reference.js +239 -48
  50. package/src/settings-catalog.js +63 -0
  51. package/src/site-check-findings.js +25 -5
  52. package/src/site-check-rules.json +3 -1
  53. package/src/site-health-findings.js +13 -13
  54. package/src/site-navigation-groups.js +70 -0
  55. package/src/styling-fixed-values.js +71 -0
  56. package/src/tag-destination-warnings.js +35 -0
  57. package/src/template-token-reach.json +242 -0
  58. package/src/theme-proposals.js +18 -27
  59. package/src/theme-resolve.js +305 -51
  60. package/src/theme-validation.js +126 -6
  61. package/src/token-reach.js +222 -0
  62. package/src/typed-page-reference.js +72 -15
  63. package/src/typed-pages.js +171 -71
  64. package/src/verbs/deploy.js +6 -0
  65. package/src/verbs/footer-push.js +30 -5
  66. package/src/verbs/forms-push.js +11 -3
  67. package/src/verbs/pages-delete.js +19 -10
  68. package/src/verbs/pages-push.js +125 -36
  69. package/src/verbs/plan.js +10 -4
  70. package/src/verbs/pull.js +277 -67
  71. package/src/verbs/staging-review.js +27 -1
  72. package/src/verbs/status.js +22 -0
  73. package/src/verbs/theme-push.js +249 -120
  74. package/src/verbs/theme-resolve.js +310 -47
  75. package/src/verbs/validate.js +71 -17
  76. package/src/workspace-check.js +37 -4
  77. package/src/workspace.js +37 -1
  78. package/test/fixtures/default-site-theme.json +516 -0
package/src/verbs/pull.js CHANGED
@@ -1,7 +1,12 @@
1
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import path from "node:path";
4
+
1
5
  import {
2
6
  getNavigation,
3
7
  getPage,
4
8
  getSettingsGroup,
9
+ getSiteAuthoringCapabilities,
5
10
  getSitePresentation,
6
11
  getSiteRedirectMap,
7
12
  listSiteAuthors,
@@ -9,6 +14,7 @@ import {
9
14
  listSitePages,
10
15
  PAGE_STATUS_DRAFT,
11
16
  PAGE_STATUS_UNKNOWN,
17
+ requireAuthoredTagSnapshot,
12
18
  withRefusalGuidance,
13
19
  } from "../api.js";
14
20
  import {
@@ -17,6 +23,8 @@ import {
17
23
  SURFACE_DOCS_PRESENTATION,
18
24
  VERB_PULL,
19
25
  } from "../constants.js";
26
+ import { tagDestinationCatalogSlugs } from "../appearance-contract.js";
27
+ import { validateAuthoredTagNames } from "../authored-tag-names.js";
20
28
  import { AUTHORS_FILE_NAME, parseAuthorReference, projectAuthorsForWorkspace } from "../authors-contract.js";
21
29
  import { isCanonicalUuid, sanitizeDiagnostic, SiteAuthoringError } from "../errors.js";
22
30
  import { appearanceManifestEntry, footerManifestEntry, presentationManifestEntry } from "../footer-workspace.js";
@@ -25,6 +33,7 @@ import { projectRedirectMapForWorkspace, REDIRECTS_FILE_NAME } from "../redirect
25
33
  import { navigationManifestEntry } from "../navigation-workspace.js";
26
34
  import { redirectsManifestEntry } from "../redirects-workspace.js";
27
35
  import { projectNavigationForWorkspace } from "./nav-push.js";
36
+ import { parseFrontMatter } from "./pages-push.js";
28
37
  import { boundedList, openSession, successResult } from "../session.js";
29
38
  import {
30
39
  projectSettingsGroup,
@@ -43,7 +52,9 @@ import {
43
52
  isLegalTemplateType,
44
53
  isAuthorableTemplateType,
45
54
  isGeneratedTemplateType,
55
+ projectAuthoredTagSnapshot,
46
56
  sentDisplayDate,
57
+ supportsAuthoredTagWireType,
47
58
  TEMPLATE_LEGAL,
48
59
  workspaceDocumentFromPage,
49
60
  } from "../typed-pages.js";
@@ -80,6 +91,7 @@ import {
80
91
  workspaceContentHash,
81
92
  workspaceFileExists,
82
93
  workspaceFileNameForPage,
94
+ workspacePageSourceBodyHash,
83
95
  readManifest,
84
96
  writeManifest,
85
97
  writeWorkspaceFile,
@@ -149,11 +161,13 @@ function retiredSourceRecords(value) {
149
161
  * recorded content key covers exactly those and the source bytes.
150
162
  */
151
163
  function metadataEditedLocally(source, templateType) {
164
+ const { contentKey, sourceHash, sourceBodyHash } = source.baseline ?? {};
152
165
  return source.sourceFormat !== PAGE_SOURCE_FORMAT_MARKDOWN
153
166
  && !isGeneratedTemplateType(templateType)
154
- && source.baseline?.contentKey !== undefined
155
- && source.baseline?.sourceHash !== undefined
156
- && pageContentKey(source.baseline.sourceHash, source.metadata) !== source.baseline.contentKey;
167
+ && contentKey !== undefined
168
+ && sourceHash !== undefined
169
+ && pageContentKey(sourceHash, source.metadata) !== contentKey
170
+ && (sourceBodyHash === undefined || pageContentKey(sourceBodyHash, source.metadata) !== contentKey);
157
171
  }
158
172
 
159
173
  /**
@@ -259,9 +273,9 @@ function describeDifferenceSummary(differences) {
259
273
  * A file that cannot be parsed is certainly not what pull wrote, so it counts
260
274
  * as authored and is kept rather than refreshed over.
261
275
  */
262
- function holdsRemoteDocument(sourceBytes, remoteHash) {
276
+ function holdsRemoteDocument(sourceBytes, remoteHash, sourceBodyHash) {
263
277
  try {
264
- return canonicalDocumentHash(JSON.parse(sourceBytes.toString("utf8"))) === remoteHash;
278
+ return (sourceBodyHash ?? canonicalDocumentHash(JSON.parse(sourceBytes.toString("utf8")))) === remoteHash;
265
279
  } catch {
266
280
  return undefined;
267
281
  }
@@ -277,6 +291,100 @@ function parsePageDocument(bytes) {
277
291
  }
278
292
  }
279
293
 
294
+ function sourceWithTags(document, tags) {
295
+ return tags === undefined ? document : { ...document, tags };
296
+ }
297
+
298
+ function sourceWithoutTags(document) {
299
+ const { tags: _tags, ...body } = document;
300
+ return body;
301
+ }
302
+
303
+ function serializePage(document) {
304
+ return Buffer.from(`${JSON.stringify(document, undefined, 2)}\n`, "utf8");
305
+ }
306
+
307
+ function savedTagBaseline(baseline) {
308
+ return baseline?.authoredTagRevision === undefined ? {} : {
309
+ authoredTagRevision: baseline.authoredTagRevision,
310
+ authoredTagSlugs: baseline.authoredTagSlugs,
311
+ };
312
+ }
313
+
314
+ function projectedPageTags(page, summary, onProgress) {
315
+ const snapshot = requireAuthoredTagSnapshot(page);
316
+ const projection = projectAuthoredTagSnapshot(snapshot);
317
+ if ("reason" in projection) {
318
+ onProgress(sanitizeDiagnostic(
319
+ `Page '${displayPagePath(summary.path)}' has authored tags this workspace cannot represent. ${projection.reason} `
320
+ + "Omit tags from the source for a body-only push that preserves the site's tag assignments.",
321
+ ));
322
+ return projection;
323
+ }
324
+ return { ...projection, revision: snapshot.revision };
325
+ }
326
+
327
+ function markdownSourceTags(sourceBytes, file) {
328
+ const { fields, candidates, fault } = parseFrontMatter(sourceBytes.toString("utf8"), file);
329
+ if (fault?.field === "tags") throw fault;
330
+ if (candidates.has("tags")) {
331
+ throw new SiteAuthoringError("pages.front_matter_duplicate", `'${file}' declares tags twice.`, { field: "tags" });
332
+ }
333
+ if (!fields.has("tags")) return undefined;
334
+ try {
335
+ return JSON.parse(fields.get("tags"));
336
+ } catch {
337
+ throw new SiteAuthoringError("pages.tags_invalid", `Use a one-line JSON array of tag names in '${file}'.`, {
338
+ field: "tags",
339
+ });
340
+ }
341
+ }
342
+
343
+ function sameTagSlugs(left, right) {
344
+ return Array.isArray(right) && left.length === right.length && left.every((slug, index) => slug === right[index]);
345
+ }
346
+
347
+ function tagPullConflict(source, projection) {
348
+ const live = boundedList(projection.names, 4);
349
+ const names = live.items.map((name) => JSON.stringify([...name].slice(0, 40).join("")));
350
+ const suffix = live.truncated ? " and more" : "";
351
+ const shown = names.length === 0 ? "no authored tags" : `${names.join(", ")}${suffix}`;
352
+ return new SiteAuthoringError(
353
+ "pages.tag_pull_conflict",
354
+ `Authored tags changed for '${source.file}'. Back up your changes, align its tags with the site's list, then `
355
+ + `run 'taproot-site pull' again at the same path before reapplying changes. The site has ${shown}.`,
356
+ { field: source.file, alternatives: live.items },
357
+ );
358
+ }
359
+
360
+ /** The local source and the saved tag baseline after a retained page reconciles. */
361
+ function reconcileTrackedTags({ source, projection, sourceBytes, localDocument, markdown, localChanged, conflicted }) {
362
+ const tags = localDocument?.tags;
363
+ const saved = savedTagBaseline(source.baseline);
364
+ if (projection === undefined || conflicted) return { tags, baseline: saved };
365
+ if ("reason" in projection) return { tags, baseline: {} };
366
+ if (!markdown && localDocument === undefined) return { tags, baseline: saved };
367
+
368
+ const localTags = markdown ? markdownSourceTags(sourceBytes, source.file) : tags;
369
+ const baseline = (slugs) => ({ authoredTagRevision: projection.revision, authoredTagSlugs: slugs });
370
+ if (localTags === undefined) return { tags, baseline: baseline(null) };
371
+
372
+ const local = validateAuthoredTagNames(localTags);
373
+ if ("reason" in local) {
374
+ throw new SiteAuthoringError("pages.tags_invalid", `'${source.file}', ${local.field}. ${local.reason}`, {
375
+ field: local.field,
376
+ });
377
+ }
378
+ if (projection.revision === saved.authoredTagRevision) return { tags, baseline: saved };
379
+ if (sameTagSlugs(local.slugs, projection.slugs)) return { tags, baseline: baseline(local.slugs) };
380
+ if (sameTagSlugs(local.slugs, saved.authoredTagSlugs)) {
381
+ return markdown || localChanged
382
+ ? { tags, baseline: saved }
383
+ : { tags: projection.names, baseline: baseline(projection.slugs) };
384
+ }
385
+ throw tagPullConflict(source, projection);
386
+ }
387
+
280
388
  /**
281
389
  * The document this workspace last reconciled with, if it still holds one.
282
390
  *
@@ -313,7 +421,7 @@ async function readPreviousRemoteDocument({ workspaceDir, baselineFile, sourceBy
313
421
  }
314
422
 
315
423
  /** The JSON paths at which the site's document moved, when that is knowable. */
316
- async function describeRemoteMovement({ workspaceDir, baselineFile, sourceBytes, markdown, localChanged, body }) {
424
+ async function describeRemoteMovement({ workspaceDir, baselineFile, sourceBytes, markdown, localChanged, body, taggedTemplate }) {
317
425
  const previous = await readPreviousRemoteDocument({
318
426
  workspaceDir,
319
427
  baselineFile,
@@ -321,7 +429,9 @@ async function describeRemoteMovement({ workspaceDir, baselineFile, sourceBytes,
321
429
  markdown,
322
430
  localChanged,
323
431
  });
324
- return previous === undefined ? undefined : describeJsonDifferences(previous, body);
432
+ return previous === undefined
433
+ ? undefined
434
+ : describeJsonDifferences(taggedTemplate ? sourceWithoutTags(previous) : previous, body);
325
435
  }
326
436
 
327
437
  function bodyStatusFor(summary) {
@@ -686,6 +796,7 @@ export async function pull(invocation) {
686
796
  // are the whole of what this workspace holds for it.
687
797
  const presentationOnly = surface === SURFACE_DOCS_PRESENTATION;
688
798
 
799
+ let stageDirectory;
689
800
  return await withRefusalGuidance(onProgress, "pull", async () => {
690
801
  let pages = [];
691
802
  let truncated = false;
@@ -700,6 +811,63 @@ export async function pull(invocation) {
700
811
  }
701
812
  const live = pages.filter((summary) => !isGonePage(summary));
702
813
  const authorable = live.filter((summary) => isAuthorableTemplateType(summary.templateType));
814
+ const capabilities = authorable.some((summary) => supportsAuthoredTagWireType(summary.templateType))
815
+ ? await getSiteAuthoringCapabilities(client, siteId)
816
+ : undefined;
817
+ const readsAuthoredTags = (summary) =>
818
+ capabilities !== undefined && supportsAuthoredTagWireType(summary.templateType);
819
+
820
+ const readFreshProjection = async (summary, file) => {
821
+ onProgress(`Reading page '${summary.path}'.`);
822
+ const page = await getPage(client, summary.pageId, bodyStatusFor(summary));
823
+ const tagProjection = readsAuthoredTags(summary) ? projectedPageTags(page, summary, onProgress) : undefined;
824
+ const body = await workspaceBodyFromPage(page, summary.templateType);
825
+ const entry = {
826
+ description: typeof page.shortDescription === "string" ? page.shortDescription : "",
827
+ title: titleFromRead(page, summary),
828
+ path: pathFromRead(page, summary),
829
+ };
830
+ if (body === undefined) {
831
+ onProgress(`Page '${summary.path}' has no readable body; snapshotting metadata only.`);
832
+ return { entry };
833
+ }
834
+
835
+ const confirmedTags = tagProjection === undefined || "reason" in tagProjection ? undefined : tagProjection;
836
+ const tags = confirmedTags?.names.length > 0 ? confirmedTags.names : undefined;
837
+ const source = serializePage(sourceWithTags(body, tags));
838
+ const sourceHash = workspaceContentHash(source);
839
+ const remoteHash = canonicalDocumentHash(body);
840
+ const sourceBodyHash = supportsAuthoredTagWireType(summary.templateType) ? remoteHash : undefined;
841
+ const revision = normalizePageBodyRevision(page.bodyRevision);
842
+ const displayDate = trackedDisplayDate(page, summary.templateType);
843
+ return {
844
+ source,
845
+ entry: {
846
+ ...entry,
847
+ file,
848
+ workspaceMode: PAGE_WORKSPACE_MODE_EDITABLE,
849
+ sourceFormat: pageSourceFormat(file),
850
+ ...(isGeneratedTemplateType(summary.templateType) ? { generated: generatedIdentity(body.data) } : {}),
851
+ ...(isLegalTemplateType(summary.templateType) ? { legal: legalIdentity(body.data) } : {}),
852
+ baseline: {
853
+ remoteHash,
854
+ sourceHash,
855
+ contentKey: pageContentKey(tags === undefined ? sourceHash : sourceBodyHash, {
856
+ ...entry,
857
+ author: summary.authorRef,
858
+ }),
859
+ ...(sourceBodyHash === undefined ? {} : { sourceBodyHash }),
860
+ ...(revision === undefined ? {} : { revision }),
861
+ ...(displayDate === undefined ? {} : { displayDate }),
862
+ ...(summary.authorRef === "" ? {} : { author: summary.authorRef }),
863
+ ...(confirmedTags === undefined ? {} : {
864
+ authoredTagRevision: confirmedTags.revision,
865
+ authoredTagSlugs: tags === undefined ? null : confirmedTags.slugs,
866
+ }),
867
+ },
868
+ },
869
+ };
870
+ };
703
871
  // Generated-page sources recorded apart as retired. One whose page the site
704
872
  // lists again (a bounded listing left it out last time) takes its file back
705
873
  // as that page's source; with no baseline, pull compares the bytes with the
@@ -949,6 +1117,8 @@ export async function pull(invocation) {
949
1117
  if (source === undefined) continue;
950
1118
  onProgress(`Reading page '${summary.path}'.`);
951
1119
  const page = await getPage(client, summary.pageId, bodyStatusFor(summary));
1120
+ const taggedTemplate = supportsAuthoredTagWireType(summary.templateType);
1121
+ const tagProjection = readsAuthoredTags(summary) ? projectedPageTags(page, summary, onProgress) : undefined;
952
1122
  const body = await workspaceBodyFromPage(page, summary.templateType);
953
1123
  const description = typeof page.shortDescription === "string" ? page.shortDescription : "";
954
1124
  if (body === undefined) {
@@ -960,7 +1130,16 @@ export async function pull(invocation) {
960
1130
  // one; without the baseline the next pull could not tell it from the
961
1131
  // site's values and would overwrite it.
962
1132
  const metadataKept = metadataEditedLocally(source, summary.templateType);
963
- const keptBaseline = metadataKept ? withHeldAuthor(source.baseline, summary.authorRef) : undefined;
1133
+ const {
1134
+ authoredTagRevision: _tagRevision, authoredTagSlugs: _tagSlugs, ...bodyBaseline
1135
+ } = source.baseline ?? {};
1136
+ const tagBaseline = tagProjection !== undefined && "reason" in tagProjection
1137
+ ? {}
1138
+ : savedTagBaseline(source.baseline);
1139
+ const keptBaseline = {
1140
+ ...(metadataKept ? withHeldAuthor(bodyBaseline, summary.authorRef) : {}),
1141
+ ...tagBaseline,
1142
+ };
964
1143
  if (metadataKept) reportPendingAuthorDisagreement(source, summary, onProgress);
965
1144
  trackedPlans.set(summary.pageId, {
966
1145
  // The page is still the generated page it was; losing the record would
@@ -973,7 +1152,7 @@ export async function pull(invocation) {
973
1152
  author: metadataKept ? source.metadata.author : summary.authorRef,
974
1153
  file: source.file,
975
1154
  sourceFormat: source.sourceFormat,
976
- ...(keptBaseline === undefined ? {} : { baseline: keptBaseline }),
1155
+ ...(Object.keys(keptBaseline).length === 0 ? {} : { baseline: keptBaseline }),
977
1156
  });
978
1157
  continue;
979
1158
  }
@@ -989,16 +1168,7 @@ export async function pull(invocation) {
989
1168
  { field: source.file },
990
1169
  );
991
1170
  }
992
- const serialized = Buffer.from(`${JSON.stringify(body, undefined, 2)}\n`, "utf8");
993
- bufferedBytes += serialized.byteLength;
994
- if (bufferedBytes > WORKSPACE_LIMITS.pulledBodyBytes) {
995
- throw new SiteAuthoringError(
996
- "pages.pulled_bodies_too_large",
997
- `The tracked pages of this site exceed ${WORKSPACE_LIMITS.pulledBodyBytes} bytes, which is more than one `
998
- + "pull can hold before deciding whether any of them conflict.",
999
- { field: PAGES_DIRECTORY },
1000
- );
1001
- }
1171
+ const serialized = serializePage(body);
1002
1172
  const remoteHash = canonicalDocumentHash(body);
1003
1173
  const sourceBytes = await readWorkspaceFile(config.workspaceDir, source.file, WORKSPACE_LIMITS.documentBytes);
1004
1174
  const sourceHash = workspaceContentHash(sourceBytes);
@@ -1053,10 +1223,24 @@ export async function pull(invocation) {
1053
1223
  // the formats differ, so the bytes never match — and pull never writes
1054
1224
  // one at all. There is nothing to protect and nothing to compare, so an
1055
1225
  // unrecorded hash simply establishes itself.
1056
- const localKnown = source.baseline?.sourceHash !== undefined;
1057
- const sourceMatchesRemote = !localKnown && !markdown ? holdsRemoteDocument(sourceBytes, remoteHash) : undefined;
1058
- const localChanged = localKnown
1059
- ? source.baseline.sourceHash !== sourceHash
1226
+ const localDocument = taggedTemplate && !markdown ? parsePageDocument(sourceBytes) : undefined;
1227
+ const sourceBodyHash = localDocument === undefined ? undefined : workspacePageSourceBodyHash(localDocument);
1228
+ const tagAwareComparison = sourceBodyHash !== undefined
1229
+ && (Object.hasOwn(localDocument, "tags") || Array.isArray(source.baseline?.authoredTagSlugs));
1230
+ const savedBodyHash = tagAwareComparison ? source.baseline?.sourceBodyHash : undefined;
1231
+ const localKnown = source.baseline?.sourceHash !== undefined || savedBodyHash !== undefined;
1232
+ const sourceMatchesRemote = !localKnown && !markdown
1233
+ ? holdsRemoteDocument(sourceBytes, remoteHash, tagAwareComparison ? sourceBodyHash : undefined)
1234
+ : undefined;
1235
+ // Before the independent body hash existed, pull recorded the same
1236
+ // projection as canonical remote JSON and pretty-printed source bytes.
1237
+ const matchesLegacyBody = tagAwareComparison && savedBodyHash === undefined
1238
+ && (sourceBodyHash === source.baseline?.remoteHash
1239
+ || workspaceContentHash(serializePage(sourceWithoutTags(localDocument))) === source.baseline?.sourceHash);
1240
+ const localChanged = savedBodyHash !== undefined
1241
+ ? savedBodyHash !== sourceBodyHash
1242
+ : localKnown
1243
+ ? source.baseline.sourceHash !== sourceHash && !matchesLegacyBody
1060
1244
  : !markdown && sourceMatchesRemote !== true;
1061
1245
  // A first revision bypasses the old remote hash. Only the unbaselined
1062
1246
  // ProseMirror path above can compare this source with the site's body;
@@ -1077,6 +1261,26 @@ export async function pull(invocation) {
1077
1261
  const metadataEdited = metadataEditedLocally(source, summary.templateType);
1078
1262
  const keepLocal = markdown || localChanged;
1079
1263
  const conflicted = markdown ? remoteChanged : (localChanged || metadataEdited) && remoteChanged;
1264
+ const reconciled = reconcileTrackedTags({
1265
+ source, projection: tagProjection, sourceBytes, localDocument, markdown,
1266
+ localChanged: localChanged || !localKnown, conflicted,
1267
+ });
1268
+ const refresh = keepLocal || conflicted
1269
+ ? undefined
1270
+ : reconciled.tags === undefined
1271
+ ? serialized
1272
+ : serializePage(sourceWithTags(body, reconciled.tags));
1273
+ const refreshHash = refresh === undefined ? undefined : workspaceContentHash(refresh);
1274
+ const refreshBodyHash = taggedTemplate && refresh !== undefined ? remoteHash : undefined;
1275
+ bufferedBytes += (refresh ?? serialized).byteLength;
1276
+ if (bufferedBytes > WORKSPACE_LIMITS.pulledBodyBytes) {
1277
+ throw new SiteAuthoringError(
1278
+ "pages.pulled_bodies_too_large",
1279
+ `The tracked pages of this site exceed ${WORKSPACE_LIMITS.pulledBodyBytes} bytes, which is more than one `
1280
+ + "pull can hold before deciding whether any of them conflict.",
1281
+ { field: PAGES_DIRECTORY },
1282
+ );
1283
+ }
1080
1284
  if (metadataEdited && !remoteChanged) {
1081
1285
  onProgress(`Kept the local title, path and description of '${source.file}'; push them to send them.`);
1082
1286
  }
@@ -1110,6 +1314,7 @@ export async function pull(invocation) {
1110
1314
  ? {
1111
1315
  remoteHash,
1112
1316
  sourceHash: localChanged ? source.baseline?.sourceHash : sourceHash,
1317
+ ...(source.baseline?.sourceBodyHash === undefined ? {} : { sourceBodyHash: source.baseline.sourceBodyHash }),
1113
1318
  // Carried, never minted here: a kept source is only known to match
1114
1319
  // the site if a push or an earlier pull already said so. When this
1115
1320
  // pull adopts the site's title, path and description (they were not
@@ -1120,26 +1325,32 @@ export async function pull(invocation) {
1120
1325
  : {
1121
1326
  contentKey: markdown || metadataEdited || source.baseline.sourceHash === undefined
1122
1327
  ? source.baseline.contentKey
1123
- : pageContentKey(source.baseline.sourceHash, {
1124
- title: titleFromRead(page, summary),
1125
- path: pathFromRead(page, summary),
1126
- description,
1127
- author: summary.authorRef,
1128
- }),
1328
+ : pageContentKey(
1329
+ tagAwareComparison ? source.baseline.sourceBodyHash ?? source.baseline.sourceHash : source.baseline.sourceHash,
1330
+ {
1331
+ title: titleFromRead(page, summary),
1332
+ path: pathFromRead(page, summary),
1333
+ description,
1334
+ author: summary.authorRef,
1335
+ },
1336
+ ),
1129
1337
  }),
1338
+ ...reconciled.baseline,
1130
1339
  ...(revision === undefined ? {} : { revision }),
1131
1340
  ...(remoteDisplayDate === undefined ? {} : { displayDate: remoteDisplayDate }),
1132
1341
  ...(summary.authorRef === "" ? {} : { author: summary.authorRef }),
1133
1342
  }
1134
1343
  : {
1135
1344
  remoteHash,
1136
- sourceHash: workspaceContentHash(serialized),
1137
- contentKey: pageContentKey(workspaceContentHash(serialized), {
1345
+ sourceHash: refreshHash,
1346
+ ...(refreshBodyHash === undefined ? {} : { sourceBodyHash: refreshBodyHash }),
1347
+ contentKey: pageContentKey(reconciled.tags === undefined ? refreshHash : refreshBodyHash, {
1138
1348
  title: titleFromRead(page, summary),
1139
1349
  path: pathFromRead(page, summary),
1140
1350
  description,
1141
1351
  author: summary.authorRef,
1142
1352
  }),
1353
+ ...reconciled.baseline,
1143
1354
  ...(revision === undefined ? {} : { revision }),
1144
1355
  ...(remoteDisplayDate === undefined ? {} : { displayDate: remoteDisplayDate }),
1145
1356
  ...(summary.authorRef === "" ? {} : { author: summary.authorRef }),
@@ -1148,7 +1359,7 @@ export async function pull(invocation) {
1148
1359
  // refusal names that copy as where the site's document now is.
1149
1360
  ...(keepLocal || conflicted
1150
1361
  ? { baselineBody: serialized, baselineFile }
1151
- : { refresh: serialized, baselineFile }),
1362
+ : { refresh, baselineFile }),
1152
1363
  });
1153
1364
  if (remoteChanged) {
1154
1365
  // A refusal for this same version already worked this out, against a
@@ -1188,6 +1399,7 @@ export async function pull(invocation) {
1188
1399
  markdown,
1189
1400
  localChanged,
1190
1401
  body,
1402
+ taggedTemplate,
1191
1403
  });
1192
1404
  // Sanitized as one message: the page path is server data and the paths
1193
1405
  // are drawn from an untrusted document, and the same strings reach
@@ -1228,6 +1440,22 @@ export async function pull(invocation) {
1228
1440
  }
1229
1441
  }
1230
1442
 
1443
+ // A malformed snapshot on an untracked typed page must also fail before
1444
+ // touching the workspace. Spool each validated projection as it arrives
1445
+ // so a fresh pull need only hold one of those bodies in memory at a time.
1446
+ const stagedFresh = new Map();
1447
+ for (const summary of authorable) {
1448
+ if (tracked.has(summary.pageId) || !readsAuthoredTags(summary)) continue;
1449
+ const { entry, source } = await readFreshProjection(summary, pageFiles.get(summary.pageId));
1450
+ let stageFile;
1451
+ if (source !== undefined) {
1452
+ stageDirectory ??= await mkdtemp(path.join(tmpdir(), "taproot-pull-pages-"));
1453
+ stageFile = path.join(stageDirectory, String(stagedFresh.size));
1454
+ await writeFile(stageFile, source, { mode: 0o600 });
1455
+ }
1456
+ stagedFresh.set(summary.pageId, { entry, stageFile });
1457
+ }
1458
+
1231
1459
  // Internal state, written before the refusal below on purpose: it is what
1232
1460
  // makes "the site's version is preserved at ..." true. Nothing here is a
1233
1461
  // page source, and rewriting it is idempotent.
@@ -1281,6 +1509,7 @@ export async function pull(invocation) {
1281
1509
  isGenerated: summary.isGenerated,
1282
1510
  workspaceMode: PAGE_WORKSPACE_MODE_METADATA_ONLY,
1283
1511
  ...(summary.authorRef === "" ? {} : { author: summary.authorRef }),
1512
+ ...(summary.reviewAuthorMissing === undefined ? {} : { reviewAuthorMissing: summary.reviewAuthorMissing }),
1284
1513
  };
1285
1514
  if (isAuthorableTemplateType(summary.templateType)) {
1286
1515
  // This pull is reconciling the page, so the manifest below carries the
@@ -1320,40 +1549,13 @@ export async function pull(invocation) {
1320
1549
  manifestPages.push(entry);
1321
1550
  continue;
1322
1551
  }
1323
- onProgress(`Reading page '${summary.path}'.`);
1324
- const page = await getPage(client, summary.pageId, bodyStatusFor(summary));
1325
- const body = await workspaceBodyFromPage(page, summary.templateType);
1326
- entry.description = typeof page.shortDescription === "string" ? page.shortDescription : "";
1327
- entry.title = titleFromRead(page, summary);
1328
- entry.path = pathFromRead(page, summary);
1329
- if (body === undefined) {
1330
- // The server accepts and stores a body it never validates, so an
1331
- // unreadable one is a real state. It is reported rather than written
1332
- // as an empty document that a later push would send back.
1333
- onProgress(`Page '${summary.path}' has no readable body; snapshotting metadata only.`);
1334
- } else {
1335
- entry.file = pageFiles.get(summary.pageId);
1336
- if (isGeneratedTemplateType(summary.templateType)) entry.generated = generatedIdentity(body.data);
1337
- if (isLegalTemplateType(summary.templateType)) entry.legal = legalIdentity(body.data);
1338
- const source = Buffer.from(`${JSON.stringify(body, undefined, 2)}\n`, "utf8");
1339
- entry.workspaceMode = PAGE_WORKSPACE_MODE_EDITABLE;
1340
- entry.sourceFormat = pageSourceFormat(entry.file);
1341
- const revision = normalizePageBodyRevision(page.bodyRevision);
1342
- const displayDate = trackedDisplayDate(page, summary.templateType);
1343
- entry.baseline = {
1344
- remoteHash: canonicalDocumentHash(body),
1345
- sourceHash: workspaceContentHash(source),
1346
- contentKey: pageContentKey(workspaceContentHash(source), {
1347
- title: entry.title,
1348
- path: entry.path,
1349
- description: entry.description,
1350
- author: entry.author,
1351
- }),
1352
- ...(revision === undefined ? {} : { revision }),
1353
- ...(displayDate === undefined ? {} : { displayDate }),
1354
- ...(summary.authorRef === "" ? {} : { author: summary.authorRef }),
1355
- };
1356
- await writeWorkspaceFile(config.workspaceDir, entry.file, source);
1552
+ const staged = stagedFresh.get(summary.pageId);
1553
+ const fresh = staged === undefined
1554
+ ? await readFreshProjection(summary, pageFiles.get(summary.pageId))
1555
+ : { entry: staged.entry, source: staged.stageFile === undefined ? undefined : await readFile(staged.stageFile) };
1556
+ Object.assign(entry, fresh.entry);
1557
+ if (fresh.source !== undefined) {
1558
+ await writeWorkspaceFile(config.workspaceDir, entry.file, fresh.source);
1357
1559
  bodies += 1;
1358
1560
  const baselineFile = internalPageBaselineFile(summary.pageId);
1359
1561
  if (baselineFile !== undefined) await deleteWorkspaceFile(config.workspaceDir, baselineFile);
@@ -1422,7 +1624,13 @@ export async function pull(invocation) {
1422
1624
  ? { appearance: appearanceManifestEntry(pulledAppearance) }
1423
1625
  : {}
1424
1626
  ),
1425
- ...(presentationRevision === undefined ? {} : { presentation: presentationManifestEntry(presentationRevision) }),
1627
+ ...(presentationRevision === undefined ? {} : {
1628
+ presentation: presentationManifestEntry(
1629
+ presentationRevision, presentation.sitePublishingPreferences?.tagDestinations,
1630
+ tagDestinationCatalogSlugs(presentation.tagDestinationCatalog),
1631
+ presentation.sitePublishingPreferences?.recipeMetadataDestinations,
1632
+ ),
1633
+ }),
1426
1634
  ...(formsBaseline === undefined ? {} : { forms: formsBaseline }),
1427
1635
  ...(marketingBaseline === undefined ? {} : { [MARKETING_MANIFEST_KEY]: marketingBaseline }),
1428
1636
  pages: manifestPages,
@@ -1493,5 +1701,7 @@ export async function pull(invocation) {
1493
1701
  files: pulledSettings.map((entry) => entry.file),
1494
1702
  },
1495
1703
  });
1704
+ }).finally(async () => {
1705
+ if (stageDirectory !== undefined) await rm(stageDirectory, { recursive: true, force: true });
1496
1706
  });
1497
1707
  }
@@ -1,5 +1,11 @@
1
- import { mintStagingPreviewHandoff, withRefusalGuidance } from "../api.js";
1
+ import {
2
+ getStagingPreviewStatus,
3
+ mintStagingPreviewHandoff,
4
+ STAGING_HOSTING_SETUP_GUIDANCE,
5
+ withRefusalGuidance,
6
+ } from "../api.js";
2
7
  import { STAGING_REVIEW_SESSION_NOTE, VERB_STAGING_REVIEW } from "../constants.js";
8
+ import { SiteAuthoringError } from "../errors.js";
3
9
  import { openSession, successResult } from "../session.js";
4
10
 
5
11
  export const STAGING_REVIEW_GUIDANCE = "Open the URL once in a browser, then switch the site's theme toggle between "
@@ -20,6 +26,26 @@ export const STAGING_REVIEW_GUIDANCE = "Open the URL once in a browser, then swi
20
26
  export async function stagingReview(invocation) {
21
27
  const { client, siteId, now, onProgress } = await openSession(invocation);
22
28
  return await withRefusalGuidance(onProgress, "staging review", async () => {
29
+ const staging = await getStagingPreviewStatus(client, siteId);
30
+ if (!staging.ready) {
31
+ throw new SiteAuthoringError("staging.host_unavailable", STAGING_HOSTING_SETUP_GUIDANCE, { field: "Hosting" });
32
+ }
33
+ if (staging.hasStagedRelease === false) {
34
+ throw new SiteAuthoringError(
35
+ "staging.deployment_required",
36
+ "There is no acknowledged staging release to review. Run 'taproot-site deploy --staging' first "
37
+ + "or wait for the first staging deployment to finish.",
38
+ { field: "staging" },
39
+ );
40
+ }
41
+ if (staging.hasStagedRelease !== true) {
42
+ throw new SiteAuthoringError(
43
+ "staging.release_status_unavailable",
44
+ "Taproot could not confirm a staging release. Retry on an updated server, or run "
45
+ + "'taproot-site deploy --staging --handoff' when ready to stage a release.",
46
+ { field: "staging" },
47
+ );
48
+ }
23
49
  onProgress("Minting a fresh single-use staging review handoff.");
24
50
  const handoff = await mintStagingPreviewHandoff(client, siteId, { now, returnPath: invocation.reviewPath });
25
51
  onProgress(`Staging review handoff minted for ${handoff.stagingUrl}. ${STAGING_REVIEW_GUIDANCE}`);
@@ -3,10 +3,12 @@ import {
3
3
  getDeploySelection,
4
4
  getPublishingReadiness,
5
5
  getSiteHealth,
6
+ getStagingPreviewStatus,
6
7
  IMAGE_PROCESSING_STATE_COMPLETE,
7
8
  IMAGE_PROCESSING_STATE_FAILED,
8
9
  listDeployments,
9
10
  listSiteImages,
11
+ STAGING_HOSTING_SETUP_GUIDANCE,
10
12
  withRefusalGuidance,
11
13
  } from "../api.js";
12
14
  import { installedWhatsNew } from "../changelog.js";
@@ -162,6 +164,24 @@ async function summarizeStagedHealth(client, siteId, stagedDeploymentId, onProgr
162
164
  };
163
165
  }
164
166
 
167
+ async function reportStagingHosting(client, siteId, onProgress) {
168
+ let hosting;
169
+ try {
170
+ hosting = await getStagingPreviewStatus(client, siteId);
171
+ } catch (error) {
172
+ const reason = `Staging hosting status could not be read (${readFailureCode(error)}).`;
173
+ onProgress(reason);
174
+ return { readyKnown: false, reason };
175
+ }
176
+ const releaseStatus = hosting.hasStagedRelease === undefined ? {} : { hasStagedRelease: hosting.hasStagedRelease };
177
+ if (!hosting.ready) {
178
+ onProgress(`Staging hosting: no ready address. ${STAGING_HOSTING_SETUP_GUIDANCE}`);
179
+ return { ready: false, guidance: STAGING_HOSTING_SETUP_GUIDANCE, ...releaseStatus };
180
+ }
181
+ onProgress(`Staging hosting: ${hosting.stagingUrl}`);
182
+ return { ready: true, url: hosting.stagingUrl, ...releaseStatus };
183
+ }
184
+
165
185
  export async function status(invocation) {
166
186
  const { client, siteId, surface, platform, release, onProgress } = await openSession(invocation);
167
187
  const presentationOnly = surface === SURFACE_DOCS_PRESENTATION;
@@ -183,6 +203,7 @@ export async function status(invocation) {
183
203
  ? { ...reviewed, stagedPageIds: [], includeNavigation: false }
184
204
  : reviewed;
185
205
  const readiness = await getPublishingReadiness(client, siteId, selection);
206
+ const stagingHosting = await reportStagingHosting(client, siteId, onProgress);
186
207
  onProgress("Reading the deployment log.");
187
208
  const {
188
209
  deployments,
@@ -251,6 +272,7 @@ export async function status(invocation) {
251
272
  blockers: blockers.items,
252
273
  ...(blockers.truncated ? { blockersTruncated: true } : {}),
253
274
  },
275
+ stagingHosting,
254
276
  deployments: {
255
277
  // One page of the log, not the site's history. `listTruncated` says so
256
278
  // rather than letting `total` read as a count of every deployment the