create-pmos 0.611.0 → 0.613.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 (97) hide show
  1. package/package.json +105 -27
  2. package/payload/KIT-VERSION +2 -2
  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/payload/state/log.md +1 -1
  7. package/workspace/briefing-premium-board-test.js +1 -1
  8. package/workspace/briefing-premium-calendar-2-test.js +3 -2
  9. package/workspace/briefing-premium-calendar-3-test.js +1 -1
  10. package/workspace/briefing-premium-calendar-test.js +1 -1
  11. package/workspace/briefing-premium-insights-test.js +1 -1
  12. package/workspace/briefing-premium-test.js +1 -1
  13. package/workspace/changelog.json +104 -0
  14. package/workspace/guide/layout.md +52 -18
  15. package/workspace/guide/programs.md +3 -3
  16. package/workspace/guide/routine.md +28 -13
  17. package/workspace/guide/settings-and-switches.md +1 -1
  18. package/workspace/lib/board-premium.js +12 -4
  19. package/workspace/lib/cos-chat.js +1 -0
  20. package/workspace/lib/doc-library.js +43 -12
  21. package/workspace/lib/doc-path.js +30 -0
  22. package/workspace/lib/engine/boards.js +4 -2
  23. package/workspace/lib/events-place.js +190 -38
  24. package/workspace/lib/events-stated.js +129 -0
  25. package/workspace/lib/initiative-chat.js +1 -0
  26. package/workspace/lib/insights-premium.js +13 -1
  27. package/workspace/lib/library-find.js +162 -0
  28. package/workspace/lib/library-items.js +196 -24
  29. package/workspace/lib/notes.js +3 -0
  30. package/workspace/lib/plan-items.js +17 -3
  31. package/workspace/lib/routes-artefacts.js +5 -2
  32. package/workspace/lib/routes-boards.js +6 -2
  33. package/workspace/lib/routes-doc-sheet.js +1 -0
  34. package/workspace/lib/routes-events-place.js +47 -10
  35. package/workspace/lib/routes-library.js +74 -8
  36. package/workspace/lib/routes-report-setups.js +13 -2
  37. package/workspace/lib/routine-reports.js +36 -4
  38. package/workspace/lib/status-when.js +36 -0
  39. package/workspace/lib/task-items.js +5 -3
  40. package/workspace/package-lock.json +2 -2
  41. package/workspace/package.json +1 -1
  42. package/workspace/premium-vw-meet-test.js +2 -1
  43. package/workspace/premium-vw-notes-test.js +3 -2
  44. package/workspace/public/pm/artefact-kind.js +87 -0
  45. package/workspace/public/pm/bd-ini-panel.js +6 -6
  46. package/workspace/public/pm/bd-span.js +7 -1
  47. package/workspace/public/pm/bd-work.css +62 -0
  48. package/workspace/public/pm/bd-work.js +195 -68
  49. package/workspace/public/pm/cozy-bar.css +11 -0
  50. package/workspace/public/pm/cozy-bar.js +99 -0
  51. package/workspace/public/pm/cozy-day-pick.css +27 -0
  52. package/workspace/public/pm/cozy-day-pick.js +97 -0
  53. package/workspace/public/pm/cozy-ev.css +0 -4
  54. package/workspace/public/pm/cozy-events-view.js +165 -33
  55. package/workspace/public/pm/cozy-events.css +75 -3
  56. package/workspace/public/pm/cozy-events.js +86 -18
  57. package/workspace/public/pm/cozy-goals.css +172 -0
  58. package/workspace/public/pm/cozy-library.css +106 -17
  59. package/workspace/public/pm/cozy-nav.js +2 -3
  60. package/workspace/public/pm/cozy-pick.css +3 -0
  61. package/workspace/public/pm/cozy-pop-work.css +83 -24
  62. package/workspace/public/pm/cozy-pop-work.js +313 -72
  63. package/workspace/public/pm/cozy-popup.css +11 -2
  64. package/workspace/public/pm/cozy-popup.js +67 -9
  65. package/workspace/public/pm/cozy-routine-job.js +203 -0
  66. package/workspace/public/pm/cozy-routine-model.js +139 -31
  67. package/workspace/public/pm/cozy-routine-pop.js +164 -42
  68. package/workspace/public/pm/cozy-routine.css +61 -8
  69. package/workspace/public/pm/cozy-routine.js +207 -28
  70. package/workspace/public/pm/cozy-settings.js +1 -5
  71. package/workspace/public/pm/cozy-status-when.js +48 -0
  72. package/workspace/public/pm/cozy-viewer.js +19 -8
  73. package/workspace/public/pm/cozy-vw-mtg.css +39 -0
  74. package/workspace/public/pm/goals-model.js +205 -0
  75. package/workspace/public/pm/goals-open.js +124 -0
  76. package/workspace/public/pm/home-chat.js +4 -2
  77. package/workspace/public/pm/home-ini.js +8 -6
  78. package/workspace/public/pm/ini-edit.js +3 -1
  79. package/workspace/public/pm/ini-view-model.js +1 -1
  80. package/workspace/public/pm/library-model.js +170 -42
  81. package/workspace/public/pm/library-open.js +8 -5
  82. package/workspace/public/pm/page-chat.js +12 -2
  83. package/workspace/public/pm/pop-work-model.js +199 -41
  84. package/workspace/public/pm/premium-board.js +108 -43
  85. package/workspace/public/pm/premium-goals.js +213 -0
  86. package/workspace/public/pm/premium-library.js +376 -62
  87. package/workspace/public/pm/premium-shell.js +1 -1
  88. package/workspace/public/pm/premium-vw-mtg.js +79 -1
  89. package/workspace/public/pm/scope-chip.js +207 -0
  90. package/workspace/public/premium-events.html +3 -1
  91. package/workspace/public/premium-goals.html +37 -0
  92. package/workspace/public/premium-library.html +15 -7
  93. package/workspace/public/premium-routine.html +2 -0
  94. package/workspace/server.js +2 -1
  95. package/workspace/test-lists/doc-path.json +9 -0
  96. package/workspace/test-lists/goals-place.json +9 -0
  97. package/workspace/test-lists/status-when.json +9 -0
