create-pmos 0.492.0 → 0.494.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 (102) hide show
  1. package/package.json +75 -27
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/mods/pmos-cockpit/README.md +1 -1
  4. package/payload/mods/pmos-cockpit/hooks/lib/guard.mjs +2 -2
  5. package/payload/planning/evals/eval-calibration.md +1 -1
  6. package/payload/planning/okrs/health-budgets.md +1 -1
  7. package/payload/state/discoveries.md +1 -1
  8. package/workspace/briefing-premium-initiative-test.js +2 -1
  9. package/workspace/changelog.json +74 -0
  10. package/workspace/fixtures/initiatives-api/list.json +0 -4
  11. package/workspace/fixtures/initiatives-api/roadmap.json +255 -275
  12. package/workspace/fixtures/initiatives-api/sheet.json +2 -3
  13. package/workspace/fixtures/report-api/draft.json +4 -4
  14. package/workspace/fixtures/reports-page/draft-biweekly-2026-10-16.md +4 -4
  15. package/workspace/guide/board.md +2 -2
  16. package/workspace/guide/briefing-premium.md +2 -0
  17. package/workspace/guide/claude-proposes.md +2 -2
  18. package/workspace/guide/data-freshness.md +3 -1
  19. package/workspace/guide/index.md +2 -2
  20. package/workspace/guide/initiative-boards.md +2 -2
  21. package/workspace/guide/initiatives-roadmap.md +38 -39
  22. package/workspace/guide/initiatives-screen.md +22 -20
  23. package/workspace/guide/initiatives-timeline.md +7 -9
  24. package/workspace/guide/integrated-work.md +7 -8
  25. package/workspace/guide/layout.md +2 -2
  26. package/workspace/guide/lifecycle.md +2 -2
  27. package/workspace/guide/notes.md +1 -1
  28. package/workspace/guide/pm-only-acts.md +5 -5
  29. package/workspace/guide/pm-only-lines.md +3 -3
  30. package/workspace/guide/report-slides.md +14 -1
  31. package/workspace/guide/reports.md +4 -2
  32. package/workspace/guide/today.md +2 -2
  33. package/workspace/guide/your-impact.md +6 -7
  34. package/workspace/lib/board-cli.js +1 -1
  35. package/workspace/lib/board-fold.js +6 -6
  36. package/workspace/lib/board-premium.js +3 -3
  37. package/workspace/lib/board-trail.js +30 -3
  38. package/workspace/lib/calendar-tidy.js +1 -1
  39. package/workspace/lib/core-docs.js +2 -2
  40. package/workspace/lib/engine/boards.js +11 -11
  41. package/workspace/lib/engine/signals/detectors.js +13 -13
  42. package/workspace/lib/engine/signals/facts.js +5 -3
  43. package/workspace/lib/git-shape.js +21 -0
  44. package/workspace/lib/grill-runs.js +21 -6
  45. package/workspace/lib/grill.js +1 -1
  46. package/workspace/lib/health-rules-factory.js +13 -14
  47. package/workspace/lib/health-rules-plan.js +8 -7
  48. package/workspace/lib/impact.js +29 -16
  49. package/workspace/lib/initiative-cli.js +59 -63
  50. package/workspace/lib/initiative-needs.js +6 -6
  51. package/workspace/lib/initiative-premium.js +2 -2
  52. package/workspace/lib/initiative-writer.js +2 -2
  53. package/workspace/lib/lifecycle-stage.js +39 -0
  54. package/workspace/lib/page-warm.js +68 -0
  55. package/workspace/lib/placements.js +117 -95
  56. package/workspace/lib/plan-rules.js +7 -5
  57. package/workspace/lib/pm-guard.js +1 -3
  58. package/workspace/lib/pm-lines-needs.js +1 -1
  59. package/workspace/lib/report-design.js +6 -1
  60. package/workspace/lib/report-draft.js +17 -16
  61. package/workspace/lib/report-export.js +148 -9
  62. package/workspace/lib/report-pyramid.js +434 -0
  63. package/workspace/lib/report-slides-data.js +11 -7
  64. package/workspace/lib/report-structure.js +5 -1
  65. package/workspace/lib/report-templates.js +81 -20
  66. package/workspace/lib/routes-boards.js +9 -8
  67. package/workspace/lib/routes-brief-page.js +20 -3
  68. package/workspace/lib/routes-grill.js +10 -4
  69. package/workspace/lib/routes-impact.js +12 -4
  70. package/workspace/lib/routes-initiatives.js +29 -43
  71. package/workspace/lib/routes-notes.js +24 -15
  72. package/workspace/lib/routes-programs.js +6 -4
  73. package/workspace/lib/routes-report-design.js +15 -0
  74. package/workspace/lib/routes-report-flow.js +106 -17
  75. package/workspace/lib/routes-report-setups.js +2 -1
  76. package/workspace/lib/routes-report-structure.js +3 -0
  77. package/workspace/lib/split-merge.js +2 -3
  78. package/workspace/lib/wf-bridge.js +5 -3
  79. package/workspace/package-lock.json +2 -2
  80. package/workspace/package.json +1 -1
  81. package/workspace/premium-chat-report-tab-test.js +5 -1
  82. package/workspace/public/pm/cozy-vw-rp.css +12 -0
  83. package/workspace/public/pm/fetch-share.js +38 -0
  84. package/workspace/public/pm/home-app.js +21 -3
  85. package/workspace/public/pm/home-chat.js +5 -4
  86. package/workspace/public/pm/home-impact.css +23 -13
  87. package/workspace/public/pm/home-impact.js +49 -32
  88. package/workspace/public/pm/home-ini.css +2 -0
  89. package/workspace/public/pm/http.js +1 -1
  90. package/workspace/public/pm/ini-view.css +55 -0
  91. package/workspace/public/pm/ini-view.js +5 -2
  92. package/workspace/public/pm/premium-board.js +1 -0
  93. package/workspace/public/pm/premium-insights.js +1 -0
  94. package/workspace/public/pm/premium-report-read.js +25 -6
  95. package/workspace/public/pm/premium-report-tab.js +69 -14
  96. package/workspace/public/pm/report-flow.js +93 -10
  97. package/workspace/public/pm/view-notes.js +8 -8
  98. package/workspace/replaced-tests.json +14 -0
  99. package/workspace/server.js +24 -3
  100. package/workspace/skills/report-template.skill +8 -0
  101. package/workspace/test-lists/page-open-speed.json +5 -0
  102. package/workspace/test-lists/report-pyramid.json +9 -0
