create-pmos 0.424.0 → 0.426.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 (110) hide show
  1. package/package.json +25 -25
  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-deliveries-test.js +153 -0
  7. package/workspace/board-programs-test.js +60 -36
  8. package/workspace/board-shot.js +4 -3
  9. package/workspace/briefing-premium-board-test.js +9 -6
  10. package/workspace/briefing-premium-insights-test.js +31 -15
  11. package/workspace/briefing-premium-products-test.js +46 -43
  12. package/workspace/calm-timeline-test.js +190 -0
  13. package/workspace/changelog.json +24 -0
  14. package/workspace/ev-everywhere-test.js +3 -1
  15. package/workspace/guide/briefing-premium.md +3 -2
  16. package/workspace/guide/claude-proposes.md +16 -1
  17. package/workspace/guide/home.md +2 -2
  18. package/workspace/guide/index.md +1 -0
  19. package/workspace/guide/notes.md +39 -1
  20. package/workspace/guide/present-in-a-meeting.md +57 -0
  21. package/workspace/guide/programs.md +4 -3
  22. package/workspace/lib/board-premium.js +3 -1
  23. package/workspace/lib/briefing-premium-products.js +18 -4
  24. package/workspace/lib/chat-file-locate.js +40 -2
  25. package/workspace/lib/engine/boards.js +8 -2
  26. package/workspace/lib/idle-close.js +60 -0
  27. package/workspace/lib/loose-proposals.js +302 -0
  28. package/workspace/lib/meeting-focus.js +64 -14
  29. package/workspace/lib/my-work-premium.js +1 -1
  30. package/workspace/lib/proposal-runs.js +77 -2
  31. package/workspace/lib/propose-cli.js +42 -1
  32. package/workspace/lib/route-modules.js +1 -0
  33. package/workspace/lib/routes-boards.js +16 -4
  34. package/workspace/lib/routes-brief-page.js +9 -1
  35. package/workspace/lib/routes-briefing-premium.js +19 -0
  36. package/workspace/lib/routes-loose.js +210 -0
  37. package/workspace/lib/routes-meeting-focus.js +28 -6
  38. package/workspace/lib/routes-pm-items.js +27 -17
  39. package/workspace/lib/settings-store.js +2 -1
  40. package/workspace/lib/task-cli.js +18 -11
  41. package/workspace/milestone-pins-test.js +170 -0
  42. package/workspace/package-lock.json +2 -2
  43. package/workspace/package.json +1 -1
  44. package/workspace/premium-board-actions-test.js +2 -1
  45. package/workspace/premium-briefing-depth-test.js +2 -2
  46. package/workspace/premium-chat-term-test.js +13 -2
  47. package/workspace/premium-core-doc-issue-test.js +1 -1
  48. package/workspace/premium-rec-now-test.js +153 -0
  49. package/workspace/premium-rec-tab-test.js +167 -0
  50. package/workspace/product-lane-test.js +30 -17
  51. package/workspace/public/pm/bd-acts.js +6 -3
  52. package/workspace/public/pm/bd-deliveries.js +218 -0
  53. package/workspace/public/pm/bd-pin-card.css +16 -0
  54. package/workspace/public/pm/bd-pin-card.js +80 -0
  55. package/workspace/public/pm/bd-pins.js +33 -0
  56. package/workspace/public/pm/bd-pop.js +2 -0
  57. package/workspace/public/pm/bd-prog.js +5 -4
  58. package/workspace/public/pm/bd-span.js +140 -102
  59. package/workspace/public/pm/cozy-aud.css +9 -0
  60. package/workspace/public/pm/cozy-aud.js +80 -0
  61. package/workspace/public/pm/cozy-board.css +73 -11
  62. package/workspace/public/pm/cozy-home.css +16 -1
  63. package/workspace/public/pm/cozy-live-pill.js +3 -0
  64. package/workspace/public/pm/cozy-pick.css +41 -0
  65. package/workspace/public/pm/cozy-pick.js +134 -0
  66. package/workspace/public/pm/cozy-rec-bridge.js +32 -0
  67. package/workspace/public/pm/cozy-rec-now.css +104 -0
  68. package/workspace/public/pm/cozy-rec-now.js +330 -0
  69. package/workspace/public/pm/cozy-rec-present.css +69 -0
  70. package/workspace/public/pm/cozy-rec-present.js +467 -0
  71. package/workspace/public/pm/cozy-rec-tab.css +90 -0
  72. package/workspace/public/pm/cozy-rec-tab.js +219 -0
  73. package/workspace/public/pm/cozy-settings.js +8 -2
  74. package/workspace/public/pm/cozy-today.css +4 -0
  75. package/workspace/public/pm/home-app.js +51 -22
  76. package/workspace/public/pm/home-data.js +5 -3
  77. package/workspace/public/pm/home-list.js +63 -15
  78. package/workspace/public/pm/home-more.js +2 -31
  79. package/workspace/public/pm/home-today.js +19 -9
  80. package/workspace/public/pm/ini-tasks.js +4 -1
  81. package/workspace/public/pm/live-model.js +1 -1
  82. package/workspace/public/pm/loose-props.css +54 -0
  83. package/workspace/public/pm/loose-props.js +262 -0
  84. package/workspace/public/pm/premium-board.js +65 -30
  85. package/workspace/public/pm/premium-insights.js +42 -24
  86. package/workspace/public/pm/premium-meeting.js +17 -4
  87. package/workspace/public/pm/premium-mtg-present.js +4 -3
  88. package/workspace/public/pm/premium-report-read.js +2 -0
  89. package/workspace/public/pm/premium-vw-mtg.js +15 -7
  90. package/workspace/public/pm/rec-state.js +13 -5
  91. package/workspace/public/pm/rec-tab-core.js +92 -0
  92. package/workspace/public/pm/term-view.js +81 -10
  93. package/workspace/public/pm/view-notes.js +9 -0
  94. package/workspace/public/premium-aud.html +22 -0
  95. package/workspace/public/premium-board.html +2 -0
  96. package/workspace/public/premium-insights.html +2 -1
  97. package/workspace/public/premium-rec.html +30 -0
  98. package/workspace/public/premium.html +1 -0
  99. package/workspace/rec-present-test.js +229 -0
  100. package/workspace/server.js +116 -7
  101. package/workspace/skills/loose-propose.skill +39 -0
  102. package/workspace/task-milestones-test.js +15 -6
  103. package/workspace/test-lists/board-deliveries.json +13 -0
  104. package/workspace/test-lists/calm-timeline.json +5 -0
  105. package/workspace/test-lists/loose-props.json +9 -0
  106. package/workspace/test-lists/milestone-pins.json +6 -0
  107. package/workspace/test-lists/rec-now.json +6 -0
  108. package/workspace/test-lists/rec-present.json +13 -0
  109. package/workspace/test-lists/recording-tab.json +13 -0
  110. package/workspace/timeline-holds-test.js +44 -42
