create-pmos 0.646.0 → 0.648.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 (30) hide show
  1. package/package.json +27 -27
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/design-system/ui/components/Suggestion/README.md +8 -0
  4. package/payload/design-system/ui/components/Timeline/README.md +8 -0
  5. package/payload/design-system/ui/components/bundle.css +38 -0
  6. package/payload/planning/evals/eval-calibration.md +1 -1
  7. package/payload/planning/okrs/health-budgets.md +1 -1
  8. package/payload/state/discoveries.md +1 -1
  9. package/workspace/changelog.json +26 -0
  10. package/workspace/design-system/ui/components/Suggestion/README.md +8 -0
  11. package/workspace/design-system/ui/components/Timeline/README.md +8 -0
  12. package/workspace/design-system/ui/components/bundle.css +38 -0
  13. package/workspace/guide/layout.md +15 -0
  14. package/workspace/lib/routes-backlog.js +6 -2
  15. package/workspace/lib/sprint-now.js +79 -0
  16. package/workspace/package-lock.json +2 -2
  17. package/workspace/package.json +1 -1
  18. package/workspace/public/pm/bd-backlog.js +36 -14
  19. package/workspace/public/pm/bd-ds.css +0 -7
  20. package/workspace/public/pm/bd-span.js +10 -5
  21. package/workspace/public/pm/bd-sprint-ds.js +115 -0
  22. package/workspace/public/pm/bd-sprint.js +71 -56
  23. package/workspace/public/pm/bd-stands.js +165 -0
  24. package/workspace/public/pm/bd-work-ds.css +144 -0
  25. package/workspace/public/pm/bd-work.css +8 -77
  26. package/workspace/public/pm/bd-work.js +79 -46
  27. package/workspace/public/pm/komorebi.css +39 -0
  28. package/workspace/public/pm/premium-board.js +57 -10
  29. package/workspace/public/pm/readonly.js +3 -0
  30. package/workspace/public/premium-board.html +4 -1
@@ -221,7 +221,7 @@ const slipWords = (r, e) => { const p = r.plan, b = p && day(p.end), n = p && p.
221
221
  * (pm/cozy-pop-work.js), so the bar has one design everywhere (Wawan, 2026-11-19). X: a date → its percent of the box; the markup sits in a
222
222
  * position:relative box of the row's height. o: { pxPct: px per 1 % of the box, reach: days in which ◇s merge, mode: 'all' | 'pinned',
223
223
  * label: false drops the end label, phone } → html */
