@deskwork/studio 0.9.5

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 (93) hide show
  1. package/dist/build-client-assets.d.ts +51 -0
  2. package/dist/build-client-assets.d.ts.map +1 -0
  3. package/dist/build-client-assets.js +341 -0
  4. package/dist/build-client-assets.js.map +1 -0
  5. package/dist/components/scrapbook-item.d.ts +108 -0
  6. package/dist/components/scrapbook-item.d.ts.map +1 -0
  7. package/dist/components/scrapbook-item.js +205 -0
  8. package/dist/components/scrapbook-item.js.map +1 -0
  9. package/dist/lib/editorial-skills-catalogue.d.ts +33 -0
  10. package/dist/lib/editorial-skills-catalogue.d.ts.map +1 -0
  11. package/dist/lib/editorial-skills-catalogue.js +211 -0
  12. package/dist/lib/editorial-skills-catalogue.js.map +1 -0
  13. package/dist/lib/override-render.d.ts +41 -0
  14. package/dist/lib/override-render.d.ts.map +1 -0
  15. package/dist/lib/override-render.js +80 -0
  16. package/dist/lib/override-render.js.map +1 -0
  17. package/dist/listen.d.ts +78 -0
  18. package/dist/listen.d.ts.map +1 -0
  19. package/dist/listen.js +155 -0
  20. package/dist/listen.js.map +1 -0
  21. package/dist/pages/chrome.d.ts +26 -0
  22. package/dist/pages/chrome.d.ts.map +1 -0
  23. package/dist/pages/chrome.js +50 -0
  24. package/dist/pages/chrome.js.map +1 -0
  25. package/dist/pages/content-detail.d.ts +14 -0
  26. package/dist/pages/content-detail.d.ts.map +1 -0
  27. package/dist/pages/content-detail.js +279 -0
  28. package/dist/pages/content-detail.js.map +1 -0
  29. package/dist/pages/content.d.ts +39 -0
  30. package/dist/pages/content.d.ts.map +1 -0
  31. package/dist/pages/content.js +414 -0
  32. package/dist/pages/content.js.map +1 -0
  33. package/dist/pages/dashboard.d.ts +32 -0
  34. package/dist/pages/dashboard.d.ts.map +1 -0
  35. package/dist/pages/dashboard.js +803 -0
  36. package/dist/pages/dashboard.js.map +1 -0
  37. package/dist/pages/help.d.ts +24 -0
  38. package/dist/pages/help.d.ts.map +1 -0
  39. package/dist/pages/help.js +433 -0
  40. package/dist/pages/help.js.map +1 -0
  41. package/dist/pages/html.d.ts +35 -0
  42. package/dist/pages/html.d.ts.map +1 -0
  43. package/dist/pages/html.js +73 -0
  44. package/dist/pages/html.js.map +1 -0
  45. package/dist/pages/index.d.ts +21 -0
  46. package/dist/pages/index.d.ts.map +1 -0
  47. package/dist/pages/index.js +174 -0
  48. package/dist/pages/index.js.map +1 -0
  49. package/dist/pages/layout.d.ts +33 -0
  50. package/dist/pages/layout.d.ts.map +1 -0
  51. package/dist/pages/layout.js +50 -0
  52. package/dist/pages/layout.js.map +1 -0
  53. package/dist/pages/review-scrapbook-drawer.d.ts +20 -0
  54. package/dist/pages/review-scrapbook-drawer.d.ts.map +1 -0
  55. package/dist/pages/review-scrapbook-drawer.js +98 -0
  56. package/dist/pages/review-scrapbook-drawer.js.map +1 -0
  57. package/dist/pages/review.d.ts +68 -0
  58. package/dist/pages/review.d.ts.map +1 -0
  59. package/dist/pages/review.js +434 -0
  60. package/dist/pages/review.js.map +1 -0
  61. package/dist/pages/scrapbook.d.ts +21 -0
  62. package/dist/pages/scrapbook.d.ts.map +1 -0
  63. package/dist/pages/scrapbook.js +250 -0
  64. package/dist/pages/scrapbook.js.map +1 -0
  65. package/dist/pages/shortform.d.ts +17 -0
  66. package/dist/pages/shortform.d.ts.map +1 -0
  67. package/dist/pages/shortform.js +142 -0
  68. package/dist/pages/shortform.js.map +1 -0
  69. package/dist/request-context.d.ts +52 -0
  70. package/dist/request-context.d.ts.map +1 -0
  71. package/dist/request-context.js +84 -0
  72. package/dist/request-context.js.map +1 -0
  73. package/dist/routes/api.d.ts +36 -0
  74. package/dist/routes/api.d.ts.map +1 -0
  75. package/dist/routes/api.js +175 -0
  76. package/dist/routes/api.js.map +1 -0
  77. package/dist/routes/scrapbook-file.d.ts +19 -0
  78. package/dist/routes/scrapbook-file.d.ts.map +1 -0
  79. package/dist/routes/scrapbook-file.js +77 -0
  80. package/dist/routes/scrapbook-file.js.map +1 -0
  81. package/dist/routes/scrapbook-mutations.d.ts +33 -0
  82. package/dist/routes/scrapbook-mutations.d.ts.map +1 -0
  83. package/dist/routes/scrapbook-mutations.js +310 -0
  84. package/dist/routes/scrapbook-mutations.js.map +1 -0
  85. package/dist/server.d.ts +52 -0
  86. package/dist/server.d.ts.map +1 -0
  87. package/dist/server.js +581 -0
  88. package/dist/server.js.map +1 -0
  89. package/dist/tailscale.d.ts +63 -0
  90. package/dist/tailscale.d.ts.map +1 -0
  91. package/dist/tailscale.js +118 -0
  92. package/dist/tailscale.js.map +1 -0
  93. package/package.json +60 -0