@@ -32,10 +32,11 @@
32
32
  * WHAT draftOf FOLDS (Run 5, slice 5A). Local files only, no git fetch and no model (X18):
33
33
  * - the window: since the last issue of this cadence before the slot (lib/issues.js), else report_cycle_days back
34
34
  * from `now` (X20). Two calls with the same inputs and `now` give the same draft; another `now`, another window;
35
- * - one block per work-lane initiative active in the window (scripts/lane-defs.js group `work`, D86 point 4): in Now,
36
- * or with an item line, a horizon move, a gate or a lifecycle line in the window. Off track and at risk first, then
37
- * the Roadmap order. Stage from initiative-display.js displayOf; health from `health` (a function of the health
38
- * ctx, or a map by id; tests inject it) else lib/health.js healthOf. An off-track or at-risk block with no reason
35
+ * - one block per work-lane initiative active in the window (scripts/lane-defs.js group `work`, D86 point 4): not
36
+ * dormant and either ranked by a line or under way (past its spec, not accepted; lib/lifecycle-stage.js), or with an
37
+ * item line, a Roadmap move, a gate or a lifecycle line in the window. Off track and at risk first, then the
38
+ * Roadmap rank (D105: was "in Now" and the Now, Next, Later order). Stage from initiative-display.js displayOf;
39
+ * health from `health` (a function of the health ctx, or a map by id; tests inject it) else lib/health.js healthOf. An off-track or at-risk block with no reason
39
40
  * at its level refuses the whole draft (422);
40
41
  * - progress from plan-items (proposed items never count; an item the factory join marks integrated counts done);
41
42
  * a measured value only from a measurements line whose source is `<path>@<sha>` (no KR is computed here);
@@ -54,6 +55,7 @@ const consoleState = require('./console-state');
54
55
  const planItems = require('./plan-items.js');
55
56
  const planTree = require('./plan-tree.js');
56
57
  const placements = require('./placements.js');
58
+ const lifecycle = require('./lifecycle-stage.js');
57
59
  const measurements = require('./measurements.js');
58
60
  const issues = require('./issues.js');
59
61
  const factoryJoin = require('./factory-join.js');
@@ -102,8 +104,6 @@ const SOURCE_RE = /^[^@\s]+@[0-9a-f]{7,40}$/;
102
104
  const DAY = 86400000;
103
105
  const SEVERITY = { off: 3, 'at-risk': 2, unknown: 1, on: 0 };
104
106
  const LEVEL_WORD = { off: 'Off track', 'at-risk': 'At risk', unknown: 'Unknown', on: 'On track' };
105
- const HORIZON_WORD = { now: 'Now', next: 'Next', later: 'Later' };
106
- const HORIZONS = ['now', 'next', 'later'];
107
107
  const LIFECYCLE_WORD = { 'on-hold': 'put on hold', held: 'put on hold', closed: 'closed', cancelled: 'cancelled', active: 'reopened' };
108
108
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
109
109
 
@@ -289,7 +289,6 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
289
289
  const id = row.id;
290
290
  const its = itemsOf(id);
291
291
  const placement = has(plc.byInit, id) ? plc.byInit[id] : null;
292
- const horizon = placements.horizonOf(plc, id);
293
292
  const moves = plc.moves.filter((m) => m.init === id && inWin(m.at));
