create-pmos 0.397.0 → 0.398.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 (145) hide show
  1. package/package.json +13 -13
  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 +101 -52
  8. package/workspace/briefing-premium-board-test.js +252 -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 +86 -196
  12. package/workspace/briefing-premium-doc-edit-test.js +95 -83
  13. package/workspace/briefing-premium-initiative-test.js +159 -296
  14. package/workspace/briefing-premium-insights-test.js +337 -219
  15. package/workspace/briefing-premium-metrics-test.js +53 -97
  16. package/workspace/briefing-premium-products-test.js +40 -27
  17. package/workspace/briefing-premium-sources-test.js +66 -48
  18. package/workspace/briefing-premium-test.js +150 -647
  19. package/workspace/briefing-premium-work-test.js +88 -283
  20. package/workspace/changelog.json +12 -0
  21. package/workspace/fixtures/board-premium-trail.js +32 -0
  22. package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
  23. package/workspace/guide/briefing-premium.md +3 -1
  24. package/workspace/guide/home.md +47 -0
  25. package/workspace/guide/index.md +1 -0
  26. package/workspace/lib/agent-roles.js +71 -0
  27. package/workspace/lib/board-premium.js +85 -19
  28. package/workspace/lib/board-trail.js +223 -0
  29. package/workspace/lib/home-work-item.js +58 -0
  30. package/workspace/lib/insights-goals.js +196 -0
  31. package/workspace/lib/insights-premium.js +62 -14
  32. package/workspace/lib/insights-records.js +101 -0
  33. package/workspace/lib/jira-tickets.js +1 -1
  34. package/workspace/lib/route-modules.js +4 -0
  35. package/workspace/lib/routes-board-trail.js +33 -0
  36. package/workspace/lib/routes-home-desk.js +176 -0
  37. package/workspace/lib/routes-insights-premium.js +12 -3
  38. package/workspace/lib/routes-insights-records.js +129 -0
  39. package/workspace/lib/routes-notes.js +1 -0
  40. package/workspace/lib/routes-viewer.js +108 -0
  41. package/workspace/lib/transcript-steps.js +123 -0
  42. package/workspace/lib/viewer-meeting.js +205 -0
  43. package/workspace/lib/viewer-report.js +89 -0
  44. package/workspace/package-lock.json +2 -2
  45. package/workspace/package.json +1 -1
  46. package/workspace/premium-board-actions-test.js +85 -75
  47. package/workspace/premium-briefing-depth-test.js +66 -53
  48. package/workspace/premium-chat-attach-test.js +54 -63
  49. package/workspace/premium-chat-chart-tab-test.js +35 -37
  50. package/workspace/premium-chat-context-test.js +19 -18
  51. package/workspace/premium-chat-goal-view-test.js +23 -23
  52. package/workspace/premium-chat-notes-test.js +26 -31
  53. package/workspace/premium-chat-report-tab-test.js +32 -28
  54. package/workspace/premium-chat-term-test.js +16 -16
  55. package/workspace/premium-chat-viewer-test.js +60 -59
  56. package/workspace/premium-core-doc-issue-test.js +50 -43
  57. package/workspace/premium-html-viewer-test.js +14 -17
  58. package/workspace/premium-phone-card-test.js +7 -2
  59. package/workspace/premium-phone-room-test.js +41 -35
  60. package/workspace/premium-report-read-test.js +115 -197
  61. package/workspace/premium-viewer-download-test.js +19 -22
  62. package/workspace/premium-viewer-flicker-test.js +11 -16
  63. package/workspace/premium-viewer-share-test.js +6 -9
  64. package/workspace/premium-viewer-test.js +41 -60
  65. package/workspace/premium-vw-backlog-test.js +53 -33
  66. package/workspace/premium-vw-cal-test.js +82 -128
  67. package/workspace/premium-vw-copy-test.js +17 -33
  68. package/workspace/premium-vw-doc-test.js +11 -10
  69. package/workspace/premium-vw-item-test.js +50 -49
  70. package/workspace/premium-vw-jira-test.js +53 -27
  71. package/workspace/premium-vw-meet-test.js +118 -187
  72. package/workspace/premium-vw-notes-test.js +85 -108
  73. package/workspace/premium-vw-rec-test.js +72 -194
  74. package/workspace/premium-vw-slides-test.js +46 -50
  75. package/workspace/premium-welcome-test.js +3 -2
  76. package/workspace/premium-work-depth-test.js +61 -53
  77. package/workspace/public/pm/bd-acts.js +305 -0
  78. package/workspace/public/pm/bd-span.js +186 -82
  79. package/workspace/public/pm/bd-stages.js +25 -11
  80. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  81. package/workspace/public/pm/c3-md.js +3 -395
  82. package/workspace/public/pm/c3-phone-detail.js +1 -1
  83. package/workspace/public/pm/c3-phone-model.js +3 -68
  84. package/workspace/public/pm/chat-term.js +3 -3
  85. package/workspace/public/pm/cozy-board.css +497 -230
  86. package/workspace/public/pm/cozy-home.css +570 -142
  87. package/workspace/public/pm/cozy-home.js +5 -3
  88. package/workspace/public/pm/cozy-insights.css +296 -167
  89. package/workspace/public/pm/cozy-md.js +396 -0
  90. package/workspace/public/pm/cozy-nav.js +17 -6
  91. package/workspace/public/pm/cozy-placeholder.js +26 -0
  92. package/workspace/public/pm/cozy-viewer.css +3 -3
  93. package/workspace/public/pm/cozy-viewer.js +144 -0
  94. package/workspace/public/pm/cozy-vw.css +485 -0
  95. package/workspace/public/pm/cozy.css +83 -1
  96. package/workspace/public/pm/home-adddoc.js +48 -0
  97. package/workspace/public/pm/home-app.js +905 -0
  98. package/workspace/public/pm/home-around.js +515 -0
  99. package/workspace/public/pm/home-chat.js +459 -0
  100. package/workspace/public/pm/home-data.js +312 -0
  101. package/workspace/public/pm/home-draft.js +68 -0
  102. package/workspace/public/pm/home-more.js +249 -0
  103. package/workspace/public/pm/home-phone-card.js +109 -0
  104. package/workspace/public/pm/home-work.js +519 -0
  105. package/workspace/public/pm/phone-moment.js +69 -0
  106. package/workspace/public/pm/pm-work-view.js +1 -1
  107. package/workspace/public/pm/premium-attach.js +4 -0
  108. package/workspace/public/pm/premium-board.js +423 -394
  109. package/workspace/public/pm/premium-chart-tab.js +110 -62
  110. package/workspace/public/pm/premium-deck.js +3 -3
  111. package/workspace/public/pm/premium-first.js +25 -21
  112. package/workspace/public/pm/premium-insights.js +792 -568
  113. package/workspace/public/pm/premium-meeting.js +61 -549
  114. package/workspace/public/pm/premium-notes.js +1 -1
  115. package/workspace/public/pm/premium-report-frame.css +20 -0
  116. package/workspace/public/pm/premium-report-read.js +509 -480
  117. package/workspace/public/pm/premium-report-tab.js +87 -63
  118. package/workspace/public/pm/premium-shell.js +72 -119
  119. package/workspace/public/pm/premium-viewer.js +22 -1
  120. package/workspace/public/pm/premium-vw-cal.js +187 -48
  121. package/workspace/public/pm/premium-vw-doc.css +6 -0
  122. package/workspace/public/pm/premium-vw-doc.js +40 -2
  123. package/workspace/public/pm/premium-vw-file.js +2 -2
  124. package/workspace/public/pm/premium-vw-meet.js +6 -83
  125. package/workspace/public/pm/premium-vw-mtg.js +731 -0
  126. package/workspace/public/pm/premium-vw-notes.js +56 -69
  127. package/workspace/public/pm/premium-vw-open.js +35 -0
  128. package/workspace/public/pm/premium-vw-page.js +16 -0
  129. package/workspace/public/pm/premium-vw-rec.js +11 -218
  130. package/workspace/public/pm/premium-vw-slides.css +5 -0
  131. package/workspace/public/pm/premium-vw-slides.js +44 -8
  132. package/workspace/public/pm/term-view.js +22 -0
  133. package/workspace/public/premium-board.html +28 -70
  134. package/workspace/public/premium-initiative.html +8 -48
  135. package/workspace/public/premium-insights.html +22 -60
  136. package/workspace/public/premium-viewer.html +20 -0
  137. package/workspace/public/premium.html +16 -107
  138. package/workspace/server.js +18 -3
  139. package/workspace/test-files.json +1 -0
  140. package/workspace/test-lists/home-libs.json +9 -0
  141. package/workspace/test-lists/premium-report-read.json +1 -1
  142. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  143. package/workspace/test-lists/premium-vw-notes.json +1 -1
  144. package/workspace/public/pm/premium-work.js +0 -729
  145. package/workspace/public/pm/premium.js +0 -1146