@@ -0,0 +1,803 @@
1
+ /**
2
+ * Studio dashboard page — `/dev/editorial-studio`.
3
+ *
4
+ * Ported from audiocontrol.org's `editorial-studio.astro`. Reads each
5
+ * site's calendar + the review pipeline + the report, then renders the
6
+ * five-stage editorial calendar with site filtering, the shortform
7
+ * coverage matrix for Published blog entries, awaiting-press / recent-
8
+ * proofs panels, and a voice-drift signal sidebar.
9
+ *
10
+ * The audiocontrol original was tightly coupled to two hardcoded sites
11
+ * (`'audiocontrol' | 'editorialcontrol'`) and the `feature-image`
12
+ * pipeline. Both go away here:
13
+ *
14
+ * - Sites come from `ctx.config.sites`. The two-letter site label
15
+ * (was `'AC' | 'EC'`) is the first 2 letters uppercased.
16
+ * - The feature-image pipeline isn't part of deskwork core yet; the
17
+ * "feature image →" / "✓ baked" affordances are dropped. The
18
+ * scrapbook chip stays — `@deskwork/core/scrapbook` provides
19
+ * `countScrapbook`.
20
+ */
21
+ import { readCalendar } from '@deskwork/core/calendar';
22
+ import { buildReport, } from '@deskwork/core/review/report';
23
+ import { readWorkflows } from '@deskwork/core/review/pipeline';
24
+ import { bodyState } from '@deskwork/core/body-state';
25
+ import { countScrapbook, countScrapbookForEntry } from '@deskwork/core/scrapbook';
26
+ import { PLATFORMS, STAGES, effectiveContentType, hasRepoContent, } from '@deskwork/core/types';
27
+ import { resolveCalendarPath, resolveBlogFilePath, findEntryFile, } from '@deskwork/core/paths';
28
+ import { html, unsafe } from "./html.js";
29
+ import { layout } from "./layout.js";
30
+ import { renderEditorialFolio } from "./chrome.js";
31
+ const PLATFORMS_ORDER = [
32
+ 'reddit',
33
+ 'linkedin',
34
+ 'youtube',
35
+ 'instagram',
36
+ ];
37
+ const STAGE_ORNAMENTS = {
38
+ Ideas: '◇',
39
+ Planned: '§',
40
+ Outlining: '⊹',
41
+ Drafting: '✎',
42
+ Review: '※',
43
+ Paused: '⏸',
44
+ Published: '✓',
45
+ };
46
+ const MONTH_NAMES = [
47
+ 'January', 'February', 'March', 'April', 'May', 'June',
48
+ 'July', 'August', 'September', 'October', 'November', 'December',
49
+ ];
50
+ function isPlatform(value) {
51
+ return PLATFORMS.includes(value);
52
+ }
53
+ function siteLabel(site) {
54
+ return site.slice(0, 2).toUpperCase();
55
+ }
56
+ function stateLabel(state) {
57
+ return state.replace('-', ' ');
58
+ }
59
+ /**
60
+ * Internal correlation key for the dashboard's `Map<key, …>` joins.
61
+ * Phase 19d: prefer the calendar entry's stable UUID when present,
62
+ * falling back to the slug for legacy data (workflows / entries
63
+ * created before frontmatter ids landed). The function is overloaded
64
+ * via two arities — `covKey(site, slug)` for slug-only callers and
65
+ * `covKey(site, slug, entryId)` for callers that have access to the
66
+ * id. The latter form picks `entryId` when it's a non-empty string,
67
+ * else falls through to `slug`. Display still uses slug as the human
68
+ * label; this key only correlates internally.
69
+ *
70
+ * The "fallback" here is the legacy migration path — not the kind of
71
+ * silent fallback the project rules forbid. Doctor reports the legacy
72
+ * cases so operators can backfill ids.
73
+ */
74
+ function covKey(site, slug, entryId) {
75
+ const stable = entryId !== undefined && entryId !== null && entryId !== ''
76
+ ? entryId
77
+ : slug;
78
+ return `${site}::${stable}`;
79
+ }
80
+ function fmtRelTime(iso, now) {
81
+ const t = new Date(iso).getTime();
82
+ const s = Math.max(0, Math.floor((now.getTime() - t) / 1000));
83
+ if (s < 60)
84
+ return `${s}s ago`;
85
+ const m = Math.floor(s / 60);
86
+ if (m < 60)
87
+ return `${m}m ago`;
88
+ const h = Math.floor(m / 60);
89
+ if (h < 48)
90
+ return `${h}h ago`;
91
+ return `${Math.floor(h / 24)}d ago`;
92
+ }
93
+ function workflowLink(w) {
94
+ if (w.contentKind === 'shortform') {
95
+ // Phase 21c: shortform now renders inside the unified review
96
+ // surface. Workflow-id deep-links land on the right workflow
97
+ // without first resolving an entry id — the route handler
98
+ // recognises a workflow id and dispatches accordingly.
99
+ return `/dev/editorial-review/${w.id}`;
100
+ }
101
+ // Phase 19d: prefer the canonical id-based URL when the workflow
102
+ // carries entryId. The legacy slug URL still works (server.ts will
103
+ // 302-redirect it), but emitting the canonical form skips the
104
+ // redirect round trip and makes the UI's outbound links honest.
105
+ const key = w.entryId ?? w.slug;
106
+ const kindBit = w.contentKind === 'outline' ? '&kind=outline' : '';
107
+ return `/dev/editorial-review/${key}?site=${w.site}${kindBit}`;
108
+ }
109
+ function blogPreviewLink(site, slug, host, entry) {
110
+ if (entry.stage === 'Published')
111
+ return `https://${host}/blog/${slug}/`;
112
+ // Phase 19d: prefer the canonical id-based URL.
113
+ const key = entry.id ?? slug;
114
+ return `/dev/editorial-review/${key}?site=${site}`;
115
+ }
116
+ function loadDashboardData(ctx, getIndex) {
117
+ // `getIndex` is currently consumed downstream by renderRow →
118
+ // entryBodyStateOf, not here. Threading it through keeps the call
119
+ // signature symmetric with renderDashboard and leaves room for
120
+ // future load-time uses (e.g., joining workflows by entry id).
121
+ void getIndex;
122
+ const calendarEntries = [];
123
+ const distributions = [];
124
+ const slugsBySite = {};
125
+ const sites = Object.keys(ctx.config.sites);
126
+ for (const site of sites) {
127
+ slugsBySite[site] = [];
128
+ const calendarPath = resolveCalendarPath(ctx.projectRoot, ctx.config, site);
129
+ const cal = readCalendar(calendarPath);
130
+ // Build a slug → id map up front so distributions can resolve
131
+ // their entry's stable id even when the DistributionRecord
132
+ // pre-dates the entryId field.
133
+ const idBySlug = new Map();
134
+ for (const entry of cal.entries) {
135
+ calendarEntries.push({ site, entry });
136
+ slugsBySite[site].push(entry.slug);
137
+ if (entry.id)
138
+ idBySlug.set(entry.slug, entry.id);
139
+ }
140
+ for (const d of cal.distributions) {
141
+ const dr = d;
142
+ const entryId = dr.entryId ?? idBySlug.get(dr.slug) ?? null;
143
+ distributions.push({
144
+ site,
145
+ platform: dr.platform,
146
+ slug: dr.slug,
147
+ entryId,
148
+ shortform: typeof dr.shortform === 'string' && dr.shortform.length > 0,
149
+ });
150
+ }
151
+ }
152
+ const workflows = readWorkflows(ctx.projectRoot, ctx.config);
153
+ const approved = workflows.filter((w) => w.state === 'approved');
154
+ const terminal = workflows
155
+ .filter((w) => w.state === 'applied' || w.state === 'cancelled')
156
+ .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))
157
+ .slice(0, 10);
158
+ const shortformCoverage = new Map();
159
+ for (const d of distributions) {
160
+ if (!d.shortform)
161
+ continue;
162
+ if (!isPlatform(d.platform))
163
+ continue;
164
+ const key = covKey(d.site, d.slug, d.entryId);
165
+ const set = shortformCoverage.get(key) ?? new Set();
166
+ set.add(d.platform);
167
+ shortformCoverage.set(key, set);
168
+ }
169
+ // Phase 21c — shortform workflows count as coverage too. Distributions
170
+ // come from the calendar (an `editorial-publish` side-effect), so a
171
+ // freshly-started shortform draft (no published-yet distribution
172
+ // record) wouldn't show in the matrix without this branch.
173
+ for (const w of workflows) {
174
+ if (w.contentKind !== 'shortform')
175
+ continue;
176
+ if (w.state === 'applied' || w.state === 'cancelled')
177
+ continue;
178
+ if (!w.platform || !isPlatform(w.platform))
179
+ continue;
180
+ const key = covKey(w.site, w.slug, w.entryId);
181
+ const set = shortformCoverage.get(key) ?? new Set();
182
+ set.add(w.platform);
183
+ shortformCoverage.set(key, set);
184
+ }
185
+ const publishedBlogEntries = calendarEntries
186
+ .filter(({ entry }) => entry.stage === 'Published' && effectiveContentType(entry) === 'blog')
187
+ .sort((a, b) => (b.entry.datePublished ?? '').localeCompare(a.entry.datePublished ?? ''));
188
+ const activeBySitedSlug = new Map();
189
+ for (const w of workflows) {
190
+ if (w.state === 'applied' || w.state === 'cancelled')
191
+ continue;
192
+ const key = covKey(w.site, w.slug, w.entryId);
193
+ const list = activeBySitedSlug.get(key) ?? [];
194
+ list.push(w);
195
+ activeBySitedSlug.set(key, list);
196
+ }
197
+ const report = buildReport(ctx.projectRoot, ctx.config, {});
198
+ return {
199
+ calendarEntries,
200
+ distributions,
201
+ slugsBySite,
202
+ workflows,
203
+ approved,
204
+ terminal,
205
+ publishedBlogEntries,
206
+ shortformCoverage,
207
+ activeBySitedSlug,
208
+ report,
209
+ };
210
+ }
211
+ function entryBodyStateOf(ctx, site, entry, getIndex) {
212
+ if (!hasRepoContent(effectiveContentType(entry)))
213
+ return 'missing';
214
+ // When the entry has a stable id AND the route layer wired in a
215
+ // per-request index getter, use the id-driven content-index lookup
216
+ // — this matches files whose path doesn't follow the slug template
217
+ // (e.g., writingcontrol-shape projects where slug `the-outbound`
218
+ // resolves to `projects/the-outbound/index.md` while the calendar
219
+ // slug doesn't bake the path). Without an id or getter, fall back
220
+ // to the slug-template behavior so non-route callers still work.
221
+ if (entry.id !== undefined && entry.id !== '' && getIndex) {
222
+ const path = findEntryFile(ctx.projectRoot, ctx.config, site, entry.id, getIndex(site), { slug: entry.slug });
223
+ if (path !== undefined)
224
+ return bodyState(path);
225
+ }
226
+ const fallback = resolveBlogFilePath(ctx.projectRoot, ctx.config, site, entry.slug);
227
+ return bodyState(fallback);
228
+ }
229
+ function findStageWorkflow(data, site, entry, stage) {
230
+ const list = data.activeBySitedSlug.get(covKey(site, entry.slug, entry.id)) ?? [];
231
+ if (stage === 'Outlining')
232
+ return list.find((w) => w.contentKind === 'outline');
233
+ return list.find((w) => w.contentKind === 'longform');
234
+ }
235
+ // ---------------------------------------------------------------------------
236
+ // Section renderers
237
+ // ---------------------------------------------------------------------------
238
+ function renderHeader(data, ctx, now) {
239
+ const volume = '01';
240
+ const issueNum = String(data.workflows.length).padStart(2, '0');
241
+ const issueDate = `${now.getDate()} ${MONTH_NAMES[now.getMonth()]} ${now.getFullYear()}`;
242
+ return unsafe(html `
243
+ <header class="er-pagehead er-pagehead--centered">
244
+ <p class="er-pagehead__kicker">
245
+ Vol. ${volume} &middot; № ${issueNum} &middot; Press-check
246
+ </p>
247
+ <h1 class="er-pagehead__title">
248
+ Editorial <em>Studio</em>
249
+ </h1>
250
+ <p class="er-pagehead__deck">
251
+ Project: <code>${ctx.projectRoot}</code>
252
+ &nbsp;·&nbsp; <a class="er-link-marginalia" href="/dev/editorial-help">the manual</a>
253
+ </p>
254
+ <p class="er-pagehead__meta">
255
+ <span>${issueDate}</span>
256
+ <span class="sep">·</span>
257
+ <span>${data.calendarEntries.length} on the calendar</span>
258
+ <span class="sep">·</span>
259
+ <span>${data.activeBySitedSlug.size} in review</span>
260
+ <span class="sep">·</span>
261
+ <span>${data.approved.length} awaiting press</span>
262
+ </p>
263
+ </header>`);
264
+ }
265
+ function renderFilterStrip(sites) {
266
+ return unsafe(html `
267
+ <section class="er-filter" data-filter-strip>
268
+ <span class="er-filter-label">Find</span>
269
+ <input type="search" data-filter-input placeholder="slug, title…" autocomplete="off" />
270
+ <span class="er-filter-label er-filter-label--gap">Site</span>
271
+ <div class="er-chips" role="tablist">
272
+ <button class="er-chip" aria-pressed="true" data-site-chip="all">all</button>
273
+ ${sites.map((s) => unsafe(html `<button class="er-chip" data-site-chip="${s}">${siteLabel(s).toLowerCase()}</button>`))}
274
+ </div>
275
+ <span class="er-filter-label er-filter-label--gap">Stage</span>
276
+ <div class="er-chips" role="tablist">
277
+ <button class="er-chip" aria-pressed="true" data-stage-chip="all">all</button>
278
+ ${STAGES.map((s) => unsafe(html `<button class="er-chip" data-stage-chip="${s}">${s.toLowerCase()}</button>`))}
279
+ </div>
280
+ </section>`);
281
+ }
282
+ const STAGE_EMPTY_MESSAGES = {
283
+ Ideas: 'No open ideas. Run /editorial-add to capture one.',
284
+ Planned: 'Nothing planned. /editorial-plan <slug> to promote an idea.',
285
+ Outlining: 'Nothing in outlining. /editorial-outline <slug> to start one.',
286
+ Drafting: 'No posts in drafting.',
287
+ Review: 'Nothing in review stage.',
288
+ Paused: 'Nothing paused. /deskwork:pause <slug> sets an entry aside without losing where it was.',
289
+ Published: 'No published posts yet.',
290
+ };
291
+ function renderRowMeta(ctx, site, entry, stage, hasFile, getIndex) {
292
+ const kind = effectiveContentType(entry);
293
+ const parts = [];
294
+ if (entry.targetKeywords && entry.targetKeywords.length > 0 && stage === 'Planned') {
295
+ parts.push(unsafe(html `<span class="er-calendar-meta"><em>kw:</em> ${entry.targetKeywords.join(', ')}</span>`));
296
+ }
297
+ if (entry.issueNumber && entry.issueNumber > 0) {
298
+ parts.push(unsafe(html `<span class="er-calendar-meta">issue #${entry.issueNumber}</span>`));
299
+ }
300
+ if (entry.datePublished && stage === 'Published') {
301
+ parts.push(unsafe(html `<span class="er-calendar-meta">${entry.datePublished}</span>`));
302
+ }
303
+ if (stage === 'Paused' && entry.pausedFrom) {
304
+ parts.push(unsafe(html `<span class="er-calendar-meta"><em>was:</em> ${entry.pausedFrom}</span>`));
305
+ }
306
+ if (kind !== 'blog') {
307
+ parts.push(unsafe(html `<span class="er-calendar-meta er-calendar-meta-kind">${kind}</span>`));
308
+ }
309
+ if (kind === 'blog' && hasFile) {
310
+ // Phase 19c+: prefer the id-driven content-index lookup so entries
311
+ // whose on-disk path doesn't match the slug template (e.g.
312
+ // writingcontrol-shape projects) report the correct count. When the
313
+ // entry has no id binding OR no per-request index getter is wired,
314
+ // fall through to the slug-template path. The fallback is the
315
+ // legacy migration path, not a silent default — doctor reports the
316
+ // unbound cases so operators can backfill ids.
317
+ const n = entry.id !== undefined && entry.id !== '' && getIndex
318
+ ? countScrapbookForEntry(ctx.projectRoot, ctx.config, site, entry, getIndex(site))
319
+ : countScrapbook(ctx.projectRoot, ctx.config, site, entry.slug);
320
+ if (n > 0) {
321
+ const label = n === 1 ? 'scrapbook item' : 'scrapbook items';
322
+ parts.push(unsafe(html `<a class="er-calendar-meta er-calendar-meta-scrapbook er-calendar-meta-link"
323
+ href="/dev/scrapbook/${site}/${entry.slug}"
324
+ title="${n} ${label}">scrapbook · <span class="er-calendar-meta-scrapbook-count">${n}</span> →</a>`));
325
+ }
326
+ }
327
+ return unsafe(parts.map((p) => p.__raw).join(''));
328
+ }
329
+ function renderRowActions(site, entry, stage, hasFile, bodyWritten, wf) {
330
+ const kind = effectiveContentType(entry);
331
+ const buttons = [];
332
+ if (stage === 'Ideas') {
333
+ buttons.push(html `<button class="er-btn er-btn-small er-copy-btn" type="button"
334
+ data-copy="/editorial-plan --site ${site} ${entry.slug}" title="copy command">plan →</button>`);
335
+ }
336
+ if (stage === 'Planned' && !hasFile) {
337
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-primary" type="button"
338
+ data-action="scaffold-draft" data-site="${site}" data-slug="${entry.slug}">scaffold →</button>`);
339
+ }
340
+ if (stage === 'Planned' && hasFile) {
341
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-primary er-copy-btn" type="button"
342
+ data-copy="/editorial-outline --site ${site} ${entry.slug}"
343
+ title="scaffold file exists — copy to sketch the outline in Claude Code">outline →</button>`);
344
+ }
345
+ if (stage === 'Outlining' && wf && wf.state === 'iterating') {
346
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-primary er-copy-btn" type="button"
347
+ data-copy="/editorial-iterate --kind outline --site ${site} ${entry.slug}"
348
+ title="operator clicked Iterate">iterate outline →</button>`);
349
+ }
350
+ if (stage === 'Outlining' && wf && wf.state === 'approved') {
351
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-approve er-copy-btn" type="button"
352
+ data-copy="/editorial-outline-approve --site ${site} ${entry.slug}"
353
+ title="outline approved — advance to Drafting">approve outline →</button>`);
354
+ }
355
+ if (stage === 'Outlining' &&
356
+ wf &&
357
+ (wf.state === 'open' || wf.state === 'in-review')) {
358
+ buttons.push(html `<a class="er-btn er-btn-small" href="${workflowLink(wf)}"
359
+ title="open the review surface to annotate / edit the outline">review outline →</a>`);
360
+ }
361
+ if (stage === 'Outlining' && !wf) {
362
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-primary er-copy-btn" type="button"
363
+ data-copy="/editorial-outline --site ${site} ${entry.slug}"
364
+ title="no outline workflow found — copy to (re)start one">outline →</button>`);
365
+ }
366
+ if ((stage === 'Drafting' || stage === 'Review') && !bodyWritten) {
367
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-primary er-copy-btn" type="button"
368
+ data-copy="/editorial-draft --site ${site} ${entry.slug}"
369
+ title="body is still the placeholder">draft body →</button>`);
370
+ }
371
+ if ((stage === 'Drafting' || stage === 'Review') && bodyWritten && !wf) {
372
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-primary" type="button"
373
+ data-action="enqueue-review" data-site="${site}" data-slug="${entry.slug}"
374
+ title="body is drafted — create a longform review workflow">review →</button>`);
375
+ }
376
+ if (stage === 'Drafting' || stage === 'Review') {
377
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-approve" type="button"
378
+ data-action="mark-published" data-site="${site}" data-slug="${entry.slug}"
379
+ title="flip to Published + set date">publish →</button>`);
380
+ }
381
+ if (stage === 'Published' && !wf) {
382
+ buttons.push(html `<button class="er-btn er-btn-small er-copy-btn" type="button"
383
+ data-copy="/editorial-draft-review --site ${site} ${entry.slug}"
384
+ title="re-review a published post">re-review</button>`);
385
+ }
386
+ // #27 — Paused gets a "resume" copy; pausable stages get a "pause" copy.
387
+ if (stage === 'Paused') {
388
+ buttons.push(html `<button class="er-btn er-btn-small er-btn-primary er-copy-btn" type="button"
389
+ data-copy="/deskwork:resume --site ${site} ${entry.slug}"
390
+ title="restore to ${entry.pausedFrom ?? 'prior stage'}">resume →</button>`);
391
+ }
392
+ else if (stage === 'Ideas' ||
393
+ stage === 'Planned' ||
394
+ stage === 'Outlining' ||
395
+ stage === 'Drafting' ||
396
+ stage === 'Review') {
397
+ buttons.push(html `<button class="er-btn er-btn-small er-copy-btn" type="button"
398
+ data-copy="/deskwork:pause --site ${site} ${entry.slug}"
399
+ title="set aside without losing the prior stage">pause</button>`);
400
+ }
401
+ if (kind === 'blog') {
402
+ buttons.push(html `<button class="er-btn er-btn-small" type="button" data-action="rename-open"
403
+ title="rename the slug — copies /editorial-rename-slug to clipboard">rename →</button>`);
404
+ }
405
+ return unsafe(`<span class="er-calendar-action">${buttons.join('')}</span>`);
406
+ }
407
+ function renderRow(ctx, data, sited, stage, index, getIndex) {
408
+ const { site, entry } = sited;
409
+ const kind = effectiveContentType(entry);
410
+ const body = entryBodyStateOf(ctx, site, entry, getIndex);
411
+ const hasFile = body !== 'missing';
412
+ const bodyWritten = body === 'written';
413
+ const wf = findStageWorkflow(data, site, entry, stage);
414
+ const search = [
415
+ entry.slug,
416
+ entry.title,
417
+ (entry.targetKeywords ?? []).join(' '),
418
+ kind,
419
+ site,
420
+ ].join(' ').toLowerCase();
421
+ const host = ctx.config.sites[site]?.host ?? site;
422
+ const slugCell = wf
423
+ ? unsafe(html `<a href="${workflowLink(wf)}" title="open the review surface">${entry.slug}</a>`)
424
+ : hasFile
425
+ ? unsafe(html `<a href="${blogPreviewLink(site, entry.slug, host, entry)}"
426
+ title="${entry.stage === 'Published' ? 'read the published article' : 'open the review surface for this draft'}">${entry.slug}</a>`)
427
+ : entry.slug;
428
+ const fileDot = hasRepoContent(kind)
429
+ ? unsafe(html `<span class="er-file-dot er-file-${body}"
430
+ title="${body === 'missing'
431
+ ? 'no blog file'
432
+ : body === 'placeholder'
433
+ ? 'scaffold present, body is the placeholder'
434
+ : 'body written'}">●</span>`)
435
+ : '';
436
+ const stamp = wf
437
+ ? unsafe(html `<span class="er-stamp er-stamp-${wf.state}">${stateLabel(wf.state)} v${wf.currentVersion}</span>`)
438
+ : '';
439
+ const renameForm = kind === 'blog'
440
+ ? unsafe(html `<form class="er-rename-inline" data-rename-form
441
+ data-site="${site}" data-slug="${entry.slug}" hidden>
442
+ <span class="er-rename-kicker" aria-hidden="true">rename →</span>
443
+ <code class="er-rename-old" title="current slug; will 301 after rename">${entry.slug}</code>
444
+ <span class="er-rename-arrow" aria-hidden="true">→</span>
445
+ <input type="text" name="new-slug" data-rename-input autocomplete="off" spellcheck="false"
446
+ placeholder="new-slug-here" aria-label="new slug" required />
447
+ <small class="er-rename-hint" data-rename-hint>lowercase, digits, hyphens</small>
448
+ <button type="button" class="er-btn er-btn-small" data-action="rename-cancel">cancel</button>
449
+ <button type="submit" class="er-btn er-btn-small er-btn-primary"
450
+ data-action="rename-copy">copy /rename →</button>
451
+ </form>`)
452
+ : '';
453
+ // Hierarchical entries (slugs containing `/`) get a depth indicator the
454
+ // CSS layer indents off of. Storage stays flat; this is a display-only
455
+ // marker. Depth = number of `/` in the slug (so "the-outbound" → 0,
456
+ // "the-outbound/characters" → 1, etc.).
457
+ const depth = entry.slug.split('/').length - 1;
458
+ const depthAttrs = depth > 0
459
+ ? unsafe(html ` data-depth="${depth}" style="--er-row-depth: ${depth}"`)
460
+ : '';
461
+ // For nested entries, show only the leaf segment as the prominent
462
+ // identifier — the ancestor segments are implied by the visual indent
463
+ // and the position in the sorted list.
464
+ const slugDisplay = depth > 0
465
+ ? unsafe(html `<span class="er-row-slug-ancestors" aria-hidden="true">${entry.slug.slice(0, entry.slug.lastIndexOf('/') + 1)}</span><span class="er-row-slug-leaf">${entry.slug.slice(entry.slug.lastIndexOf('/') + 1)}</span>`)
466
+ : '';
467
+ const slugCellWithHierarchy = depth > 0 ? slugDisplay : slugCell;
468
+ return unsafe(html `
469
+ <div class="er-calendar-row-wrap" data-row-wrap data-search="${search}"${depthAttrs}>
470
+ <div class="er-calendar-row" data-stage="${stage}" data-site="${site}"
471
+ data-slug="${entry.slug}" data-search="${search}">
472
+ <span class="er-row-num">№ ${String(index + 1).padStart(2, '0')}</span>
473
+ <div class="er-calendar-body">
474
+ <span class="er-row-site er-row-site--${site}" title="${host}">${siteLabel(site)}</span>
475
+ <span class="er-row-slug">${depth > 0 ? slugCellWithHierarchy : slugCell}</span>
476
+ <span class="er-calendar-title">${entry.title}</span>
477
+ ${renderRowMeta(ctx, site, entry, stage, hasFile, getIndex)}
478
+ </div>
479
+ <span class="er-calendar-status">${fileDot}${stamp}</span>
480
+ ${renderRowActions(site, entry, stage, hasFile, bodyWritten, wf)}
481
+ </div>
482
+ ${renameForm}
483
+ </div>`);
484
+ }
485
+ function renderStageSection(ctx, data, stage, entries, sites, getIndex) {
486
+ const intakeBlock = stage === 'Ideas'
487
+ ? unsafe(html `
488
+ <div class="er-intake-form" data-intake-form hidden>
489
+ <p class="er-intake-hint">
490
+ Fill in what you know; the agent will use the values verbatim.
491
+ </p>
492
+ <div class="er-intake-grid">
493
+ <label>
494
+ <span>Site</span>
495
+ <select data-intake-field="site">
496
+ ${sites.map((s) => unsafe(html `<option value="${s}">${s}</option>`))}
497
+ </select>
498
+ </label>
499
+ <label>
500
+ <span>Content type</span>
501
+ <select data-intake-field="contentType">
502
+ <option value="blog">blog (default)</option>
503
+ <option value="youtube">youtube</option>
504
+ <option value="tool">tool</option>
505
+ </select>
506
+ </label>
507
+ <label class="er-intake-wide">
508
+ <span>Title</span>
509
+ <input type="text" data-intake-field="title" placeholder="Working title" />
510
+ </label>
511
+ <label class="er-intake-wide">
512
+ <span>Description</span>
513
+ <textarea data-intake-field="description" rows="4"></textarea>
514
+ </label>
515
+ <label class="er-intake-wide" data-intake-content-url hidden>
516
+ <span>Content URL</span>
517
+ <input type="url" data-intake-field="contentUrl" placeholder="https://..." />
518
+ </label>
519
+ </div>
520
+ <div class="er-intake-actions">
521
+ <button class="er-btn er-btn-small" type="button" data-action="intake-cancel">cancel</button>
522
+ <button class="er-btn er-btn-small er-btn-primary" type="button"
523
+ data-action="intake-copy">copy intake →</button>
524
+ </div>
525
+ </div>`)
526
+ : '';
527
+ const intakeButton = stage === 'Ideas'
528
+ ? unsafe(html `<button class="er-btn er-btn-small er-section-action" type="button"
529
+ data-action="intake-toggle"
530
+ title="fill out an intake sheet">intake new idea →</button>`)
531
+ : '';
532
+ const body = entries.length === 0
533
+ ? unsafe(html `<div class="er-empty" style="padding: 1rem 0.25rem; font-size: 0.95rem;">
534
+ ${STAGE_EMPTY_MESSAGES[stage]}
535
+ </div>`)
536
+ : unsafe(entries
537
+ .map((e, i) => renderRow(ctx, data, e, stage, i, getIndex).__raw)
538
+ .join(''));
539
+ return unsafe(html `
540
+ <section class="er-section" data-stage-section="${stage}">
541
+ <h2 class="er-section-head">
542
+ <span>${stage}</span>
543
+ <span class="ornament">${STAGE_ORNAMENTS[stage]}</span>
544
+ <span class="count">№ ${entries.length}</span>
545
+ ${intakeButton}
546
+ </h2>
547
+ ${intakeBlock}
548
+ ${body}
549
+ </section>`);
550
+ }
551
+ /**
552
+ * Shortform workflow lookup keyed by (site, entryId|slug, platform).
553
+ * Built once per dashboard render so the coverage matrix can render
554
+ * each covered cell as a direct link to the workflow's review surface
555
+ * — phase 21c replaces the prior "✓" sigil + copy-CLI-command flow.
556
+ */
557
+ function indexShortformWorkflows(data) {
558
+ const out = new Map();
559
+ for (const w of data.workflows) {
560
+ if (w.contentKind !== 'shortform')
561
+ continue;
562
+ if (w.state === 'applied' || w.state === 'cancelled')
563
+ continue;
564
+ if (!w.platform)
565
+ continue;
566
+ const key = `${covKey(w.site, w.slug, w.entryId)}::${w.platform}`;
567
+ out.set(key, w);
568
+ }
569
+ return out;
570
+ }
571
+ function renderShortformMatrix(data, ctx) {
572
+ if (data.publishedBlogEntries.length === 0)
573
+ return unsafe('');
574
+ const wfIndex = indexShortformWorkflows(data);
575
+ const rows = data.publishedBlogEntries.map(({ site, entry }) => {
576
+ const covered = data.shortformCoverage.get(covKey(site, entry.slug, entry.id)) ??
577
+ new Set();
578
+ const cells = PLATFORMS_ORDER.map((p) => {
579
+ const has = covered.has(p);
580
+ const wfKey = `${covKey(site, entry.slug, entry.id)}::${p}`;
581
+ const wf = wfIndex.get(wfKey);
582
+ // A covered cell with a live workflow → link straight into the
583
+ // unified review surface. A covered cell without a workflow
584
+ // (distribution recorded outside the studio's pipeline — legacy
585
+ // data) keeps the static "✓" so the matrix doesn't lie about
586
+ // what's clickable. Empty cells render a real start button that
587
+ // POSTs to /api/dev/editorial-review/start-shortform and
588
+ // navigates to the new workflow's review URL.
589
+ let inner;
590
+ if (has && wf) {
591
+ inner = html `<a class="er-sf-link" href="/dev/editorial-review/${wf.id}"
592
+ title="${p} workflow · open in review">✓</a>`;
593
+ }
594
+ else if (has) {
595
+ inner = html `<span class="er-sf-check" title="${p} copy drafted">✓</span>`;
596
+ }
597
+ else {
598
+ inner = html `<button class="er-sf-start-btn" type="button"
599
+ data-action="start-shortform"
600
+ data-site="${site}"
601
+ data-slug="${entry.slug}"
602
+ data-platform="${p}"
603
+ title="Start a ${p} shortform draft for ${entry.slug}">start</button>`;
604
+ }
605
+ const cls = has ? 'er-sf-cell er-sf-cell-covered' : 'er-sf-cell er-sf-cell-empty';
606
+ return html `<td class="${cls}">${unsafe(inner)}</td>`;
607
+ }).join('');
608
+ const host = ctx.config.sites[site]?.host ?? site;
609
+ return html `
610
+ <tr data-site="${site}">
611
+ <th scope="row" class="er-sf-slug">
612
+ <span class="er-row-site er-row-site--${site}" title="${host}">${siteLabel(site)}</span>
613
+ ${entry.slug}
614
+ </th>
615
+ ${unsafe(cells)}
616
+ </tr>`;
617
+ }).join('');
618
+ return unsafe(html `
619
+ <section class="er-section">
620
+ <h2 class="er-section-head">
621
+ <span>Short form · coverage</span>
622
+ <span class="count">${data.publishedBlogEntries.length} × ${PLATFORMS_ORDER.length}</span>
623
+ </h2>
624
+ <table class="er-sf-matrix">
625
+ <thead>
626
+ <tr>
627
+ <th scope="col" class="er-sf-slug-col">slug</th>
628
+ ${PLATFORMS_ORDER.map((p) => unsafe(html `<th scope="col" class="er-sf-platform er-sf-platform-${p}">${p}</th>`))}
629
+ </tr>
630
+ </thead>
631
+ <tbody>${unsafe(rows)}</tbody>
632
+ </table>
633
+ </section>`);
634
+ }
635
+ function renderApprovedSection(data, ctx) {
636
+ if (data.approved.length === 0)
637
+ return unsafe('');
638
+ const rows = data.approved
639
+ .map((w) => {
640
+ const host = ctx.config.sites[w.site]?.host ?? w.site;
641
+ const platformBit = w.contentKind === 'shortform' && w.platform
642
+ ? html `<span class="er-row-channel"> · ${w.platform}${w.channel ? ` · ${w.channel}` : ''}</span>`
643
+ : '';
644
+ const flagBit = w.contentKind === 'shortform' && w.platform
645
+ ? ` --platform ${w.platform}${w.channel ? ` --channel ${w.channel}` : ''}`
646
+ : '';
647
+ return html `
648
+ <a class="er-row" href="${workflowLink(w)}" data-slug="${w.slug}"
649
+ data-site="${w.site}" data-state="${w.state}">
650
+ <span class="er-row-num">→</span>
651
+ <span class="er-row-site er-row-site--${w.site}" title="${host}">${siteLabel(w.site)}</span>
652
+ <span class="er-row-slug">${w.slug}</span>
653
+ <span class="er-row-kind">${w.contentKind}${unsafe(platformBit)}</span>
654
+ <span class="er-stamp er-stamp-approved">approved</span>
655
+ <span class="er-row-ts">v${w.currentVersion}</span>
656
+ <span class="er-row-hint">
657
+ Run · <code>/editorial-approve --site ${w.site} ${w.slug}${flagBit}</code>
658
+ </span>
659
+ </a>`;
660
+ })
661
+ .join('');
662
+ return unsafe(html `
663
+ <section class="er-section">
664
+ <h2 class="er-section-head">
665
+ <span>Awaiting press</span>
666
+ <span class="count">№ ${data.approved.length}</span>
667
+ </h2>
668
+ ${unsafe(rows)}
669
+ </section>`);
670
+ }
671
+ function renderTerminalSection(data, ctx, now) {
672
+ if (data.terminal.length === 0)
673
+ return unsafe('');
674
+ const rows = data.terminal
675
+ .map((w) => {
676
+ const host = ctx.config.sites[w.site]?.host ?? w.site;
677
+ const platformBit = w.contentKind === 'shortform' && w.platform
678
+ ? html `<span class="er-row-channel"> · ${w.platform}</span>`
679
+ : '';
680
+ return html `
681
+ <div class="er-row" data-state="${w.state}" data-site="${w.site}">
682
+ <span class="er-row-num">—</span>
683
+ <span class="er-row-site er-row-site--${w.site}" title="${host}">${siteLabel(w.site)}</span>
684
+ <span class="er-row-slug" style="color: var(--er-ink-soft);">${w.slug}</span>
685
+ <span class="er-row-kind">${w.contentKind}${unsafe(platformBit)}</span>
686
+ <span class="er-stamp er-stamp-${w.state}">${w.state}</span>
687
+ <span class="er-row-ts">${fmtRelTime(w.updatedAt, now)}</span>
688
+ </div>`;
689
+ })
690
+ .join('');
691
+ return unsafe(html `
692
+ <section class="er-section">
693
+ <h2 class="er-section-head">
694
+ <span>Recent proofs</span>
695
+ <span class="count">last ${data.terminal.length}</span>
696
+ </h2>
697
+ ${unsafe(rows)}
698
+ </section>`);
699
+ }
700
+ function renderSidebar(data) {
701
+ const totalTerminal = data.report.all.approvedCount + data.report.all.cancelledCount;
702
+ const hasEnoughSignal = totalTerminal >= 5;
703
+ const topTwo = data.report.topCategories.filter((c) => c.count > 0).slice(0, 2);
704
+ const driftBody = hasEnoughSignal && topTwo.length > 0
705
+ ? unsafe(html `
706
+ <p class="er-drift-primary">
707
+ <em>${topTwo[0].category}</em>
708
+ <span class="count"> ${topTwo[0].count}</span>
709
+ </p>
710
+ ${topTwo[1]
711
+ ? unsafe(html `<p class="er-drift-secondary" style="margin: 0;">
712
+ then <em style="color: var(--er-red-pencil);">${topTwo[1].category}</em> · ${topTwo[1].count}
713
+ </p>`)
714
+ : ''}
715
+ <div style="margin-top: var(--er-space-2); font-family: var(--er-font-mono); font-size: 0.68rem; color: var(--er-faded);">
716
+ from ${data.report.all.approvedCount} approved · ${data.report.all.cancelledCount} cancelled<br />
717
+ <code style="margin-top: 0.25rem; display: inline-block;">/editorial-review-report --site &lt;site&gt;</code>
718
+ </div>`)
719
+ : unsafe(html `
720
+ <p style="font-family: var(--er-font-display); font-style: italic; color: var(--er-ink-soft); margin: 0;">
721
+ ${totalTerminal === 0
722
+ ? 'No proofs yet. The signal builds with use.'
723
+ : `Only ${totalTerminal} terminal ${totalTerminal === 1 ? 'proof' : 'proofs'} so far — need ${5 - totalTerminal} more.`}
724
+ </p>`);
725
+ return unsafe(html `
726
+ <aside>
727
+ <section class="er-drift">
728
+ <div class="er-drift-label">Voice-drift · signal</div>
729
+ ${driftBody}
730
+ </section>
731
+ <section class="er-slip" style="margin-top: var(--er-space-4);">
732
+ <div class="er-slip-header">Short form</div>
733
+ <h3 class="er-slip-title">Social copy</h3>
734
+ <p style="font-size: 0.85rem; margin: 0 0 var(--er-space-1); color: var(--er-ink-soft);">
735
+ Click <em>start</em> in the coverage matrix above to begin a
736
+ shortform draft. Edit, iterate, and approve in the unified
737
+ review surface.
738
+ </p>
739
+ <p style="margin-top: var(--er-space-2);">
740
+ <a href="/dev/editorial-review-shortform">Go to the shortform desk →</a>
741
+ </p>
742
+ </section>
743
+ </aside>`);
744
+ }
745
+ // ---------------------------------------------------------------------------
746
+ // Entry point
747
+ // ---------------------------------------------------------------------------
748
+ export function renderDashboard(ctx, getIndex) {
749
+ const sites = Object.keys(ctx.config.sites);
750
+ const data = loadDashboardData(ctx, getIndex);
751
+ const now = ctx.now ? ctx.now() : new Date();
752
+ const stageSections = STAGES.map((stage) => {
753
+ // Sort by (site, slug) so hierarchical entries cluster under their
754
+ // ancestor — `the-outbound` immediately precedes `the-outbound/characters`
755
+ // and `the-outbound/characters/strivers`. This is purely a display
756
+ // ordering; the underlying calendar storage stays a flat table.
757
+ const stageEntries = data.calendarEntries
758
+ .filter((e) => e.entry.stage === stage)
759
+ .sort((a, b) => {
760
+ const siteCmp = a.site.localeCompare(b.site);
761
+ if (siteCmp !== 0)
762
+ return siteCmp;
763
+ return a.entry.slug.localeCompare(b.entry.slug);
764
+ });
765
+ return renderStageSection(ctx, data, stage, stageEntries, sites, getIndex).__raw;
766
+ }).join('\n');
767
+ const body = html `
768
+ ${renderEditorialFolio('dashboard', 'press-check')}
769
+ ${renderHeader(data, ctx, now)}
770
+ <main class="er-container">
771
+ ${renderFilterStrip(sites)}
772
+ <div class="er-layout">
773
+ <div>
774
+ ${unsafe(stageSections)}
775
+ ${renderShortformMatrix(data, ctx)}
776
+ ${renderApprovedSection(data, ctx)}
777
+ ${renderTerminalSection(data, ctx, now)}
778
+ </div>
779
+ ${renderSidebar(data)}
780
+ </div>
781
+ </main>
782
+ <div class="er-toast" data-toast hidden></div>
783
+ <div class="er-poll-indicator" data-poll>auto-refresh · 10s</div>`;
784
+ return layout({
785
+ title: 'Editorial Studio — dev',
786
+ cssHrefs: [
787
+ '/static/css/editorial-review.css',
788
+ '/static/css/editorial-nav.css',
789
+ '/static/css/editorial-studio.css',
790
+ ],
791
+ bodyAttrs: 'data-review-ui="studio"',
792
+ bodyHtml: body,
793
+ embeddedJson: [
794
+ {
795
+ id: '',
796
+ attr: 'data-rename-slugs',
797
+ data: data.slugsBySite,
798
+ },
799
+ ],
800
+ scriptModules: ['/static/dist/editorial-studio-client.js'],
801
+ });
802
+ }
803
+ //# sourceMappingURL=dashboard.js.map