@@ -0,0 +1,262 @@
1
+ /* pm/loose-props.js — Claude's clean-up of Home's "Not in an initiative" (feedback batch 13 item 3, option A; canvas In development, XlcA1Desk,
2
+ * XlcA2After, XlcA3Sheet, XlcA4Pick, and the twelve rules of XlcA0Grill). The fold and the routes are lib/loose-proposals.js and
3
+ * lib/routes-loose.js; the rows the server reads are pm/home-list.js looseSnapshot. Nothing is written before the PM's ✓.
4
+ *
5
+ * sync(M, D, H) after each read of Home: sends what the group shows (only when it changed) and keeps what Claude proposes; H.redraw()
6
+ * when the ✦ changes
7
+ * chipOf() → the ✦ on the group's header: { n, label } | null (hidden at 0: zero is silence)
8
+ * open(H) the ✦'s press: "Claude proposes N" in the Viewer. Groups Link, Tidy and Start an initiative, each proposal with ⌄, ✓ and ✕;
9
+ * a Link row's tile changes its initiative (Claude's pick first, then the PM's initiatives, last "+ New initiative from this
10
+ * row"); ✕ on a row leaves it out (struck, with Undo). ✓ in the header approves every row not left out. An open proposal
11
+ * shows 5 rows, then "+N more". After the first approval a History fold lists each one with its own Undo.
12
+ * closeOne(H, sid) the Home pill menu's ✓ on a session that is idle and safe to close (item 7)
13
+ * The host gives H.toast(text, undo?), H.reload(), H.where() → { ws, board } (the product a new initiative starts in), H.total() → the rows
14
+ * the group shows, H.today() → YYYY-MM-DD. */
15
+ import { pmGet, pmPost } from './http.js';
16
+ import { looseSnapshot } from './home-list.js';
17
+
18
+ const CSS = new URL('./loose-props.css', import.meta.url).href;
19
+ if (typeof document !== 'undefined' && document.head && !document.querySelector(`link[href="${CSS}"]`)) {
20
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = CSS; document.head.appendChild(l);
21
+ }
22
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
23
+ const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
24
+ export const I = {
25
+ spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z',
26
+ check: 'M5 12l5 5 9-10', x: 'M6 6l12 12M18 6L6 18', down: 'M6 9l6 6 6-6', up: 'M6 15l6-6 6 6', undo: 'M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3',
27
+ link: 'M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1',
28
+ merge: 'M8 8h11v11H8zM5 16V5h11', done: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M8 12l3 3 5-6', away: 'M4 5h16v4H4zM5 9v10h14V9M10 13h4',
29
+ start: 'M12 5v14M5 12h14', clock: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 7v5l3 2', repeat: 'M17 2l3 3-3 3M4 11V9a4 4 0 0 1 4-4h12M7 22l-3-3 3-3M20 13v2a4 4 0 0 1-4 4H4',
30
+ chev: 'M7 10l5 5 5-5', plus: 'M12 5v14M5 12h14', power: 'M12 3v8M6.3 6.3a8 8 0 1 0 11.4 0',
31
+ };
32
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
33
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
34
+ const md = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? MON[+m[2] - 1] + ' ' + +m[3] : ''; };
35
+ const ago = (iso, today) => {
36
+ const a = Date.parse(String(iso || '').slice(0, 10) + 'T00:00:00Z'), b = Date.parse(String(today || '').slice(0, 10) + 'T00:00:00Z');
37
+ if (!Number.isFinite(a) || !Number.isFinite(b)) return '';
38
+ const n = Math.max(0, Math.round((b - a) / 864e5));
39
+ return n === 0 ? 'today' : n + ' d ago';
40
+ };
41
+ /** Two letters for an initiative's tile ("IDPF data fixes" → ID, "Tender new CIAM" → TC). */
42
+ export const tileOf = (title) => { const w = String(title || '').trim().split(/[\s_-]+/).filter(Boolean); return (w.length > 1 && w[0].length < 4 ? w[0][0] + w[1][0] : String(w[0] || '?').slice(0, 2)).toUpperCase(); };
43
+ const SHOW = 5; // an open proposal shows 5 rows, then "+N more" (the grill's legacy pile)
44
+
45
+ const S = { props: null, history: [], inis: [], sig: '', H: null, open: new Set(), more: new Set(), out: new Set(), choices: {}, pick: null, busy: false };
46
+
47
+ /* ── reading and the ✦ ── */
48
+ const sigOf = (t) => { let h = 5381; for (let i = 0; i < t.length; i++) h = ((h * 33) ^ t.charCodeAt(i)) >>> 0; return h.toString(36); };
49
+ export async function sync(M, D, H) {
50
+ S.H = H;
51
+ const raw = looseSnapshot(M, D);
52
+ // to the day: a live chat's last output moves every few seconds, and idle is counted in days, so a new minute is not a change to send
53
+ const snap = { ...raw, rows: raw.rows.map((r) => ({ ...r, at: String(r.at || '').slice(0, 10) })) };
54
+ S.inis = snap.inis;
55
+ const sig = sigOf(JSON.stringify(snap));
56
+ const today = H.today ? H.today() : '';
57
+ // the page reads first, and sends what it shows only when the server holds something else: opening Home writes nothing new
58
+ let r = await pmGet('/api/loose-props?today=' + encodeURIComponent(today)).catch(() => null);
59
+ if (!r || r.ok === false) return;
60
+ if ((r.sig || '') !== sig && (snap.rows.length || r.sig)) r = await pmPost('/api/loose-props/rows', { ...snap, sig, today }).catch(() => null);
61
+ if (!r || r.ok === false) return;
62
+ const was = JSON.stringify(chipOf());
63
+ S.props = r.props || null; S.history = r.history || [];
64
+ if (JSON.stringify(chipOf()) !== was && H.redraw) H.redraw();
65
+ if (isShown()) draw();
66
+ }
67
+ export function chipOf() {
68
+ const p = S.props;
69
+ if (!p || !p.n) return null;
70
+ return { n: p.n, label: 'Claude proposes a clean-up of ' + plural(p.n, 'row', 'rows') + '. Open' };
71
+ }
72
+
73
+ /* ── the Viewer ── */
74
+ const VW = () => (typeof window !== 'undefined' ? window.czViewer : null);
75
+ const isShown = () => { const v = VW(), c = v && v.current(); return !!(c && c.id === 'lp'); };
76
+ const ib = (attr, label, icon, cls = '') => `<button type="button" class="lp-ib${cls ? ' ' + cls : ''}" ${attr} aria-label="${esc(label)}" title="${esc(label)}">${SVG(icon, 16, 2.2)}</button>`;
77
+ const iconOf = (p) => ({ ini: I.link, merge: I.merge, finish: I.done, close: I.power, away: I.away, new: I.start }[p.type] || I.link);
78
+ function titleOf(p) {
79
+ const n = p.rows.filter((x) => !S.out.has(x.row)).length;
80
+ if (p.type === 'ini') return 'Link ' + n + ' to ' + (p.data.title || p.data.ini);
81
+ if (p.type === 'merge') return 'Merge ' + plural(n, 'double', 'doubles');
82
+ if (p.type === 'finish') return 'Finish ' + plural(n, 'chat that is done', 'chats that are done');
83
+ if (p.type === 'away') return 'Put away ' + plural(n, 'idle chat', 'idle chats');
84
+ if (p.type === 'close') return 'Close ' + plural(n, 'idle session that is safe', 'idle sessions that are safe');
85
+ return 'Start “' + (p.data.title || 'a new initiative') + '” from ' + n;
86
+ }
87
+ function whyOf(p) {
88
+ if (p.type === 'merge' && p.into) return 'Your item “' + p.into.title + '” stays; the chat with the same name joins it. ' + (p.why && !/^Your item stays/.test(p.why) ? p.why : '');
89
+ if (p.type === 'new') return (p.why ? p.why + ' ' : '') + 'It starts in the first stage of your board.';
90
+ return p.why || '';
91
+ }
92
+ /** The quiet line under a row: what it is, and why it is here. */
93
+ function metaOf(p, x) {
94
+ const today = S.H && S.H.today ? S.H.today() : '';
95
+ if (p.type === 'finish') return md(x.quoteAt) + ': “' + x.quote + '”';
96
+ if (p.type === 'away') return 'Last message ' + (ago(x.at, today) || 'long ago');
97
+ if (p.type === 'close') return [x.ini ? (iniById(x.ini) || {}).title || '' : 'Not in an initiative', x.say].filter(Boolean).join(' · ');
98
+ if (x.kind === 'meeting') return (x.daily || 'Meeting') + ' · links every one from today';
99
+ return [x.kind === 'item' ? 'Your item' : 'Chat', ago(x.at, today), x.waits ? 'waits on you' : '', x.late ? 'late' : ''].filter(Boolean).join(' · ');
100
+ }
101
+ const iniById = (id) => S.inis.find((i) => i.id === id) || null;
102
+ function tileHtml(p, x) {
103
+ if (p.type !== 'ini' && p.type !== 'new') return '';
104
+ const c = S.choices[x.row];
105
+ const title = c ? (c.new ? 'New: ' + x.title : (iniById(c.ini) || {}).title || c.ini) : p.type === 'ini' ? p.data.title || p.data.ini : p.data.title;
106
+ const t = c && c.new ? '+' : tileOf(title);
107
+ const on = S.pick === x.row;
108
+ return `<button type="button" class="lp-tile${c ? ' moved' : ''}${on ? ' on' : ''}" data-lp-tile="${esc(x.row)}" data-lp-p="${esc(p.id)}" aria-haspopup="menu" aria-expanded="${on}" aria-label="${esc('Goes to ' + title + '. Choose another')}" title="${esc(title)}"><b>${esc(t)}</b>${SVG(I.chev, 12, 2.4)}</button>`;
109
+ }
110
+ function rowHtml(p, x) {
111
+ const out = S.out.has(x.row);
112
+ const lead = x.kind === 'meeting' ? `<span class="lp-mk">${SVG(I.clock, 15)}</span>` : x.waits ? '<span class="lp-mk"><i class="lp-dot" role="img" aria-label="Waits on you"></i></span>' : x.late ? '<span class="lp-mk"><i class="lp-late" role="img" aria-label="Late"></i></span>' : '<span class="lp-mk"></span>';
113
+ const meta = out ? 'Left out by you' : metaOf(p, x);
114
+ const act = out ? ib(`data-lp-back="${esc(x.row)}" data-lp-scope="${esc(p.scope)}"`, 'Undo: put it back', I.undo) : ib(`data-lp-out="${esc(x.row)}" data-lp-scope="${esc(p.scope)}"`, 'Leave this one out', I.x);
115
+ return `<div class="lp-r${out ? ' out' : ''}">${lead}<span class="w"><b>${esc(x.title)}</b><small>${x.kind === 'meeting' && x.daily && !out ? SVG(I.repeat, 12, 2) : ''}${esc(meta)}</small></span>${out ? '' : tileHtml(p, x)}${act}</div>`
116
+ + (S.pick === x.row ? pickHtml(p, x) : '');
117
+ }
118
+ /** The picker right under a tile (XlcA4Pick): Claude's pick first, then the PM's initiatives, last a new initiative from this row. */
119
+ function pickHtml(p, x) {
120
+ const c = S.choices[x.row], cur = c ? (c.new ? 'new' : c.ini) : p.type === 'ini' ? p.data.ini : 'start';
121
+ const opt = (id, title, attr, mark) => `<button type="button" role="menuitemradio" aria-checked="${cur === id}" ${attr}><span class="lp-tl">${mark || esc(tileOf(title))}</span><span class="t">${esc(title)}</span>${cur === id ? SVG(I.check, 15, 2.4) : ''}</button>`;
122
+ const first = p.type === 'ini' ? opt(p.data.ini, p.data.title || p.data.ini, `data-lp-to="${esc(p.data.ini)}"`) : opt('start', p.data.title, 'data-lp-to=""');
123
+ const rest = S.inis.filter((i) => i.id !== (p.type === 'ini' ? p.data.ini : '')).map((i) => opt(i.id, i.title, `data-lp-to="${esc(i.id)}"`)).join('');
124
+ return `<div class="lp-pick" role="menu" data-esc-layer aria-label="Where ${esc(x.title)} goes"><p>Claude’s pick</p>${first}${rest ? '<p>Your initiatives</p>' + rest : ''}`
125
+ + `<button type="button" role="menuitemradio" aria-checked="${cur === 'new'}" data-lp-to="+new" class="nw"><span class="lp-tl">${SVG(I.plus, 14, 2.2)}</span><span class="t">New initiative from this row</span></button></div>`;
126
+ }
127
+ function propHtml(p) {
128
+ const op = S.open.has(p.id), all = S.more.has(p.id), rows = all ? p.rows : p.rows.slice(0, SHOW), left = p.rows.length - rows.length;
129
+ return `<div class="lp-p" data-lp="${esc(p.id)}"><div class="lp-ph"><span class="lp-ic">${SVG(iconOf(p), 17)}</span><span class="w"><b>${esc(titleOf(p))}</b>${whyOf(p) ? `<small>${esc(whyOf(p))}</small>` : ''}</span>`
130
+ + ib(`data-lp-fold="${esc(p.id)}" aria-expanded="${op}"`, op ? 'Hide the rows' : 'Show the rows', op ? I.up : I.down)
131
+ + ib(`data-lp-keep="${esc(p.id)}"`, 'Approve', I.check, 'ok') + ib(`data-lp-drop="${esc(p.id)}"`, 'Drop it', I.x) + '</div>'
132
+ + (op ? `<div class="lp-rows">${rows.map((x) => rowHtml(p, x)).join('')}${left > 0 ? `<button type="button" class="lp-more" data-lp-more="${esc(p.id)}">+${left} more</button>` : ''}</div>` : '')
133
+ + '</div>';
134
+ }
135
+ const SECTION = { link: 'Link', tidy: 'Tidy', start: 'Start an initiative' };
136
+ function histHtml() {
137
+ const h = S.history || [];
138
+ if (!h.length) return '';
139
+ const when = (iso) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? '' : md(iso.slice(0, 10)) + ' ' + String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
140
+ return `<details class="lp-hist"><summary>History</summary>${h.map((x) => `<div class="lp-hr${x.undone ? ' undone' : ''}"><span class="w"><b>${esc(x.said || plural(x.n, 'row placed', 'rows placed'))}</b><small>${esc(when(x.at))}${x.undone ? ' · undone' : ''}</small></span>`
141
+ + (x.undone ? '' : ib(`data-lp-undo="${esc(x.batch)}"`, 'Undo this approval', I.undo)) + '</div>').join('')}</details>`;
142
+ }
143
+ function bodyHtml() {
144
+ const P = S.props;
145
+ if (!P || !P.n) return `<div class="lp">${P && P.looking ? '<p class="lp-intro">Claude is looking at the rows now. Its proposals show here.</p>' : '<p class="lp-intro">Nothing to clean up now.</p>'}${histHtml()}</div>`;
146
+ const total = Math.max(S.H && S.H.total ? S.H.total() : 0, P.total || 0, P.n), rest = total - P.n;
147
+ const intro = plural(total, 'row sits', 'rows sit') + ' outside an initiative. ' + (rest > 0 ? 'I can place ' + P.n + '; the other ' + rest + ' stay where they are.' : 'I can place ' + (P.n === 1 ? 'it' : 'all ' + P.n) + '.') + ' The tick at the top approves all.';
148
+ const secs = P.groups.map((g) => `<section class="lp-sec" aria-label="${esc(SECTION[g.group])}"><h4>${esc(SECTION[g.group])}</h4>${g.props.map(propHtml).join('')}</section>`).join('');
149
+ return `<div class="lp"><p class="lp-intro">${esc(intro)}</p>${secs}${histHtml()}</div>`;
150
+ }
151
+ const presses = () => (S.props && S.props.n ? [{ act: 'all', label: 'Approve all ' + S.props.n, icon: I.check, solid: true }] : []);
152
+ function draw() {
153
+ const v = VW(), b = v && v.body(), c = v && v.current();
154
+ if (!b || !c || c.id !== 'lp') return;
155
+ const top = b.scrollTop, hist = b.querySelector('.lp-hist'), histOpen = !!(hist && hist.open);
156
+ b.innerHTML = bodyHtml();
157
+ b.scrollTop = top;
158
+ if (histOpen) { const h = b.querySelector('.lp-hist'); if (h) h.open = true; }
159
+ v.setPresses(c.id, presses());
160
+ const t = 'Claude proposes' + (S.props && S.props.n ? ' ' + S.props.n : '');
161
+ if (c.title !== t && v.retitle) v.retitle(c.id, t);
162
+ }
163
+ const say = (m, undo) => { if (S.H && S.H.toast) S.H.toast(m, undo); };
164
+ async function after(r) {
165
+ if (r && r.props !== undefined) { S.props = r.props || null; S.history = r.history || S.history; }
166
+ draw();
167
+ if (S.H && S.H.reload) await Promise.resolve(S.H.reload()).catch(() => {});
168
+ }
169
+ async function keep(ids, all) {
170
+ if (S.busy) return;
171
+ S.busy = true;
172
+ const at = S.H && S.H.where ? S.H.where() : null, today = S.H && S.H.today ? S.H.today() : undefined;
173
+ const res = await pmPost('/api/loose-props/keep', { ...(all ? { all: true } : { ids }), out: [...S.out], choices: S.choices, ...(at ? { where: at } : {}), today }).catch(() => null);
174
+ S.busy = false;
175
+ if (!res || res.ok === false) { say((res && res.error) || 'Nothing was placed.'); return; }
176
+ S.choices = {}; S.pick = null;
177
+ const batch = res.batch;
178
+ say(res.said + (res.warn ? '. ' + res.warn : ''), async () => {
179
+ const u = await pmPost('/api/loose-props/undo', { batch, today }).catch(() => null);
180
+ if (!u || u.ok === false) return { ok: false, error: (u && u.error) || 'The undo did not land.' };
181
+ if (u.kept) say(plural(u.kept, 'change was', 'changes were') + ' kept: a started initiative stays on the Board.');
182
+ await after(u);
183
+ return { ok: true };
184
+ });
185
+ await after(res);
186
+ if (!S.props || !S.props.n) { const v = VW(); if (v && isShown()) v.close(); }
187
+ }
188
+ /** The pill menu's ✓ on one session (batch 13 item 7, canvas XcsA1Pill): closes it if it is still idle and safe; the toast has Undo. */
189
+ export async function closeOne(H, sid) {
190
+ S.H = H;
191
+ const today = H && H.today ? H.today() : undefined;
192
+ const res = await pmPost('/api/loose-props/close', { sid, today }).catch(() => null);
193
+ if (!res || res.ok === false) { say((res && res.error) || 'The session was not closed.'); if (H && H.reload) await Promise.resolve(H.reload()).catch(() => {}); return; }
194
+ const batch = res.batch;
195
+ say(res.said, async () => {
196
+ const u = await pmPost('/api/loose-props/undo', { batch, today }).catch(() => null);
197
+ if (!u || u.ok === false) return { ok: false, error: (u && u.error) || 'The undo did not land.' };
198
+ await after(u);
199
+ return { ok: true };
200
+ });
201
+ await after(res);
202
+ }
203
+ async function onPress(e) {
204
+ const b = e.target.closest('button'); if (!b) { if (S.pick && !e.target.closest('.lp-pick')) { S.pick = null; draw(); } return; }
205
+ const d = b.dataset;
206
+ if (d.lpFold) { if (S.open.has(d.lpFold)) S.open.delete(d.lpFold); else S.open.add(d.lpFold); draw(); return; }
207
+ if (d.lpMore) { S.more.add(d.lpMore); draw(); return; }
208
+ if (d.lpTile) { S.pick = S.pick === d.lpTile ? null : d.lpTile; draw(); const m = VW().body().querySelector('.lp-pick [aria-checked="true"]') || VW().body().querySelector('.lp-pick button'); if (m) m.focus(); return; }
209
+ if ('lpTo' in d) {
210
+ const row = S.pick, p = (S.props.groups || []).flatMap((g) => g.props).find((x) => x.rows.some((y) => y.row === row));
211
+ if (row && p) {
212
+ const v = d.lpTo;
213
+ if (v === '+new') { const at = S.H && S.H.where ? S.H.where() : {}; const own = iniById(p.data.ini) || {}; S.choices[row] = { new: true, ws: own.ws || at.ws, board: own.board || at.board, anchor: own.anchor || '' }; }
214
+ else if (!v || (p.type === 'ini' && v === p.data.ini)) delete S.choices[row];
215
+ else { const i = iniById(v) || { id: v }; S.choices[row] = { ini: i.id, title: i.title, ...(i.ws ? { ws: i.ws } : {}) }; }
216
+ }
217
+ S.pick = null; draw(); return;
218
+ }
219
+ if (d.lpKeep) { await keep([d.lpKeep], false); return; }
220
+ if (d.lpDrop) {
221
+ const p = (S.props.groups || []).flatMap((g) => g.props).find((x) => x.id === d.lpDrop); if (!p) return;
222
+ b.disabled = true;
223
+ const r = await pmPost('/api/loose-props/drop', { scope: p.scope, rows: p.rows.map((x) => x.row) }).catch(() => null);
224
+ if (!r || r.ok === false) { b.disabled = false; say((r && r.error) || 'Nothing was changed.'); return; }
225
+ await refresh(); return;
226
+ }
227
+ if (d.lpOut || d.lpBack) {
228
+ const row = d.lpOut || d.lpBack, back = !!d.lpBack;
229
+ b.disabled = true;
230
+ const r = await pmPost('/api/loose-props/' + (back ? 'undrop' : 'drop'), { scope: d.lpScope, rows: [row] }).catch(() => null);
231
+ if (!r || r.ok === false) { b.disabled = false; say((r && r.error) || 'Nothing was changed.'); return; }
232
+ // the row stays drawn, struck, until the Viewer closes: Undo puts it back (XlcA1Desk)
233
+ if (back) S.out.delete(row); else { S.out.add(row); delete S.choices[row]; }
234
+ draw(); return;
235
+ }
236
+ if (d.lpUndo) {
237
+ b.disabled = true;
238
+ const r = await pmPost('/api/loose-props/undo', { batch: d.lpUndo, today: S.H && S.H.today ? S.H.today() : undefined }).catch(() => null);
239
+ if (!r || r.ok === false) { b.disabled = false; say((r && r.error) || 'The undo did not land.'); return; }
240
+ say(r.kept ? 'Undone. ' + plural(r.kept, 'change was', 'changes were') + ' kept: a started initiative stays on the Board.' : 'Undone.');
241
+ await after(r);
242
+ }
243
+ }
244
+ async function refresh() {
245
+ const r = await pmGet('/api/loose-props?today=' + encodeURIComponent(S.H && S.H.today ? S.H.today() : '')).catch(() => null);
246
+ if (r && r.ok) { S.props = r.props || null; S.history = r.history || []; }
247
+ draw();
248
+ if (S.H && S.H.redraw) S.H.redraw();
249
+ }
250
+ /** The ✦'s press. */
251
+ export function open(H) {
252
+ const v = VW(); if (!v) return;
253
+ if (H) S.H = H;
254
+ S.out = new Set(); S.choices = {}; S.pick = null; S.more = new Set();
255
+ // the first proposal opens, so its rows read at once (XlcA1Desk); the rest stay folded until pressed
256
+ const first = S.props && S.props.groups && S.props.groups[0] && S.props.groups[0].props[0];
257
+ S.open = new Set(first ? [first.id] : []);
258
+ v.open({ id: 'lp', kind: 'Claude proposes', title: 'Claude proposes' + (S.props && S.props.n ? ' ' + S.props.n : ''), icon: I.spark, presses: presses(),
259
+ onPress: (act) => { if (act === 'all') keep([], true); },
260
+ render: (b) => { b.onclick = onPress; b.onkeydown = (e) => { if (e.key === 'Escape' && S.pick) { e.stopPropagation(); S.pick = null; draw(); } }; draw(); },
261
+ onClose: () => { S.out = new Set(); S.pick = null; if (S.H && S.H.redraw) S.H.redraw(); } });
262
+ }
@@ -19,10 +19,12 @@
19
19
  * Where no record holds a value for an initiative, the element says so: nothing is invented. */