@@ -0,0 +1,515 @@
1
+ /* pm/home-around.js — Around you on Home: what the agents and the outside world left for you (initiative premium-briefing-depth;
2
+ * moved onto Home by premium-agreed-design). The Agreed design does not draw it, so it is a plain minimal card in the Viewer with a
3
+ * "Waiting for design" marker, opened from More. It keeps every feature of the old Briefing card:
4
+ * the six rows, in the PRD order: agent proposals · mentions · portfolio pulse · horizon scan · report found · data freshness
5
+ * the prep line (the meetings left today and how many are prepped) and today's digests from the morning brief
6
+ * each row opens its own view in the same card, with Back to the rows; Escape closes the Viewer
7
+ * Every read is a route the console already uses and every write is a press that says what it does first (pmPost carries the launch nonce).
8
+ * A source that cannot be read is named in its row, never shown as empty. Which products: ?ws=<id> that one, otherwise every product Home reads.
9
+ * Nothing here posts to Slack, Jira, Confluence or mail.
10
+ * openAround(key?) → the body element; key opens one row's view at once (prop | men | pulse | scan | rep | src) */
11
+ import { pmGet, pmPost } from './http.js';
12
+ import { open as vwOpen } from './cozy-viewer.js';
13
+ import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words.js';
14
+
15
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
16
+ const WAIT = '<p class="hx-wait"><i aria-hidden="true"></i>Waiting for design</p>';
17
+ const STAMP = (n) => String(n).padStart(2, '0');
18
+ 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); };
19
+ const CHECK = '<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l4.5 4.5L19 7"/></svg>';
20
+ const SRCN = { slack: 'Slack', jira: 'Jira', confluence: 'Confluence', mail: 'Mail' };
21
+ const srcName = (s) => SRCN[s] || String(s || 'a source');
22
+ const first = (s) => String(s || '').trim().split(/\s+/)[0];
23
+ const pl = (n, one, many) => n + ' ' + (n === 1 ? one : many);
24
+ const BDI = {
25
+ at: '<circle cx="12" cy="12" r="4"/><path d="M16 12v1.5a2.5 2.5 0 0 0 5 0V12a9 9 0 1 0-3.5 7.1"/>',
26
+ prop: '<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>',
27
+ pulse: '<path d="M3 12h4l3-7 4 14 3-7h4"/>',
28
+ scan: '<circle cx="11" cy="11" r="7"/><path d="m20 20-4-4"/>',
29
+ rep: '<path d="M7 3h8l4 4v14H7z"/><path d="M14 3v5h5M10 13h6M10 17h6"/>',
30
+ src: '<path d="M20 11a8 8 0 0 0-14.6-4.5M4 13a8 8 0 0 0 14.6 4.5"/><path d="M5 3v4h4M19 21v-4h-4"/>',
31
+ x: '<path d="M6 6l12 12M18 6 6 18"/>',
32
+ };
33
+ const bdIco = (d) => `<svg class="i" viewBox="0 0 24 24" aria-hidden="true">${d}</svg>`;
34
+ const H2 = (t) => `<h4>${esc(t)}</h4>`;
35
+ const kv = (rows) => `<dl class="hv-facts">${rows.map(([k, v]) => `<div><dt>${esc(k)}</dt><dd>${esc(v)}</dd></div>`).join('')}</dl>`;
36
+
37
+ const A = { prop: null, men: null, pulse: null, scan: null, rep: null, src: null, prep: null, dig: null }; // the last answer of each read
38
+ const DEC = new Map(); // proposals decided on this visit: id → { item, st: 'kept' | 'back' | 'dropped', note, wrote, warnings }
39
+ const PNOTE = {}, PERR = {}, PBACK = new Set();
40
+ const MREAD = new Map(), MADD = new Set();
41
+ const SDEC = new Map();
42
+ const SERR = {}, SWHY = {}, SOPEN = new Set();
43
+ const REC = new Map(), RERR = {}, SNOTE = {};
44
+ const PMORE = new Set();
45
+ let MTAB = 'all', BUSY = '', PSEL = '', PINFO = false, VIEW = '', PRODS = null;
46
+ const getj = async (p) => { const r = await pmGet(p); return r && r.ok !== false ? r : { ok: false, error: (r && r.error) || 'the server did not answer' }; };
47
+ const wq = (ws) => (ws ? 'ws=' + encodeURIComponent(ws) : '');
48
+ const wsParam = () => new URLSearchParams(location.search).get('ws') || '';
49
+ const said = (r) => 'could not be read: ' + (r && r.error ? r.error : 'the server did not answer');
50
+ async function prods() {
51
+ const one = wsParam(); if (one) return [{ ws: one, name: one }];
52
+ if (!PRODS) { const r = await getj('/api/briefing-premium'); PRODS = r.ok && r.model && r.model.products ? r.model.products.available.filter((x) => x.on).map((x) => ({ ws: x.ws, name: x.name })) : []; if (!PRODS.length) PRODS = [{ ws: '', name: '' }]; }
53
+ return PRODS;
54
+ }
55
+
56
+ /* ── reads ── */
57
+ async function readProps(P) {
58
+ const items = [], errs = [];
59
+ await Promise.all(P.flatMap((p) => ['initiative', 'work'].map(async (kind) => {
60
+ const r = await getj('/api/driver/open?target_kind=' + kind + (p.ws ? '&' + wq(p.ws) : ''));
61
+ if (!r.ok) { errs.push(r.error); return; }
62
+ if (r.mode !== 'approve') return; // Off and Shadow raise nothing here (the console draws the same)
63
+ for (const [tid, list] of Object.entries(r.targets || {})) for (const pr of list) items.push({ id: pr.id, ws: r.ws, pname: P.length > 1 ? p.name : '', kind, tid, p: pr, title: '' });
64
+ })));
65
+ items.sort((a, b) => String(a.p.at).localeCompare(String(b.p.at)) || a.id.localeCompare(b.id));
66
+ if (items.some((x) => x.kind === 'work')) {
67
+ const w = await getj('/api/pm-items'), by = new Map(((w.ok && w.items) || []).map((i) => [i.id, i.title]));
68
+ items.forEach((x) => { if (x.kind === 'work') x.title = by.get(x.tid) || ''; });
69
+ }
70
+ if (!items.length && errs.length) return { ok: false, error: errs[0] };
71
+ return { ok: true, items, errs };
72
+ }
73
+ let BP = null;
74
+ const briefPage = (force) => (BP && !force && Date.now() - BP.at < 30000 ? BP.p : (BP = { at: Date.now(), p: getj('/api/brief-page' + (wsParam() ? '?' + wq(wsParam()) : '')) }).p);
75
+ async function readMen() { const r = await briefPage(); return r.ok ? { ok: true, list: Array.isArray(r.mentions) ? r.mentions : null } : r; }
76
+ const PST = { 'on time': ['ok', 'On time'], 'at risk': ['warn', 'At risk'], delayed: ['bad', 'Delayed'], overdue: ['bad', 'Overdue'], 'no plan': ['', 'No plan'] };
77
+ /** One Calendar row as the pulse draws it. cls: bad (late) · warn (at risk) · ok (on plan) · '' (no plan date). The Calendar's own status. */
78
+ export function pulseRow(g) {
79
+ const j = g.jira && Number.isInteger(g.jira.total) && g.jira.total > 0 && Number.isInteger(g.jira.done) ? g.jira : null;
80
+ const f = (g.forecast && (g.forecast.end || g.forecast.start)) || null;
81
+ if (j && (!PST[g.status] || g.status === 'no plan')) {
82
+ const all = j.done >= j.total;
83
+ return { id: g.id, title: g.title || g.id, cls: j.blocked > 0 ? 'warn' : all ? 'ok' : '', word: j.blocked > 0 ? 'Blocked' : all ? 'Done in Jira' : 'In progress',
84
+ why: j.done + ' of ' + j.total + ' done in Jira' + (j.blocked > 0 ? ', ' + j.blocked + ' blocked' : '') + '; no promised date' };
85
+ }
86
+ const k = PST[g.status] ? g.status : 'no plan', p = g.promised || null;
87
+ return { id: g.id, title: g.title || g.id, cls: PST[k][0], word: PST[k][1] + (g.slip_days > 0 ? ' +' + g.slip_days + ' d' : ''),
88
+ why: (p ? 'Forecast ' + (f || 'not set') + ' vs promised ' + p : 'No promised date' + (f ? '; forecast ' + f : '')) + (j ? '. ' + j.done + ' of ' + j.total + ' done in Jira' : '') };
89
+ }
90
+ async function readPulse(P) {
91
+ const d = new Date(), day = d.getFullYear() + '-' + STAMP(d.getMonth() + 1) + '-' + STAMP(d.getDate()), rows = [], errs = [];
92
+ let none = 0;
93
+ await Promise.all(P.map(async (p, i) => {
94
+ const r = await getj('/api/calendar-views?view=quarter&only=gantt&date=' + day + (p.ws ? '&' + wq(p.ws) : ''));
95
+ if (!r.ok) { errs.push(r.error); return; }
96
+ none += Number(r.no_plan) || 0;
97
+ for (const g of r.gantt || []) rows.push({ ...pulseRow(g), ws: p.ws, pname: P.length > 1 ? p.name : '', at: i });
98
+ }));
99
+ rows.sort((a, b) => a.at - b.at);
100
+ if (!rows.length && !none && errs.length) return { ok: false, error: errs[0] };
101
+ return { ok: true, rows, none, errs };
102
+ }
103
+ async function readScan(P) {
104
+ const got = [], errs = [];
105
+ await Promise.all(P.map(async (p, i) => { const r = await getj('/api/scan/portfolio' + (p.ws ? '?' + wq(p.ws) : '')); if (!r.ok) errs.push(r.error); else got.push({ ...r, pname: P.length > 1 ? p.name : '', at: i }); }));
106
+ got.sort((a, b) => a.at - b.at);
107
+ if (!got.length && errs.length) return { ok: false, error: errs[0] };
108
+ return { ok: true, scans: got, errs };
109
+ }
110
+ async function readReps(P) {
111
+ const got = [], errs = [];
112
+ await Promise.all(P.map(async (p, i) => {
113
+ const r = await getj('/api/report-setups' + (p.ws ? '?' + wq(p.ws) : ''));
114
+ if (!r.ok) errs.push((P.length > 1 && p.name ? p.name + ': ' : '') + r.error);
115
+ else got.push({ ws: r.ws || p.ws, pname: P.length > 1 ? p.name : '', at: i, finder: r.finder || null, findings: Array.isArray(r.findings) ? r.findings : [] });
116
+ }));
117
+ got.sort((a, b) => a.at - b.at);
118
+ if (!got.length && errs.length) return { ok: false, error: errs[0] };
119
+ return { ok: true, prods: got, errs };
120
+ }
121
+ const readSrc = () => getj('/api/sources' + (wsParam() ? '?' + wq(wsParam()) : ''));
122
+ /** Today's digests from the morning brief (the Briefing model's Today items of kind digest). */
123
+ async function readDig() {
124
+ const r = await getj('/api/briefing-premium' + (wsParam() ? '?' + wq(wsParam()) : ''));
125
+ if (!r.ok || !r.model) return { ok: false, error: r.error || 'the Briefing is not read yet' };
126
+ const T = r.model.today || {};
127
+ return { ok: true, items: [].concat(T.earlier || [], T.ahead || []).filter((e) => e && e.kind === 'digest') };
128
+ }
129
+ async function readAll(which) {
130
+ const P = await prods(), all = !which;
131
+ const job = { prop: () => readProps(P), men: () => readMen(), pulse: () => readPulse(P), scan: () => readScan(P), rep: () => readReps(P), src: () => readSrc(), prep: () => briefPage(), dig: () => readDig() };
132
+ await Promise.all(Object.keys(job).filter((k) => all || which.includes(k)).map(async (k) => { try { A[k] = await job[k](); } catch (e) { A[k] = { ok: false, error: String((e && e.message) || e) }; } }));
133
+ redraw();
134
+ }
135
+
136
+ /* ── words ── */
137
+ const PWHAT = { problem: 'Problem statement', evidence: 'Evidence', sizing: 'Opportunity sizing', assumption: 'Riskiest assumption and spike brief', stakeholders: 'Stakeholders', move: 'Move', note: 'Note', 'next-step': 'Next step', 'follow-up': 'Follow-up' };
138
+ const pWhat = (p) => (p.what === 'move' && p.data && p.data.to ? 'Move to ' + p.data.to : PWHAT[p.what] || p.what);
139
+ const pKeep = (p) => ({ problem: 'Keep writes the problem statement into the stage record.', move: 'Keep moves the initiative on its board.', 'next-step': 'Keep adds the next step to your Work item.', 'follow-up': 'Keep copies the follow-up text. Nothing is sent to anyone.', doc: 'Keep issues the draft document.' }[p.what] || 'Keep records that you accept it. Nothing else changes.');
140
+ const pWrote = (w) => ({ problem: 'The problem statement is in the stage record.', move: 'The initiative moved.', doc: 'The document was issued.', 'next-step': 'The next step is in your Work item.' }[w] || 'It is recorded. Nothing else changed.');
141
+ const pText = (p) => {
142
+ const t = p.data && typeof p.data.text === 'string' ? p.data.text : '';
143
+ if (p.what === 'move') return 'Move this initiative to ' + ((p.data && p.data.to) || 'the next stage') + '.';
144
+ if (t) return t;
145
+ if (p.data && Array.isArray(p.data.items)) return pl(p.data.items.length, 'item', 'items') + ' with a pointer each.';
146
+ return '';
147
+ };
148
+ const iniTitle = (x) => { const r = A.pulse && A.pulse.ok && A.pulse.rows.find((y) => y.id === x.tid && y.ws === x.ws); return r ? r.title : ''; };
149
+ const targetOf = (x) => (x.kind === 'work' ? 'Work · ' : 'Initiative · ') + (x.title || (x.kind === 'initiative' ? iniTitle(x) : '') || x.tid);
150
+ const openProps = () => (A.prop && A.prop.ok ? A.prop.items : []);
151
+ const shownMen = () => {
152
+ const l = A.men && A.men.ok && A.men.list ? A.men.list : [];
153
+ return l.filter((m) => !m.in_needs && (MREAD.has(m.id) || !m.read)).map((m) => (MREAD.has(m.id) ? { ...m, read: MREAD.get(m.id) } : m));
154
+ };
155
+ const waitM = (l) => l.filter((m) => m.reply && !m.read);
156
+ function menLine(l) {
157
+ const w = waitM(l), rest = l.filter((m) => !m.read).length - w.length;
158
+ if (!w.length) return rest ? 'No one is waiting on a reply. ' + pl(rest, 'mention is', 'mentions are') + ' for your information.' : 'No mentions are left unread.';
159
+ const names = w.map((m) => (m.who ? first(m.who) : 'Someone') + ' in ' + srcName(m.source)), s = names.length < 2 ? names[0] : names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1];
160
+ return s + (w.length === 1 ? ' is' : ' are') + ' waiting on your reply.' + (rest ? ' ' + rest + (rest === 1 ? ' more is' : ' more are') + ' for your information.' : '');
161
+ }
162
+ const mWhen = (iso) => {
163
+ if (!iso) return '';
164
+ const d = new Date(iso), n = new Date(), hm = STAMP(d.getHours()) + ':' + STAMP(d.getMinutes()), k = (x) => x.getFullYear() * 400 + x.getMonth() * 32 + x.getDate(), y = new Date(n); y.setDate(y.getDate() - 1);
165
+ return k(d) === k(n) ? hm : k(d) === k(y) ? 'yesterday ' + hm : d.getDate() + '/' + (d.getMonth() + 1) + ' ' + hm;
166
+ };
167
+ const groups = (rows) => ({ bad: rows.filter((r) => r.cls === 'bad'), warn: rows.filter((r) => r.cls === 'warn'), ok: rows.filter((r) => r.cls === 'ok'), none: rows.filter((r) => !r.cls) });
168
+ const PGW = { bad: 'Late', warn: 'At risk', ok: 'On plan', none: 'No plan date' };
169
+ const bar = (g, n, extra) => `<span class="bd-bar" aria-hidden="true">${['bad', 'warn', 'ok', 'none'].map((k) => { const c = k === 'none' ? g.none.length + extra : g[k].length; return c ? `<i class="${k}" data-w="${c / n * 100}"></i>` : ''; }).join('')}</span>`;
170
+ const dayWord = (iso) => {
171
+ const d = new Date(iso); if (!Number.isFinite(d.getTime())) return '';
172
+ const n = new Date(), y = new Date(n), hm = STAMP(d.getHours()) + ':' + STAMP(d.getMinutes()); y.setDate(y.getDate() - 1);
173
+ return d.toDateString() === n.toDateString() ? 'today, ' + hm : d.toDateString() === y.toDateString() ? 'yesterday, ' + hm : d.getDate() + ' ' + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()] + ', ' + hm;
174
+ };
175
+ const scanOpen = () => (A.scan && A.scan.ok ? A.scan.scans.reduce((n, s) => n + (s.proposals_waiting || 0), 0) : 0);
176
+ const repFound = () => (A.rep && A.rep.ok ? A.rep.prods.flatMap((q) => q.findings.map((f) => ({ ...f, ws: q.ws, pname: q.pname }))) : []);
177
+ const behindSrc = () => { if (!A.src || !A.src.ok) return []; const ids = behindOf(lineItems(A.src.sources)).map((i) => i.id); return A.src.sources.filter((s) => ids.includes(s.id)); };
178
+ const joinN = (a) => (a.length < 2 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1]);
179
+ function scanNowLine(S) {
180
+ if (S.length && S.every((x) => x.switched_off)) return ' · Scan now is off here';
181
+ const M = S.map((x) => x.manual).filter((m) => m && m.limit);
182
+ if (!M.length) { const no = S.map((x) => x.manual).find((m) => m && m.ok === false && m.error); return no ? ' · ' + no.error : ''; }
183
+ const left = M.reduce((n, m) => n + (m.left || 0), 0), lim = M.reduce((n, m) => n + m.limit, 0);
184
+ return M.every((m) => m.ok === false) ? ' · Scan now: ' + (M[0].error || 'not now') : ' · Scan now: ' + left + ' of ' + lim + ' left today';
185
+ }
186
+ /** Refresh all's step, in words (the same run as the Sources card). */
187
+ function allText(a) {
188
+ if (!a) return '';
189
+ const S = a.steps || [], reads = S.filter((x) => x.step === 'read'), der = S.filter((x) => x.step === 'derived');
190
+ const left = reads.filter((x) => x.state === 'running' || x.state === 'waiting'), bad = S.filter((x) => x.state === 'failed').map((x) => x.label);
191
+ if (a.phase === 'read') return 'Step 1 of 2: reading ' + left.map((x) => x.label).join(', ') + '. Home\'s list is written after them.';
192
+ if (a.phase === 'derived') return 'Step 2 of 2: writing Home\'s list from the reads' + (bad.length ? ' (' + bad.join(', ') + ' failed, so its last read is used)' : '') + '.';
193
+ const ok = der.length && der.every((x) => x.state === 'done');
194
+ return 'Refresh all ended: ' + (ok ? 'the sources were read and Home\'s list was written again' : 'Home\'s list was not written again') + '.' + (bad.length ? ' Failed: ' + bad.join(', ') + '.' : '');
195
+ }
196
+
197
+ /** The six rows: { k, ic, t, s, m (count html), bar, wait }. Every word comes from A. */
198
+ function aroundRows() {
199
+ const R = [], rd = 'Reading…';
200
+ { const a = A.prop, n = a && a.ok ? a.items.length : 0;
201
+ R.push({ k: 'prop', ic: BDI.prop, wait: n > 0, t: !a ? rd : !a.ok ? 'Agent proposals ' + said(a) : n ? pl(n, 'agent proposal waits', 'agent proposals wait') + ' on you' : 'No agent proposals wait',
202
+ s: !a || !a.ok ? '' : n ? 'Keep, send back or drop each one' : 'The agent files a draft here when it has one', m: n ? `<span class="due">${n}</span>` : '' }); }
203
+ { const a = A.men, l = shownMen(), w = waitM(l);
204
+ R.push({ k: 'men', ic: BDI.at, wait: w.length > 0, t: !a ? rd : !a.ok ? 'Mentions ' + said(a) : a.list === null ? 'No brief for today, so no mentions were read' : l.filter((m) => !m.read).length ? menLine(l) : 'No one has mentioned you today',
205
+ s: !a || !a.ok || !l.filter((m) => !m.read).length ? '' : [...new Set(l.filter((m) => !m.read).map((m) => srcName(m.source)))].join(', '), m: w.length ? '<span class="due od">Reply</span>' : '' }); }
206
+ { const a = A.pulse, g = a && a.ok ? groups(a.rows) : null, n = a && a.ok ? a.rows.length + a.none : 0;
207
+ R.push({ k: 'pulse', ic: BDI.pulse, wait: !!(g && g.bad.length), t: !a ? rd : !a.ok ? 'Portfolio pulse ' + said(a) : n ? `Portfolio pulse: ${g.bad.length} late, ${g.warn.length} at risk` : 'Portfolio pulse: nothing to compare yet',
208
+ s: !a || !a.ok ? '' : n ? `${g.ok.length} on plan · ${g.none.length + a.none} with no plan date` : 'No initiative has a promised date or a Jira read.', bar: n ? bar(g, n, a.none) : '', m: '' }); }
209
+ { const a = A.scan, S = a && a.ok ? a.scans : [], w = scanOpen(), run = S.some((x) => x.open), last = S.map((x) => x.last && x.last.at).filter(Boolean).sort().pop(), nrep = S.reduce((n, x) => n + x.reports.filter((r) => r.written && !r.parent).length, 0);
210
+ R.push({ k: 'scan', ic: BDI.scan, wait: w > 0, t: !a ? rd : !a.ok ? 'Horizon scan ' + said(a) : run ? 'Horizon scan: scanning now' : w ? 'Horizon scan: ' + pl(w, 'proposal waits', 'proposals wait') + ' for you' : S.every((x) => x.switched_off) ? 'Horizon scan: switched off' : last ? 'Horizon scan: nothing waits' : 'Horizon scan: no scan has run yet',
211
+ s: !a || !a.ok ? '' : run ? 'Reading the web and the repository' : (last ? 'Ran ' + dayWord(last).toLowerCase() + (nrep ? ' · ' + pl(nrep, 'report', 'reports') : '') : 'Start one from here') + scanNowLine(S), m: w ? `<span class="due">${w}</span>` : '' }); }
212
+ { const a = A.rep, L = repFound(), n = L.length, fd = a && a.ok ? a.prods.map((q) => q.finder).filter(Boolean) : [], off = fd.length > 0 && fd.every((x) => x.cadence === 'off'), nx = fd.map((x) => x.next_run).filter(Boolean).sort()[0];
213
+ R.push({ k: 'rep', ic: BDI.rep, wait: n > 0, t: !a ? rd : !a.ok ? 'Report finder ' + said(a) : n === 1 ? 'Report found: ' + L[0].name : n ? pl(n, 'report', 'reports') + ' found in your work' : off ? 'The report finder is off' : 'No report found',
214
+ s: !a || !a.ok ? '' : n ? 'Set it up, or say it is not a report' : nx ? 'The finder looks next ' + dayWord(nx) : off ? 'Switch it on in Settings' : 'It reads your calendar, Slack and the subjects of mail you sent', m: n ? `<span class="due">${n}</span>` : '' }); }
215
+ { const a = A.src, b = behindSrc();
216
+ R.push({ k: 'src', ic: BDI.src, wait: b.length > 0, t: !a ? rd : !a.ok ? 'Data freshness ' + said(a) : b.length > 2 ? b.length + ' sources need a new read' : b.length ? joinN(b.map((s) => s.label)) + (b.length === 1 ? ' needs' : ' need') + ' a new read' : 'Every source was read recently',
217
+ s: !a || !a.ok ? '' : b.length > 2 ? joinN(b.map((s) => s.label)) + '. Read on a schedule, not live' : 'Sources are read on a schedule, not live', m: b.length ? `<span class="due">${b.length}</span>` : '' }); }
218
+ return R;
219
+ }
220
+ const pHm = (iso) => { const d = new Date(iso); return STAMP(d.getHours()) + ':' + STAMP(d.getMinutes()); };
221
+ /** The prep line: of the meetings still ahead today, how many have nothing left to do before them (/api/brief-page, `before` is the open items linked to a meeting). */
222
+ function prepHtml() {
223
+ const p = A.prep, t = p && p.ok ? p.today || [] : [], left = t.filter((m) => m.state !== 'past'), ok = left.filter((m) => !(m.before || []).length).length;
224
+ if (!left.length) return '<div id="prep" class="ar-prep" hidden></div>';
225
+ const cur = t.find((m) => m.state === 'now'), nxt = cur || t.find((m) => m.state === 'next'), R = 17, C = 2 * Math.PI * R;
226
+ return `<div id="prep" class="ar-prep"><svg width="44" height="44" viewBox="0 0 44 44" role="img" aria-label="${ok} of ${left.length} prepped"><circle class="rb" cx="22" cy="22" r="${R}" fill="none" stroke-width="6"/><circle class="rg" cx="22" cy="22" r="${R}" fill="none" stroke-width="6" stroke-linecap="round" stroke-dasharray="${(C * ok / left.length).toFixed(2)} ${C.toFixed(2)}" transform="rotate(-90 22 22)"/><text class="rt" x="22" y="26" text-anchor="middle">${ok}/${left.length}</text></svg><div>${nxt ? `<b>${esc(nxt.title)}${cur ? ' is on now' : ' at ' + pHm(nxt.start) + ' is next'}</b>` : ''}<span>${pl(left.length, 'meeting', 'meetings')} left today. ${ok} of ${left.length} prepped.</span></div></div>`;
227
+ }
228
+ const bdLink = (href) => (/^https:\/\/\S+$/i.test(String(href || '')) ? href : '');
229
+ /** Today's digests: each with its lines and its link (the morning brief's summary, not a copy of the source). */
230
+ function digHtml() {
231
+ const a = A.dig; if (!a || !a.ok || !a.items.length) return '';
232
+ return `<section class="hx-sec" id="aroundDig"><h4>Digests ${a.items.length}</h4>${a.items.map((e) => { const d = e.dialog || {}, p = d.pane || {}, l = bdLink(d.link);
233
+ return `<div class="bd-it ar-dig"><span class="bd-t">${esc(e.title)}</span><p class="bd-why">${esc(e.sub || '')}</p>${(p.paras || []).map((x) => `<p class="bd-q">${esc(x)}</p>`).join('')}${l ? `<div class="bd-acts"><a class="hx-b cta alt srcLink" href="${esc(l)}" target="_blank" rel="noopener noreferrer">${esc(d.linkLabel || 'Open it')}</a></div>` : ''}</div>`; }).join('')}</section>`;
234
+ }
235
+ function listHtml() {
236
+ const R = aroundRows(), n = R.filter((r) => r.wait).length;
237
+ const cap = [A.prop, A.men, A.pulse, A.scan, A.rep, A.src].some((x) => x === null) ? 'Reading' : n ? n + ' to look at' : 'quiet';
238
+ return WAIT + `<div class="ar-hd"><b>Around you</b><small id="aroundCap">${esc(cap)}</small></div>` + prepHtml()
239
+ + `<div id="aroundBody" class="ar-rows">${R.map((r) => `<button type="button" class="ar-row" data-bd="${r.k}"><span class="ar-ic">${bdIco(r.ic)}</span><span class="wtx"><span class="wtit">${esc(r.t)}</span>${r.s ? `<span class="ws">${esc(r.s)}</span>` : ''}${r.bar || ''}</span>${r.m ? `<span class="wm">${r.m}</span>` : ''}</button>`).join('')}</div>`
240
+ + digHtml() + '<p class="hx-n">Nothing here posts to Slack, Jira, Confluence or mail. A button that records something says what, before you press it.</p>';
241
+ }
242
+
243
+ /* ── the pieces of a view ── */
244
+ const bdActs = (...b) => `<div class="bd-acts">${b.join('')}</div>`;
245
+ const bdBtn = (label, act, id, alt, attrs) => `<button type="button" class="hx-b cta${alt ? ' alt' : ' pri'}" data-bda="${act}"${id != null ? ` data-id="${esc(id)}"` : ''}${attrs || ''}>${esc(label)}</button>`;
246
+ const bdDone = (ok, text) => `<p class="bd-done" role="status">${ok ? CHECK : bdIco(BDI.x)}<span>${esc(text)}</span></p>`;
247
+ const bdChip = (t, c) => `<span class="bd-chip${c ? ' ' + c : ''}">${esc(t)}</span>`;
248
+ const bdFail = (id, e) => (e[id] ? `<p class="nodef err" role="alert">${esc(e[id])}</p>` : '');
249
+
250
+ /* ── agent proposals ── */
251
+ function propItem(it, sel) {
252
+ const p = it.p, d = DEC.get(it.id), id = it.id, text = pText(p), more = PMORE.has(id), on = !d && id === sel;
253
+ const src = (p.sources || []).filter((s) => s && s.ref).map((s) => (bdLink(s.ref) ? `<a href="${esc(bdLink(s.ref))}" target="_blank" rel="noopener noreferrer">${esc(s.label || s.ref)}</a>` : esc((s.label ? s.label + ': ' : '') + s.ref))).join(' · ');
254
+ const line = text || (p.why ? 'Why: ' + p.why : ''), extra = (text && p.why) || src;
255
+ let act = '';
256
+ if (d) act = d.st === 'kept' ? bdDone(true, 'Kept. ' + pWrote(d.wrote) + (d.warnings.length ? ' ' + d.warnings.join(' ') : '')) : d.st === 'back' ? bdDone(true, 'Sent back with your note: “' + d.note + '”. The note starts a new run.') : bdDone(false, 'Dropped. It counts as a correction.');
257
+ else if (on && !PBACK.has(id)) act = bdFail(id, PERR);
258
+ const pick = d ? `<span class="bd-t">${esc(targetOf(it))}</span>` : `<button type="button" class="bd-t pc-pick" data-bda="psel" data-id="${esc(id)}" aria-pressed="${on}">${esc(targetOf(it))}</button>`;
259
+ return `<div class="bd-it pcard${d ? ' decided' : ''}${on ? ' on' : ''}" data-id="${esc(id)}"${d ? '' : ' data-bda="psel"'}><small class="pc-k">${esc(pWhat(p))}${it.pname ? ' · ' + esc(it.pname) : ''}</small>${pick}`
260
+ + (line ? `<p class="pc-line${more ? ' open' : ''}"><span>${esc(line)}</span>${extra ? `<button type="button" class="pc-more" data-bda="pmore" data-id="${esc(id)}" aria-expanded="${more}">${more ? 'Less' : 'Read more'}</button>` : ''}</p>` : '')
261
+ + (extra ? `<div class="pc-x"${more ? '' : ' hidden'}>${text && p.why ? `<p class="bd-why">Why: ${esc(p.why)}</p>` : ''}${src ? `<p class="bd-why">Sources: ${src}</p>` : ''}</div>` : '') + act + '</div>';
262
+ }
263
+ const propSel = (L) => { const w = L.filter((it) => !DEC.has(it.id)); return (w.find((it) => it.id === PSEL) || w[0] || {}).id || ''; };
264
+ function propsHtml() {
265
+ const a = A.prop; if (!a || !a.ok) return `<p class="nodef err" role="alert">Agent proposals ${esc(said(a))}</p>`;
266
+ const L = a.items.concat([...DEC.values()].map((d) => d.item).filter((it) => !a.items.some((o) => o.id === it.id))), sel = propSel(L), it = L.find((x) => x.id === sel);
267
+ const notes = [it ? pKeep(it.p) + ' Drop counts as a correction. Send back starts a new run with your note. None of the three can be undone.' : '', 'The agent mode (Off, Shadow, Approve) stays in Settings. This list shows a kind only when its mode is Approve.', a.errs.length ? 'Not read: ' + a.errs[0] : ''].filter(Boolean);
268
+ const info = `<div class="pc-info"><button type="button" class="hx-b alt" data-bda="pinfo" aria-expanded="${PINFO}" aria-controls="pcNotes"><i class="pc-i" aria-hidden="true">i</i>Nothing changes a record until you keep it</button><div id="pcNotes"${PINFO ? '' : ' hidden'}>${notes.map((t) => `<p class="bd-why">${esc(t)}</p>`).join('')}</div></div>`;
269
+ const back = it && PBACK.has(it.id), id = it ? esc(it.id) : '';
270
+ const note = back ? `<label class="bd-l" for="bdn-${id}">What should the agent change?</label><textarea id="bdn-${id}" data-bdn="${id}" maxlength="500" rows="2">${esc(PNOTE[it.id] || '')}</textarea>${bdFail(it.id, PERR)}` : '';
271
+ const pbar = !it ? '' : `<div class="pc-bar">${note}<div class="pc-row">${back
272
+ ? `<button type="button" class="hx-b pc-q" data-bda="pcancel" data-id="${id}">Cancel</button><button type="button" class="hx-b pri pc-p" data-bda="pback" data-id="${id}"${(PNOTE[it.id] || '').trim() ? '' : ' disabled'}>Send back</button>`
273
+ : `<button type="button" class="hx-b pc-q" data-bda="pnote" data-id="${id}">Send back</button><button type="button" class="hx-b pc-q" data-bda="pdrop" data-id="${id}">Drop</button><button type="button" class="hx-b pri pc-p" data-bda="pkeep" data-id="${id}">Keep</button>`}</div><p class="pc-fine">${L.filter((x) => !DEC.has(x.id)).length > 1 ? 'For the chosen card · ' : ''}Can’t be undone</p></div>`;
274
+ return (L.length ? `<div class="bd-list pc-list">${L.map((x) => propItem(x, sel)).join('')}</div>` : `<p class="empty3">${CHECK}No agent proposals wait.</p>`) + info + pbar;
275
+ }
276
+ const propTitle = () => { const a = A.prop; if (!a || !a.ok) return 'Agent proposals'; const n = a.items.length; return n ? n + (n === 1 ? ' waits' : ' wait') + ' for you' : 'All decided'; };
277
+ async function propPress(b) {
278
+ if (b.dataset.bda === 'pinfo') { PINFO = !PINFO; draw('[data-bda="pinfo"]'); return; }
279
+ const act = b.dataset.bda, id = b.dataset.id;
280
+ if (act === 'pmore') { if (PMORE.has(id)) PMORE.delete(id); else PMORE.add(id); draw(`[data-bda="pmore"][data-id="${CSS.escape(id)}"]`); return; }
281
+ const it = openProps().find((x) => x.id === id); if (!it) return;
282
+ if (act === 'psel') { PSEL = id; draw(`[data-bda="psel"][data-id="${CSS.escape(id)}"]`); return; }
283
+ if (act === 'pnote') { PBACK.add(id); draw(`[data-bdn="${CSS.escape(id)}"]`); return; }
284
+ if (act === 'pcancel') { PBACK.delete(id); delete PERR[id]; draw(`[data-bda="pnote"][data-id="${CSS.escape(id)}"]`); return; }
285
+ const note = (PNOTE[id] || '').trim();
286
+ if (act === 'pback' && !note) { PERR[id] = 'Write one line for the agent. A note starts its next run.'; draw(`[data-bdn="${CSS.escape(id)}"]`); return; }
287
+ if (!['pkeep', 'pback', 'pdrop'].includes(act)) return;
288
+ BUSY = id; b.disabled = true;
289
+ const r = await pmPost('/api/driver/' + (act === 'pkeep' ? 'keep' : act === 'pback' ? 'return' : 'drop'), { ws: it.ws, proposal: id, ...(act === 'pback' ? { note } : {}) });
290
+ BUSY = '';
291
+ if (!r || r.ok !== true) { PERR[id] = (r && r.error) || 'It was not recorded.'; draw(); return; }
292
+ delete PERR[id]; PBACK.delete(id);
293
+ DEC.set(id, { item: it, st: act === 'pkeep' ? 'kept' : act === 'pback' ? 'back' : 'dropped', note, wrote: r.wrote, warnings: r.warnings || [] });
294
+ toast(act === 'pkeep' ? 'Kept.' : act === 'pback' ? 'Sent back with your note.' : 'Dropped. It counts as a correction.');
295
+ await readAll(['prop']); draw('.pc-bar .pc-p:not([disabled])');
296
+ }
297
+
298
+ /* ── mentions ── */
299
+ const taskLine = (m) => (m.reply ? 'Reply to ' + (m.who ? first(m.who) : 'the sender') + ' (' + srcName(m.source) + ') by today' : 'Read ' + (m.who ? first(m.who) : 'the sender') + '\'s note (' + srcName(m.source) + ')');
300
+ function menHtml() {
301
+ const a = A.men; if (!a || !a.ok) return `<p class="nodef err" role="alert">Mentions ${esc(said(a))}</p>`;
302
+ if (a.list === null) return '<p class="empty3">No brief for today, so no mentions were read.</p><p class="hx-n">Mentions come from today\'s brief. Nothing here replies, reacts or posts in Slack, Jira, Confluence or mail.</p>';
303
+ const l = shownMen(), ORD = ['slack', 'jira', 'confluence', 'mail'], srcs = ORD.filter((k) => l.some((m) => m.source === k)).concat([...new Set(l.map((m) => m.source))].filter((k) => !ORD.includes(k)));
304
+ if (MTAB !== 'all' && !srcs.includes(MTAB)) MTAB = 'all';
305
+ const rows = l.filter((m) => MTAB === 'all' || m.source === MTAB).sort((x, y) => (y.reply - x.reply) || ((y.at ? Date.parse(y.at) : 0) - (x.at ? Date.parse(x.at) : 0)));
306
+ const tabs = `<div class="hx-tabs" role="group" aria-label="Source">${['all', ...srcs].map((k) => `<button type="button" data-bda="mtab" data-k="${esc(k)}" aria-pressed="${MTAB === k}">${k === 'all' ? 'All ' + l.length : esc(srcName(k)) + ' ' + l.filter((m) => m.source === k).length}</button>`).join('')}</div>`;
307
+ const item = (m) => {
308
+ const link = bdLink(m.link), when = mWhen(m.at);
309
+ const acts = m.read ? bdActs(bdBtn('Mark unread', 'munread', m.id, true))
310
+ : bdActs(MADD.has(m.id) ? bdDone(true, 'In your Work list.') : bdBtn('Make it a task', 'madd', m.id), bdBtn('Mark read', 'mread', m.id, true), link ? `<a class="hx-b cta alt" href="${esc(link)}" target="_blank" rel="noopener noreferrer" data-bdlink="${esc(m.id)}">Open in ${esc(srcName(m.source))}</a>` : '')
311
+ + (MADD.has(m.id) ? '' : `<p class="bd-why">Make it a task adds “${esc(taskLine(m))}” to your Work list. Mark read hides it from today's list.</p>`) + bdFail(m.id, SERR);
312
+ return `<div class="bd-it${m.read ? ' decided' : ''}" data-id="${esc(m.id)}"><div class="bd-h">${bdChip(srcName(m.source) + (m.where ? ' · ' + m.where : ''))}${when ? bdChip(when) : ''}${m.reply ? bdChip('Needs your reply', 'warn') : bdChip('For your information')}</div><span class="bd-t">${esc(m.who || srcName(m.source))}</span><p class="bd-q">${esc(m.text)}</p>${m.initiative ? `<p class="bd-why">${esc(m.initiative)}</p>` : ''}${acts}</div>`;
313
+ };
314
+ return (l.length ? `<div class="bd-top">${tabs}</div><div class="bd-list">${rows.map(item).join('')}</div>` : '<p class="empty3">' + CHECK + 'No one has mentioned you today.</p>')
315
+ + '<p class="hx-n">Mentions come from today\'s brief. A mention that is already a Needs-you row is not listed here. Nothing here replies, reacts or posts in Slack, Jira, Confluence or mail.</p>';
316
+ }
317
+ async function menPress(b) {
318
+ const act = b.dataset.bda, id = b.dataset.id;
319
+ if (act === 'mtab') { MTAB = b.dataset.k; draw(`[data-bda="mtab"][data-k="${CSS.escape(MTAB)}"]`); return; }
320
+ const m = shownMen().find((x) => x.id === id); if (!m || !['madd', 'mread', 'munread'].includes(act)) return;
321
+ BUSY = id; b.disabled = true; delete SERR[id];
322
+ const r = act === 'madd' ? await pmPost('/api/pm-items/add', { line: taskLine(m) }) : await pmPost('/api/mentions/read', { id, read: act === 'mread' });
323
+ BUSY = '';
324
+ if (!r || r.ok === false) { SERR[id] = 'That did not go through' + (r && r.error ? ': ' + r.error : '.'); draw(); return; }
325
+ if (act === 'madd') { MADD.add(id); toast('Added to Work: ' + taskLine(m).replace(/ by today$/, '')); draw(`.bd-it[data-id="${CSS.escape(id)}"] [data-bda="mread"]`); }
326
+ else { MREAD.set(id, act === 'mread'); toast(act === 'mread' ? 'Marked read.' : 'Marked unread.'); draw(`.bd-it[data-id="${CSS.escape(id)}"] button`); }
327
+ }
328
+
329
+ /* ── portfolio pulse ── */
330
+ function pulseHtml() {
331
+ const a = A.pulse; if (!a || !a.ok) return `<p class="nodef err" role="alert">Portfolio pulse ${esc(said(a))}</p>`;
332
+ const g = groups(a.rows), n = a.rows.length + a.none, item = (r) => `<div class="bd-it"><div class="bd-h">${bdChip(r.word, r.cls === 'bad' ? 'hot' : r.cls === 'warn' ? 'warn' : '')}${r.pname ? bdChip(r.pname) : ''}</div><span class="bd-t">${esc(r.title)}</span><p class="bd-why">${esc(r.why)}</p>${bdActs(`<a class="hx-b cta alt" href="/premium.html?ini=${encodeURIComponent(r.id)}${r.ws ? '&ws=' + encodeURIComponent(r.ws) : ''}">Open the initiative</a>`)}</div>`;
333
+ const hot = g.bad.concat(g.warn);
334
+ return `<div class="bd-leg">${['bad', 'warn', 'ok', 'none'].map((k) => `<span><i class="${k}"></i>${PGW[k]} ${k === 'none' ? g.none.length + a.none : g[k].length}</span>`).join('')}</div>${n ? bar(g, n, a.none) : ''}`
335
+ + H2('Needs a look') + (hot.length ? `<div class="bd-list">${hot.map(item).join('')}</div>` : '<p class="hx-n">Nothing is late or at risk.</p>')
336
+ + `<details class="bd-more"><summary>${g.ok.length} on plan</summary><div class="bd-list">${g.ok.map(item).join('')}</div></details>`
337
+ + `<details class="bd-more"><summary>${g.none.length + a.none} with no plan date</summary><div class="bd-list">${g.none.map(item).join('')}</div>${a.none ? `<p class="hx-n">${pl(a.none, 'more initiative has', 'more initiatives have')} no promised date and no Jira read, so they are not listed.</p>` : ''}</details>`
338
+ + (a.errs.length ? `<p class="hx-n">Not read: ${esc(a.errs[0])}</p>` : '') + '<p class="hx-n">The status is the Calendar\'s: the promised date against the forecast, or the Jira read. It is not a forecast of its own, and nothing here changes a record.</p>';
339
+ }
340
+
341
+ /* ── horizon scan ── */
342
+ const SKIND = { create: ['New initiative', 'Approve', 'The initiative was created in the first stage of the board.'], research: ['Research', 'Start the research', 'A research scan was started.'], attach: ['Evidence', 'Approve', 'An evidence line was written.'] };
343
+ const sDoes = (p) => { const f = p.fields || {}; return p.kind === 'create' ? 'Approve creates the initiative in the first stage of the ' + (f.board || 'board') + ' workflow.' : p.kind === 'research' ? 'Start the research starts a research scan' + (f.question ? ' for “' + f.question + '”' : '') + '.' : 'Approve writes an evidence line on ' + (f.initiative || 'the initiative') + '.'; };
344
+ function scanProp(p, ws) {
345
+ const d = SDEC.get(p.id), k = SKIND[p.kind] || [p.kind, 'Approve', 'It is recorded.'], f = p.fields || {};
346
+ const act = d ? bdDone(d.st === 'ok', d.st === 'ok' ? 'Approved. ' + k[2] : 'Dismissed. It counts as a correction.') + (d.st === 'no' ? bdActs(bdBtn('Undo', 'sundo', p.id, true, ` data-ws="${esc(ws)}"`)) : '')
347
+ : SOPEN.has(p.id) ? `<label class="bd-l" for="bds-${esc(p.id)}">Why dismiss it? A reason is required.</label><input type="text" id="bds-${esc(p.id)}" data-bds="${esc(p.id)}" maxlength="500" value="${esc(SWHY[p.id] || '')}" placeholder="For example: we already decided this">${bdFail(p.id, SERR)}`
348
+ + bdActs(bdBtn('Dismiss', 'sdis', p.id, false, ` data-ws="${esc(ws)}"${(SWHY[p.id] || '').trim() ? '' : ' disabled'}`), bdBtn('Cancel', 'sdiscancel', p.id, true)) + '<p class="bd-why">A dismissal counts as a correction. The scan will not raise the same thing again.</p>'
349
+ : bdActs(bdBtn(k[1], 'sapp', p.id, false, ` data-ws="${esc(ws)}"`), bdBtn('Dismiss', 'sdisopen', p.id, true)) + `<p class="bd-why">${esc(sDoes(p))} Dismiss asks for a reason and counts as a correction.</p>` + bdFail(p.id, SERR);
350
+ return `<div class="bd-it${d ? ' decided' : ''}" data-id="${esc(p.id)}"><div class="bd-h">${bdChip(k[0])}${f.board ? bdChip(f.board) : ''}</div><span class="bd-t">${esc(p.title)}</span>${p.why ? `<p class="bd-why">${esc(p.why)}</p>` : ''}${p.finding ? `<p class="bd-q">${esc(p.finding)}</p>` : ''}${act}</div>`;
351
+ }
352
+ function scanPart(s) {
353
+ const lastWord = s.last ? dayWord(s.last.at) + (s.last.ok === false ? ' (did not finish' + (s.last.reason ? ': ' + s.last.reason : '') + ')' : '') : 'No scan has run yet';
354
+ const nextWord = s.switched_off ? 'Scans are switched off on this machine' : s.next ? dayWord(s.next) + (s.schedule ? ' · ' + s.schedule : '') : (s.schedule || 'Not scheduled');
355
+ let ctl;
356
+ if (s.open) ctl = `<div class="bd-it"><span class="bd-t">Scanning now</span><div class="bd-steps">${(s.open.steps || []).map((x) => `<div class="${esc(x.state)}"><i></i>${esc(x.label || x.id)}${x.state === 'work' ? ' …' : ''}</div>`).join('')}</div>${bdActs(bdBtn(s.open.stopping ? 'Stopping…' : 'Stop', 'sstop', s.ws, true, s.open.stopping ? ' disabled' : ''))}<p class="bd-why">Stop ends the scan. Nothing it has not filed is written.</p></div>`;
357
+ else {
358
+ const m = s.manual || {}, no = s.switched_off ? 'Scans are switched off on this machine.' : m.ok === false ? (m.error || 'A manual scan cannot start now.') : '';
359
+ ctl = bdActs(bdBtn('Scan now', 'snow', s.ws, false, no ? ' disabled' : '')) + `<p class="bd-why">${no ? esc(no) + ' ' : ''}Scan now starts an agent that reads the public web for your watch list and this repository, then writes reports with proposals. Nothing acts until you approve it.${m.limit ? ' ' + m.left + ' of ' + m.limit + ' manual scans left today.' : ''}</p>`;
360
+ }
361
+ const top = s.reports.filter((r) => !r.parent && r.written), scan = s.last && s.last.scan, show = top.filter((r) => r.scan === scan || (r.proposals && r.proposals.open > 0) || [...SDEC.values()].some((d) => d.p.report === r.id));
362
+ const reps = show.map((r) => {
363
+ const ps = s.proposals.filter((p) => p.report === r.id), dec = [...SDEC.entries()].filter(([, d]) => d.p.report === r.id && !ps.some((p) => p.id === d.p.id)).map(([, d]) => d.p), all = ps.concat(dec);
364
+ return H2(r.label || r.type + ' report') + `<p class="bd-q">${esc(r.title)}</p><p class="bd-why">From: ${esc(r.origin || 'the repository')} · ${ps.length} of ${(r.proposals && r.proposals.total) || all.length} proposals wait</p><div class="bd-list">${all.map((p) => scanProp(p, s.ws)).join('')}</div>`;
365
+ }).join('');
366
+ return (s.pname ? H2(s.pname) : '') + kv([['Last scan', lastWord], ['Next', nextWord]]) + ctl + (reps || (s.last ? '<p class="hx-n">The last scan wrote no report.</p>' : ''));
367
+ }
368
+ function scanHtml() {
369
+ const a = A.scan; if (!a || !a.ok) return `<p class="nodef err" role="alert">Horizon scan ${esc(said(a))}</p>`;
370
+ return a.scans.map(scanPart).join('') + (a.errs.length ? `<p class="hx-n">Not read: ${esc(a.errs[0])}</p>` : '') + '<p class="hx-n">One scan covers the whole product. The watch list, the scan setting, the report documents and Change on a proposal stay in Settings.</p>';
371
+ }
372
+ let SPOLL = null;
373
+ function scanPoll() {
374
+ clearTimeout(SPOLL);
375
+ if (!A.scan || !A.scan.ok || !A.scan.scans.some((s) => s.open)) return;
376
+ SPOLL = setTimeout(async () => { if (VIEW !== 'scan') return; await readAll(['scan']); scanPoll(); }, 4000);
377
+ }
378
+ async function scanPress(b) {
379
+ const act = b.dataset.bda, id = b.dataset.id, ws = b.dataset.ws || '';
380
+ if (act === 'sdisopen') { SOPEN.add(id); draw(`[data-bds="${CSS.escape(id)}"]`); return; }
381
+ if (act === 'sdiscancel') { SOPEN.delete(id); delete SERR[id]; draw(`[data-bda="sdisopen"][data-id="${CSS.escape(id)}"]`); return; }
382
+ if (!['snow', 'sstop', 'sapp', 'sdis', 'sundo'].includes(act)) return;
383
+ const why = (SWHY[id] || '').trim();
384
+ if (act === 'sdis' && !why) return;
385
+ BUSY = id; b.disabled = true;
386
+ let r;
387
+ if (act === 'snow') r = await pmPost('/api/scan/now', { ws: id });
388
+ else if (act === 'sstop') r = await pmPost('/api/scan/stop', { ws: id });
389
+ else r = await pmPost('/api/scan/proposal', { ws, id, action: act === 'sapp' ? 'approve' : act === 'sdis' ? 'dismiss' : 'undo', ...(act === 'sdis' ? { why } : {}) });
390
+ BUSY = '';
391
+ if (!r || r.ok !== true) { SERR[id] = (r && r.error) || 'It did not go through.'; draw(); toast(SERR[id]); return; }
392
+ delete SERR[id];
393
+ if (act === 'sapp' || act === 'sdis') { const p = A.scan.scans.flatMap((s) => s.proposals).find((x) => x.id === id); if (p) SDEC.set(id, { st: act === 'sapp' ? 'ok' : 'no', p }); SOPEN.delete(id); toast(act === 'sapp' ? 'Approved.' : 'Dismissed. It counts as a correction.'); }
394
+ else if (act === 'sundo') { SDEC.delete(id); toast('The dismissal was taken back.'); }
395
+ else toast(act === 'snow' ? 'Scan started. It runs in the background.' : 'Stopping the scan.');
396
+ await readAll(['scan']); draw(act === 'snow' ? '[data-bda="sstop"]' : act === 'sstop' ? '[data-bda="snow"]' : `.bd-it[data-id="${CSS.escape(id)}"] .bd-done`); scanPoll();
397
+ }
398
+
399
+ /* ── report found ── */
400
+ const EVK = { mail: 'Mail', calendar: 'Calendar', slack: 'Slack', drive: 'Drive', confluence: 'Confluence' };
401
+ const CONF = { likely: 'Likely', 'not-sure': 'Not sure' };
402
+ function repItem(f) {
403
+ const d = REC.get(f.id), id = f.id;
404
+ const ev = (f.evidence || []).filter((e) => e && e.text).map((e) => bdChip((EVK[e.kind] || String(e.kind || 'Source')) + ': ' + e.text)).join('');
405
+ const act = d ? (d.st === 'set' ? bdDone(true, 'Set up' + (d.setup ? ' as ' + d.setup : '') + '. Its first cycle is drafted on this machine. Nothing was sent.') : bdDone(true, 'Marked not a report. The finder will not raise it again.'))
406
+ : bdActs(bdBtn('Set up', 'rset', id, false, ` data-ws="${esc(f.ws)}"`), bdBtn('Not a report', 'rno', id, true, ` data-ws="${esc(f.ws)}"`)) + '<p class="bd-why">Set up creates the recurring report and drafts its first cycle on this machine. PMOS drafts only. Nothing is sent. Not a report: the finder will not raise it again.</p>' + bdFail(id, RERR);
407
+ return `<div class="bd-it${d ? ' decided' : ''}" data-id="${esc(id)}"><div class="bd-h">${f.confidence && CONF[f.confidence] ? bdChip(CONF[f.confidence]) : ''}${f.pname ? bdChip(f.pname) : ''}</div><span class="bd-t">${esc(f.name)}</span>${f.why ? `<p class="bd-q">${esc(f.why)}</p>` : ''}${ev ? `<p class="bd-h">${ev}</p>` : ''}${act}</div>`;
408
+ }
409
+ function repHtml() {
410
+ const a = A.rep; if (!a || !a.ok) return `<p class="nodef err" role="alert">Report finder ${esc(said(a))}</p>`;
411
+ const L = repFound().concat([...REC.values()].map((d) => d.f).filter((f) => !repFound().some((o) => o.id === f.id && o.ws === f.ws)));
412
+ return (L.length ? `<p class="bd-top">${repFound().length ? pl(repFound().length, 'report was', 'reports were') + ' found in your work.' : 'All decided.'} PMOS drafts only. Nothing is sent.</p><div class="bd-list">${L.map(repItem).join('')}</div>` : `<p class="empty3">${CHECK}No report found.</p>`)
413
+ + (a.errs.length ? `<p class="hx-n">Not read: ${esc(a.errs[0])}</p>` : '') + '<p class="hx-n">The finder reads your calendar, Slack and the subjects of mail you sent, never message bodies. Change first, the report finder settings and every other report press stay in Insights.</p>';
414
+ }
415
+ async function repPress(b) {
416
+ const act = b.dataset.bda, id = b.dataset.id, ws = b.dataset.ws || '', f = repFound().find((x) => x.id === id && x.ws === ws);
417
+ if (!f || !['rset', 'rno'].includes(act)) return;
418
+ BUSY = id; b.disabled = true;
419
+ const r = act === 'rset' ? await pmPost('/api/report-setups/setup', { ws, finding: id }) : await pmPost('/api/report-setups/dismiss', { ws, finding: id, name: f.name });
420
+ BUSY = '';
421
+ if (!r || r.ok !== true) { RERR[id] = (r && r.error) || 'It did not go through.'; draw(); toast(RERR[id]); return; }
422
+ delete RERR[id];
423
+ REC.set(id, { st: act === 'rset' ? 'set' : 'no', f, setup: act === 'rset' && r.setup ? r.setup.name || '' : '' });
424
+ toast(act === 'rset' ? 'Set up. Nothing is sent.' : 'Marked not a report.');
425
+ await readAll(['rep']); draw(`.bd-it[data-id="${CSS.escape(id)}"] .bd-done`);
426
+ }
427
+
428
+ /* ── data freshness ── */
429
+ const SSTATE = { fresh: 'Recent', stale: 'Old', never: 'Never read', building: 'Reading now…', failed: 'Failed', off: 'Off' };
430
+ const limitWord = (ms) => (ms >= 48 * 3600000 ? Math.round(ms / 86400000) + ' days' : Math.round(ms / 3600000) + ' hours');
431
+ function srcHtml() {
432
+ const a = A.src; if (!a || !a.ok) return `<p class="nodef err" role="alert">Data freshness ${esc(said(a))}</p>`;
433
+ const b = behindSrc(), many = refreshTargets(a.sources);
434
+ const row = (s) => {
435
+ const when = s.id === 'repository' && s.state === 'fresh' ? 'watching' : s.as_of ? whenRead(s.as_of) : 'never';
436
+ const sch = s.schedule ? [s.schedule.cadence, s.schedule.day, s.schedule.time].filter(Boolean).join(' ') : s.skill ? 'no schedule' : 'on every change';
437
+ return `<div class="bd-src"><span><b>${esc(s.label)}</b><small><span class="bd-st ${esc(s.state)}">${esc(SSTATE[s.state] || s.state)}</span> · ${esc(when)} · ${esc(sch)}${s.stale_after_ms ? ' · old after ' + esc(limitWord(s.stale_after_ms)) : ''}</small><small>${s.skill ? 'Refresh starts the ' + esc(s.skill) + ' skill in an agent session, with your own connection.' : 'Refresh rebuilds the facts on this machine.'}</small>${SNOTE[s.id] ? `<small role="status">${esc(SNOTE[s.id])}</small>` : ''}</span>${bdBtn('Refresh', 'sfone', s.id, true, (s.state === 'off' || s.state === 'building' ? ' disabled' : '') + ` aria-label="Refresh ${esc(s.label)}"`)}</div>`;
438
+ };
439
+ return `<div class="bd-top"><p class="hx-n">Sources are read on a schedule, not live. ${b.length ? pl(b.length, 'source needs', 'sources need') + ' a new read.' : 'None is old.'}</p>${bdBtn('Refresh all', 'sfall', '', false, many.length ? '' : ' disabled')}</div>${a.sources.map(row).join('')}<p class="hx-n">Refresh all reads every source, then writes Home's list from those reads. The server calls nothing outside this machine: an outside source is read by a skill, with your own connection.</p>`;
440
+ }
441
+ let FPOLL = null;
442
+ function srcPoll(n) {
443
+ clearTimeout(FPOLL);
444
+ if (!n || !A.src || !A.src.ok || !A.src.sources.some((s) => s.state === 'building')) return;
445
+ FPOLL = setTimeout(async () => { if (VIEW !== 'src') return; await readAll(['src']); srcPoll(n - 1); }, 3000);
446
+ }
447
+ async function srcPress(b) {
448
+ const act = b.dataset.bda; if (!['sfone', 'sfall'].includes(act)) return;
449
+ const ids = act === 'sfall' ? refreshTargets(A.src.sources) : [b.dataset.id];
450
+ BUSY = 'src'; b.disabled = true;
451
+ if (act === 'sfall') {
452
+ const r = await pmPost('/api/sources/refresh-all', { ws: A.src.ws || wsParam() || '' });
453
+ BUSY = '';
454
+ toast(!r || !r.ok ? 'Refresh all did not start: ' + ((r && r.error) || 'the server did not answer') + '.' : r.joined ? 'Refresh all is already running. ' + allText(r.all) : allText(r.all));
455
+ await readAll(['src']); draw('[data-bda="sfall"]'); srcPoll(8);
456
+ return;
457
+ }
458
+ const got = await Promise.all(ids.map(async (id) => [id, await pmPost('/api/sources/refresh', { ws: A.src.ws || wsParam() || '', source: id })]));
459
+ BUSY = '';
460
+ let bad = 0;
461
+ for (const [id, r] of got) { if (r && r.ok) SNOTE[id] = r.started === 'session' ? 'An agent session started to read it.' : 'Rebuilding the facts on this machine.'; else { bad++; SNOTE[id] = 'It did not start: ' + ((r && r.error) || 'the server did not answer') + '.'; } }
462
+ toast(bad ? bad + ' of ' + ids.length + ' did not start.' : 'Reading again.');
463
+ await readAll(['src']); draw(`[data-bda="sfone"][data-id="${CSS.escape(ids[0])}"]`); srcPoll(8);
464
+ }
465
+
466
+ /* ── the card ── */
467
+ const VIEWS = {
468
+ prop: { kind: 'Agent proposals', title: propTitle, html: propsHtml, press: propPress, say: () => (A.prop && A.prop.ok ? (A.prop.items.length ? pl(A.prop.items.length, 'proposal waits', 'proposals wait') + ' for you. Keep one to record it, send it back with a note, or drop it.' : 'No proposal waits for you.') : 'The proposals could not be read.') },
469
+ men: { kind: 'Mentions', title: () => 'Mentions', html: menHtml, press: menPress, say: () => (A.men && A.men.ok && A.men.list ? menLine(shownMen()) + ' Make one a task, mark it read, or open it where it was said.' : 'Mentions could not be read from today\'s brief.') },
470
+ pulse: { kind: 'Portfolio pulse', title: () => 'Portfolio pulse', html: pulseHtml, press: async () => {}, say: () => { const a = A.pulse, g = a && a.ok ? groups(a.rows) : null; return g ? `${g.bad.length} late and ${g.warn.length} at risk, of ${a.rows.length + a.none}. The late and at-risk ones are listed first.` : 'The initiatives could not be read.'; } },
471
+ scan: { kind: 'Horizon scan', title: () => 'Horizon scan', html: scanHtml, press: scanPress, say: () => (A.scan && A.scan.ok ? (scanOpen() ? pl(scanOpen(), 'proposal waits', 'proposals wait') + ' for you. Nothing acts until you approve it.' : 'No proposal waits for you. Nothing acts until you approve it.') : 'The scan could not be read.') },
472
+ rep: { kind: 'Report finder', title: () => 'Report found', html: repHtml, press: repPress, say: () => (A.rep && A.rep.ok ? (repFound().length ? pl(repFound().length, 'report was', 'reports were') + ' found in your work. Set it up, or say it is not a report. PMOS drafts only.' : 'No report waits for you.') : 'The findings could not be read.') },
473
+ src: { kind: 'Data freshness', title: () => 'Data freshness', html: srcHtml, press: srcPress, say: () => { const b = behindSrc(); return A.src && A.src.ok ? (b.length ? joinN(b.map((s) => s.label)) + (b.length === 1 ? ' needs' : ' need') + ' a new read. Refresh one, or all.' : 'Every source was read recently.') : 'The sources could not be read.'; } },
474
+ };
475
+ let BODY = null;
476
+ /** Draw the card: the rows, or the open view. focus: a selector to focus after the draw. */
477
+ function draw(focus) {
478
+ if (!BODY || !BODY.isConnected) return;
479
+ const V = VIEWS[VIEW];
480
+ if (!V) BODY.innerHTML = `<div class="ar">${listHtml()}</div>`;
481
+ else {
482
+ const t = document.getElementById('czVwTitle'); if (t) t.textContent = V.title();
483
+ BODY.innerHTML = `<div class="ar">${WAIT}<div class="ar-hd"><button type="button" class="hx-b alt" data-bda="back">Back to Around you</button></div><p class="hx-n ar-say">${esc(V.say())}</p><div class="bd-a" data-bd-view="${VIEW}">${V.html()}</div></div>`;
484
+ }
485
+ BODY.querySelectorAll('.bd-bar i[data-w]').forEach((i) => i.style.setProperty('--bd-w', i.dataset.w + '%')); // each part of the pulse bar is as wide as its share
486
+ if (focus) { const f = BODY.querySelector(focus) || BODY.querySelector('.bd-a button:not([disabled]), .bd-a a'); if (f) f.focus(); }
487
+ }
488
+ const redraw = () => draw();
489
+ function show(k) {
490
+ VIEW = VIEWS[k] ? k : '';
491
+ PSEL = ''; PINFO = false;
492
+ BODY = vwOpen({ id: 'more:around' + (VIEW ? ':' + VIEW : ''), kind: VIEW ? VIEWS[VIEW].kind : 'Around you', title: VIEW ? VIEWS[VIEW].title() : 'What the agents and others left for you', icon: 'info',
493
+ render: (b) => { b.classList.add('hx'); BODY = b; draw(); wire(b); }, onClose: () => { clearTimeout(SPOLL); clearTimeout(FPOLL); } });
494
+ if (VIEW === 'scan') scanPoll();
495
+ if (VIEW === 'src') srcPoll(8);
496
+ return BODY;
497
+ }
498
+ function wire(b) {
499
+ b.onclick = async (e) => {
500
+ const r = e.target.closest('[data-bd]'); if (r && !VIEW) { show(r.dataset.bd); return; }
501
+ const t = e.target.closest('[data-bda]'); if (!t || BUSY) return;
502
+ if (t.dataset.bda === 'back') { show(''); return; }
503
+ if (t.disabled) return;
504
+ if (VIEWS[VIEW]) await VIEWS[VIEW].press(t);
505
+ };
506
+ b.oninput = (e) => {
507
+ const n = e.target.closest('[data-bdn]'); if (n) { PNOTE[n.dataset.bdn] = n.value; const k = b.querySelector(`[data-bda="pback"][data-id="${CSS.escape(n.dataset.bdn)}"]`); if (k) k.disabled = !n.value.trim(); return; }
508
+ const s = e.target.closest('[data-bds]'); if (s) { SWHY[s.dataset.bds] = s.value; const k = b.querySelector(`[data-bda="sdis"][data-id="${CSS.escape(s.dataset.bds)}"]`); if (k) k.disabled = !s.value.trim(); }
509
+ };
510
+ }
511
+ export function openAround(key) {
512
+ const body = show(key || '');
513
+ readAll();
514
+ return body;
515
+ }