@anthusai/papyrus 1.10.0 → 1.11.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 (61) hide show
  1. package/amplify/data/resource.js +3 -3
  2. package/amplify/data/resource.ts +3 -3
  3. package/amplify/functions/category-action/handler.ts +18 -18
  4. package/amplify/functions/console-chat-responder/src/main.rs +1 -1
  5. package/amplify/functions/content-actions/handler.py +23 -0
  6. package/amplify/functions/content-actions/requirements.txt +1 -1
  7. package/amplify/functions/content-actions/resource.js +1 -1
  8. package/amplify/functions/content-actions/resource.ts +1 -1
  9. package/amplify/functions/renditions/requirements.txt +1 -1
  10. package/amplify/functions/shared/slack-events.ts +2 -2
  11. package/amplify/publication/renditions-function.js +1 -1
  12. package/amplify/publication/renditions-function.ts +1 -1
  13. package/app/api/local-preview/derive/route.ts +28 -0
  14. package/app/api/local-preview/media/route.ts +25 -0
  15. package/app/globals.css +28 -28
  16. package/app/layout.tsx +8 -5
  17. package/app/newsroom/[section]/[...selection]/page.tsx +0 -1
  18. package/app/newsroom/[section]/page.tsx +0 -1
  19. package/app/newsroom/insights/[threadId]/page.tsx +5 -16
  20. package/app/newsroom/insights/page.tsx +4 -12
  21. package/components/board-card-excerpts.tsx +45 -0
  22. package/components/markus-ir-preview.tsx +47 -2
  23. package/components/news-desk-page.tsx +0 -1
  24. package/components/news-desk-taxonomy-client.ts +25 -220
  25. package/components/newsroom-article-editor.tsx +135 -39
  26. package/components/newsroom-assignment-detail.tsx +35 -1
  27. package/components/newsroom-board-view.tsx +29 -7
  28. package/components/newsroom-newsprint-board.css +9 -2
  29. package/components/newsroom-ops-overview.tsx +27 -5
  30. package/components/newsroom-organizer-shell.tsx +25 -7
  31. package/components/newsroom-organizer.css +196 -4
  32. package/components/priming-proof-page.tsx +17 -8
  33. package/components/prospectus-account-chooser.tsx +103 -0
  34. package/components/story-reporting-trail-client.ts +91 -0
  35. package/components/story-reporting-trail.tsx +115 -0
  36. package/components/topic-steering-workspace.tsx +154 -671
  37. package/components/ui/sheet.tsx +1 -0
  38. package/components/wiki-concepts-view.tsx +153 -0
  39. package/components/wiki-index-client.ts +51 -0
  40. package/lib/content-actions-client.ts +3 -0
  41. package/lib/content-actions-demo.ts +55 -3
  42. package/lib/content-item-lifecycle.ts +4 -2
  43. package/lib/front-matter-fields.ts +42 -0
  44. package/lib/local-preview-seed.ts +33 -0
  45. package/lib/newsroom-articles.ts +2 -0
  46. package/lib/newsroom-board.ts +4 -0
  47. package/lib/newsroom-forum-routes.ts +2 -43
  48. package/lib/newsroom-index-filters.ts +3 -40
  49. package/lib/newsroom-media-backend.ts +5 -0
  50. package/lib/newsroom-nav.ts +1 -3
  51. package/lib/newsroom-organizer-nav.ts +5 -12
  52. package/lib/newsroom-section-routing.ts +1 -1
  53. package/lib/newsroom-sections.ts +12 -0
  54. package/lib/papyrus-web-locations.ts +3 -24
  55. package/lib/priming-proof-report.ts +1 -0
  56. package/lib/semantic-graph.ts +5 -5
  57. package/lib/site-brand.ts +9 -0
  58. package/lib/story-reporting-trail.ts +106 -0
  59. package/lib/wiki.ts +56 -0
  60. package/package.json +12 -1
  61. package/routes.manifest.json +23 -7