20
20
  import { pmPost } from './http.js';
21
21
  import { followDoc } from './doc-follow.js';
22
- import { $, $$, esc, store, crumbHtml, wireCrumb, chatAbout, setPageGaps } from './premium-shell.js';
22
+ import { $, $$, esc, store, chatAbout, setPageGaps } from './premium-shell.js';
23
+ import * as PK from './cozy-pick.js'; // the one product picker Home, Board and Insights share (batch 12 item 5)
23
24
  import { mountNav } from './cozy-nav.js';
24
25
  import { mountLivePill } from './cozy-live-pill.js';
25
26
  import { stepsHelpHtml } from './bd-stages.js';
27
+ import { msMode } from './bd-pins.js';
26
28
  import { timelineHtml, legendHtml, hasHold, planKeys, gapKeys, plainGaps, skipsOf, skipWords, gapWords, SPANS, md } from './bd-span.js';
27
29
  import * as TL from './bd-scroll.js';
28
30
  import * as Acts from './bd-acts.js';
@@ -39,6 +41,7 @@ import * as SM from './split-merge.js'; // split one initiative in two, or mer
39
41
  import * as PM from './prog-move.js'; // move an initiative out of its program, or to another (canvas LpA1More, LpA2Other)
40
42
  import * as Pop from './bd-pop.js'; // the order of a program's initiatives: the grip and Claude's order from the dates (canvas RoADrag, RoASuggest)
