create-pmos 0.842.0 → 0.844.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 (32) hide show
  1. package/package.json +37 -3
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/board-shared-ui-test.js +1 -0
  7. package/workspace/changelog.json +36 -2
  8. package/workspace/guide/cli.md +13 -1
  9. package/workspace/guide/layout.md +2 -0
  10. package/workspace/guide/settings-and-switches.md +1 -0
  11. package/workspace/lib/build-engine.js +4 -1
  12. package/workspace/lib/factory-traces.js +2 -1
  13. package/workspace/lib/features.json +1 -0
  14. package/workspace/lib/initiative-cost.js +259 -0
  15. package/workspace/lib/pmos-verbs.js +4 -1
  16. package/workspace/lib/routes-factory-metrics.js +54 -1
  17. package/workspace/lib/routes-proposals.js +7 -0
  18. package/workspace/lib/sprint-cli.js +30 -4
  19. package/workspace/lib/sprint-now.js +39 -4
  20. package/workspace/package-lock.json +2 -2
  21. package/workspace/package.json +1 -1
  22. package/workspace/public/pm/bd-backlog-ds.js +24 -4
  23. package/workspace/public/pm/bd-backlog.css +3 -0
  24. package/workspace/public/pm/bd-backlog.js +36 -7
  25. package/workspace/public/pm/bd-sprint-ds.js +117 -23
  26. package/workspace/public/pm/bd-sprint.js +9 -1
  27. package/workspace/public/pm/bd-work-ds.css +29 -0
  28. package/workspace/public/pm/cozy-pop-work.js +14 -1
  29. package/workspace/public/pm/initiative-cost.js +103 -0
  30. package/workspace/task-press-test.js +1 -1
  31. package/workspace/test-lists/initiative-cost.json +9 -0
  32. package/workspace/test-lists/tb-sprint-balanced.json +9 -0
@@ -2,11 +2,13 @@
2
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
3
  * and the presses.
4
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.
5
+ * · cardHtml(N, o): the right column (board TbSprint, page balanced, 2026-11-25): the Summary card (the sprint, how much it holds, its
6
+ * end, one bar of To do, In progress and Done, the three counts and who holds what), the Sprint goal (o.goal, editable) and PMOS
7
+ * suggests (o.sug). No other metric: Wawan was not confident in them.
8
+ * · stripHtml(N, o): the four counts over the page: To do, In progress, Done "n of m", No initiative.
8
9
  * · 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
+ * State, Theme, none), columns Task, Who, State, Ticket (the Jira key, a link, or "Not in Jira") and Epic (its key and name).
11
+ * The due date and its badges follow the title. Late = the due date has passed and the
10
12
  * task is not done: a red badge after the date. "Moved twice" is a plain badge.
11
13
  * 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
14
  import { sugHtml } from './bd-stands.js';
@@ -14,10 +16,11 @@ import { sugHtml } from './bd-stands.js';
14
16
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
15
17
  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
18
  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 16v4zM13.5 6.5l4 4', 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' };
19
+ out: 'M14 5h5v5M19 5l-8 8M17 14v5H5V7h5', down: 'M7 10l5 5 5-5', ok: 'M5 12.5l4.5 4.5L19 7.5', x: 'M6 6l12 12M18 6L6 18' };
18
20
  const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