@@ -45,6 +45,7 @@ function SheetContent({
45
45
  <DialogPrimitive.Backdrop
46
46
  className={cn(
47
47
  "fixed inset-0 z-50 bg-black/40 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
48
+ typeof className === "string" && className.includes("md:hidden") && "md:hidden",
48
49
  backdropClassName,
49
50
  )}
50
51
  />
@@ -0,0 +1,153 @@
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+ import { useEffect, useMemo, useState, type ReactNode } from "react";
5
+ import type { SemanticNodeRecord } from "../lib/category-repository";
6
+ import { isLocalPreviewEnabled } from "../lib/local-preview";
7
+ import { getNewsroomNavHref } from "../lib/newsroom-nav";
8
+ import type { createSemanticGraphSnapshot } from "../lib/semantic-graph";
9
+ import {
10
+ conceptEditedAt, conceptId, conceptTitle, conceptWikiPath, conceptsByTitle, recentlyEditedConcepts, resolveConceptLink,
11
+ } from "../lib/wiki";
12
+ import { MarkusIrPreview } from "./markus-ir-preview";
13
+ import { createWikiIndexPage, loadWikiIndexPage, type WikiIndexPage } from "./wiki-index-client";
14
+
15
+ type SemanticGraph = ReturnType<typeof createSemanticGraphSnapshot>;
16
+
17
+ const editedFormat = new Intl.DateTimeFormat(undefined, { dateStyle: "medium" });
18
+
19
+ function formatEdited(value: string): string {
20
+ const parsed = new Date(value);
21
+ return value && !Number.isNaN(parsed.getTime()) ? editedFormat.format(parsed) : "";
22
+ }
23
+
24
+ function kindLabel(kind: string): string {
25
+ return kind.replace(/_/g, " ");
26
+ }
27
+
28
+ function ConceptLink({ children, demo, node, onOpen }: { children?: ReactNode; demo: boolean; node: SemanticNodeRecord; onOpen: (lineageId: string) => void }) {
29
+ return <a className="wiki-link" data-wiki-concept-link={conceptId(node)} href={getNewsroomNavHref(conceptWikiPath(node), demo)} onClick={event => { if (event.metaKey || event.ctrlKey || event.shiftKey) return; event.preventDefault(); onOpen(conceptId(node)); }}>{children ?? conceptTitle(node)}</a>;
30
+ }
31
+
32
+ function ConceptRows({ demo, nodes, onOpen, showEdited }: { demo: boolean; nodes: SemanticNodeRecord[]; onOpen: (lineageId: string) => void; showEdited?: boolean }) {
33
+ if (!nodes.length) return <p className="wiki-empty">No concepts to show.</p>;
34
+ return <ul className="wiki-concept-list">
35
+ {nodes.map(node => <li key={conceptId(node)}>
36
+ <ConceptLink demo={demo} node={node} onOpen={onOpen} />
37
+ <span className="wiki-chip">{kindLabel(node.nodeKind)}</span>
38
+ {showEdited && conceptEditedAt(node) && <span className="wiki-meta">edited {formatEdited(conceptEditedAt(node))}</span>}
39
+ </li>)}
40
+ </ul>;
41
+ }
42
+
43
+ function WikiIndexPageView({ demo, nodes, onOpen }: { demo: boolean; nodes: SemanticNodeRecord[]; onOpen: (lineageId: string) => void }) {
44
+ const [page, setPage] = useState<WikiIndexPage | null>(null);
45
+ const [error, setError] = useState<string | null>(null);
46
+ const [saving, setSaving] = useState(false);
47
+ useEffect(() => {
48
+ let cancelled = false;
49
+ loadWikiIndexPage(demo || isLocalPreviewEnabled()).then(loaded => { if (!cancelled) setPage(loaded); }).catch((reason: unknown) => { if (!cancelled) setError(reason instanceof Error ? reason.message : "Could not load the wiki index."); });
50
+ return () => { cancelled = true; };
51
+ }, [demo]);
52
+ const dynamicDirectives = useMemo(() => ({
53
+ "recent-concepts": (attributes: Record<string, unknown>) => <ConceptRows demo={demo} nodes={recentlyEditedConcepts(nodes, { kind: typeof attributes.kind === "string" ? attributes.kind : null, limit: Number(attributes.limit) || 10 })} onOpen={onOpen} showEdited />,
54
+ "concept-list": (attributes: Record<string, unknown>) => <ConceptRows demo={demo} nodes={conceptsByTitle(nodes, { kind: typeof attributes.kind === "string" ? attributes.kind : null, limit: Number(attributes.limit) || null })} onOpen={onOpen} />,
55
+ "concept-count": (attributes: Record<string, unknown>) => <strong>{nodes.filter(node => !attributes.kind || node.nodeKind === attributes.kind).length}</strong>,
56
+ }), [demo, nodes, onOpen]);
57
+ const renderLink = (href: string, children: ReactNode) => {
58
+ const node = resolveConceptLink(href, nodes);
59
+ return node ? <ConceptLink demo={demo} node={node} onOpen={onOpen}>{children}</ConceptLink> : null;
60
+ };
61
+ if (error) return <p className="wiki-empty" role="alert">{error}</p>;
62
+ if (!page) return <p className="wiki-empty">Loading the wiki…</p>;
63
+ return <article className="wiki-page" data-wiki-index>
64
+ <div className="wiki-page-tools">
65
+ {page.itemId
66
+ ? <Link className="wiki-tool-link" href={getNewsroomNavHref(`/newsroom/articles/${encodeURIComponent(page.itemId)}`, demo)}>Edit this page</Link>
67
+ : <button className="wiki-tool-link" disabled={saving} onClick={() => { setSaving(true); createWikiIndexPage(demo || isLocalPreviewEnabled()).then(setPage).catch((reason: unknown) => setError(reason instanceof Error ? reason.message : "Could not save the index.")).finally(() => setSaving(false)); }} type="button">{saving ? "Saving…" : "Save this page so it can be edited"}</button>}
68
+ </div>
69
+ <MarkusIrPreview bodyIr={page.bodyIr} dynamicDirectives={dynamicDirectives} renderLink={renderLink} />
70
+ </article>;
71
+ }
72
+
73
+ function ConceptPageView({ demo, graph, node, nodes, onOpen }: { demo: boolean; graph: SemanticGraph; node: SemanticNodeRecord; nodes: SemanticNodeRecord[]; onOpen: (lineageId: string) => void }) {
74
+ const lineage = conceptId(node);
75
+ const groups = graph.neighbors("semanticNode", lineage);
76
+ const references = graph.referencesForSemanticNode(lineage);
77
+ const byLineage = new Map(nodes.map(candidate => [conceptId(candidate), candidate]));
78
+ const aliases = (node.aliases ?? []).filter(Boolean) as string[];
79
+ return <article className="wiki-page" data-wiki-concept={lineage}>
80
+ <h1>{conceptTitle(node)}</h1>
81
+ <p className="wiki-meta"><span className="wiki-chip">{kindLabel(node.nodeKind)}</span> {node.status !== "current" && <span className="wiki-chip">{node.status}</span>} {conceptEditedAt(node) && <>Last edited {formatEdited(conceptEditedAt(node))}</>}{node.versionCreatedBy ? ` by ${node.versionCreatedBy}` : ""}</p>
82
+ {aliases.length > 0 && <p className="wiki-meta">Also known as {aliases.join(", ")}</p>}
83
+ {node.description ? node.description.split(/\n{2,}/).map((paragraph, index) => <p key={index}>{paragraph}</p>) : <p className="wiki-empty">This concept has no description yet.</p>}
84
+ <section data-wiki-section="connections">
85
+ <h2>Connections</h2>
86
+ {groups.length ? groups.map(group => <div className="wiki-connection-group" key={`${group.direction}-${group.predicate}`}>
87
+ <h3>{group.label}</h3>
88
+ <ul className="wiki-concept-list">
89
+ {group.objects.map(object => {
90
+ const target = object.kind === "semanticNode" ? byLineage.get(object.lineageId) : undefined;
91
+ return <li key={`${object.kind}-${object.lineageId}`}>{target ? <ConceptLink demo={demo} node={target} onOpen={onOpen} /> : <span>{object.label}</span>}<span className="wiki-chip">{target ? kindLabel(target.nodeKind) : object.kind}</span></li>;
92
+ })}
93
+ </ul>
94
+ </div>) : <p className="wiki-empty">No connections recorded.</p>}
95
+ </section>
96
+ <section data-wiki-section="references">
97
+ <h2>References</h2>
98
+ {references.length ? <ul className="wiki-concept-list">
99
+ {references.map(reference => <li key={reference.lineageId}><Link href={getNewsroomNavHref(`/newsroom/references/${encodeURIComponent(reference.lineageId)}`, demo)}>{reference.label}</Link></li>)}
100
+ </ul> : <p className="wiki-empty">No references recorded.</p>}
101
+ </section>
102
+ </article>;
103
+ }
104
+
105
+ /**
106
+ * The concept wiki: the front page is a content item whose Markus body can hold live components
107
+ * (recently edited concepts, concept lists), and every concept in the knowledge graph is a page
108
+ * linked to the concepts and references it connects to.
109
+ */
110
+ export function WikiConceptsView({ demo = false, graph, initialNodeLineageId, nodes }: { demo?: boolean; graph: SemanticGraph; initialNodeLineageId?: string | null; nodes: SemanticNodeRecord[] }) {
111
+ const [selected, setSelected] = useState<string | null>(initialNodeLineageId ?? null);
112
+ const [search, setSearch] = useState("");
113
+ const [kind, setKind] = useState("");
114
+ useEffect(() => { setSelected(initialNodeLineageId ?? null); }, [initialNodeLineageId]);
115
+ useEffect(() => {
116
+ const onPop = () => {
117
+ const match = window.location.pathname.match(/\/concepts\/([^/?#]+)/);
118
+ setSelected(match ? decodeURIComponent(match[1]) : null);
119
+ };
120
+ window.addEventListener("popstate", onPop);
121
+ return () => window.removeEventListener("popstate", onPop);
122
+ }, []);
123
+ const open = (lineageId: string | null) => {
124
+ setSelected(lineageId);
125
+ const target = getNewsroomNavHref(lineageId ? `/newsroom/concepts/${encodeURIComponent(lineageId)}` : "/newsroom/concepts", demo);
126
+ if (`${window.location.pathname}${window.location.search}` !== target) window.history.pushState(null, "", target);
127
+ };
128
+ const node = selected ? nodes.find(candidate => conceptId(candidate) === selected || candidate.id === selected) ?? null : null;
129
+ const kinds = useMemo(() => Array.from(new Set(nodes.map(candidate => candidate.nodeKind))).sort(), [nodes]);
130
+ const matches = useMemo(() => {
131
+ const needle = search.trim().toLowerCase();
132
+ return conceptsByTitle(nodes, { kind: kind || null }).filter(candidate => !needle || conceptTitle(candidate).toLowerCase().includes(needle) || (candidate.aliases ?? []).some(alias => alias?.toLowerCase().includes(needle)));
133
+ }, [kind, nodes, search]);
134
+ return <div className="wiki" data-wiki>
135
+ <nav aria-label="Wiki" className="wiki-sidebar">
136
+ <button className="wiki-home" data-wiki-home aria-current={node ? undefined : "page"} onClick={() => open(null)} type="button">Wiki home</button>
137
+ <input aria-label="Search concepts" className="wiki-search" onChange={event => setSearch(event.target.value)} placeholder="Search concepts" value={search} />
138
+ {kinds.length > 1 && <select aria-label="Concept kind" className="wiki-kind" onChange={event => setKind(event.target.value)} value={kind}>
139
+ <option value="">All kinds</option>
140
+ {kinds.map(option => <option key={option} value={option}>{kindLabel(option)}</option>)}
141
+ </select>}
142
+ <ul className="wiki-sidebar-list">
143
+ {matches.map(candidate => <li key={conceptId(candidate)}><a aria-current={node && conceptId(node) === conceptId(candidate) ? "page" : undefined} href={getNewsroomNavHref(conceptWikiPath(candidate), demo)} onClick={event => { if (event.metaKey || event.ctrlKey || event.shiftKey) return; event.preventDefault(); open(conceptId(candidate)); }}>{conceptTitle(candidate)}</a></li>)}
144
+ </ul>
145
+ </nav>
146
+ <div className="wiki-main">
147
+ {node
148
+ ? <ConceptPageView demo={demo} graph={graph} node={node} nodes={nodes} onOpen={open} />
149
+ : selected ? <p className="wiki-empty" role="alert">That concept page was not found.</p>
150
+ : <WikiIndexPageView demo={demo} nodes={nodes} onOpen={open} />}
151
+ </div>
152
+ </div>;
153
+ }
@@ -0,0 +1,51 @@
1
+ "use client";
2
+
3
+ import { generateClient } from "aws-amplify/data";
4
+ import type { Schema } from "../amplify/data/resource";
5
+ import { resolveArticlesBackend } from "../lib/newsroom-articles";
6
+ import { isLocalPreviewEnabled } from "../lib/local-preview";
7
+ import { DEFAULT_WIKI_INDEX_MARKUS, WIKI_INDEX_SLUG, WIKI_PAGE_ITEM_TYPE } from "../lib/wiki";
8
+ import { configureAmplifyClient } from "./amplify-client-provider";
9
+
10
+ export type WikiIndexPage = {
11
+ /** The id of the stored content item, or null while the wiki still shows the built-in starter content. */
12
+ itemId: string | null;
13
+ bodyMarkus: string;
14
+ bodyIr: unknown;
15
+ };
16
+
17
+ type GraphqlResponse = { data?: { itemBySlug?: { items?: Record<string, unknown>[] | null } | null } | null; errors?: { message?: string }[] | null };
18
+
19
+ async function storedIndexRow(preview: boolean): Promise<Record<string, unknown> | null> {
20
+ if (preview || isLocalPreviewEnabled()) return null;
21
+ configureAmplifyClient();
22
+ const client = generateClient<Schema>() as unknown as { graphql: (options: Record<string, unknown>) => Promise<GraphqlResponse> };
23
+ const response = await client.graphql({
24
+ query: "query ($slug: String!) { itemBySlug(slug: $slug) { items { id versionNumber versionState bodyMarkus bodyIr } } }",
25
+ variables: { slug: WIKI_INDEX_SLUG },
26
+ authMode: "userPool",
27
+ });
28
+ if (response.errors?.length) throw new Error(response.errors.map(error => error.message ?? "GraphQL error").join("; "));
29
+ const rows = (response.data?.itemBySlug?.items ?? []).filter(Boolean) as Record<string, unknown>[];
30
+ const ranked = rows.sort((left, right) => Number(right.versionNumber ?? 0) - Number(left.versionNumber ?? 0));
31
+ return ranked.find(row => row.versionState === "current") ?? ranked[0] ?? null;
32
+ }
33
+
34
+ async function derive(bodyMarkus: string, preview: boolean): Promise<unknown> {
35
+ const result = await resolveArticlesBackend(preview).actions.deriveMarkus({ frontMatterYaml: null, bodyMarkus, includeIr: true });
36
+ return result.bodyIr ?? null;
37
+ }
38
+
39
+ /** Loads the wiki's front page content item, falling back to the starter content until one is saved. */
40
+ export async function loadWikiIndexPage(preview: boolean): Promise<WikiIndexPage> {
41
+ const row = await storedIndexRow(preview);
42
+ const bodyMarkus = typeof row?.bodyMarkus === "string" && row.bodyMarkus.trim() ? row.bodyMarkus : DEFAULT_WIKI_INDEX_MARKUS;
43
+ const storedIr = row?.bodyIr;
44
+ return { itemId: row ? String(row.id) : null, bodyMarkus, bodyIr: storedIr ?? await derive(bodyMarkus, preview) };
45
+ }
46
+
47
+ /** Saves the starter index as the wiki-index content item so editors can change it like any other page. */
48
+ export async function createWikiIndexPage(preview: boolean): Promise<WikiIndexPage> {
49
+ const saved = await resolveArticlesBackend(preview).actions.saveItemDraft({ id: null, type: WIKI_PAGE_ITEM_TYPE, slug: WIKI_INDEX_SLUG, section: null, frontMatterYaml: `title: Concept wiki\n`, bodyMarkus: DEFAULT_WIKI_INDEX_MARKUS, aliases: [], expectedContentHash: null });
50
+ return { itemId: saved.item.id, bodyMarkus: DEFAULT_WIKI_INDEX_MARKUS, bodyIr: await derive(DEFAULT_WIKI_INDEX_MARKUS, preview) };
51
+ }
@@ -13,6 +13,9 @@ export type SaveItemDraftInput = {
13
13
  bodyMarkus: string;
14
14
  aliases: string[];
15
15
  expectedContentHash: string | null;
16
+ /** Records a new draft version of the story instead of correcting the current one in place. */
17
+ newVersion?: boolean;
18
+ changeReason?: string | null;
16
19
  };
17
20
 
18
21
  export type DeriveMarkusResult = { ok: true; bodyIrBytes: number; bodyIr?: unknown; errors: [] };
@@ -1,4 +1,5 @@
1
1
  import { ContentActionFailure } from "./content-actions-client";
2
+ import { isLocalPreviewEnabled } from "./local-preview";
2
3
  import type {
3
4
  DeriveMarkusInput,
4
5
  DeriveMarkusResult,
@@ -12,7 +13,7 @@ import {
12
13
  demoContentHash,
13
14
  type DemoArticleRecord,
14
15
  } from "./newsroom-demo-articles";
15
- import { createLocalPreviewEditableArticle } from "./local-preview-seed";
16
+ import { createLocalPreviewEditableArticle, lineageForPreviewVersion, recordLocalPreviewDesk, recordLocalPreviewVersion } from "./local-preview-seed";
16
17
  import { sourceLineOffset, type ArticlesBackend, type EditableArticle, type NewsroomArticleRow } from "./newsroom-articles";
17
18
 
18
19
  function titleFromYaml(frontMatterYaml: string | null, fallback: string): string {
@@ -30,6 +31,18 @@ function demoAttribute(attributes: string, name: string): string {
30
31
  return match ? match[1] : "";
31
32
  }
32
33
 
34
+ async function deriveThroughPreviewMarkusEngine(input: DeriveMarkusInput): Promise<DeriveMarkusResult | null> {
35
+ try {
36
+ const response = await fetch("/api/local-preview/derive", { method: "POST", body: JSON.stringify({ frontMatterYaml: input.frontMatterYaml, bodyMarkus: input.bodyMarkus }) });
37
+ if (!response.ok) return null;
38
+ const result = await response.json() as DeriveMarkusResult & { error?: string };
39
+ if (result.error) return null;
40
+ return input.includeIr ? result : { ...result, bodyIr: undefined };
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+
33
46
  function demoEnvelope(bodyMarkus: string) {
34
47
  const images: Record<string, Record<string, unknown>> = {};
35
48
  const children = bodyMarkus
@@ -74,6 +87,10 @@ export function createDemoArticlesBackend(): ArticlesBackend {
74
87
  return {
75
88
  actions: {
76
89
  async deriveMarkus(input: DeriveMarkusInput): Promise<DeriveMarkusResult> {
90
+ if (isLocalPreviewEnabled()) {
91
+ const derived = await deriveThroughPreviewMarkusEngine(input);
92
+ if (derived) return derived;
93
+ }
77
94
  const lines = input.bodyMarkus.split("\n");
78
95
  const invalidIndex = lines.findIndex((line) => line.includes(":::nope"));
79
96
  if (invalidIndex >= 0) {
@@ -91,6 +108,28 @@ export function createDemoArticlesBackend(): ArticlesBackend {
91
108
  },
92
109
  async saveItemDraft(input: SaveItemDraftInput): Promise<SaveItemDraftResult> {
93
110
  const existing = input.id ? requireRecord(input.id) : null;
111
+ if (input.newVersion && existing) {
112
+ const lineageId = createLocalPreviewEditableArticle(existing.id)?.lineageId ?? existing.id;
113
+ const versionNumber = (existing.versionNumber ?? 1) + 1;
114
+ const id = `${lineageId}-v${versionNumber}`;
115
+ const frontMatterYaml = input.frontMatterYaml ?? "";
116
+ const record: DemoArticleRecord = {
117
+ ...existing,
118
+ id,
119
+ slug: existing.slug,
120
+ section: input.section,
121
+ title: titleFromYaml(input.frontMatterYaml, existing.slug),
122
+ status: "draft",
123
+ frontMatterYaml,
124
+ bodyMarkus: input.bodyMarkus,
125
+ contentHash: demoContentHash(frontMatterYaml, input.bodyMarkus),
126
+ versionNumber,
127
+ updatedAt: new Date().toISOString(),
128
+ };
129
+ records.set(id, record);
130
+ recordLocalPreviewVersion(lineageId, { id, versionNumber, versionState: "current", status: "draft", stage: null, headline: record.title, changeReason: input.changeReason ?? null, versionCreatedBy: "You", versionCreatedAt: record.updatedAt, updatedAt: record.updatedAt });
131
+ return { ok: true, item: { id, contentHash: record.contentHash, status: "draft", slug: record.slug, versionNumber } };
132
+ }
94
133
  if (existing && input.expectedContentHash !== null && input.expectedContentHash !== existing.contentHash) {
95
134
  throw new ContentActionFailure([
96
135
  { code: "conflict", message: "The item changed since it was loaded.", line: null },
@@ -120,6 +159,7 @@ export function createDemoArticlesBackend(): ArticlesBackend {
120
159
  updatedAt: new Date().toISOString(),
121
160
  };
122
161
  records.set(id, record);
162
+ recordLocalPreviewDesk(id, record.section);
123
163
  return {
124
164
  ok: true,
125
165
  item: {
@@ -172,11 +212,23 @@ export function createDemoArticlesBackend(): ArticlesBackend {
172
212
  .sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
173
213
  },
174
214
  async loadArticle(id: string): Promise<EditableArticle> {
175
- const previewRecord = records.get(id) ? null : createLocalPreviewEditableArticle(id);
176
- if (previewRecord) return previewRecord;
215
+ if (!records.has(id)) {
216
+ const previewRecord = createLocalPreviewEditableArticle(id);
217
+ if (previewRecord) {
218
+ records.set(id, {
219
+ ...previewRecord,
220
+ title: titleFromYaml(previewRecord.frontMatterYaml, previewRecord.slug),
221
+ status: previewRecord.status === "published" ? "published" : "draft",
222
+ contentHash: demoContentHash(previewRecord.frontMatterYaml, previewRecord.bodyMarkus),
223
+ publishedContentHash: previewRecord.status === "published" ? demoContentHash(previewRecord.frontMatterYaml, previewRecord.bodyMarkus) : null,
224
+ updatedAt: new Date().toISOString(),
225
+ });
226
+ }
227
+ }
177
228
  const record = requireRecord(id);
178
229
  return {
179
230
  id: record.id,
231
+ lineageId: createLocalPreviewEditableArticle(record.id)?.lineageId ?? lineageForPreviewVersion(record.id),
180
232
  type: record.type,
181
233
  section: record.section,
182
234
  slug: record.slug,
@@ -28,9 +28,9 @@ export const DEFAULT_CONTENT_ITEM_STAGE_DEFINITIONS: readonly ContentItemStageDe
28
28
  { key: "copywriting", label: "Copywriting" },
29
29
  { key: "illustration", label: "Illustration" },
30
30
  { key: "typesetting", label: "Typesetting" },
31
- { key: "published", label: "Published" },
32
- { key: "held", label: "Held" },
33
31
  { key: "spiked", label: "Spiked", collapsedUntilOpened: true },
32
+ { key: "held", label: "Held" },
33
+ { key: "published", label: "Published" },
34
34
  ];
35
35
 
36
36
  export function contentItemStageKeys(stageDefinitions: readonly ContentItemStageDefinition[]): string[] {
@@ -68,6 +68,8 @@ export type ContentItemVersionRecord = {
68
68
  status: string;
69
69
  title?: string | null;
70
70
  headline?: string | null;
71
+ deck?: string | null;
72
+ metadata?: unknown;
71
73
  slug: string;
72
74
  section?: string | null;
73
75
  updatedAt?: string | null;
@@ -0,0 +1,42 @@
1
+ import { parseDocument } from "yaml";
2
+ import type { ContentItemVersionRecord } from "./content-item-lifecycle";
3
+
4
+ /** Front matter keys the editor shows as form fields instead of raw YAML. */
5
+ export const FRONT_MATTER_TITLE_KEY = "title";
6
+ export const FRONT_MATTER_SUBTITLE_KEY = "deck";
7
+ export const FRONT_MATTER_BLURB_KEY = "blurb";
8
+
9
+ /** Reads one text field from front matter YAML; invalid YAML or a non-text value reads as empty. */
10
+ export function readFrontMatterText(frontMatterYaml: string | null | undefined, key: string): string {
11
+ if (!frontMatterYaml?.trim()) return "";
12
+ const document = parseDocument(frontMatterYaml);
13
+ if (document.errors.length) return "";
14
+ const value = document.get(key);
15
+ return typeof value === "string" ? value : "";
16
+ }
17
+
18
+ /** Sets or removes one text field in front matter YAML, keeping every other line and comment as written. */
19
+ export function writeFrontMatterText(frontMatterYaml: string | null | undefined, key: string, value: string): string {
20
+ const document = parseDocument(frontMatterYaml?.trim() ? frontMatterYaml : "{}\n");
21
+ if (document.errors.length) return frontMatterYaml ?? "";
22
+ if (value.trim()) document.set(key, value);
23
+ else document.delete(key);
24
+ const text = document.toString();
25
+ return text.trim() === "{}" ? "" : text;
26
+ }
27
+
28
+ function metadataFrontMatterYaml(metadata: unknown): string {
29
+ const parsed = typeof metadata === "string" ? safeJson(metadata) : metadata;
30
+ const text = (parsed as { frontMatterYaml?: unknown } | null)?.frontMatterYaml;
31
+ return typeof text === "string" ? text : "";
32
+ }
33
+
34
+ function safeJson(text: string): unknown {
35
+ try { return JSON.parse(text); } catch { return null; }
36
+ }
37
+
38
+ /** A few lines for a board card: the blurb when one is recorded, else the subtitle. */
39
+ export function contentItemExcerpt(version: Pick<ContentItemVersionRecord, "deck" | "metadata">): string | undefined {
40
+ const blurb = readFrontMatterText(metadataFrontMatterYaml(version.metadata), FRONT_MATTER_BLURB_KEY).trim();
41
+ return blurb || version.deck?.trim() || undefined;
42
+ }
@@ -1,5 +1,7 @@
1
1
  import type { AssignmentRecord, ReferenceRecord } from "./category-repository";
2
2
  import type { EditableArticle } from "./newsroom-articles";
3
+ import type { MediaAssetRecord } from "./newsroom-media";
4
+ import { EMPTY_STORY_REPORTING_TRAIL, type StoryReportingTrail, type TrailVersion } from "./story-reporting-trail";
3
5
  import { contentItemStageKeys, type ContentItemVersionRecord } from "./content-item-lifecycle";
4
6
  import { getContentItemStageDefinitions } from "./site-brand";
5
7
 
@@ -95,12 +97,17 @@ export function createLocalPreviewAssignments(): AssignmentRecord[] {
95
97
  return [...assignmentsOnContentItems, ...assignmentsWithoutContentItem];
96
98
  }
97
99
 
100
+ export function createLocalPreviewRealPublishedVersions(): ContentItemVersionRecord[] {
101
+ return [];
102
+ }
103
+
98
104
  export function createLocalPreviewEditableArticle(id: string): EditableArticle | null {
99
105
  const version = createLocalPreviewContentItemVersions().find(candidate => candidate.id === id);
100
106
  if (!version) return null;
101
107
  const headline = version.headline || version.title || version.slug;
102
108
  return {
103
109
  id: version.id,
110
+ lineageId: version.lineageId,
104
111
  type: version.type,
105
112
  section: version.section ?? null,
106
113
  slug: version.slug,
@@ -113,3 +120,29 @@ export function createLocalPreviewEditableArticle(id: string): EditableArticle |
113
120
  everPublished: version.status === "published",
114
121
  };
115
122
  }
123
+
124
+ export function recordLocalPreviewDesk(articleId: string, deskId: string | null): void {
125
+ const version = createLocalPreviewContentItemVersions().find(candidate => candidate.id === articleId);
126
+ if (version) version.section = deskId;
127
+ }
128
+
129
+ const previewSavedVersions = new Map<string, TrailVersion[]>();
130
+ const previewLineageByVersionId = new Map<string, string>();
131
+
132
+ export function recordLocalPreviewVersion(lineageId: string, version: TrailVersion): void {
133
+ previewSavedVersions.set(lineageId, [version, ...(previewSavedVersions.get(lineageId) ?? [])]);
134
+ previewLineageByVersionId.set(version.id, lineageId);
135
+ }
136
+
137
+ export function lineageForPreviewVersion(versionId: string): string | null {
138
+ return previewLineageByVersionId.get(versionId) ?? null;
139
+ }
140
+
141
+ export function createLocalPreviewReportingTrail(lineageId: string): StoryReportingTrail {
142
+ const saved = previewSavedVersions.get(lineageId) ?? [];
143
+ return { ...EMPTY_STORY_REPORTING_TRAIL, versions: saved };
144
+ }
145
+
146
+ export function createLocalPreviewMediaAssets(_itemId: string): MediaAssetRecord[] {
147
+ return [];
148
+ }
@@ -59,6 +59,7 @@ export type NewsroomArticleEditorState = {
59
59
 
60
60
  export type EditableArticle = {
61
61
  id: string;
62
+ lineageId?: string | null;
62
63
  type: string;
63
64
  section: string | null;
64
65
  slug: string;
@@ -267,6 +268,7 @@ export async function loadEditableArticle(client: ArticlesDataClient, id: string
267
268
  const status: ArticleStatus = record.status === "published" ? "published" : "draft";
268
269
  return {
269
270
  id: String(record.id),
271
+ lineageId: typeof record.lineageId === "string" ? record.lineageId : null,
270
272
  type: String(record.type),
271
273
  section: typeof record.section === "string" ? record.section : null,
272
274
  slug: String(record.slug),
@@ -9,6 +9,7 @@ import {
9
9
  latestVersionPerContentItem,
10
10
  type ContentItemVersionRecord,
11
11
  } from "./content-item-lifecycle";
12
+ import { contentItemExcerpt } from "./front-matter-fields";
12
13
  import { assignmentStatusLabel } from "./newsroom-assignments";
13
14
  import { getContentItemName, getContentItemStageDefinitions } from "./site-brand";
14
15
 
@@ -18,6 +19,8 @@ export interface NativeBoardIssue extends KanbanIssue {
18
19
  nativeId: string;
19
20
  nativeStatus: string;
20
21
  href: string;
22
+ /** A few lines to show under the headline: the blurb, else the subtitle. */
23
+ excerpt?: string;
21
24
  }
22
25
 
23
26
  export function contentItemBoardPathSegment(): string {
@@ -57,6 +60,7 @@ export function projectContentItemBoard(records: {
57
60
  title: version.headline || version.title || version.slug, nativeStatus: stage, status: `${contentItemType}/${stage}`,
58
61
  priority: 2, description: workCount ? `${workCount} assignment${workCount === 1 ? "" : "s"} on this ${contentItemType}.` : undefined,
59
62
  updated_at: version.updatedAt ?? undefined, href: `/newsroom/articles/${encodeURIComponent(version.id)}`,
63
+ excerpt: contentItemExcerpt(version),
60
64
  };
61
65
  });
62
66
  }
@@ -1,7 +1,6 @@
1
1
  import { toPublicNewsroomPath } from "./newsroom-base-path";
2
2
 
3
3
  export const FORUM_THREAD_ROUTE_PREFIX = "/newsroom/forum/";
4
- export const INSIGHT_THREAD_ROUTE_PREFIX = "/newsroom/insights/";
5
4
  export const FORUM_MESSAGE_HASH_PREFIX = "message-";
6
5
 
7
6
  export function isForumThreadId(id: string | null | undefined): boolean {
@@ -9,11 +8,6 @@ export function isForumThreadId(id: string | null | undefined): boolean {
9
8
  return value.startsWith("message-thread-");
10
9
  }
11
10
 
12
- export function isInsightThreadId(id: string | null | undefined): boolean {
13
- const value = String(id ?? "").trim();
14
- return Boolean(value) && !isForumThreadId(value);
15
- }
16
-
17
11
  export function getForumMessageAnchorId(messageId: string): string {
18
12
  return `${FORUM_MESSAGE_HASH_PREFIX}${encodeURIComponent(messageId.trim())}`;
19
13
  }
@@ -33,7 +27,7 @@ export function parseForumMessageAnchorFromHash(hash: string | null | undefined)
33
27
  export type ParsedNewsroomForumRoute = {
34
28
  threadId: string | null;
35
29
  messageId: string | null;
36
- surface: "edition_forum" | "insight_forum" | null;
30
+ surface: "edition_forum" | null;
37
31
  };
38
32
 
39
33
  export function parseNewsroomForumRoute(pathname: string, hash?: string | null): ParsedNewsroomForumRoute {
@@ -43,13 +37,6 @@ export function parseNewsroomForumRoute(pathname: string, hash?: string | null):
43
37
  return { threadId: null, messageId: parseForumMessageAnchorFromHash(hash), surface: null };
44
38
  }
45
39
  const tail = segments.slice(newsroomIndex + 1);
46
- if (tail[0] === "insights" && tail[1]) {
47
- return {
48
- threadId: decodeURIComponent(tail[1]),
49
- messageId: parseForumMessageAnchorFromHash(hash),
50
- surface: "insight_forum",
51
- };
52
- }
53
40
  if (tail[0] === "forum" && tail[1]) {
54
41
  return {
55
42
  threadId: decodeURIComponent(tail[1]),
@@ -86,24 +73,11 @@ export function buildForumThreadUrl(
86
73
  return toPublicNewsroomPath(`/newsroom/forum/${encodedThreadId}${query ? `?${query}` : ""}${hash ? `#${hash}` : ""}`);
87
74
  }
88
75
 
89
- export function buildInsightThreadUrl(
90
- threadId: string,
91
- options?: { messageId?: string | null; demo?: boolean },
92
- ): string {
93
- const encodedThreadId = encodeURIComponent(threadId.trim());
94
- const params = new URLSearchParams();
95
- if (options?.demo) params.set("demo", "1");
96
- const query = params.toString();
97
- const hash = options?.messageId ? getForumMessageAnchorId(options.messageId) : "";
98
- return toPublicNewsroomPath(`${INSIGHT_THREAD_ROUTE_PREFIX}${encodedThreadId}${query ? `?${query}` : ""}${hash ? `#${hash}` : ""}`);
99
- }
100
-
101
76
  export function buildThreadUrlForSurface(
102
77
  surface: ParsedNewsroomForumRoute["surface"],
103
78
  threadId: string,
104
79
  options?: { messageId?: string | null; demo?: boolean },
105
80
  ): string {
106
- if (surface === "insight_forum") return buildInsightThreadUrl(threadId, options);
107
81
  return buildForumThreadUrl(threadId, options);
108
82
  }
109
83
 
@@ -122,7 +96,7 @@ export function pushForumThreadUrl(
122
96
  const surface = options?.surface ?? readCurrentForumRoute().surface;
123
97
  const url = threadId
124
98
  ? buildThreadUrlForSurface(surface, threadId, options)
125
- : (surface === "insight_forum" ? buildNewsroomInsightsIndexUrl(options?.demo) : buildNewsroomForumIndexUrl(options?.demo));
99
+ : buildNewsroomForumIndexUrl(options?.demo);
126
100
  const current = `${window.location.pathname}${window.location.search}${window.location.hash}`;
127
101
  if (current === url) return;
128
102
  if (options?.replace) {
@@ -132,24 +106,9 @@ export function pushForumThreadUrl(
132
106
  }
133
107
  }
134
108
 
135
- export function pushInsightThreadUrl(
136
- threadId: string | null,
137
- options?: { messageId?: string | null; demo?: boolean; replace?: boolean },
138
- ) {
139
- pushForumThreadUrl(threadId, { ...options, surface: "insight_forum" });
140
- }
141
-
142
109
  export function buildNewsroomForumIndexUrl(demo?: boolean): string {
143
110
  const params = new URLSearchParams();
144
111
  if (demo) params.set("demo", "1");
145
112
  const query = params.toString();
146
113
  return toPublicNewsroomPath(query ? `/newsroom?${query}` : "/newsroom");
147
114
  }
148
-
149
- export function buildNewsroomInsightsIndexUrl(demo?: boolean, domain?: string): string {
150
- const params = new URLSearchParams();
151
- if (demo) params.set("demo", "1");
152
- if (domain?.trim()) params.set("domain", domain.trim());
153
- const query = params.toString();
154
- return toPublicNewsroomPath(query ? `/newsroom/insights?${query}` : "/newsroom/insights");
155
- }