@taprootio/site-authoring 0.56.0 → 0.60.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 (60) hide show
  1. package/README.md +27 -12
  2. package/package.json +2 -2
  3. package/src/api.js +16 -0
  4. package/src/block-flow.js +4 -2
  5. package/src/changelog.json +99 -0
  6. package/src/chrome-additions.js +106 -0
  7. package/src/chrome-features.js +43 -10
  8. package/src/chrome-input.js +137 -30
  9. package/src/chrome-report.js +4 -2
  10. package/src/cli.js +56 -17
  11. package/src/content/button-styles.js +27 -0
  12. package/src/content/components.js +76 -10
  13. package/src/content/free-form-section-registry.json +9 -0
  14. package/src/content/free-form-sections.js +55 -16
  15. package/src/content/markdown.js +133 -56
  16. package/src/content/media-presentation.js +37 -0
  17. package/src/content/tiptap-prosemirror.ts +26 -10
  18. package/src/credentials.js +2 -1
  19. package/src/delivery-check.js +10 -2
  20. package/src/font-catalog.js +9 -6
  21. package/src/footer-content.js +1 -1
  22. package/src/footer-contract.js +3 -0
  23. package/src/footer-draft-hash.js +1 -0
  24. package/src/heading-outline.js +94 -6
  25. package/src/image-description-contract.js +5 -3
  26. package/src/image-description-write.js +26 -0
  27. package/src/index.js +1 -0
  28. package/src/output.js +2 -1
  29. package/src/page-structure-checks.js +14 -25
  30. package/src/placed-image-ids.js +42 -17
  31. package/src/presentation-reference.js +63 -18
  32. package/src/problems.js +147 -4
  33. package/src/reference-help.js +102 -57
  34. package/src/site-check-findings.js +2 -3
  35. package/src/site-check-rules.json +0 -1
  36. package/src/site-health-findings.js +7 -9
  37. package/src/site-health-image-checks.js +4 -1
  38. package/src/site-health-precheck.js +23 -6
  39. package/src/site-navigation-groups.js +16 -0
  40. package/src/status-warning-paints.js +175 -0
  41. package/src/template-token-reach.json +13 -18
  42. package/src/theme-proposals.js +143 -55
  43. package/src/theme-resolve.js +14 -1
  44. package/src/theme-validation.js +70 -38
  45. package/src/token-reach.js +20 -0
  46. package/src/typed-page-reference.js +10 -3
  47. package/src/typed-pages.js +7 -7
  48. package/src/verbs/changelog.js +23 -2
  49. package/src/verbs/delivery-check.js +43 -9
  50. package/src/verbs/media-images.js +4 -4
  51. package/src/verbs/pages-push.js +38 -32
  52. package/src/verbs/plan.js +28 -20
  53. package/src/verbs/pull.js +179 -24
  54. package/src/verbs/theme-push.js +59 -15
  55. package/src/verbs/theme-resolve.js +109 -11
  56. package/src/verbs/validate.js +97 -16
  57. package/src/workspace-check.js +4 -4
  58. package/src/workspace-context-usage.js +180 -0
  59. package/src/workspace.js +12 -0
  60. package/test/fixtures/default-site-theme.json +1 -1
package/src/verbs/plan.js CHANGED
@@ -32,7 +32,7 @@ import { FOOTER_SETTINGS_FILE } from "../footer-workspace.js";
32
32
  import { workspaceFormKeys } from "../forms-workspace.js";
33
33
  import { preflightPageTagWrites } from "../page-tag-writes.js";
34
34
  import { latestPostsTagProblems } from "../latest-posts-tags.js";
35
- import { CHECK_AREA, collectProblems, problemsError, problemsOf, problemsWithinBudget, withinByteBudget } from "../problems.js";
35
+ import { CHECK_AREA, appendAll, collectProblems, omittedAreas, omittedProblemDigest, problemTotal, problemsError, problemsOf, problemsWithinBudget, withFullProblems, withinByteBudget } from "../problems.js";
36
36
  import { openSession, successResult, warnIfExternalWritesPaused } from "../session.js";
37
37
  import { IMAGE_IDENTIFIER, usedImageIds } from "../typed-pages.js";
38
38
  import { checkWorkspace } from "../workspace-check.js";
@@ -167,7 +167,7 @@ function step(name, status, detail = {}) {
167
167
  }
168
168
 
169
169
  function stepStatus(problems, name, changed) {
170
- if (problems.some((problem) => problem.area === STEP_AREAS[name])) return BLOCKED;
170
+ if (problems.some((problem) => problem.area === STEP_AREAS[name]) || omittedAreas(problems).has(STEP_AREAS[name])) return BLOCKED;
171
171
  return changed ? READY : NOTHING_TO_DO;
172
172
  }
173
173
 
@@ -228,7 +228,7 @@ async function preflight(session, invocation) {
228
228
  areas: PLANNED_AREAS,
229
229
  onProgress,
230
230
  });
231
- problems.push(...offline.problems);
231
+ appendAll(problems, offline.problems);
232
232
 
233
233
  // What the site holds of every image this plan depends on, read by id so a
234
234
  // large library cannot hide one: the recorded uploads, and the images the