19
21
  export const dayText = (d) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(d || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
20
22
  const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
23
+ const SPARK = '✦';
21
24
 
22
25
  export const TABS = [['all', 'All'], ['todo', 'To do'], ['doing', 'In progress'], ['done', 'Done']];
23
26
  export const GROUPS = [['ini', 'Initiative'], ['who', 'Who'], ['state', 'State'], ['theme', 'Theme'], ['none', 'None']];
@@ -36,24 +39,105 @@ export function holdsText(N) {
36
39
  /** Due first (no date last), then the title. */
37
40
  const byDue = (a, b) => (a.due || '9999').localeCompare(b.due || '9999') || a.title.localeCompare(b.title);
38
41
 
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 } */
42
+ /** The sprint in three counts and who holds what: the server's summary (lib/sprint-now.js summaryOf), else the same from the rows. */
43
+ export function summaryOf(N) {
44
+ if (N && N.summary) return N.summary;
45
+ const s = { todo: 0, doing: 0, done: 0, all: 0, by: [] }, m = new Map();
46
+ for (const r of N ? N.rows : []) {
47
+ const k = tabOfRow(r); s[k]++; s.all++;
48
+ if (k === 'done') continue;
49
+ const w = String(r.who || '');
50
+ if (!m.has(w)) m.set(w, { who: w, todo: 0, doing: 0, open: 0 });
51
+ const e = m.get(w); e[k]++; e.open++;
52
+ }
53
+ s.by = [...m.values()].sort((a, b) => (!a.who) - (!b.who) || b.open - a.open || a.who.localeCompare(b.who));
54
+ return s;
55
+ }
56
+ /** "By person: Wawan 4 to do · Suhas 1 to do, 1 in progress · no one 5". Only what each one holds; '' when nobody holds open work. */
57
+ export function byText(S) {
58
+ const one = (e) => (e.who ? [e.todo ? e.todo + ' to do' : '', e.doing ? e.doing + ' in progress' : ''].filter(Boolean).join(', ') : String(e.open));
59
+ return S.by.length ? 'By person: ' + S.by.map((e) => (e.who || 'no one') + ' ' + one(e)).join(' · ') : '';
60
+ }
61
+ /** "11 tickets" when all the work is in Jira, else "11 tasks". */
62
+ const workText = (N, n) => plural(n, N.other ? 'task' : 'ticket', N.other ? 'tasks' : 'tickets');
63
+ const SEGS = [['todo', 'To do'], ['doing', 'In progress'], ['done', 'Done']];
64
+ const WORD = ['No', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve'];
65
+ const word = (n, low) => { const w = n < WORD.length ? WORD[n] : String(n); return low && n < WORD.length ? w.toLowerCase() : w; };
66
+ /** Whole days from today to the sprint's end, or null (no end, or already past). */
67
+ export function daysLeft(N, today) {
68
+ const t0 = Date.parse(String(today || new Date().toISOString()).slice(0, 10)), t1 = Date.parse(String((N && N.end) || '').slice(0, 10));
69
+ return Number.isFinite(t0) && Number.isFinite(t1) && t1 >= t0 ? Math.round((t1 - t0) / 864e5) : null;
70
+ }
71
+ /** PMOS's one sentence per state (board TbSprint, ✦ under each count), written from the sprint's own rows, never by a model:
72
+ * "Ten of eleven are not started with 6 days left. Five have no owner." → { todo, doing, done }; a state with no work has no sentence. */
73
+ export function sentencesOf(N, o = {}) {
74
+ const R = (N && N.rows) || [], S = summaryOf(N), left = daysLeft(N, o.today), out = { todo: '', doing: '', done: '' };
75
+ const of = (k) => R.filter((r) => tabOfRow(r) === k);
76
+ const lateN = (L) => L.filter((r) => r.late > 0).length, movedN = (L) => L.filter((r) => r.moved >= 2).length;
77
+ const tail = left == null ? '' : left === 0 ? ' on the last day' : ` with ${plural(left, 'day', 'days')} left`;
78
+ if (S.todo) {
79
+ const L = of('todo'), none = L.filter((r) => !r.who).length, late = lateN(L), mv = movedN(L);
80
+ out.todo = (S.todo === S.all ? (S.all === 1 ? 'The only task is not started' : `All ${S.all} are not started`) : `${word(S.todo)} of ${word(S.all, true)} ${S.todo === 1 ? 'is' : 'are'} not started`) + tail + '.'
81
+ + (none ? (none === S.todo && S.todo > 1 ? ' None has an owner.' : ` ${word(none)} ${none === 1 ? 'has' : 'have'} no owner.`) : '')
82
+ + (late ? ` ${word(late)} ${late === 1 ? 'is' : 'are'} past the due date.` : '') + (mv ? ` ${word(mv)} moved from earlier sprints.` : '');
83
+ }
84
+ if (S.doing) {
85
+ const L = of('doing'), late = lateN(L);
86
+ const by = new Map(); for (const r of L) by.set(r.who || '', (by.get(r.who || '') || 0) + 1);
87
+ const holders = [...by.entries()].sort((a, b) => (!a[0]) - (!b[0]) || b[1] - a[1]).map(([w, n]) => (w || 'no one') + (S.doing > 1 ? ' ' + n : ''));
88
+ out.doing = (S.doing === 1 ? `${holders[0].replace(/^no one$/, 'No one')} ${holders[0] === 'no one' ? 'holds' : 'has'} the one under way.` : `${word(S.doing)} under way: ${holders.join(', ')}.`)
89
+ + (late ? ` ${word(late)} ${late === 1 ? 'is' : 'are'} past the due date.` : '');
90
+ }
91
+ if (S.done) {
92
+ const L = of('done'), out1 = L.filter((r) => !r.key).length;
93
+ out.done = `${word(S.done)} of ${word(S.all, true)} done${tail}.` + (out1 && out1 < S.done ? ` ${word(out1)} ${out1 === 1 ? 'was' : 'were'} outside Jira.` : out1 && out1 === S.done ? (S.done === 1 ? ' It was outside Jira.' : ' All were outside Jira.') : '');
94
+ }
95
+ return out;
96
+ }
97
+
98
+ /** The right column of This sprint (board TbSprint, page balanced): the Summary card, the Sprint goal and PMOS suggests, each its own block.
99
+ * o: { label (the sprint's name or its picker), goal: { lines: [text], mine, editing, edit (the textarea's html), newer (html) },
100
+ * read: { old, title }, sug: the Suggestion's html }. '' when the sprint holds no work (zero is silence). */
41
101
  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(' · ');
102
+ const S = summaryOf(N);
103
+ if (!S.all) return '';
104
+ const meta = [o.label || esc(N.label || N.name), workText(N, S.all), N.end ? 'ends ' + dayText(N.end) : ''].filter(Boolean).join(' · ');
44
105
  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>` : '';
106
+ const pct = (n) => Math.round((n / S.all) * 1000) / 10;
107
+ const bar = `<div class="wk-sp3" role="img" aria-label="${S.todo} to do, ${S.doing} in progress, ${S.done} done">${SEGS.filter(([k]) => S[k]).map(([k]) => `<span class="${k}" style="width:${pct(S[k])}%"></span>`).join('')}</div>`;
108
+ const say = sentencesOf(N, { today: o.today });
109
+ const rows = SEGS.map(([k, n]) => `<div class="pm-row wk-sprw"><i class="wk-dot ${k}" aria-hidden="true"></i><span>${n}</span><b>${S[k]}</b></div>`
110
+ + (say[k] ? `<p class="pm-meta wk-spsay"><span class="pm-star" aria-hidden="true">${SPARK}</span> ${esc(say[k])}</p>` : '')).join('');
111
+ const by = byText(S);
112
+ const sum = `<section class="pm-block wk-spsum" aria-label="Summary"><div class="head"><h2 class="pm-h-sm">Summary</h2><span class="sp"></span>${read}</div>`
113
+ + `<p class="pm-meta wk-spm">${meta}</p>${bar}${rows}${by ? `<p class="pm-meta wk-spby">${esc(by)}</p>` : ''}</section>`;
47
114
  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>`
115
+ const goal = `<section class="pm-block wk-spgoal" aria-label="Sprint goal"><div class="head"><h2 class="pm-h-sm">Sprint goal</h2><span class="sp"></span><button type="button" class="pm-btn" data-spedit="goals" aria-label="Edit Sprint goal" title="Edit Sprint goal">${SV(I.pen)}</button></div><div class="wk-spc1">`
49
116
  + (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>`;
117
+ + (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></section>';
118
+ const sug = o.sug ? `<section class="pm-block wk-spsg" aria-label="PMOS suggests"><div class="head"><h2 class="pm-h-sm">PMOS suggests</h2></div>${o.sug}</section>` : '';
119
+ return `<div class="wk-sp wk-spside">${sum}${goal}${sug}</div>`;
120
+ }
121
+
122
+ /** The strip over This sprint (board TbSprint): To do, In progress, Done and No initiative, each a count and one sub-line. o: { today }.
123
+ * A zero sub-line says nothing; No initiative shows only when some work has none. '' when the sprint holds no work. */
124
+ export function stripHtml(N, o = {}) {
125
+ const S = summaryOf(N);
126
+ if (!S.all) return '';
127
+ const R = N.rows || [];
128
+ const noOwner = R.filter((r) => tabOfRow(r) === 'todo' && !r.who).length;
129
+ const first = R.filter((r) => tabOfRow(r) === 'doing').sort(byDue)[0];
130
+ const t0 = Date.parse(String(o.today || new Date().toISOString()).slice(0, 10)), t1 = Date.parse(String(N.end || '').slice(0, 10));
131
+ const left = Number.isFinite(t0) && Number.isFinite(t1) && t1 >= t0 ? Math.round((t1 - t0) / 864e5) : null;
132
+ const noIni = R.filter((r) => !r.ini).length;
133
+ const tile = (n, name, sub) => `<div class="wk-stat"><b>${n}</b><span class="name">${name}</span>${sub ? `<span class="pm-meta">${esc(sub)}</span>` : ''}</div>`;
134
+ const tiles = [
135
+ tile(S.todo, 'To do', noOwner ? noOwner + ' with no owner' : ''),
136
+ tile(S.doing, 'In progress', first ? (first.who ? first.who + ': ' : '') + first.title : ''),
137
+ tile(`${S.done} of ${S.all}`, 'Done', left != null ? (left === 0 ? 'Last day of ' : plural(left, 'day', 'days') + ' left in ') + (N.label || N.name) : ''),
138
+ noIni ? tile(noIni, 'No initiative', noIni === S.all ? 'all the work in this sprint' : 'of ' + S.all) : '',
139
+ ];
140
+ return `<div class="wk-stats" role="group" aria-label="This sprint in numbers">${tiles.join('')}</div>`;
57
141
  }
58
142
 
59
143
  /** The Suggestion of one sprint proposal (pm/bk-sprint.js proposalsOf): Why, PMOS will, What changes, Based on. */
@@ -86,14 +170,24 @@ export function groupsOf(rows, o = {}) {
86
170
  .map((g) => ({ ...g, rows: g.rows.slice().sort((a, b) => (a.state === 'Done') - (b.state === 'Done') || byDue(a, b)) }));
87
171
  }
88
172
 
173
+ /** The Ticket cell: the Jira key, a link to the ticket (counted as sprintLink); a task outside Jira says so. */
174
+ export function ticketHtml(r) {
175
+ if (!r.key) return '<span class="pm-chip">Not in Jira</span>';
176
+ return r.url ? `<a class="pm-meta code wk-tk" href="${esc(r.url)}" target="_blank" rel="noopener" data-splink title="Open ${esc(r.key)} in Jira">${esc(r.key)}${SV(I.out, 12)}</a>` : `<span class="pm-meta code">${esc(r.key)}</span>`;
177
+ }
178
+ /** The Epic cell: the epic's key and name, a link to it in Jira; no epic says nothing. */
179
+ export function epicHtml(e) {
180
+ if (!e || !e.key) return '';
181
+ const inner = `<b class="code">${esc(e.key)}</b>${e.name ? ' ' + esc(e.name) : ''}`;
182
+ return e.url ? `<a class="wk-ep" href="${esc(e.url)}" target="_blank" rel="noopener" data-splink title="Open epic ${esc(e.key)} in Jira">${inner}</a>` : `<span class="wk-ep">${inner}</span>`;
183
+ }
89
184
  const badgeOf = (s) => `<span class="pm-badge${s === 'In progress' || s === 'In review' ? ' blue' : ''}">${esc(s)}</span>`;
90
185
  function rowHtml(r, nest, sel) {
91
186
  const on = !!(sel && sel.has(r.uid));
92
187
  const t = r.open ? `<button type="button" class="wk-tt" data-spopen="${esc(r.uid)}">${esc(r.title)}</button>`
93
188
  : r.url ? `<a class="wk-tt" href="${esc(r.url)}" target="_blank" rel="noopener">${esc(r.title)}</a>` : esc(r.title);
94
- const src = r.key ? `<span class="pm-meta code">${esc(r.key)}</span>` : '<span class="pm-chip">Not in Jira</span>';
95
- 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>`;
96
- return `<tr class="wk-sr${r.state === 'Done' ? ' wk-dn' : ''}${on ? ' sel' : ''}" data-sp="${esc(r.uid)}"${sel && sel.size ? ` aria-selected="${on}"` : ''}><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>`;
189
+ const due = r.due || r.late || movedText(r.moved) ? ` <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>` : '';
190
+ return `<tr class="wk-sr${r.state === 'Done' ? ' wk-dn' : ''}${on ? ' sel' : ''}" data-sp="${esc(r.uid)}"${sel && sel.size ? ` aria-selected="${on}"` : ''}><td class="${nest ? 'wk-nest' : ''}"><b>${t}</b>${due}</td><td>${esc(r.who) || '<span class="pm-meta">No one</span>'}</td><td>${badgeOf(r.state)}</td><td>${ticketHtml(r)}</td><td>${epicHtml(r.epic)}</td></tr>`;
97
191
  }
98
192
  /** The Tasks block. o: { tab, group, menu (the Group menu is open), themes, sel (the picked rows, Set of uid: Cmd, Ctrl or Shift-click picks) } */
99
193
  export function tasksHtml(N, o = {}) {
@@ -110,7 +204,7 @@ export function tasksHtml(N, o = {}) {
110
204
  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>` : '';
111
205
  return head + g.rows.map((r) => rowHtml(r, !!g.name, o.sel)).join('');
112
206
  }).join('');
113
- 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>`
207
+ const table = R.length ? `<table class="pm-table wk-spx"><thead><tr><th>Task</th><th>Who</th><th>State</th><th>Ticket</th><th>Epic</th></tr></thead><tbody>${body}</tbody></table>`
114
208
  : '<p class="pm-meta">Nothing here.</p>';
115
209
  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>`;
116
210
  }
@@ -22,6 +22,7 @@
22
22
  * press() first on each press in the Backlog. */
23
23
  import * as SK from './bk-sprint.js';
24
24
  import * as DS from './bd-sprint-ds.js'; // This sprint from the system's parts (WorkSprintDS)
25
+ import { noteUse } from './use-log.js';
25
26
 
26
27
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
27
28
  const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
@@ -111,10 +112,15 @@ export function bandHtml(o, deps) {
111
112
 
112
113
  /** The sprint's open tickets as This sprint's rows, until GET /api/backlog answers with sprintNow. */
113
114
  function nowOf(sp) {
114
- 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 }));
115
+ 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, epic: t.epic && t.epic.key ? { key: t.epic.key, name: t.epic.name || '', url: null } : null }));
115
116
  const jira = rows.filter((r) => r.key).length;
116
117
  return { name: sp.name, label: sp.label, start: null, end: null, rows, jira, other: rows.length - jira, done: 0, total: rows.length };
117
118
  }
119
+ /** The strip of four counts over This sprint (board TbSprint, page balanced); '' when a past sprint shows or the sprint holds no work. */
120
+ export function stripNowHtml() {
121
+ if (!CUR || !CUR.now || CURP) return '';
122
+ return DS.stripHtml(CUR.now, {});
123
+ }
118
124
  /** The Tasks block of the sprint shown (WorkSprintDS); '' when a past sprint shows (its list is pastListHtml). */
119
125
  export function tasksNowHtml(sel) {
120
126
  if (!CUR || !CUR.now || CURP) return '';
@@ -282,6 +288,8 @@ export async function press(e, deps) {
282
288
  const t0 = e.target;
283
289
  const hit = (a) => t0.closest('[' + a + ']');
284
290
  let b;
291
+ // a Ticket or Epic link opens Jira itself; counted on this computer only (the health number of tb-sprint-balanced)
292
+ if (hit('data-splink')) { noteUse('sprintLink'); console.info('[tb-sprint-balanced] Jira link opened'); return false; }
285
293
  if ((b = hit('data-sppick'))) { PICK = b.dataset.sppick; PAST = ''; THEME = ''; EDIT = ''; deps.draw(); return true; }
286
294
  if (hit('data-spmenu')) { MENU = !MENU; deps.draw(); const f = document.querySelector('.sbo-mi.on, .sbo-mi'); if (MENU && f) f.focus(); return true; }
287
295
  if (hit('data-spolder')) { OLDER = true; deps.draw(); return true; }
@@ -143,6 +143,33 @@ body.bd-page.sp-on [id="bkBody"] { display: flex; flex-direction: column; gap: v
143
143
  .wk-spx .wk-due { gap: var(--space-8); flex-wrap: nowrap; }
144
144
  .wk-spx tr.wk-g td { padding: 0; }
145
145
 
146
+ /* ── This sprint, balanced (board TbSprint, page balanced): the strip, Tasks beside the right column, the Summary card ── */
147
+ .wk-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-12); }
148
+ .wk-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: var(--space-12) var(--space-16); background: var(--card); border-radius: var(--radius-sm); box-shadow: inset 0 0 0 1px var(--line); }
149
+ .wk-stat > b { font-size: var(--fs-display); line-height: 28px; font-weight: var(--fw-strong); color: var(--ink); font-variant-numeric: tabular-nums; }
150
+ .wk-stat .name { font-size: var(--fs-row); color: var(--ink); }
151
+ .wk-stat .pm-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
152
+ .wk-spgrid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: var(--space-16); align-items: start; }
153
+ @media (max-width: 1099px) { .wk-spgrid { grid-template-columns: minmax(0, 1fr); } }
154
+ .wk-spside { display: flex; flex-direction: column; gap: var(--space-16); min-width: 0; }
155
+ .wk-spsum .wk-spm { margin: 0 0 var(--space-12); }
156
+ .wk-sp3 { display: flex; height: 8px; border-radius: var(--radius-pill); background: var(--well); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; margin-bottom: var(--space-8); }
157
+ .wk-sp3 > span { display: block; height: 100%; }
158
+ .wk-sp3 > .todo, .wk-dot.todo { background: var(--muted); }
159
+ .wk-sp3 > .doing, .wk-dot.doing { background: var(--blue); }
160
+ .wk-sp3 > .done, .wk-dot.done { background: var(--leaf); }
161
+ .wk-sprw { gap: var(--space-8); height: 28px; font-size: var(--fs-row); }
162
+ .wk-sprw > span { flex: 1; }
163
+ .wk-sprw > b { font-weight: var(--fw-strong); font-variant-numeric: tabular-nums; }
164
+ .wk-dot { width: 8px; height: 8px; border-radius: var(--radius-pill); flex: none; }
165
+ .wk-spby { margin: var(--space-8) 0 0; }
166
+ .wk-bkt .wk-tk, .wk-bk .wk-ep, .wk-spx .wk-tk, .wk-spx .wk-ep { color: var(--blue); text-decoration: none; display: inline-flex; align-items: center; gap: var(--space-4); }
167
+ .wk-bkt .wk-tk:hover, .wk-bk .wk-ep:hover, .wk-spx .wk-tk:hover, .wk-spx .wk-ep:hover { text-decoration: underline; }
168
+ .wk-bkt .wk-tk:focus-visible, .wk-bk .wk-ep:focus-visible, .wk-spx .wk-tk:focus-visible, .wk-spx .wk-ep:focus-visible { box-shadow: var(--glow); border-radius: var(--radius-sm); outline: none; }
169
+ .wk-bk .wk-ep, .wk-spx .wk-ep { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; color: var(--ink); }
170
+ .wk-bk .wk-ep b, .wk-spx .wk-ep b { font-weight: var(--fw-strong); color: var(--blue); }
171
+ .wk-spx td > .wk-due { display: inline-flex; margin-left: var(--space-8); }
172
+
146
173
  /* ── Backlog (WorkBacklogDS): Where it stands, the capture, the ranked Table ── */
147
174
  body.bd-page.bk-on [id="bdFilter"] { display: none; }
148
175
  body.bd-page.bk-on [id="bkBody"] { display: flex; flex-direction: column; gap: var(--space-16); max-width: none; }
@@ -221,6 +248,8 @@ body.bd-page.bk-on [id="bkBody"] { display: flex; flex-direction: column; gap: v
221
248
  @media (max-width: 760px) {
222
249
  .lb-m .lb-said span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
223
250
  }
251
+ .wk-spsay { margin: 0 0 var(--space-8) 16px; }
252
+ .wk-spsay .pm-star { margin-right: 2px; }
224
253
 
225
254
  /* Work › Initiatives (board TbInitiatives, slice 2, job 2038): the summary strip, the chips, and the list beside the Key results column 2 : 1.
226
255
  Under 1100 px the column sits under the list and the strip takes two cells a row. */
@@ -38,6 +38,7 @@ import * as IF from './inline-fields.js'; // a task's sprint and priority, set
38
38
  import * as SD from './star-draft.js'; // a ✦ draft runs as a PMOS background job and lands on its line (star-buttons-act-directly A7)
39
39
  import * as CAP from './pop-cap.js'; // five actions at most: Ask PMOS and the toolbar's four, the rest under ⋯ (popup-cap, idea A498)
40
40
  import { noteUse } from './use-log.js';
41
+ import * as IC from './initiative-cost.js'; // ⋯ › Cost (initiative-cost, A17): the factory's spend per merged pull request, in a sheet
41
42
  import * as BVD from './built-vs-design.js'; // the built screen beside its design, its circles, Accept and Send back (built-vs-design, A380)
42
43
  import * as STMAP from './story-map.js'; // a new bet's story map with the Release 1 line (initiative story-map, A419)
43
44
  import * as TLY from './three-layouts.js'; // three layouts for a new screen, pick one (initiative three-layouts, A317)
@@ -1762,12 +1763,24 @@ async function addArt(x, h) {
1762
1763
  * every part of the old page, as a drill-in, and every suggestion. body: the popup body the host drew into (it carries the wired handlers). */
1763
1764
  export function moreItems(x, h, body) {
1764
1765
  // under the popup cap (PopupCapDS) Plan, View and Jira come first; View holds Every part
1765
- const cap = capItems(body, h), out = cap.concat(artItems(body));
1766
+ const cap = capItems(body, h), out = cap.concat(artItems(body), costItems(body));
1766
1767
  if (h.allParts && !cap.some((it) => it.label === 'Every part')) out.push({ label: 'Every part', on: () => h.allParts() });
1767
1768
  if (h.props) out.push({ label: 'Everything PMOS suggests', on: () => h.props() });
1768
1769
  return out.length ? out.concat({ sep: true }) : out;
1769
1770
  }
1770
1771
 
1772
+ /** ⋯ › Cost (initiative-cost, A17): what the factory spent on this initiative, one row per merged pull request. Only when a factory ran on it
1773
+ * (zero is silence); the read is Work's (pm/initiative-cost.js load), so the first ⋯ may come before it and the next one has it. Money
1774
+ * shows in the sheet only, never on the popup itself. */
1775
+ function costItems(body) {
1776
+ if (RO || !body || !body.__pwx || !body.querySelector || !body.querySelector('.pw.pwd')) return [];
1777
+ const r = body.__pwx.r(); if (!r || !r.id) return [];
1778
+ IC.load();
1779
+ const row = IC.rowOf(r.ws || '', r.id);
1780
+ if (!row) return [];
1781
+ return [{ label: 'Cost', on: () => import('./primitives.js').then((P) => { const el = document.createElement('div'); el.innerHTML = IC.iniHtml(row); P.sheet({ title: 'Cost', sub: r.title || r.id, body: [el], attrs: { 'data-ic-sheet': r.id } }); }) }];
1782
+ }
1783
+
1771
1784
  /** The Artefacts section of ⋯ (artefacts-in-more-menu): read when ⋯ opens, so an artefact just added is there. The presses are the ones the
1772
1785
  * side card had: open full screen with Back, add, and the ✦ merge goes to the chat. */
1773
1786
  function artItems(body) {
@@ -0,0 +1,103 @@
1
+ /* pm/initiative-cost.js — Work › Cost and the initiative's ⋯ › Cost (initiative initiative-cost, job #1906, idea A17; board BatchReleaseDS
2
+ * panel 21 on the main canvas, agreed 2026-11-25). What the factory spent per initiative and per merged pull request, from
3
+ * GET /api/initiative-cost (lib/initiative-cost.js, the same store as `pmos cost`).
4
+ * Pure parts first, so Node imports them (initiative-cost.test.js); the page parts touch the DOM only when called.
5
+ *
6
+ * hasSpend(products) → true when some factory spent: Work shows the Cost tab only then (zero is silence)
7
+ * rowsOf(products) → [row] every product's rows, each with its ws and product name, most spend first
8
+ * tabHtml(products, { undone }) → the Cost tab: the table (Initiative, Agent hours, Spend, Result) and one ✦ line per stalled initiative
9
+ * with icon-only Pause and Keep going; a paused one has a Resume button
10
+ * iniHtml(row) → the ⋯ › Cost sheet: one row per merged pull request, with its own cost
11
+ * money(n) · hoursText(h) · resultText(row)
12
+ * load({ force }) → Promise<products> · rowOf(ws, ini) → row | null the page's one read, kept a minute
13
+ * press(e, { post, say, redraw }) → true when the press was a Cost button
14
+ *
15
+ * Money shows here only (Totals only on the Cost tab; no money on other pages). The words say PMOS. Every button is an icon with its
16
+ * aria-label. Text from records goes through esc(). */
17
+ import { pmGet } from './http.js';
18
+ export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
19
+ const SV = (d, cls = '') => `<svg class="pm-ic${cls ? ' ' + cls : ''}" width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${d}"/></svg>`;
20
+ const IC = {
21
+ star: 'M12 3l1.8 5.4L19 10.2l-5.2 1.8L12 17.4l-1.8-5.4L5 10.2l5.2-1.8z',
22
+ pause: 'M8 5v14M16 5v14',
23
+ keep: 'M6 6l12 12M18 6L6 18',
24
+ play: 'M7 5l12 7-12 7z',
25
+ link: 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6',
26
+ };
27
+ const STALL_DAYS = 7;
28
+
29
+ export function money(n) { const v = Number(n) || 0; return '$' + (v >= 100 ? Math.round(v) : v >= 10 ? Math.round(v) : v.toFixed(2)); }
30
+ export function hoursText(h) { const v = Number(h) || 0; return v > 0 ? (v >= 10 ? Math.round(v) : v) + ' h' : '—'; }
31
+ export function resultText(r) {
32
+ if (r.stall) return `0 merged in ${STALL_DAYS} days`;
33
+ if (r.merged) return r.merged + (r.merged === 1 ? ' PR merged' : ' PRs merged');
34
+ return 'Nothing merged yet';
35
+ }
36
+ export function rowsOf(products) {
37
+ const out = [];
38
+ for (const p of Array.isArray(products) ? products : []) for (const r of (p && p.rows) || []) out.push({ ...r, ws: p.ws || '', product: p.name || p.ws || '' });
39
+ return out.sort((a, b) => b.costUsd - a.costUsd || a.ini.localeCompare(b.ini));
40
+ }
41
+ export const hasSpend = (products) => rowsOf(products).some((r) => r.runs > 0);
42
+
43
+ const btn = (attrs, label, d) => `<button type="button" class="pm-btn" ${attrs} aria-label="${esc(label)}" title="${esc(label)}">${SV(d)}</button>`;
44
+ const keyOf = (r) => esc((r.ws || '') + '|' + r.ini);
45
+ const dataOf = (r) => `data-ic-ws="${esc(r.ws || '')}" data-ic-ini="${esc(r.ini)}"`;
46
+
47
+ /** The Cost tab. o.undone: keys (ws|ini) the PM answered on this page, so their ✦ line goes at once. */
48
+ export function tabHtml(products, o = {}) {
49
+ const rows = rowsOf(products), many = new Set(rows.map((r) => r.ws)).size > 1, gone = o.undone || new Set();
50
+ if (!rows.length) return '<section class="pm-block ic-cost" aria-label="Cost"><p class="pm-meta">No factory has run on an initiative here yet.</p></section>';
51
+ const th = (t) => `<th scope="col">${esc(t)}</th>`;
52
+ const body = rows.map((r) => {
53
+ const res = r.paused ? `<span class="pm-badge">Paused</span>` : r.stall ? `<span class="ic-alert">${esc(resultText(r))}</span>` : esc(resultText(r));
54
+ const name = `<button type="button" class="pw-lk" data-ic-open ${dataOf(r)}>${esc(r.ini)}</button>${many ? ` <span class="pm-meta">${esc(r.product)}</span>` : ''}`;
55
+ const resume = r.paused ? ' ' + btn(`data-ic-resume ${dataOf(r)}`, `Resume ${r.ini}'s jobs`, IC.play) : '';
56
+ return `<tr data-ic-row="${keyOf(r)}"><td>${name}</td><td>${esc(hoursText(r.hours))}</td><td>${esc(money(r.costUsd))}</td><td>${res}${resume}</td></tr>`;
57
+ }).join('');
58
+ const table = `<table class="pm-table ic-table"><thead><tr>${th('Initiative')}${th('Agent hours')}${th('Spend')}${th('Result')}</tr></thead><tbody>${body}</tbody></table>`;
59
+ const asks = rows.filter((r) => r.stall && !r.paused && !gone.has((r.ws || '') + '|' + r.ini)).map((r) => `<div class="ic-ask" data-ic-ask="${keyOf(r)}"><p class="pm-said">${SV(IC.star, 'pm-star')}<span>${esc(r.ini)} has spent ${esc(money(r.sinceUsd || r.recentUsd))} with no merge in ${STALL_DAYS} days. Pause its jobs?</span></p>`
60
+ + `<div class="pm-row">${btn(`data-ic-pause ${dataOf(r)}`, `Pause ${r.ini}'s new jobs`, IC.pause)}${btn(`data-ic-keep ${dataOf(r)}`, 'Keep going', IC.keep)}</div></div>`).join('');
61
+ const total = rows.reduce((s, r) => s + (Number(r.costUsd) || 0), 0);
62
+ return `<section class="pm-block ic-cost" aria-label="Cost"><div class="pm-row ic-head"><h2 class="pm-h-sm">Cost</h2><span class="pm-meta">${esc(money(total))} in all</span></div>${table}${asks}</section>`;
63
+ }
64
+
65
+ /** The initiative's ⋯ › Cost sheet: one row per merged pull request. */
66
+ export function iniHtml(r) {
67
+ if (!r) return '<p class="pm-meta">No factory has run on this initiative yet.</p>';
68
+ const th = (t) => `<th scope="col">${esc(t)}</th>`;
69
+ const head = `<p class="pm-meta">${esc(hoursText(r.hours))} · ${esc(money(r.costUsd))} · ${esc(String(r.tokens || 0))} tokens · ${esc(resultText(r))}${r.paused ? ' · Paused' : ''}</p>`;
70
+ if (!r.prs || !r.prs.length) return head + '<p class="pm-meta">No pull request merged yet.</p>';
71
+ const body = r.prs.map((p) => `<tr><td>${esc(p.title || p.item)}${p.url ? ' ' + `<a class="pm-btn" href="${esc(p.url)}" target="_blank" rel="noopener" aria-label="Open the pull request" title="Open the pull request">${SV(IC.link)}</a>` : ''}</td><td>${esc(hoursText(p.hours))}</td><td>${esc(money(p.costUsd))}</td><td>${esc(String(p.tokens || 0))}</td></tr>`).join('');
72
+ return head + `<table class="pm-table ic-table"><thead><tr>${th('Pull request')}${th('Agent hours')}${th('Spend')}${th('Tokens')}</tr></thead><tbody>${body}</tbody></table>`;
73
+ }
74
+
75
+ /* ── the page: one read, kept a minute ── */
76
+ const S = { got: null, at: 0, inflight: null };
77
+ export function load({ force = false } = {}) {
78
+ if (!force && S.got && Date.now() - S.at < 60000) return Promise.resolve(S.got);
79
+ if (S.inflight) return S.inflight;
80
+ S.inflight = pmGet('/api/initiative-cost').catch(() => null)
81
+ .then((j) => { S.got = j && j.ok ? j.products || [] : (S.got || []); S.at = Date.now(); S.inflight = null; return S.got; });
82
+ return S.inflight;
83
+ }
84
+ export const cached = () => S.got;
85
+ export function rowOf(ws, ini) { return rowsOf(S.got || []).find((r) => r.ini === ini && (!ws || !r.ws || r.ws === ws)) || null; }
86
+
87
+ /** A press on the Cost tab. post(path, body) → Promise<{ ok }>; say(msg, undo?) the page's toast; redraw() after a change. */
88
+ export function press(e, { post, say, redraw, open, undone } = {}) {
89
+ const b = e.target.closest('[data-ic-pause],[data-ic-keep],[data-ic-resume],[data-ic-open]');
90
+ if (!b || b.disabled) return false;
91
+ const d = b.dataset, body = { ws: d.icWs || undefined, ini: d.icIni };
92
+ if ('icOpen' in d) { if (open) open(d.icIni, d.icWs); return true; }
93
+ const act = 'icPause' in d ? 'pause' : 'icKeep' in d ? 'keep' : 'resume';
94
+ b.disabled = true;
95
+ post('/api/initiative-cost/' + act, body).then((r) => {
96
+ if (!r || !r.ok) { b.disabled = false; if (say) say((r && r.error) || 'That did not save. Try again in a moment.'); return; }
97
+ if (undone && act !== 'resume') undone.add((d.icWs || '') + '|' + d.icIni);
98
+ const again = () => post('/api/initiative-cost/resume', body).then(() => load({ force: true }).then(() => redraw && redraw()));
99
+ if (say) say(act === 'pause' ? `Paused ${d.icIni}'s new jobs. Running work finishes.` : act === 'keep' ? `${d.icIni} keeps going.` : `${d.icIni}'s jobs run again.`, act === 'pause' ? again : undefined);
100
+ return load({ force: true }).then(() => redraw && redraw());
101
+ });
102
+ return true;
103
+ }
@@ -109,7 +109,7 @@ const back = (p) => p.evaluate(() => { const b = document.querySelector('#czView
109
109
  const n0 = H.posts.length;
110
110
  await hp.click(`${V} [data-iv-check="t1"]`);
111
111
  ok('T3 the check box saves Done and opens nothing', await until(() => H.posts.slice(n0).some((x) => x.path === '/api/boards/tasks/state' && x.body.task === 't1' && x.body.state === 'Done'), 5000)
112
- && await hp.evaluate((v) => !!document.querySelector(v + ' [data-hi-v="page"]'), V), JSON.stringify(H.posts.slice(n0)));
112
+ && await until(() => hp.evaluate((v) => !!document.querySelector(v + ' [data-hi-v="page"]'), V), 3000), JSON.stringify(H.posts.slice(n0))); // the save redraws the page: a slow runner can look mid-redraw
113
113
  ok('T0 no page error on Home', H.errors.length === 0, H.errors.join(' | '));
114
114
  await H.ctx.close();
115
115
 
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "What each initiative and merged pull request cost (initiative initiative-cost, done test C1-C7, N1-N3): the pure fold, the stall ✦, the pause in build-engine next and claim, pmos cost, the route in process and the Cost tab's HTML, on a scratch product with the vendored work-item ledger. No server, browser, model or network.",
3
+ "modules": [
4
+ "initiative-cost.test.js"
5
+ ],
6
+ "seconds": {
7
+ "initiative-cost.test.js": 2
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "initiative tb-sprint-balanced (jobs #2018 tb-sprint-summary, #2016 tb-backlog-sprint-cols; board TbSprint, Exploring 3 page balanced): the Summary card, the strip, Ticket and Epic columns, pmos sprint now. Pure: page modules imported, lib/sprint-now.js on readings in memory, the CLI on a stand-in server.",
3
+ "modules": [
4
+ "test/tb-sprint-balanced.test.js"
5
+ ],
6
+ "seconds": {
7
+ "test/tb-sprint-balanced.test.js": 1
8
+ }
9
+ }