41
43
  import * as BI from './bd-ini-panel.js';
44
+ import * as DL from './bd-deliveries.js'; // the Deliveries lane under the timeline's axis (batch 13 item 4, XcalmA6Lane)
42
45
  import { nextHtml } from './bd-next.js';
43
46
  import { statusOf as ivStatus } from './ini-view-model.js';
44
47
  import { initiativeRename, taskRename } from './rename-press.js';
@@ -58,9 +61,14 @@ const F = { chips: new Set(), q: '', owners: new Set(), cats: new Set(), sprints
58
61
  let GR = {}; // the first questions still open per initiative (GET /api/board-grill?ids=): { [id]: { open, total, later } }
59
62
  let PGS = []; // the programs (GET /api/programs): every view groups the rows a program holds under it (PgBoard)
60
63
  let XR = {}; // the other products' rows a program here holds, read once (GET /api/board-premium?ws=): { [ws]: { name, rows } }
61
- // the products picked (batch 11 item 7): ?all=1 every product, ?pick=<ws>|<board> repeated several, else one board
62
- const PICK = new URLSearchParams(location.search).getAll('pick').filter((x) => /\|/.test(x));
63
- const ALL = new URLSearchParams(location.search).get('all') === '1' || PICK.length > 1; // All products, or several: their boards on one page (PgBoard)
64
+ // the boards shown: the one product pick Home and Insights share (batch 12 item 5, saved, never in the address), read at the first load
65
+ // (resolvePick). A link with ?ws=&board= (or the older ?all=1, ?pick=<ws>|<board>) is a one-off view: it shows that and leaves the pick alone.
66
+ const Q0 = new URLSearchParams(location.search);
67
+ let PICK = Q0.getAll('pick').filter((x) => /\|/.test(x));
68
+ let ALL = Q0.get('all') === '1' || PICK.length > 1; // All products, or several: their boards on one page (PgBoard)
69
+ const DEEP = ALL || PICK.length > 0 || Q0.has('ws') || Q0.has('board');
70
+ let ONE = null; // the one ticked product's board, 'ws|id', when the pick holds one
71
+ let PKP = null, picked = false; // the saved pick (GET /api/briefing-premium/products), and whether it has been turned into boards
64
72
  let byProduct = store.get(GROUPING_KEY) === 'product'; // the grouping: programs first (default) or By product (PgBoardProduct)
65
73
  let DM = {}; // the documents' history (GET /api/board-docs): { [path]: { changed, by, log } }
66
74
  let peek = null; // what the Viewer shows for the Board: { kind: 'ini', key } an initiative or its ticket, { kind: 'acts' } an acts panel
@@ -138,27 +146,50 @@ function say(msg, undo) {
138
146
  clearTimeout(toastT); toastT = setTimeout(() => { t.hidden = true; }, undo ? 10000 : 5000);
139
147
  }
140
148
 
149
+ /* ── the product chip (batch 12 item 5, canvas XhpA5Pages): the same chip and list as Home's; it replaces "pmos-idpf +1" ── */
150
+ /** The pick as this page shows it: the saved one, or for a one-off link the products on screen. */
151
+ function shownPick() {
152
+ if (!PKP) return null;
153
+ if (!DEEP) return PKP;
154
+ const ws = new Set(M.board.all ? (M.board.products || []).map((p) => p.ws) : [M.board.ws]);
155
+ return { ...PKP, products: PKP.products.map((p) => ({ ...p, on: ws.has(p.ws) })) };
156
+ }
157
+ function drawPick() {
158
+ const P = shownPick(), host = $('#crumbHost'); if (!host) return;
159
+ host.innerHTML = P ? PK.chipHtml(P, { id: 'bdPick', label: 'Products' }) : `<span class="crpg">${esc(M.board.name || 'Board')}</span>`;
160
+ const chip = $('#bdPick'); if (!chip) return;
161
+ // a product's line: its open initiatives on this page (zero is silence)
162
+ const lines = (ws) => { const rows = (M.initiatives.list.rows || []).filter((r) => (M.board.all ? r.ws === ws : M.board.ws === ws)); return rows.length ? rows.length + (rows.length === 1 ? ' initiative' : ' initiatives') : ''; };
163
+ chip.onclick = (e) => { e.stopPropagation(); PK.openPicker(chip, { P: shownPick(), label: 'Products', lines, note: 'One pick for Home, Board and Insights: unticking a product here also takes it off Home.', onApply: async (on) => { const r = await PK.savePick(on); if (!r.ok) say(r.error); } }); };
164
+ }
165
+ // a saved pick (this chip, or Settings): the Board opens on the ticked products, without a one-off link's ws or board
166
+ addEventListener('pp:changed', () => { const q = new URLSearchParams(location.search); ['ws', 'board', 'all', 'pick'].forEach((k) => q.delete(k)); const s = q.toString(); location.assign(location.pathname + (s ? '?' + s : '')); });
167
+ /** Turn the saved pick into the boards to read: every product's board (All), several (PICK), one (ONE) or the default board. false while the
168
+ * default board is still being read (its switcher lists the boards). A one-off link keeps its own. */
169
+ async function resolvePick() {
170
+ if (picked) return true;
171
+ if (!PKP) PKP = await PK.readPick();
172
+ if (DEEP || !PKP) { picked = true; return true; }
173
+ const h = await readBoard('');
174
+ if (h.r && h.r.state === 'reading') return false;
175
+ picked = true;
176
+ const sw = (h.r && h.r.ok && h.r.model && h.r.model.board.switcher) || null;
177
+ if (!sw) return true; // one board: nothing to pick between
178
+ const on = new Set(PKP.products.filter((p) => p.on).map((p) => p.ws)), keys = sw.filter((b) => on.has(b.ws)).map((b) => b.ws + '|' + b.id);
179
+ if (!keys.length) return true;
180
+ if (keys.length === sw.length) { ALL = true; PICK = []; return true; }
181
+ if (keys.length === 1) { ONE = keys[0]; return true; }
182
+ PICK = keys; ALL = true;
183
+ return true;
184
+ }
185
+
141
186
  /* ── the toolbar: picker, chips ───────────────────────────────────────────────────────────────────────────────────── */
142
187
  let crumbed = false;
143
188
  function drawHead() {
144
189
  if (!crumbed) {
145
190
  crumbed = true;
146
- // the picker: All products first when there is more than one product, then each product's board
147
- const list = M.board.switcher || [], boards = list.length > 1 ? [{ ws: '*', id: '*', name: 'All products' }, ...list] : list;
148
- // the button says it once: All products, the one product, or the first product and "+N" (several)
191
+ drawPick();
149
192
  const names = (M.board.products || []).map((p) => p.name), some = ALL && PICK.length > 1;
150
- const label = some ? esc(names[0] || 'Products') + ' <b>+' + (names.length - 1) + '</b>' : esc(M.board.name || 'Board');
151
- $('#crumbHost').innerHTML = crumbHtml({ page: '', board: M.board.name || 'Board', boards });
152
- $('#crBoard').innerHTML = label;
153
- // several products can be ticked (batch 11 item 7); the pick goes into the address, so a reload keeps it
154
- const picked = !ALL ? [M.board.ws + '|' + M.board.id] : (M.board.products || []).map((p) => p.ws + '|' + p.id);
155
- const goBoard = (ws, id) => location.assign(id === '*' ? '/premium-board.html?all=1' : '/premium-board.html?ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(id));
156
- wireCrumb({ boards, board: ALL ? '*' : M.board.id, goBoard, picked: list.length > 1 ? picked : null, goPicked: (keys) => {
157
- if (keys.length === list.length) return goBoard('*', '*');
158
- if (keys.length === 1) { const [ws, id] = keys[0].split('|'); return goBoard(ws, id); }
159
- location.assign('/premium-board.html?' + keys.map((k) => 'pick=' + encodeURIComponent(k)).join('&'));
160
- } });
161
- $('#crBoard').setAttribute('aria-label', 'Product: ' + (some ? names.join(', ') : M.board.name || 'Board'));
162
193
  chatAbout('board:this-board', some ? 'the ' + names.join(', ') + ' boards' : ALL ? 'all products' : M.board.name ? 'the ' + M.board.name + ' board' : 'this board');
163
194
  }
164
195
  $('#snap').textContent = M.header.text;
@@ -397,9 +428,10 @@ function drawTrack(L) {
397
428
  /* ── the timeline (AgBoardTimeline; TsCOpen, TsCDesk, TsAllSpans, TsCPhone) ───────────────────────────────────────── */
398
429
  function drawTime(L) {
399
430
  const S = M.steps || [], phone = PHONE.matches, bw = $('#ibBody').clientWidth || innerWidth;
400
- const T = timelineHtml(L, M, span, { groups: groups(L), progState, folded: PG.folded, prodHtml: (g) => PG.prodHtml(g, 'tg-prd'), prodCell: (g) => PG.prodCell(g), subHtml: (n) => PG.subHtml(n, 'tg-psb'), progTile: () => PG.progTile(), productsOf: PG.productsOf,
431
+ const T = timelineHtml(L, M, span, { groups: groups(L), progState, folded: PG.folded, prodHtml: (g) => PG.prodHtml(g, 'tg-prd'), prodCell: (g, dots) => PG.prodCell(g, dots), msMode: msMode(), subHtml: (n) => PG.subHtml(n, 'tg-psb'), progTile: () => PG.progTile(), productsOf: PG.productsOf,
401
432
  foldBtn: (g) => PG.foldBtn(g.key, g.program.title), memberIcon: (id) => PG.memberIcon(PGS, id), sel: peek && peek.kind !== 'acts' ? peek.key : null, status: statusOf, phone, trackPx: bw - 2 - (phone ? 0 : matchMedia('(max-width: 980px)').matches ? 180 : 250), avatar: (n) => V.avatar(n, 'sm'),
402
- askHref: (none) => askHref(null, 'Propose start and end dates for ' + none.map((r) => r.title).join(', ')) });
433
+ askHref: (none) => askHref(null, 'Propose start and end dates for ' + none.map((r) => r.title).join(', ')),
434
+ lane: (c) => DL.laneHtml(c, { span, progState }) });
403
435
  return T.html;
404
436
  }
405
437
  /** A phone's view switch (BdPhone): List, By stage, the stage track and the timeline (TsCPhone: it scrolls sideways like the desktop's). */
@@ -487,12 +519,12 @@ $('#ibBody').addEventListener('click', (e) => {
487
519
  const op = e.target.closest('[data-open]'); if (op) { Acts.open[op.dataset.open](op); return; }
488
520
  const st = e.target.closest('[data-steps]'); if (st) { togglePop('popSteps', st); return; }
489
521
  const tk = e.target.closest('[data-tk]'); if (tk) { openTicket(tk.dataset.ini, tk.dataset.tk, tk); return; }
490
- if (e.target.closest('[data-act], [data-hold]')) return; // pm/bd-acts.js handles its own presses (a ⏸ on the timeline opens its hold there)
522
+ if (e.target.closest('[data-act], [data-hold], [data-ms-pick]')) return; // pm/bd-acts.js handles its own presses (a ⏸ on the timeline opens its hold there; a ◇ its milestones, pm/bd-pin-card.js)
491
523
  const pg = e.target.closest('[data-prog]'); if (pg) { PG.openProgram(pg.dataset.prog, pg); return; }
492
524
  // a counted milestone ◇ lists its milestones right under it; on a phone the row's bar lane opens them in a sheet (batch 11 item 3)
493
525
  const mc = e.target.closest('[data-ms-row]'); if (mc) { msPop(mc, rowOf(mc.dataset.msRow), mc.dataset.msIds.split(' ')); return; }
494
526
  // a product lane's counted ◇ lists its milestones with their initiatives; on a phone a tap on the lane lists them all in a sheet (batch 11 item 17)
495
- const ml = e.target.closest('[data-ms-lane]'); if (ml) { lanePop(ml, ml.dataset.msLane); return; }
527
+ const ml = e.target.closest('[data-ms-lane]'); if (ml) { lanePop(ml, ml.dataset.msLane, ml.dataset.laneName); return; }
496
528
  const pl = PHONE.matches && e.target.closest('.tgq-r.tg-lane > .tg-p[data-lane-ms]'); if (pl) { lanePop(pl, pl.dataset.laneMs, pl.dataset.laneName); return; }
497
529
  // a gap's press (batch 11 item 13): its words, and + New task with its dates while part of it is ahead
498
530
  const gp = e.target.closest('[data-gap]'); if (gp) { gapPop(gp, rowOf(gp.dataset.gap)); return; }
@@ -500,6 +532,7 @@ $('#ibBody').addEventListener('click', (e) => {
500
532
  const lane = PHONE.matches && e.target.closest('.tgq-r[data-row] > .tg-p'); if (lane) { const r = rowOf(lane.parentElement.dataset.row); if (r && ((r.milestones || []).length || plainGaps(r).length || skipsOf(r).length)) { msPop(lane, r, null, true); return; } }
501
533
  const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key), b, view === 'time' ? 'time' : 'track');
502
534
  });
535
+ DL.wire($('#ibBody'), { redraw: () => drawInit() }); // the Deliveries lane: hover links the row, the fold is remembered
503
536
  $('#ibBody').addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target.matches('[data-steps]')) { e.preventDefault(); togglePop('popSteps', e.target); } });
504
537
  /* By stage (BdByStage): a card dragged to another column moves the initiative there (POST /api/boards/move), with Undo in the toast. The column is
505
538
  * one of the eight steps; the move goes to the first of the board's own stages that maps onto it. */
@@ -881,15 +914,17 @@ async function readAll(q) {
881
914
  return { r: { ok: true, model, stale: got.some((g) => g.r && g.r.stale) || h.r.stale }, status: 200 };
882
915
  }
883
916
  async function load() {
884
- const p = new URLSearchParams(location.search), [pw, pb] = PICK.length > 1 ? PICK[0].split('|') : [p.get('ws'), p.get('board')], q = [pw ? 'ws=' + encodeURIComponent(pw) : '', pb ? 'board=' + encodeURIComponent(pb) : ''].filter(Boolean).join('&');
885
- const { r, status } = ALL ? await readAll(q) : await readBoard(q);
886
- clearInterval(readTimer);
887
- if (r && r.state === 'reading') {
917
+ // while the board is read (the pick's default board, then the picked ones) the page says so and shows no row instead of a guess
918
+ const reading = () => {
888
919
  const t0 = Date.now(), tick = () => { const s = 'Reading the board · ' + Math.round((Date.now() - t0) / 1000) + ' s so far'; $('#snap').textContent = s; if (!M) $('#ibBody').innerHTML = `<p class="bd-msg"><b>${esc(s)}</b> The board derives each initiative from its records. This page shows nothing until it has read, rather than guess.</p>`; };
889
920
  tick(); readTimer = setInterval(tick, 1000);
890
921
  setTimeout(load, 3000);
891
- return;
892
- }
922
+ };
923
+ if (!(await resolvePick())) { clearInterval(readTimer); reading(); return; }
924
+ const p = new URLSearchParams(location.search), [pw, pb] = PICK.length > 1 ? PICK[0].split('|') : ONE ? ONE.split('|') : [p.get('ws'), p.get('board')], q = [pw ? 'ws=' + encodeURIComponent(pw) : '', pb ? 'board=' + encodeURIComponent(pb) : ''].filter(Boolean).join('&');
925
+ const { r, status } = ALL ? await readAll(q) : await readBoard(q);
926
+ clearInterval(readTimer);
927
+ if (r && r.state === 'reading') { reading(); return; }
893
928
  if (!r || !r.ok) {
894
929
  $('#snap').textContent = 'The board could not be read';
895
930
  if (!M) $('#ibBody').innerHTML = `<p class="bd-msg err" role="alert"><b>The board could not be read</b>, so this page shows nothing rather than guess.${r && r.error ? ' The reason: ' + esc(r.error) : status ? ' The server answered ' + status + '.' : ' The server did not answer.'}</p>`;
@@ -988,7 +1023,7 @@ V.init({ M: () => M, wf: wfState, statusOf, usual: usualOf, trail: TI, docMeta,
988
1023
  Asks.init({ M: () => M, load, say, panel: actsPanel, close: closePanel, rowOf, openIni: openIniAny, openDoc: viewDoc, anchors, programs: () => PGS, reloadPrograms: loadPrograms });
989
1024
  Acts.init({ M: () => M, wf: wfState, load, say, panel: actsPanel, close: closePanel, redraw: () => { drawChips(); drawInit(); if (tab === 'docs') drawDocs(); }, F, rowOf, statusOf, openIni: openIniAny,
990
1025
  openTicket: (ini, tk) => openTicket(ini, tk, $('#bdFind')), askHref, pageHref, trail: TI, docMeta, loadDocMeta, viewDoc,
991
- grouping: () => ({ on: groupingOn(), byProduct }), setGrouping, sprintFilter: sprintFilterOn });
1026
+ grouping: () => ({ on: groupingOn(), byProduct }), setGrouping, sprintFilter: sprintFilterOn, timeline: () => curView() === 'time' });
992
1027
  BI.mount({ M: () => M, statusOf, dayTitle, usual: usualOf, fmt, md, ago, segHtml, barHtml: V.barHtml, grill: (id) => GR[id], rowOf, pageHref, askHref, refreshJira: () => refreshJira(), viewDoc,
993
1028
  send: (r) => import('./tk-send.js').then((S) => S.openSend({ ws: r.ws || M.board.ws || null, board: r.boardId || M.board.id, initiative: r.id, toast: say })),
994
1029
  acts: (r, b) => Acts.open.row(r, b), hold: (r, i, b) => Acts.open.hold(r, i, b), grillOpen: (r, b) => Asks.openGrill(r.id, r.title, (r.track && r.track.label) || 'Triage', false, b), onShow: iniShown, onHide: iniHidden,
@@ -16,13 +16,15 @@
16
16
  * POST /api/insights-records/tile. A tile goes amber only after two readings past its target. "Delivery trends" is also a view.
17
17
  * IsLibrary Found in your work as cards (Set it up, Not a report with Undo), the reports as Report · Next · Status, and a report's setup in the
18
18
  * Viewer card (Setup, Issues, Brief); a request from Home with Set it up, Change it and Cancel. New report hands off to Home.
19
- * IsMenus the product picker (each product's goal count, Portfolio rolls the goals of every product up), the Dashboard menu, Find (goals,
19
+ * IsMenus the product chip (the one pick Home and Board share, batch 12 item 5: one ticked = that product; several = Portfolio, their
20
+ * goals rolled up and grouped by product), the Dashboard menu, Find (goals,
20
21
  * reports and dashboards), Filter (status, owner, kind), ⋯ (Sources, Export, About) and the empty trend of a goal with one reading.
21
22
  * IsPhone the goal detail full screen with Readings, Moved by and Dashboards; a report setup as a sheet.
22
23
  * window.czViewer is feature-detected, with this page's side panel as the fallback. A report file opens in the report reader
23
24
  * (pm/premium-report-read.js), the report panel in the Viewer card. The page has no #dlg. */
24
25
  import { $, $$, esc, toast, wireRail, setPageGaps } from './premium-shell.js';
25
26
  import { pmPost } from './http.js';
27
+ import * as PK from './cozy-pick.js'; // the one product picker Home, Board and Insights share (batch 12 item 5)
26
28
  import { openReport } from './premium-report-read.js';
27
29
  import { mountNav } from './cozy-nav.js';
28
30
  import { mountLivePill } from './cozy-live-pill.js';
@@ -34,7 +36,11 @@ let tab = 'goals';
34
36
  let per = null; // the period { key, label, name, from, to }
35
37
  let find = '';
36
38
  let filt = { status: [], owner: [], kind: [] }; // the Filter (IsMenus): each group holds the chips that are on
37
- let PF = null; // Portfolio (IsMenus): { goals, charts, products } rolled up from every product's model, or null
39
+ let PF = null; // Portfolio (IsMenus): { goals, charts, products } rolled up from the ticked products' models, or null
40
+ // the products shown: the one saved pick (GET /api/briefing-premium/products). A link with ?ws= or ?board= is a one-off view of that product.
41
+ const DEEP = new URLSearchParams(location.search).has('ws') || new URLSearchParams(location.search).has('board');
42
+ let PKP = null;
43
+ const pickedWs = () => (PKP && !DEEP ? PKP.products.filter((p) => p.on).sort((a, b) => (b.primary ? 1 : 0) - (a.primary ? 1 : 0)).map((p) => p.ws) : []); // the default workspace first
38
44
  let loadedAt = 0;
39
45
  let selecting = false; let picked = []; // New dashboard: the goals picked in the table, in order
40
46
  wireRail('rep');
@@ -72,7 +78,7 @@ const closeViewer = () => { if (window.czViewer && typeof window.czViewer.close
72
78
  // The Viewer floats over the page (XvAInsight); the page does not move for it.
73
79
 
74
80
  /* ── small menus: one open at a time, Escape and an outside press close it ─────────────────────────────────────────────────────── */
75
- const MENUS = [['#prodPick', '#prodMenu'], ['#viewChip', '#viewMenu'], ['#perChip', '#perMenu'], ['#filtB', '#filtMenu'], ['#newB', '#newMenu'], ['#moreB', '#moreMenu']];
81
+ const MENUS = [['#viewChip', '#viewMenu'], ['#perChip', '#perMenu'], ['#filtB', '#filtMenu'], ['#newB', '#newMenu'], ['#moreB', '#moreMenu']];
76
82
  function menu(btn, box, open) { $(box).hidden = !open; $(btn).setAttribute('aria-expanded', String(open)); }
77
83
  function closeMenus(except) { for (const [b, m] of MENUS) if (m !== except && !$(m).hidden) menu(b, m, false); const cm = $('#chMenu'); if (cm) cm.hidden = true; if (!$('#findRow').hidden) closeFind(false); }
78
84
  for (const [b, m] of MENUS) {
@@ -156,12 +162,7 @@ const curDash = () => M.dashboards.find((d) => d.id === dash) || M.dashboards[0]
156
162
  const dashName = (D) => (D.id === 'all' ? 'All goals' : D.name);
157
163
  const nGoals = (k) => k + (k === 1 ? ' goal' : ' goals');
158
164
  function drawBar() {
159
- $('#prodName').textContent = PF ? 'Portfolio' : M.board.name || 'Insights';
160
- const boards = M.board.switcher || [];
161
- /* the product picker: each product with its goal count, then Portfolio, which rolls every product's goals up */
162
- $('#prodMenu').innerHTML = '<p class="ins-mh">Product</p>' + (boards.length ? boards.map((b) => `<button type="button" role="menuitemradio" aria-checked="${!PF && b.id === M.board.id && b.ws === M.board.ws}" data-ws="${esc(b.ws)}" data-board="${esc(b.id)}">${esc(b.name)}<span class="k">${b.goals != null ? esc(nGoals(b.goals)) : ''}</span></button>`).join('')
163
- : '<p class="note ins-mnote">One product is registered.</p>')
164
- + (boards.length > 1 ? `<div class="ins-hr"></div><button type="button" role="menuitemradio" aria-checked="${!!PF}" data-portfolio>Portfolio · all products</button><p class="note ins-mnote">Portfolio rolls goals up across products.</p>` : '');
165
+ drawPick();
165
166
  $('#nGoals').textContent = String(dash === TRENDS ? 0 : goalsShown().length);
166
167
  $('#nOutcomes').textContent = String(outcomesShown().length);
167
168
  const D = curDash();
@@ -172,12 +173,22 @@ function drawBar() {
172
173
  + `<div class="ins-hr"></div><button type="button" role="menuitem" data-newdash>${SV(I.plus)}New dashboard</button>`;
173
174
  drawPeriod(); drawFilter();
174
175
  }
175
- $('#prodMenu').addEventListener('click', (e) => {
176
- if (e.target.closest('[data-portfolio]')) { closeMenus(); if (!PF) openPortfolio(); return; }
177
- const b = e.target.closest('[data-board]'); if (!b) return;
178
- if (PF && b.dataset.ws === M.board.ws && b.dataset.board === M.board.id) { closeMenus(); PF = null; redraw(); return; }
179
- location.assign('/premium-insights.html?ws=' + encodeURIComponent(b.dataset.ws) + '&board=' + encodeURIComponent(b.dataset.board));
180
- });
176
+ /* the product chip (canvas XhpA5Pages): the same chip and list as Home's. It replaces the one-product menu and "Portfolio · all products" */
177
+ function shownPick() {
178
+ if (!PKP) return null;
179
+ if (!DEEP) return PKP;
180
+ return { ...PKP, products: PKP.products.map((p) => ({ ...p, on: p.ws === M.board.ws })) }; // a one-off link: the product on screen
181
+ }
182
+ function drawPick() {
183
+ const P = shownPick(), host = $('#prodHost');
184
+ host.innerHTML = P ? PK.chipHtml(P, { id: 'prodPick', label: 'Products' }) : `<span class="ins-ttl">${esc(M.board.name || 'Insights')}</span>`;
185
+ const chip = $('#prodPick'); if (!chip) return;
186
+ // a product's line: its goals, from what this page read (zero is silence)
187
+ const lines = (ws) => { const n = PF ? PF.goals.filter((g) => g.ws === ws).length : ws === M.board.ws ? M.goals.length : 0; return n ? nGoals(n) : ''; };
188
+ chip.onclick = (e) => { e.stopPropagation(); closeMenus(); PK.openPicker(chip, { P: shownPick(), label: 'Products', lines, note: 'One pick for Home, Board and Insights: unticking a product here also takes it off Home.', onApply: async (on) => { const r = await PK.savePick(on); if (!r.ok) toast(r.error); } }); };
189
+ }
190
+ // a saved pick (this chip, or Settings): Insights opens on the ticked products, without a one-off link's ws or board
191
+ addEventListener('pp:changed', () => { const q = new URLSearchParams(location.search); ['ws', 'board'].forEach((k) => q.delete(k)); const s = q.toString(); location.assign(location.pathname + (s ? '?' + s : '')); });
181
192
  $('#viewMenu').addEventListener('click', (e) => {
182
193
  if (e.target.closest('[data-newdash]')) { closeMenus(); openNewDash(); return; }
183
194
  const b = e.target.closest('[data-view]'); if (!b) return; closeMenus(); setView(b.dataset.view);
@@ -200,11 +211,12 @@ $('.ins-tabs').addEventListener('keydown', (e) => {
200
211
  });
201
212
  function setView(id) { dash = id; setTab('goals'); redraw(); }
202
213
 
203
- /* Portfolio: the goals of every product, each product's model read once through GET /api/insights-premium, grouped by product. A goal of another
204
- * product keeps its own workspace, so a reading added to it goes there. Budgets, Outcomes and Library stay the open product's. */
205
- async function openPortfolio() {
206
- const seen = new Set([M.board.ws]), others = (M.board.switcher || []).filter((b) => !seen.has(b.ws) && seen.add(b.ws));
207
- toast('Reading every product’s goals.');
214
+ /* Portfolio: the goals of the ticked products (several ticked, batch 12 item 5), each product's model read once through GET /api/insights-premium,
215
+ * grouped by product. A goal of another product keeps its own workspace, so a reading added to it goes there. Budgets, Outcomes and Library stay
216
+ * the first ticked product's, and say so (oneNote). */
217
+ async function openPortfolio(only = pickedWs(), keepTab = false) {
218
+ const seen = new Set([M.board.ws]), others = (M.board.switcher || []).filter((b) => (!only.length || only.includes(b.ws)) && !seen.has(b.ws) && seen.add(b.ws));
219
+ toast('Reading the goals of the products you picked.');
208
220
  const got = await Promise.all(others.map(async (b) => { try { const r = await (await fetch('/api/insights-premium?ws=' + encodeURIComponent(b.ws) + '&board=' + encodeURIComponent(b.id), { credentials: 'same-origin' })).json(); return r && r.ok ? r.model : null; } catch { return null; } }));
209
221
  const goals = M.goals.map((g) => Object.assign({}, g, { prod: M.board.name, ws: M.board.ws, rid: g.id })), charts = {}, products = [M.board.name], unread = [];
210
222
  got.forEach((m, i) => {
@@ -214,9 +226,11 @@ async function openPortfolio() {
214
226
  for (const g of m.goals || []) goals.push(Object.assign({}, g, { id: m.board.ws + '~' + g.id, rid: g.id, key: g.key ? m.board.ws + '~' + g.key : null, prod: m.board.name || others[i].name, ws: m.board.ws, moves: g.moves || [] }));
215
227
  });
216
228
  PF = { goals, charts, products, unread };
217
- dash = 'all'; setTab('goals'); redraw();
229
+ dash = 'all'; if (!keepTab) setTab('goals'); redraw();
218
230
  if (unread.length) toast('Not read: ' + unread.join(', ') + '. Their goals are not in Portfolio.');
219
231
  }
232
+ /** With several products ticked, Outcomes and Library are still read one product at a time: say which (principle 7, honest state). */
233
+ const oneNote = () => (PF ? `<p class="note ins-onenote">Shows ${esc(M.board.name || 'the first product')} only: this tab reads one product at a time.</p>` : '');
220
234
  const allGoals = () => (PF ? PF.goals : M.goals);
221
235
  const goalById = (id) => allGoals().find((x) => x.id === id) || null;
222
236
  const goalWs = (g) => (g && g.ws) || M.board.ws;
@@ -849,7 +863,7 @@ function drawOutcomes() {
849
863
  : (need.length ? `<b>${esc(need[0].title)} needs your verdict${dueOf(need[0]) !== null ? ' by ' + esc(md(dueOf(need[0]))) : ''}.</b> ` : '') + esc('Of ' + P.length + (P.length === 1 ? ' promise ' : ' promises ') + (per.said || 'in these dates') + ', ' + met + (met === 1 ? ' is' : ' are') + ' met, ' + part + (part === 1 ? ' is' : ' are') + ' partly met and ' + win + (win === 1 ? ' is' : ' are') + ' still in their window.');
850
864
  const head = '<div class="ins-tr ins-th ins-ocols" role="row"><div role="columnheader">Shipped initiative</div><div role="columnheader">What it promised · and what happened so far</div><div role="columnheader">Guardrail and overlap</div><div role="columnheader">Window</div><div role="columnheader">Verdict</div></div>';
851
865
  const groups = Object.keys(OUT_G).map((k) => { const G = L.filter((r) => r.group === k); return G.length ? `<div class="ins-grp" role="row"><span role="cell">${k === 'decided' ? 'Decided ' + esc(per.said || 'in these dates') : OUT_G[k]}</span> <span class="q">${G.length}</span></div>` + G.map(outRow).join('') : ''; }).join('');
852
- $('#outTbl').innerHTML = head + (groups || '<div class="ins-empty">Nothing to judge yet.</div>');
866
+ $('#outTbl').innerHTML = oneNote() + head + (groups || '<div class="ins-empty">Nothing to judge yet.</div>');
853
867
  }
854
868
  $('#outTbl').addEventListener('click', (e) => { const b = e.target.closest('[data-verdict]'); if (b) openVerdict((M.outcomes || []).find((r) => r.id === b.dataset.verdict)); });
855
869
 
@@ -1197,7 +1211,7 @@ function drawList() {
1197
1211
  const table = nRep ? `<div class="ins-rtbl" id="repAsks"><div class="ins-rl ins-rlh" role="presentation"><span>Report</span><span>Next</span><span>Status</span></div><div role="list">${reps.map(repRowHtml).join('')}${asks.map(askRowHtml).join('')}</div></div>`
1198
1212
  : !empty ? '<div class="ins-empty"><b>No report is set up and no report file is on record.</b> Reports are made in Home.</div>' : '';
1199
1213
  const dashBlock = `<div class="ins-sec"><h3>Dashboards</h3><span class="q">${dashes.length} · a dashboard is a saved view of Goals</span></div><div class="ins-dgrid" role="list">${dashes.map(dashCard).join('')}</div>`;
1200
- $('#repBody').innerHTML = `<div id="listRows" aria-label="Dashboards and reports">${fbox}${empty}${table}${dashBlock}</div>`;
1214
+ $('#repBody').innerHTML = `${oneNote()}<div id="listRows" aria-label="Dashboards and reports">${fbox}${empty}${table}${dashBlock}</div>`;
1201
1215
  }
1202
1216
  $('#repBody').addEventListener('click', async (e) => {
1203
1217
  const d = e.target.closest('[data-d]'); if (d) { setView(d.dataset.d); return; }
@@ -1343,7 +1357,10 @@ function draw() {
1343
1357
  redraw();
1344
1358
  }
1345
1359
  async function load() {
1346
- const p = new URLSearchParams(location.search), q = [p.get('ws') ? 'ws=' + encodeURIComponent(p.get('ws')) : '', p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
1360
+ if (!PKP) PKP = await PK.readPick();
1361
+ // the pick: one ticked = that product; several = the first one read, then Portfolio of them all
1362
+ const p = new URLSearchParams(location.search), on = pickedWs(), pw = DEEP ? p.get('ws') : on[0] || null;
1363
+ const q = [pw ? 'ws=' + encodeURIComponent(pw) : '', DEEP && p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
1347
1364
  let r = null, status = 0;
1348
1365
  try { const res = await fetch('/api/insights-premium' + (q ? '?' + q : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
1349
1366
  if (!r || !r.ok) {
@@ -1353,6 +1370,7 @@ async function load() {
1353
1370
  return;
1354
1371
  }
1355
1372
  const first = !M; M = r.model; loadedAt = Date.now(); draw(); if (first || !BM) bmLoad();
1373
+ if (on.length > 1 && first) await openPortfolio(on, true);
1356
1374
  // A shared goal link (?goal=<id>, from "Copy link" in the goal's ⋯) opens that goal once, after the first read.
1357
1375
  if (first) { const gid = new URLSearchParams(location.search).get('goal'); if (gid && allGoals().some((g) => g.id === gid)) openGoalDetail(gid); }
1358
1376
  }