294
293
  const gates = [
295
294
  ...acc.rows.filter((a) => a.initiative_id === id && a.accepted === true && inWin(a.accepted_at || a.at)).map((a) => ({ gate: 'acceptance', at: String(a.accepted_at || a.at) })),
@@ -300,7 +299,9 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
300
299
  const lifeHere = life.rows.filter((l) => l.initiative_id === id && inWin(l.at));
301
300
  const touched = its.some((it) => it.history.some((h) => inWin(h.at)));
302
301
  if (row.stopped && Number.isFinite(toMs(row.stopped.at)) && toMs(row.stopped.at) <= fromMs) continue;
303
- const active = (placement && horizon === 'now') || touched || moves.length || gates.length || lifeHere.length;
302
+ // D105: was "in Now". Now: not dormant, and either a line ranked it on the Roadmap or its work is under way.
303
+ const committed = !!placement && !placement.dormant && (placement.source === 'ledger' || lifecycle.underway(row));
304
+ const active = committed || touched || moves.length || gates.length || lifeHere.length;
304
305
  if (!active) continue;
305
306
 
306
307
  const narrowed = { items: Object.fromEntries(its.map((it) => [it.id, it])), order: its.map((it) => it.id),
@@ -325,7 +326,7 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
325
326
  const doneNow = real.filter((it) => it.state === 'done' && inWin(it.doneAt));
326
327
  const done = real.filter(isDone).length;
327
328
  const today = dayOf(nowMs);
328
- const horizonEnd = dayOf(nowMs + cycle * DAY);
329
+ const cycleEnd = dayOf(nowMs + cycle * DAY);
329
330
  const open = real.filter((it) => !isDone(it));
330
331
  const carried = open.filter((it) => it.due && it.due < today)
331
332
  .sort((a, b) => byText(a.due, b.due) || byText(a.id, b.id)).map((it) => ({ id: it.id, title: it.title, due: it.due }));
@@ -333,7 +334,7 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
333
334
  const stageIdx = (s) => { const k = stageIds.indexOf(s); return k === -1 ? stageIds.length : k; };
334
335
  const ordered = open.slice().sort((a, b) => (stageIdx(a.stage) - stageIdx(b.stage)) || (a.order - b.order)
335
336
  || byText(String(a.createdAt), String(b.createdAt)) || byText(a.id, b.id));
336
- const dated = ordered.filter((it) => [it.start, it.due].some((d) => d && d >= today && d <= horizonEnd));
337
+ const dated = ordered.filter((it) => [it.start, it.due].some((d) => d && d >= today && d <= cycleEnd));
337
338
  const coming = dated.length ? { basis: 'dates', list: dated } : { basis: 'order', list: ordered.slice(0, 3) };
338
339
  const m = measurement && SOURCE_RE.test(String(measurement.source)) ? measurement : null;
339
340
 
@@ -352,11 +353,11 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
352
353
  },
353
354
  coming_cycle: { basis: coming.basis, items: coming.list.map((it) => ({ id: it.id, title: it.title, start: it.start || null, due: it.due || null })) },
354
355
  note: has(notes, id) ? notes[id] : '',
355
- _order: [SEVERITY[h.level], HORIZONS.indexOf(horizon), placement ? placement.rank : Infinity],
356
+ _order: [SEVERITY[h.level], placement ? placement.rank : Infinity],
356
357
  });
357
358
  }
358
- // Off track and at risk first; then Now, Next, Later in their Roadmap order; then the id.
359
- blocks.sort((a, b) => (b._order[0] - a._order[0]) || (a._order[1] - b._order[1]) || (a._order[2] - b._order[2]) || byText(a.id, b.id));
359
+ // Off track and at risk first; then the Roadmap rank; then the id.
360
+ blocks.sort((a, b) => (b._order[0] - a._order[0]) || (a._order[1] - b._order[1]) || byText(a.id, b.id));
360
361
  for (const b of blocks) delete b._order;
361
362
 
362
363
  // The Timeline strip, frozen at fold time: one row per block with dated items, one span per stage.
@@ -390,7 +391,7 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
390
391
  const decided = [];
391
392
  const plcRel = relMain(ledgers.ledgerPath(abs, 'placements'));
392
393
  for (const mv of plc.moves) {
393
- if (work.has(mv.init) && inWin(mv.at) && isStr(mv.by) && mv.by.startsWith('pm:')) decided.push({ text: `${titleOf.get(mv.init)} moved to ${HORIZON_WORD[mv.to] || mv.to}`, at: mv.at, source: plcRel });
394
+ if (work.has(mv.init) && inWin(mv.at) && isStr(mv.by) && mv.by.startsWith('pm:')) decided.push({ text: `${titleOf.get(mv.init)} ranked #${mv.to} on the Roadmap`, at: mv.at, source: plcRel });
394
395
  }