@@ -26,6 +26,8 @@
26
26
  * date has no bar: PMOS does not invent a date.
27
27
  * 5 Artefacts: one table: Artefact, Kind, Updated. A core document a gate needs that is not written is a grey row that says which gate. */
28
28
 
29
+ import { gapsOf } from './cozy-bar.js';
30
+ import { provenStatus, NO_SIGNAL } from './status-proof.js';
29
31
  const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
30
32
  const DAY = 864e5;
31
33
  const day = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
@@ -36,6 +38,7 @@ const todayOf = (o) => day(o && o.today) || (() => { const d = new Date(); retur
36
38
  const norm = (s) => String(s || '').trim().toLowerCase().replace(/\s+/g, ' ');
37
39
  export const MAX_SUGGEST = 3;
38
40
  export const MANY = 6;
41
+ export const NEXT = 5; // a long stage shows its late and in-progress tasks and the next five
39
42
  export const MODES = [['quarter', 'Quarter'], ['half', 'Half'], ['year', 'Year'], ['2y', '2 yr'], ['5y', '5 yr'], ['full', 'Full']];
40
43
 
41
44
  /** "4 Nov" this year, "13 Jan 2027" in any other. */
@@ -59,6 +62,8 @@ export function spanOf(dates, mode, today) {
59
62
  if (!mode || mode === 'full') {
60
63
  let a = new Date(Math.min(...ds)), b = new Date(Math.max(...ds));
61
64
  if (between(a, b) < 28) b = new Date(a.getFullYear(), a.getMonth(), a.getDate() + 28);
65
+ // Today sits inside the span, never at its right edge (board 20): the span runs on to at least a fifth past today
66
+ if (between(t, b) < between(a, b) * 0.2) b = new Date(t.getFullYear(), t.getMonth(), t.getDate() + Math.max(14, Math.round(between(a, t) * 0.25)));
62
67
  const pad = Math.max(2, Math.round(between(a, b) * 0.03));
63
68
  a = new Date(a.getFullYear(), a.getMonth(), a.getDate() - pad); b = new Date(b.getFullYear(), b.getMonth(), b.getDate() + pad);
64
69
  return { a: iso(a), b: iso(b) };
@@ -162,10 +167,12 @@ export function draftDesc(v) {
162
167
 
163
168
  /* ── the Overview ── */
164
169
  const firstSentences = (s, n = 2) => { const parts = String(s || '').replace(/\s+/g, ' ').trim().match(/[^.!?]+[.!?]+(\s|$)|[^.!?]+$/g) || []; return parts.slice(0, n).join('').trim(); };
170
+ /** Text that is only an import note ("…162 issues, 35 open. tsv. It is in Closed."): never the Overview's words (round 3 point 14). */
171
+ export const importNote = (s) => { const t = String(s || ''); return /\b(tsv|csv|xlsx)\b/i.test(t) || /\b\d+ issues?\b.*\b\d+ open\b/i.test(t) || /^\s*(imported|import)\b/i.test(t); };
165
172
  /** The summary: what it is (the record's description, else PMOS's draft), then where it stands, in PMOS's words. own: the PM's words lead. */
166
173
  export function summaryOf(r, v, o = {}) {
167
174
  const t = todayOf(o), st = v.stage || {}, d = st.dates || {}, said = [];
168
- const desc = v.desc ? String(v.desc) : '', draft = !desc ? draftDesc(v) : null;
175
+ const desc = v.desc && !importNote(v.desc) ? String(v.desc) : '', draft = !desc ? draftDesc(v) : null;
169
176
  const lead = desc || (draft && draft.text) || '';
170
177
  if (st.name && st.n) said.push('It is in ' + st.name + (d.left ? (/over$/.test(d.left) ? ' and ' + d.left + ' its plan' : ', ' + d.left) : '') + '.');
171
178
  const late = ((v.tasks || {}).sections || []).flatMap((s) => (s.top || []).concat(...(s.groups || []).map((g) => g.rows || []))).filter((x) => x.late);
@@ -173,33 +180,50 @@ export function summaryOf(r, v, o = {}) {
173
180
  else if (late.length > 1) said.push(plural(late.length, 'task is', 'tasks are') + ' late.');
174
181
  const gate = st.gate && (st.gate.parts || []).filter((x) => !x.ok).map((x) => x.text);
175
182
  if (gate && gate.length) said.push(gate.join(' and ').replace(/^./, (c) => c.toUpperCase()) + ', so it cannot pass the ' + String(st.gate.label || 'gate').replace(/^Gate/, 'gate') + '.');
176
- return { lead: firstSentences(lead, 3), own: !!desc, draft, status: said.join(' '), text: [firstSentences(lead, 3), said.join(' ')].filter(Boolean).join(' ') };
183
+ // folded (board 20): the first sentence, where it stands, and how many tasks of the stage in progress are open; the gate waits for Details
184
+ const cur = ((v.tasks || {}).sections || []).find((s) => s.kind === 'stage' && s.status === 'now');
185
+ let openLine = '';
186
+ if (cur) {
187
+ const ts = (cur.top || []).concat(...(cur.groups || []).map((g) => g.rows || [])), n = ts.length + (cur.done || []).length, op = ts.filter((x) => !x.closed).length;
188
+ if (n && op) openLine = op + ' of ' + n + ' tasks in ' + cur.name + ' ' + (op === 1 ? 'is' : 'are') + ' open.';
189
+ }
190
+ const gateLine = said.length && gate && gate.length ? said[said.length - 1] : '';
191
+ const where = gateLine ? said.slice(0, -1) : said;
192
+ return { lead: firstSentences(lead, 3), own: !!desc, draft, status: said.join(' '), text: [firstSentences(lead, 3), said.join(' ')].filter(Boolean).join(' '),
193
+ short: firstSentences(lead, 1), folded: where.concat(openLine ? [openLine] : []).join(' ') };
194
+ }
195
+ /** A value shaped like an id, never a name: a hash ("8f24f28c35"), a KR key ("KR-C4", "O2.KR1", "q4-2026:o2:kr1"), a health budget key. The
196
+ * grid never shows one (round 3 points 4 and 12). */
197
+ export function idShaped(v) {
198
+ const s = String(v == null ? '' : v).trim(); if (!s) return false;
199
+ if (/\s/.test(s)) return false;
200
+ return /^[0-9a-f]{7,}$/i.test(s) || /^(kr|o)\d*[-.:]?[a-z]?\d/i.test(s) || /^[a-z0-9-]+(:[a-z0-9-]+)+$/i.test(s) || /^(o\d+|[a-z]+-[a-z]?\d+)(\.[a-z0-9-]+)+$/i.test(s) || /^health:/i.test(s);
177
201
  }
178
- /** The facts: name on the left, value on the right (a Confluence page). act: what a press on the value does (the host has it). */
202
+ const STATUS_WORD = { 'on track': 'On track', 'at risk': 'At risk', late: 'Late', done: 'Done', 'on hold': 'On hold' };
203
+ /** The Details grid (round 3 point 12): Stage / Status, Start / Target end, Next milestone / Goal, Product / Program, Workflow / Open. One
204
+ * plain value each; a field with no value, or only an id for a value, is not there. act: what a press on the value does (the host has it). */
179
205
  export function factsOf(r, v, o = {}) {
180
- const t = todayOf(o), st = v.stage || {}, d = st.dates || {}, F = [];
181
- if (st.name) F.push({ k: 'Stage', v: st.name + (st.n ? ' · ' + (r.status === 'done' ? 'Done' : r.ended ? 'Ended' : 'In progress') : ''), act: 'stage' });
182
- if (r.start || r.end) {
183
- const p = [r.start ? dayText(r.start, t) : '', r.end ? dayText(r.end, t) : ''].filter(Boolean).join(' to ');
184
- F.push({ k: 'Plan dates', v: p, note: d.over ? d.left : '', warn: !!d.over, act: 'dates' });
185
- }
206
+ const t = todayOf(o), st = v.stage || {}, F = [];
207
+ const add = (f) => { if (f && f.v && !idShaped(f.v)) F.push(f); };
208
+ const closed = !!(r.closed || r.ended), live = !closed && r.status !== 'done';
209
+ // a cell is pressable only when the press opens something (round 3 point 15): Next milestone, Goal, Product, Program. The rest is plain text
210
+ add(st.name ? { k: 'Stage', v: st.name, read: true } : null);
211
+ const end = day(r.end), over = live && end && end < t ? between(end, t) : 0;
212
+ // Status through the provenance rule (status-proof.js): a claim with no source and read time says No signal
213
+ const ps = closed ? '' : provenStatus(r, o.now);
214
+ const sw = closed ? 'Closed' : ps === NO_SIGNAL ? 'No signal' : STATUS_WORD[ps] || '';
215
+ add(sw ? { k: 'Status', v: sw + (sw === 'Late' && over ? ', ' + plural(over, 'day', 'days') + ' over' : ''), warn: sw === 'Late' || sw === 'At risk', read: true } : null);
216
+ add(r.start ? { k: 'Start', v: dayText(r.start, t), read: true } : null);
217
+ add(r.end ? { k: 'Target end', v: dayText(r.end, t), note: over ? plural(over, 'day', 'days') + ' over' : '', warn: !!over, read: true } : null);
186
218
  const nm = nextMilestone(v, t);
187
- if (nm) F.push({ k: 'Next milestone', v: nm.name, note: nm.date, warn: nm.late, act: nm.uid ? 'task:' + nm.uid : '' });
188
- else if (r.end) F.push({ k: 'Next milestone', v: 'Plan end', note: dayText(r.end, t), grey: true });
189
- if (st.next && st.next.name) F.push({ k: 'Next stage', v: st.next.name, act: 'next' });
219
+ add(nm ? { k: 'Next milestone', v: nm.name, note: nm.date, warn: nm.late, act: nm.uid ? 'task:' + nm.uid : '', read: !nm.uid } : null);
220
+ add(o.goal ? { k: 'Goal', v: o.goal, act: o.canGoal ? 'goal' : '', read: !o.canGoal } : null);
221
+ add(o.product ? { k: 'Product', v: o.product, act: o.canProduct ? 'product' : '', read: !o.canProduct } : null);
222
+ add(o.program && o.program.title ? { k: 'Program', v: o.program.title, act: o.program.id ? 'program' : '', read: !o.program.id } : null);
190
223
  const wf = v.summary && v.summary.wf;
191
- if (wf && wf.name) F.push({ k: 'Workflow', v: wf.name + (st.of ? ', ' + plural(st.of, 'stage', 'stages') : ''), act: 'wf' });
192
- if (o.goal || v.anchor) F.push({ k: 'Goal', v: o.goal || v.anchor });
193
- if (o.product) F.push({ k: 'Product', v: o.product, act: o.canProduct ? 'product' : '' }); // board 27: one level up
194
- if (o.program) F.push({ k: 'Program', v: o.program.title, act: 'program' }); // board 26
195
- if (st.gate && (st.gate.parts || []).length) {
196
- const no = st.gate.parts.filter((x) => !x.ok);
197
- const say = (no.length ? no : st.gate.parts).map((x) => x.text).join(' · ');
198
- F.push({ k: st.gate.label || 'Gate', v: say.charAt(0).toUpperCase() + say.slice(1), warn: no.length > 0, read: true });
199
- }
200
- const tk = v.tasks || {}, docs = (o.docs || []).filter((x) => x.path).length;
201
- const open = [tk.open ? plural(tk.open, 'task', 'tasks') : '', docs ? plural(docs, 'document', 'documents') : ''].filter(Boolean).join(' · ');
202
- if (open) F.push({ k: 'Open', v: open, read: true });
224
+ add(wf && wf.name ? { k: 'Workflow', v: wf.name + (st.of ? ', ' + plural(st.of, 'stage', 'stages') : ''), read: true } : null);
225
+ const tk = v.tasks || {}, docs = (o.docs || []).filter((x) => x.path).length + (o.items || []).length;
226
+ add({ k: 'Open', v: [tk.open ? plural(tk.open, 'task', 'tasks') : '', docs ? plural(docs, 'document', 'documents') : ''].filter(Boolean).join(' · '), read: true });
203
227
  return F;
204
228
  }
205
229
  /** The next open milestone task (◇), else null. */
@@ -214,10 +238,61 @@ function nextMilestone(v, t) {
214
238
  return { name: ms.title, date: dl.text, late: dl.late, uid: ms.uid };
215
239
  }
216
240
 
241
+ /* ── the Overview explains the initiative (round 3 point 10): Problem, Goal, Done when, from its own records; never invented ── */
242
+ const textOf = (f) => (f && typeof f === 'object' && !Array.isArray(f) ? String(f.text || '') : '');
243
+ /** overviewOf(r, v, o) → { lines: [{ k, text, src, path?, edit, miss?, ask?, id }], status }. o.art: GET /api/artefacts?scope=experiment:<id>
244
+ * .artefacts (null while it reads), o.docs, o.goal (the goal's name). A line with no source says so and carries the words ✓ sends to Ask PMOS.
245
+ * edit: { to: 'artefact', artefact, field } | { to: 'desc' } | null (not edited here). */
246
+ export function overviewOf(r, v, o = {}) {
247
+ const A = new Map(((o.art || [])).map((a) => [a.key, a])), ex = A.get('experiment') || { fields: {}, carried: [] }, dt = A.get('done-test') || { fields: {}, carried: [] };
248
+ const title = v.title || r.title || 'this initiative';
249
+ const docs = (o.docs || []).filter((d) => d && (d.path || d.link) && d.title);
250
+ const from = docs.find((d) => /brief/i.test(d.title)) || docs.find((d) => /\bprd\b/i.test(d.title)) || docs[0] || null;
251
+ const fromW = from ? (/brief/i.test(from.title) ? 'the brief' : /\bprd\b/i.test(from.title) ? 'the PRD' : from.title) : '';
252
+ const offer = (k, what) => ({ miss: k + ' is not written.' + (fromW ? ' Draft it from ' + fromW + '?' : ' Draft it with you?'),
253
+ ask: 'Draft ' + what + ' for ' + title + (fromW ? ' from ' + fromW : '') + ', in two short sentences, for me to read. Say what you read. Do not invent anything the records do not say.' });
254
+ const carriedPath = (a, f) => ((a.carried || []).find((c) => c.field === f && (c.path || c.text)) || null);
255
+ const lines = [];
256
+ // Problem: the Experiment's problem line, else the problem statement it carries
257
+ const pb = textOf(ex.fields.why), pc = carriedPath(ex, 'why');
258
+ if (pb) lines.push({ id: 'problem', k: 'Problem', text: pb, src: 'the Experiment', edit: { to: 'artefact', artefact: 'experiment', field: 'why' } });
259
+ else if (pc && pc.text) lines.push({ id: 'problem', k: 'Problem', text: String(pc.text), src: pc.title || 'the problem statement', path: pc.path || '', edit: { to: 'artefact', artefact: 'experiment', field: 'why' } });
260
+ else lines.push({ id: 'problem', k: 'Problem', text: '', edit: { to: 'artefact', artefact: 'experiment', field: 'why' }, ...offer('Problem', 'the problem (who has it and what it costs)') });
261
+ // Goal: the hypothesis, else the record's description; with the goal or key result it serves, by name
262
+ const hy = textOf(ex.fields.hypothesis), ds = v.desc && !importNote(v.desc) ? firstSentences(v.desc, 2) : '';
263
+ const serves = o.goal ? 'It serves ' + o.goal.replace(/\.$/, '') + '.' : '';
264
+ if (hy) lines.push({ id: 'goal', k: 'Goal', text: hy, serves, src: 'the Experiment', edit: { to: 'artefact', artefact: 'experiment', field: 'hypothesis' } });
265
+ else if (ds) lines.push({ id: 'goal', k: 'Goal', text: ds, serves, src: 'the record', edit: { to: 'desc' } });
266
+ else lines.push({ id: 'goal', k: 'Goal', text: '', serves, edit: { to: 'artefact', artefact: 'experiment', field: 'hypothesis' }, ...offer('Goal', 'what we are trying to achieve') });
267
+ // Done when: the done test's checks
268
+ const ck = Array.isArray(dt.fields.check) ? dt.fields.check.filter((x) => x && x.text) : [];
269
+ if (ck.length) lines.push({ id: 'done', k: 'Done when', text: ck[0].text + (ck.length > 1 ? ' (and ' + plural(ck.length - 1, 'more check', 'more checks') + ')' : ''), src: 'the Done test', edit: null });
270
+ else lines.push({ id: 'done', k: 'Done when', text: '', edit: { to: 'artefact', artefact: 'done-test', field: 'check' }, ...offer('Done when', 'the done test (how we will know it worked, and when we check)') });
271
+ const sm = summaryOf(r, v, o);
272
+ const status = sm.status.replace(/^It is in /, 'In ');
273
+ return { lines, status, reading: o.art == null };
274
+ }
275
+
276
+ /** The goal's name for an anchor (GET /api/boards/anchors rows { value, kind, label }): "KR-C4", "O-C:KR-C4" or "O-C.KR-C4" finds the KR
277
+ * whose value ends in it, and its label without the token ("KR-C4 De-risk Okta dependency" → "De-risk Okta dependency"). '' when none. */
278
+ export function goalName(list, anchor) {
279
+ const a = String(anchor || '').trim().toUpperCase().replace(/^KR:/, ''); if (!a) return '';
280
+ const L = list || [], dotted = a.replace(/:/g, '.'), last = dotted.split('.').pop(), two = dotted.split('.').slice(-2).join('.');
281
+ // "q4-2026:o2:kr1" (a period first), "O2.KR1", "health:ux": the whole value, else the objective and the KR, else a KR id found once
282
+ let hit = L.find((x) => { const u = String(x.value || '').toUpperCase(); return u === dotted || u === a || u === two; });
283
+ if (!hit) { const by = L.filter((x) => x.kind === 'kr' && String(x.value || '').toUpperCase().split('.').pop() === last); if (by.length === 1) hit = by[0]; }
284
+ if (!hit) return '';
285
+ const lb = String(hit.label || '');
286
+ if (hit.kind === 'kr') return lb.replace(/^\S+\s+(?:[—–:-]\s*)?/, '').replace(/\.$/, '');
287
+ const m = /\((.+)\)$/.exec(lb); return m ? m[1] : lb;
288
+ }
289
+
217
290
  /* ── the work breakdown ── */
218
291
  function taskRow(x, t) {
219
292
  const dl = x.end ? dateLate(x.end, t, !x.closed) : { text: x.start ? 'from ' + dayText(x.start, t) : '', late: false };
220
- return { kind: 'task', uid: x.uid, title: x.title, status: taskStatus(x), date: dl.text, late: dl.late, start: x.start || '', end: x.end || '', done: !!x.closed, ms: !!x.ms, jira: !!x.jkey, canCheck: !!x.canCheck };
293
+ const st = taskStatus(x);
294
+ return { kind: 'task', uid: x.uid, title: x.title, status: st, date: dl.text, late: dl.late, start: x.start || '', end: x.end || '', since: x.since || '', done: !!x.closed, ms: !!x.ms, jira: !!x.jkey, canCheck: !!x.canCheck,
295
+ prog: /progress|review/i.test(st), wont: !!x.wont || st === "Won't do" };
221
296
  }
222
297
  export function breakdownOf(r, v, o = {}) {
223
298
  const t = todayOf(o), list = ((v.stage || {}).ladder || []).map((s, i) => ({ name: s.name, status: s.cls, ms: !!s.ms, i }));
@@ -228,8 +303,15 @@ export function breakdownOf(r, v, o = {}) {
228
303
  const cur = stages.findIndex((s) => s.status === 'now');
229
304
  const rows = [];
230
305
  let many = false;
306
+ const looseSec = secs.find((s) => s.kind === 'none');
307
+ const looseTs = looseSec ? (looseSec.top || []).concat(...(looseSec.groups || []).map((g) => g.rows || [])) : [];
308
+ // the tasks in no stage are one quiet folded row at the end (round 3 point 21): no task rows and no bars until it is opened; its one ✦
309
+ // offers to put them in the stage in progress, the one stage PMOS can name for each
310
+ const looseUnder = null;
311
+ const loose = [];
231
312
  const stageRow = (s, i) => {
232
313
  const ts = (s.top || []).concat(...(s.groups || []).map((g) => g.rows || []));
314
+ const lz = looseUnder === s ? looseTs : [];
233
315
  const all = ts.concat(s.done || []);
234
316
  const nDone = (s.done || []).length, n = all.length;
235
317
  const [ta, tb] = taskSpan(all);
@@ -240,14 +322,28 @@ export function breakdownOf(r, v, o = {}) {
240
322
  else if (s.status !== 'skip') { a = ta; b = tb; }
241
323
  const live = s.status === 'now' && r.status !== 'done' && !r.ended;
242
324
  const dl = b && (s.status === 'now' || s.status === 'next') ? dateLate(b, t, live || ts.some((x) => !x.closed)) : { text: b && s.status === 'done' ? '' : '', late: false };
243
- const isOpen = shut.has(s.key) ? false : open.has(s.key) ? true : s.status === 'now' || ts.some((x) => x.late);
325
+ const isOpen = shut.has(s.key) ? false : open.has(s.key) ? true : s.status === 'now';
244
326
  const count = n ? (s.status === 'next' && !nDone ? plural(n, 'task', 'tasks') : nDone + ' of ' + n + ' done') : '';
245
- rows.push({ kind: 'stage', key: s.key, n: s.n, name: s.name, ms: !!s.ms, status: STATUS[s.status] || '', count, date: dl.text, late: dl.late, start: a, end: b,
246
- done: s.status === 'done', open: isOpen && n > 0, can: n > 0, now: s.status === 'now', skip: s.status === 'skip' });
247
- if (!(isOpen && n > 0)) return;
327
+ const has = n + lz.length > 0;
328
+ // the bar's gap line and its ◇s (pm/cozy-bar.js stageBar): the stage's dated tasks, and its milestone tasks
329
+ const gaps = a && b ? gapsOf(all.filter((x) => !x.wont).map((x) => [x.start || x.end, x.end || x.start]).filter(([p]) => p), a, b) : [];
330
+ const marks = all.filter((x) => x.ms && !x.wont && x.end).map((x) => ({ uid: x.uid, title: x.title, end: x.end, done: !!x.closed, late: !!x.late && !x.closed }));
331
+ rows.push({ kind: 'stage', key: s.key, n: s.n, name: s.name, ms: !!s.ms, status: STATUS[s.status] || '', count, date: dl.text, late: dl.late, start: a, end: b, gaps, marks, tone: s.status === 'done' ? 'dn' : s.status === 'now' ? 'now' : '',
332
+ done: s.status === 'done', open: (isOpen || lz.length > 0) && has, can: has, now: s.status === 'now', skip: s.status === 'skip' });
333
+ if (!((isOpen || lz.length > 0) && has)) return;
248
334
  const sorted = ts.slice().sort(urgent);
249
335
  if (s.status === 'now' && sorted.length > MANY) many = true;
250
- for (const x of sorted) rows.push({ ...taskRow(x, t), sec: s.key });
336
+ // a long stage (round 3 point 7): the late and in-progress tasks, then the next NEXT, then "N more"
337
+ const all2 = sorted.map((x) => taskRow(x, t));
338
+ let shown = all2;
339
+ if (all2.length > NEXT + 3 && !(o.moreOpen && o.moreOpen.has(s.key))) {
340
+ const hot = all2.filter((x) => x.late || x.prog), rest = all2.filter((x) => !x.late && !x.prog);
341
+ const keep = new Set(hot.concat(rest.slice(0, NEXT)));
342
+ shown = all2.filter((x) => keep.has(x));
343
+ }
344
+ for (const x of shown) rows.push({ ...x, sec: s.key });
345
+ if (shown.length < all2.length) rows.push({ kind: 'more', key: s.key, n: all2.length - shown.length, label: plural(all2.length - shown.length, 'more task', 'more tasks') });
346
+ for (const x of lz.slice().sort(urgent)) { rows.push({ ...taskRow(x, t), sec: '', loose: s.key }); loose.push({ uid: x.uid, title: x.title, to: s.key, name: s.name }); }
251
347
  if (nDone) {
252
348
  const dd = s.done.map((x) => x.end).filter(Boolean).sort();
253
349
  rows.push({ kind: 'done', key: s.key, n: nDone, label: plural(nDone, 'task', 'tasks') + ' done', open: dOpen.has(s.key), start: (s.done.map((x) => x.start).filter(Boolean).sort()[0]) || dd[0] || '', end: dd[dd.length - 1] || '' });
@@ -266,13 +362,14 @@ export function breakdownOf(r, v, o = {}) {
266
362
  }
267
363
  stageRow(s, i);
268
364
  });
269
- const loose = secs.find((s) => s.kind === 'none');
270
- if (loose) {
271
- const ts = (loose.top || []).concat(...(loose.groups || []).map((g) => g.rows || [])), isOpen = !shut.has('');
272
- rows.push({ kind: 'stage', key: '', n: '', name: 'Not in a stage', status: '', count: plural(ts.length, 'open task', 'open tasks'), date: '', start: '', end: '', open: isOpen && ts.length > 0, can: ts.length > 0 });
365
+ const ts = looseTs.filter((x) => !x.closed);
366
+ if (ts.length) {
367
+ const isOpen = open.has('') && !shut.has('');
368
+ rows.push({ kind: 'stage', key: '', n: '', name: 'Not in a stage', status: '', count: plural(ts.length, 'open task', 'open tasks'), date: '', start: '', end: '', open: isOpen, can: true, loose: true });
273
369
  if (isOpen) for (const x of ts.slice().sort(urgent)) rows.push({ ...taskRow(x, t), sec: '' });
370
+ if (cur >= 0) for (const x of ts) loose.push({ uid: x.uid, title: x.title, to: stages[cur].key, name: stages[cur].name });
274
371
  }
275
- return { rows, many, list };
372
+ return { rows, many, list, loose };
276
373
  }
277
374
 
278
375
  /* ── the artefacts ── */
@@ -284,14 +381,18 @@ export function artefactsOf(v, o = {}) {
284
381
  for (const it of o.items || []) {
285
382
  if (!it || !it.name || seen.has(key(it.name))) continue;
286
383
  seen.add(key(it.name));
287
- out.push({ id: it.id, title: it.name, kind: it.kindText || KIND_OF_ITEM[it.kind] || 'Document', when: it.updated ? dayText(it.updated, t) || it.updated : '', item: it, link: it.kind === 'link' });
384
+ out.push({ id: it.id, title: it.name, kind: it.kindText || KIND_OF_ITEM[it.kind] || 'Document', when: it.updated ? dayText(it.updated, t) || it.updated : '', item: it, link: it.kind === 'link',
385
+ type: it.type || '', path: (it.open && it.open.doc && it.open.doc.path) || '', akind: it.kind, at: Date.parse(it.updated || '') || 0,
386
+ // the Library's own Kind (lib/library-items.js kindOf, PR #1376) when it is a specific one; the popup's resolver only fills in for older servers
387
+ kindName: it.kindText && !/^(Document|Meeting notes|Link|File)$/.test(it.kindText) ? (it.kindText === 'Rubric' ? 'Eval rubric' : it.kindText) : '' });
288
388
  }
289
389
  for (const d of o.docs || []) {
290
390
  if (!d || !d.title || seen.has(key(d.title))) continue;
291
391
  if (d.path || d.link) {
292
392
  seen.add(key(d.title));
293
393
  const lk = d.link && d.link.url;
294
- out.push({ id: d.key, title: d.title, kind: lk ? 'Link · ' + (d.link.kind || 'page') : d.kind === 'Slides' ? 'Slides' : 'Document', when: whenOf(d.when, t), path: d.path || '', url: lk || '', link: !!lk });
394
+ out.push({ id: d.key, title: d.title, kind: lk ? 'Link · ' + (d.link.kind || 'page') : d.kind === 'Slides' ? 'Slides' : 'Document', when: whenOf(d.when, t), path: d.path || '', url: lk || '', link: !!lk,
395
+ type: d.type || '', akind: lk ? 'link' : 'doc', at: Date.parse(d.at || d.date || d.updated || d.when || '') || 0 });
295
396
  }
296
397
  }
297
398
  // what a gate needs and is not written: grey rows that say which gate (board 21)
@@ -304,19 +405,70 @@ export function artefactsOf(v, o = {}) {
304
405
  seen.add(key(d.title));
305
406
  out.push({ id: d.key, title: d.title, kind: 'Document', missing: 'Not written · needed for the gate to ' + (gateName || 'the next stage'), key: d.key, act: d.act || null });
306
407
  }
408
+ // the gate names a document the page has not read a row for ("PRD and rubric not written"): its grey row all the same (board 21)
409
+ const NAMES = { prd: 'PRD', rubric: 'Rubric', 'done test': 'Done test', spec: 'Spec', brief: 'Brief' };
410
+ for (const part of gate.parts.filter((x) => !x.ok)) {
411
+ for (const m of String(part.text || '').matchAll(/\b(prd|rubric|done test|spec|brief)\b/gi)) {
412
+ const title = NAMES[m[1].toLowerCase()];
413
+ if (seen.has(key(title)) || out.some((a) => key(a.title).split(' ').includes(key(title)))) continue;
414
+ seen.add(key(title));
415
+ out.push({ id: 'gate:' + key(title), title, kind: 'Document', missing: 'Not written · needed for the gate to ' + (gateName || 'the next stage') });
416
+ }
417
+ }
307
418
  }
308
419
  return out;
309
420
  }
310
421
  const whenOf = (w, t) => { const s = String(w || ''); return day(s) ? dayText(s, t) : s.replace(/^added\s+/, ''); };
311
422
 
423
+ /* ── what PMOS suggests from the record itself (board 3, 25), next to what lib/proposals.js proposes ── */
424
+ const andList = (a) => (a.length <= 1 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1]);
425
+ /** derivedOf(r, v, o, bd, arts) → { top: [s], rows: Map(uid → s) }. Each s: { id, derived: true, say, why, ask?, move? }. ask: the words ✓ sends
426
+ * to Ask PMOS, which does it in a real session; move: { uid, to, name } ✓ puts a task in a stage. o.dropped: the ids the PM said No to. */
427
+ export function derivedOf(r, v, o, bd, arts) {
428
+ const t = todayOf(o), drop = o.dropped || new Set(), top = [], rows = new Map(), title = v.title || r.title || 'this initiative';
429
+ const live = r.status !== 'done' && !r.ended && !r.closed;
430
+ // the plan end has passed and an open task runs later: move the plan end to that task's date
431
+ const end = day(r.end);
432
+ if (live && end && end < t) {
433
+ const all = ((v.tasks || {}).sections || []).flatMap((s) => (s.top || []).concat(...(s.groups || []).map((g) => g.rows || []))).filter((x) => !x.closed && day(x.end) && day(x.end) >= t);
434
+ const last = all.sort((a, b) => b.end.localeCompare(a.end))[0];
435
+ if (last) top.push({ id: 'd:plan-end', derived: true, say: 'Move the plan end to ' + dayText(last.end, t) + '. It follows ' + last.title + '.',
436
+ why: 'The plan ended on ' + dayText(r.end, t) + ', and ' + last.title + ' is due on ' + dayText(last.end, t) + '.',
437
+ ask: 'Move the plan end of ' + title + ' to ' + last.end + ': it follows the task ' + last.title + '. Tell me what else moves.' });
438
+ }
439
+ // a document the gate needs is not written: PMOS drafts it from what is written, for the PM to read
440
+ const miss = (arts || []).filter((a) => a.missing).map((a) => a.title);
441
+ if (live && miss.length) {
442
+ const n = (arts || []).filter((a) => !a.missing).length, what = andList(miss.map((m) => 'the ' + m));
443
+ top.push({ id: 'd:draft', derived: true, say: 'Let me draft ' + what + (n ? ' from the ' + plural(n, 'document', 'documents') : '') + ', for you to read.',
444
+ why: 'The gate to the next stage needs ' + what + ', and ' + (miss.length === 1 ? 'it is' : 'they are') + ' not written.',
445
+ ask: 'Draft ' + what + ' for ' + title + (n ? ' from its ' + plural(n, 'document', 'documents') : '') + ', for me to read.' });
446
+ }
447
+ // honest state (round 3 point 13): closed or done, with open tasks, is a contradiction PMOS asks about
448
+ const nOpen = (v.tasks || {}).open || 0;
449
+ if ((r.closed || r.ended || r.status === 'done') && nOpen > 0) {
450
+ const w = r.status === 'done' && !r.closed && !r.ended ? 'done' : 'closed';
451
+ top.unshift({ id: 'd:closed-open', derived: true, say: 'It is ' + w + ', but ' + plural(nOpen, 'task is', 'tasks are') + ' open. Close them, or reopen the initiative?',
452
+ why: '', choices: [{ label: 'Close them', ask: 'Close the ' + plural(nOpen, 'open task', 'open tasks') + ' of ' + title + '. It is ' + w + '. Tell me what you closed.' },
453
+ { label: 'Reopen', ask: 'Reopen ' + title + ': it has ' + plural(nOpen, 'open task', 'open tasks') + '. Put it back in the stage it was in before, and tell me where.' }] });
454
+ }
455
+ // one ✦ on the Not in a stage row (round 3 point 21), keyed 'stage:' (the row of no stage)
456
+ const lz = (bd && bd.loose) || [];
457
+ if (lz.length) rows.set('stage:', { id: 'd:loose', derived: true, say: (lz.length === 1 ? 'Put it in ' : 'Put the ' + lz.length + ' tasks in ') + lz[0].name + '?', why: '', moveAll: { uids: lz.map((x) => x.uid), to: lz[0].to, name: lz[0].name } });
458
+ return { top: top.filter((s) => !drop.has(s.id)), rows: new Map([...rows].filter(([, s]) => !drop.has(s.id))) };
459
+ }
460
+
312
461
  /* ── one initiative ── */
313
462
  export function workOf(r, v, o = {}) {
314
463
  const t = todayOf(o);
315
- const sum = summaryOf(r, v, o), sug = suggestsOf(v), bd = breakdownOf(r, v, o);
464
+ const sum = summaryOf(r, v, o), sug = suggestsOf(v), bd = breakdownOf(r, v, o), arts = artefactsOf(v, o);
465
+ const dv = derivedOf(r, v, o, bd, arts);
466
+ const all = sug.top.concat(dv.top), rowS = new Map(sug.rows);
467
+ for (const [k, s] of dv.rows) if (!rowS.has(k)) rowS.set(k, s);
316
468
  const dates = [r.start, r.end].concat(bd.rows.flatMap((x) => [x.start, x.end])).filter(Boolean);
317
469
  const span = spanOf(dates, o.mode || 'full', t);
318
- return { title: v.title || r.title || '', summary: sum, suggests: sug.top, more: sug.more, rowSuggests: sug.rows, facts: factsOf(r, v, o),
319
- rows: bd.rows, many: bd.many, span, today: iso(t), artefacts: artefactsOf(v, o) };
470
+ return { title: v.title || r.title || '', summary: sum, overview: overviewOf(r, v, o), suggests: all.slice(0, MAX_SUGGEST), more: sug.more + Math.max(0, all.length - MAX_SUGGEST), rowSuggests: rowS, facts: factsOf(r, v, o),
471
+ rows: bd.rows, many: bd.many, span, today: iso(t), artefacts: arts };
320
472
  }
321
473
 
322
474
  /* ── one level up: a program or a product (boards 26, 27) ── */
@@ -330,6 +482,12 @@ export function levelOf(L, o = {}) {
330
482
  });
331
483
  const span = spanOf(rows.flatMap((x) => [x.start, x.end]).filter(Boolean), o.mode || 'full', t);
332
484
  const late = rows.filter((x) => x.late).length;
333
- return { kind: L.kind, title: L.title, summary: L.summary || '', facts: L.facts || [], rows, span, today: iso(t), late, artefacts: (L.docs || []).map((d) => ({ ...d, when: whenOf(d.when, t) })),
485
+ // the same Overview shape as an initiative (round 3 point 10): what it is for, its goal, done when; a line with no source offers a draft
486
+ const nm = L.kind === 'product' ? 'product' : 'program', who = L.title || 'this ' + nm;
487
+ const line = (id, k, text, what) => (text ? { id, k, text: String(text), edit: null } : { id, k, text: '', edit: null, miss: k + ' is not written. Draft it with you?',
488
+ ask: 'Draft ' + what + ' for the ' + nm + ' ' + who + ', in two short sentences, for me to read. Say what you read. Do not invent anything the records do not say.' });
489
+ const sum = L.summary && !importNote(L.summary) ? firstSentences(L.summary, 2) : '';
490
+ const overview = { lines: [line('for', 'For', sum, 'what the ' + nm + ' is for'), line('goal', 'Goal', L.goal || '', 'the goal of the ' + nm), line('done', 'Done when', L.done || '', 'how we will know the ' + nm + ' worked')], status: L.status || '' };
491
+ return { kind: L.kind, title: L.title, summary: L.summary || '', overview, facts: L.facts || [], rows, span, today: iso(t), late, artefacts: (L.docs || []).map((d) => ({ ...d, when: whenOf(d.when, t) })),
334
492
  suggests: suggestsOf({ props: L.props || null }).top };
335
493
  }