@deskwork/studio 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,559 @@
1
+ /**
2
+ * Per-post review page — `/dev/editorial-review/:slug`.
3
+ *
4
+ * Renders one workflow's current draft inside a margin-note review
5
+ * shell. The body markdown is rendered server-side (so the operator
6
+ * sees content immediately, no flash of unrendered text), with the
7
+ * frontmatter description injected as a dek paragraph after the
8
+ * body's repeated H1.
9
+ *
10
+ * Ported from `pages/dev/editorial-review/[slug].astro`. Differences:
11
+ * - The full <BlogLayout> Astro component went away; we render the
12
+ * review shell as the page body. Site-specific blog chrome was
13
+ * never useful in the review surface (the review is about the
14
+ * prose, not the page chrome).
15
+ * - Site defaults to `config.defaultSite` rather than the hardcoded
16
+ * `'editorialcontrol'` upstream used.
17
+ * - The outline-split helper lives under the plugin tree's `public/src/`
18
+ * (it's a browser module) but it's pure TS, so it can run server-side
19
+ * for the initial render too. After the marketplace-install fix
20
+ * (issue #4), `public/` was relocated from packages/studio/ into
21
+ * plugins/deskwork-studio/, hence the long relative import below.
22
+ */
23
+
24
+ import { handleGetWorkflow } from '@deskwork/core/review/handlers';
25
+ import type {
26
+ DraftVersion,
27
+ DraftWorkflowItem,
28
+ } from '@deskwork/core/review/types';
29
+ import {
30
+ parseDraftFrontmatter,
31
+ renderMarkdownToHtml,
32
+ } from '@deskwork/core/review/render';
33
+ import { readCalendar } from '@deskwork/core/calendar';
34
+ import { findEntry, findEntryById } from '@deskwork/core/calendar-mutations';
35
+ import type { CalendarEntry } from '@deskwork/core/types';
36
+ import type { ContentIndex } from '@deskwork/core/content-index';
37
+ import { splitOutline } from '@deskwork/core/outline-split';
38
+ import type { StudioContext } from '../routes/api.ts';
39
+ import { html, unsafe, type RawHtml } from './html.ts';
40
+ import { layout } from './layout.ts';
41
+ import { renderEditorialFolio } from './chrome.ts';
42
+ import { escapeHtml } from './html.ts';
43
+ import { renderScrapbookDrawer } from './review-scrapbook-drawer.ts';
44
+ import { existsSync } from 'node:fs';
45
+ import { resolveCalendarPath } from '@deskwork/core/paths';
46
+
47
+ /**
48
+ * Per-request content-index getter. The route layer wires this to the
49
+ * Hono context's memoized cache so a single review render only builds
50
+ * the index once per site even though both the inline-text loader and
51
+ * the scrapbook drawer ask for it. When omitted, callers fall back to
52
+ * slug-template path resolution.
53
+ */
54
+ export type ReviewIndexGetter = (site: string) => ContentIndex;
55
+
56
+ interface ReviewQuery {
57
+ /** ?site=<slug> override; null falls back to config.defaultSite. */
58
+ site: string | null;
59
+ /** ?v=<n>; null shows the workflow's currentVersion. */
60
+ version: string | null;
61
+ /** ?kind=outline | longform; null defaults to longform. */
62
+ kind?: string | null;
63
+ }
64
+
65
+ /**
66
+ * How the route resolved the request. Phase 19d added the canonical
67
+ * id-based URL; the legacy slug URL still resolves to a render via the
68
+ * 302-redirect path (the redirect target lands here as `kind: 'id'`).
69
+ *
70
+ * `kind: 'slug'` is reserved for the legacy fallback when the calendar
71
+ * entry has no id stamped on it yet — pre-doctor state, not a "fallback"
72
+ * the project rules forbid but the migration path the plan calls out.
73
+ *
74
+ * Phase 21c added `kind: 'workflow'` so the dashboard can deep-link
75
+ * straight to a specific workflow id without first knowing the entry
76
+ * id — shortform cells use this to land on the unified review surface
77
+ * after `start-shortform` returns the new workflow.
78
+ */
79
+ export type ReviewLookup =
80
+ | { kind: 'id'; entryId: string; slug: string }
81
+ | { kind: 'slug'; slug: string }
82
+ | { kind: 'workflow'; workflowId: string };
83
+
84
+ function isSuccessBody(
85
+ body: unknown,
86
+ ): body is { workflow: DraftWorkflowItem; versions: DraftVersion[] } {
87
+ if (typeof body !== 'object' || body === null) return false;
88
+ return 'workflow' in body && 'versions' in body;
89
+ }
90
+
91
+ function errorFromBody(body: unknown): string {
92
+ if (typeof body === 'object' && body !== null) {
93
+ const value = Reflect.get(body, 'error');
94
+ if (typeof value === 'string') return value;
95
+ }
96
+ return 'unknown error';
97
+ }
98
+
99
+ function pickContentKind(
100
+ rawKind: string | null | undefined,
101
+ ): 'longform' | 'outline' | 'shortform' {
102
+ if (rawKind === 'outline') return 'outline';
103
+ if (rawKind === 'shortform') return 'shortform';
104
+ return 'longform';
105
+ }
106
+
107
+ function pickSite(ctx: StudioContext, raw: string | null): string {
108
+ if (raw && raw in ctx.config.sites) return raw;
109
+ return ctx.config.defaultSite;
110
+ }
111
+
112
+ function stringField(v: unknown): string | undefined {
113
+ return typeof v === 'string' ? v : undefined;
114
+ }
115
+
116
+ interface PreparedRender {
117
+ fm: Record<string, unknown>;
118
+ bodyHtml: string;
119
+ outlineHtml: string;
120
+ }
121
+
122
+ async function prepareRender(
123
+ markdown: string,
124
+ contentKind: 'longform' | 'outline' | 'shortform',
125
+ ): Promise<PreparedRender> {
126
+ const parsed = parseDraftFrontmatter(markdown);
127
+ const fm = parsed.frontmatter;
128
+
129
+ // Outline + shortform render the body as-is (no outline-split). Only
130
+ // longform pulls the optional briefing-sheet drawer out of the body.
131
+ const split = contentKind !== 'longform'
132
+ ? { body: parsed.body, outline: '', present: false, startLine: -1, endLine: -1 }
133
+ : splitOutline(parsed.body);
134
+
135
+ const bodyHtml = await renderMarkdownToHtml(split.body);
136
+
137
+ // Inject the description as a dek after the body's first <h1>.
138
+ const description = stringField(fm.description);
139
+ const dekHtml = description
140
+ ? `<p class="er-dispatch-dek">${escapeHtml(description)}</p>`
141
+ : '';
142
+ const h1Close = bodyHtml.indexOf('</h1>');
143
+ const renderedHtml =
144
+ dekHtml && h1Close >= 0
145
+ ? bodyHtml.slice(0, h1Close + 5) + dekHtml + bodyHtml.slice(h1Close + 5)
146
+ : dekHtml + bodyHtml;
147
+
148
+ const outlineHtml = split.outline
149
+ ? await renderMarkdownToHtml(split.outline)
150
+ : '';
151
+
152
+ return { fm, bodyHtml: renderedHtml, outlineHtml };
153
+ }
154
+
155
+ function stateLabel(state?: string): string {
156
+ return (state ?? '').replace('-', ' ');
157
+ }
158
+
159
+ function renderVersionsStrip(
160
+ versions: readonly DraftVersion[],
161
+ site: string,
162
+ contentKind: 'longform' | 'outline' | 'shortform',
163
+ current: DraftVersion,
164
+ ): RawHtml {
165
+ if (versions.length <= 1) return unsafe('');
166
+ const kindBit =
167
+ contentKind === 'outline'
168
+ ? '&kind=outline'
169
+ : contentKind === 'shortform'
170
+ ? '&kind=shortform'
171
+ : '';
172
+ const links = versions
173
+ .map((v) => {
174
+ const isActive = v.version === current.version;
175
+ const href = `?site=${site}${kindBit}&v=${v.version}`;
176
+ return html`<a href="${href}" class="${isActive ? 'active' : ''}">v${v.version}</a>`;
177
+ })
178
+ .join('');
179
+ return unsafe(html`<span class="er-strip-versions">${unsafe(links)}</span>`);
180
+ }
181
+
182
+ /**
183
+ * Build the slash command that the operator pastes into Claude Code to
184
+ * advance the workflow from its current pending state. Mirrors the
185
+ * client-side button-handler logic so server-rendered "copy again"
186
+ * affordances stay consistent.
187
+ */
188
+ function pendingSkillCmd(workflow: DraftWorkflowItem): string {
189
+ const { site, slug, contentKind, state } = workflow;
190
+ if (state === 'iterating') {
191
+ return contentKind === 'outline'
192
+ ? `/deskwork:iterate --kind outline --site ${site} ${slug}`
193
+ : `/deskwork:iterate --site ${site} ${slug}`;
194
+ }
195
+ if (state === 'approved') {
196
+ // Outline-approve semantics still TBD (see editorial-review-client.ts);
197
+ // for now both kinds emit the same /deskwork:approve.
198
+ return `/deskwork:approve --site ${site} ${slug}`;
199
+ }
200
+ return '';
201
+ }
202
+
203
+ function renderControlsRight(workflow: DraftWorkflowItem): RawHtml {
204
+ const isActive = workflow.state === 'open' || workflow.state === 'in-review';
205
+ const isApproved = workflow.state === 'approved';
206
+ const isIterating = workflow.state === 'iterating';
207
+ const isTerminal = workflow.state === 'applied' || workflow.state === 'cancelled';
208
+ const buttons: string[] = [];
209
+ buttons.push(html`<button class="er-btn er-btn-small" data-action="toggle-edit" type="button">Edit</button>`);
210
+ if (isActive) {
211
+ buttons.push(html`<button class="er-btn er-btn-small er-btn-approve" data-action="approve" type="button">Approve</button>`);
212
+ buttons.push(html`<button class="er-btn er-btn-small" data-action="iterate" type="button">Iterate</button>`);
213
+ buttons.push(html`<button class="er-btn er-btn-small er-btn-reject" data-action="reject" type="button">Reject</button>`);
214
+ }
215
+ if (isApproved) {
216
+ const applyCmd = pendingSkillCmd(workflow);
217
+ buttons.push(html`<span class="er-pending-state">awaiting apply…</span>`);
218
+ buttons.push(html`<button class="er-btn er-btn-small" data-action="copy-cmd" data-cmd="${applyCmd}" title="Copy ${applyCmd} to clipboard" type="button">copy <code>/deskwork:approve</code></button>`);
219
+ buttons.push(html`<button class="er-btn er-btn-small er-btn-reject" data-action="reject" type="button">Reject</button>`);
220
+ }
221
+ if (isIterating) {
222
+ const iterateCmd = pendingSkillCmd(workflow);
223
+ buttons.push(html`<span class="er-pending-state">agent iterating…</span>`);
224
+ buttons.push(html`<button class="er-btn er-btn-small" data-action="copy-cmd" data-cmd="${iterateCmd}" title="Copy ${iterateCmd} to clipboard" type="button">copy <code>/deskwork:iterate</code></button>`);
225
+ }
226
+ if (isTerminal) {
227
+ buttons.push(html`<span class="er-pending-state er-pending-state--filed">filed (${workflow.state})</span>`);
228
+ }
229
+ buttons.push(html`<button class="er-btn er-btn-small" data-action="shortcuts" type="button" aria-label="Show keyboard shortcuts" title="Keyboard shortcuts">?</button>`);
230
+ return unsafe(`<span class="er-strip-right">${buttons.join('')}</span>`);
231
+ }
232
+
233
+ function renderError(
234
+ slug: string,
235
+ site: string,
236
+ contentKind: 'longform' | 'outline' | 'shortform',
237
+ message: string,
238
+ ): string {
239
+ const startCmd =
240
+ contentKind === 'outline'
241
+ ? `/deskwork:outline --site ${site} ${slug}`
242
+ : contentKind === 'shortform'
243
+ ? `/deskwork:shortform-start --site ${site} ${slug} <platform>`
244
+ : `/deskwork:review-start --site ${site} ${slug}`;
245
+ const body = html`
246
+ <div data-review-ui="longform">
247
+ ${renderEditorialFolio('reviews', `longform · ${slug}`)}
248
+ <div class="er-error">
249
+ <h1>No galley to review.</h1>
250
+ <p><strong>Slug:</strong> <code>${slug}</code></p>
251
+ <p>${message}</p>
252
+ <p>Start one with:</p>
253
+ <p><code>${startCmd}</code></p>
254
+ <p style="margin-top: 2rem;"><a href="/dev/editorial-studio">← back to the studio</a></p>
255
+ </div>
256
+ </div>`;
257
+ return layout({
258
+ title: `Review — ${slug} — error`,
259
+ cssHrefs: [
260
+ '/static/css/editorial-review.css',
261
+ '/static/css/editorial-nav.css',
262
+ ],
263
+ bodyHtml: body,
264
+ scriptModules: [],
265
+ });
266
+ }
267
+
268
+ function renderShortcutsOverlay(): RawHtml {
269
+ return unsafe(html`
270
+ <div class="er-shortcuts" data-shortcuts-overlay hidden role="dialog" aria-modal="true" aria-label="Keyboard shortcuts">
271
+ <div class="er-shortcuts-backdrop" data-shortcuts-backdrop></div>
272
+ <div class="er-shortcuts-panel">
273
+ <h2>Keyboard</h2>
274
+ <dl>
275
+ <dt><kbd>e</kbd> / dbl-click</dt><dd>toggle edit mode</dd>
276
+ <dt>select text</dt><dd>leave a margin note</dd>
277
+ <dt><kbd>⌘</kbd><kbd>↵</kbd> / <kbd>ctrl</kbd><kbd>↵</kbd></dt><dd>save margin note (in composer)</dd>
278
+ <dt><kbd>a</kbd></dt><dd>approve</dd>
279
+ <dt><kbd>i</kbd></dt><dd>iterate</dd>
280
+ <dt><kbd>r</kbd></dt><dd>reject</dd>
281
+ <dt><kbd>j</kbd> / <kbd>k</kbd></dt><dd>next / previous margin note</dd>
282
+ <dt><kbd>?</kbd></dt><dd>this panel</dd>
283
+ <dt><kbd>esc</kbd></dt><dd>close / cancel composer</dd>
284
+ </dl>
285
+ <p class="er-shortcuts-footer">Press <kbd>?</kbd> anytime.</p>
286
+ </div>
287
+ </div>`);
288
+ }
289
+
290
+ function renderMarginalia(): RawHtml {
291
+ return unsafe(html`
292
+ <aside class="er-marginalia" data-comments-sidebar aria-label="Margin notes">
293
+ <p class="er-marginalia-head">Margin notes</p>
294
+ <p class="er-marginalia-empty" data-sidebar-empty>Select text in the draft, then either click the floating <em>Mark</em> pencil above your selection — or click anywhere here in the margin to open the note.</p>
295
+ <section class="er-marginalia-composer" data-comment-composer hidden aria-label="New margin note">
296
+ <p class="er-marginalia-composer-head">New mark</p>
297
+ <div class="er-marginalia-composer-quote" data-composer-quote></div>
298
+ <label class="er-marginalia-composer-label" for="comment-category">Mark as</label>
299
+ <select id="comment-category" class="er-marginalia-composer-select" data-comment-category>
300
+ <option value="other" selected>other</option>
301
+ <option value="voice-drift">voice-drift</option>
302
+ <option value="missing-receipt">missing-receipt</option>
303
+ <option value="tutorial-framing">tutorial-framing</option>
304
+ <option value="saas-vocabulary">saas-vocabulary</option>
305
+ <option value="fake-authority">fake-authority</option>
306
+ <option value="structural">structural</option>
307
+ </select>
308
+ <label class="er-marginalia-composer-label" for="comment-text">Note</label>
309
+ <textarea id="comment-text" class="er-marginalia-composer-textarea" data-comment-text rows="4"
310
+ placeholder="What needs attention here?"></textarea>
311
+ <div class="er-marginalia-composer-actions">
312
+ <button type="button" class="er-btn er-btn-small" data-action="cancel-comment">Cancel</button>
313
+ <button type="button" class="er-btn er-btn-small er-btn-primary" data-action="submit-comment">Leave mark</button>
314
+ </div>
315
+ </section>
316
+ <ol class="er-marginalia-list" data-sidebar-list></ol>
317
+ </aside>`);
318
+ }
319
+
320
+ function renderEditMode(outlineHasContent: boolean): RawHtml {
321
+ const outlineBtnAttrs = outlineHasContent ? '' : ' hidden';
322
+ return unsafe(html`
323
+ <div class="er-edit-mode" data-edit-toolbar hidden>
324
+ <div class="er-edit-chrome">
325
+ <div class="er-edit-modes" role="tablist" aria-label="Editor mode">
326
+ <button class="er-edit-mode-btn" data-edit-view="source" type="button" aria-pressed="true">Source</button>
327
+ <button class="er-edit-mode-btn" data-edit-view="split" type="button" aria-pressed="false">Split</button>
328
+ <button class="er-edit-mode-btn" data-edit-view="preview" type="button" aria-pressed="false">Preview</button>
329
+ </div>
330
+ <div class="er-edit-actions">
331
+ <button class="er-btn er-btn-small" data-action="outline-drawer" type="button" title="Show the outline for reference (O)" aria-pressed="false"${unsafe(outlineBtnAttrs)}>Outline ↗</button>
332
+ <button class="er-btn er-btn-small" data-action="focus-mode" type="button" title="Distraction-free mode (Shift+F)" aria-pressed="false">Focus ⛶</button>
333
+ <button class="er-btn er-btn-primary" data-action="save-version" type="button">Save as new version</button>
334
+ <button class="er-btn" data-action="cancel-edit" type="button">Cancel</button>
335
+ <span class="er-edit-hint" data-edit-hint></span>
336
+ </div>
337
+ </div>
338
+ <div class="er-edit-panes" data-edit-panes data-view="source">
339
+ <div class="er-edit-source" data-edit-source aria-label="Markdown source"></div>
340
+ <div class="er-edit-preview" data-edit-preview aria-label="Rendered preview"></div>
341
+ </div>
342
+ <textarea id="draft-edit" data-draft-edit hidden></textarea>
343
+ <div class="er-focus-exit" data-focus-exit aria-hidden="true">
344
+ <button type="button" data-action="exit-focus" title="Exit focus (Esc)">← exit focus</button>
345
+ </div>
346
+ <div class="er-focus-save" data-focus-save aria-hidden="true">
347
+ <button type="button" class="er-btn er-btn-small er-btn-primary" data-action="save-version">Save</button>
348
+ <span class="er-focus-save-hint" data-focus-save-hint></span>
349
+ </div>
350
+ </div>`);
351
+ }
352
+
353
+ function renderOutlineDrawer(outlineHtml: string): RawHtml {
354
+ const hidden = outlineHtml ? '' : ' hidden';
355
+ return unsafe(html`
356
+ <button class="er-outline-tab" data-outline-tab type="button" aria-label="Show outline"${unsafe(hidden)}>
357
+ <span class="er-outline-tab-label">Outline</span>
358
+ </button>
359
+ <aside class="er-outline-drawer" data-outline-drawer aria-label="Outline reference" hidden>
360
+ <header class="er-outline-drawer-head">
361
+ <span class="er-outline-drawer-kicker">Briefing sheet</span>
362
+ <button type="button" class="er-outline-drawer-close" data-outline-close aria-label="Close outline (O or Esc)">×</button>
363
+ </header>
364
+ <div class="er-outline-drawer-body" data-outline-drawer-body>${unsafe(outlineHtml)}</div>
365
+ <footer class="er-outline-drawer-foot">
366
+ <span>Read-only · edit via <code>/editorial-iterate --kind outline</code></span>
367
+ </footer>
368
+ </aside>`);
369
+ }
370
+
371
+ /**
372
+ * Resolve the calendar entry that backs this review surface. Callers
373
+ * have either an `entryId` (id-canonical route) or a slug (legacy
374
+ * route) to work with. Returns `null` when no calendar entry matches —
375
+ * ad-hoc workflows + pre-doctor entries fall through to the slug-
376
+ * template legacy path elsewhere.
377
+ *
378
+ * Failures (calendar absent, parse error) are swallowed to null so a
379
+ * transient calendar issue never blocks the review render.
380
+ */
381
+ function lookupReviewEntry(
382
+ ctx: StudioContext,
383
+ site: string,
384
+ lookup: ReviewLookup,
385
+ fallbackSlug: string,
386
+ ): CalendarEntry | null {
387
+ try {
388
+ const calendarPath = resolveCalendarPath(ctx.projectRoot, ctx.config, site);
389
+ if (!existsSync(calendarPath)) return null;
390
+ const cal = readCalendar(calendarPath);
391
+ if (lookup.kind === 'id') {
392
+ const byId = findEntryById(cal, lookup.entryId);
393
+ if (byId !== undefined) return byId;
394
+ }
395
+ const slug = lookup.kind === 'workflow' ? fallbackSlug : lookup.slug;
396
+ const bySlug = findEntry(cal, slug);
397
+ return bySlug ?? null;
398
+ } catch {
399
+ return null;
400
+ }
401
+ }
402
+
403
+ export async function renderReviewPage(
404
+ ctx: StudioContext,
405
+ lookup: ReviewLookup,
406
+ query: ReviewQuery,
407
+ getIndex?: ReviewIndexGetter,
408
+ ): Promise<string> {
409
+ const queryKind = pickContentKind(query.kind ?? null);
410
+
411
+ // Workflow-id lookup short-circuits site + entryId resolution: the
412
+ // workflow record carries everything we need to render. Phase 21c
413
+ // added this path so the dashboard's shortform matrix (and any other
414
+ // surface that knows a workflow id) can deep-link to the unified
415
+ // review surface without first knowing the calendar entry id.
416
+ const fetched = lookup.kind === 'workflow'
417
+ ? handleGetWorkflow(ctx.projectRoot, ctx.config, {
418
+ id: lookup.workflowId,
419
+ entryId: null,
420
+ site: null,
421
+ slug: null,
422
+ contentKind: null,
423
+ platform: null,
424
+ channel: null,
425
+ })
426
+ : handleGetWorkflow(ctx.projectRoot, ctx.config, {
427
+ id: null,
428
+ entryId: lookup.kind === 'id' ? lookup.entryId : null,
429
+ site: pickSite(ctx, query.site),
430
+ slug: lookup.slug,
431
+ contentKind: queryKind,
432
+ platform: null,
433
+ channel: null,
434
+ });
435
+
436
+ // Slug used in error messages and the title fallback. For
437
+ // workflow-id lookups we don't know the slug until the fetch
438
+ // succeeds, so use the id as a placeholder for any pre-fetch error.
439
+ const lookupSlug =
440
+ lookup.kind === 'workflow' ? lookup.workflowId : lookup.slug;
441
+ // Site for the chrome / outbound links. Workflow-id lookups carry
442
+ // their own site through the fetched workflow record.
443
+ let resolvedSite = pickSite(ctx, query.site);
444
+
445
+ if (fetched.status !== 200 || !isSuccessBody(fetched.body)) {
446
+ return renderError(
447
+ lookupSlug,
448
+ resolvedSite,
449
+ queryKind,
450
+ errorFromBody(fetched.body),
451
+ );
452
+ }
453
+
454
+ const { workflow, versions } = fetched.body;
455
+ // Workflow-id paths drive contentKind from the workflow itself —
456
+ // it's the source of truth, not the URL kind hint.
457
+ const contentKind: 'longform' | 'outline' | 'shortform' =
458
+ lookup.kind === 'workflow' ? workflow.contentKind : queryKind;
459
+ if (lookup.kind === 'workflow') resolvedSite = workflow.site;
460
+ const slug = workflow.slug;
461
+
462
+ const requested = query.version ? parseInt(query.version, 10) : workflow.currentVersion;
463
+ const currentVersion =
464
+ versions.find((v) => v.version === requested) ?? versions[versions.length - 1];
465
+
466
+ if (!currentVersion) {
467
+ return renderError(
468
+ slug,
469
+ resolvedSite,
470
+ contentKind,
471
+ 'no current version on this workflow',
472
+ );
473
+ }
474
+
475
+ const { fm, bodyHtml, outlineHtml } = await prepareRender(
476
+ currentVersion.markdown,
477
+ contentKind,
478
+ );
479
+
480
+ const draftState = { workflow, currentVersion, versions };
481
+
482
+ const titleField = stringField(fm.title) ?? `Draft: ${slug}`;
483
+
484
+ // Phase 19c+: look up the calendar entry so the scrapbook drawer +
485
+ // inline-text loader can resolve the on-disk scrapbook directory via
486
+ // the content index when a frontmatter-id binding exists. Falls back
487
+ // to slug-template addressing when no entry / no id is present.
488
+ // Shortform skips the scrapbook drawer entirely — different surface
489
+ // shape, no margin-note workflow.
490
+ const reviewEntry = lookupReviewEntry(ctx, resolvedSite, lookup, slug);
491
+ const reviewIndex = getIndex ? getIndex(resolvedSite) : undefined;
492
+ const isShortform = contentKind === 'shortform';
493
+
494
+ // Phase 21c — shortform header. Renders above the editor on the
495
+ // unified review surface so the operator sees the platform (and
496
+ // channel, if any) at a glance. Reuses existing `--er-*` design
497
+ // tokens; no new CSS introduced.
498
+ const shortformMeta: RawHtml = isShortform
499
+ ? unsafe(html`
500
+ <div class="er-shortform-meta">
501
+ <span class="er-platform">${workflow.platform ?? 'other'}</span>
502
+ ${workflow.channel
503
+ ? unsafe(html`<span class="er-channel">${workflow.channel}</span>`)
504
+ : ''}
505
+ </div>`)
506
+ : unsafe('');
507
+
508
+ const reviewUiAttr = isShortform ? 'shortform' : 'longform';
509
+ const folioSpine = isShortform
510
+ ? `shortform · ${workflow.platform ?? '?'}${workflow.channel ? ` · ${workflow.channel}` : ''} · ${slug}`
511
+ : `longform · ${slug}`;
512
+
513
+ const body = html`
514
+ <div data-review-ui="${reviewUiAttr}" class="er-review-shell">
515
+ ${renderEditorialFolio('reviews', folioSpine)}
516
+ ${shortformMeta}
517
+ <div class="er-draft-frame">
518
+ <div id="draft-body" data-draft-body
519
+ title="Double-click to edit · select text to leave a margin note">${unsafe(bodyHtml)}</div>
520
+ ${renderEditMode(outlineHtml.length > 0)}
521
+ </div>
522
+ <div class="er-strip">
523
+ <a class="er-strip-back" href="/dev/editorial-studio" title="Back to the editorial studio">← studio</a>
524
+ <span class="er-strip-galley">Galley <em>№ ${currentVersion.version}</em></span>
525
+ <span class="er-strip-slug">${workflow.site} / ${workflow.slug}</span>
526
+ ${renderVersionsStrip(versions, resolvedSite, contentKind, currentVersion)}
527
+ <span class="er-strip-center">
528
+ <span class="er-stamp er-stamp-big er-stamp-${workflow.state}" data-state-label>
529
+ ${stateLabel(workflow.state)}
530
+ </span>
531
+ <span class="er-strip-hint" aria-hidden="true">select text to mark · double-click to edit · <kbd>?</kbd> for shortcuts</span>
532
+ </span>
533
+ ${renderControlsRight(workflow)}
534
+ </div>
535
+ ${renderMarginalia()}
536
+ <button class="er-pencil-btn" data-add-comment-btn hidden type="button">Mark</button>
537
+ ${isShortform ? unsafe('') : renderOutlineDrawer(outlineHtml)}
538
+ ${isShortform
539
+ ? unsafe('')
540
+ : renderScrapbookDrawer(ctx, resolvedSite, reviewEntry, workflow.slug, reviewIndex)}
541
+ <div class="er-toast" data-toast hidden></div>
542
+ ${renderShortcutsOverlay()}
543
+ <div class="er-poll-indicator" data-poll>auto-refresh · 8s</div>
544
+ </div>`;
545
+
546
+ return layout({
547
+ title: `${titleField} — Review`,
548
+ cssHrefs: [
549
+ '/static/css/editorial-review.css',
550
+ '/static/css/editorial-nav.css',
551
+ '/static/css/blog-figure.css',
552
+ '/static/css/review-viewport.css',
553
+ '/static/css/scrap-row.css',
554
+ ],
555
+ bodyHtml: body,
556
+ embeddedJson: [{ id: 'draft-state', data: draftState }],
557
+ scriptModules: ['/static/dist/editorial-review-client.js'],
558
+ });
559
+ }