@@ -254,7 +254,7 @@ async function preflight(session, invocation) {
254
254
  : { videos: [], truncated: false };
255
255
  const media = await collectProblems(problems, { area: CHECK_AREA.media }, async () =>
256
256
  await pendingMediaFiles(workspaceDir, mediaManifest, { imageStates, videos }));
257
- problems.push(...(media?.problems ?? []));
257
+ appendAll(problems, media?.problems ?? []);
258
258
  const pendingMedia = media?.files ?? [];
259
259
  const plannedMedia = {
260
260
  ...mediaManifest,
@@ -293,9 +293,10 @@ async function preflight(session, invocation) {
293
293
  onProgress,
294
294
  });
295
295
  const pageTagCapabilities = await preflightPageTagWrites(client, siteId, pages);
296
- problems.push(...pages.problems, ...latestPostsTagProblems(pages.planned, manifest, { sendingOnly: true }));
297
- problems.push(...await placedVideoProblems(client, siteId, pages.planned));
298
- problems.push(...(await placedFormProblems(client, siteId, pages.planned, () => workspaceFormKeys(workspaceDir))).problems);
296
+ appendAll(problems, pages.problems);
297
+ appendAll(problems, latestPostsTagProblems(pages.planned, manifest, { sendingOnly: true }));
298
+ appendAll(problems, await placedVideoProblems(client, siteId, pages.planned));
299
+ appendAll(problems, (await placedFormProblems(client, siteId, pages.planned, () => workspaceFormKeys(workspaceDir))).problems);
299
300
  const sending = pages.planned.filter((page) => !page.unchanged);
300
301
 
301
302
  // An image a page names must be one the site holds; an image this plan
@@ -312,7 +313,7 @@ async function preflight(session, invocation) {
312
313
  : new Map([...imageStates, ...await readImageStates(client, siteId, unread)]);
313
314
  for (const { file, imageId } of pageImages) {
314
315
  if (pageImageStates.has(imageId)) continue;
315
- problems.push(...problemsOf(new SiteAuthoringError(
316
+ appendAll(problems, problemsOf(new SiteAuthoringError(
316
317
  "plan.page_image_missing",
317
318
  `'${file}' names image ${imageId}, which this site does not hold (it was deleted, or belongs to another `
318
319
  + "site). Upload the file with media upload and refer to it by its media path.",
@@ -326,9 +327,9 @@ async function preflight(session, invocation) {
326
327
  theme = await comparePresentation(client, siteId, offline.presentation, manifest);
327
328
  // Only a theme step that would run can be refused.
328
329
  if (theme.changed && theme.baseline === undefined) {
329
- problems.push(...problemsOf(presentationPullRequired(), { area: CHECK_AREA.presentation }));
330
+ appendAll(problems, problemsOf(presentationPullRequired(), { area: CHECK_AREA.presentation }));
330
331
  } else if (theme.changed && theme.stale && !theme.replaying) {
331
- problems.push(...problemsOf(presentationMovedRefusal(theme), { area: CHECK_AREA.presentation }));
332
+ appendAll(problems, problemsOf(presentationMovedRefusal(theme), { area: CHECK_AREA.presentation }));
332
333
  }
333
334
  }
334
335
 
@@ -340,7 +341,7 @@ async function preflight(session, invocation) {
340
341
  ? undefined
341
342
  : computeFooterDraftHash(theme.current.sitePublishingPreferences?.footerSettings ?? {});
342
343
  if (footerChanged && liveFooterDraftHash !== undefined && liveFooterDraftHash !== manifest.footer?.expectedDraftHash) {
343
- problems.push(...problemsOf(new SiteAuthoringError(
344
+ appendAll(problems, problemsOf(new SiteAuthoringError(
344
345
  "footer.concurrent_modification",
345
346
  "The footer changed on the site after this workspace was pulled, so footer push would be refused. Pull, "
346
347
  + "reconcile the footer document, and plan again.",
@@ -352,12 +353,12 @@ async function preflight(session, invocation) {
352
353
  const unheld = (imageIds) => imageIds.filter((imageId) => imageStates.get(imageId) !== IMAGE_PROCESSING_STATE_COMPLETE);
353
354
  if (theme?.changed === true) {
354
355
  for (const imageId of unheld(appearanceImages)) {
355
- problems.push(...problemsOf(settingsImageMissing(imageId, "the appearance settings"), { area: CHECK_AREA.presentation }));
356
+ appendAll(problems, problemsOf(settingsImageMissing(imageId, "the appearance settings"), { area: CHECK_AREA.presentation }));
356
357
  }
357
358
  }
358
359
  if (footerChanged) {
359
360
  for (const imageId of unheld(footerImages)) {
360
- problems.push(...problemsOf(settingsImageMissing(imageId, "the footer"), {
361
+ appendAll(problems, problemsOf(settingsImageMissing(imageId, "the footer"), {
361
362
  area: CHECK_AREA.footer,
362
363
  file: FOOTER_SETTINGS_FILE,
363
364
  }));
@@ -395,7 +396,7 @@ async function preflight(session, invocation) {
395
396
  if (requireNavigationBaseline(manifest) !== live.revision) throw navigationMovedRefusal();
396
397
  } catch (error) {
397
398
  if (!(error instanceof SiteAuthoringError)) throw error;
398
- problems.push(...problemsOf(error, { area: CHECK_AREA.navigation, file: NAVIGATION_FILE_NAME }));
399
+ appendAll(problems, problemsOf(error, { area: CHECK_AREA.navigation, file: NAVIGATION_FILE_NAME }));
399
400
  }
400
401
  }
401
402
  }
@@ -438,7 +439,11 @@ async function preflight(session, invocation) {
438
439
  footer: [footerChanged, workspaceFooter === undefined ? "" : computeFooterContentHash(workspaceFooter), liveFooterDraftHash ?? ""],
439
440
  theme: theme === undefined ? [] : [theme.changeSetHash, theme.current.revision],
440
441
  navigation: [stableJson(offline.navigation?.navItems ?? null), stableJson(liveNavigation ?? null)],
441
- problems: problems.map((problem) => [problem.area ?? "", problem.file ?? "", problem.code, problem.field ?? ""]),
442
+ problems: [
443
+ ...problems.map((problem) => [problem.area ?? "", problem.file ?? "", problem.code, problem.field ?? ""]),
444
+ omittedProblemDigest(problems),
445
+ problemTotal(problems),
446
+ ],
442
447
  }), "utf8").digest("hex")}`;
443
448
  return {
444
449
  steps,
@@ -487,12 +492,13 @@ function planReport(planned) {
487
492
  // The problems get whatever the rest of the report leaves of the result's
488
493
  // bound, so a long plan still serializes.
489
494
  const rest = Buffer.byteLength(JSON.stringify(report), "utf8");
495
+ const total = problemTotal(problems);
490
496
  const shown = problemsWithinBudget(problems, LIMITS.githubOutputBytes - RESULT_ENVELOPE_BYTES - rest);
491
497
  return {
492
498
  ...report,
493
499
  problems: shown,
494
- problemCount: problems.length,
495
- ...(shown.length < problems.length ? { problemsTruncated: true } : {}),
500
+ problemCount: total,
501
+ ...(shown.length < total ? { problemsTruncated: true } : {}),
496
502
  };
497
503
  }
498
504
 
@@ -504,7 +510,7 @@ export async function plan(invocation) {
504
510
  session.onProgress(
505
511
  report.ready
506
512
  ? `Ready: run 'taproot-site apply --plan ${report.planHash}' to send it. Nothing was written.`
507
- : `${planned.problems.length} problem(s) block the plan; fix them and plan again. Nothing was written.`,
513
+ : `${problemTotal(planned.problems)} problem(s) block the plan; fix them and plan again. Nothing was written.`,
508
514
  );
509
515
  return successResult(VERB_PLAN, session.siteId, report);
510
516
  }
@@ -549,12 +555,14 @@ export async function apply(invocation) {
549
555
  onProgress("Re-planning to confirm the workspace and the site still match the plan.");
550
556
  const planned = await recordedPlan(session, invocation);
551
557
  if (planned.planHash !== invocation.planHash) {
552
- throw new SiteAuthoringError(
558
+ const stale = new SiteAuthoringError(
553
559
  "apply.plan_stale",
554
560
  "The workspace or the site changed since that plan was made, so nothing was applied. Run 'taproot-site plan' "
555
561
  + "again, read it, and apply the new planHash.",
556
562
  { field: "planHash", alternatives: [planned.planHash] },
557
- ).withProblems(planned.problems);
563
+ );
564
+ withFullProblems(stale, planned.problems);
565
+ throw stale;
558
566
  }
559
567
  if (planned.problems.length > 0) throw problemsError(planned.problems, "apply sent nothing; the plan has problems");
560
568
 
package/src/verbs/pull.js CHANGED
@@ -18,6 +18,7 @@ import {
18
18
  withRefusalGuidance,
19
19
  } from "../api.js";
20
20
  import {
21
+ LIMITS,
21
22
  REFUSAL_CAPABILITY_MISSING,
22
23
  REFUSAL_UNCLASSIFIED,
23
24
  SURFACE_DOCS_PRESENTATION,
@@ -38,7 +39,7 @@ import { projectRedirectMapForWorkspace, REDIRECTS_FILE_NAME } from "../redirect
38
39
  import { navigationManifestEntry } from "../navigation-workspace.js";
39
40
  import { redirectsManifestEntry } from "../redirects-workspace.js";
40
41
  import { projectNavigationForWorkspace } from "./nav-push.js";
41
- import { parseFrontMatter } from "./pages-push.js";
42
+ import { parseFrontMatter, readWorkspacePageSource } from "./pages-push.js";
42
43
  import { boundedList, openSession, successResult } from "../session.js";
43
44
  import {
44
45
  projectSettingsGroup,
@@ -478,13 +479,16 @@ function bodyStatusFor(summary) {
478
479
  function assignPageFiles(pages, tracked, kept = new Set()) {
479
480
  // `kept` holds files this pull must not write over: the sources of retired
480
481
  // generated pages, which may hold unpushed edits (TR01195).
481
- const reserved = new Set([...pages.map((summary) => `${PAGES_DIRECTORY}/${summary.pageId}.pm.json`), ...kept]);
482
+ // Names compare case-insensitively: pages/ABOUT.pm.json and pages/about.pm.json are one file on macOS and Windows.
483
+ const key = (file) => file.toLowerCase();
484
+ const reserved = new Set([...pages.map((summary) => `${PAGES_DIRECTORY}/${summary.pageId}.pm.json`), ...kept].map(key));
485
+ const keptKeys = new Set([...kept].map(key));
482
486
  const claimed = new Set();
483
487
  const assigned = new Map();
484
488
  for (const summary of pages) {
485
489
  const source = tracked.get(summary.pageId);
486
490
  if (source === undefined) continue;
487
- claimed.add(source.file);
491
+ claimed.add(key(source.file));
488
492
  assigned.set(summary.pageId, source.file);
489
493
  }
490
494
  const homeFirst = [...pages].sort((left, right) => {
@@ -498,13 +502,13 @@ function assignPageFiles(pages, tracked, kept = new Set()) {
498
502
  if (assigned.has(summary.pageId)) continue;
499
503
  const fallback = `${PAGES_DIRECTORY}/${summary.pageId}.pm.json`;
500
504
  const preferred = `${PAGES_DIRECTORY}/${workspaceFileNameForPage(summary.path, summary.pageId)}.pm.json`;
501
- const available = preferred === fallback || (!claimed.has(preferred) && !reserved.has(preferred));
505
+ const available = preferred === fallback || (!claimed.has(key(preferred)) && !reserved.has(key(preferred)));
502
506
  const file = available ? preferred : fallback;
503
507
  // The page-id fallback is unique by construction, so the only way it is
504
508
  // already taken is a tracked source that was renamed onto another page's
505
509
  // reserved name by hand. Guessing which page owns it is exactly the
506
510
  // ambiguity this task exists to remove.
507
- if (claimed.has(file)) {
511
+ if (claimed.has(key(file)) || keptKeys.has(key(file))) {
508
512
  throw new SiteAuthoringError(
509
513
  "pages.source_conflict",
510
514
  `Page ${summary.pageId} has no free workspace file: '${file}' is already the tracked source of another `
@@ -512,7 +516,7 @@ function assignPageFiles(pages, tracked, kept = new Set()) {
512
516
  { field: file },
513
517
  );
514
518
  }
515
- claimed.add(file);
519
+ claimed.add(key(file));
516
520
  assigned.set(summary.pageId, file);
517
521
  }
518
522
  return assigned;
@@ -585,33 +589,165 @@ async function resolveTrackedSources(workspaceDir, pages, registry, onProgress)
585
589
  * scheme; see `withoutSupersededRemoteHashes`.
586
590
  */
587
591
  async function readSourceRegistry(workspaceDir, siteId) {
588
- if (!await workspaceFileExists(workspaceDir, MANIFEST_FILE_NAME)) return new Map();
592
+ if (!await workspaceFileExists(workspaceDir, MANIFEST_FILE_NAME)) return { registry: new Map(), pending: [] };
589
593
  let parsed;
590
594
  try {
591
595
  parsed = await readWorkspaceJson(workspaceDir, MANIFEST_FILE_NAME, WORKSPACE_LIMITS.manifestBytes);
592
596
  } catch {
593
- return new Map();
597
+ return { registry: new Map(), pending: [] };
594
598
  }
595
599
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed) || parsed.siteId !== siteId) {
596
- return new Map();
600
+ return { registry: new Map(), pending: [] };
597
601
  }
598
602
  const manifest = withoutRetiredReadOnlyProjections(parsed);
603
+ // A new source's metadata lives only in its pending entry until its first save.
604
+ const pending = [];
599
605
  for (const entry of Array.isArray(manifest.pages) ? manifest.pages : []) {
600
606
  if (entry === null || typeof entry !== "object" || Array.isArray(entry) || isCanonicalUuid(entry.pageId)) continue;
601
607
  if (!["file", "title", "path"].some((field) => Object.hasOwn(entry, field))) continue;
602
- const field = sanitizeDiagnostic(entry.file, MANIFEST_FILE_NAME);
603
- const label = sanitizeDiagnostic(entry.path, field);
604
- // A new source's metadata lives only here until its first save.
608
+ pending.push(entry);
609
+ }
610
+ const registry = pageSourceRegistry(manifest);
611
+ return {
612
+ registry: parsed.manifestVersion === MANIFEST_VERSION ? registry : withoutSupersededRemoteHashes(registry),
613
+ pending,
614
+ };
615
+ }
616
+
617
+ /** The manifest is read back under a byte bound, so a pull that would write a larger one is refused first. */
618
+ export function requireManifestRoom(pending, live) {
619
+ const bytes = (value) => Buffer.byteLength(JSON.stringify(value), "utf8");
620
+ // A pulled page entry also carries a baseline hash and authored fields; 512 bytes covers them.
621
+ const estimate = pending.reduce((total, entry) => total + bytes(entry), 0)
622
+ + live.reduce((total, summary) => total + bytes(summary) + 512, 0);
623
+ if (estimate > WORKSPACE_LIMITS.manifestBytes) {
605
624
  throw new SiteAuthoringError(
606
- "pages.source_conflict",
607
- `The pending page entry '${label}' has no server page id. Pull would discard its saved metadata. `
608
- + "Save the draft with 'taproot-site pages push' first, or back up and move its source file and manifest "
609
- + "entry before running 'taproot-site pull' again. Nothing was changed.",
610
- { field },
625
+ "pull.manifest_too_large",
626
+ `The pull manifest would exceed ${WORKSPACE_LIMITS.manifestBytes} bytes with the pending page entries it keeps. `
627
+ + "Save or remove pending entries, then run 'taproot-site pull' again. Nothing was changed.",
611
628
  );
612
629
  }
613
- const registry = pageSourceRegistry(manifest);
614
- return parsed.manifestVersion === MANIFEST_VERSION ? registry : withoutSupersededRemoteHashes(registry);
630
+ }
631
+
632
+ function pendingRefusal(entry, reason) {
633
+ const field = sanitizeDiagnostic(entry.file, MANIFEST_FILE_NAME);
634
+ const label = sanitizeDiagnostic(entry.path, field);
635
+ return new SiteAuthoringError(
636
+ "pages.source_conflict",
637
+ `The pending page entry '${label}' has no server page id and ${reason}. Pull would discard its saved metadata. `
638
+ + "Save the draft with 'taproot-site pages push' first (a legal page needs 'taproot-site login --legal-drafts', "
639
+ + "then 'taproot-site --legal-drafts pages push'), or back up and move its source file and manifest "
640
+ + "entry before running 'taproot-site pull' again. Nothing was changed.",
641
+ { field },
642
+ );
643
+ }
644
+
645
+ /**
646
+ * Refuses, before any request, a pending entry pull cannot carry as it is: no file on disk, no usable path,
647
+ * or a path or file another pending entry already uses.
648
+ */
649
+ async function requireCarriablePendingEntries(workspaceDir, pending) {
650
+ const seenPaths = new Set();
651
+ const seenFiles = new Set();
652
+ const effectivePaths = new Map();
653
+ for (const entry of pending) {
654
+ // Like pages push, only an entry with no pageId at all is a pending draft.
655
+ if (entry.pageId !== undefined) {
656
+ const field = sanitizeDiagnostic(entry.file, MANIFEST_FILE_NAME);
657
+ throw new SiteAuthoringError(
658
+ "pages.source_conflict",
659
+ `The page entry '${sanitizeDiagnostic(entry.path, field)}' has a pageId that is not a canonical page id. Remove the `
660
+ + "pageId to keep the entry as a draft, or replace it with the page's real id, then run 'taproot-site pull' again. "
661
+ + "Nothing was changed.",
662
+ { field },
663
+ );
664
+ }
665
+ const file = typeof entry.file === "string" ? entry.file : undefined;
666
+ if (file === undefined || !await workspaceFileExists(workspaceDir, file)) {
667
+ throw pendingRefusal(entry, "has no source file on disk");
668
+ }
669
+ if (pageSourceFormat(file) === undefined || !isDiscoverablePageSource(file)) {
670
+ throw pendingRefusal(entry, "names a file that is not a page source");
671
+ }
672
+ const paths = await pendingEffectivePaths(workspaceDir, entry);
673
+ if (paths.length === 0) throw pendingRefusal(entry, "has no usable path");
674
+ if (paths.some((path) => seenPaths.has(path)) || seenFiles.has(file.toLowerCase())) {
675
+ throw pendingRefusal(entry, "shares its path or source file with another pending entry");
676
+ }
677
+ for (const path of paths) seenPaths.add(path);
678
+ seenFiles.add(file.toLowerCase());
679
+ effectivePaths.set(entry, paths);
680
+ }
681
+ return effectivePaths;
682
+ }
683
+
684
+ /** The page paths a pending source claims: a Markdown source's front matter wins over its entry, as in pages push. */
685
+ async function pendingEffectivePaths(workspaceDir, entry) {
686
+ if (pageSourceFormat(entry.file) !== PAGE_SOURCE_FORMAT_MARKDOWN) {
687
+ const path = normalizePagePath(entry.path);
688
+ return path === undefined ? [] : [path];
689
+ }
690
+ try {
691
+ const source = await readWorkspacePageSource({ workspaceDir, file: entry.file, manifestEntry: entry });
692
+ return source.pagePath === undefined ? source.pathClaims : [source.pagePath];
693
+ } catch {
694
+ return [];
695
+ }
696
+ }
697
+
698
+ /**
699
+ * The pending entries this pull carries into the new manifest, unchanged, with their files.
700
+ *
701
+ * Once the page list is read, an entry is carried only when nothing can claim its path or file: no live page
702
+ * holds its path, no tracked source is the same file, and the listing was complete. Anything else refuses
703
+ * before a byte is written, so the saved metadata is never discarded.
704
+ */
705
+ function requireNoPendingCollisions(pending, { live, tracked, truncated, retiredFiles, effectivePaths }) {
706
+ if (pending.length === 0) return;
707
+ if (truncated) throw pendingRefusal(pending[0], "cannot be checked against a page list this pull could not read in full");
708
+ const livePaths = new Set(live.map((summary) => normalizePagePath(summary.path) ?? summary.path));
709
+ const takenFiles = new Set([...[...tracked.values()].map((source) => source.file), ...retiredFiles].map((file) => file.toLowerCase()));
710
+ for (const entry of pending) {
711
+ if (effectivePaths.get(entry).some((path) => livePaths.has(path))) throw pendingRefusal(entry, "has a path a page on the site holds");
712
+ if (takenFiles.has(entry.file.toLowerCase())) throw pendingRefusal(entry, "shares its source file with another page");
713
+ }
714
+ }
715
+
716
+ const PENDING_SAVE_REMINDER = "Save kept pending pages with 'taproot-site pages push'.";
717
+ const PENDING_LEGAL_REMINDER = "A legal page needs 'taproot-site login --legal-drafts', then 'taproot-site --legal-drafts pages push'.";
718
+
719
+ /** What a pull tells the author about the pending entries it kept. */
720
+ async function describeKeptPending(workspaceDir, entries, effectivePaths) {
721
+ const items = [];
722
+ let legal = false;
723
+ // One source at a time: each read can be as large as a document.
724
+ for (const entry of entries) {
725
+ try {
726
+ legal ||= (await readWorkspaceJson(workspaceDir, entry.file, WORKSPACE_LIMITS.documentBytes))?.template === TEMPLATE_LEGAL;
727
+ } catch {
728
+ // A Markdown source or an unreadable one is not a legal document.
729
+ }
730
+ // The path a targeted push will find: a Markdown source's front matter wins over its entry.
731
+ items.push({ file: entry.file, path: displayPagePath(effectivePaths.get(entry)?.[0] ?? entry.path ?? "") });
732
+ }
733
+ return {
734
+ count: items.length,
735
+ items,
736
+ reminder: legal ? `${PENDING_SAVE_REMINDER} ${PENDING_LEGAL_REMINDER}` : PENDING_SAVE_REMINDER,
737
+ };
738
+ }
739
+
740
+ /** Keeps the count and shrinks the item list until the block fits the bytes the rest of the result leaves. */
741
+ function fitKeptPending(block, byteBudget) {
742
+ const shown = [];
743
+ let used = Buffer.byteLength(JSON.stringify({ ...block, items: [], itemsTruncated: true }), "utf8");
744
+ for (const item of block.items.slice(0, MAXIMUM_REPORTED)) {
745
+ const size = Buffer.byteLength(JSON.stringify(item), "utf8") + 1;
746
+ if (used + size > byteBudget) break;
747
+ shown.push(item);
748
+ used += size;
749
+ }
750
+ return { ...block, items: shown, ...(shown.length < block.items.length ? { itemsTruncated: true } : {}) };
615
751
  }
616
752
 
617
753
  /**
@@ -806,7 +942,8 @@ export async function pull(invocation) {
806
942
 
807
943
  await requireWorkspaceBelongsToSite(config.workspaceDir, siteId);
808
944
 
809
- const registry = await readSourceRegistry(config.workspaceDir, siteId);
945
+ const { registry, pending: pendingEntries } = await readSourceRegistry(config.workspaceDir, siteId);
946
+ const pendingPaths = await requireCarriablePendingEntries(config.workspaceDir, pendingEntries);
810
947
 
811
948
  // A managed Docs site has no pages, navigation, or redirects of its own to
812
949
  // snapshot (TR00790): the Docs shell takes those from the artifact, and the
@@ -953,10 +1090,14 @@ export async function pull(invocation) {
953
1090
  );
954
1091
  }
955
1092
  }
1093
+ const retiredFiles = retiredGeneratedSources.map((source) => source.file);
1094
+ requireNoPendingCollisions(pendingEntries, { live, tracked, truncated, retiredFiles, effectivePaths: pendingPaths });
1095
+ requireManifestRoom(pendingEntries, live);
1096
+ const keptPendingEntries = pendingEntries;
956
1097
  const pageFiles = assignPageFiles(
957
1098
  authorable,
958
1099
  tracked,
959
- new Set(retiredGeneratedSources.map((source) => source.file)),
1100
+ new Set([...retiredFiles, ...keptPendingEntries.map((entry) => entry.file)]),
960
1101
  );
961
1102
 
962
1103
  // A fresh destination has no ownership baseline. Protect legal drafts even
@@ -1678,11 +1819,21 @@ export async function pull(invocation) {
1678
1819
  }),
1679
1820
  ...(formsBaseline === undefined ? {} : { forms: formsBaseline }),
1680
1821
  ...(marketingBaseline === undefined ? {} : { [MARKETING_MANIFEST_KEY]: marketingBaseline }),
1681
- pages: manifestPages,
1822
+ pages: [...manifestPages, ...keptPendingEntries],
1682
1823
  ...(retiredGeneratedSources.length === 0 ? {} : { retiredGeneratedSources }),
1683
1824
  };
1684
1825
  await writeManifest(config.workspaceDir, manifest);
1685
- onProgress(`Wrote ${MANIFEST_FILE_NAME} describing ${manifestPages.length} pages.`);
1826
+ // TR01420: count every manifest entry, so the line agrees with the file.
1827
+ onProgress(
1828
+ `Wrote ${MANIFEST_FILE_NAME} describing ${manifest.pages.length} pages`
1829
+ + `${keptPendingEntries.length === 0 ? "" : ` (${keptPendingEntries.length} kept pending)`}.`,
1830
+ );
1831
+ const keptPendingPages = keptPendingEntries.length === 0
1832
+ ? undefined
1833
+ : await describeKeptPending(config.workspaceDir, keptPendingEntries, pendingPaths);
1834
+ if (keptPendingPages !== undefined) {
1835
+ onProgress(`Kept ${keptPendingPages.count} pending page(s) that were never saved. ${keptPendingPages.reminder}`);
1836
+ }
1686
1837
  if (revisionsRecordedWithoutBodyComparison > 0) {
1687
1838
  onProgress(
1688
1839
  `revision recorded for ${revisionsRecordedWithoutBodyComparison} pages that had none; bodies were not compared`,
@@ -1704,7 +1855,7 @@ export async function pull(invocation) {
1704
1855
  })),
1705
1856
  MAXIMUM_REPORTED,
1706
1857
  );
1707
- return successResult(VERB_PULL, siteId, {
1858
+ const result = successResult(VERB_PULL, siteId, {
1708
1859
  manifestFile: MANIFEST_FILE_NAME,
1709
1860
  ...(presentationOnly ? { authoringSurface: SURFACE_DOCS_PRESENTATION } : {}),
1710
1861
  pages: {
@@ -1746,6 +1897,10 @@ export async function pull(invocation) {
1746
1897
  files: pulledSettings.map((entry) => entry.file),
1747
1898
  },
1748
1899
  });
1900
+ if (keptPendingPages === undefined) return result;
1901
+ // Result bytes after the workspace was rewritten must never overflow, so the list gives way first.
1902
+ const room = LIMITS.githubOutputBytes - Buffer.byteLength(JSON.stringify(result), "utf8") - 2048;
1903
+ return { ...result, keptPendingPages: fitKeptPending(keptPendingPages, Math.max(0, room)) };
1749
1904
  }).finally(async () => {
1750
1905
  if (stageDirectory !== undefined) await rm(stageDirectory, { recursive: true, force: true });
1751
1906
  });
@@ -11,8 +11,20 @@ import {
11
11
  tagDestinationCatalogSlugs,
12
12
  footerPresentationOverlay,
13
13
  } from "../appearance-contract.js";
14
- import { captureChromeResources, selectNameReportEligibility } from "../chrome-input.js";
14
+ import { captureChromeResources, describeSkippedLinks, selectNameReportEligibility } from "../chrome-input.js";
15
15
  import { completeChromeReport } from "../chrome-report.js";
16
+ import { fitChromeAdditions } from "../chrome-additions.js";
17
+ import { readWorkspaceContextUsage } from "../workspace-context-usage.js";
18
+ import {
19
+ contextScopedNames,
20
+ hasContextScopedStatusWarning,
21
+ notCountedLine,
22
+ statusPaintFields,
23
+ statusPaintLines,
24
+ statusWarningPaints,
25
+ usageUnavailableLine,
26
+ } from "../status-warning-paints.js";
27
+ import { sharedThemeContextNames } from "../content/free-form-sections.js";
16
28
  import { REFUSAL_UNCLASSIFIED, VERB_THEME_PUSH } from "../constants.js";
17
29
  import { MISSING_SETTING_MESSAGE, SiteAuthoringError } from "../errors.js";
18
30
  import { projectFooterSettingsForWorkspace, validateFooterDocument } from "../footer-contract.js";
@@ -429,8 +441,11 @@ export async function comparePresentation(client, siteId, validated, manifest) {
429
441
  };
430
442
  }
431
443
 
432
- function reportPushWarnings(themes, onProgress) {
433
- for (const warning of themes.warnings) onProgress(`Espalier warning: ${warning}`);
444
+ function reportPushWarnings(themes, onProgress, paints = statusWarningPaints(themes.warnings)) {
445
+ for (const warning of themes.warnings) {
446
+ onProgress(`Espalier warning: ${warning}`);
447
+ for (const line of statusPaintLines(paints, warning)) onProgress(line);
448
+ }
434
449
  if (themes.warningsTruncated) {
435
450
  const hidden = themes.warningCount - themes.warnings.length;
436
451
  onProgress(
@@ -444,15 +459,25 @@ function reportPushWarnings(themes, onProgress) {
444
459
  };
445
460
  }
446
461
 
447
- async function completePushWarnings(appearance, resources, evidence, onProgress, chromeDependencies) {
462
+ async function completePushWarnings(appearance, resources, evidence, onProgress, chromeDependencies, usageRead) {
448
463
  const { themes } = appearance;
449
- const { warnings } = await completeChromeReport({
464
+ const { warnings, skippedNavigationLinks } = await completeChromeReport({
450
465
  themes,
451
466
  appearance,
452
467
  resources,
453
468
  nameReportEnabled: selectNameReportEligibility(evidence),
454
469
  }, chromeDependencies);
455
- return reportPushWarnings(withChromeWarnings(themes, warnings), onProgress);
470
+ const bounded = withChromeWarnings(themes, warnings);
471
+ const paints = statusWarningPaints(bounded.warnings, { usage: usageRead?.usage });
472
+ const reported = reportPushWarnings(bounded, onProgress, paints);
473
+ for (const line of [...notCountedLine(usageRead?.skipped), ...usageUnavailableLine(usageRead?.unavailable)]) onProgress(line);
474
+ if (skippedNavigationLinks?.count > 0) onProgress(describeSkippedLinks(skippedNavigationLinks));
475
+ return {
476
+ warnings: reported,
477
+ ...statusPaintFields(bounded.warnings, paints),
478
+ ...(usageRead?.skipped === undefined ? {} : { contextUsageSkipped: usageRead.skipped }),
479
+ ...(skippedNavigationLinks?.count > 0 ? { skippedNavigationLinks } : {}),
480
+ };
456
481
  }
457
482
 
458
483
  async function saveComparedPresentation(session, comparison) {
@@ -570,7 +595,8 @@ export async function themePush(invocation, chromeDependencies) {
570
595
  // saved. Context-only differences are theme push's own to write.
571
596
  if (!dryRun) requireFooterContentPushed(appearanceContext.footer, publishing.footerSettings);
572
597
  const proposedFooter = dryRun && hasFooterContentEdits(appearanceContext.footer, publishing.footerSettings)
573
- ? validateFooterDocument(publishing.footerSettings, appearanceContext)
598
+ // Shape and images only: the chrome inventory classifies page targets, and footer push checks membership.
599
+ ? validateFooterDocument(publishing.footerSettings, { knownImageIds: appearanceContext.knownImageIds })
574
600
  : undefined;
575
601
  const baseline = readPresentationBaseline(appearanceContext.manifest);
576
602
  if (!dryRun && baseline === undefined) {
@@ -582,6 +608,7 @@ export async function themePush(invocation, chromeDependencies) {
582
608
  onProgress(`Validated the complete light/dark theme pair and ${scalarOperations.length} appearance settings.`);
583
609
  let comparison;
584
610
  let resources;
611
+ let usageRead;
585
612
  let saved;
586
613
  try {
587
614
  // Both modes check the complete proposed context state against the site.
@@ -604,6 +631,21 @@ export async function themePush(invocation, chromeDependencies) {
604
631
  // Keep the optional snapshot on this side of the save. Report completion
605
632
  // never reads settings or manifests after the response has arrived.
606
633
  resources = await captureChromeResources({ ...appearanceContext, siteId, workspaceDir: config.workspaceDir });
634
+ // Read before the save so the evidence is the workspace the author pushed.
635
+ // Optional evidence: a failed read leaves usage unknown and never blocks the save.
636
+ // Reading converts every page, so skip it unless a warning names a context the usage could annotate.
637
+ if (hasContextScopedStatusWarning(validated.themes.warnings)) usageRead = await readWorkspaceContextUsage({
638
+ workspaceDir: config.workspaceDir,
639
+ siteId,
640
+ // The candidate theme's full shared list, so a page naming a context only the candidate defines still counts.
641
+ themeContexts: sharedThemeContextNames(validated.style.lightTheme, validated.style.darkTheme),
642
+ manifest: appearanceContext.manifest,
643
+ mediaManifest: resources.mediaManifest,
644
+ header: validated.header,
645
+ footerSettings: validated.publishing?.footerSettings,
646
+ content: invocation.content,
647
+ contexts: contextScopedNames(validated.themes.warnings),
648
+ }).catch(() => undefined);
607
649
  if (!dryRun) saved = await saveComparedPresentation(session, comparison);
608
650
  } catch (error) {
609
651
  reportPushWarnings(validated.themes, onProgress);
@@ -618,7 +660,7 @@ export async function themePush(invocation, chromeDependencies) {
618
660
  const footerContent = proposedFooter === undefined
619
661
  ? undefined
620
662
  : compareFooterContent(appearanceContext.footer, comparison.currentFooter, proposedFooter);
621
- const warnings = await completePushWarnings(
663
+ const pushWarnings = await completePushWarnings(
622
664
  validated,
623
665
  {
624
666
  ...resources,
@@ -629,6 +671,7 @@ export async function themePush(invocation, chromeDependencies) {
629
671
  { current, manifest },
630
672
  onProgress,
631
673
  chromeDependencies,
674
+ usageRead,
632
675
  );
633
676
  for (const entry of differences) {
634
677
  if (entry.paths.length === 0 && entry.truncated !== true) continue;
@@ -656,7 +699,7 @@ export async function themePush(invocation, chromeDependencies) {
656
699
  );
657
700
  }
658
701
  onProgress("Dry run: nothing was written.");
659
- return successResult(VERB_THEME_PUSH, siteId, {
702
+ return fitChromeAdditions(successResult(VERB_THEME_PUSH, siteId, {
660
703
  dryRun: true,
661
704
  revision: {
662
705
  ...(baseline === undefined ? {} : { baseline: baseline.revision }),
@@ -673,8 +716,8 @@ export async function themePush(invocation, chromeDependencies) {
673
716
  differences,
674
717
  ...(footerContent === undefined ? {} : { footerContent }),
675
718
  ...(tagDestinationWarnings === undefined ? {} : { tagDestinationWarnings }),
676
- warnings,
677
- });
719
+ ...pushWarnings,
720
+ }));
678
721
  }
679
722
 
680
723
  const { presentation, applied } = saved;
@@ -682,7 +725,7 @@ export async function themePush(invocation, chromeDependencies) {
682
725
  reportPushWarnings(validated.themes, onProgress);
683
726
  throw error;
684
727
  });
685
- const warnings = await completePushWarnings(
728
+ const pushWarnings = await completePushWarnings(
686
729
  {
687
730
  ...validated,
688
731
  footerPresentation: { context: projectedFooter.context, logoVariant: projectedFooter.logoVariant },
@@ -691,6 +734,7 @@ export async function themePush(invocation, chromeDependencies) {
691
734
  { saved, current, manifest },
692
735
  onProgress,
693
736
  chromeDependencies,
737
+ usageRead,
694
738
  );
695
739
  onProgress(
696
740
  applied
@@ -704,10 +748,10 @@ export async function themePush(invocation, chromeDependencies) {
704
748
  ...scalarOperations.map((operation) => `${operation.settingsType}.${operation.setting}`),
705
749
  ...THEME_SETTINGS.map((setting) => `${SETTINGS_TYPE_TAPROOT_STYLES}.${setting}`),
706
750
  ];
707
- return successResult(VERB_THEME_PUSH, siteId, {
751
+ return fitChromeAdditions(successResult(VERB_THEME_PUSH, siteId, {
708
752
  applied,
709
753
  revision: presentation.revision,
710
754
  written: boundedList(written, 100),
711
- warnings,
712
- });
755
+ ...pushWarnings,
756
+ }));
713
757
  }