224
- export const rowBar = (r, X, now, o = {}) => qBar(r, X, now, !!o.phone, md, o.pxPct || 0, { reach: o.reach || 7, mode: o.mode || 'all', noLabel: o.label === false });
224
+ export const rowBar = (r, X, now, o = {}) => qBar(r, X, now, !!o.phone, md, o.pxPct || 0, { reach: o.reach || 7, mode: o.mode || 'all', noLabel: o.label === false, endIn: !!o.endIn });
225
225
  function qBar(r, X, now, phone, fmt, pxPct, ms = {}) {
226
226
  const s = day(r.start), e = day(r.end), fr = fcRange(r), fc = r.forecast ? null : r.track && day(r.track.forecast), tone = toneOf(r);
227
227
  const tm = taskMarks(r, X, now, phone, pxPct, ms), et = tm.end, note = markWords(r, now);
@@ -249,7 +249,7 @@ function qBar(r, X, now, phone, fmt, pxPct, ms = {}) {
249
249
  const name = landsOf(r, et), eTitle = name + ' · ' + md(ed) + (et && et.stage ? ' · ◆ ' + et.stage : '') + (et && et.done ? ' · done' : isLate ? ' · late' : '');
250
250
  // nothing lands (batch 25 item 13): a workflow with no ◆ stage and no dated milestone draws no ◇ and no label; the bar's own end says it
251
251
  if (!name) return out + planMarks(r, X, phone, fmt);
252
- out += `<button type="button" class="tg-end${et && et.done ? ' dn' : ''}${isLate ? ' late' : ''}" data-ms-pick="${esc(r.key)}" data-ms-id="${esc(et ? et.id : '')}" style="left:${P(X(ed))}" aria-haspopup="dialog" aria-label="${esc(eTitle + '. Milestones of ' + r.title)}" title="${esc(eTitle + (clash ? '. ' + clash : ''))}"></button>`;
252
+ if (!tm.endMerged) out += `<button type="button" class="tg-end${et && et.done ? ' dn' : ''}${isLate ? ' late' : ''}" data-ms-pick="${esc(r.key)}" data-ms-id="${esc(et ? et.id : '')}" style="left:${P(X(ed))}" aria-haspopup="dialog" aria-label="${esc(eTitle + '. Milestones of ' + r.title)}" title="${esc(eTitle + (clash ? '. ' + clash : ''))}"></button>`;
253
253
  // with the Next milestone column on, the column names it and the bar's end has no label (StsA8Board); the ◇ keeps the words as its hover
254
254
  if (!ms.noLabel) out += endLabel(Math.max(X(e), X(ed), over ? X(now) : 0, late ? X(fc) : 0, fr ? X(fr.high) : 0), name, ed, isLate ? 'late' : risk, now, pxPct, hover, slipHtml(r));
255
255
  } else if (fc) {
@@ -398,9 +398,14 @@ function taskMarks(r, X, now, phone, pxPct, ms) {
398
398
  const M = (r.milestones || []).filter((m) => day(m.date));
399
399
  if (!M.length) return { html: '', end: null };
400
400
  const end = endTask(r, M, ms.reach || 0), show = new Set(shownMs(r, ms.mode || 'pinned').map((m) => m.id));
401
- const L = M.filter((m) => (!end || m.id !== end.id) && show.has(m.id)).map((m) => ({ ...m, late: msLate(m, now, r), stage: msStage(r, m) }))
401
+ // Work (WorkDS, ms.endIn): the end ◇ merges with milestones less than `reach` days from it, into one numbered mark
402
+ const withEnd = !!(ms.endIn && end);
403
+ const L = M.filter((m) => (withEnd && end && m.id === end.id) || ((!end || m.id !== end.id) && show.has(m.id))).map((m) => ({ ...m, late: msLate(m, now, r), stage: msStage(r, m) }))
402
404
  .filter((m) => { const x = X(day(m.date)); return x > 0 && x < 100; });
403
- const C = mergeClose(L, Math.max(1, ms.reach || 7));
405
+ const C0 = mergeClose(L, Math.max(1, ms.reach || 7));
406
+ const hasEnd = (c) => withEnd && c.items.some((m) => m.id === end.id);
407
+ // the end alone stays the end ◇ qBar draws; merged with others it is drawn here, once, as part of the count
408
+ const C = C0.filter((c) => !(hasEnd(c) && c.n < 2)), endMerged = C.some(hasEnd);
404
409
  const html = C.map((c) => {
405
410
  const x = P(X(day(c.date))), tone = c.late ? ' late' : c.done ? ' dn' : '';
406
411
  const one = c.items[0], words = (m) => m.name + ' · ' + md(day(m.date)) + (m.stage ? ' · ◆ ' + m.stage : '') + (m.late ? ' · late' : m.done ? ' · done' : '');
@@ -408,7 +413,7 @@ function taskMarks(r, X, now, phone, pxPct, ms) {
408
413
  ? `<button type="button" class="tg-tmc${tone}" data-ms-row="${esc(r.key)}" data-ms-ids="${esc(c.items.map((m) => m.id).join(' '))}" style="left:${x}" aria-haspopup="menu" aria-label="${esc(c.n + ' milestones, ' + c.range + ': ' + c.items.map((m) => m.name).join(', '))}" title="${esc(c.items.map(words).join('\n'))}"><b aria-hidden="true">${c.n}</b></button>`
409
414
  : `<button type="button" class="tg-tm${tone}" data-ms-pick="${esc(r.key)}" data-ms-id="${esc(one.id)}" style="left:${x}" aria-haspopup="dialog" aria-label="${esc('Milestone ' + words(one) + '. Milestones of ' + r.title)}" title="${esc(words(one))}"></button>`;
410
415
  }).join('');
411
- return { html, end };
416
+ return { html, end, endMerged };
412
417
  }
413
418
 
414
419
  /* ── the product lane (feedback batch 11 item 17; canvas PlmA1Board, PlmA2Folded, PlmA3Phone) ──
@@ -0,0 +1,115 @@
1
+ /* pm/bd-sprint-ds.js — This sprint built from the design system's parts (initiative work-ds-sprint; Exploring 3 page "work", board
2
+ * WorkSprintDS). Pure: HTML from data, no state and no fetch. pm/bd-sprint.js keeps the state (the tab, the group, the goal being edited)
3
+ * and the presses.
4
+ *
5
+ * · cardHtml(N, o): the one Summary card. The sprint, its end and what it holds ("21 Jira tickets and 7 tasks outside Jira"), "11 of 28
6
+ * done" with a bar, then four columns: Sprint goal (o.goal, editable), In progress, To do and Done, each with its count and top tasks;
7
+ * then one Suggestion (o.sug). No other metric: Wawan was not confident in them.
8
+ * · tasksHtml(N, o): the Tasks Table. Tabs All / To do / In progress / Done (no Late tab), the Group menu (Initiative by default, Who,
9
+ * State, Theme, none), columns Task, Who, State, Source (the Jira key, or "Not in Jira") and Due. Late = the due date has passed and the
10
+ * task is not done: a red badge after the date. "Moved twice" is a plain badge.
11
+ * N is one sprint of GET /api/backlog's sprintNow (lib/sprint-now.js): all work in the sprint's dates, Jira and not. */
12
+ import { sugHtml } from './bd-stands.js';
13
+
14
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
15
+ const SV = (d, n = 16) => `<svg class="pm-ic" width="${n}" height="${n}" viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
16
+ const I = { star: 'M12 3l1.8 5.4L19 10.2l-5.2 1.8L12 17.4l-1.8-5.4L5 10.2l5.2-1.8z', pen: 'M4 20h4L19 9l-4-4L4 16z', read: 'M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7',
17
+ down: 'M7 10l5 5 5-5', ok: 'M5 12.5l4.5 4.5L19 7.5', x: 'M6 6l12 12M18 6L6 18' };
18
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
19
+ export const dayText = (d) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(d || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
20
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
21
+
22
+ export const TABS = [['all', 'All'], ['todo', 'To do'], ['doing', 'In progress'], ['done', 'Done']];
23
+ export const GROUPS = [['ini', 'Initiative'], ['who', 'Who'], ['state', 'State'], ['theme', 'Theme'], ['none', 'None']];
24
+ const tabOfRow = (r) => (r.state === 'Done' ? 'done' : r.state === 'To do' ? 'todo' : 'doing');
25
+ /** The rows of one tab. */
26
+ export const rowsOf = (N, tab) => (N ? N.rows : []).filter((r) => tab === 'all' || !tab || tabOfRow(r) === tab);
27
+ export const countsOf = (N) => { const c = { all: 0, todo: 0, doing: 0, done: 0 }; for (const r of N ? N.rows : []) { c.all++; c[tabOfRow(r)]++; } return c; };
28
+ /** "moved twice" and on: the ticket was in two sprints before this one. */
29
+ export const movedText = (n) => (n >= 3 ? `moved ${n} times` : n === 2 ? 'moved twice' : '');
30
+ const lateText = (n) => plural(n, 'day late', 'days late');
31
+ /** What the sprint holds, in words: "21 Jira tickets and 7 tasks outside Jira". Zero is silence. */
32
+ export function holdsText(N) {
33
+ const a = N.jira ? plural(N.jira, 'Jira ticket', 'Jira tickets') : '', b = N.other ? plural(N.other, 'task outside Jira', 'tasks outside Jira') : '';
34
+ return [a, b].filter(Boolean).join(' and ');
35
+ }
36
+ /** Due first (no date last), then the title. */
37
+ const byDue = (a, b) => (a.due || '9999').localeCompare(b.due || '9999') || a.title.localeCompare(b.title);
38
+
39
+ /** The Summary card. o: { label (the sprint's name or its picker), goal: { lines: [text], mine, editing, edit (the textarea's html),
40
+ * newer (html) }, read: { old, title }, sug: the Suggestion's html } */
41
+ export function cardHtml(N, o = {}) {
42
+ const c = countsOf(N), pct = c.all ? Math.round((c.done / c.all) * 1000) / 10 : 0;
43
+ const meta = [o.label || esc(N.label || N.name), N.end ? 'ends ' + dayText(N.end) : '', esc(holdsText(N))].filter(Boolean).join(' · ');
44
+ const read = o.read ? `<button type="button" class="pm-btn wk-rd${o.read.old ? ' old' : ''}" data-spread aria-label="Read Jira again" title="${esc(o.read.title || 'Read Jira again')}">${SV(I.read)}</button>` : '';
45
+ const head = `<div class="head"><h2 class="pm-h-sm pm-row">${SV(I.star).replace('pm-ic', 'pm-ic pm-star')}This sprint</h2><span class="sp"></span><span class="pm-meta wk-spm">${meta}</span>${read}</div>`;
46
+ const done = c.all ? `<div class="pm-row wk-spd"><b>${c.done} of ${c.all} done</b><div class="wk-spbar" role="progressbar" aria-label="${c.done} of ${c.all} done" aria-valuenow="${c.done}" aria-valuemin="0" aria-valuemax="${c.all}"><span style="width:${pct}%"></span></div></div>` : '';
47
+ const g = o.goal || { lines: [] };
48
+ const goal = `<div class="wk-spc1"><div class="pm-row wk-sph"><b>Sprint goal</b><button type="button" class="pm-btn" data-spedit="goals" aria-label="Edit Sprint goal" title="Edit Sprint goal">${SV(I.pen)}</button></div>`
49
+ + (g.editing ? g.edit : g.lines.length ? `<ul>${g.lines.map((t) => `<li>${esc(t)}</li>`).join('')}</ul>` : '<p class="pm-meta">No goal yet. Write one; it can name work outside Jira.</p>')
50
+ + (g.editing ? '' : g.newer || (!g.mine && g.lines.length ? '<p class="pm-meta">Drafted from the sprint\'s work. Edit to make it yours.</p>' : '')) + '</div>';
51
+ const col = (tab, name) => {
52
+ const R = rowsOf(N, tab).slice().sort(byDue).slice(0, 3);
53
+ if (!c[tab]) return `<div class="wk-spc1"><div class="pm-row wk-sph"><b>${name}</b></div></div>`;
54
+ return `<div class="wk-spc1"><div class="pm-row wk-sph"><b>${name} <span class="pm-meta">${c[tab]}</span></b></div><ul>${R.map((r) => `<li>${esc(r.title)}${movedText(r.moved) ? ` <span class="pm-badge">${movedText(r.moved)}</span>` : ''}</li>`).join('')}</ul></div>`;
55
+ };
56
+ return `<section class="pm-block wk-sp" aria-label="This sprint">${head}${done}<div class="wk-spcols">${goal}${col('doing', 'In progress')}${col('todo', 'To do')}${col('done', 'Done')}</div>${o.sug || ''}</section>`;
57
+ }
58
+
59
+ /** The Suggestion of one sprint proposal (pm/bk-sprint.js proposalsOf): Why, PMOS will, What changes, Based on. */
60
+ export function sugOfProp(p, label) {
61
+ if (!p) return '';
62
+ const n = p.uids.length, tk = plural(n, 'ticket', 'tickets');
63
+ const why = p.kind === 'link' ? `Their parent ticket is already in ${p.iniTitle}, so they belong there too.`
64
+ : p.kind === 'place' ? `The ${p.theme} tickets have no initiative, and ${p.iniTitle} has the same name.`
65
+ : `${n} ${p.theme} tickets in ${label || 'this sprint'} have no initiative, so nobody reports on them.`;
66
+ const will = p.kind === 'home' ? [`Open New initiative named ${p.theme}`, 'Place its tickets once you save it'] : [`Put ${n === 1 ? 'the ticket' : 'the ' + n + ' tickets'} in ${p.iniTitle}`];
67
+ const changes = p.kind === 'home' ? 'Nothing changes until you save the initiative. Nothing is sent to anyone.' : `The ${tk} show under ${p.iniTitle} here and on the initiative. Jira is not changed.`;
68
+ const basis = p.kind === 'link' ? 'The parent ticket in Jira' : 'The ticket titles' + (p.kind === 'place' ? ' and the initiative\'s name' : '');
69
+ return sugHtml({ title: p.text, why, will, changes, basis }, `data-pid="${esc(p.id)}"`, 'data-spsug');
70
+ }
71
+
72
+ /** The Group menu's groups, in order. o: { group, themes: [{ id, name, uids }] } → [{ k, name, rows }] */
73
+ export function groupsOf(rows, o = {}) {
74
+ const G = o.group || 'ini';
75
+ if (G === 'none') return [{ k: '', name: '', rows: rows.slice().sort(byDue) }];
76
+ const m = new Map(), add = (k, name, r) => { if (!m.has(k)) m.set(k, { k, name, rows: [] }); m.get(k).rows.push(r); };
77
+ const th = new Map(); for (const t of o.themes || []) for (const u of t.uids || []) th.set(u, t);
78
+ for (const r of rows) {
79
+ if (G === 'who') add(r.who || '~', r.who || 'No one', r);
80
+ else if (G === 'state') add(r.state, r.state, r);
81
+ else if (G === 'theme') { const t = th.get(r.uid); add(t ? t.name : '~', t ? t.name : 'Other work', r); }
82
+ else add(r.ini || '~', r.ini ? r.iniTitle || r.ini : 'No initiative yet', r);
83
+ }
84
+ const ST = ['In progress', 'In review', 'To do', 'Done'];
85
+ return [...m.values()].sort((a, b) => (G === 'state' ? ST.indexOf(a.k) - ST.indexOf(b.k) : (a.k === '~') - (b.k === '~') || a.name.localeCompare(b.name)))
86
+ .map((g) => ({ ...g, rows: g.rows.slice().sort((a, b) => (a.state === 'Done') - (b.state === 'Done') || byDue(a, b)) }));
87
+ }
88
+
89
+ const badgeOf = (s) => `<span class="pm-badge${s === 'In progress' || s === 'In review' ? ' blue' : ''}">${esc(s)}</span>`;
90
+ function rowHtml(r, nest) {
91
+ const t = r.open ? `<button type="button" class="wk-tt" data-spopen="${esc(r.uid)}">${esc(r.title)}</button>`
92
+ : r.url ? `<a class="wk-tt" href="${esc(r.url)}" target="_blank" rel="noopener">${esc(r.title)}</a>` : esc(r.title);
93
+ const src = r.key ? `<span class="pm-meta code">${esc(r.key)}</span>` : '<span class="pm-chip">Not in Jira</span>';
94
+ const due = `<span class="pm-row wk-due">${r.due ? `<span class="pm-meta code">${dayText(r.due)}</span>` : ''}${r.late ? `<span class="pm-badge alert">${lateText(r.late)}</span>` : ''}${movedText(r.moved) ? `<span class="pm-badge">${movedText(r.moved).replace(/^m/, 'M')}</span>` : ''}</span>`;
95
+ return `<tr class="wk-sr${r.state === 'Done' ? ' wk-dn' : ''}" data-sp="${esc(r.uid)}"><td class="${nest ? 'wk-nest' : ''}"><b>${t}</b></td><td>${esc(r.who) || '<span class="pm-meta">No one</span>'}</td><td>${badgeOf(r.state)}</td><td>${src}</td><td>${due}</td></tr>`;
96
+ }
97
+ /** The Tasks block. o: { tab, group, menu (the Group menu is open), themes } */
98
+ export function tasksHtml(N, o = {}) {
99
+ const c = countsOf(N), tab = o.tab || 'all', group = o.group || 'ini';
100
+ const tabs = `<div class="pm-tabs" role="tablist" aria-label="Show">${TABS.filter(([k]) => k === 'all' || c[k] || k === tab).map(([k, n]) => `<button type="button" class="pm-tab" role="tab" aria-selected="${k === tab}" data-sptab="${k}">${n} <span class="pm-meta">${c[k]}</span></button>`).join('')}</div>`;
101
+ const G = GROUPS.filter(([k]) => k !== 'theme' || (o.themes || []).length);
102
+ const gname = (G.find(([k]) => k === group) || G[0])[1];
103
+ const menu = `<span class="wk-mw"><button type="button" class="pm-tab wk-gb" data-spgroup aria-haspopup="menu" aria-expanded="${!!o.menu}">Group: ${gname}${SV(I.down, 14)}</button>`
104
+ + (o.menu ? `<div class="pm-menu wk-gm" role="menu" aria-label="Group">${G.map(([k, n]) => `<button type="button" role="menuitemradio" aria-checked="${k === group}" data-spgrp="${k}">${n}</button>`).join('')}</div>` : '') + '</span>';
105
+ const R = rowsOf(N, tab), GG = groupsOf(R, { group, themes: o.themes });
106
+ const all = groupsOf(N.rows, { group, themes: o.themes });
107
+ const body = GG.map((g) => {
108
+ const whole = all.find((x) => x.k === g.k) || g;
109
+ const head = g.name ? `<tr class="wk-g"><td colspan="5"><div class="pm-group"><b>${esc(g.name)}</b> <span class="pm-meta">${whole.rows.filter((r) => r.state === 'Done').length} of ${whole.rows.length} done</span></div></td></tr>` : '';
110
+ return head + g.rows.map((r) => rowHtml(r, !!g.name)).join('');
111
+ }).join('');
112
+ const table = R.length ? `<table class="pm-table wk-spx"><thead><tr><th>Task</th><th>Who</th><th>State</th><th>Source</th><th>Due</th></tr></thead><tbody>${body}</tbody></table>`
113
+ : '<p class="pm-meta">Nothing here.</p>';
114
+ return `<section class="pm-block wk-blk wk-spt" aria-label="Sprint tasks"><div class="head"><h2 class="pm-h">Tasks</h2><span class="sp"></span>${tabs}${menu}</div>${table}</section>`;
115
+ }
@@ -19,6 +19,7 @@
19
19
  * pm/bd-backlog.js calls bandHtml() while the chip is on, themeOf() for the list, pastOn()/pastListHtml() for a past sprint's list, and
20
20
  * press() first on each press in the Backlog. */
21
21
  import * as SK from './bk-sprint.js';
22
+ import * as DS from './bd-sprint-ds.js'; // This sprint from the system's parts (WorkSprintDS)
22
23
 
23
24
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
24
25
  const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
@@ -27,7 +28,7 @@ const I = { ok: 'M5 12.5l4.5 4.5L19 7', x: 'M6 6l12 12M18 6L6 18', pen: 'M4 20h4
27
28
  const SPARK = '✦';
28
29
  const OLD_MS = 36 * 3600000; // the Board's own line for an old Jira read (pm/premium-board.js jMood)
29
30
  const MON3 = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
30
- const BLOCK = { goals: 'Sprint goals', doing: 'Doing now', next: 'Planned next' };
31
+ const BLOCK = { goals: 'Sprint goal', doing: 'Doing now', next: 'Planned next' };
31
32
 
32
33
  let PICK = ''; // the sprint shown (its id), when there are more than one
33
34
  let THEME = ''; // the theme pressed (its id): the list below shows only its tickets
@@ -42,6 +43,10 @@ const DET = new Map(); // 'ws|board|name' → { state: pending|ready|failed, d
42
43
  const FILLING = new Set(); // sprints being read from Jira now (SpH3)
43
44
  const SHOWN = 8; // past sprints the picker shows before "N older sprints"
44
45
  const DR = new Map(); // sprint id → { sig, state: pending|ready|failed, d, again }
46
+ const VKEY = 'pmos.work.sprint';
47
+ const VIEW = (() => { try { const v = JSON.parse(localStorage.getItem(VKEY) || 'null'); if (v && typeof v === 'object') return { tab: DS.TABS.some(([k]) => k === v.tab) ? v.tab : 'all', group: DS.GROUPS.some(([k]) => k === v.group) ? v.group : 'ini' }; } catch { /* a private window */ } return { tab: 'all', group: 'ini' }; })();
48
+ const saveView = () => { try { localStorage.setItem(VKEY, JSON.stringify(VIEW)); } catch { /* kept for this page */ } };
49
+ let GMENU = false; // the Group menu is open
45
50
 
46
51
  const sigOf = (T) => T.map((t) => t.key + (SK.isMoving(t) ? 'm' : 't')).sort().join(',');
47
52
  const dayOf = (iso) => { const d = new Date(iso); return isNaN(d) ? '' : d.getDate() + ' ' + MON3[d.getMonth()]; };
@@ -77,7 +82,7 @@ export function bandHtml(o, deps) {
77
82
  if (PAST) { CUR = null; return pastHtml(o, H, past.find((x) => x.name === PAST), deps); }
78
83
  CURP = null;
79
84
  const sp = S.find((x) => x.id === PICK) || S[0];
80
- const T = sp.tasks, st = SK.statsOf(T);
85
+ const T = sp.tasks;
81
86
  const dr = ask(sp, deps);
82
87
  const written = dr.state === 'ready' ? SK.fromDraft(T, dr.d) : null;
83
88
  const themes = written ? written.themes : SK.themesOf(T);
@@ -87,37 +92,32 @@ export function bandHtml(o, deps) {
87
92
  const props = SK.proposalsOf(T, o.all, o.inis, themes, note.dismissed);
88
93
  CUR = { sp, themes, draft, props, note };
89
94
 
90
- const pct = (a, b) => (b ? Math.round((a / b) * 1000) / 10 : 0);
91
95
  const old = !o.readAt || Date.now() - Date.parse(o.readAt) > OLD_MS;
92
- const read = `Jira says active${o.readAt ? ' · last read ' + dayOf(o.readAt) : ''}`;
93
- const pick = S.length > 1 ? `<div class="sbo-pick" role="group" aria-label="Sprint">${S.map((x) => `<button type="button" class="bk-chip${x.id === sp.id ? ' on' : ''}" data-sppick="${esc(x.id)}" aria-pressed="${x.id === sp.id}">${esc(x.label)}<span class="k">${x.tasks.length}</span></button>`).join('')}</div>` : '';
94
- const tail = [st.todo ? st.todo + ' to do' : '', st.homeless ? `${st.homeless} of ${st.all} ${st.homeless === 1 ? 'is' : 'are'} in no initiative` : ''].filter(Boolean).join(' · ');
95
- const sum = `<div class="sbo-sum">${pick}<div class="sbo-h">${H && past.length ? pickerHtml(H, sp.name, sp.label) : `<b title="${esc(sp.name)}">${esc(sp.label)}</b>`}<button type="button" class="bk-ib" data-spread aria-label="Read Jira again" title="Read Jira again">${SV(I.read)}</button></div>`
96
- + `<p class="sbo-meta">${old ? '<i class="bk-dot amber"></i>' : ''}${esc(read)}</p>`
97
- + `<p class="sbo-big"><b>${st.moving} of ${st.all}</b> <span>moving</span></p><div class="sbo-bar" aria-hidden="true"><s style="width:${pct(st.moving, st.all)}%"></s></div>`
98
- + (tail ? `<p class="sbo-meta">${esc(tail)}</p>` : '') + '</div>';
99
- const th = `<div class="sbo-th"><p class="sbo-meta"><span class="sbo-s">${SPARK}</span> ${dr.state === 'pending' ? 'PMOS is reading the ticket titles to name the themes. Until then they are grouped by shared words.' : 'Themes PMOS found in the ticket titles. Press one to list its tickets below.'}</p>`
100
- + `<div class="sbo-thl">${themes.map((t) => `<button type="button" class="sbo-t${t.id === THEME ? ' on' : ''}" data-sptheme="${esc(t.id)}" aria-pressed="${t.id === THEME}" title="${esc(t.name)}: ${t.moving} of ${t.n} moving">`
101
- + `<b>${esc(t.name)}</b><span class="sbo-bar" aria-hidden="true"><s style="width:${pct(t.moving, t.n)}%"></s></span><span class="c">${t.moving} of ${t.n}</span></button>`).join('')}</div></div>`;
102
- const blocks = ['goals', 'doing', 'next'].map((k) => blockHtml(k, draft, note, st)).join('');
103
- const pr = props.length ? `<div class="sbo-props">${props.map((p) => `<div class="sbo-p"><span class="sbo-s" aria-hidden="true">${SPARK}</span><span class="x">${esc(p.text)}${p.sub ? `<em>${esc(p.sub)}</em>` : ''}</span>`
104
- + `<span class="bk-two"><button type="button" class="bk-ib" data-spok="${esc(p.id)}" aria-label="Yes: ${esc(p.text)}" title="Yes">${SV(I.ok)}</button><button type="button" class="bk-ib" data-spno="${esc(p.id)}" aria-label="No: ${esc(p.text)}" title="No">${SV(I.x)}</button></span></div>`).join('')}</div>` : '';
105
- return `<section class="sbo-band" aria-label="Sprint overview"><div class="sbo-top">${sum}${th}</div><div class="sbo-pl">${blocks}</div>${pr}</section>`;
96
+ // all work in the sprint's dates, Jira and not (lib/sprint-now.js); before the server's answer, the sprint's open tickets
97
+ const N = (o.now || []).find((n) => n.ws === sp.ws && n.board === sp.board && n.name === sp.name) || nowOf(sp);
98
+ CUR.now = N;
99
+ const pick = S.length > 1 ? `<span class="pm-tabs" role="group" aria-label="Sprint">${S.map((x) => `<button type="button" class="pm-tab" aria-pressed="${x.id === sp.id}" aria-selected="${x.id === sp.id}" data-sppick="${esc(x.id)}">${esc(x.label)}</button>`).join('')}</span>` : '';
100
+ const label = pick || (H && past.length ? pickerHtml(H, sp.name, sp.label) : `<b title="${esc(sp.name)}">${esc(sp.label)}</b>`);
101
+ const b = SK.blockOf(note.goals, draft.goals || []);
102
+ const goal = { lines: b.lines.map((l) => l.text), mine: !!b.mine, editing: EDIT === 'goals',
103
+ edit: `<textarea class="pm-input wk-ta" data-spta="goals" rows="${Math.max(3, b.lines.length + 1)}" aria-label="Sprint goal, one point a line">${esc(b.lines.map((l) => l.text).join('\n'))}</textarea>`
104
+ + `<div class="pm-row wk-ed"><button type="button" class="pm-btn primary" data-spsave="goals" aria-label="Save the sprint goal" title="Save">${SV(I.ok)}</button><button type="button" class="pm-btn" data-spcancel aria-label="Cancel" title="Cancel">${SV(I.x)}</button></div>`,
105
+ newer: b.newer ? `<div class="pm-sug"><span class="say">PMOS has a newer draft from the sprint's work.</span><button type="button" class="pm-btn" data-spnew="goals" aria-label="Use PMOS's newer draft of the sprint goal" title="Use it">${SV(I.ok)}</button><button type="button" class="pm-btn" data-spkeep="goals" aria-label="Keep yours" title="Keep yours">${SV(I.x)}</button></div>` : '' };
106
+ const read = { old, title: old ? 'Jira was last read ' + (o.readAt ? dayOf(o.readAt) : 'a while ago') + '. Read it again' : 'Read Jira again' + (o.readAt ? ' (last read ' + dayOf(o.readAt) + ')' : '') };
107
+ return DS.cardHtml(N, { label, goal, read, sug: DS.sugOfProp(props[0], sp.label) });
106
108
  }
107
109
 
108
- function blockHtml(k, draft, note, st) {
109
- const L = draft[k] || [], b = SK.blockOf(note[k], L);
110
- const count = k === 'doing' ? st.moving : k === 'next' ? st.todo : 0;
111
- const head = `<h4>${k === 'goals' && !b.mine ? `<span class="sbo-s" aria-hidden="true">${SPARK}</span>` : ''}${BLOCK[k]}${count ? `<span class="k">${count} ${count === 1 ? 'ticket' : 'tickets'}</span>` : ''}`
112
- + `<button type="button" class="bk-ib" data-spedit="${k}" aria-label="Edit ${BLOCK[k]}" title="Edit">${SV(I.pen)}</button></h4>`;
113
- if (EDIT === k) {
114
- return `<div class="sbo-b">${head}<textarea class="sbo-ta" data-spta="${k}" rows="${Math.max(3, b.lines.length + 1)}" aria-label="${BLOCK[k]}, one point a line">${esc(b.lines.map((l) => l.text).join('\n'))}</textarea>`
115
- + `<div class="sbo-ed"><button type="button" class="bk-ib ok" data-spsave="${k}" aria-label="Save ${BLOCK[k]}" title="Save">${SV(I.ok)}</button><button type="button" class="bk-ib" data-spcancel aria-label="Cancel" title="Cancel">${SV(I.x)}</button></div></div>`;
116
- }
117
- const ul = b.lines.length ? `<ul>${b.lines.map((l) => `<li><span>${esc(l.text)}</span>${l.n ? `<em>${l.n}</em>` : ''}</li>`).join('')}</ul>` : '';
118
- const foot = b.newer ? `<div class="sbo-new"><span><span class="sbo-s" aria-hidden="true">${SPARK}</span> PMOS has a newer draft from the tickets.</span><span class="bk-two"><button type="button" class="bk-ib" data-spnew="${k}" aria-label="Use PMOS's newer draft of ${BLOCK[k]}" title="Use it">${SV(I.ok)}</button><button type="button" class="bk-ib" data-spkeep="${k}" aria-label="Keep yours" title="Keep yours">${SV(I.x)}</button></span></div>`
119
- : k === 'goals' && !b.mine && L.length ? `<p class="sbo-meta">Drafted from the ${st.all} tickets, not from the goal set in Jira. Edit to make it yours.</p>` : '';
120
- return `<div class="sbo-b">${head}${ul}${foot}</div>`;
110
+ /** The sprint's open tickets as This sprint's rows, until GET /api/backlog answers with sprintNow. */
111
+ function nowOf(sp) {
112
+ const rows = sp.tasks.map((t) => ({ uid: SK.uidOf(t), id: t.id, src: t.src, key: t.key || '', title: t.title, ini: t.ini || null, iniTitle: t.iniTitle || '', who: t.who || '', state: t.state, due: t.due || null, late: t.late || 0, moved: 0, url: t.url || null, open: true }));
113
+ const jira = rows.filter((r) => r.key).length;
114
+ return { name: sp.name, label: sp.label, start: null, end: null, rows, jira, other: rows.length - jira, done: 0, total: rows.length };
115
+ }
116
+ /** The Tasks block of the sprint shown (WorkSprintDS); '' when a past sprint shows (its list is pastListHtml). */
117
+ export function tasksNowHtml() {
118
+ if (!CUR || !CUR.now || CURP) return '';
119
+ const themes = (CUR.themes || []).filter((t) => !t.spare && (t.uids || []).length).map((t) => ({ id: t.id, name: t.name, uids: t.uids }));
120
+ return DS.tasksHtml(CUR.now, { tab: VIEW.tab, group: VIEW.group === 'theme' && !themes.length ? 'ini' : VIEW.group, menu: GMENU, themes });
121
121
  }
122
122
 
123
123
  /* ── past sprints (initiative sprint-snapshots) ───────────────────────────────────────────────────────────── */
@@ -311,35 +311,50 @@ export async function press(e, deps) {
311
311
  deps.say(use ? BLOCK[k] + ': PMOS\'s newer draft.' : BLOCK[k] + ': yours kept.', () => back(deps, at, k, r.was));
312
312
  await deps.load(); return true;
313
313
  }
314
- if ((b = hit('data-spno'))) {
315
- const p = CUR.props.find((x) => x.id === b.dataset.spno); if (!p) return true;
316
- const r = await deps.post('/api/backlog/sprint-note', { ...at, ev: 'dismiss', id: p.id });
317
- if (!r || r.ok === false) { deps.say((r && r.error) || 'Nothing was changed.'); return true; }
318
- deps.say('Not now: ' + p.text + '.', async () => { await deps.post('/api/backlog/sprint-note', { ...at, ev: 'undismiss', id: p.id }); deps.load(); });
319
- await deps.load(); return true;
320
- }
321
- if ((b = hit('data-spok'))) {
322
- const p = CUR.props.find((x) => x.id === b.dataset.spok); if (!p) return true;
323
- if (p.kind === 'home') {
324
- if (deps.newInitiative) deps.newInitiative(p.theme, b); else deps.say('Make the initiative with New initiative, then place the tickets.');
325
- return true;
326
- }
327
- const done = [];
328
- for (const u of p.uids) {
329
- const t = deps.taskOf(u); if (!t) continue;
330
- const r = await deps.post('/api/backlog/place', { ws: t.ws, board: t.board, key: t.id, to: p.ini });
331
- if (r && r.ok) done.push({ t, from: r.from || '' }); else { deps.say((r && r.error) || 'Nothing was placed.'); break; }
332
- }
333
- if (done.length) {
334
- deps.say(`Placed ${done.length === 1 ? done[0].t.title : done.length + ' tickets'} in ${p.iniTitle}.`, async () => {
335
- for (const x of done) await deps.post('/api/backlog/place', { ws: x.t.ws, board: x.t.board, key: x.t.id, to: x.from });
336
- deps.say('Put back.'); deps.load(); deps.reload();
337
- });
338
- }
339
- await deps.load(); deps.reload(); return true;
314
+ // the Suggestion (WorkSprintDS): Yes is the old ✓, No the old ✕; the pencil picks another initiative before it places the tickets
315
+ if ((b = hit('data-spsug'))) {
316
+ const k = b.dataset.spsug, p = CUR.props.find((x) => x.id === b.dataset.pid); if (!p) return true;
317
+ if (k === 'no') return dismiss(p, at, deps);
318
+ if (k === 'yes' || p.kind === 'home' || !deps.pickIni) return accept(p, b, deps);
319
+ deps.pickIni(b, p, (id, title) => accept({ ...p, ini: id, iniTitle: title }, b, deps));
320
+ return true;
340
321
  }
322
+ if ((b = hit('data-sptab'))) { VIEW.tab = b.dataset.sptab; saveView(); deps.draw(); const n = document.querySelector(`[data-sptab="${VIEW.tab}"]`); if (n) n.focus(); return true; }
323
+ if (hit('data-spgroup')) { GMENU = !GMENU; deps.draw(); const n = document.querySelector('[data-spgrp][aria-checked="true"]'); if (GMENU && n) n.focus(); return true; }
324
+ if ((b = hit('data-spgrp'))) { VIEW.group = b.dataset.spgrp; GMENU = false; saveView(); deps.draw(); const n = document.querySelector('[data-spgroup]'); if (n) n.focus(); return true; }
325
+ if (GMENU) { GMENU = false; deps.draw(); }
326
+ if ((b = hit('data-spopen'))) { const t = deps.taskOf(b.dataset.spopen); if (t && deps.openTask) deps.openTask(t, b); return true; }
327
+ if ((b = hit('data-spno'))) { const p = CUR.props.find((x) => x.id === b.dataset.spno); return p ? dismiss(p, at, deps) : true; }
328
+ if ((b = hit('data-spok'))) { const p = CUR.props.find((x) => x.id === b.dataset.spok); return p ? accept(p, b, deps) : true; }
341
329
  return false;
342
330
  }
331
+ /** No on a proposal: not now, with Undo. */
332
+ async function dismiss(p, at, deps) {
333
+ const r = await deps.post('/api/backlog/sprint-note', { ...at, ev: 'dismiss', id: p.id });
334
+ if (!r || r.ok === false) { deps.say((r && r.error) || 'Nothing was changed.'); return true; }
335
+ deps.say('Not now: ' + p.text + '.', async () => { await deps.post('/api/backlog/sprint-note', { ...at, ev: 'undismiss', id: p.id }); deps.load(); });
336
+ await deps.load(); return true;
337
+ }
338
+ /** Yes on a proposal: place its tickets in the initiative (a ticket-move line; Jira is not written to), or open New initiative. */
339
+ async function accept(p, b, deps) {
340
+ if (p.kind === 'home') {
341
+ if (deps.newInitiative) deps.newInitiative(p.theme, b); else deps.say('Make the initiative with New initiative, then place the tickets.');
342
+ return true;
343
+ }
344
+ const done = [];
345
+ for (const u of p.uids) {
346
+ const t = deps.taskOf(u); if (!t) continue;
347
+ const r = await deps.post('/api/backlog/place', { ws: t.ws, board: t.board, key: t.id, to: p.ini });
348
+ if (r && r.ok) done.push({ t, from: r.from || '' }); else { deps.say((r && r.error) || 'Nothing was placed.'); break; }
349
+ }
350
+ if (done.length) {
351
+ deps.say(`Placed ${done.length === 1 ? done[0].t.title : done.length + ' tickets'} in ${p.iniTitle}.`, async () => {
352
+ for (const x of done) await deps.post('/api/backlog/place', { ws: x.t.ws, board: x.t.board, key: x.t.id, to: x.from });
353
+ deps.say('Put back.'); deps.load(); deps.reload();
354
+ });
355
+ }
356
+ await deps.load(); deps.reload(); return true;
357
+ }
343
358
  /** Undo of an edit: the block as it was (the PM's earlier words, or PMOS's draft). */
344
359
  async function back(deps, at, k, was) {
345
360
  await deps.post('/api/backlog/sprint-note', was ? { ...at, ev: 'note', block: k, text: was.text, base: was.base } : { ...at, ev: 'clear', block: k });
@@ -0,0 +1,165 @@
1
+ /* pm/bd-stands.js — the blocks Work opens with and ends on (initiative work-design-system-blocks; Exploring 3 page "work", boards WorkDS,
2
+ * WorkSprintDS, WorkBacklogDS; brief design-system/work-rebuild/brief.md). Built only from PMOS Komorebi parts (workspace/design-system/ui).
3
+ *
4
+ * · Where it stands: a Summary block (pm-block). It says what is happening and why it matters: the cause, what is at risk and the next
5
+ * decision point, with each initiative's name a link that opens it. Never counts alone. The words come from the record only: a late
6
+ * milestone and its days, what blocks it in Jira or waits on the PM, a stage with no dates and how long it has sat there, the next
7
+ * milestone. Nothing is invented; with nothing to say, the block says nothing (zero is silence).
8
+ * · One Suggestion after it, in the expanded form (pm-sug x): a title, Why (with its evidence), PMOS will (the exact steps), What changes
9
+ * and Based on (the sources), then Change it first (pencil), Yes (primary) and No (outline). Wawan: "user can't just trust to accept or
10
+ * reject". The Suggestion is one of PMOS's open proposals on the initiatives on screen (lib/proposals.js, r.props), the one on the most
11
+ * urgent initiative first; none open, none drawn.
12
+ * · Next milestones: a date line (pm-dline) under the Initiatives table with the next 5 milestones of all initiatives, each a diamond, its
13
+ * date, its name and its initiative. Close labels drop to a second row with a dashed lead; a milestone past the visible range is a +N mark
14
+ * at the right end with its month above it, and once the line is scrolled a matching mark shows at the left end. It follows the table's
15
+ * scale (the window the page gives).
16
+ * Everything here is pure: the page (pm/premium-board.js) passes the rows and the window and wires the presses by their data- attributes. */
17
+
18
+ export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
19
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
20
+ const DAY = 864e5;
21
+ const SV = (d, n = 16) => `<svg class="pm-ic" width="${n}" height="${n}" viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
22
+ export const I = {
23
+ star: 'M12 3l1.8 5.4L19 10.2l-5.2 1.8L12 17.4l-1.8-5.4L5 10.2l5.2-1.8z', pen: 'M4 20h4L19 9l-4-4L4 16z', ok: 'M5 12.5l4.5 4.5L19 7.5',
24
+ x: 'M6 6l12 12M18 6L6 18', plus: 'M12 5v14M5 12h14',
25
+ };
26
+ export const day = (v) => { if (v instanceof Date) return new Date(v.getFullYear(), v.getMonth(), v.getDate()); const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
27
+ /** "12 Nov", and the year when it is not this year. */
28
+ export const dm = (d, now = new Date()) => d.getDate() + ' ' + MON[d.getMonth()] + (d.getFullYear() !== now.getFullYear() ? ' ' + d.getFullYear() : '');
29
+ const days = (n) => n + (n === 1 ? ' day' : ' days');
30
+ const weeks = (n) => { const w = Math.round(n / 7); return w <= 1 ? (n === 1 ? '1 day' : n < 7 ? n + ' days' : '1 week') : w + ' weeks'; };
31
+ const closed = (r) => !!(r.closed || r.status === 'done');
32
+ const stageOf = (r) => String((r.acts && r.acts.stage) || r.stage || '');
33
+ const link = (r) => `<a href="#" data-wkopen="${esc(r.key)}">${esc(r.title)}</a>`;
34
+
35
+ /** The open milestones of a row with a date, earliest first. */
36
+ export const openMs = (r) => (r.milestones || []).filter((m) => m && !m.done && day(m.date)).sort((a, b) => day(a.date) - day(b.date));
37
+
38
+ /* ── Where it stands ──────────────────────────────────────────────────────────────────────────────────────────── */
39
+ /** One sentence for each initiative that needs saying, most urgent first, at most three, then the next decision point. → [html] */
40
+ export function standsOf(rows, now = new Date()) {
41
+ const t = day(now), open = (rows || []).filter((r) => r && !closed(r));
42
+ const said = new Set(), out = [];
43
+ // 1. late: the next milestone (or the plan's end) has passed. The cause, from the record: tickets blocked in Jira, or what waits on the PM.
44
+ const late = open.map((r) => {
45
+ const m = openMs(r)[0], d = m ? day(m.date) : (r.over && day(r.end)) || null;
46
+ return d && d < t ? { r, m, d, over: Math.round((t - d) / DAY) } : null;
47
+ }).filter(Boolean).sort((a, b) => b.over - a.over);
48
+ for (const x of late.slice(0, 2)) {
49
+ const tk = x.r.track || {}, what = x.m ? `its ${esc(dm(x.d, now))} ${esc(x.m.name || 'milestone')}` : `its planned end on ${esc(dm(x.d, now))}`;
50
+ const cause = tk.blocked ? ` because ${tk.blocked === 1 ? 'a Jira ticket is' : tk.blocked + ' Jira tickets are'} blocked`
51
+ : tk.you && tk.you.text ? ` and waits on you: ${esc(String(tk.you.text).replace(/^Your turn\s*·\s*/i, '').replace(/\.$/, ''))}` : '';
52
+ out.push(`${link(x.r)} is ${days(x.over)} past ${what}${cause}.`); said.add(x.r.key);
53
+ }
54
+ // 2. at risk, with a date still ahead
55
+ for (const r of open.filter((r) => !said.has(r.key) && r.status === 'at risk').slice(0, out.length ? 1 : 2)) {
56
+ const m = openMs(r)[0], d = m ? day(m.date) : day(r.end);
57
+ if (d && d >= t) { out.push(`${link(r)} is at risk for ${m ? esc(m.name || 'its milestone') + ' on ' : 'its end on '}${esc(dm(d, now))}.`); said.add(r.key); }
58
+ }
59
+ // 3. sitting in a stage with no dates: how long, from the day it moved there
60
+ for (const r of open.filter((r) => !said.has(r.key) && !day(r.start) && !day(r.end) && !openMs(r).length)) {
61
+ if (out.length >= 3) break;
62
+ const mv = day(r.acts && r.acts.movedOn), n = mv ? Math.round((t - mv) / DAY) : null, st = stageOf(r);
63
+ out.push(n != null && n > 0
64
+ ? `${link(r)} has sat in ${esc(st || 'its stage')} for ${weeks(n)} with no dates, so nothing shows when it will move.`
65
+ : `${link(r)} has no dates yet${st ? ' in ' + esc(st) : ''}, so nothing shows when it will move.`);
66
+ said.add(r.key);
67
+ }
68
+ // 4. the next decision point: the earliest milestone still ahead, of any initiative on screen
69
+ const next = open.flatMap((r) => openMs(r).filter((m) => day(m.date) >= t).map((m) => ({ r, m, d: day(m.date) }))).sort((a, b) => a.d - b.d)[0];
70
+ if (next) {
71
+ const n = Math.round((next.d - t) / DAY);
72
+ out.push(`The next decision point is ${esc(next.m.name || 'a milestone')} for ${link(next.r)} on ${esc(dm(next.d, now))}${n === 0 ? ', today' : n === 1 ? ', tomorrow' : n <= 14 ? ', in ' + days(n) : ''}.`);
73
+ } else if (!out.length && open.length) out.push(`Every initiative here is on its dates, and none has a milestone ahead yet.`);
74
+ return out;
75
+ }
76
+
77
+ /* ── the Suggestion: one of PMOS's open proposals ───────────────────────────────────────────────────────────────── */
78
+ const URG = (r, now) => { const t = day(now), m = openMs(r)[0], d = m ? day(m.date) : r.over ? day(r.end) : null; return d && d < t ? 0 : r.status === 'at risk' ? 1 : (r.track && r.track.you) ? 2 : 3; };
79
+ /** The open proposal to show: the most urgent initiative's first one (its groups come in the Viewer's order). → { r, p } | null */
80
+ export function pickProp(rows, now = new Date()) {
81
+ const C = (rows || []).filter((r) => r && !closed(r) && r.props && (r.props.groups || []).length).sort((a, b) => URG(a, now) - URG(b, now));
82
+ for (const r of C) for (const g of r.props.groups) for (const p of g.props || []) if (p && p.id && p.group !== 'links' && (p.title || (p.items || []).length)) return { r, p };
83
+ return null;
84
+ }
85
+ const dt = (v, now) => { const d = day(v); return d ? dm(d, now) : String(v || ''); };
86
+ /** A proposal in the Suggestion's words: { title, why, will: [text], changes, basis }. Every line comes from the proposal; one it lacks is left out. */
87
+ export function sugOf(r, p, now = new Date()) {
88
+ const items = (p.items || []).filter(Boolean);
89
+ const will = items.slice(0, 4).map((x) => (x.from || x.to) && p.group === 'dates'
90
+ ? `Move ${x.title || 'the task'}${x.from ? ' from ' + dt(x.from, now) : ''} to ${dt(x.to, now)}${x.jira ? ' (a comment on the Jira ticket; Jira is not changed)' : ''}`
91
+ : p.group === 'names' && x.from && x.to ? `Rename ${x.from} to ${x.to}` : String(x.title || ''));
92
+ if (items.length > 4) will.push(`and ${items.length - 4} more`);
93
+ if (p.ask && p.ask.owner) will.push(`Ask ${p.ask.owner} first; you see the message before it goes`);
94
+ const changes = p.plan && (p.plan.from || p.plan.to) ? `${p.stage ? p.stage + ' ' : 'The plan '}ends ${dt(p.plan.to, now)}${p.plan.from ? ' instead of ' + dt(p.plan.from, now) : ''}.` : '';
95
+ const basis = (p.sources || []).map((s) => (s && (s.label || s.name)) || '').filter(Boolean).join(', ');
96
+ const title = String(p.title || '').trim() || (will[0] || '');
97
+ return { title: title + (title && !title.includes(r.title) ? ` (${r.title})` : ''), why: String(p.why || '').trim(), will: title === will[0] && will.length === 1 ? [] : will, changes, basis };
98
+ }
99
+ /** The expanded Suggestion (pm-sug x). s: sugOf(); data: the attributes its answers carry (the page knows which proposal). */
100
+ export function sugHtml(s, data = '', at = 'data-wksug') {
101
+ if (!s || !s.title) return '';
102
+ const row = (k, v, cls = '') => (v ? `<dt>${k}</dt><dd${cls ? ` class="${cls}"` : ''}>${v}</dd>` : '');
103
+ return `<div class="pm-sug x" role="group" aria-label="PMOS suggests">`
104
+ + `<div class="ttl">${SV(I.star)}<b class="say">${esc(s.title)}</b></div>`
105
+ + `<dl>${row('Why', esc(s.why))}${row('PMOS will', s.will.length ? `<ul>${s.will.map((w) => `<li>${esc(w)}</li>`).join('')}</ul>` : '')}${row('What changes', esc(s.changes))}${row('Based on', esc(s.basis), 'src')}</dl>`
106
+ + `<div class="ans"><button type="button" class="pm-btn" ${at}="edit" ${data} aria-label="Change it first" title="Change it first">${SV(I.pen)}</button>`
107
+ + `<button type="button" class="pm-btn primary" ${at}="yes" ${data} aria-label="Yes, do it" title="Yes, do it">${SV(I.ok)}</button>`
108
+ + `<button type="button" class="pm-btn outline" ${at}="no" ${data} aria-label="No" title="No">${SV(I.x)}</button></div></div>`;
109
+ }
110
+ /** The Where it stands block: the sentences, then one Suggestion. Nothing to say and nothing suggested: no block. */
111
+ export function standsHtml(rows, o = {}) {
112
+ const now = o.now || new Date(), S = standsOf(rows, now);
113
+ const pk = o.sug === false ? null : pickProp(rows, now), sug = pk ? sugHtml(sugOf(pk.r, pk.p, now), `data-ini="${esc(pk.r.id)}" data-key="${esc(pk.r.key)}" data-pid="${esc(pk.p.id)}" data-sig="${esc(pk.p.sig || '')}"`) : '';
114
+ if (!S.length && !sug) return '';
115
+ return `<section class="pm-block wk-stands" aria-label="Where it stands"><h2 class="pm-h-sm pm-row">${SV(I.star).replace('pm-ic', 'pm-ic pm-star')}Where it stands</h2>`
116
+ + (S.length ? `<p class="wk-say">${S.join(' ')}</p>` : '') + sug + '</section>';
117
+ }
118
+
119
+ /* ── Next milestones: the date line ─────────────────────────────────────────────────────────────────────────── */
120
+ /** The next milestones of all initiatives from `from` on, earliest first. → [{ r, m, d, late }] */
121
+ export function nextMilestones(rows, now = new Date()) {
122
+ const t = day(now);
123
+ return (rows || []).filter((r) => r && !closed(r)).flatMap((r) => openMs(r).map((m) => ({ r, m, d: day(m.date), late: day(m.date) < t })))
124
+ .sort((a, b) => a.d - b.d);
125
+ }
126
+ /** Where the labels go: a label that would touch the one before it on its row drops to the next row (with a dashed lead). PURE.
127
+ * xs: the marks' positions in % of the line; w: a label's width in %. → [row index] */
128
+ export function stack(xs, w = 18) {
129
+ const ends = [], out = [];
130
+ for (const x of xs) { let k = 0; while (ends[k] != null && x < ends[k]) k++; ends[k] = x + w; out.push(k); }
131
+ return out;
132
+ }
133
+ /**
134
+ * The date line. items: nextMilestones(); W: the table's window { from, to }; o: { now, shift: how many milestones past the window's start
135
+ * were scrolled over (the left mark), title, sub, add: true draws + (New milestone) }. Shows the first 5 inside the window; the rest past
136
+ * the right end fold into +N with the month of the first of them above it.
137
+ */
138
+ export function dlineHtml(items, W, o = {}) {
139
+ const now = o.now || new Date(), t = day(now), span = +W.to - +W.from || 1;
140
+ const X = (d) => ((+d - +W.from) / span) * 100, P = (x) => Math.max(0, Math.min(100, x)).toFixed(2) + '%';
141
+ const before = items.filter((x) => x.d < W.from && x.d >= t), inside = items.filter((x) => x.d >= W.from && x.d <= W.to), after = items.filter((x) => x.d > W.to);
142
+ const shown = inside.slice(0, 5), rest = inside.slice(5).concat(after);
143
+ // the month ticks along the line, the same as the table's
144
+ const ticks = [];
145
+ for (let d = new Date(W.from.getFullYear(), W.from.getMonth(), 1); d <= W.to; d = new Date(d.getFullYear(), d.getMonth() + 1, 1)) if (d >= W.from) ticks.push(d);
146
+ const step = ticks.length > 8 ? Math.ceil(ticks.length / 8) : 1;
147
+ const tk = ticks.filter((_, i) => i % step === 0).map((d) => `<span class="tk" style="left:${P(X(d))}">${esc(MON[d.getMonth()] + (d.getMonth() === 0 ? ' ' + d.getFullYear() : ''))}</span>`).join('');
148
+ const nowM = t >= W.from && t <= W.to ? `<i class="pm-now" style="left:${P(X(t))}"><span>${esc(dm(t, now))}</span></i>` : '';
149
+ const rowsOf = stack(shown.map((x) => X(x.d)), o.lw ? (180 / o.lw) * 100 : 14); // a label is about 180 px wide
150
+ const marks = shown.map((x, i) => {
151
+ const k = rowsOf[i], name = x.m.name || 'Milestone';
152
+ return `<div class="ms${x.late ? ' late' : ''}${k ? ' low' : ''}" style="left:${P(X(x.d))};--row:${k}">`
153
+ // a read-only copy draws the diamond as a mark, not a button: its card can pin a milestone
154
+ + (o.ro ? `<span class="pm-dia${x.late ? ' late' : ''}" role="img" aria-label="${esc(name + ', ' + dm(x.d, now) + ', ' + x.r.title + (x.late ? ', late' : ''))}"></span>`
155
+ : `<button type="button" class="pm-dia${x.late ? ' late' : ''}" data-ms-pick="${esc(x.r.key)}" data-ms-id="${esc(x.m.id || '')}" aria-label="${esc(name + ', ' + dm(x.d, now) + ', ' + x.r.title + (x.late ? ', late' : ''))}" title="${esc(name + ' · ' + x.r.title)}"></button>`)
156
+ + `<span class="lb"><span class="code">${esc(dm(x.d, now))}</span><b>${esc(name)}</b><span class="pm-meta">${esc(x.r.title)}</span>${x.late ? `<span class="pm-badge alert">${days(Math.round((t - x.d) / DAY))} late</span>` : ''}</span></div>`;
157
+ }).join('');
158
+ const lo = before.length ? `<button type="button" class="pm-more l" data-wkdl="back" aria-label="${esc(before.length + ' earlier: scroll back')}" title="${esc(before.map((x) => x.m.name).join(', '))}"><span>${esc(MON[before[before.length - 1].d.getMonth()])}</span><b>+${before.length}</b></button>` : '';
159
+ const hi = rest.length ? `<button type="button" class="pm-more r" data-wkdl="on" aria-label="${esc(rest.length + ' later: scroll on')}" title="${esc(rest.map((x) => x.m.name + ' · ' + dm(x.d, now)).join('\n'))}"><span>${esc(MON[rest[0].d.getMonth()])}</span><b>+${rest.length}</b></button>` : '';
160
+ const rowsN = Math.max(1, ...rowsOf.map((k) => k + 1));
161
+ return `<section class="pm-block wk-next" aria-label="${esc(o.title || 'Next milestones')}"><div class="head"><h2 class="pm-h">${esc(o.title || 'Next milestones')}</h2>${o.sub ? `<span class="pm-meta">${esc(o.sub)}</span>` : ''}<span class="sp"></span>`
162
+ + (o.add ? `<button type="button" class="pm-btn" data-wkdl="add" aria-label="New milestone" title="New milestone">${SV(I.plus)}</button>` : '') + `</div>`
163
+ + (items.length ? `<div class="pm-dline" style="--rows:${rowsN}"><div class="axis">${tk}</div><div class="line">${nowM}${marks}</div>${lo}${hi}</div>`
164
+ : `<p class="pm-meta">No milestone ahead yet.</p>`) + '</section>';
165
+ }