create-pmos 0.106.0 → 0.108.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.
@@ -0,0 +1,383 @@
1
+ /* pm/dest-notes.js — the Notes place: every meeting note, grouped by initiative, and the note itself (meeting-notes Run 12,
2
+ * the "Notes: next features" mockup the PM approved on 2026-10-07, board 1 "Notes menu").
3
+ *
4
+ * A DESTINATION MODULE (registry.js): mountDestination(host, ctx) on every render with the same host, disposeDestination(host).
5
+ * It keeps ONE persistent root per host and redraws its two cards only when what they show changed, so a title being typed
6
+ * keeps its focus. A link from another place (a calendar event, an initiative's Notes tab) opens a note through the tab's slug.
7
+ *
8
+ * Layout, as the mockup: the page title and a search field, then two cards side by side.
9
+ * left BY INITIATIVE · n notes. One group per initiative, then "No initiative"; each row is the meeting time or day,
10
+ * the title, and an amber dot when a statement in the note differs from a file in the repository.
11
+ * right the note: one meta line (Meeting note · day time · length · initiative), the title with Record / Resume / Stop
12
+ * and the ⋯ menu, then only what is there: Conflicts with other files, Highlights, the Overview, Decisions,
13
+ * Next steps (owner · due, and Make task), Open questions, and the discussion and transcript folded at the end.
14
+ *
15
+ * WHERE EACH PART COMES FROM. After Stop and the final pass, the agent's final notes (note.final_notes: grounded in quotes);
16
+ * before that, what was caught live (view-notes.js caughtItems: the agent's minute bullets, else the labelled lines) and
17
+ * the overview the agent or this machine wrote. Conflicts are the lines, bullets and highlights whose repository check says
18
+ * the file differs (lib/notes.js conflictsOf). The overview and the final items are edited in place: a click puts the
19
+ * cursor in the text and leaving it saves (POST /api/notes/final-edit), as the mockup shows. Make task adds the next step
20
+ * to the note's initiative as a plan item in its first stage (POST /api/plan-items, the Breakdown's own writer), with Undo.
21
+ */
22
+
23
+ import { el } from './dom.js';
24
+ import { button, iconButton, field, row, menu, toast, empty, ensureComponentsCss } from './primitives.js';
25
+ import { ensureSprite } from './icons.js';
26
+ import { pmGet, pmPost } from './http.js';
27
+ import { registerCommand, openDestination } from './registry.js';
28
+ import { askConfirm } from './dialogs.js';
29
+ import * as dock from './note-dock.js';
30
+ import * as V from './view-notes.js';
31
+ import { makeTask as makeTaskFrom } from './notes-task.js';
32
+
33
+ export const COPY = Object.freeze({
34
+ title: 'Notes',
35
+ fixture: 'Notes shows your meeting notes in a real session.',
36
+ search: 'Search notes',
37
+ byInitiative: 'By initiative',
38
+ count: (n) => `${n} ${n === 1 ? 'note' : 'notes'}`,
39
+ noInitiative: 'No initiative',
40
+ none: 'No notes yet. Press Record at the top right to start one.',
41
+ noMatch: (q) => `No note matches “${q}”.`,
42
+ pick: 'Choose a note to read it.',
43
+ reading: 'Reading…',
44
+ readError: 'The notes could not be read.',
45
+ meetingNote: 'Meeting note',
46
+ record: 'Record', resume: 'Resume', stop: 'Stop',
47
+ conflicts: 'Conflicts with other files',
48
+ conflictWith: 'conflicts with',
49
+ openFile: 'Open file',
50
+ highlights: 'Highlights',
51
+ overview: 'Overview',
52
+ noOverview: 'No overview yet. It is written when you stop recording.',
53
+ decisions: 'Decisions', actions: 'Next steps', questions: 'Open questions',
54
+ makeTask: 'Make task',
55
+ taskAdded: (ini, stage) => `Added to ${ini}, under ${stage}`,
56
+ taskNoInitiative: 'Link the note to an initiative first. Make task adds the step to its breakdown.',
57
+ taskFailed: 'The task was not made',
58
+ undo: 'Undo',
59
+ discussion: 'Discussion',
60
+ transcript: (n) => `${n} transcript ${n === 1 ? 'line' : 'lines'}`,
61
+ openFull: 'Open the full note',
62
+ del: 'Delete note',
63
+ delAsk: (t) => `Delete “${t}”?`,
64
+ delBody: 'The note, its transcript and its audio are deleted from this machine.',
65
+ saved: 'Saved',
66
+ notSaved: 'Not saved',
67
+ edited: 'edited',
68
+ });
69
+
70
+ registerCommand({ id: 'notes-open', label: 'Notes', hint: 'Your meeting notes, by initiative', cli: null, run: () => openDestination('notes') });
71
+ registerCommand({ id: 'notes-menu-open', label: 'notes menu', hint: 'All notes by initiative', cli: null, run: () => openDestination('notes') });
72
+
73
+ /* ── words ───────────────────────────────────────────────────────────────────────────────────────────────────────── */
74
+
75
+ const dayStart = (d) => { const t = new Date(d); t.setHours(0, 0, 0, 0); return t.getTime(); };
76
+ /** The left column's time: "14:00" today, "Mon" this week, else "1 Oct". */
77
+ export function whenShort(iso, now = Date.now()) {
78
+ const t = Date.parse(iso);
79
+ if (!Number.isFinite(t)) return '';
80
+ const d = new Date(t);
81
+ const days = Math.round((dayStart(now) - dayStart(t)) / 86400000);
82
+ if (days === 0) return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false });
83
+ if (days > 0 && days < 7) return d.toLocaleDateString('en-GB', { weekday: 'short' });
84
+ return d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short' });
85
+ }
86
+ /** "Today 14:00", "Mon 6 Oct 14:00". */
87
+ function whenLong(iso, now = Date.now()) {
88
+ const t = Date.parse(iso);
89
+ if (!Number.isFinite(t)) return '';
90
+ const d = new Date(t);
91
+ const hm = d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false });
92
+ return (dayStart(now) === dayStart(t) ? 'Today' : d.toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short' })) + ' ' + hm;
93
+ }
94
+ const minutes = (ms) => (ms >= 60000 ? Math.round(ms / 60000) + ' min' : '');
95
+ const startOf = (n) => (n.meeting && n.meeting.start) || n.recorded_from || n.created_at || n.updated_at;
96
+ const iniName = (i) => (i ? i.title || i.id : null);
97
+ const lengthOf = (n) => {
98
+ const ts = (n.transcript || []).map((x) => x.t || 0);
99
+ return ts.length ? Math.max(...ts) : 0;
100
+ };
101
+
102
+ /** The notes, grouped by initiative title, "No initiative" last; each group newest first. Pure. */
103
+ export function groupNotes(rows) {
104
+ const groups = new Map();
105
+ for (const r of rows) {
106
+ const k = iniName(r.initiative) || '';
107
+ if (!groups.has(k)) groups.set(k, []);
108
+ groups.get(k).push(r);
109
+ }
110
+ return [...groups.entries()]
111
+ .sort((a, b) => (a[0] === '' ? 1 : b[0] === '' ? -1 : a[0].localeCompare(b[0])))
112
+ .map(([k, list]) => ({ key: k, label: k || COPY.noInitiative, rows: list }));
113
+ }
114
+
115
+ /** What the note shows, from the final notes when there are some, else from what was caught live. Pure. */
116
+ export function partsOf(n) {
117
+ const f = n.final_notes;
118
+ if (f) {
119
+ return {
120
+ from: 'final',
121
+ overview: f.overview || f.purpose || '',
122
+ decisions: (f.decisions || []).map((x, i) => ({ ...x, sec: 'decision', i })),
123
+ actions: (f.actions || []).map((x, i) => ({ ...x, sec: 'action', i })),
124
+ questions: (f.questions || []).map((x, i) => ({ ...x, sec: 'question', i })),
125
+ topics: f.topics || [],
126
+ };
127
+ }
128
+ const c = V.caughtItems(n);
129
+ let overview = '';
130
+ if (n.agent && n.agent.markdown) overview = String(n.agent.markdown).split(/\r?\n/).map((l) => l.replace(/^\s*(?:#+|[-*]|\d+[.)])\s*/, '').replace(/\*\*|__|`/g, '').trim()).filter((l) => l && !/^(summary|overview)$/i.test(l)).join(' ');
131
+ else {
132
+ const ov = n.summary && n.summary.sections && n.summary.sections.overview;
133
+ if (Array.isArray(ov)) overview = ov.map((x) => String((x && x.text) || '')).filter(Boolean).join(' ');
134
+ }
135
+ return { from: 'live', overview, decisions: c.decision, actions: c.action, questions: c.question, topics: [] };
136
+ }
137
+
138
+ /** The statements that differ from a repository file (lib/notes.js conflictsOf, read on the page). Pure. */
139
+ export function conflictsOf(n) {
140
+ const out = []; const seen = new Set();
141
+ const add = (x) => {
142
+ const c = x && !x.dropped && x.check;
143
+ if (!c || c.verdict !== 'differs' || !c.doc) return;
144
+ const k = c.doc + ':' + (c.line || 0);
145
+ if (seen.has(k)) return;
146
+ seen.add(k);
147
+ out.push({ text: x.text, doc: c.doc, line: c.line || null, t: typeof x.t === 'number' ? x.t : null });
148
+ };
149
+ (n.highlights || []).forEach(add); (n.transcript || []).forEach(add); (n.bullets || []).forEach(add);
150
+ return out;
151
+ }
152
+
153
+ /* ── mount ───────────────────────────────────────────────────────────────────────────────────────────────────────── */
154
+
155
+ const insts = new WeakMap();
156
+ const REREAD_MS = 4000;
157
+
158
+ export function mountDestination(host, ctx) {
159
+ let inst = insts.get(host);
160
+ if (!inst) {
161
+ inst = { host, root: el('div', { class: 'rp-page nt-pg', 'data-notes-page': '' }), head: null, left: el('section', { class: 'nt-pg-card nt-pg-list', 'data-ntm': 'list' }),
162
+ right: el('section', { class: 'nt-pg-card nt-pg-note', 'data-ntm': 'note' }), rows: null, error: null, q: '', open: null, note: null, slug: null,
163
+ readAt: 0, seq: 0, leftSig: '', rightSig: '', repo: null, ctx };
164
+ insts.set(host, inst);
165
+ }
166
+ inst.ctx = ctx;
167
+ ensureComponentsCss();
168
+ if (!inst.root.isConnected || inst.root.parentNode !== host) host.replaceChildren(inst.root);
169
+ if (ctx && ctx.FIXTURE) { inst.root.replaceChildren(empty({ text: COPY.fixture })); return; }
170
+ ensureSprite();
171
+ if (!inst.head) {
172
+ const find = field({ label: COPY.search, kind: 'text', hideLabel: true, placeholder: COPY.search, attrs: { 'data-ntm': 'search', class: 'nt-pg-search' } });
173
+ find.control.addEventListener('input', () => { inst.q = find.control.value; drawLeft(inst, true); });
174
+ inst.head = el('div', { class: 'rp-head nt-pg-head' }, el('h1', { class: 'rp-head__title' }, COPY.title), find);
175
+ inst.root.replaceChildren(inst.head, el('div', { class: 'nt-pg-grid' }, inst.left, inst.right));
176
+ }
177
+ inst.repo = (ctx && ctx.tab && ctx.tab.repo) || (ctx && ctx.state && ctx.state.product) || null;
178
+ const slug = (ctx && ctx.tab && ctx.tab.slug) || null;
179
+ if (slug !== inst.slug) { inst.slug = slug; if (slug) { inst.open = slug; inst.note = null; } }
180
+ if (!inst.rows || Date.now() - inst.readAt > REREAD_MS) refresh(inst);
181
+ drawLeft(inst);
182
+ drawRight(inst);
183
+ }
184
+
185
+ export function disposeDestination(host) {
186
+ const inst = insts.get(host);
187
+ if (!inst) return;
188
+ inst.seq++;
189
+ inst.root.remove();
190
+ insts.delete(host);
191
+ }
192
+
193
+ async function refresh(inst) {
194
+ const seq = ++inst.seq;
195
+ inst.readAt = Date.now();
196
+ const [r, one] = await Promise.all([pmGet('/api/notes'), inst.open ? pmGet('/api/notes/one?id=' + encodeURIComponent(inst.open)) : null]);
197
+ if (seq !== inst.seq) return;
198
+ if (r && r.ok) { inst.rows = r.notes || []; inst.error = null; } else { inst.rows = inst.rows || []; inst.error = (r && r.error) || COPY.readError; }
199
+ if (!inst.open && inst.rows.length) inst.open = inst.rows[0].id;
200
+ if (one && one.ok && one.note && one.note.id === inst.open) inst.note = one.note;
201
+ else if (inst.open && !one) loadOpen(inst);
202
+ drawLeft(inst);
203
+ drawRight(inst);
204
+ }
205
+ async function loadOpen(inst) {
206
+ const id = inst.open;
207
+ const r = await pmGet('/api/notes/one?id=' + encodeURIComponent(id));
208
+ if (inst.open !== id) return;
209
+ inst.note = r && r.ok ? r.note : null;
210
+ drawRight(inst);
211
+ }
212
+ function choose(inst, id) {
213
+ if (inst.open === id) return;
214
+ inst.open = id; inst.note = null;
215
+ drawLeft(inst, true); drawRight(inst);
216
+ loadOpen(inst);
217
+ }
218
+
219
+ /* ── the left card: notes by initiative ──────────────────────────────────────────────────────────────────────────── */
220
+
221
+ function drawLeft(inst, force) {
222
+ const rows = inst.rows;
223
+ const q = inst.q.trim().toLowerCase();
224
+ const sig = JSON.stringify([rows && rows.map((r) => [r.id, r.title, r.updated_at, iniName(r.initiative), r.conflicts]), q, inst.open, inst.error]);
225
+ if (!force && sig === inst.leftSig) return;
226
+ inst.leftSig = sig;
227
+ const shown = (rows || []).filter((r) => !q || String(r.title || '').toLowerCase().includes(q) || String(iniName(r.initiative) || '').toLowerCase().includes(q));
228
+ const head = el('h2', { class: 'nt-pg-label' }, el('span', null, COPY.byInitiative), el('span', { class: 'nt-pg-label__n' }, rows ? COPY.count(shown.length) : ''));
229
+ let body;
230
+ if (!rows) body = el('p', { class: 'nt-hint' }, COPY.reading);
231
+ else if (!rows.length) body = empty({ text: inst.error || COPY.none });
232
+ else if (!shown.length) body = empty({ text: COPY.noMatch(inst.q.trim()) });
233
+ else {
234
+ body = el('div', { class: 'nt-pg-groups' }, groupNotes(shown).map((g) => el('div', { class: 'nt-pg-group', 'data-ntm-group': g.label },
235
+ el('h3', { class: 'nt-pg-group__h' }, el('span', null, g.label), el('span', { class: 'nt-pg-label__n' }, String(g.rows.length))),
236
+ g.rows.map((r) => row({ title: r.title || 'Untitled note', compact: true,
237
+ lead: [el('span', { class: 'nt-pg-row__at' }, whenShort(startOf(r)))],
238
+ trail: r.conflicts ? [el('span', { class: 'nt-pg-warn-dot', 'data-ntm-conflict-dot': '', title: r.conflicts + (r.conflicts === 1 ? ' conflict' : ' conflicts') })] : null,
239
+ onOpen: () => choose(inst, r.id), openLabel: 'Open ' + (r.title || 'Untitled note'),
240
+ openAttrs: { 'aria-current': r.id === inst.open ? 'true' : 'false' },
241
+ attrs: { class: 'nt-pg-row', 'data-ntm-row': r.id } })))));
242
+ }
243
+ inst.left.replaceChildren(head, body);
244
+ }
245
+
246
+ /* ── the right card: the note ────────────────────────────────────────────────────────────────────────────────────── */
247
+
248
+ function drawRight(inst, force) {
249
+ const n = inst.note;
250
+ const live = dock.recordState();
251
+ const sig = JSON.stringify([inst.open, n && [n.updated_at, n.title, n.final_notes && n.final_notes.at, (n.transcript || []).length, (n.highlights || []).length, n.agent && n.agent.markdown, iniName(n.initiative)], live.mode, live.id, !!inst.rows]);
252
+ if (!force && sig === inst.rightSig) return;
253
+ // a field being typed in is not redrawn under the cursor; the next read after it is left draws it
254
+ if (inst.right.contains(document.activeElement) && document.activeElement.matches('input, [contenteditable="true"]')) return;
255
+ inst.rightSig = sig;
256
+ if (!inst.open) { inst.right.replaceChildren(empty({ text: inst.rows && inst.rows.length ? COPY.pick : COPY.none })); return; }
257
+ if (!n) { inst.right.replaceChildren(el('p', { class: 'nt-hint' }, COPY.reading)); return; }
258
+ inst.right.replaceChildren(...noteParts(inst, n, live));
259
+ }
260
+
261
+ function noteParts(inst, n, live) {
262
+ const p = partsOf(n);
263
+ const meta = [COPY.meetingNote, whenLong(startOf(n)), minutes(lengthOf(n)), iniName(n.initiative)].filter(Boolean).join(' · ');
264
+ const title = field({ label: 'Title', kind: 'title', hideLabel: true, value: n.title || '', placeholder: 'Untitled note',
265
+ attrs: { 'data-ntm': 'title', class: 'nt-pg-title' },
266
+ onCommit: async (v) => { const r = await pmPost('/api/notes/save', { id: n.id, title: v }); if (r && r.ok) { n.title = v; refresh(inst); } else toast({ text: COPY.notSaved, tone: 'destructive' }); } });
267
+ const isLive = live.mode === 'recording' && live.id === n.id;
268
+ const acts = [];
269
+ if (!n.private) {
270
+ acts.push(isLive
271
+ ? button({ label: COPY.stop, variant: 'outline', size: 'sm', onClick: () => dock.finish(), attrs: { 'data-ntm': 'stop' } })
272
+ : button({ label: (n.transcript || []).length ? COPY.resume : COPY.record, variant: 'primary', size: 'sm', icon: 'mic',
273
+ onClick: () => dock.recordNote(n.id, n.title), attrs: { 'data-ntm': (n.transcript || []).length ? 'resume' : 'record' } }));
274
+ }
275
+ const more = iconButton({ icon: 'ellipsis', ariaLabel: 'More', attrs: { 'data-ntm': 'more' },
276
+ onClick: () => menu({ anchor: more, ariaLabel: 'Note actions', items: [
277
+ { label: COPY.openFull, onSelect: () => dock.openDock(n.id) },
278
+ { label: COPY.del, onSelect: () => deleteNote(inst, n) },
279
+ ] }) });
280
+ acts.push(more);
281
+ const out = [
282
+ el('div', { class: 'nt-pg-top' },
283
+ el('span', { class: 'nt-pg-meta', 'data-ntm': 'meta' }, meta),
284
+ el('div', { class: 'nt-pg-titlerow' }, el('div', { class: 'nt-pg-titlewrap' }, title), el('div', { class: 'nt-pg-acts' }, acts))),
285
+ ];
286
+ if (n.private) out.push(el('p', { class: 'nt-hint' }, 'This note is private: it is not recorded, and nothing from it goes to Jev or to any agent.'));
287
+
288
+ const cf = conflictsOf(n);
289
+ if (cf.length) {
290
+ out.push(el('section', { class: 'nt-pg-conflicts', 'data-ntm': 'conflicts' },
291
+ el('h3', { class: 'nt-pg-sec__h nt-pg-sec__h--warn' }, el('span', null, COPY.conflicts), el('span', { class: 'nt-pg-label__n' }, String(cf.length))),
292
+ cf.map((c) => el('div', { class: 'nt-pg-li', 'data-ntm-conflict': c.doc },
293
+ el('span', { class: 'nt-pg-warn-dot' }),
294
+ el('span', { class: 'nt-pg-li__text' }, '“' + c.text + '” ', el('span', { class: 'nt-pg-dim' }, COPY.conflictWith + ' '), el('span', { class: 'nt-pg-mono' }, c.doc + (c.line ? ':' + c.line : ''))),
295
+ button({ label: COPY.openFile, variant: 'outline', size: 'sm', onClick: () => openFile(inst, c.doc), attrs: { 'data-ntm-open-file': c.doc } })))));
296
+ }
297
+
298
+ const hl = n.highlights || [];
299
+ if (hl.length) {
300
+ out.push(el('section', { class: 'nt-pg-sec nt-pg-sec--first', 'data-ntm': 'highlights' },
301
+ el('h3', { class: 'nt-pg-sec__h' }, el('span', null, COPY.highlights), el('span', { class: 'nt-pg-label__n' }, String(hl.length))),
302
+ hl.map((h) => el('div', { class: 'nt-pg-li', 'data-ntm-highlight': h.id },
303
+ el('span', { class: 'nt-pg-li__at' }, typeof h.t === 'number' ? V.fmtTime(h.t) : ''),
304
+ el('span', { class: 'nt-pg-tag' }, h.label || 'Highlight'),
305
+ el('span', { class: 'nt-pg-li__text' }, h.text,
306
+ h.check && h.check.doc ? el('span', { class: 'nt-pg-sub' }, (h.check.verdict === 'differs' ? 'Differs from ' : h.check.verdict === 'agrees' ? 'Agrees with ' : 'Closest file: ') + h.check.doc + (h.check.line ? ':' + h.check.line : '')) : null)))));
307
+ }
308
+
309
+ out.push(el('section', { class: 'nt-pg-sec nt-pg-sec--overview', 'data-ntm': 'overview' },
310
+ el('h3', { class: 'nt-pg-sec__h nt-pg-sr' }, COPY.overview),
311
+ p.overview
312
+ ? editable(p.from === 'final' ? { tag: 'p', cls: 'nt-pg-para', text: p.overview, label: 'Overview', save: (t) => saveFinal(inst, n, 'overview', 0, t) } : { tag: 'p', cls: 'nt-pg-para', text: p.overview })
313
+ : el('p', { class: 'nt-hint' }, COPY.noOverview)));
314
+
315
+ const section = (key, label, items, mark, trail) => {
316
+ if (!items.length) return null;
317
+ return el('section', { class: 'nt-pg-sec', 'data-ntm-sec': key },
318
+ el('h3', { class: 'nt-pg-sec__h' }, el('span', null, label), el('span', { class: 'nt-pg-label__n' }, String(items.length))),
319
+ items.map((x) => el('div', { class: 'nt-pg-li', 'data-ntm-item': key },
320
+ el('span', { class: 'nt-pg-li__mk', 'aria-hidden': 'true' }, mark),
321
+ p.from === 'final' ? editable({ tag: 'span', cls: 'nt-pg-li__text', text: x.text, label: label, save: (t) => saveFinal(inst, n, x.sec, x.i, t) }) : el('span', { class: 'nt-pg-li__text' }, x.text),
322
+ x.orig_text !== undefined ? el('span', { class: 'nt-pg-dim', title: 'First written as: ' + x.orig_text }, COPY.edited) : null,
323
+ trail ? trail(x) : null)));
324
+ };
325
+ out.push(section('decision', COPY.decisions, p.decisions, '—'));
326
+ out.push(section('action', COPY.actions, p.actions, '○', (x) => [
327
+ x.owner || x.due ? el('span', { class: 'nt-pg-li__who' }, [x.owner, x.due].filter(Boolean).join(' · ')) : null,
328
+ button({ label: COPY.makeTask, variant: 'outline', size: 'sm', onClick: (e) => makeTaskFrom(n, x, { repo: inst.repo, btn: e && e.currentTarget }), attrs: { 'data-ntm-make-task': '' } }),
329
+ ]));
330
+ out.push(section('question', COPY.questions, p.questions, '?'));
331
+
332
+ const tr = (n.final && n.final.segments && n.final.segments.length ? n.final.segments.map((g) => ({ t: g.t, text: g.text })) : (n.transcript || []).filter((x) => !x.dropped));
333
+ if (p.topics.length || tr.length) {
334
+ const bits = [p.topics.length ? p.topics.length + (p.topics.length === 1 ? ' topic' : ' topics') : null, tr.length ? COPY.transcript(tr.length) : null].filter(Boolean).join(' · ');
335
+ out.push(el('details', { class: 'nt-pg-sec nt-pg-fold', 'data-ntm': 'discussion' },
336
+ el('summary', { class: 'nt-pg-fold__sum' }, COPY.discussion + ' · ' + bits),
337
+ p.topics.map((tp) => el('div', { class: 'nt-pg-topic' }, el('h4', { class: 'nt-pg-topic__h' }, tp.title), (tp.points || []).map((pt) => el('p', { class: 'nt-pg-topic__p' }, pt)))),
338
+ tr.length ? el('div', { class: 'nt-pg-trans' }, tr.map((x) => el('div', { class: 'nt-pg-li' }, el('span', { class: 'nt-pg-li__at' }, V.fmtTime(x.t || 0)), el('span', { class: 'nt-pg-li__text' }, x.text)))) : null));
339
+ }
340
+ return out.filter(Boolean);
341
+ }
342
+
343
+ /** A text the PM corrects in place: a click puts the cursor in it, leaving it saves, Esc puts the words back. */
344
+ function editable({ tag, cls, text, label, save }) {
345
+ if (!save) return el(tag, { class: cls }, text);
346
+ const node = el(tag, { class: cls + ' nt-pg-edit', contenteditable: 'true', spellcheck: 'true', role: 'textbox', 'aria-label': 'Edit ' + label, 'data-ntm-edit': '' }, text);
347
+ let last = text;
348
+ node.addEventListener('keydown', (e) => {
349
+ if (e.key === 'Enter' && tag !== 'p') { e.preventDefault(); node.blur(); }
350
+ if (e.key === 'Escape') { e.preventDefault(); node.textContent = last; node.blur(); }
351
+ });
352
+ node.addEventListener('blur', async () => {
353
+ const v = node.textContent.replace(/\s+/g, ' ').trim();
354
+ if (!v || v === last) { node.textContent = last; return; }
355
+ if (await save(v)) last = v; else node.textContent = last;
356
+ });
357
+ return node;
358
+ }
359
+ async function saveFinal(inst, n, sec, i, text) {
360
+ const r = await pmPost('/api/notes/final-edit', { id: n.id, sec, i, text });
361
+ if (!r || !r.ok) { toast({ text: COPY.notSaved + ((r && r.error) ? ': ' + r.error : ''), tone: 'destructive' }); return false; }
362
+ n.final_notes = r.final_notes;
363
+ toast({ text: COPY.saved, timeout: 1500 });
364
+ return true;
365
+ }
366
+
367
+ function openFile(inst, doc) {
368
+ if (!inst.repo) return;
369
+ import('./panel-tabs.js').then((m) => m.openDoc(inst.repo, doc, 'notes')).catch(() => toast({ text: 'The file could not be opened.', tone: 'destructive' }));
370
+ }
371
+
372
+ async function deleteNote(inst, n) {
373
+ const sure = await askConfirm({ title: COPY.delAsk(n.title || 'Untitled note'), body: COPY.delBody, confirmLabel: 'Delete', cancelLabel: 'Keep it' });
374
+ if (!sure) return;
375
+ const r = await pmPost('/api/notes/delete', { id: n.id });
376
+ if (!r || !r.ok) { toast({ text: (r && r.error) || 'The note was not deleted.', tone: 'destructive' }); return; }
377
+ dock.forget(n.id);
378
+ inst.open = null; inst.note = null;
379
+ refresh(inst);
380
+ }
381
+
382
+ /** Open the Notes place on one note. */
383
+ export function openNoteHere(id) { return openDestination('notes', { slug: id }); }
@@ -53,9 +53,8 @@ export function el(tag, attrs, ...children) {
53
53
  else if (k === 'ref') { if (typeof v === 'function') v(node); }
54
54
  else if (k === 'value' || k === 'checked' || k === 'disabled' || k === 'selected') node[k] = v;
55
55
  else if (k === 'html') node.innerHTML = String(v);
56
- else if (k.length > 2 && k[0] === 'o' && k[1] === 'n' && typeof v === 'function') {
57
- node.addEventListener(k.slice(2).toLowerCase(), v);
58
- } else if (v === true) node.setAttribute(k, '');
56
+ else if (k.length > 2 && k[0] === 'o' && k[1] === 'n' && typeof v === 'function') listen(node, k.slice(2).toLowerCase(), v);
57
+ else if (v === true) node.setAttribute(k, '');
59
58
  else node.setAttribute(k, String(v));
60
59
  }
61
60
  }
@@ -63,6 +62,14 @@ export function el(tag, attrs, ...children) {
63
62
  return node;
64
63
  }
65
64
 
65
+ /** An `onX` handler of el(). The listener reads the handler from the node, so patch() can give a node it keeps the handler of
66
+ * the node drawn in its place: a kept button then runs what the newest draw says, not what the first draw said. */
67
+ function listen(node, type, fn) {
68
+ const h = node.__pmOn || (node.__pmOn = Object.create(null));
69
+ if (!(type in h)) node.addEventListener(type, function (e) { const f = node.__pmOn[type]; return f ? f.call(this, e) : undefined; });
70
+ h[type] = fn;
71
+ }
72
+
66
73
  /** {backgroundColor:'red', minHeight:'30px'} -> 'background-color:red;min-height:30px'. */
67
74
  export function style(obj) {
68
75
  if (typeof obj === 'string') return obj;
@@ -174,3 +181,63 @@ export function keepScroll(scroller) {
174
181
  scroller.removeEventListener('scroll', onScroll);
175
182
  };
176
183
  }
184
+
185
+ /**
186
+ * Patch `live`'s children to look like `fresh`'s, keeping every node that is still there (note pop-up flicker, 2026-10-08).
187
+ * A view that draws itself again on every state change can draw into a detached `fresh` and patch the screen from it: what
188
+ * did not change stays the same element, so its scroll, focus, caret, open state and CSS animation stay; what changed is
189
+ * updated in place; what is new is inserted. Children are matched by tag and by their data-* attributes (so a list keyed
190
+ * by `data-x="3"` keeps its rows), else by position. A kept node takes the attributes, the el() handlers and the form
191
+ * values of the node drawn in its place. A `kept(node)` placeholder in `fresh` stands for a node the view owns and keeps
192
+ * itself (an editor field): that node is left where it is, or moved there, and never patched.
193
+ */
194
+ export function patchChildren(live, fresh) {
195
+ let cur = live.firstChild;
196
+ for (const n of [...fresh.childNodes]) {
197
+ if (n.__pmKeep) {
198
+ const t = n.__pmKeep;
199
+ if (cur === t) cur = cur.nextSibling;
200
+ else live.insertBefore(t, cur);
201
+ continue;
202
+ }
203
+ if (cur && sameNode(cur, n)) { patchNode(cur, n); cur = cur.nextSibling; continue; }
204
+ let found = null;
205
+ if (n.nodeType === 1 && keyOf(n)) for (let c = cur; c; c = c.nextSibling) if (sameNode(c, n)) { found = c; break; }
206
+ if (found) { live.insertBefore(found, cur); patchNode(found, n); continue; }
207
+ live.insertBefore(n, cur);
208
+ }
209
+ while (cur) { const x = cur.nextSibling; live.removeChild(cur); cur = x; }
210
+ return live;
211
+ }
212
+ /** A placeholder for patchChildren(): `node` is the view's own, and stays as it is. Off a page, the node itself. */
213
+ export function kept(node) {
214
+ if (!node || !node.isConnected) return node;
215
+ const p = document.createElement('pm-kept');
216
+ p.__pmKeep = node;
217
+ node.__pmOwned = true; // never matched to, and patched into, another node drawn beside it
218
+ return p;
219
+ }
220
+ function keyOf(n) {
221
+ let k = '';
222
+ for (const a of n.attributes) if (a.name.startsWith('data-')) k += a.name + '=' + a.value + ';';
223
+ return k;
224
+ }
225
+ function sameNode(a, b) {
226
+ if (a.nodeType !== b.nodeType) return false;
227
+ if (a.nodeType !== 1) return true;
228
+ return a.tagName === b.tagName && !a.__pmOwned && keyOf(a) === keyOf(b);
229
+ }
230
+ function patchNode(a, b) {
231
+ if (a.nodeType !== 1) { if (a.nodeValue !== b.nodeValue) a.nodeValue = b.nodeValue; return; }
232
+ for (const x of [...a.attributes]) if (!b.hasAttribute(x.name)) a.removeAttribute(x.name);
233
+ for (const x of b.attributes) if (a.getAttribute(x.name) !== x.value) a.setAttribute(x.name, x.value);
234
+ const ha = a.__pmOn; const hb = b.__pmOn;
235
+ if (ha) for (const t in ha) if (!hb || !hb[t]) ha[t] = null;
236
+ if (hb) for (const t in hb) listen(a, t, hb[t]);
237
+ const tag = a.tagName;
238
+ if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') {
239
+ if (a.value !== b.value && a !== document.activeElement) a.value = b.value;
240
+ if (a.checked !== b.checked) a.checked = b.checked;
241
+ }
242
+ patchChildren(a, b);
243
+ }
@@ -36,6 +36,7 @@ export const COPY = {
36
36
  board: 'Board',
37
37
  reports: 'Reports',
38
38
  docs: 'Docs',
39
+ notes: 'Notes',
39
40
  people: 'People',
40
41
  agent: 'Agent',
41
42
  settings: 'Settings',
@@ -1,19 +1,21 @@
1
- /* pm/note-dock.js — the meeting note being taken, kept small at the bottom right of the workspace (meeting-notes Run 6).
1
+ /* pm/note-dock.js — the meeting note being taken: the Record control's brain and the pop-up (meeting-notes Run 6, Run 12).
2
2
  *
3
- * Take notes on a calendar event makes the note and starts listening at once. The note stays minimized as a pill at the
4
- * bottom right: a red dot while it listens, its title and its time. A press on the pill opens the note as a pop-up: the same
5
- * note as the Notes tab, in one column (pm/view-notes.js renderInline). Minimize or Esc puts it back; Open in Notes shows it
6
- * on the full screen. The pill stays on every destination.
3
+ * The Record control lives in the top bar (pm/topbar.js, mockup board 2): Record when idle, the red dot with the clock, the
4
+ * highlighter and Pause while listening, Resume when paused. Take notes on a calendar event makes the note and starts
5
+ * listening at once. A press on the clock opens the note as a pop-up: the same note as the Notes tab, in one column
6
+ * (pm/view-notes.js renderInline). Minimize or Esc puts it away; the highlight pop-up sits bottom right on every place.
7
7
  *
8
- * One note at a time. The note is kept in this browser (KEY), so it is still there after a reload; a note that no longer
9
- * listens can be put away with the x. Starting another note while one is listening asks first.
8
+ * One note at a time. The note is kept in this browser (KEY), so it is still there after a reload. Starting another note
9
+ * while one is listening asks first.
10
10
  *
11
11
  * mountDock() → draws the dock on every render (pm/app.js boot)
12
- * takeNotes(e, opts, btn) → makes a note linked to the event, starts listening, and keeps it minimized
12
+ * recordState() → { mode: idle | recording | paused, id, title, started } for the top bar
13
+ * recordNew(btn) · recordNote(id, title) · pauseNow() · resumeNow() · finish() · highlightNow()
14
+ * takeNotes(e, opts, btn) → makes a note linked to the event, starts listening
13
15
  * openDock(id) → shows a note in the pop-up
14
16
  * minimize() · activeId() · forget(id)
15
17
  */
16
- import { el } from './dom.js';
18
+ import { el, patchChildren } from './dom.js';
17
19
  import { button, iconButton, layer, toast, ensureComponentsCss } from './primitives.js';
18
20
  import { askConfirm } from './dialogs.js';
19
21
  import { pmPost } from './http.js';
@@ -96,6 +98,57 @@ async function switchFrom() {
96
98
  return true;
97
99
  }
98
100
 
101
+ /* ── the Record control at the right of the top bar (meeting-notes Run 12, mockup board 2) ────────────────────────────
102
+ * It replaces the pill: idle it says Record; while the note listens it shows the red dot and the clock (a press opens the
103
+ * note), the highlight and Pause; paused it shows the clock and Resume. Stop, in the note, ends it and the control is idle
104
+ * again. The note it holds is the dock's one note (active). */
105
+
106
+ /** { mode: 'idle'|'recording'|'paused', id, title, started } — what the Record control shows. */
107
+ export function recordState() {
108
+ if (!active) return { mode: 'idle', id: null, title: '', started: null };
109
+ const live = !!V && liveId() === active.id;
110
+ return { mode: live ? 'recording' : 'paused', id: active.id, title: titleOf(), started: live && V.liveStarted ? V.liveStarted() : null };
111
+ }
112
+ /** Record: a new note, linked to nothing, that listens at once. */
113
+ export async function recordNew(btn) {
114
+ if (active && liveId() === active.id) { openDock(active.id); return; }
115
+ if (btn) btn.disabled = true;
116
+ const r = await pmPost('/api/notes/new', {});
117
+ if (btn) btn.disabled = false;
118
+ if (!r || !r.ok) { toast({ text: (r && r.error) || 'The note was not made.', tone: 'destructive' }); return; }
119
+ await recordNote(r.note.id, r.note.title || '');
120
+ refreshNotes();
121
+ }
122
+ /** Record or Resume on one note: it becomes the dock's note and listens. Another note that is listening is asked about first. */
123
+ export async function recordNote(id, title) {
124
+ if (active && active.id !== id && liveId() === active.id && !await switchFrom()) return;
125
+ active = { id, title: title || '' }; write();
126
+ const v = V || await import('./view-notes.js');
127
+ V = v;
128
+ setState({});
129
+ if (await v.listenNow(viewCtx, id)) toast({ text: 'Notes are being taken. Let people know.' });
130
+ setState({});
131
+ }
132
+ /** Pause: listening stops and the note stays here, ready to Resume. */
133
+ export async function pauseNow() {
134
+ if (V && active && liveId() === active.id) await V.stopListening(viewCtx);
135
+ setState({});
136
+ }
137
+ /** Resume the paused note. */
138
+ export function resumeNow() { if (active) return recordNote(active.id, active.title); return null; }
139
+ /** Stop: listening stops and the note leaves the Record control (the final notes are written after Stop). */
140
+ export async function finish() {
141
+ if (V && active && liveId() === active.id) await V.stopListening(viewCtx);
142
+ active = null; open = false; write();
143
+ if (V) V.setPopped(null);
144
+ setState({});
145
+ }
146
+ /** Highlight: the last 30 seconds and what is said next, on the note that is listening. */
147
+ export function highlightNow() {
148
+ if (!V || !active || liveId() !== active.id) return;
149
+ V.highlightNow(viewCtx, active.id);
150
+ }
151
+
99
152
  /** Take notes on a calendar event: make the note, start listening at once, and keep it minimized. */
100
153
  export async function takeNotes(e, { ws, repo, initiative } = {}, btn) {
101
154
  if (active && liveId() === active.id && !await switchFrom()) { openDock(active.id); return; }
@@ -122,23 +175,26 @@ function draw() {
122
175
  const v = view();
123
176
  const live = !!active && !!v && liveId() === active.id;
124
177
  clearInterval(tick); tick = null;
125
- if (!active || !v) { host.replaceChildren(); return; }
178
+ // The dock draws on every state change, and a transcript line comes in every few seconds while it listens. It draws into
179
+ // a detached node and patches the screen from it, so only what changed is touched: the lines already shown, the field
180
+ // being typed in, the scroll stay as they are, and a new line is appended (2026-10-08 flicker).
181
+ const fresh = el('div');
182
+ // the highlight's pop-up is drawn here, on every place, whether the note is open or not
183
+ const hl = v && v.highlightPanel ? v.highlightPanel(viewCtx) : null;
184
+ if (!active || !v) { if (hl) fresh.appendChild(hl); patchChildren(host, fresh); return; }
126
185
  if (live) tick = setInterval(() => { const c = host.querySelector('[data-nt-dock-clock]'); if (c) c.textContent = clockText(); }, 1000);
127
- if (!open) {
128
- const pill = button({ label: el('span', { class: 'nt-pill__txt' },
129
- live ? el('span', { class: 'nt-live-dot', 'aria-hidden': 'true' }) : null,
130
- el('span', { class: 'nt-pill__title' }, titleOf()),
131
- live ? el('span', { class: 'nt-pill__clock', 'data-nt-dock-clock': '' }, clockText()) : null),
132
- variant: 'outline', attrs: { class: 'nt-pill', 'data-nt-pill': live ? 'live' : 'idle', 'aria-label': (live ? 'Notes are being taken: ' : 'Meeting note: ') + titleOf() + '. Open the note.' },
133
- onClick: () => openDock(active.id) });
134
- host.replaceChildren(el('div', { class: 'nt-pillrow' }, pill,
135
- live ? null : iconButton({ icon: 'x', ariaLabel: 'Put the note away', onClick: close, attrs: { 'data-nt-dock-close': '' } })));
136
- return;
137
- }
186
+ // the Record control at the top right shows the note now (Run 12): no pill
187
+ if (!open) { if (hl) fresh.appendChild(hl); patchChildren(host, fresh); return; }
138
188
  // the note draws its own bar (status, Stop, Minimize and the ⋯ menu): the pop-up adds no second head (Run 7)
139
189
  const body = el('div', { class: 'nt-pop__body' });
140
190
  const pop = el('section', { class: 'nt-pop', role: 'dialog', 'aria-label': 'Meeting note', 'data-nt-pop': active.id }, body);
141
- host.replaceChildren(pop);
191
+ fresh.appendChild(pop);
192
+ if (hl) fresh.appendChild(hl);
142
193
  if (!v.renderInline(body, viewCtx, active.id, { onMinimize: minimize })) body.appendChild(el('p', { class: 'nt-hint' }, 'Another note is being taken.'),
143
194
  button({ label: 'Minimize', variant: 'ghost', size: 'sm', onClick: minimize, attrs: { 'data-nt-minimize': '' } }));
195
+ // a transcript read to its end follows the new lines; one the PM scrolled up in stays where they left it
196
+ const box = host.querySelector('[data-nt-pop] [data-nt-transcript]');
197
+ const atEnd = !!box && box.scrollTop + box.clientHeight >= box.scrollHeight - 8;
198
+ patchChildren(host, fresh);
199
+ if (atEnd && box.isConnected) box.scrollTop = box.scrollHeight;
144
200
  }
@@ -58,10 +58,10 @@ export function meetingOf(e) {
58
58
  start: e.start, end: e.end || null, title: e.title };
59
59
  }
60
60
 
61
+ /** Open a note in the Notes place (meeting-notes Run 12): the list by initiative, with this note open. */
61
62
  export async function openNote(id) {
62
- const [v, c] = await Promise.all([import('./view-notes.js'), import('./panel-cockpit.js')]);
63
- v.openNote(id);
64
- c.openView('notes');
63
+ const r = await import('./registry.js');
64
+ r.openDestination('notes', { slug: id });
65
65
  }
66
66
  const dayOf = (iso) => { try { return new Date(iso).toLocaleDateString([], { weekday: 'short', day: 'numeric', month: 'short' }); } catch { return ''; } };
67
67
  const clock = (iso) => { try { return new Date(iso).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } catch { return ''; } };