395
396
  for (const l of life.rows) {
396
397
  if (work.has(l.initiative_id) && inWin(l.at) && has(LIFECYCLE_WORD, l.state)) decided.push({ text: `${titleOf.get(l.initiative_id)} ${LIFECYCLE_WORD[l.state]}`, at: String(l.at), source: relHere(path.join(L.runsDir, 'lifecycle.jsonl')) });
@@ -493,7 +494,7 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
493
494
  const slides = slidesData({
494
495
  product: def.product || path.basename(main), cadence, slot: theSlot, nowMs, window, cycleDays: cycle,
495
496
  blocks, rows, itemsOf,
496
- stageLabel, horizonOf: (id) => placements.horizonOf(plc, id),
497
+ stageLabel, lifecycleOf: (id) => lifecycle.labelOf(rows.find((r) => r.id === id)),
497
498
  rankOf: (id) => (has(plc.byInit, id) && Number.isFinite(plc.byInit[id].rank) ? plc.byInit[id].rank : Infinity),
498
499
  isDone: (it) => it.state === 'done' || integratedAll.has(it.id),
499
500
  });
@@ -552,7 +553,7 @@ function render(draft, { notes, name: given, purpose } = {}) {
552
553
  const lc = b.last_cycle;
553
554
  push(`- Done: ${lc.done.length ? lc.done.map((x) => `${x.title} (${x.id})`).join('; ') : 'none'}`);
554
555
  push(`- Gates passed: ${lc.gates.length ? lc.gates.map((g) => `${g.gate}, ${short(g.at)}`).join('; ') : 'none'}`);
555
- push(`- Horizon moves: ${lc.moves.length ? lc.moves.map((m) => `${HORIZON_WORD[m.from] || 'none'} to ${HORIZON_WORD[m.to] || m.to}, ${short(m.at)}`).join('; ') : 'none'}`);
556
+ push(`- Roadmap moves: ${lc.moves.length ? lc.moves.map((m) => `${m.from == null ? 'added' : '#' + m.from} to #${m.to}, ${short(m.at)}`).join('; ') : 'none'}`);
556
557
  push(`- Overdue, carried over: ${lc.carried.length ? lc.carried.map((x) => `${x.title}, due ${short(x.due)}`).join('; ') : 'none'}`);
557
558
  push('', `**Coming cycle** (${b.coming_cycle.basis === 'dates' ? 'items that start or fall due' : 'the next 3 by order'})`, '');
558
559
  if (!b.coming_cycle.items.length) push('- none');
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
  /* report-export.js — a report document as a file on this machine: .docx, .pptx, .xlsx or .csv (initiative report-workspace, PRD section 6).
3
3
  *
4
- * exportOf(markdown, fmt) → { ok, fmt, name, mime, buffer } | { ok: false, error } fmt: docx | pptx | xlsx | csv
4
+ * exportOf(markdown, fmt, { look }?) → { ok, fmt, name, mime, buffer } | { ok: false, error } fmt: docx | pptx | xlsx | csv
5
5
  * parseReport(markdown) → { title, subtitle, blocks: [{ t: 'h', level, text } | { t: 'p', text } | { t: 'li', text } | { t: 'table', rows }] }
6
6
  * sectionsOf(report) → [{ heading, blocks }] the blocks under each level-2 heading
7
- * docx(report) · pptx(report) · xlsx(report) · csv(report) → Buffer (csv: string)
7
+ * docx(report) · pptx(report, deck?) · xlsx(report) · csv(report) → Buffer (csv: string)
8
8
  * zip(entries) · unzip(buffer) → Buffer · [{ name, data }] a minimal zip writer and reader
9
9
  *
10
10
  * NO DEPENDENCY, NO NETWORK. The Office files are ZIP packages of small XML parts, built here from the report's markdown.
@@ -15,7 +15,8 @@
15
15
  * WHAT THE MARKDOWN BECOMES. The frontmatter gives the title. A level-2 heading starts a section; a level-3 heading is a
16
16
  * sub-heading in it. A pipe table becomes rows. A `- ` line is a bullet, any other line a paragraph. A note marker, the slide data
17
17
  * comment and any other HTML comment are dropped: they are for PMOS, not for the reader.
18
- * .docx headings, paragraphs and bullets .pptx a title slide, then one slide per section (title and bullets)
18
+ * .docx headings, paragraphs and bullets .pptx a title slide, then one slide per section (title and bullets); a cadence draft
19
+ * (lib/report-draft.js) is the Pyramid deck instead (lib/report-pyramid.js, canvas RsA): the same slides as the slide view and the PDF
19
20
  * .xlsx one sheet: a table is its rows; otherwise one row for each line, with its section beside it .csv the same rows
20
21
  */
21
22
  const zlib = require('zlib');
@@ -209,7 +210,139 @@ function slideLines(blocks) {
209
210
  return out;
210
211
  }
211
212
 
212
- function pptx(report) {
213
+ // ── the Pyramid deck as shapes (lib/report-pyramid.js; canvas RsA): the same slides as the in-app view and the PDF ──────────────────────
214
+ const PX = 9525; // one 1280 x 720 px slide → 12192000 x 6858000 EMU
215
+ const hex = (c) => String(c || '#000000').replace('#', '').toUpperCase().replace(/^([0-9A-F])([0-9A-F])([0-9A-F])$/, '$1$1$2$2$3$3');
216
+ /** One slide of the Pyramid deck as <p:sld> XML: rectangles, shapes and text boxes placed on a 1280 x 720 grid. */
217
+ function pyramidSlideXml(s, L) {
218
+ let id = 1;
219
+ const out = [];
220
+ const E = (v) => Math.round(v * PX);
221
+ const fill = (c) => (c ? `<a:solidFill><a:srgbClr val="${hex(c)}"/></a:solidFill>` : '<a:noFill/>');
222
+ const ln = (c, w, dash) => (c ? `<a:ln w="${Math.round((w || 1) * PX)}">${fill(c)}${dash ? '<a:prstDash val="dash"/>' : ''}</a:ln>` : '<a:ln><a:noFill/></a:ln>');
223
+ const shape = (x, y, w, h, o = {}) => { id++; out.push(`<p:sp><p:nvSpPr><p:cNvPr id="${id}" name="${o.name || 'Shape ' + id}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr><p:spPr><a:xfrm${o.flip ? ' flipV="1"' : ''}><a:off x="${E(x)}" y="${E(y)}"/><a:ext cx="${E(Math.max(w, 0.5))}" cy="${E(Math.max(h, 0.5))}"/></a:xfrm><a:prstGeom prst="${o.geom || 'rect'}"><a:avLst/></a:prstGeom>${fill(o.fill)}${ln(o.line, o.lw, o.dash)}</p:spPr></p:sp>`); };
224
+ const run = (t, o) => `<a:r><a:rPr lang="en-GB" sz="${Math.round((o.size || 18) * 75)}"${o.bold ? ' b="1"' : ''} dirty="0">${fill(o.color || L.ink)}<a:latin typeface="${xml(L.font)}"/></a:rPr><a:t>${xml(t)}</a:t></a:r>`;
225
+ /** a text box; paras = [string | [[text, opts], …]] */
226
+ const text = (x, y, w, h, paras, o = {}) => {
227
+ id++;
228
+ const ps = (Array.isArray(paras) ? paras : [paras]).map((p) => `<a:p><a:pPr algn="${o.align || 'l'}"/>${(Array.isArray(p) ? p : [[p, {}]]).map(([t, ro]) => run(t, { ...o, ...ro })).join('')}</a:p>`).join('');
229
+ out.push(`<p:sp><p:nvSpPr><p:cNvPr id="${id}" name="${o.name || 'Text ' + id}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr><p:spPr><a:xfrm><a:off x="${E(x)}" y="${E(y)}"/><a:ext cx="${E(w)}" cy="${E(h)}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/></p:spPr><p:txBody><a:bodyPr wrap="square" lIns="0" tIns="0" rIns="0" bIns="0" anchor="${o.anchor || 't'}"><a:normAutofit/></a:bodyPr><a:lstStyle/>${ps}</p:txBody></p:sp>`);
230
+ };
231
+ const navy = s.kind === 'title';
232
+ if (navy) shape(0, 0, 1280, 720, { fill: L.accent, name: 'Background' });
233
+ // the footer: the source of every number on the slide, and the page number
234
+ shape(0, 672, 1280, 1, { fill: navy ? '#4A5571' : L.line, name: 'Footer rule' });
235
+ text(67, 686, 1050, 22, s.source || '', { size: 15, color: navy ? '#C9D3EA' : '#8A8478', name: 'Source' });
236
+ text(1150, 686, 63, 22, String(s.n), { size: 15, color: navy ? '#C9D3EA' : '#8A8478', align: 'r', name: 'Page number' });
237
+ if (navy) {
238
+ text(67, 270, 1000, 22, s.tag.toUpperCase(), { size: 15, bold: true, color: '#C9D3EA' });
239
+ text(67, 300, 1000, 230, s.title, { size: 64, bold: true, color: '#FFFFFF', anchor: 'b', name: 'Title' });
240
+ text(67, 545, 1000, 70, s.sub, { size: 22, color: '#DDE4F3' });
241
+ return out;
242
+ }
243
+ let y = 48;
244
+ if (s.tag) { text(67, y, 900, 22, s.tag.toUpperCase(), { size: 15, bold: true, color: L.muted }); y += 34; }
245
+ text(67, y, 1120, 92, s.title, { size: 35, bold: true, name: 'Title' });
246
+ y += 100;
247
+ shape(67, y, 90, 3, { fill: L.accent, name: 'Rule' });
248
+ y += 30;
249
+ if (s.kind === 'answer') {
250
+ const right = s.ask && s.ask.question;
251
+ s.supports.forEach((x, i) => {
252
+ const yy = y + i * 92;
253
+ if (i) shape(67, yy - 10, right ? 640 : 1146, 1, { fill: L.line });
254
+ shape(67, yy, 35, 35, { geom: 'ellipse', fill: L.accent });
255
+ text(67, yy + 6, 35, 24, String(i + 1), { size: 18, bold: true, color: '#FFFFFF', align: 'ctr' });
256
+ text(121, yy, right ? 586 : 1092, 30, x.head, { size: 22, bold: true });
257
+ text(121, yy + 32, right ? 586 : 1092, 44, x.text, { size: 18, color: L.soft });
258
+ });
259
+ if (right) {
260
+ shape(750, y, 463, 210, { geom: 'roundRect', fill: L.ask, line: L.accent, lw: 3 });
261
+ text(776, y + 22, 411, 20, 'YOUR CALL', { size: 15, bold: true, color: L.accent });
262
+ text(776, y + 50, 411, 110, s.ask.question, { size: 22, bold: true });
263
+ text(776, y + 170, 411, 24, `For ${s.ask.who}${s.ask.by ? ' · by ' + s.ask.by : ''}`, { size: 18, color: L.soft });
264
+ }
265
+ } else if (s.kind === 'scorecard') {
266
+ const cols = s.kr ? [220, 120, 80, 230, 270, 226] : [260, 140, 90, 260, 396];
267
+ const xs = cols.reduce((a, w) => a.concat(a[a.length - 1] + w), [67]);
268
+ const hd = ['INITIATIVE', 'STAGE', 'STATUS', 'DONE OF TOTAL'].concat(s.kr ? [`${s.kr.toUpperCase()} · NOW VS TARGET`] : [], ['WHY, WHAT WE DO']);
269
+ hd.forEach((h, i) => text(xs[i] + 8, y, cols[i] - 12, 20, h, { size: 15, bold: true, color: L.muted }));
270
+ shape(67, y + 28, 1146, 3, { fill: '#D3CCBF' });
271
+ const rowH = 62;
272
+ s.rows.forEach((r, k) => {
273
+ const ry = y + 40 + k * rowH; const mid = ry + rowH / 2 - 12;
274
+ text(xs[0] + 8, mid, cols[0] - 12, 24, r.title, { size: 17, bold: true });
275
+ text(xs[1] + 8, mid, cols[1] - 12, 24, r.stage, { size: 17 });
276
+ const g = { on: ['ellipse', L.on], 'at-risk': ['triangle', L.risk], off: ['rect', L.off] }[r.level];
277
+ shape(xs[2] + 10, mid + 4, 16, 16, g ? { geom: g[0], fill: g[1], name: `Status: ${r.level}` } : { geom: 'ellipse', line: L.unknown, lw: 2, name: 'Status: unknown' });
278
+ if (r.progress.total) {
279
+ shape(xs[3] + 8, mid + 6, 120, 12, { geom: 'roundRect', fill: L.track });
280
+ shape(xs[3] + 8, mid + 6, Math.max(1, (120 * r.progress.done) / r.progress.total), 12, { geom: 'roundRect', fill: L.accent });
281
+ text(xs[3] + 136, mid, 90, 24, [[[`${r.progress.done} of ${r.progress.total}`, { bold: true }], ...(r.progress.delta ? [[` +${r.progress.delta}`, { color: L.on }]] : [])]], { size: 16 });
282
+ } else text(xs[3] + 8, mid, cols[3] - 12, 24, r.progress.label || 'no breakdown', { size: 16, color: L.soft });
283
+ let c = 4;
284
+ if (s.kr) {
285
+ const m = r.measure;
286
+ if (m && m.target != null) {
287
+ const max = m.unit === '%' && Math.max(m.value, m.target) <= 100 ? 100 : Math.max(m.value, m.target, 1) * 1.25;
288
+ const w = 200; const at = (v) => (w * Math.max(0, v)) / max;
289
+ shape(xs[4] + 8, mid - 2, w, 8, { geom: 'roundRect', fill: L.track });
290
+ shape(xs[4] + 8, mid - 4, Math.max(1, at(m.value)), 12, { fill: L.accent });
291
+ shape(xs[4] + 8 + Math.min(at(m.target), w - 3), mid - 9, 3, 22, { line: L.ink, lw: 2 });
292
+ text(xs[4] + 8, mid + 16, cols[4] - 12, 20, [[[`${m.value}${m.unit}`, { bold: true }], [` of ${m.target}${m.unit}`, {}], ...(r.gap ? [[` · ${r.gap}`, { bold: true, color: m.value < m.target ? L.off : L.on }]] : [])]], { size: 14 });
293
+ } else if (m) text(xs[4] + 8, mid, cols[4] - 12, 24, `${m.value}${m.unit}`, { size: 16, bold: true });
294
+ c = 5;
295
+ }
296
+ if (r.comment) text(xs[c] + 8, ry + 6, cols[c] - 12, rowH - 10, r.comment, { size: 15, color: L.soft, anchor: 'ctr' });
297
+ shape(67, ry + rowH, 1146, 1, { fill: L.line });
298
+ });
299
+ } else if (s.kind === 'timeline') {
300
+ const P = require('./report-pyramid.js');
301
+ const DAY = 86400000; const ms = (d) => Date.parse(d + 'T00:00:00Z');
302
+ const from = ms(s.from); const to = Math.max(ms(s.to), from + DAY); const left = 67 + 240; const right = 67 + 1036;
303
+ const X = (d) => left + ((ms(d) - from) / (to - from)) * (right - left);
304
+ const top = y + 30; const rowH = 70; const bottom = top + s.rows.length * rowH;
305
+ const step = Math.max(1, Math.ceil((to - from) / DAY / 6));
306
+ for (let t = from; t <= to; t += step * DAY) { const d = new Date(t).toISOString().slice(0, 10); shape(X(d), top - 6, 1, bottom - top, { fill: L.line }); text(X(d) - 40, y, 80, 20, P.short(d), { size: 15, color: '#8A8478', align: 'ctr' }); }
307
+ s.rows.forEach((r, i) => {
308
+ const ry = top + i * rowH;
309
+ text(67, ry + 8, 230, 26, r.title, { size: 18, bold: true });
310
+ for (const h of r.holds) shape(X(h.from), ry + 6, Math.max(4, X(h.to || s.to) - X(h.from)), 32, { geom: 'roundRect', fill: L.track, name: 'On hold' });
311
+ for (const sp of r.spans) {
312
+ const w = Math.max(6, X(sp.due) - X(sp.start));
313
+ shape(X(sp.start), ry + 6, w, 32, { geom: 'roundRect', fill: L.accent, name: `Span ${sp.stage}` });
314
+ if (sp.stage && w > 60) text(X(sp.start) + 11, ry + 13, w - 16, 22, sp.stage, { size: 16, bold: true, color: '#FFFFFF' });
315
+ }
316
+ const due = r.spans.reduce((a, sp) => (sp.due > a ? sp.due : a), '');
317
+ const m = r.milestone && /^\d{4}-\d{2}-\d{2}$/.test(String(r.milestone.due)) ? r.milestone.due : due;
318
+ if (m) { shape(X(m) + 3, ry + 12, 20, 20, { geom: 'diamond', line: L.ink, lw: 2.6, name: 'Due date' }); text(X(m) + 30, ry + 13, 90, 22, P.short(m), { size: 16, bold: true, color: L.muted }); }
319
+ r.overdue.slice(0, 1).forEach((o) => { shape(X(o.due) - 7, ry + 46, 14, 14, { geom: 'roundRect', fill: L.off, name: 'Overdue' }); text(X(o.due) + 14, ry + 43, 520, 22, `${o.title}, due ${P.short(o.due)}, overdue`, { size: 16, bold: true, color: L.off }); });
320
+ });
321
+ if (s.today) { shape(X(s.today), top - 10, 1, bottom - top + 10, { line: L.today, lw: 2.4, dash: true, name: 'Today' }); text(X(s.today) - 40, bottom + 4, 80, 20, 'Today', { size: 15, bold: true, color: L.today, align: 'ctr' }); }
322
+ } else if (s.kind === 'ask') {
323
+ const a = s.ask; const n = a.options.length;
324
+ const w = n ? (1146 - 26 * (n - 1)) / n : 0;
325
+ a.options.forEach((o, i) => {
326
+ const x = 67 + i * (w + 26);
327
+ shape(x, y, w, 120, { geom: 'roundRect', fill: i ? '#FFFFFF' : L.ask, line: i ? '#CFC8BA' : L.accent, lw: 3 });
328
+ text(x + 26, y + 22, w - 52, 20, `OPTION ${'ABC'[i]}`, { size: 15, bold: true, color: L.muted });
329
+ text(x + 26, y + 50, w - 52, 60, o, { size: 22, bold: true });
330
+ });
331
+ let yy = y + (n ? 146 : 0);
332
+ if (a.more) { text(67, yy, 1146, 60, a.more, { size: 18, color: L.soft }); yy += 70; }
333
+ text(67, yy, 1146, 26, [[['Who ', { bold: true }], [a.who, {}], ...(a.by ? [[' By ', { bold: true }], [a.by, {}]] : [])]], { size: 18, color: L.soft });
334
+ } else if (s.kind === 'sources') {
335
+ text(67, y, 540, 20, 'REACHED', { size: 15, bold: true, color: L.muted });
336
+ (s.reached.length ? s.reached : ['None']).slice(0, 8).forEach((x, i) => text(67, y + 34 + i * 44, 540, 40, x, { size: 18, color: L.soft }));
337
+ if (s.notReached.length) {
338
+ text(655, y, 540, 20, 'WHAT WE DON’T KNOW YET', { size: 15, bold: true, color: L.off });
339
+ s.notReached.slice(0, 6).forEach((x, i) => text(655, y + 34 + i * 70, 558, 64, [[[x.source, { bold: true, size: 21 }]], [[x.why ? x.why[0].toUpperCase() + x.why.slice(1) + '.' : '', { color: L.soft }]]], { size: 18 }));
340
+ }
341
+ }
342
+ return out;
343
+ }
344
+
345
+ function pptx(report, deck) {
213
346
  const slides = []; // { title, lines, kind }
214
347
  slides.push({ kind: 'title', title: report.title, lines: report.subtitle ? [report.subtitle] : [] });
215
348
  for (const s of sectionsOf(report)) {
@@ -226,6 +359,10 @@ function pptx(report) {
226
359
  const body = s.lines.length ? sp(3, 'Content', s.kind === 'title' ? 'subTitle' : 'body', s.kind === 'title' ? 914400 : 609600, s.kind === 'title' ? 3810000 : 1371600, s.kind === 'title' ? 10363200 : 10972800, s.kind === 'title' ? 914400 : 4846320, bodyParas) : '';
227
360
  return `${DECL}<p:sld xmlns:a="${NS_A}" xmlns:r="${NS_R}" xmlns:p="${NS_P}"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>${title}${body}</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>`;
228
361
  };
362
+ const look = deck ? deck.look : null;
363
+ const font = look ? xml(look.font) : 'Calibri';
364
+ if (deck) { slides.length = 0; for (const p of deck.slides) slides.push({ kind: p.kind, xml: pyramidSlideXml(p, look) }); }
365
+ const shapesSlide = (parts) => `${DECL}<p:sld xmlns:a="${NS_A}" xmlns:r="${NS_R}" xmlns:p="${NS_P}"><p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>${parts.join('')}</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>`;
229
366
  const layoutXml = `${DECL}<p:sldLayout xmlns:a="${NS_A}" xmlns:r="${NS_R}" xmlns:p="${NS_P}" type="obj" preserve="1"><p:cSld name="Title and Content"><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>`
230
367
  + sp(2, 'Title 1', 'title', 609600, 365760, 10972800, 914400, '<a:p><a:endParaRPr lang="en-GB"/></a:p>')
231
368
  + sp(3, 'Content Placeholder 2', 'body', 609600, 1371600, 10972800, 4846320, '<a:p><a:endParaRPr lang="en-GB"/></a:p>')
@@ -237,7 +374,8 @@ function pptx(report) {
237
374
  + '<p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst><p:txStyles><p:titleStyle><a:lvl1pPr algn="l"><a:defRPr sz="3200" b="1"><a:solidFill><a:schemeClr val="tx1"/></a:solidFill><a:latin typeface="+mj-lt"/></a:defRPr></a:lvl1pPr></p:titleStyle>'
238
375
  + '<p:bodyStyle><a:lvl1pPr marL="285750" indent="-285750"><a:defRPr sz="1800"><a:solidFill><a:schemeClr val="tx1"/></a:solidFill><a:latin typeface="+mn-lt"/></a:defRPr></a:lvl1pPr></p:bodyStyle><p:otherStyle><a:defPPr><a:defRPr lang="en-GB"/></a:defPPr></p:otherStyle></p:txStyles></p:sldMaster>';
239
376
  const themeXml = `${DECL}<a:theme xmlns:a="${NS_A}" name="PMOS"><a:themeElements><a:clrScheme name="PMOS"><a:dk1><a:srgbClr val="1F2328"/></a:dk1><a:lt1><a:srgbClr val="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="2F5FD0"/></a:accent1><a:accent2><a:srgbClr val="7A8CA5"/></a:accent2><a:accent3><a:srgbClr val="2E8B57"/></a:accent3><a:accent4><a:srgbClr val="C58A00"/></a:accent4><a:accent5><a:srgbClr val="B3412F"/></a:accent5><a:accent6><a:srgbClr val="6B5BB0"/></a:accent6><a:hlink><a:srgbClr val="2F5FD0"/></a:hlink><a:folHlink><a:srgbClr val="6B5BB0"/></a:folHlink></a:clrScheme>`
240
- + '<a:fontScheme name="PMOS"><a:majorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme>'
377
+ + `<a:fontScheme name="PMOS"><a:majorFont><a:latin typeface="${font}"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="${font}"/>`
378
+ + '<a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme>'
241
379
  + '<a:fmtScheme name="PMOS"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:fillStyleLst>'
242
380
  + '<a:lnStyleLst><a:ln w="9525"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="19050"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="28575"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln></a:lnStyleLst>'
243
381
  + '<a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst>'
@@ -250,7 +388,7 @@ function pptx(report) {
250
388
  { name: '[Content_Types].xml', data: `${DECL}<Types xmlns="${NS_CT}"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/><Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/><Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/><Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>`
251
389
  + slides.map((s, i) => `<Override PartName="/ppt/slides/slide${i + 1}.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>`).join('') + '</Types>' },
252
390
  { name: '_rels/.rels', data: `${DECL}<Relationships xmlns="${NS_PKG_REL}">${rel('rId1', 'officeDocument', 'ppt/presentation.xml')}<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/></Relationships>` },
253
- { name: 'docProps/core.xml', data: coreProps(report.title) },
391
+ { name: 'docProps/core.xml', data: coreProps(deck ? deck.name : report.title) },
254
392
  { name: 'ppt/presentation.xml', data: presXml },
255
393
  { name: 'ppt/_rels/presentation.xml.rels', data: `${DECL}<Relationships xmlns="${NS_PKG_REL}">${rel('rId1', 'slideMaster', 'slideMasters/slideMaster1.xml')}${slides.map((s, i) => rel('rId' + (i + 2), 'slide', `slides/slide${i + 1}.xml`)).join('')}${rel('rId' + (n + 2), 'theme', 'theme/theme1.xml')}</Relationships>` },
256
394
  { name: 'ppt/slideMasters/slideMaster1.xml', data: masterXml },
@@ -260,7 +398,7 @@ function pptx(report) {
260
398
  { name: 'ppt/theme/theme1.xml', data: themeXml },
261
399
  ];
262
400
  slides.forEach((s, i) => {
263
- entries.push({ name: `ppt/slides/slide${i + 1}.xml`, data: slideXml(s) });
401
+ entries.push({ name: `ppt/slides/slide${i + 1}.xml`, data: s.xml ? shapesSlide(s.xml) : slideXml(s) });
264
402
  entries.push({ name: `ppt/slides/_rels/slide${i + 1}.xml.rels`, data: `${DECL}<Relationships xmlns="${NS_PKG_REL}">${rel('rId1', 'slideLayout', '../slideLayouts/slideLayout1.xml')}</Relationships>` });
265
403
  });
266
404
  return zip(entries);
@@ -335,11 +473,12 @@ const FORMATS = Object.freeze({
335
473
  });
336
474
  const BUILD = { docx, pptx, xlsx, csv: (r) => Buffer.from(csv(r), 'utf8') };
337
475
 
338
- function exportOf(markdown, fmt) {
476
+ /** opts.look: the look lib/report-pyramid.js lookOf read (the route passes it); a cadence draft's .pptx is the Pyramid deck in that look. */
477
+ function exportOf(markdown, fmt, opts = {}) {
339
478
  if (!Object.prototype.hasOwnProperty.call(FORMATS, fmt)) return { ok: false, error: `fmt must be one of ${Object.keys(FORMATS).join(', ')}` };
340
479
  const report = parseReport(markdown);
341
480
  let buffer;
342
- try { buffer = BUILD[fmt](report); } catch (e) { return { ok: false, error: 'the file could not be built: ' + String((e && e.message) || e).slice(0, 160) }; }
481
+ try { buffer = fmt === 'pptx' ? pptx(report, require('./report-pyramid.js').deckOf(markdown, opts.look)) : BUILD[fmt](report); } catch (e) { return { ok: false, error: 'the file could not be built: ' + String((e && e.message) || e).slice(0, 160) }; }
343
482
  const stem = plain(report.title).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60) || 'report';
344
483
  return { ok: true, fmt, name: `${stem}.${fmt}`, mime: FORMATS[fmt].mime, buffer };
345
484
  }