create-pmos 0.397.0 → 0.399.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 (195) hide show
  1. package/package.json +25 -25
  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-adddoc-test.js +105 -52
  8. package/workspace/briefing-premium-board-test.js +284 -128
  9. package/workspace/briefing-premium-calendar-2-test.js +135 -198
  10. package/workspace/briefing-premium-calendar-3-test.js +143 -418
  11. package/workspace/briefing-premium-calendar-test.js +85 -196
  12. package/workspace/briefing-premium-doc-edit-test.js +99 -83
  13. package/workspace/briefing-premium-initiative-test.js +175 -290
  14. package/workspace/briefing-premium-insights-test.js +414 -219
  15. package/workspace/briefing-premium-metrics-test.js +55 -97
  16. package/workspace/briefing-premium-products-test.js +44 -28
  17. package/workspace/briefing-premium-sources-test.js +70 -49
  18. package/workspace/briefing-premium-test.js +155 -648
  19. package/workspace/briefing-premium-work-test.js +88 -283
  20. package/workspace/changelog.json +24 -0
  21. package/workspace/ev-everywhere-test.js +210 -0
  22. package/workspace/fixtures/board-premium-trail.js +32 -0
  23. package/workspace/fixtures/premium-viewer-fixtures.js +187 -0
  24. package/workspace/guide/briefing-premium.md +3 -1
  25. package/workspace/guide/home.md +68 -0
  26. package/workspace/guide/index.md +1 -0
  27. package/workspace/lib/agent-roles.js +71 -0
  28. package/workspace/lib/board-grill.js +63 -0
  29. package/workspace/lib/board-premium.js +121 -24
  30. package/workspace/lib/board-trail.js +223 -0
  31. package/workspace/lib/home-work-item.js +58 -0
  32. package/workspace/lib/initiative-layout.js +77 -0
  33. package/workspace/lib/insights-goals.js +196 -0
  34. package/workspace/lib/insights-premium.js +64 -15
  35. package/workspace/lib/insights-records.js +115 -0
  36. package/workspace/lib/jira-tickets.js +1 -1
  37. package/workspace/lib/meeting-points.js +52 -0
  38. package/workspace/lib/news-for-you.js +88 -0
  39. package/workspace/lib/notes-series.js +29 -6
  40. package/workspace/lib/report-confirm.js +48 -0
  41. package/workspace/lib/route-modules.js +12 -0
  42. package/workspace/lib/routes-board-docs.js +46 -0
  43. package/workspace/lib/routes-board-grill.js +90 -0
  44. package/workspace/lib/routes-board-trail.js +33 -0
  45. package/workspace/lib/routes-home-desk.js +176 -0
  46. package/workspace/lib/routes-home-review.js +108 -0
  47. package/workspace/lib/routes-initiative-layout.js +57 -0
  48. package/workspace/lib/routes-insights-premium.js +16 -4
  49. package/workspace/lib/routes-insights-records.js +133 -0
  50. package/workspace/lib/routes-meeting-points.js +37 -0
  51. package/workspace/lib/routes-news.js +57 -0
  52. package/workspace/lib/routes-notes.js +3 -1
  53. package/workspace/lib/routes-report-confirm.js +31 -0
  54. package/workspace/lib/routes-search.js +38 -0
  55. package/workspace/lib/routes-viewer.js +108 -0
  56. package/workspace/lib/search-index.js +176 -0
  57. package/workspace/lib/transcript-steps.js +123 -0
  58. package/workspace/lib/viewer-meeting.js +205 -0
  59. package/workspace/lib/viewer-report.js +89 -0
  60. package/workspace/package-lock.json +2 -2
  61. package/workspace/package.json +1 -1
  62. package/workspace/premium-board-actions-test.js +128 -82
  63. package/workspace/premium-briefing-depth-test.js +104 -90
  64. package/workspace/premium-chat-attach-test.js +54 -63
  65. package/workspace/premium-chat-chart-tab-test.js +37 -37
  66. package/workspace/premium-chat-context-test.js +19 -18
  67. package/workspace/premium-chat-goal-view-test.js +23 -23
  68. package/workspace/premium-chat-notes-test.js +26 -31
  69. package/workspace/premium-chat-report-tab-test.js +46 -28
  70. package/workspace/premium-chat-term-test.js +16 -16
  71. package/workspace/premium-chat-viewer-test.js +60 -59
  72. package/workspace/premium-core-doc-issue-test.js +52 -43
  73. package/workspace/premium-html-viewer-test.js +14 -17
  74. package/workspace/premium-phone-card-test.js +10 -3
  75. package/workspace/premium-phone-room-test.js +41 -35
  76. package/workspace/premium-report-read-test.js +152 -197
  77. package/workspace/premium-viewer-download-test.js +19 -22
  78. package/workspace/premium-viewer-flicker-test.js +11 -16
  79. package/workspace/premium-viewer-share-test.js +6 -9
  80. package/workspace/premium-viewer-test.js +41 -60
  81. package/workspace/premium-vw-backlog-test.js +53 -33
  82. package/workspace/premium-vw-cal-test.js +97 -128
  83. package/workspace/premium-vw-copy-test.js +17 -33
  84. package/workspace/premium-vw-doc-test.js +17 -10
  85. package/workspace/premium-vw-item-test.js +50 -49
  86. package/workspace/premium-vw-jira-test.js +53 -27
  87. package/workspace/premium-vw-meet-test.js +115 -187
  88. package/workspace/premium-vw-notes-test.js +88 -109
  89. package/workspace/premium-vw-rec-test.js +71 -194
  90. package/workspace/premium-vw-slides-test.js +46 -50
  91. package/workspace/premium-welcome-test.js +3 -2
  92. package/workspace/premium-work-depth-test.js +61 -53
  93. package/workspace/public/pm/bd-acts.js +383 -0
  94. package/workspace/public/pm/bd-asks.js +261 -0
  95. package/workspace/public/pm/bd-pop.js +59 -0
  96. package/workspace/public/pm/bd-span.js +222 -82
  97. package/workspace/public/pm/bd-stages.js +25 -11
  98. package/workspace/public/pm/bd-views.js +169 -0
  99. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  100. package/workspace/public/pm/c3-md.js +3 -395
  101. package/workspace/public/pm/c3-phone-detail.js +1 -1
  102. package/workspace/public/pm/c3-phone-model.js +3 -68
  103. package/workspace/public/pm/chat-term.js +3 -3
  104. package/workspace/public/pm/cozy-board.css +798 -230
  105. package/workspace/public/pm/cozy-ev.css +228 -0
  106. package/workspace/public/pm/cozy-evmodel.js +106 -0
  107. package/workspace/public/pm/cozy-evui.js +47 -0
  108. package/workspace/public/pm/cozy-home.css +570 -142
  109. package/workspace/public/pm/cozy-home.js +5 -3
  110. package/workspace/public/pm/cozy-insights.css +437 -170
  111. package/workspace/public/pm/cozy-md.js +396 -0
  112. package/workspace/public/pm/cozy-nav.js +104 -29
  113. package/workspace/public/pm/cozy-news.js +140 -0
  114. package/workspace/public/pm/cozy-placeholder.js +26 -0
  115. package/workspace/public/pm/cozy-search.js +203 -0
  116. package/workspace/public/pm/cozy-settings.js +198 -0
  117. package/workspace/public/pm/cozy-sources.js +89 -0
  118. package/workspace/public/pm/cozy-today.css +217 -0
  119. package/workspace/public/pm/cozy-viewer.css +3 -3
  120. package/workspace/public/pm/cozy-viewer.js +145 -0
  121. package/workspace/public/pm/cozy-vw-mtg.css +350 -0
  122. package/workspace/public/pm/cozy-vw-rp.css +152 -0
  123. package/workspace/public/pm/cozy-vw.css +485 -0
  124. package/workspace/public/pm/cozy.css +83 -1
  125. package/workspace/public/pm/home-adddoc.js +48 -0
  126. package/workspace/public/pm/home-app.js +1179 -0
  127. package/workspace/public/pm/home-around.js +413 -0
  128. package/workspace/public/pm/home-chat.js +512 -0
  129. package/workspace/public/pm/home-data.js +312 -0
  130. package/workspace/public/pm/home-dictate.js +54 -0
  131. package/workspace/public/pm/home-draft.js +68 -0
  132. package/workspace/public/pm/home-ini-model.js +190 -0
  133. package/workspace/public/pm/home-ini.css +171 -0
  134. package/workspace/public/pm/home-ini.js +456 -0
  135. package/workspace/public/pm/home-list.js +276 -0
  136. package/workspace/public/pm/home-more.js +132 -0
  137. package/workspace/public/pm/home-phone-card.js +109 -0
  138. package/workspace/public/pm/home-review.js +104 -0
  139. package/workspace/public/pm/home-task.js +67 -0
  140. package/workspace/public/pm/home-today.js +144 -0
  141. package/workspace/public/pm/home-work.js +547 -0
  142. package/workspace/public/pm/phone-moment.js +69 -0
  143. package/workspace/public/pm/pm-work-view.js +1 -1
  144. package/workspace/public/pm/premium-attach.js +4 -0
  145. package/workspace/public/pm/premium-board.js +548 -395
  146. package/workspace/public/pm/premium-chart-tab.js +109 -62
  147. package/workspace/public/pm/premium-deck.js +3 -3
  148. package/workspace/public/pm/premium-first.js +23 -21
  149. package/workspace/public/pm/premium-insights.js +1102 -581
  150. package/workspace/public/pm/premium-meeting.js +61 -549
  151. package/workspace/public/pm/premium-mtg-present.js +138 -0
  152. package/workspace/public/pm/premium-mtg-replay.js +142 -0
  153. package/workspace/public/pm/premium-notes.js +1 -1
  154. package/workspace/public/pm/premium-report-frame.css +20 -0
  155. package/workspace/public/pm/premium-report-read.js +669 -476
  156. package/workspace/public/pm/premium-report-tab.js +116 -67
  157. package/workspace/public/pm/premium-shell.js +76 -123
  158. package/workspace/public/pm/premium-viewer.js +22 -1
  159. package/workspace/public/pm/premium-vw-cal.js +277 -48
  160. package/workspace/public/pm/premium-vw-doc.css +6 -0
  161. package/workspace/public/pm/premium-vw-doc.js +40 -2
  162. package/workspace/public/pm/premium-vw-file.js +2 -2
  163. package/workspace/public/pm/premium-vw-meet.js +6 -83
  164. package/workspace/public/pm/premium-vw-mtg.js +958 -0
  165. package/workspace/public/pm/premium-vw-notes.js +116 -68
  166. package/workspace/public/pm/premium-vw-open.js +35 -0
  167. package/workspace/public/pm/premium-vw-page.js +16 -0
  168. package/workspace/public/pm/premium-vw-rec.js +11 -218
  169. package/workspace/public/pm/premium-vw-slides.css +5 -0
  170. package/workspace/public/pm/premium-vw-slides.js +44 -8
  171. package/workspace/public/pm/rp-parts.js +269 -0
  172. package/workspace/public/pm/term-view.js +22 -0
  173. package/workspace/public/premium-board.html +29 -70
  174. package/workspace/public/premium-initiative.html +8 -48
  175. package/workspace/public/premium-insights.html +26 -64
  176. package/workspace/public/premium-viewer.html +20 -0
  177. package/workspace/public/premium.html +18 -107
  178. package/workspace/r/m1.png +0 -0
  179. package/workspace/r/m2.png +0 -0
  180. package/workspace/r/m3.png +0 -0
  181. package/workspace/r/nl.png +0 -0
  182. package/workspace/server.js +18 -3
  183. package/workspace/test-files.json +1 -0
  184. package/workspace/test-lists/home-libs.json +9 -0
  185. package/workspace/test-lists/initiative-layout.json +9 -0
  186. package/workspace/test-lists/premium-report-read.json +1 -1
  187. package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
  188. package/workspace/test-lists/premium-uncovered-reports.json +9 -0
  189. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  190. package/workspace/test-lists/premium-vw-notes.json +1 -1
  191. package/workspace/test-lists/uf-everywhere.json +15 -0
  192. package/workspace/test-lists/uf-home.json +9 -0
  193. package/workspace/test-lists/uncovered-board.json +9 -0
  194. package/workspace/public/pm/premium-work.js +0 -729
  195. package/workspace/public/pm/premium.js +0 -1146
