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,312 @@
1
+ /* pm/home-data.js — Home's models, pure (initiative premium-agreed-design, Home; mockup Main.dc.html place="work", AgHome*, AgInit*, AgProduct, AgChat*).
2
+ *
3
+ * Home is one desk: the list on the left, the chat in the middle and the Viewer on the right. This file turns what the routes answer into what
4
+ * the desk draws, and touches no page, so a node test imports it:
5
+ * homeLists(D) the Home list: Needs you (top 3 + "N more"), Initiatives (the product first) and Loose, each row with its kids
6
+ * iniLayout(D, id) one initiative as a layout of Home: its card's groups (Needs you, Sessions, Stakeholders, Meetings, Routines, Files,
7
+ * Finished sessions) and the Elsewhere line
8
+ * productCard(D) the product's card: "This week", the KRs and the budget on track or at risk, Then, the next routine, the CTA
9
+ * weeklyUpdate(D) the weekly update the Viewer shows and Send turns into a mail draft: On track, At risk, Needs a decision
10
+ * streamOf(conv, o) the chat's stream: day dividers, "New since you left", "N earlier messages", messages, Worked-for folds
11
+ * meetLineOf(P) the meeting line: the current or next meeting, +N for the rest of the day
12
+ * roleOf(s, roles) an agent's role name and initial for a session ("Claude" when no skill names one)
13
+ * D is { brief, board, sessions, desk, trail, today, schedules, now }: the answers of GET /api/briefing-premium, /api/board-premium,
14
+ * /api/sessions, /api/home-desk, /api/board-trail, /api/brief-page and /api/schedules. A part that did not answer is left out, never guessed. */
15
+
16
+ export const ICON = {
17
+ chat: 'M4 5h16v11H9l-5 4z', doc: 'M7 3h7l5 5v13H7zM14 3v5h5', goal: 'M5 21V4M5 4h12l-2 4 2 4H5',
18
+ routine: 'M4 12a8 8 0 0 1 14-5.3M20 4v4h-4M20 12a8 8 0 0 1-14 5.3M4 20v-4h4', person: 'M12 12a4 4 0 1 0 0-8a4 4 0 1 0 0 8M4 21a8 8 0 0 1 16 0',
19
+ product: 'M4 20V10M10 20V4M16 20v-8M22 20H2', auto: 'M12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6M12 2v3M12 19v3M2 12h3M19 12h3',
20
+ clock: 'M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18M12 7v5l3 2', ticket: 'M4 5h16v14H4zM8 10h8M8 14h5',
21
+ gate: 'M12 3l8 4v5c0 5-3.5 8-8 9c-4.5-1-8-4-8-9V7zM8.5 12l2.5 2.5 4.5-5', warn: 'M12 4l9 16H3zM12 10v4M12 17v.5',
22
+ };
23
+ /** The two-letter avatars the mockup tints (AGENT_TINT); any other initial takes the O tint. */
24
+ export const TINTS = ['C', 'St', 'Re', 'Sp', 'Ev', 'De', 'Dl', 'Co', 'Bu', 'Ka', 'O', 'An', 'Di', 'Bi'];
25
+ export const tintOf = (k) => (TINTS.includes(k) ? k : 'O');
26
+
27
+ export const STAGES = ['Triage', 'Discover', 'Plan', 'Prioritize', 'Build', 'Deliver', 'Monitor', 'Evaluate'];
28
+ const RANK = { needs: 4, blocked: 3, working: 2, quiet: 1 };
29
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
30
+ const DOW = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
31
+ const pad = (n) => String(n).padStart(2, '0');
32
+ export const hm = (iso) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? '' : pad(d.getHours()) + ':' + pad(d.getMinutes()); };
33
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
34
+ const cap1 = (s) => (s ? String(s).charAt(0).toUpperCase() + String(s).slice(1) : '');
35
+
36
+ /* ── roles ── */
37
+ const DEFAULT_ROLE = { key: 'claude', name: 'Claude', initial: 'C' };
38
+ /** The role of a session: the server's (from the skill that started it), else the first slash command of the conversation, else Claude. */
39
+ export function roleOf(s, roles, first) {
40
+ if (s && s.role && s.role.key && s.role.key !== 'claude') return s.role;
41
+ const m = /^\s*\/([a-z0-9][a-z0-9._-]{0,60})/i.exec(String(first || ''));
42
+ if (m && Array.isArray(roles)) {
43
+ for (const r of roles) if ((r.patterns || []).some((p) => { try { return new RegExp(p).test(m[1].toLowerCase()); } catch { return false; } })) return { key: r.key, name: r.name, initial: r.initial };
44
+ }
45
+ return (s && s.role) || DEFAULT_ROLE;
46
+ }
47
+
48
+ /* ── sessions ── */
49
+ /** A session's conversation key ("init:viewer" from origin "chat:init:viewer"), or null for a session that is not a chat. */
50
+ export const keyOfSession = (s) => (s && /^chat:/.test(String(s.origin || '')) ? String(s.origin).slice(5) : null);
51
+ /** The initiative a session works on: its record, else its chat key (init:<id> or init:<id>:<n>), else none. */
52
+ export function iniOfSession(s) {
53
+ if (s && s.initiative) return s.initiative;
54
+ const k = keyOfSession(s); const m = k && /^(?:init|board):([^:]+)/.exec(k);
55
+ return m ? m[1] : null;
56
+ }
57
+ const stateOf = (s) => (s.shown === 'needs' ? 'needs' : s.shown === 'blocked' ? 'blocked' : s.shown === 'working' ? 'working' : s.shown === 'exited' ? 'exited' : 'quiet');
58
+ export function sessionRow(s, roles) {
59
+ const role = roleOf(s, roles);
60
+ const st = stateOf(s);
61
+ const name = s.hx && s.hx.title ? s.hx.title : s.name || 'Session';
62
+ return { id: 's:' + s.id, kind: 'session', sid: s.id, key: keyOfSession(s), ini: iniOfSession(s), name, state: st, initial: role.initial, role,
63
+ hint: role.name + ' · ' + (s.label || (st === 'working' ? 'Running' : st === 'needs' ? 'Ready for you' : 'Idle')), icon: 'chat', created: s.created || '' };
64
+ }
65
+
66
+ /* ── needs you ── */
67
+ const NEED_ICON = { decision: 'gate', blocked: 'warn', waited: 'clock', src: 'doc', ev: 'gate' };
68
+ function needRow(r) {
69
+ return { id: 'n:' + r.key, kind: 'need', key: r.key, ini: (r.from || [])[0] || null, name: r.title, hint: [r.product, r.subject || r.prepared, r.kind === 'source' && r.subject && !/^No .* is on record\.$/.test(r.prepared || '') ? r.prepared : ''].filter(Boolean).join(' · '), product: r.product || null, state: r.kind === 'blocked' ? 'blocked' : 'needs',
70
+ icon: NEED_ICON[r.kind] || 'gate', row: r };
71
+ }
72
+ /** Every row that waits on the PM: the Briefing's list, then each session that is ready for you or may be blocked (its shown state, from the server). */
73
+ export function needsOf(D) {
74
+ const rows = ((D.brief && D.brief.list && D.brief.list.rows) || []).map(needRow);
75
+ for (const s of D.sessions || []) {
76
+ if (s.shown !== 'needs' && s.shown !== 'blocked') continue;
77
+ const r = sessionRow(s, D.desk && D.desk.roles); rows.push({ ...r, id: 'n:s:' + s.id, needSession: true });
78
+ }
79
+ // the product's weekly update: drafted from the board each week, it waits on the PM until it is sent (a sent record for this week)
80
+ if (boardRows(D).length) {
81
+ const P = (D.desk && D.desk.product) || {}, wk = weekOf(D.now || Date.now());
82
+ if (!(P.sent || []).some((x) => x.week === wk.iso)) {
83
+ const rt = nextRoutine(D, D.now || Date.now(), /comm|update|weekly|status|stakeholder/i);
84
+ rows.push({ id: 'n:update', kind: 'update', key: UPDATE_KEY, ini: 'product', name: 'Weekly update · ready to send', hint: 'Communicator · ' + (rt ? 'goes out ' + rt.when : 'send it when it reads right'), state: 'needs', icon: 'doc', initialRole: 'Co' });
85
+ }
86
+ }
87
+ return rows;
88
+ }
89
+ export const UPDATE_KEY = 'chat:weekly-update';
90
+
91
+ /* ── initiatives ── */
92
+ export const boardRows = (D) => (D.board && D.board.initiatives && D.board.initiatives.list && D.board.initiatives.list.rows) || (D.board && D.board.rows) || [];
93
+ export const live = (s) => s.shown !== 'exited' && s.state !== 'exited';
94
+ /** The kids of one initiative: its needs, its live sessions and today's meetings about it, the loudest first. */
95
+ export function kidsOf(D, id) {
96
+ const needs = needsOf(D).filter((r) => r.ini === id && !r.needSession);
97
+ const ses = (D.sessions || []).filter((s) => live(s) && iniOfSession(s) === id).map((s) => sessionRow(s, D.desk && D.desk.roles));
98
+ const meet = todayOf(D).filter((m) => meetIni(m) === id && m.state !== 'past').map((m) => ({ id: 'm:' + (m.id || m.title), kind: 'meeting', ini: id, name: m.title, hint: (m.state === 'now' ? 'Now' : hm(m.start)) + ' meeting', state: 'quiet', icon: 'clock', meeting: m }));
99
+ return [...needs, ...ses, ...meet].sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0));
100
+ }
101
+ export function kidsChip(kids) {
102
+ const need = kids.filter((x) => x.state === 'needs' || x.state === 'blocked').length, run = kids.filter((x) => x.state === 'working').length;
103
+ return { text: need ? (need === 1 ? 'your turn' : need + ' next steps') : run ? run + ' running' : String(kids.length), loud: need > 0 };
104
+ }
105
+ const TURN = (r, kids) => (kids.some((k) => k.state === 'needs' || k.state === 'blocked') ? 'your turn' : kids.some((k) => k.state === 'working') ? 'agents working' : /stalled|hold/i.test(String(r.status || '') + ' ' + String((r.acts && r.acts.life) || '')) ? 'stalled' : r.late ? 'late' : '');
106
+ function iniRow(D, r) {
107
+ const kids = kidsOf(D, r.id);
108
+ const st = kids.some((k) => k.state === 'needs') ? 'needs' : kids.some((k) => k.state === 'blocked') ? 'blocked' : kids.some((k) => k.state === 'working') ? 'working' : 'quiet';
109
+ return { id: 'i:' + r.id, kind: 'ini', ini: r.id, name: r.title, hint: [cap1(r.lane || 'feature'), r.stage, TURN(r, kids)].filter(Boolean).join(' · '), state: st, icon: 'goal', kids, chip: kids.length ? kidsChip(kids) : null, board: r };
110
+ }
111
+ export const OPEN = (r) => !(r.acts && (r.acts.archived || r.acts.life === 'done' || r.acts.life === 'cancelled'));
112
+
113
+ /* ── the product ── */
114
+ const statusOf = (r) => String(r.status || '').toLowerCase();
115
+ const risky = (r) => r.late || /risk|late|stalled|blocked/.test(statusOf(r));
116
+ const anchorOf = (r) => (r.kr ? r.kr : /^health:/.test(String(r.anchor || '')) ? String(r.anchor) : r.anchor ? String(r.anchor) : 'No anchor');
117
+ export function productName(D) {
118
+ const b = D.board && D.board.board;
119
+ return (b && (b.product || b.ws || b.name)) || (D.desk && D.desk.ws) || 'This product';
120
+ }
121
+ /** The product's KRs and budgets this week: one item per anchor, on track when none of its initiatives is late or at risk. */
122
+ export function productCard(D, now = Date.now()) {
123
+ const rows = boardRows(D).filter(OPEN);
124
+ const by = new Map();
125
+ for (const r of rows) { const a = anchorOf(r); if (!by.has(a)) by.set(a, []); by.get(a).push(r); }
126
+ const items = [...by.entries()].filter(([a]) => a !== 'No anchor').map(([a, L]) => {
127
+ const bad = L.filter(risky);
128
+ const lead = (bad[0] || L[0]);
129
+ const health = /^health:/.test(a);
130
+ const words = bad.length ? (bad[0].late ? 'running late' : /stalled/.test(statusOf(bad[0])) ? 'stalled' : statusOf(bad[0]) || 'at risk') : health ? 'within budget' : 'on track';
131
+ return { kind: bad.length ? 'risk' : 'ok', label: (health ? a : a + ' · ' + lead.title) + ' ' + (health && !bad.length ? '· within budget' : words), anchor: a, ids: L.map((x) => x.id) };
132
+ });
133
+ const krs = items.filter((x) => !/^health:/.test(x.anchor)).length, budgets = items.length - krs;
134
+ const ok = items.filter((x) => x.kind === 'ok').length;
135
+ const P = (D.desk && D.desk.product) || { recipients: [], sent: [] };
136
+ const to = P.recipients || [];
137
+ const wk = weekOf(now);
138
+ const sentThis = (P.sent || []).find((s) => s.week === wk.iso);
139
+ const rt = nextRoutine(D, now, /comm|update|weekly|status|stakeholder/i);
140
+ return {
141
+ name: productName(D) + ' · product', kind: 'Product · ' + plural(krs, 'KR', 'KRs') + (budgets ? ', ' + plural(budgets, 'budget', 'budgets') : ''),
142
+ stage: 'Week of ' + wk.label, title: 'This week', of: ok + ' of ' + items.length + ' on track', items,
143
+ turn: sentThis ? 'agents' : 'you',
144
+ payoff: to.length ? 'The update goes to ' + listWords(to) + '. It marks anything that looks green but is not.' : 'Say who the update goes to, then send it from your own mail. It marks anything that looks green but is not.',
145
+ time: rt ? 'Next routine: ' + rt.name + ' · ' + rt.when : 'No routine is scheduled for this product',
146
+ cta: sentThis ? 'Read the sent update' : 'Review the weekly update', sent: sentThis || null, week: wk,
147
+ };
148
+ }
149
+ const listWords = (a) => (a.length <= 1 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1]);
150
+ /** Monday of this week: { iso: 'YYYY-MM-DD', label: 'Oct 19' }. */
151
+ export function weekOf(now = Date.now()) {
152
+ const d = new Date(now); const day = (d.getDay() + 6) % 7; d.setDate(d.getDate() - day);
153
+ return { iso: d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()), label: MON[d.getMonth()] + ' ' + d.getDate() };
154
+ }
155
+ /** The weekly update's three sections from the board: each initiative once, with its stage and anchor and one line of why. */
156
+ export function weeklyUpdate(D, now = Date.now()) {
157
+ const rows = boardRows(D).filter(OPEN);
158
+ const trail = (D.trail && D.trail.items) || {}, usual = (D.trail && D.trail.usual) || {};
159
+ const needIds = new Set(needsOf(D).filter((r) => r.row && r.row.kind === 'decision').map((r) => r.ini));
160
+ const line = (r) => {
161
+ const t = trail[r.id], u = t && usual[String(r.stage || '').toLowerCase()];
162
+ const days = t && t.days != null ? 'In ' + r.stage + ' for ' + plural(t.days, 'day', 'days') : 'In ' + (r.stage || 'no stage');
163
+ const over = t && u && u.days != null && t.days > u.days ? ', ' + plural(t.days - u.days, 'day', 'days') + ' over its usual time' : '';
164
+ const fin = r.finish ? '. Planned finish ' + r.finish : '';
165
+ return days + over + fin + '.';
166
+ };
167
+ const item = (r) => ({ id: r.id, title: r.title, meta: [r.stage, anchorOf(r)].filter(Boolean).join(' · '), text: line(r), flag: r.late && !/late/.test(statusOf(r)) ? 'Looks green, but it is past its planned finish' : '' });
168
+ const decide = rows.filter((r) => needIds.has(r.id) || /stalled|hold/.test(statusOf(r)));
169
+ const risk = rows.filter((r) => !decide.includes(r) && risky(r));
170
+ const ok = rows.filter((r) => !decide.includes(r) && !risk.includes(r));
171
+ const P = (D.desk && D.desk.product) || {};
172
+ return { week: weekOf(now), to: P.recipients || [], sent: P.sent || [], sections: [['ok', 'On track', ok.map(item)], ['risk', 'At risk', risk.map(item)], ['decide', 'Needs a decision', decide.map(item)]] };
173
+ }
174
+ /** The update as mail text, for the mailto draft. */
175
+ export function updateText(U, name) {
176
+ const out = [name + ' · week of ' + U.week.label, ''];
177
+ for (const [, h, L] of U.sections) { if (!L.length) continue; out.push(h.toUpperCase()); for (const x of L) out.push('- ' + x.title + ' (' + x.meta + '): ' + x.text + (x.flag ? ' ' + x.flag + '.' : '')); out.push(''); }
178
+ out.push('Drafted in PMOS from the ladders and run logs.');
179
+ return out.join('\n');
180
+ }
181
+
182
+ /* ── routines and meetings ── */
183
+ const DOWN = { mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6, sun: 0 };
184
+ /** The soonest enabled schedule (matching `re` on its task or name when given): { name, when }. */
185
+ export function nextRoutine(D, now = Date.now(), re = null) {
186
+ const L = ((D.schedules && D.schedules.schedules) || []).filter((s) => s.enabled !== false && s.next);
187
+ const pick = (re ? L.filter((s) => re.test(String(s.task || s.skill || '') + ' ' + String(s.name || s.label || ''))) : L).sort((a, b) => Date.parse(a.next) - Date.parse(b.next))[0];
188
+ if (!pick) return null;
189
+ const d = new Date(pick.next);
190
+ return { name: cap1(String(pick.name || pick.label || pick.task || pick.skill || 'Routine').replace(/[-_]/g, ' ')), when: (d.toDateString() === new Date(now).toDateString() ? 'today' : DOW[d.getDay()]) + ' ' + hm(pick.next), s: pick };
191
+ }
192
+ export const todayOf = (D) => (D.today && D.today.ok && Array.isArray(D.today.today) ? D.today.today : []);
193
+ 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;
194
+ /** The line's words from the brief-page day: { meeting, more, note, time, aria } or null when no meeting is left today. */
195
+ export function meetLineOf(P) {
196
+ const t = P && P.ok && Array.isArray(P.today) ? P.today : [];
197
+ const left = t.filter((m) => m && m.state !== 'past');
198
+ const m = left.find((x) => x.state === 'now') || left.find((x) => x.state === 'next') || left[0];
199
+ if (!m) return null;
200
+ const todo = (m.before || []).filter((x) => x && !x.done).length;
201
+ const note = m.state === 'now' ? 'on now' : todo ? todo + ' to do before' : (m.prepared || []).length ? 'prep ready' : '';
202
+ const time = m.state === 'now' ? 'Now' : hm(m.start);
203
+ return { meeting: m, more: left.length - 1, note, time, aria: (m.state === 'now' ? 'Meeting on now: ' : 'Next meeting: ' + time + ' ') + m.title + (note ? ', ' + note : '') };
204
+ }
205
+
206
+ /* ── the Home list ── */
207
+ /** { needs: { rows, more }, initiatives, loose, needN } — loose are the chats and sessions with no initiative. */
208
+ export function homeLists(D, { allNeeds = false } = {}) {
209
+ const needs = needsOf(D);
210
+ const inis = boardRows(D).filter(OPEN).map((r) => iniRow(D, r));
211
+ inis.sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0));
212
+ const prod = boardRows(D).length ? productRow(D) : null;
213
+ const loose = (D.sessions || []).filter((s) => live(s) && !iniOfSession(s) && s.shown !== 'needs' && s.shown !== 'blocked').map((s) => ({ ...sessionRow(s, D.desk && D.desk.roles), loose: true }))
214
+ .sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0));
215
+ return { needs: { rows: allNeeds ? needs : needs.slice(0, 3), more: Math.max(0, needs.length - 3), all: needs.length }, initiatives: prod ? [prod, ...inis] : inis, loose, needN: needs.length };
216
+ }
217
+ function productRow(D) {
218
+ const P = productCard(D);
219
+ const risk = P.items.filter((x) => x.kind === 'risk').length;
220
+ const kids = needsOf(D).filter((r) => r.kind === 'update');
221
+ const upd = P.sent ? 'update sent' : 'update ready';
222
+ return { id: 'p:product', kind: 'product', name: P.name, hint: 'Product · ' + upd + (risk ? ', ' + risk + ' at risk' : ''), state: P.sent ? 'quiet' : 'needs', icon: 'product',
223
+ kids, chip: P.sent ? null : { text: 'your turn', loud: true } };
224
+ }
225
+
226
+ /* ── one initiative as a layout ── */
227
+ /** The groups under an initiative's card, and the Elsewhere line. */
228
+ export function iniLayout(D, id) {
229
+ const needs = needsOf(D);
230
+ const mine = needs.filter((r) => r.ini === id);
231
+ const ses = (D.sessions || []).filter((s) => iniOfSession(s) === id).map((s) => sessionRow(s, D.desk && D.desk.roles));
232
+ const people = (((D.desk && D.desk.stakeholders) || {})[id] || []).map((p) => ({ id: 'k:' + p.name, kind: 'person', name: p.name + (p.role ? ' · ' + p.role : ''), hint: p.note || 'Stakeholder', initial: initials(p.name), state: 'quiet', person: p }));
233
+ const meet = todayOf(D).filter((m) => meetIni(m) === id).map((m) => ({ id: 'm:' + (m.id || m.title), kind: 'meeting', name: m.title, hint: (m.state === 'now' ? 'Now' : hm(m.start)) + ' meeting' + (m.state === 'past' ? ' · done' : ''), state: m.state === 'now' ? 'working' : 'quiet', icon: 'clock', meeting: m }));
234
+ const routines = ((D.schedules && D.schedules.schedules) || []).filter((s) => s.initiative === id || new RegExp('\\b' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\b').test(String(s.name || s.label || ''))).map((s) => ({ id: 'r:' + (s.id || s.name), kind: 'routine', name: cap1(String(s.name || s.task || s.skill || 'Routine').replace(/[-_]/g, ' ')), hint: s.next ? 'Next ' + DOW[new Date(s.next).getDay()] + ' ' + hm(s.next) : 'Not scheduled', state: 'quiet', icon: 'routine', schedule: s }));
235
+ const files = (D.files || []).map((f) => ({ id: 'f:' + f.path, kind: 'file', name: f.name, hint: f.meta || f.path, state: 'quiet', icon: 'doc', file: f }));
236
+ const groups = [
237
+ ['needs', 'Needs you', mine],
238
+ ['sessions', 'Sessions', ses.filter((s) => s.state !== 'exited').sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0))],
239
+ ['people', 'Stakeholders', people],
240
+ ['meetings', 'Meetings', meet],
241
+ ['routines', 'Routines', routines],
242
+ ['files', 'Files', files],
243
+ ['done', 'Finished sessions', ses.filter((s) => s.state === 'exited')],
244
+ ].map(([key, title, rows]) => ({ key, title, rows })).filter((g) => g.rows.length);
245
+ const other = needs.filter((r) => r.ini !== id);
246
+ const byIni = new Map(); for (const r of other) { const k = r.ini || ''; byIni.set(k, (byIni.get(k) || 0) + 1); }
247
+ const top = [...byIni.entries()].sort((a, b) => b[1] - a[1]);
248
+ const titleOf = (k) => { const b = boardRows(D).find((r) => r.id === k); return b ? b.title : k || 'Home'; };
249
+ const elsewhere = other.length ? { n: other.length, text: top.map(([k, n]) => (n === 1 ? 'Your turn in ' : n + ' next steps in ') + titleOf(k)).join(' · '), first: other[0] } : null;
250
+ return { groups, elsewhere };
251
+ }
252
+ export const initials = (name) => { const w = String(name || '').trim().split(/\s+/); return w.length > 1 ? (w[0][0] + w[1][0]).toUpperCase() : String(name || '?').slice(0, 2).replace(/^./, (c) => c.toUpperCase()); };
253
+
254
+ /* ── the chat stream ── */
255
+ const dayKey = (iso) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? '' : d.toDateString(); };
256
+ export function dayLabel(iso, now = Date.now()) {
257
+ const d = new Date(iso); if (Number.isNaN(d.getTime())) return '';
258
+ const t = new Date(now), y = new Date(now); y.setDate(t.getDate() - 1);
259
+ return d.toDateString() === t.toDateString() ? 'Today' : d.toDateString() === y.toDateString() ? 'Yesterday' : DOW[d.getDay()] + ' ' + d.getDate() + ' ' + MON[d.getMonth()];
260
+ }
261
+ const dur = (ms) => { const s = Math.max(0, Math.round(ms / 1000)); return s < 60 ? s + 's' : s < 3600 ? Math.round(s / 60) + ' min' : Math.floor(s / 3600) + ' h ' + Math.round((s % 3600) / 60) + ' min'; };
262
+ /** The stream items of one conversation, oldest first.
263
+ * o: { seen (ISO of the PM's last look), show (how many messages show before the fold; Infinity shows all), now }
264
+ * Each item keeps mi, the index of its message in the conversation (a report chip or a context chip names its message by it). */
265
+ export function streamOf(messages, o = {}) {
266
+ const M = Array.isArray(messages) ? messages : [];
267
+ const items = [];
268
+ // fold the tool lines between two texts into one Worked-for item, timed from the message before it
269
+ let lastAt = null;
270
+ for (let mi = 0; mi < M.length; mi++) {
271
+ const m = M[mi];
272
+ if (m.role === 'tool') {
273
+ const prev = items[items.length - 1];
274
+ const calls = m.calls || [];
275
+ if (prev && prev.t === 'worked') { prev.tools = { ...prev.tools }; for (const [k, v] of Object.entries(m.tools || {})) prev.tools[k] = (prev.tools[k] || 0) + v; prev.calls = prev.calls.concat(calls); prev.end = m.at || prev.end; if (m.ask) { prev.ask = m.ask; prev.askMsg = m; prev.mi = mi; } }
276
+ else items.push({ t: 'worked', tools: { ...(m.tools || {}) }, calls: calls.slice(), start: lastAt, end: m.at || null, at: m.at || null, ask: m.ask || null, askMsg: m.ask ? m : null, mi });
277
+ continue;
278
+ }
279
+ items.push({ t: m.role === 'user' ? 'user' : 'agent', text: m.text || '', at: m.at || null, mi });
280
+ lastAt = m.at || lastAt;
281
+ }
282
+ for (const it of items) if (it.t === 'worked') it.took = it.start && it.end ? dur(Date.parse(it.end) - Date.parse(it.start)) : '';
283
+ const show = o.show == null ? 12 : o.show;
284
+ const hidden = Math.max(0, items.length - show);
285
+ const shown = items.slice(hidden);
286
+ const out = [];
287
+ if (hidden) out.push({ t: 'fold', n: hidden, text: hidden + ' earlier ' + (hidden === 1 ? 'message' : 'messages') + ' · show' });
288
+ let day = hidden && items[hidden - 1] ? dayKey(items[hidden - 1].at) : '';
289
+ let marked = false;
290
+ const seen = o.seen ? Date.parse(o.seen) : null;
291
+ for (const it of shown) {
292
+ const k = dayKey(it.at);
293
+ if (k && k !== day) { out.push({ t: 'day', text: dayLabel(it.at, o.now) }); day = k; }
294
+ if (!marked && seen && it.t === 'agent' && it.at && Date.parse(it.at) > seen) { out.push({ t: 'since', text: 'New since you left · ' + hm(it.at) }); marked = true; }
295
+ out.push(it);
296
+ }
297
+ return out;
298
+ }
299
+ /** The live run: who works, on which step, how long, and how far (for the steps card and the run strip). */
300
+ export function runOf(conv, role, now = Date.now()) {
301
+ if (!conv || (conv.turn !== 'agent' && conv.turn !== 'tool')) return null;
302
+ const steps = Array.isArray(conv.steps) ? conv.steps : null;
303
+ const cur = steps ? steps.findIndex((s) => s.state === 'now') : -1;
304
+ const ms = (conv.messages || []).filter((m) => m.role === 'user').pop();
305
+ const since = ms && ms.at ? Date.parse(ms.at) : null;
306
+ const t = since ? Math.max(0, Math.round((now - since) / 1000)) : null;
307
+ const clock = t == null ? '' : Math.floor(t / 60) + ':' + pad(t % 60);
308
+ const title = cur >= 0 ? steps[cur].text : conv.openCall ? 'Running ' + conv.openCall : 'Working';
309
+ return { who: role, title, clock, steps, at: cur, n: steps ? steps.length : 0,
310
+ sub: role.name + (steps && cur >= 0 ? ' · step ' + (cur + 1) + ' of ' + steps.length : '') + (clock ? ' · ' + clock : ''),
311
+ frac: steps && steps.length ? Math.max(0.08, (steps.filter((s) => s.state === 'done').length + 0.5) / steps.length) : 0.5 };
312
+ }
@@ -0,0 +1,54 @@
1
+ /* pm/home-dictate.js — the mic of the chat input: dictation into a text box (initiative premium-uncovered-features, H2; canvas HmMic and
2
+ * HmPhone). The mic is part of the input, nothing new to learn: press it, speak, the words appear as text in the box, stop, edit, send.
3
+ * It is the browser's own speech recognition (SpeechRecognition, as the console's live notes use it). Nothing is recorded as audio,
4
+ * nothing is saved, and nothing is sent: the text stays in the box until the PM sends it. A browser without speech recognition shows no mic.
5
+ * canDictate() true when this browser can turn speech into text
6
+ * dictate(box, { onState }) starts listening into the box (a textarea or an input) → { stop(), cancel(), on() }
7
+ * onState({ on, text, secs }) after each change; stop keeps the words, cancel puts the box back as it was */
8
+ const SR = () => (typeof window !== 'undefined' && (window.SpeechRecognition || window.webkitSpeechRecognition)) || null;
9
+ export const canDictate = () => !!SR();
10
+
11
+ let current = null;
12
+ export function dictate(box, o = {}) {
13
+ if (current) current.stop();
14
+ const Rec = SR();
15
+ const state = { on: false, text: '', secs: 0 };
16
+ const said = (v) => { try { o.onState && o.onState({ ...state, ...v }); } catch { /* the page redraws on its own */ } };
17
+ // box is the text box, or a function that finds it: a page that redraws its input still gets the words in the box shown now
18
+ const B = typeof box === 'function' ? box : () => box;
19
+ const el0 = B();
20
+ if (!Rec || !el0) { said({ on: false, error: 'This browser cannot turn speech into text. Type instead.' }); return { stop() {}, cancel() {}, on: () => false }; }
21
+ const before = el0.value || '';
22
+ const lead = before && !/\s$/.test(before) ? before + ' ' : before;
23
+ let finalText = '', interim = '', t0 = Date.now(), tick = null, stopped = false;
24
+ const r = new Rec();
25
+ r.continuous = true; r.interimResults = true;
26
+ r.lang = (typeof navigator !== 'undefined' && navigator.language) || 'en-US';
27
+ const put = () => {
28
+ const x = B(); if (x) { x.value = lead + finalText + interim; x.dispatchEvent(new Event('input', { bubbles: true })); }
29
+ state.text = (finalText + interim).trim();
30
+ said({});
31
+ };
32
+ r.onresult = (e) => {
33
+ interim = '';
34
+ for (let i = e.resultIndex; i < e.results.length; i++) {
35
+ const res = e.results[i];
36
+ if (res.isFinal) finalText += res[0].transcript.replace(/^\s+/, finalText ? ' ' : '');
37
+ else interim += res[0].transcript;
38
+ }
39
+ put();
40
+ };
41
+ const end = () => { clearInterval(tick); state.on = false; interim = ''; if (current === C) current = null; if (!stopped) put(); said({ on: false }); };
42
+ r.onerror = (e) => { said({ on: false, error: e && e.error === 'not-allowed' ? 'The browser did not allow the microphone.' : 'Listening stopped.' }); };
43
+ r.onend = end;
44
+ const C = {
45
+ stop() { stopped = false; try { r.stop(); } catch { end(); } },
46
+ cancel() { stopped = true; try { r.abort(); } catch { /* ended */ } const x = B(); if (x) { x.value = before; x.dispatchEvent(new Event('input', { bubbles: true })); } end(); },
47
+ on: () => state.on,
48
+ };
49
+ try { r.start(); } catch { said({ on: false, error: 'Listening could not start.' }); return C; }
50
+ current = C; state.on = true; t0 = Date.now();
51
+ tick = setInterval(() => { state.secs = Math.round((Date.now() - t0) / 1000); said({}); }, 1000);
52
+ said({});
53
+ return C;
54
+ }
@@ -0,0 +1,68 @@
1
+ /* home-draft.js — a core document's draft, read in Home's Viewer, with Issue it (premium-agreed-design; initiative premium-core-doc-issue).
2
+ * Drawn in the Viewer's card shape (canvas HmMyWork: the title, the line under it, the chips, the foot): the Issue it bar above the text,
3
+ * Read and Edit. Edit is the document page's own editor (premium-vw-doc.js, ctx.host), so a save goes through POST /api/doc-sheet/edit as everywhere else.
4
+ * Issue it posts POST /api/core-docs/issue { ws, scope, key, slot } and nothing else: it marks the draft issued and sends nothing to anyone.
5
+ * Issue it is refused here while the editor holds typed text that is not saved.
6
+ *
7
+ * openDraftVw({ VW, pmGet, pmPost, toast, ws, scope, doc, onIssued })
8
+ * doc the docs row: { key, title, path, slot, st, state }
9
+ * onIssued awaited after the route answers ok (the page reads again)
10
+ */
11
+ import { mdHtml } from './premium-doc-edit.js';
12
+
13
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
14
+
15
+ export function openDraftVw(o) {
16
+ const d = o.doc;
17
+ const X = { tab: 'read', text: null, err: '', issued: d.st !== 'draft', dirty: false, busy: false, msg: '' };
18
+ const wsq = () => (o.ws ? '&ws=' + encodeURIComponent(o.ws) : '');
19
+ let body = null;
20
+ const bar = () => (X.issued
21
+ ? '<div class="hm-iss done" data-issue-bar="done" role="status"><span>Issued. Nothing was sent to anyone.</span></div>'
22
+ : `<div class="hm-iss" data-issue-bar="draft"><span>A draft. Nothing is sent: issuing marks it issued and sends nothing to anyone.</span><button type="button" class="hx-b pri" data-ds="issue"${X.busy ? ' disabled' : ''}>Issue it</button></div>`);
23
+ const draw = () => {
24
+ if (!body) return;
25
+ const tabs = `<div class="hx-tabs ut-chips" role="tablist" aria-label="Draft">${[['read', 'Read'], ['edit', 'Edit']].map(([k, l]) => `<button type="button" class="cz-chip${X.tab === k ? ' on' : ' gh'}" role="tab" aria-selected="${X.tab === k}" aria-pressed="${X.tab === k}" data-ds="${k}">${l}</button>`).join('')}</div>`;
26
+ const text = X.text == null ? `<p class="hx-n">${esc(X.err || 'Reading the draft.')}</p>` : `<div class="dsbody hm-md">${mdHtml(X.text).html}</div>`;
27
+ body.innerHTML = `<div class="ut-vc"><div><h2 class="ut-h2">${esc(d.title || 'Draft')}</h2><p class="ut-sub">${esc(d.path)}</p></div>` + bar() + `<p class="hx-n" id="dsErr" role="alert">${esc(X.msg)}</p>` + tabs
28
+ + (X.tab === 'read' ? text : '<div class="hm-dsed" data-ds-host></div>') + '</div>';
29
+ if (X.tab === 'edit') mountEditor();
30
+ };
31
+ async function read() {
32
+ const p = encodeURIComponent(d.path);
33
+ const lg = await o.pmGet('/api/doc-sheet/log?path=' + p + wsq());
34
+ const revs = (lg && lg.ok && lg.revisions) || [];
35
+ const at = revs.length ? await o.pmGet('/api/doc-sheet/at?path=' + p + '&rev=' + revs[revs.length - 1].rev + wsq()) : null;
36
+ if (at && at.ok) { X.text = at.text; X.err = ''; } else { X.text = null; X.err = (at && at.error) || (lg && lg.error) || 'The draft could not be read.'; }
37
+ if (X.tab === 'read') draw();
38
+ }
39
+ async function mountEditor() {
40
+ const host = body.querySelector('[data-ds-host]'); if (!host) return;
41
+ X.dirty = false;
42
+ host.addEventListener('input', () => { X.dirty = true; });
43
+ host.addEventListener('keydown', (e) => { if (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Enter') X.dirty = true; });
44
+ const M = await import('./premium-vw-doc.js');
45
+ M.openDocPage({ path: d.path, title: d.title }, { host, ws: () => o.ws || '', onWrite: async () => { X.dirty = false; await read(); }, onClose: () => { X.dirty = false; X.tab = 'read'; draw(); } });
46
+ }
47
+ body = o.VW.open({ id: 'draft:' + o.scope + ':' + d.key, kind: 'Draft · ' + (d.state || 'Draft'), title: d.title, icon: 'doc', render: (b) => { body = b; draw(); } });
48
+ body.onclick = async (e) => {
49
+ const b = e.target.closest('[data-ds]'); if (!b || !body.contains(b)) return;
50
+ const k = b.dataset.ds;
51
+ if (k === 'read' || k === 'edit') {
52
+ if (k === X.tab) return;
53
+ if (k === 'read' && X.dirty) { X.msg = 'You have unsaved changes in Edit. Save or cancel them there.'; body.querySelector('#dsErr').textContent = X.msg; return; } // leaving Edit would drop the typed text
54
+ X.msg = ''; X.tab = k; draw(); if (k === 'read') read(); return;
55
+ }
56
+ if (k !== 'issue') return;
57
+ if (X.dirty) { X.msg = 'This draft has unsaved changes. Save or cancel them first, then issue it.'; body.querySelector('#dsErr').textContent = X.msg; return; }
58
+ X.busy = true; X.msg = ''; draw();
59
+ const r = await o.pmPost('/api/core-docs/issue', { ws: o.ws, scope: o.scope, key: d.key, slot: d.slot });
60
+ X.busy = false;
61
+ if (!r || r.ok !== true) { X.msg = (r && r.error) || 'The draft was not issued.'; draw(); return; }
62
+ X.issued = true; draw();
63
+ o.toast('Issued. Nothing was sent to anyone.');
64
+ if (o.onIssued) await o.onIssued();
65
+ };
66
+ read();
67
+ return body;
68
+ }