@@ -0,0 +1,276 @@
1
+ /* pm/home-list.js — Home's one list, pure (initiative premium-uncovered-features, H1 and H2; canvas HmMyWork, HmReview, HmProducts, HmDay,
2
+ * HmDecide, HmMic, HmPhone, HmPhone2).
3
+ *
4
+ * There is no Needs you group and no Your list (PM, canvas review 2026-10-22/23): every next step sits under its initiative, and the list is
5
+ * grouped by product. This file turns what the routes answer into what the list draws, and touches no page, so a node test imports it:
6
+ * productsOf(D) the products the list shows: the board's own first, then every product Home reads (GET /api/briefing-premium products)
7
+ * and every product a next step names; each with its goals line ("2 of 4 goals on track")
8
+ * homeList(D, o) { greet, yours, filters, groups, untouched, filter } for the list column
9
+ * todayCard(D, o) the Today card through the day: day (greeting and the day's load), soon (a meeting in 15 minutes or less), live
10
+ * (a meeting on now), rec (a recording that is no calendar meeting), eod (the end of a day with something open), clear
11
+ * staleInis(D, now, days) open initiatives with no change for `days` days or more, the longest first
12
+ * reviewModel(D, now) the weekly review's four steps, from the My work model, the stale initiatives and the review log (GET /api/home-review)
13
+ * fileUnder(text, inis) the initiative a typed task names (its title or id in the text), or null: the task then goes on the PM's own list
14
+ * D is home-data.js's D plus { work (GET /api/my-work-premium model), items (GET /api/boards/items), others ([{ ws, name, model }], the boards of
15
+ * the other products), phoneDay (GET /api/phone-day), review (GET /api/home-review) }. A part that did not answer is left out, never guessed. */
16
+ import { needsOf, boardRows, productCard, productName, sessionRow, iniOfSession, todayOf, live, OPEN, hm } from './home-data.js';
17
+
18
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
19
+ const DOW = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
20
+ const RANK = { needs: 4, blocked: 3, working: 2, quiet: 1 };
21
+ const pad = (n) => String(n).padStart(2, '0');
22
+ const cap1 = (s) => (s ? String(s).charAt(0).toUpperCase() + String(s).slice(1) : '');
23
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
24
+ const isoDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); };
25
+ const dayDiff = (iso, now) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); if (!m) return null; const a = new Date(+m[1], +m[2] - 1, +m[3]); const t = new Date(now); t.setHours(0, 0, 0, 0); return Math.round((a - t) / 86400000); };
26
+ const shortDay = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
27
+ export const REVIEW_DAY = 5; // Friday
28
+ export const STALE_DAYS = 14;
29
+
30
+ /* ── the greeting ── */
31
+ export function greetWord(now = Date.now()) { const h = new Date(now).getHours(); return h < 12 ? 'Good morning' : h < 18 ? 'Good afternoon' : 'Good evening'; }
32
+ /** "Good morning. 2 next steps are yours today." */
33
+ export function greeting(n, now = Date.now()) {
34
+ return greetWord(now) + '. ' + (n ? plural(n, 'next step is', 'next steps are') + ' yours today.' : 'No next step is yours today.');
35
+ }
36
+
37
+ /* ── products ── */
38
+ const initialsOf = (name) => { const w = String(name || '').trim().split(/[\s_-]+/).filter(Boolean); return (w.length > 1 ? w[0][0] + w[1][0] : String(name || '?').slice(0, 2)).toUpperCase(); };
39
+ function goalsOf(model) {
40
+ const C = productCard({ board: model });
41
+ const n = C.items.length, ok = C.items.filter((x) => x.kind === 'ok').length;
42
+ return { ok, n, text: n ? ok + ' of ' + n + ' goals on track' : 'No goal anchored yet' };
43
+ }
44
+ /* A row the brief tags "Across products" names no product: it is not a group of its own, it sits with the rows that name none. */
45
+ const ACROSS = 'Across products';
46
+ const prodOf = (x) => (x && x.product && x.product !== ACROSS ? x.product : '');
47
+ /** The products the list shows, the board's own product first. Each: { key, ws, name, initials, primary, model, goals, on }. */
48
+ export function productsOf(D) {
49
+ const out = [];
50
+ const add = (p) => { const k = p.ws || 'n:' + String(p.name).toLowerCase(); if (out.some((x) => x.key === k || x.name.toLowerCase() === String(p.name).toLowerCase())) return; out.push({ ...p, key: k, initials: initialsOf(p.name) }); };
51
+ const b = D.board && D.board.board;
52
+ const av = (D.brief && D.brief.products && D.brief.products.available) || [];
53
+ const named = (ws) => ((ws && av.find((a) => a.ws === ws)) || {}).name || '';
54
+ if (D.board) add({ ws: (b && b.ws) || '', name: (b && b.product) || named(b && b.ws) || productName(D), primary: true, model: D.board, goals: goalsOf(D.board) });
55
+ for (const o of D.others || []) if (o && o.model) add({ ws: o.ws, name: o.name || productName({ board: o.model }), primary: false, model: o.model, goals: goalsOf(o.model) });
56
+ for (const a of av) if (a.on) add({ ws: a.ws, name: a.name, primary: false, model: null, goals: null });
57
+ for (const r of needsOf(D)) if (prodOf(r)) add({ ws: '', name: r.product, primary: false, model: null, goals: null });
58
+ return out;
59
+ }
60
+
61
+ /* ── rows ── */
62
+ function taskHint(t, now, mine) {
63
+ const d = t.end ? dayDiff(t.end, now) : null;
64
+ const when = d == null ? '' : d === 0 ? 'due today' : d === 1 ? 'due tomorrow' : d < 0 ? plural(-d, 'day', 'days') + ' late' : 'due ' + shortDay(t.end);
65
+ if (!mine) return ['Waiting on ' + (/^agent:/.test(String(t.owner)) ? 'an agent' : t.owner), when].filter(Boolean).join(' · ');
66
+ return ['Task', t.status && t.status !== 'To do' ? t.status : '', when].filter(Boolean).join(' · ');
67
+ }
68
+ /** The PMOS tasks of an initiative that are not done: the PM's first, then the ones that wait on someone else. */
69
+ export function tasksOf(D, ini, now = Date.now()) {
70
+ const me = String((D.today && D.today.me) || '').toLowerCase();
71
+ const items = ((D.items && D.items.items) || []).filter((t) => t && t.src === 'pmos' && t.kind !== 'Epic' && t.ini === ini && t.status !== 'Done');
72
+ return items.map((t) => {
73
+ const ow = String(t.owner || '').toLowerCase();
74
+ const mine = !ow || /^(pm|you)(:|$)/.test(ow) || (!!me && (ow === me || ow.startsWith(me + ' ')));
75
+ return { id: 't:' + t.uid, kind: 'task', ini, name: t.title, hint: taskHint(t, now, mine), state: mine ? 'quiet' : 'wait', mine, due: t.end || '', late: !!(t.end && dayDiff(t.end, now) < 0), task: t };
76
+ }).sort((a, b) => (b.mine - a.mine) || String(a.due).localeCompare(String(b.due)));
77
+ }
78
+ function meetRow(m, ini) {
79
+ return { id: 'm:' + (m.id || m.title), kind: 'meeting', ini: ini || null, name: m.title, hint: (m.state === 'now' ? 'Now' : hm(m.start)) + (ini ? ' meeting' : ' · not linked'), state: m.state === 'now' ? 'working' : 'quiet', icon: 'clock', meeting: m };
80
+ }
81
+ /** Today's unread mentions of the PM (GET /api/brief-page mentions). One that names an initiative is that initiative's next step. */
82
+ const mentionsOf = (D) => (D.today && Array.isArray(D.today.mentions) ? D.today.mentions : []).filter((m) => m && !m.read && !m.done);
83
+ function mentionRow(m, ini) {
84
+ return { id: 'men:' + (m.id || m.at), kind: 'mention', ini: ini || null, name: (m.who ? m.who + ' ' : '') + (m.text ? 'asks: ' + m.text : 'named you'),
85
+ hint: (ini ? 'Next step · ' : '') + 'Mention' + (m.where ? ' · ' + m.where : m.source ? ' · ' + cap1(m.source) : ''), state: 'needs', mention: m, link: m.link || '', step: !!ini };
86
+ }
87
+ const meetIni = (m) => (m && (m.initiative || (m.level && m.level.kind === 'initiative' && m.level.id) || (m.about && m.about.kind === 'initiative' && m.about.id))) || null;
88
+ /** A next step's hint without its product's name: the product is the group's header. */
89
+ const bareHint = (x) => { const h = String(x.hint || ''), p = prodOf(x); return p && h.startsWith(p + ' · ') ? h.slice(p.length + 3) : p && h === p ? '' : h; }; // the group names the product; "Across products" stays
90
+ function iniRowOf(D, r, needs, now) {
91
+ const steps = needs.filter((x) => x.ini === r.id && !x.needSession).map((x) => ({ ...x, step: true, hint: 'Next step' + (bareHint(x) ? ' · ' + bareHint(x) : '') }))
92
+ .concat(mentionsOf(D).filter((m) => m.initiative === r.id).map((m) => mentionRow(m, r.id)));
93
+ const ses = (D.sessions || []).filter((s) => live(s) && iniOfSession(s) === r.id).map((s) => sessionRow(s, D.desk && D.desk.roles));
94
+ const tasks = tasksOf(D, r.id, now);
95
+ const meet = todayOf(D).filter((m) => meetIni(m) === r.id && m.state !== 'past').map((m) => meetRow(m, r.id));
96
+ const turn = steps.length > 0 || ses.some((s) => s.state === 'needs' || s.state === 'blocked');
97
+ const mine = tasks.filter((t) => t.mine).length;
98
+ const run = ses.filter((s) => s.state === 'working').length;
99
+ const right = turn ? 'your turn' + (mine ? ' · ' + plural(mine, 'task', 'tasks') : '') : mine ? plural(mine, 'task', 'tasks') : run ? run + ' running' : 'Nothing today';
100
+ const kids = [...steps, ...ses.sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0)), ...tasks, ...meet];
101
+ const hint = r.made ? [cap1(r.lane), r.stage].filter(Boolean).join(' · ') : [cap1(r.lane || 'feature'), r.stage].filter(Boolean).join(' · ');
102
+ return { id: 'i:' + r.id, kind: 'ini', ini: r.id, name: r.title, hint, right, turn, busy: kids.length > 0, state: turn ? 'needs' : run ? 'working' : 'quiet', kids, board: r, updated: r.updated || '' };
103
+ }
104
+
105
+ /* ── the list ── */
106
+ const sameName = (a, b) => String(a || '').toLowerCase() === String(b || '').toLowerCase();
107
+ /** o: { filter ('today' | 'waiting' | 'kept' | 'done'), product (a product key, or null for all), now } */
108
+ export function homeList(D, o = {}) {
109
+ const now = o.now || D.now || Date.now();
110
+ const needs = needsOf(D);
111
+ const products = productsOf(D);
112
+ const primary = products.find((p) => p.primary) || null;
113
+ const used = new Set();
114
+ const W = D.work || null;
115
+ const tab = (k) => ((W && W.queue && W.queue.tabs) || []).find((t) => t.key === k) || null;
116
+ const tabRows = (k) => { const t = tab(k); return t ? t.groups.flatMap((g) => g.rows || []) : []; };
117
+ const filters = [
118
+ { key: 'today', label: 'Today' },
119
+ { key: 'waiting', label: 'Waiting', n: W && W.waiting ? W.waiting.rows.length : 0 },
120
+ { key: 'kept', label: 'Kept', n: (tab('kept') || {}).n || 0 },
121
+ { key: 'done', label: 'Done' },
122
+ ];
123
+ const groups = [];
124
+ for (const p of products) {
125
+ if (o.product && o.product !== p.key) continue;
126
+ const rows = (p.model && p.model.initiatives && p.model.initiatives.list && p.model.initiatives.list.rows) || (p.primary ? boardRows(D) : []);
127
+ const open = rows.filter(OPEN);
128
+ const ids = new Set(open.map((r) => r.id));
129
+ const mineNeeds = needs.filter((x) => (x.ini && ids.has(x.ini)) || (p.primary ? x.ini === 'product' || (!x.ini && !prodOf(x) && !x.needSession) || (prodOf(x) && sameName(prodOf(x), p.name)) : prodOf(x) && sameName(prodOf(x), p.name)));
130
+ mineNeeds.forEach((x) => used.add(x.id));
131
+ // a next step whose initiative is not an open row of the board (a prototype, a record the board does not list) still sits under that
132
+ // initiative, never loose under the product (canvas HmMyWork): the initiative's row is made from the step's own subject
133
+ const extra = new Map();
134
+ for (const x of mineNeeds) if (x.ini && x.ini !== 'product' && !ids.has(x.ini) && !x.needSession && !extra.has(x.ini)) extra.set(x.ini, { id: x.ini, title: (x.row && x.row.subject) || x.ini, lane: (x.row && x.row.lane) || '', stage: (x.row && x.row.stage) || '', made: true });
135
+ for (const id of extra.keys()) ids.add(id);
136
+ const inis = open.concat([...extra.values()]).map((r) => iniRowOf(D, r, mineNeeds, now));
137
+ inis.sort((a, b) => (b.turn - a.turn) || (b.busy - a.busy) || (RANK[b.state] || 0) - (RANK[a.state] || 0));
138
+ // the product's own next steps (its weekly update, a decision with no initiative) sit under its header, before the initiatives
139
+ const flat = mineNeeds.filter((x) => !x.ini || !ids.has(x.ini)).filter((x) => !x.needSession).map((x) => ({ ...x, flat: true, hint: bareHint(x) }));
140
+ const turnN = inis.filter((x) => x.turn).length + flat.length;
141
+ const shown = inis.filter((x) => x.turn || x.busy);
142
+ groups.push({ key: 'p:' + p.key, kind: 'product', product: p, name: p.name, primary: !!p.primary, goals: p.goals, flat, inis: shown, rest: inis.filter((x) => !shown.includes(x)),
143
+ count: inis.length, turnN, closedLine: [inis.length ? plural(inis.length, 'initiative', 'initiatives') : '', turnN ? turnN + ' your turn' : ''].filter(Boolean).join(' · ') || 'Nothing open' });
144
+ }
145
+ // sessions that wait on the PM and belong to no initiative of a product: they are next steps too, under "Not in an initiative"
146
+ const looseNeeds = needs.filter((x) => !used.has(x.id) && !(x.ini && groups.some((g) => g.inis.concat(g.rest).some((i) => i.ini === x.ini))));
147
+ const loose = [];
148
+ for (const x of looseNeeds) loose.push({ ...x, flat: true });
149
+ for (const r of tabRows('today')) loose.push({ id: 'w:' + r.key, kind: 'item', key: r.key, name: r.title, hint: [r.overdue ? 'late' : '', r.sub ? r.sub.replace(/^Yours\b/, 'your own note') : 'your own note'].filter(Boolean).join(' · '), check: true, item: r });
150
+ const inIni = new Set(groups.flatMap((g) => g.inis.concat(g.rest)).map((i) => i.ini));
151
+ for (const m of mentionsOf(D).filter((x) => !(x.initiative && inIni.has(x.initiative)))) loose.push(mentionRow(m, null));
152
+ for (const m of todayOf(D).filter((x) => !meetIni(x) && x.state !== 'past')) loose.push(meetRow(m, null));
153
+ for (const s of (D.sessions || []).filter((s) => live(s) && !iniOfSession(s) && s.shown !== 'needs' && s.shown !== 'blocked')) loose.push({ ...sessionRow(s, D.desk && D.desk.roles), loose: true });
154
+ if (!o.product || o.product === 'loose') groups.push({ key: 'loose', kind: 'loose', name: 'Not in an initiative', rows: loose, n: loose.length });
155
+ const stale = staleInis(D, now);
156
+ const untouched = { n: stale.length + ((W && W.review && W.review.n) || 0), inis: stale.length, items: (W && W.review && W.review.n) || 0, day: new Date(now).getDay() === REVIEW_DAY ? 'today' : 'Fri' };
157
+ // a filter other than Today shows one plain list from the PM's own list (the items carry no initiative)
158
+ let list = null;
159
+ if (o.filter === 'waiting') list = { title: 'Waiting on others', rows: (W && W.waiting ? W.waiting.rows : []).map((r) => ({ id: 'w:' + r.key, kind: 'item', key: r.key, name: r.title, hint: r.sub || '', state: 'wait', item: r })), empty: 'Nobody owes you anything.' };
160
+ if (o.filter === 'kept') list = { title: 'Kept for later', rows: tabRows('kept').map((r) => ({ id: 'w:' + r.key, kind: 'item', key: r.key, name: r.title, hint: r.sub || '', check: true, item: r })), empty: 'Nothing is kept for later.' };
161
+ if (o.filter === 'done') {
162
+ const done = tabRows('done').map((r) => ({ id: 'w:' + r.key, kind: 'item', key: r.key, name: r.title, hint: r.sub || 'Done', done: true, item: r }));
163
+ const fin = (D.phoneDay && D.phoneDay.finished) || [];
164
+ for (const f of fin) done.push({ id: 'fin:' + (f.id || f.title), kind: 'finished', name: f.title, hint: f.status === 'review' ? 'Finished · waits for your review' : 'Finished', done: true, finished: f });
165
+ list = { title: 'Done today', rows: done, empty: 'Nothing is done yet today.' };
166
+ }
167
+ const yours = needs.length + mentionsOf(D).filter((m) => m.initiative && groups.some((g) => g.inis.concat(g.rest || []).some((i) => i.ini === m.initiative))).length;
168
+ const nIni = groups.filter((g) => g.kind === 'product').reduce((n, g) => n + g.count, 0);
169
+ return { yours, greet: greeting(yours, now), products, primary, filters, filter: o.filter || 'today', groups, list, untouched,
170
+ counts: { products: products.length, initiatives: nIni } };
171
+ }
172
+
173
+ /* ── the Today card through the day ── */
174
+ const DAY_FROM = 9, DAY_TO = 18;
175
+ /** The day's load bar from 09 to 18: free and meeting stretches, the meeting on now marked. { segs: [{ flex, m, now }], sub } */
176
+ export function dayLoad(today, now = Date.now()) {
177
+ const L = (Array.isArray(today) ? today : []).filter((m) => m && m.start).map((m) => ({ m, a: Date.parse(m.start), b: m.end ? Date.parse(m.end) : Date.parse(m.start) + (m.minutes || 30) * 60000 })).filter((x) => !Number.isNaN(x.a)).sort((x, y) => x.a - y.a);
178
+ const d0 = new Date(now); d0.setHours(DAY_FROM, 0, 0, 0); const d1 = new Date(now); d1.setHours(DAY_TO, 0, 0, 0);
179
+ const segs = []; let at = d0.getTime();
180
+ for (const x of L) {
181
+ const a = Math.max(x.a, at), b = Math.min(x.b, d1.getTime());
182
+ if (b <= a) continue;
183
+ if (a > at) segs.push({ flex: Math.round((a - at) / 60000), m: false });
184
+ segs.push({ flex: Math.round((b - a) / 60000), m: true, now: x.m.state === 'now' });
185
+ at = b;
186
+ }
187
+ if (at < d1.getTime()) segs.push({ flex: Math.round((d1.getTime() - at) / 60000), m: false });
188
+ const mins = L.reduce((n, x) => n + Math.max(0, Math.round((x.b - x.a) / 60000)), 0);
189
+ const dur = mins >= 60 ? (Math.round(mins / 30) / 2).toString().replace(/\.0$/, '') + ' h' : mins + ' min';
190
+ const sub = L.length ? plural(L.length, 'meeting', 'meetings') + ' · ' + dur + ' · first at ' + hm(L[0].m.start) : 'No meeting today';
191
+ return { segs: L.length ? segs : [], sub, n: L.length };
192
+ }
193
+ const listWords = (a) => (a.length <= 1 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1]);
194
+ /** The card's mode and words. o: { now, rec: { id, title, at, paused, meeting } | null, hidden (the end-of-day card was closed today), titleOf(ini) } */
195
+ export function todayCard(D, o = {}) {
196
+ const now = o.now || D.now || Date.now();
197
+ const t = todayOf(D);
198
+ const needs = needsOf(D);
199
+ const titleOf = o.titleOf || ((id) => id);
200
+ if (o.rec && !o.rec.meeting) {
201
+ const s = o.rec.at ? Math.max(0, Math.round((now - Date.parse(o.rec.at)) / 1000)) : null;
202
+ return { mode: 'rec', id: o.rec.id, paused: !!o.rec.paused, clock: s == null ? '' : Math.floor(s / 60) + ':' + pad(s % 60), title: o.rec.title || 'A recording', sub: (o.rec.title ? o.rec.title : 'A recording') + ' · not on the calendar' };
203
+ }
204
+ const nowM = t.find((m) => m.state === 'now');
205
+ if (nowM) {
206
+ const mins = Math.max(0, Math.round((now - Date.parse(nowM.start)) / 60000));
207
+ const done = (nowM.before || []).filter((x) => x && x.done).length, all = (nowM.before || []).length;
208
+ return { mode: 'live', meeting: nowM, title: nowM.title, rec: !!(o.rec && o.rec.meeting), mins: mins + ' min', sub: all ? 'To do before: ' + done + ' of ' + all + ' done' : nowM.people && nowM.people.length ? 'With ' + listWords(nowM.people.slice(0, 3)) : 'On now' };
209
+ }
210
+ const soon = t.find((m) => m.state !== 'past' && Date.parse(m.start) > now && Date.parse(m.start) - now <= 15 * 60000);
211
+ if (soon) {
212
+ const inMin = Math.max(1, Math.round((Date.parse(soon.start) - now) / 60000));
213
+ const ini = meetIni(soon);
214
+ const todo = (soon.before || []).filter((x) => x && !x.done).length;
215
+ const parts = [soon.people && soon.people.length ? 'With ' + listWords(soon.people.slice(0, 3)) : '', ini ? titleOf(ini) : '', todo ? plural(todo, 'thing', 'things') + ' to do before' : '', soon.minutes ? soon.minutes + ' min' : ''].filter(Boolean);
216
+ const link = [soon.join, soon.link, soon.url].find((u) => /^https:\/\//.test(String(u || ''))) || '';
217
+ return { mode: 'soon', meeting: soon, time: hm(soon.start), title: soon.title, in: 'in ' + inMin + ' min', sub: parts.join(' · '), link, prep: (soon.prepared || []).length > 0 || todo > 0 };
218
+ }
219
+ const h = new Date(now).getHours();
220
+ if (h >= 17 && !o.hidden) {
221
+ const P = D.phoneDay && D.phoneDay.ok !== false ? D.phoneDay : null;
222
+ const block = needs.find((x) => x.row && /decision|blocked/.test(x.row.kind)) || needs[0] || null;
223
+ const rec = P && P.recap ? P.recap : null;
224
+ const moved = rec && (rec.moved || []).length ? rec.moved.slice(0, 2).map((m) => m.text).join(' · ') : '';
225
+ const doneLine = moved || (rec ? [rec.decided ? plural(rec.decided, 'decision', 'decisions') : '', rec.done ? plural(rec.done, 'task', 'tasks') + ' done' : '', rec.finished ? rec.finished + ' finished' : ''].filter(Boolean).join(' · ') : '');
226
+ const runs = (D.sessions || []).filter((s) => s.shown === 'working');
227
+ const over = runs.length ? (runs.length === 1 ? ((runs[0].hx && runs[0].hx.title) || runs[0].name) + ' runs.' : runs.length + ' sessions run.') + ' Results are in New for you by morning.' : '';
228
+ const tm = P && P.tomorrow ? P.tomorrow : null;
229
+ const first = tm && (tm.meetings || []).length ? tm.meetings.slice().sort((a, b) => Date.parse(a.start) - Date.parse(b.start))[0] : null;
230
+ const tomorrow = tm ? (first ? 'First meeting ' + hm(first.start) : 'No meeting') + (needs.length ? ' · ' + needs.length + ' on your list' : '') : '';
231
+ if (!block) return { mode: 'clear', time: hm(new Date(now).toISOString()), line: 'All clear.' + (tomorrow ? ' Tomorrow: ' + tomorrow.charAt(0).toLowerCase() + tomorrow.slice(1) + '.' : '') };
232
+ const waits = block.ini && block.ini !== 'product' ? titleOf(block.ini) : '';
233
+ return { mode: 'eod', time: hm(new Date(now).toISOString()), block, blockLine: block.name + ' still waits on you.', why: waits && waits !== block.name ? waits + ' cannot move on without it.' : block.hint || '', later: !!(block.row && block.row.kind !== 'source'),
234
+ lines: [['Done', doneLine], ['Overnight', over], ['Tomorrow', tomorrow]].filter((x) => x[1]) };
235
+ }
236
+ const load = dayLoad(t, now);
237
+ return { mode: 'day', load };
238
+ }
239
+
240
+ /* ── the weekly review ── */
241
+ /** Open initiatives with no change for `days` days or more, the longest first: { id, title, stage, days, owner }. */
242
+ export function staleInis(D, now = Date.now(), days = STALE_DAYS) {
243
+ return boardRows(D).filter(OPEN).filter((r) => !/^(Deliver|Monitor|Evaluate)$/.test(String(r.stage || '')) && r.updated && !Number.isNaN(Date.parse(r.updated)))
244
+ .map((r) => ({ id: r.id, title: r.title, stage: r.stage || '', days: Math.floor((now - Date.parse(r.updated)) / 86400000), owner: r.owner || null, life: (r.acts && r.acts.life) || null }))
245
+ .filter((r) => r.days >= days && r.life !== 'on-hold').sort((a, b) => b.days - a.days);
246
+ }
247
+ export const REVIEW_STEPS = [['sort', 'Sort what came in'], ['wait', 'Check what you wait on'], ['untouched', 'Look at untouched work'], ['pick', "Pick next week's three"]];
248
+ /** The review of this week: { week, label, steps: [{ key, label, done, now, note, n }], at (the step on now), last, kept } */
249
+ export function reviewModel(D, now = Date.now()) {
250
+ const R = (D.review && D.review.ok) ? D.review : { steps: {}, kept: {}, last: null };
251
+ const W = D.work || null;
252
+ const tab = (k) => ((W && W.queue && W.queue.tabs) || []).find((t) => t.key === k) || { n: 0, groups: [] };
253
+ const n = { sort: tab('inbox').n || 0, wait: W && W.waiting ? W.waiting.rows.length : 0, untouched: staleInis(D, now).length + ((W && W.review && W.review.n) || 0), pick: 3 };
254
+ const steps = REVIEW_STEPS.map(([key, label]) => ({ key, label, done: !!(R.steps && R.steps[key]), note: (R.steps && R.steps[key] && R.steps[key].note) || '', n: n[key] }));
255
+ const at = steps.findIndex((s) => !s.done);
256
+ steps.forEach((s, i) => { s.now = i === at; });
257
+ const d = new Date(now);
258
+ return { week: R.week || '', label: d.getDate() + ' ' + MON[d.getMonth()], steps, at, done: at < 0, last: R.last || null, kept: R.kept || {}, open: d.getDay() === REVIEW_DAY && at >= 0, started: steps.some((s) => s.done) };
259
+ }
260
+
261
+ /* ── filing a typed task ── */
262
+ const words = (s) => String(s || '').toLowerCase().replace(/[^a-z0-9 ]+/g, ' ').split(/\s+/).filter((w) => w.length > 2);
263
+ /** The open initiative a typed line names: its id, or every word of its title (the longest title that matches), else null. */
264
+ export function fileUnder(text, inis) {
265
+ const t = String(text || '').toLowerCase(), tw = new Set(words(t));
266
+ let best = null, bestN = 0;
267
+ for (const r of inis || []) {
268
+ if (!r || !r.id) continue;
269
+ if (t.includes(String(r.id).toLowerCase())) return r.id;
270
+ const w = words(r.title);
271
+ if (w.length && w.length <= 6 && w.every((x) => tw.has(x)) && w.length > bestN) { best = r.id; bestN = w.length; }
272
+ }
273
+ return best;
274
+ }
275
+ export const dayOf = (now = Date.now()) => isoDay(now);
276
+ export const dowOf = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? DOW[new Date(+m[1], +m[2] - 1, +m[3]).getDay()] : ''; };
@@ -0,0 +1,132 @@
1
+ /* pm/home-more.js — the features the Agreed design does not draw yet, as plain minimal versions in the Viewer
2
+ * (initiative premium-agreed-design, Home: "keep every uncovered feature usable, in the cozy style, with a small Waiting for design marker").
3
+ *
4
+ * Each opens in the Viewer card (cozy-viewer.js), never the old dialog, and reads and writes through the routes the old pages used:
5
+ * openSettings() the designed Settings (pm/cozy-settings.js, premium-uncovered-features E3)
6
+ * openSources() the designed Sources (pm/cozy-sources.js, E3); readLine below gives its read lines
7
+ * openMyWork(tab) home-work.js: Your list, Waiting on others, Weekly review, Untouched; an item's fields and agent; Focus and jobs;
8
+ * keys and swipe on the rows (GET /api/my-work-premium; the /api/pm-items, /api/pm-jobs and /api/my-work presses)
9
+ * openAround(key?) home-around.js: Around you is gone (premium-uncovered-features, HmAround); its views stay, opened from New for you
10
+ * openEndOfDay() GET /api/phone-day: what finished today, the recap and tomorrow's meetings
11
+ * openProducts() which products Home reads (GET /api/briefing-premium products, POST /api/settings ws.briefing.include)
12
+ * openSearch(go) the designed Search (pm/cozy-search.js, E1): the repository and every worktree
13
+ * openInbox(go) New for you (pm/cozy-news.js, E2), which replaces the agents' results
14
+ * openRecorder() a note recorded now with no calendar event (the Viewer's newNote, else POST /api/notes/new)
15
+ * moreItems the ⋯ menu's rows, [key, label, icon]: the features the place menu does not hold (Search, New for you, Sources and
16
+ * Settings are in the place menu, cozy-nav.js)
17
+ * Every write is the PM's press (pmPost carries the launch nonce). Nothing here sends anything outside PMOS. */
18
+ import { pmGet, pmPost } from './http.js';
19
+ import { open as vwOpen } from './cozy-viewer.js';
20
+
21
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
22
+ const wsQ = (pre = '?') => { const w = new URLSearchParams(location.search).get('ws'); return w ? pre + 'ws=' + encodeURIComponent(w) : ''; };
23
+ export const WAIT = '<p class="hx-wait"><i aria-hidden="true"></i>Waiting for design</p>';
24
+ const toast = (t) => { const el = document.getElementById('toast'); if (!el) return; el.textContent = t; el.classList.add('on'); clearTimeout(toast.t); toast.t = setTimeout(() => el.classList.remove('on'), 4200); };
25
+ const when = (iso) => { const d = new Date(iso); if (Number.isNaN(d.getTime())) return ''; const p = (n) => String(n).padStart(2, '0'); return (d.toDateString() === new Date().toDateString() ? '' : d.getDate() + ' ' + d.toLocaleString('en-GB', { month: 'short' }) + ' ') + p(d.getHours()) + ':' + p(d.getMinutes()); };
26
+ const row = (title, sub, right = '') => `<div class="hx-row"><span class="hx-t"><b>${esc(title)}</b>${sub ? `<em>${esc(sub)}</em>` : ''}</span>${right}</div>`;
27
+ const btn = (label, attrs, pri) => `<button type="button" class="hx-b${pri ? ' pri' : ''}" ${attrs}>${esc(label)}</button>`;
28
+ const sec = (h, inner) => `<section class="hx-sec"><h4>${esc(h)}</h4>${inner}</section>`;
29
+ /** Open one feature in the Viewer: draw(body) is called again after each press. */
30
+ function card(o, draw) {
31
+ return vwOpen({ id: 'more:' + o.id, kind: o.kind, title: o.title, icon: o.icon, render: (body) => { body.classList.add('hx'); draw(body); } });
32
+ }
33
+
34
+ export const moreItems = [
35
+ ['work', 'My work', 'list'], ['eod', 'End of the day', 'cal'], ['cal', 'Calendar', 'cal'], ['rec', 'Record a note', 'mic'], ['products', 'Products', 'chart'],
36
+ ];
37
+
38
+ /** The ⋯ list itself in the Viewer, for a page with no menu of its own: items are [label, open]. */
39
+ export function listCard(items) {
40
+ return card({ id: 'more', kind: 'More', title: 'Waiting for design', icon: 'list' }, (b) => {
41
+ b.innerHTML = WAIT + items.map(([l], i) => `<button type="button" class="hx-hit" data-i="${i}"><b>${esc(l)}</b></button>`).join('');
42
+ b.onclick = (e) => { const t = e.target.closest('[data-i]'); if (t && items[+t.dataset.i][1]) items[+t.dataset.i][1](); };
43
+ });
44
+ }
45
+
46
+ /* ── Settings ── the designed dialog (pm/cozy-settings.js) */
47
+ export function openSettings(section) { return import('./cozy-settings.js').then((M) => M.openSettings(section)); }
48
+
49
+ /* ── Sources ── */
50
+ /** A read line: "<source> read HH:MM" for each id, from one GET /api/sources answer. ids name freshness rows ('initiatives', 'calendar', …)
51
+ * or derived content ('d:brief'). A source never read or failed says so. */
52
+ export function readLine(s, ids) {
53
+ if (!s || !s.ok) return '';
54
+ return ids.map((id) => {
55
+ const der = id.startsWith('d:'), x = der ? (s.derived || []).find((d) => d.id === id.slice(2)) : (s.sources || []).find((r) => r.id === id);
56
+ if (!x) return null;
57
+ const at = der ? x.at : x.as_of;
58
+ const w = x.state === 'failed' ? 'failed' : at ? (der ? 'built ' : 'read ') + when(at) : x.state === 'off' ? 'off' : der ? 'not built yet' : 'not read yet';
59
+ return (der ? ({ brief: 'Brief' })[x.id] || x.label : x.label) + ' ' + w;
60
+ }).filter(Boolean).join(' · ');
61
+ }
62
+ /** Sources: the designed card in the Viewer (pm/cozy-sources.js). */
63
+ export function openSources() { return import('./cozy-sources.js').then((M) => M.openSources()); }
64
+
65
+ /* ── My work ── */
66
+ /* ── My work ── the four tabs, the item with its fields and its agent, Focus and jobs, and the keys and swipe on the rows, in home-work.js */
67
+ export function openMyWork(tab = 'yours') { return import('./home-work.js').then((M) => M.openMyWork(tab)); }
68
+
69
+ /* ── Around you ── gone (HmAround): its parts have one home each, and New for you names them. key opens one of its views (home-around.js). */
70
+ export function openAround(key) { return import('./home-around.js').then((M) => M.openAround(key)); }
71
+
72
+ /* ── End of the day ── */
73
+ export function openEndOfDay() {
74
+ const M = { r: null };
75
+ const draw = (b) => {
76
+ const r = M.r;
77
+ if (!r) { b.innerHTML = WAIT + '<p class="hx-n">Reading the day.</p>'; return; }
78
+ if (!r.ok) { b.innerHTML = WAIT + `<p class="hx-n">The day could not be read${r.error ? ': ' + esc(r.error) : ''}.</p>`; return; }
79
+ const fin = (r.finished || []).map((f) => row(f.title, f.status === 'review' ? 'Waits for your review' : f.status)).join('') || '<p class="hx-n">Nothing finished for you today.</p>';
80
+ const rec = r.recap ? (r.recap.moved || []).map((m) => row(m.text, m.sub)).join('') || '<p class="hx-n">No decision, done item or draft today.</p>' : '';
81
+ const tom = r.tomorrow ? (r.tomorrow.meetings || []).map((m) => row(m.title, new Date(m.start).toTimeString().slice(0, 5))).join('') || '<p class="hx-n">No meeting.</p>' : '';
82
+ b.innerHTML = WAIT + sec('Finished for you', fin) + sec('How the day went', rec) + sec(r.tomorrow ? 'Tomorrow · ' + r.tomorrow.label : 'Tomorrow', tom);
83
+ };
84
+ const body = card({ id: 'eod', kind: 'End of the day', title: 'Today and tomorrow', icon: 'cal' }, draw);
85
+ pmGet('/api/phone-day').then((r) => { M.r = r || { ok: false }; if (body.isConnected) draw(body); });
86
+ return body;
87
+ }
88
+
89
+ /* ── Products ── */
90
+ export function openProducts() {
91
+ const M = { P: null, head: '', msg: '' };
92
+ const one = new URLSearchParams(location.search).get('ws'); // Home narrowed to one workspace (?ws=): a way back to the picked products
93
+ const draw = (b) => {
94
+ const P = M.P, on = P ? P.available.filter((x) => x.on).length : 0;
95
+ b.innerHTML = WAIT + (M.head ? `<p class="hx-n" id="hxSnap">${esc(M.head)}</p>` : '')
96
+ + (one ? '<p class="hx-n">Home shows one workspace now. <a id="pickAll" href="/premium.html">All picked products</a></p>' : '')
97
+ + (!P ? '<p class="hx-n">Reading the products.</p>' : !P.available.length ? '<p class="hx-n">No product workspace is registered.</p>'
98
+ : sec('Home reads', `<p class="hx-n" id="hxCount">Products ${on} of ${P.available.length}</p>` + P.available.map((x) => row(x.name, x.home ? 'home' : '', `<button type="button" class="hx-sw" role="switch" aria-checked="${!!x.on}" aria-label="${esc(x.name)}${x.home ? ' (home)' : ''}" data-ws="${esc(x.ws)}">${x.on ? 'On' : 'Off'}</button>`)).join('') + btn('Back to the default', 'data-reset="1"')))
99
+ + `<p class="hx-n" role="status">${esc(M.msg)}</p>`;
100
+ };
101
+ const body = card({ id: 'products', kind: 'Products', title: 'Which products Home reads', icon: 'chart' }, draw);
102
+ const read = async () => {
103
+ const r = await pmGet('/api/briefing-premium');
104
+ M.P = r && r.ok && r.model ? r.model.products || { available: [] } : { available: [] };
105
+ M.head = r && r.ok && r.model && r.model.header ? r.model.header.text : ''; // what is read and what is not, from the records
106
+ if (body.isConnected) draw(body);
107
+ };
108
+ body.onclick = async (e) => {
109
+ const t = e.target.closest('button'); if (!t || !M.P) return;
110
+ const on = M.P.available.filter((x) => x.on).map((x) => x.ws);
111
+ const r = await pmPost('/api/settings', t.dataset.reset ? { key: 'ws.briefing.include', reset: true } : { key: 'ws.briefing.include', value: on.includes(t.dataset.ws) ? on.filter((x) => x !== t.dataset.ws) : on.concat(t.dataset.ws) });
112
+ M.msg = r && r.ok ? 'Saved. Home reads the products you picked.' : (r && r.error) || 'Not saved.';
113
+ read(); window.dispatchEvent(new CustomEvent('hm:reload'));
114
+ };
115
+ read();
116
+ return body;
117
+ }
118
+
119
+ /* ── Search ── the designed palette (pm/cozy-search.js); go is the page's own opener for an initiative ({ ini }), a session ({ ses }) or a file ({ doc }) */
120
+ export function openSearch(go) { return import('./cozy-search.js').then((M) => M.openSearch({ go })); }
121
+
122
+ /* ── New for you ── it replaces the agents' results (the bell) and Around you (pm/cozy-news.js) */
123
+ export function openInbox(go) { return import('./cozy-news.js').then((M) => M.openNews({ go })); }
124
+
125
+ /* ── record a note now ── */
126
+ export async function openRecorder() {
127
+ // the Viewer's registry (premium-vw-open.js): newNote starts an untitled note now, the recorder starts and the meeting card opens on it
128
+ await import('./premium-vw-open.js');
129
+ const ws = new URLSearchParams(location.search).get('ws') || '';
130
+ try { const r = await window.czViews.newNote({ ws }); if (r && r.ok === false && r.error) toast(r.error); return r; }
131
+ catch { toast('The note was not started.'); return null; }
132
+ }
@@ -0,0 +1,109 @@
1
+ /* pm/home-phone-card.js — the phone moment card, moved onto Home (initiative premium-agreed-design; the card itself is premium-phone-card,
2
+ * planning/prd/premium-phone-card-prd.md R1 to R5). On a phone it is the Today card at the top of the list (canvas HmPhone and HmPhone2):
3
+ * the moment of the day, in the card's shape. At 640 px and narrower only; a desktop never reads /api/phone-day.
4
+ * The moment comes from momentOf (c3-phone-model.js) over the /api/brief-page day and the clock; every line comes from /api/brief-page or
5
+ * /api/phone-day. Done and Undo press /api/pm-items/done and /reopen on the PM's own item; nothing is written on load.
6
+ * mountPhoneCard({ pmGet, pmPost, toast, ws, openMeeting }) → { el, read } */
7
+ import { momentOf, inText } from './phone-moment.js';
8
+
9
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
10
+ const two = (n) => String(n).padStart(2, '0');
11
+ const hm = (iso) => { const d = new Date(iso); return two(d.getHours()) + ':' + two(d.getMinutes()); };
12
+ const first = (n) => String(n || '').trim().split(/\s+/)[0];
13
+ const who = (m) => (m.people && m.people.length ? m.people.map(first).join(', ') : '');
14
+ const num = (n, one, many) => (n === 1 ? '1 ' + one : (n || 0) + ' ' + many);
15
+ const CHECK = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>';
16
+ const PHONE = '(max-width:640px)';
17
+
18
+ export function mountPhoneCard(o) {
19
+ const P = { page: null, day: null, dayAt: 0, dec: new Map(), err: {}, busy: '' };
20
+ const on = () => matchMedia(PHONE).matches;
21
+ const el = document.createElement('section');
22
+ el.className = 'hm-phc'; el.id = 'phoneCard'; el.hidden = true; el.setAttribute('aria-label', 'Now');
23
+
24
+ const own = () => ((P.page && P.page.ok && P.page.needs) || []).filter((n) => n && n.id && (n.kind === 'overdue' || n.kind === 'due-today'))
25
+ .map((n) => ({ id: n.id, headline: n.headline, label: n.kind === 'overdue' ? (n.days_late === 1 ? '1 day late' : n.days_late + ' days late') : 'Due today', kind: n.kind, looks: !!(n.evidence && n.evidence.text) }));
26
+ const btn = (label, act, id, alt) => `<button type="button" class="cta${alt ? ' alt' : ''}" data-pha="${act}"${id != null ? ` data-id="${esc(id)}"` : ''}>${esc(label)}</button>`;
27
+ const item = (n) => {
28
+ const act = P.dec.has(n.id) ? `<p class="phok" role="status">${CHECK}<span>Done.</span></p><div class="phacts">${btn('Undo', 'phundo', n.id, true)}</div>` : `<div class="phacts">${btn(n.looks ? 'Confirm done' : 'Done', 'phdone', n.id)}</div>`;
29
+ return `<div class="phfit" data-id="${esc(n.id)}"><span class="label">${esc(n.label)}</span><b class="phtt">${esc(n.headline)}</b>${act}${P.err[n.id] ? `<p class="pherr" role="alert">${esc(P.err[n.id])}</p>` : ''}</div>`;
30
+ };
31
+ const items = (list) => list.concat([...P.dec.values()].filter((x) => !list.some((y) => y.id === x.id))).map(item).join('');
32
+ const open = (m) => btn('Open the meeting', 'phopen', m.id, true);
33
+ const big = (t) => `<b class="phbig">${esc(t)}</b>`;
34
+ const L = (t) => `<p class="phl">${esc(t)}</p>`, S = (t) => `<p class="phs">${esc(t)}</p>`;
35
+ const dayErr = () => (P.day && P.day.ok === false ? S('Today could not be read: ' + P.day.error + '.') : !P.day ? S('Reading your day.') : '');
36
+
37
+ function moment(mo) {
38
+ const m = mo.meeting, mine = own(), day = P.day && P.day.ok !== false ? P.day : null, fin = day ? day.finished || [] : [];
39
+ const waits = mine.length ? num(mine.length, 'item of yours waits', 'items of yours wait') + '.' : 'Nothing of yours is due.';
40
+ const finRows = (n) => fin.slice(0, n).map((t) => `<div class="phfit"><span class="label">${t.status === 'review' ? 'Waits for you' : t.status === 'sent' ? 'Sent' : 'Finished'}</span><b class="phtt">${esc(t.title)}</b><p class="phs">${esc(t.summary)}</p></div>`).join('');
41
+ const fits = (list) => items(list.map((n) => mine.find((x) => x.id === n.id)).filter(Boolean));
42
+ if (mo.kind === 'meeting') return `<span class="label">Under way · ends ${esc(inText(mo.minutes))}</span>${big(m.title)}${who(m) ? L(who(m)) : ''}<div class="phacts">${open(m)}</div>`;
43
+ if (mo.kind === 'before') {
44
+ const prep = (m.prepared || []).slice(0, 3).map((x) => S(x.text)).join('') || S('Nothing is prepared for it.');
45
+ const bf = (m.before || []).filter((x) => x && x.id && !x.done).map((x) => ({ id: x.id, headline: x.title, label: 'Before you go', kind: 'before' }));
46
+ const line = [who(m), m.initiative].filter(Boolean).join(' · ');
47
+ return `<span class="label">Starts ${esc(inText(mo.minutes))} · ${hm(m.start)}</span>${big(m.title)}${line ? L(line) : ''}${prep}${items(bf)}<div class="phacts">${open(m)}</div>`;
48
+ }
49
+ if (mo.kind === 'after') return `<span class="label">Just ended · ${hm(m.end || m.start)}</span>${big(m.title)}${S('The notes of this meeting, if there are any, are in the meeting.')}<div class="phacts">${open(m)}</div>`;
50
+ if (mo.kind === 'gap') return `<span class="label">Until ${esc(mo.next.title)} at ${hm(mo.next.start)}</span>${big(mo.minutes + ' free minutes')}${mo.fits.length ? fits(mo.fits) : L('Nothing of yours is due. A good moment to prepare the next meeting.')}`;
51
+ if (mo.kind === 'morning') {
52
+ const top = mine.slice(0, 3);
53
+ const nx = mo.next ? `<div class="phfit"><b class="phtt">First up: ${esc(mo.next.title)} at ${hm(mo.next.start)}</b><p class="phs">${esc(inText((Date.parse(mo.next.start) - Date.now()) / 60000).replace(/^in/, 'In'))}${who(mo.next) ? ' · ' + esc(who(mo.next)) : ''}</p><div class="phacts">${open(mo.next)}</div></div>` : S('No meetings today.');
54
+ return `<span class="label">Your morning</span>${big(top.length ? ['', 'One thing', 'Two things', 'Three things'][top.length] + ' this morning' : 'Nothing pressing this morning')}${items(top)}${S(waits)}${nx}`;
55
+ }
56
+ if (mo.kind === 'work') return `<span class="label">${mo.next ? 'Next: ' + esc(mo.next.title) + ' at ' + hm(mo.next.start) : 'No more meetings today'}</span>${big(fin.length ? 'Finished for you' : 'Nothing new from the agent')}${fin.length ? finRows(2) + S('Approving a draft waits for your computer.') : dayErr() || S('When the agent finishes a draft today, it shows here.')}${mo.fits.length ? fits(mo.fits) : ''}${mo.next ? `<div class="phacts">${open(mo.next)}</div>` : ''}`;
57
+ if (mo.kind === 'recap') {
58
+ const r = day && day.recap, one = mine[0];
59
+ const stats = r ? `<div class="phstats"><div><b>${r.meetings || 0}</b><span>meetings</span></div><div><b>${r.decided || 0}</b><span>decided in meetings</span></div><div><b>${r.done || 0}</b><span>done by you</span></div></div>${(r.moved || []).length ? `<div class="phfit"><b class="phtt">What moved</b>${r.moved.map((x) => `<p class="phs">${esc(x.text)}${x.sub ? ' · ' + esc(x.sub) : ''}</p>`).join('')}</div>` : ''}` : dayErr();
60
+ return `<span class="label">Evening recap</span>${big('How today went')}${stats}<div class="phfit"><b class="phtt">Still open · ${mine.length}</b>${mine.slice(0, 3).map((x) => S(x.headline)).join('')}${S(mine.length ? 'They come first on Home tomorrow.' : 'Nothing of yours is still open.')}</div>${one ? `<div class="phfit"><span class="label">One thing tonight, if you have a minute</span>${items([one])}</div>` : ''}`;
61
+ }
62
+ const r = day && day.recap, tm = day && day.tomorrow;
63
+ return `<span class="label">End of day</span>${big(tm ? 'Tomorrow, ' + tm.label : 'Tomorrow, at a glance')}${r ? L('Today: ' + [num(r.meetings, 'meeting', 'meetings'), num(r.decided, 'decision', 'decisions'), num(r.done, 'item done', 'items done')].join(', ') + '.') : ''}${tm ? `<div class="phfit"><b class="phtt">${tm.meetings.length ? num(tm.meetings.length, 'meeting', 'meetings') : 'No meetings'}</b>${tm.meetings.slice(0, 5).map((x) => `<p class="phs">${hm(x.start)} · ${esc(x.title)}${who(x) ? ' · ' + esc(who(x)) : ''}</p>`).join('')}</div>` : dayErr()}${S(mine.length ? num(mine.length, 'item carries', 'items carry') + ' over. They open first on Home tomorrow.' : 'Nothing carries over.')}`;
64
+ }
65
+ const momentNow = () => momentOf({ today: P.page.today || [], needs: own(), now: new Date() });
66
+ function draw(focus) {
67
+ el.hidden = !on(); if (el.hidden) return;
68
+ let h;
69
+ if (!P.page) h = '<span class="label">Now</span><p class="phl">Reading your day.</p>';
70
+ else if (!P.page.ok) h = `<span class="label">Now</span><p class="pherr" role="alert">Your day could not be read: ${esc(P.page.error || 'the workspace server did not answer')}.</p>`;
71
+ else { const mo = momentNow(); el.dataset.moment = mo.kind; h = moment(mo); }
72
+ el.innerHTML = h;
73
+ if (focus) { const f = el.querySelector(focus); if (f) f.focus(); }
74
+ }
75
+ async function read(force) {
76
+ if (!on()) { draw(); return; }
77
+ const ws = o.ws && o.ws();
78
+ P.page = (await o.pmGet('/api/brief-page' + (ws ? '?ws=' + encodeURIComponent(ws) : '')).catch(() => null)) || { ok: false, error: 'the workspace server did not answer' };
79
+ const mo = P.page.ok ? momentNow() : null;
80
+ if (mo && ['work', 'recap', 'night'].includes(mo.kind) && (force || !P.day || Date.now() - P.dayAt > 300000)) { P.day = (await o.pmGet('/api/phone-day').catch(() => null)) || { ok: false, error: 'the workspace server did not answer' }; P.dayAt = Date.now(); }
81
+ draw();
82
+ }
83
+ el.onclick = async (e) => { // delegated: every press is a <button data-pha>
84
+ const b = e.target.closest('[data-pha]'); if (!b || P.busy) return;
85
+ const act = b.dataset.pha, id = b.dataset.id;
86
+ if (act === 'phopen') {
87
+ const m = ((P.page && P.page.today) || []).find((x) => x.id === id);
88
+ if (!m) { o.toast('PMOS does not hold that meeting any more, so it could not be opened.'); return; }
89
+ try { await o.openMeeting(m); } catch { o.toast('The meeting could not be opened.'); }
90
+ return;
91
+ }
92
+ const n = own().find((x) => x.id === id) || P.dec.get(id) || ((P.page && P.page.today) || []).flatMap((x) => x.before || []).map((x) => ({ id: x.id, headline: x.title, label: 'Before you go', kind: 'before' })).find((x) => x.id === id);
93
+ if (!n) return;
94
+ P.busy = id; b.disabled = true; delete P.err[id];
95
+ const r = await o.pmPost(act === 'phdone' ? '/api/pm-items/done' : '/api/pm-items/reopen', { id }).catch(() => null);
96
+ P.busy = '';
97
+ const sel = `.phfit[data-id="${CSS.escape(id)}"] button`;
98
+ if (!r || r.ok === false) { P.err[id] = 'That did not go through' + (r && r.error ? ': ' + r.error : '.'); draw(sel); return; }
99
+ if (act === 'phdone') { P.dec.set(id, n); o.toast('Done: ' + n.headline); } else { P.dec.delete(id); o.toast('Reopened: ' + n.headline); }
100
+ draw(sel);
101
+ await read(true); draw(sel);
102
+ };
103
+ const mq = matchMedia(PHONE), again = () => { if (!document.hidden) read(); };
104
+ if (mq.addEventListener) mq.addEventListener('change', again); else mq.addListener(again);
105
+ document.addEventListener('visibilitychange', again);
106
+ setInterval(() => { if (!document.hidden && on()) read(true); }, 60000);
107
+ read();
108
+ return { el, read };
109
+ }