create-pmos 0.410.0 → 0.412.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 (131) hide show
  1. package/package.json +25 -30
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-adddoc-test.js +2 -2
  7. package/workspace/briefing-premium-initiative-test.js +9 -15
  8. package/workspace/briefing-premium-insights-test.js +2 -2
  9. package/workspace/briefing-premium-test.js +3 -3
  10. package/workspace/changelog.json +24 -0
  11. package/workspace/chat-asks-test.js +146 -0
  12. package/workspace/guide/board.md +1 -1
  13. package/workspace/guide/breakdown.md +6 -13
  14. package/workspace/guide/briefing-premium.md +1 -1
  15. package/workspace/guide/home.md +24 -0
  16. package/workspace/guide/index.md +1 -1
  17. package/workspace/guide/initiative-driver.md +1 -1
  18. package/workspace/guide/initiatives-screen.md +1 -1
  19. package/workspace/guide/pm-only-acts.md +23 -24
  20. package/workspace/guide/today.md +1 -1
  21. package/workspace/home-rows-test.js +149 -56
  22. package/workspace/ini-workflow-test.js +4 -4
  23. package/workspace/lib/briefing-premium-agent.js +8 -1
  24. package/workspace/lib/briefing-premium-writes.js +5 -4
  25. package/workspace/lib/coredoc-cli.js +1 -1
  26. package/workspace/lib/driver-cli.js +2 -1
  27. package/workspace/lib/driver-decide.js +3 -2
  28. package/workspace/lib/driver.js +2 -1
  29. package/workspace/lib/engine/boards.js +3 -1
  30. package/workspace/lib/goal-chat.js +94 -30
  31. package/workspace/lib/grant-mint.js +3 -2
  32. package/workspace/lib/initiative-cli.js +9 -9
  33. package/workspace/lib/issues.js +5 -4
  34. package/workspace/lib/mention-cli.js +70 -0
  35. package/workspace/lib/mention-store.js +307 -0
  36. package/workspace/lib/people-store.js +1 -1
  37. package/workspace/lib/people.js +3 -1
  38. package/workspace/lib/placements.js +13 -15
  39. package/workspace/lib/plan-items.js +17 -48
  40. package/workspace/lib/pm-guard.js +18 -5
  41. package/workspace/lib/pm-lines-needs.js +9 -5
  42. package/workspace/lib/pmos-verbs.js +3 -0
  43. package/workspace/lib/report-cli.js +2 -2
  44. package/workspace/lib/routes-board-metric-targets.js +0 -1
  45. package/workspace/lib/routes-boards.js +12 -0
  46. package/workspace/lib/routes-briefing-premium.js +5 -7
  47. package/workspace/lib/routes-core-docs.js +0 -1
  48. package/workspace/lib/routes-custom-docs.js +0 -1
  49. package/workspace/lib/routes-driver.js +0 -1
  50. package/workspace/lib/routes-home-desk.js +1 -1
  51. package/workspace/lib/routes-home-review.js +1 -1
  52. package/workspace/lib/routes-initiative-layout.js +1 -1
  53. package/workspace/lib/routes-insights-records.js +0 -1
  54. package/workspace/lib/routes-meeting-material.js +0 -1
  55. package/workspace/lib/routes-mentions.js +62 -9
  56. package/workspace/lib/routes-onboarding.js +3 -1
  57. package/workspace/lib/routes-orchestrator.js +0 -1
  58. package/workspace/lib/routes-premium-charts.js +0 -1
  59. package/workspace/lib/routes-premium-dashboards.js +0 -1
  60. package/workspace/lib/routes-programs.js +1 -1
  61. package/workspace/lib/routes-records.js +1 -1
  62. package/workspace/lib/routes-report-design.js +7 -3
  63. package/workspace/lib/routes-report-setups.js +0 -1
  64. package/workspace/lib/routes-report-structure.js +0 -1
  65. package/workspace/lib/routes-runs.js +2 -5
  66. package/workspace/lib/routes-scan.js +0 -1
  67. package/workspace/lib/routes-sources.js +1 -1
  68. package/workspace/lib/run-answers.js +14 -5
  69. package/workspace/lib/scan-cli.js +2 -1
  70. package/workspace/lib/scan.js +2 -1
  71. package/workspace/lib/session-files.js +132 -0
  72. package/workspace/lib/session-name.js +103 -0
  73. package/workspace/lib/source-reads.js +4 -1
  74. package/workspace/lib/vendor/scripts/onboarding/proposals.js +7 -3
  75. package/workspace/package-lock.json +2 -2
  76. package/workspace/package.json +1 -1
  77. package/workspace/premium-board-actions-test.js +10 -8
  78. package/workspace/premium-chat-goal-setup-test.js +203 -0
  79. package/workspace/premium-chat-goal-view-test.js +28 -23
  80. package/workspace/premium-chat-line-test.js +189 -0
  81. package/workspace/premium-core-doc-issue-test.js +1 -1
  82. package/workspace/premium-viewer-share-test.js +5 -2
  83. package/workspace/premium-vw-backlog-test.js +1 -1
  84. package/workspace/premium-vw-item-test.js +1 -1
  85. package/workspace/premium-vw-jira-test.js +1 -1
  86. package/workspace/public/pm/chat-ask.js +17 -9
  87. package/workspace/public/pm/cozy-home-rows.css +39 -1
  88. package/workspace/public/pm/cozy-home.css +112 -12
  89. package/workspace/public/pm/cozy-search.js +2 -1
  90. package/workspace/public/pm/cozy-steps.css +69 -0
  91. package/workspace/public/pm/cozy-steps.js +90 -0
  92. package/workspace/public/pm/goal-chat.js +141 -23
  93. package/workspace/public/pm/home-app.js +68 -35
  94. package/workspace/public/pm/home-ask.js +121 -0
  95. package/workspace/public/pm/home-chat.js +120 -68
  96. package/workspace/public/pm/home-data.js +10 -2
  97. package/workspace/public/pm/home-goal.js +159 -0
  98. package/workspace/public/pm/home-ini.css +35 -0
  99. package/workspace/public/pm/home-ini.js +50 -19
  100. package/workspace/public/pm/home-line.css +59 -0
  101. package/workspace/public/pm/home-line.js +200 -0
  102. package/workspace/public/pm/home-list.js +2 -2
  103. package/workspace/public/pm/home-mentions.js +303 -111
  104. package/workspace/public/pm/home-ses-name.js +65 -0
  105. package/workspace/public/pm/home-stage-card.js +94 -0
  106. package/workspace/public/pm/home-sweep.js +112 -0
  107. package/workspace/public/pm/home-today.js +7 -2
  108. package/workspace/public/pm/premium-initiative-head.js +8 -4
  109. package/workspace/public/pm/rename-press.js +24 -0
  110. package/workspace/public/pm/wf-page.css +3 -0
  111. package/workspace/public/pm/wf-page.js +2 -1
  112. package/workspace/public/premium-workflows.html +1 -0
  113. package/workspace/replaced-tests.json +101 -0
  114. package/workspace/server.js +133 -20
  115. package/workspace/session-names-test.js +144 -0
  116. package/workspace/skills/jira-push.skill +1 -0
  117. package/workspace/skills/morning-brief.skill +2 -1
  118. package/workspace/skills/report-daily.skill +1 -0
  119. package/workspace/skills/report-monthly.skill +1 -0
  120. package/workspace/skills/report-weekly.skill +1 -0
  121. package/workspace/skills/sources-read.skill +3 -2
  122. package/workspace/stage-card-test.js +203 -0
  123. package/workspace/test-lists/chat-asks.json +13 -0
  124. package/workspace/test-lists/chat-progress.json +13 -0
  125. package/workspace/test-lists/mentions-a-plus.json +9 -0
  126. package/workspace/test-lists/premium-chat-goal-setup.json +9 -0
  127. package/workspace/test-lists/session-files.json +5 -0
  128. package/workspace/test-lists/session-names.json +13 -0
  129. package/workspace/test-lists/stage-card.json +6 -0
  130. package/workspace/tk-tasks-test.js +1 -1
  131. package/workspace/workflows-setup-test.js +17 -0
@@ -15,7 +15,7 @@
15
15
  * fileUnder(text, inis) the initiative a typed task names (its title or id in the text), or null: the task then goes on the PM's own list
16
16
  * D is home-data.js's D plus { work (GET /api/my-work-premium model), items (GET /api/boards/items), others ([{ ws, name, model }], the boards of
17
17
  * the other products), phoneDay (GET /api/phone-day), review (GET /api/home-review) }. A part that did not answer is left out, never guessed. */
18
- import { needsOf, boardRows, productCard, productName, sessionRow, iniOfSession, todayOf, live, OPEN, hm } from './home-data.js';
18
+ import { needsOf, boardRows, productCard, productName, sessionRow, nameOf, iniOfSession, todayOf, live, OPEN, hm } from './home-data.js';
19
19
  import { programState, groupRows } from './program-model.js';
20
20
  import { STEPS, stageKey } from './premium-initiative-head.js';
21
21
 
@@ -310,7 +310,7 @@ export function todayCard(D, o = {}) {
310
310
  // Done is counts, never a meeting's decision text: a decision is not a thing done, and only the ones the PM confirmed count (testing fixes)
311
311
  const doneLine = rec ? [rec.done ? plural(rec.done, 'task', 'tasks') + ' done' : '', rec.decided ? plural(rec.decided, 'decision', 'decisions') + ' confirmed' : '', rec.finished ? plural(rec.finished, 'draft', 'drafts') + ' finished' : '', rec.to_confirm ? rec.to_confirm + ' from notes to confirm' : ''].filter(Boolean).join(' · ') : '';
312
312
  const runs = (D.sessions || []).filter((s) => s.shown === 'working');
313
- const over = runs.length ? (runs.length === 1 ? ((runs[0].hx && runs[0].hx.title) || runs[0].name) + ' runs.' : runs.length + ' sessions run.') + ' Results are in New for you by morning.' : '';
313
+ const over = runs.length ? (runs.length === 1 ? nameOf(runs[0]) + ' runs.' : runs.length + ' sessions run.') + ' Results are in New for you by morning.' : '';
314
314
  const tm = P && P.tomorrow ? P.tomorrow : null;
315
315
  const first = tm && (tm.meetings || []).length ? tm.meetings.slice().sort((a, b) => Date.parse(a.start) - Date.parse(b.start))[0] : null;
316
316
  const tomorrow = tm ? (first ? 'First meeting ' + hm(first.start) : 'No meeting') + (needs.length ? ' · ' + needs.length + ' on your list' : '') : '';
@@ -1,24 +1,33 @@
1
- /* pm/home-mentions.js — @Mentions on Home: a permanent row at the top of the list and the Mentions Viewer (Viewer kit; canvas XvANew,
2
- * XvAMention, XvAMentionJira, XvAMentionDoc, XvAMentionMail).
1
+ /* pm/home-mentions.js — @Mentions on Home: a permanent row at the top of the list and the Mentions Viewer (agreed A+; canvas
2
+ * XmsMentionsGrill on the phone, XmsDeskList, XmsDeskOne and XmsDeskRefine on the desktop).
3
3
  *
4
- * rowHtml(D, { sel }) → the row's markup: "@ Mentions" and "N new" while some are unread. With none new the row stays, with no count
5
- * (zero is silence). The press is data-hr-mentions; home-app.js opens the Viewer.
6
- * openMentions(ctx) → the Mentions Viewer: the summary card (how many are new, who asked what, ONE primary: Reply to <first>), then
7
- * "New" (open) and "Earlier" (folded, the ones already read). A mention opens with back: true, so ← returns here.
8
- * openOne(m, ctx, { back }) → one mention: how long it waits on the PM, what it is about, where it is, ONE primary (Draft a reply), the
9
- * source excerpt with the mention outlined, What I checked (only the brief's own checks), Open in <source> and its
10
- * initiative with its stage. ⋯ holds Make it a task and Mark read (or Mark unread).
11
- * ctx: { D() → Home's data, pmPost, toast, reload(), iniTitle(id), stageOf(id), goIni(id), draft(m) }
4
+ * rowHtml(D, { sel }) → the row's markup: "@ Mentions" and a badge with how many asks wait on the PM (reading does not clear it,
5
+ * answering does). A new ask since the PM last opened Mentions adds one line under the name ("Maya asks about
6
+ * SSO scope"). With nothing waiting the row stays, with no badge (zero is silence). The press is data-hr-mentions.
7
+ * openMentions(ctx) → the Mentions Viewer: the summary card (how many wait, the oldest, who asks what; one round Reply press that opens
8
+ * the oldest), "Waiting on you" (every unanswered ask, any age, oldest first, the age the only signal, 5 then
9
+ * Show all) and "Last 7 days" (what does not wait, by real day: Today, Yesterday with its date, then dated days).
10
+ * What PMOS could not read is said once at the end, with its next action. A failed read keeps the last list.
11
+ * openOne(m, ctx, o) → one mention: what is asked and by when, its place, four one-tap icons with Undo (Mark answered, Remind me
12
+ * tomorrow, Make it a task, Not an ask), What I found, the Proposed reply (pencil: change it with Claude in the
13
+ * chat; send: copy it and open the source), and the source messages folded at the bottom.
14
+ * load(ctx) → GET /api/mentions into ctx.D().mentions, keeping the last good list when the read fails
15
+ * ctx: { D() → Home's data, pmGet, pmPost, toast, toastUndo(msg, undo), reload(), iniTitle(id), stageOf(id), onBoard(id), board() → { ws, board },
16
+ * goIni(id), draft(m) }
12
17
  *
13
- * The mentions are today's (GET /api/brief-page mentions, Home's D.today). New = not marked read. Mark read is POST /api/mentions/read;
14
- * Make it a task is POST /api/pm-items/add. Nothing here replies or posts: Draft a reply opens Home's chat to write it, and the PM sends
15
- * it where the mention is. A mention shows only here: it is no longer a row under its initiative (say it once). */
18
+ * The data is GET /api/mentions (lib/mention-store.js): its own store, so the brief's 30-item cap cannot crowd a mention out. Every press is
19
+ * POST /api/mentions/act (one mark, undone by act: undo). Nothing here replies or posts: send copies the reply and opens the source, and
20
+ * the PM sends it there. A mention shows only here: it is no longer a row under its initiative (say it once). */
16
21
  import * as VW from './cozy-viewer.js';
17
22
 
18
23
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
19
24
  const SRC = { slack: 'Slack', jira: 'Jira', confluence: 'Confluence', mail: 'Mail', gmail: 'Gmail', figma: 'Figma', doc: 'the document' };
20
25
  const ICON = { jira: 'jira', confluence: 'doc', doc: 'doc', mail: 'M3.5 5.5h17v13h-17zM3.5 6l8.5 7 8.5-7', gmail: 'M3.5 5.5h17v13h-17zM3.5 6l8.5 7 8.5-7' };
21
- const TICK = 'M5 12.5l4.5 4.5L19 7.5';
26
+ const P = {
27
+ tick: 'M5 12.5l4.5 4.5L19 7.5', clock: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 7.5V12l3 2', task: 'M4 4h11v11H4zM7 9.5l2 2 3-3.5M18 13v8M14 17h8',
28
+ x: 'M6 6l12 12M18 6L6 18', reply: 'M9 14L4 9l5-5M4 9h10a6 6 0 0 1 6 6v3', pen: 'M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4', send: 'M21 3L10 14M21 3l-7 18-4-7-7-4z',
29
+ plug: 'M9 3v5M15 3v5M6 8h12v3a6 6 0 0 1-12 0zM12 17v4', again: 'M20 11a8 8 0 1 0-2.3 5.7M20 5v6h-6', chev: 'M10 7l5 5-5 5',
30
+ };
22
31
  const svg = (d, w = 16, sw = 2) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
23
32
  const srcName = (s) => SRC[s] || (s ? String(s).charAt(0).toUpperCase() + String(s).slice(1) : 'its source');
24
33
  const first = (who) => String(who || 'someone').trim().split(/\s+/)[0];
@@ -26,20 +35,62 @@ const clip = (s, n) => { s = String(s || '').replace(/\s+/g, ' ').trim(); return
26
35
  const https = (u) => (/^https:\/\/\S+$/i.test(String(u || '')) ? u : '');
27
36
  const isMail = (s) => s === 'mail' || s === 'gmail';
28
37
  const isDoc = (s) => s === 'confluence' || s === 'doc';
38
+ const T = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : 0; };
39
+ const DAY = 86400000;
40
+ const store = {
41
+ get(k) { try { return localStorage.getItem(k); } catch { return null; } },
42
+ set(k, v) { try { localStorage.setItem(k, String(v)); } catch { /* a private window */ } },
43
+ };
44
+ const SEEN = 'cz-men-seen'; // when the PM last opened Mentions: a newer ask adds its line under the row's name
45
+ const CACHE = 'cz-men-last'; // the last list that loaded, with its time, for a read that fails (E4)
29
46
 
30
47
  /* ── the data ── */
31
- /** Today's mentions: { all, fresh (not read yet), earlier (read) }, newest first as the server sends them. */
48
+ /** Load GET /api/mentions into D.mentions. A failed read keeps the last good list and says when it is from. */
49
+ export async function load(ctx) {
50
+ const D = ctx.D();
51
+ const r = await ctx.pmGet('/api/mentions').catch(() => null);
52
+ if (r && r.ok) {
53
+ D.mentions = { ...r, at: Date.now() };
54
+ store.set(CACHE, JSON.stringify(D.mentions));
55
+ closeTasks(ctx, r);
56
+ return D.mentions;
57
+ }
58
+ let last = D.mentions && !D.mentions.failed ? D.mentions : null;
59
+ if (!last) { try { last = JSON.parse(store.get(CACHE) || 'null'); } catch { last = null; } }
60
+ D.mentions = { ...(last || { waiting: [], recent: [], gaps: [], count: 0 }), failed: true, from: last ? last.at : 0 };
61
+ return D.mentions;
62
+ }
63
+ /** { waiting, recent, gaps, failed, from } of Home's data; empty lists before the first read. */
32
64
  export function mentionsOf(D) {
33
- const all = (D && D.today && Array.isArray(D.today.mentions) ? D.today.mentions : []).filter((m) => m && m.id && !m.done);
34
- return { all, fresh: all.filter((m) => !m.read), earlier: all.filter((m) => m.read) };
65
+ const m = (D && D.mentions) || null;
66
+ return { waiting: (m && m.waiting) || [], recent: (m && m.recent) || [], gaps: (m && m.gaps) || [], failed: !!(m && m.failed), from: (m && m.from) || 0, loaded: !!m };
67
+ }
68
+ /** A task made from a mention closes itself when the PM replies in the source (XmsMentionsGrill scenario 15). */
69
+ async function closeTasks(ctx, r) {
70
+ for (const m of r.recent || []) {
71
+ if (m.status !== 'replied' || !m.task || m.task_closed) continue;
72
+ const t = m.task;
73
+ const res = t.kind === 'board' ? await ctx.pmPost('/api/boards/tasks/state', { ws: t.ws, board: t.board, task: t.id, state: 'Done' }) : await ctx.pmPost('/api/pm-items/done', { id: t.id, how: 'confirmed' });
74
+ if (res && res.ok) await ctx.pmPost('/api/mentions/act', { id: m.id, act: 'closed' });
75
+ }
35
76
  }
36
77
  /** "40 min", "2 h", "1 day", "3 days"; '' with no time. */
37
78
  export function age(at, now = Date.now()) {
38
- const t = Date.parse(at || ''); if (!Number.isFinite(t)) return '';
79
+ const t = T(at); if (!t) return '';
39
80
  const m = Math.max(0, Math.round((now - t) / 60000));
40
81
  if (m < 60) return Math.max(1, m) + ' min';
41
82
  const h = Math.round(m / 60); if (h < 24) return h + ' h';
42
- const d = Math.round(h / 24); return d === 1 ? '1 day' : d + ' days';
83
+ const d = Math.floor(h / 24); return d === 1 ? '1 day' : d + ' days';
84
+ }
85
+ const late = (at, now = Date.now()) => now - T(at) >= 2 * DAY;
86
+ const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
87
+ const MO = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
88
+ const day0 = (t) => { const d = new Date(t); d.setHours(0, 0, 0, 0); return d.getTime(); };
89
+ /** The PM's local day of a time: "Today", "Yesterday, Sat 24 Oct", "Thu 23 Oct". */
90
+ export function dayLabel(at, now = Date.now()) {
91
+ const t = T(at), d = new Date(t), n = Math.round((day0(now) - day0(t)) / DAY);
92
+ const dated = WD[d.getDay()] + ' ' + d.getDate() + ' ' + MO[d.getMonth()];
93
+ return n <= 0 ? 'Today' : n === 1 ? 'Yesterday, ' + dated : dated;
43
94
  }
44
95
  /** Where the mention is, the way the frames say it: "Slack #product", "SLV-144 comment", "comment on PRD v3", "email". */
45
96
  export function placeOf(m) {
@@ -51,130 +102,271 @@ export function placeOf(m) {
51
102
  return [srcName(m.source), w].filter(Boolean).join(' ');
52
103
  }
53
104
  const whoOf = (m) => m.who || srcName(m.source);
54
- const askWord = (m) => (m.reply ? 'asks' : 'wrote');
105
+ const askOf = (m) => (m.ask ? first(whoOf(m)) + ' asks ' + m.ask.replace(/^[A-Z](?=[a-z])/, (c) => c.toLowerCase()).replace(/[.?!]+$/, '') : first(whoOf(m)) + ' asks “' + clip(m.text, 70).replace(/[.?!]+$/, '') + '”');
55
106
 
56
- /* ── the row on Home (XvANew .row) ── */
107
+ /* ── the row on Home (XmsMentionsGrill 4) ── */
57
108
  export function rowHtml(D, o = {}) {
58
- const n = mentionsOf(D).fresh.length;
109
+ const { waiting } = mentionsOf(D);
110
+ const n = waiting.length;
59
111
  const sel = o.sel === 'mentions';
112
+ const seen = +(store.get(SEEN) || 0);
113
+ const nu = seen ? waiting.filter((m) => T(m.since) > seen || (m.count > 1 && T(m.last) > seen)).sort((a, b) => T(b.last) - T(a.last))[0] : null;
114
+ const sub = nu ? clip(first(whoOf(nu)) + ' asks ' + (nu.ask ? nu.ask.replace(/[.?!]+$/, '') : 'you something'), 60) : '';
60
115
  return `<div class="hv-card hr-card hr-men-card"><div class="hm-r hv-r hr-men${sel ? ' sel' : ''}${n ? ' new' : ''}" data-id="mentions">`
61
- + `<button type="button" class="hm-rm" data-hr-mentions${sel ? ' aria-current="true"' : ''} aria-label="Mentions${n ? ', ' + n + ' new' : ''}">`
62
- + '<span class="hv-mk hr-at" aria-hidden="true">@</span><span class="hm-rt"><b>Mentions</b></span>'
63
- + (n ? `<span class="hv-st hr-new">${n} new</span>` : '') + '<span class="hv-xc" aria-hidden="true"></span></button></div></div>';
116
+ + `<button type="button" class="hm-rm" data-hr-mentions${sel ? ' aria-current="true"' : ''} aria-label="Mentions${n ? ', ' + n + (n === 1 ? ' waits' : ' wait') + ' on your reply' : ''}">`
117
+ + `<span class="hv-mk hr-at" aria-hidden="true">@</span><span class="hm-rt"><b>Mentions</b>${sub ? `<small class="hr-sub">${esc(sub)}</small>` : ''}</span>`
118
+ + (n ? `<span class="hr-bd" aria-hidden="true">${n}</span>` : '') + '<span class="hv-xc" aria-hidden="true"></span></button></div></div>';
64
119
  }
65
120
 
66
- /* ── the Mentions Viewer (XvANew .vw) ── */
67
- function itemHtml(m, now) {
68
- const head = [whoOf(m), placeOf(m), m.at ? age(m.at, now) + ' ago' : ''].filter(Boolean).join(' · ');
69
- const sub = [m.text ? '“' + clip(m.text, 120) + '”' : '', m.checks && m.checks[0] ? 'I checked: ' + clip(m.checks[0], 80) : ''].filter(Boolean).join(' · ');
70
- return `<button type="button" class="hr-mi" data-hr-mi="${esc(m.id)}" aria-label="${esc(whoOf(m) + ', ' + placeOf(m) + '. Open')}">`
71
- + `<span class="hr-mdot${m.read ? ' read' : ''}" aria-hidden="true"></span><span class="hr-mw"><b>${esc(head)}</b>${sub ? `<span>${esc(sub)}</span>` : ''}</span>`
72
- + `<span class="hr-mcv">${svg('M10 7l5 5-5 5', 15)}</span></button>`;
73
- }
74
- function listHtml(ctx) {
121
+ /* ── the Mentions Viewer (XmsMentionsGrill 1, 2, E1 to E4; XmsDeskList) ── */
122
+ function waitRow(m, now) {
123
+ const a = age(m.since, now);
124
+ let sub;
125
+ if (m.drafted) sub = `<span><em class="hr-dr">Your draft is ready.</em> Send it from ${esc(srcName(m.source))} to clear this.</span>`;
126
+ else sub = `<span>${esc('“' + clip(m.text, 110) + '”' + (m.count > 1 ? (T(m.last) >= day0(now) ? ' and a follow-up today' : ' and ' + (m.count - 1) + ' more') : ''))}</span>`;
127
+ const check = m.check ? `<div class="hr-ck" role="group" aria-label="${esc('Did you answer ' + first(whoOf(m)) + ' already?')}"><span>Did you answer this already?</span>`
128
+ + `<button type="button" class="hr-ckb" data-hr-ck="yes" data-id="${esc(m.id)}" aria-label="Yes, I answered it" title="Yes, I answered it">${svg(P.tick, 15, 2.2)}</button>`
129
+ + `<button type="button" class="hr-ckb" data-hr-ck="no" data-id="${esc(m.id)}" aria-label="No, keep it waiting" title="No, keep it waiting">${svg(P.x, 15, 2.2)}</button></div>` : '';
130
+ return `<button type="button" class="hr-mi hr-w8" data-hr-mi="${esc(m.id)}" aria-label="${esc(whoOf(m) + ', ' + placeOf(m) + ', waiting ' + a + '. Open')}">`
131
+ + `<span class="hr-mw"><b>${esc(whoOf(m) + ' · ' + placeOf(m))}${m.count > 1 ? `<i class="hr-cn" aria-label="${m.count} asks">${m.count}</i>` : ''}</b>${sub}</span>`
132
+ + `<span class="hr-age${late(m.since, now) ? ' late' : ''}">${esc(a)}</span></button>` + check;
133
+ }
134
+ function statusLine(m) {
135
+ if (m.status === 'replied') return 'You replied in the thread';
136
+ if (m.status === 'answered') return 'Marked answered by you';
137
+ if (m.status === 'task') return 'A task now: ' + ((m.task && m.task.title) || 'Reply to ' + first(whoOf(m)));
138
+ if (m.status === 'notask') return 'You said it is not an ask';
139
+ return '';
140
+ }
141
+ function recentRow(m, now) {
142
+ const st = statusLine(m);
143
+ const today = T(m.last) >= day0(now);
144
+ const right = today ? age(m.last, now) : WD[new Date(T(m.last)).getDay()];
145
+ const done = m.status === 'replied' || m.status === 'answered'; // a done ask carries the tick icon, not a ✓ glyph (R28-13)
146
+ const sub = st ? `<span class="hr-st">${done ? svg(P.tick, 13, 2.2) + ' ' : ''}${esc(st)}</span>` : `<span>${esc('“' + clip(m.text, 110) + '”')}${m.broadcast ? ' <em class="hr-nc">Not counted as an ask</em>' : ''}</span>`;
147
+ const dot = m.fyi && !m.read;
148
+ return `<button type="button" class="hr-mi${dot ? ' hr-un' : ' hr-rd'}" data-hr-mi="${esc(m.id)}" aria-label="${esc(whoOf(m) + ', ' + placeOf(m) + (dot ? ', not opened' : '') + '. Open')}">`
149
+ + `<span class="hr-mdot${dot ? '' : ' read'}" aria-hidden="true"></span><span class="hr-mw"><b>${esc(whoOf(m) + ' · ' + placeOf(m))}</b>${sub}</span>`
150
+ + `<span class="hr-age">${esc(right)}</span></button>`;
151
+ }
152
+ function byDay(list, now) {
153
+ let out = '', cur = '';
154
+ for (const m of list) { const d = dayLabel(m.last, now); if (d !== cur) { out += `<p class="hr-day">${esc(d)}</p>`; cur = d; } out += recentRow(m, now); }
155
+ return out;
156
+ }
157
+ const hmOf = (t) => { const d = new Date(t); return String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
158
+ function gapsHtml(gaps) {
159
+ return (gaps || []).map((g) => {
160
+ if (g.kind === 'stale') {
161
+ const t = T(g.upto), y = day0(Date.now()) - day0(t) === DAY;
162
+ return `<div class="hr-gap"><p><b>Today’s check hasn’t run yet.</b> Mentions are up to ${esc(hmOf(t) + (y ? ' yesterday' : ' on ' + dayLabel(g.upto).replace(/^Yesterday, /, '')))}.</p>`
163
+ + `<button type="button" class="czs-ib" data-hr-gap="check" aria-label="Check now" title="Check now">${svg(P.again, 16, 2)}</button></div>`;
164
+ }
165
+ const s = srcName(g.source);
166
+ const said = g.state === 'not-reached' ? `<b>PMOS couldn’t reach ${esc(s)}</b> at the last check, so ${esc(s)} mentions may be missing.` : `<b>${esc(s)} isn’t connected</b>, so ${esc(s)} mentions are missing.`;
167
+ return `<div class="hr-gap"><p>${said}</p><button type="button" class="czs-ib" data-hr-gap="connect" aria-label="${esc('Connect ' + s)}" title="${esc('Connect ' + s)}">${svg(P.plug, 16, 2)}</button></div>`;
168
+ }).join('');
169
+ }
170
+ /** The summary card's words. Pure, so a unit test can read it. */
171
+ export function summaryOf(L, now = Date.now()) {
172
+ const { waiting, recent } = L;
173
+ const n = waiting.length;
174
+ if (L.failed) return { line: 'Couldn’t refresh Mentions', text: L.from ? 'Showing the list from ' + hmOf(L.from) + '. The workspace didn’t answer.' : 'The workspace didn’t answer, so nothing can be shown yet.', retry: true };
175
+ if (!n && !recent.length) return { text: 'Nobody mentioned you in the last 7 days.', bare: true };
176
+ if (!n) {
177
+ const asks = recent.filter((m) => !m.fyi).length, fyiToday = recent.filter((m) => m.fyi && T(m.last) >= day0(now)).length;
178
+ const parts = [asks ? 'You answered ' + (asks === 1 ? 'the one ask' : 'all ' + asks + ' asks') + ' this week.' : '', fyiToday ? fyiToday + (fyiToday === 1 ? ' FYI from today is' : ' FYIs from today are') + ' under Last 7 days.' : ''].filter(Boolean);
179
+ return { line: 'Nothing waits on you', text: parts.join(' ') || 'What came in this week is under Last 7 days.' };
180
+ }
181
+ let text;
182
+ if (n >= 6) {
183
+ const by = {}; for (const m of waiting) { const k = m.where || srcName(m.source); by[k] = (by[k] || 0) + 1; }
184
+ const top = Object.entries(by).sort((a, b) => b[1] - a[1])[0];
185
+ text = (top && top[1] * 2 >= n ? 'Most are from ' + top[0] + '. ' : '') + first(whoOf(waiting[0])) + '’s ask has waited ' + age(waiting[0].since, now) + '.';
186
+ } else {
187
+ const said = waiting.slice(0, 2).map((m) => askOf(m) + (m.count > 1 && T(m.last) >= day0(now) ? ', and asked again today' : '') + '.');
188
+ text = said.join(' ') + (n > 2 ? ' And ' + (n - 2) + ' more.' : '');
189
+ }
190
+ return { line: n + (n === 1 ? ' waits' : ' wait') + ' on your reply', right: 'oldest ' + age(waiting[0].since, now), text, reply: true };
191
+ }
192
+ function listHtml(ctx, X) {
75
193
  const now = Date.now();
76
- const { fresh, earlier } = mentionsOf(ctx.D());
77
- const n = fresh.length;
78
- const end = (t) => (/[.?!…]”?$/.test(t) ? t : t + '.');
79
- const said = fresh.slice(0, 2).map((m) => end(first(whoOf(m)) + ' ' + askWord(m) + (m.text ? ' “' + clip(m.text, 70) + '”' : ' something'))).join(' ');
80
- const sum = n
81
- ? VW.czSummary({ line: n + ' new since this morning', tone: 'you', text: said + (n > 2 ? ' And ' + (n - 2) + ' more.' : ''), primary: { label: 'Reply to ' + first(whoOf(fresh[0])), act: 'reply' } })
82
- : VW.czSummary({ text: earlier.length ? 'Nothing new. What you already read today is under Earlier.' : 'Nobody has mentioned you today.' });
194
+ const L = mentionsOf(ctx.D());
195
+ const s = summaryOf(L, now);
196
+ const round = s.reply ? `<button type="button" class="hr-rp" data-hr-act="reply" aria-label="${esc('Reply to ' + first(whoOf(L.waiting[0])))}" title="${esc('Reply to ' + first(whoOf(L.waiting[0])))}">${svg(P.reply, 18, 2.2)}</button>`
197
+ : s.retry ? `<button type="button" class="czs-ib" data-hr-act="retry" aria-label="Try again" title="Try again">${svg(P.again, 16, 2)}</button>` : '';
198
+ const sum = `<div class="hr-sum${s.reply ? ' you' : ''}">${s.line ? `<div class="czs-line${s.reply ? ' you' : ''}">${s.reply ? '<span class="czs-dot" aria-hidden="true"></span>' : ''}<span>${esc(s.line)}</span>${s.right ? `<span class="czs-r hr-old">${esc(s.right)}</span>` : ''}</div>` : ''}`
199
+ + `<div class="hr-sumb"><p class="czs-p">${esc(s.text)}</p>${round}</div></div>`;
200
+ if (s.bare) return '<div class="hr-vb">' + sum + gapsHtml(L.gaps) + '</div>';
201
+ const w = L.waiting, show = X.all || w.length <= 5 ? w : w.slice(0, 5);
202
+ const wHtml = '<div class="hr-ml">' + show.map((m) => waitRow(m, now)).join('') + (show.length < w.length ? `<button type="button" class="hr-all" data-hr-act="all">Show all ${w.length}</button>` : '') + '</div>';
83
203
  const secs = VW.czSections([
84
- n ? { id: 'new', title: 'New', count: n, open: true, html: '<div class="hr-ml">' + fresh.map((m) => itemHtml(m, now)).join('') + '</div>' } : null,
85
- earlier.length ? { id: 'earlier', title: 'Earlier', count: earlier.length, open: false, html: '<div class="hr-ml">' + earlier.map((m) => itemHtml(m, now)).join('') + '</div>' } : null,
204
+ w.length ? { id: 'waiting', title: 'Waiting on you', count: w.length, open: true, html: wHtml } : null,
205
+ L.recent.length ? { id: 'recent', title: 'Last 7 days', count: L.recent.length, open: false, html: '<div class="hr-ml">' + byDay(L.recent, now) + '</div>' } : null,
86
206
  ], { key: 'mentions' });
87
- return '<div class="hr-vb">' + sum + secs + '</div>';
207
+ return '<div class="hr-vb">' + sum + secs + gapsHtml(L.gaps) + '</div>';
88
208
  }
209
+ let LIST = null; // the list Viewer that is open: { body, X }, so a press elsewhere redraws it
89
210
  export function openMentions(ctx) {
90
211
  sheet();
212
+ store.set(SEEN, Date.now());
213
+ const X = { all: false };
91
214
  const draw = (b) => {
92
- b.innerHTML = listHtml(ctx);
93
- b.onclick = (e) => {
94
- const t = e.target.closest('[data-hr-mi],[data-czs-act]'); if (!t || !b.contains(t)) return;
95
- const { all, fresh } = mentionsOf(ctx.D());
215
+ LIST = { body: b, X };
216
+ b.innerHTML = listHtml(ctx, X);
217
+ b.onclick = async (e) => {
218
+ const t = e.target.closest('[data-hr-mi],[data-hr-act],[data-hr-ck],[data-hr-gap]'); if (!t || !b.contains(t)) return;
219
+ const L = mentionsOf(ctx.D());
220
+ const all = [...L.waiting, ...L.recent];
221
+ if (t.dataset.hrCk) { // a 30+ day ask, asked once: ✓ it was answered, × keep it waiting and ask again in 30 days
222
+ const m = all.find((x) => x.id === t.dataset.id); if (!m) return;
223
+ await act(ctx, m, t.dataset.hrCk === 'yes' ? 'answered' : 'keep');
224
+ return;
225
+ }
96
226
  if (t.dataset.hrMi) { const m = all.find((x) => x.id === t.dataset.hrMi); if (m) openOne(m, ctx, { back: true }); return; }
97
- if (t.dataset.czsAct === 'reply' && fresh[0]) ctx.draft(fresh[0]);
227
+ if (t.dataset.hrAct === 'reply' && L.waiting[0]) { openOne(L.waiting[0], ctx, { back: true }); return; }
228
+ if (t.dataset.hrAct === 'all') { X.all = true; draw(b); return; }
229
+ if (t.dataset.hrAct === 'retry') { await load(ctx); draw(b); ctx.redrawList(); return; }
230
+ if (t.dataset.hrGap === 'connect') { import('./cozy-settings.js').then((S) => S.openSettings('connectors')).catch(() => {}); return; }
231
+ if (t.dataset.hrGap === 'check') {
232
+ const r = await ctx.pmPost('/api/sources/refresh-all', { ws: (ctx.board() || {}).ws || '' });
233
+ ctx.toast(r && r.ok ? 'Checking every source now. Mentions update when it is done.' : 'The check did not start: ' + ((r && r.error) || 'the workspace did not answer') + '.');
234
+ }
98
235
  };
99
236
  };
100
- const { fresh } = mentionsOf(ctx.D());
101
- return VW.open({ id: 'mentions', kind: 'Mentions', title: 'Mentions', icon: 'spark', render: draw,
102
- more: fresh.length ? [{ label: 'Mark all read', on: () => markAll(ctx) }] : [] });
103
- }
104
- async function markAll(ctx) {
105
- const { fresh } = mentionsOf(ctx.D());
106
- let ok = 0;
107
- for (const m of fresh) { const r = await ctx.pmPost('/api/mentions/read', { id: m.id, read: true }); if (r && r.ok) { m.read = true; ok++; } }
108
- ctx.toast(ok === fresh.length ? 'Marked read.' : 'Marked ' + ok + ' of ' + fresh.length + ' read. The server did not take the rest.');
109
- if (VW.current() && VW.current().id === 'mentions') openMentions(ctx);
237
+ const body = VW.open({ id: 'mentions', kind: 'Mentions', title: 'Mentions', icon: 'spark', render: draw });
238
+ // read again on open, so the list is never older than the press that opened it
239
+ load(ctx).then(() => { const c = VW.current(); if (c && c.id === 'mentions' && LIST && LIST.body === body) draw(body); ctx.redrawList(); });
240
+ return body;
241
+ }
242
+ function redrawOpen(ctx) {
243
+ const c = VW.current(); if (!c) return;
244
+ if (c.id === 'mentions' && LIST && LIST.body.isConnected) { LIST.body.innerHTML = listHtml(ctx, LIST.X); return; }
245
+ }
246
+
247
+ /* ── the one-tap acts, each with Undo ── */
248
+ const SAID = {
249
+ answered: (m) => 'Marked answered: ' + first(whoOf(m)) + '’s ' + (isMail(m.source) ? 'email' : 'ask'),
250
+ snooze: () => 'Hidden until 09:00 tomorrow',
251
+ notask: (m) => 'Not an ask: ' + first(whoOf(m)) + '’s stops counting',
252
+ keep: () => 'Kept waiting. I’ll ask again in 30 days.',
253
+ };
254
+ async function act(ctx, m, kind, extra = {}) {
255
+ const r = await ctx.pmPost('/api/mentions/act', { id: m.id, act: kind, ...extra });
256
+ if (!r || !r.ok) { ctx.toast('That did not go through' + (r && r.error ? ': ' + r.error : '.')); return false; }
257
+ await load(ctx);
258
+ const c = VW.current();
259
+ if (c && c.id === 'mention:' + m.id && kind !== 'drafted') VW.back(); else redrawOpen(ctx);
260
+ ctx.redrawList();
261
+ if (SAID[kind]) ctx.toastUndo(SAID[kind](m), async () => { const u = await ctx.pmPost('/api/mentions/act', { id: m.id, act: 'undo' }); await load(ctx); redrawOpen(ctx); ctx.redrawList(); return u; });
262
+ return true;
263
+ }
264
+ const taskTitle = (m) => 'Reply to ' + first(whoOf(m));
265
+ /** Make it a task: on the mention's initiative when Home's board holds it, else the PM's own tasks. The toast says where, with Undo. */
266
+ async function makeTask(ctx, m) {
267
+ const title = taskTitle(m);
268
+ const b = ctx.board() || {};
269
+ const onIni = m.initiative && ctx.onBoard(m.initiative) && b.board;
270
+ let task;
271
+ if (onIni) {
272
+ const r = await ctx.pmPost('/api/boards/tasks/add', { ws: b.ws, board: b.board, initiative: m.initiative, title });
273
+ if (!r || !r.ok || !r.item) { ctx.toast('The task was not added' + (r && r.error ? ': ' + r.error : '.')); return; }
274
+ task = { id: r.item.uid || r.item.id, kind: 'board', ws: b.ws, board: b.board, initiative: m.initiative, title };
275
+ } else {
276
+ const r = await ctx.pmPost('/api/pm-items/add', { line: title });
277
+ if (!r || r.ok === false || !(r.item && r.item.id)) { ctx.toast('The task was not added' + (r && r.error ? ': ' + r.error : '.')); return; }
278
+ task = { id: r.item.id, kind: 'item', title };
279
+ }
280
+ const r2 = await ctx.pmPost('/api/mentions/act', { id: m.id, act: 'task', task });
281
+ if (!r2 || !r2.ok) { ctx.toast('The task was added, but the mention still waits: ' + ((r2 && r2.error) || 'the workspace did not answer') + '.'); return; }
282
+ await load(ctx);
283
+ const c = VW.current(); if (c && c.id === 'mention:' + m.id) VW.back(); else redrawOpen(ctx);
110
284
  ctx.reload();
285
+ ctx.toastUndo((onIni ? 'Task added to ' + ctx.iniTitle(m.initiative) : 'Added to your own tasks') + ': ' + title, async () => {
286
+ const u = task.kind === 'board' ? await ctx.pmPost('/api/boards/tasks/undo-add', { ws: task.ws, board: task.board, task: task.id }) : await ctx.pmPost('/api/pm-items/remove', { id: task.id });
287
+ await ctx.pmPost('/api/mentions/act', { id: m.id, act: 'undo' });
288
+ await load(ctx); redrawOpen(ctx); ctx.reload();
289
+ return u;
290
+ });
291
+ }
292
+ /** Send: PMOS never posts. It copies the reply, opens the source, and the row says the draft waits to be sent there. */
293
+ async function sendReply(ctx, m) {
294
+ const text = m.draft || '';
295
+ let copied = false;
296
+ try { if (text && navigator.clipboard) { await navigator.clipboard.writeText(text); copied = true; } } catch { copied = false; }
297
+ const l = https(m.link); if (l) window.open(l, '_blank', 'noopener');
298
+ await act(ctx, m, 'drafted', { to: srcName(m.source) });
299
+ ctx.toast((copied ? 'Copied. ' : 'Copy the reply, then ') + 'Paste it in ' + srcName(m.source) + ' to send it.' + (l ? '' : ' This mention has no link, so open ' + srcName(m.source) + ' yourself.'));
111
300
  }
112
301
 
113
- /* ── one mention (XvAMention, XvAMentionJira, XvAMentionDoc, XvAMentionMail) ── */
114
- const hm = (at) => { const t = Date.parse(at || ''); if (!Number.isFinite(t)) return ''; const d = new Date(t); return String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
302
+ /* ── one mention (XmsMentionsGrill 3, XmsDeskOne, XmsDeskRefine) ── */
303
+ const hm = (at) => (T(at) ? hmOf(T(at)) : '');
115
304
  const ini2 = (who) => esc(String(who || '?').replace(/[^A-Za-z]/g, '').slice(0, 2) || '?');
116
305
  const msgHtml = (x, me) => `<div class="hr-msg${me ? ' me' : ''}"><span class="hr-av" aria-hidden="true">${ini2(x.who)}</span><span class="hr-w"><small><b>${esc(x.who || 'Someone')}</b>${hm(x.at) ? ' · ' + hm(x.at) : ''}</small><span>${esc(x.text)}</span></span></div>`;
117
- /** The source excerpt, with the mention outlined. Only what the record holds: the thread when the brief kept it, else the mention's words. */
306
+ /** The source messages, with the asker's outlined. Only what the record holds: the thread when the read kept it, else the mention's words. */
118
307
  export function excerptHtml(m) {
119
- const own = { who: whoOf(m), at: m.at, text: m.text || '' };
308
+ const own = { who: whoOf(m), at: m.since || m.last, text: m.text || '' };
120
309
  const thread = Array.isArray(m.thread) && m.thread.length ? m.thread : null;
121
- // the mention in the thread: the last message of its author (the server keeps the author's last time as m.at)
122
- let at = -1;
123
- if (thread) for (let i = thread.length - 1; i >= 0; i--) if (!m.who || thread[i].who === m.who) { at = i; break; }
124
- const msgs = thread ? thread.map((x, i) => msgHtml(i === at && !x.text ? { ...x, text: m.text } : x, i === at)).join('') + (at < 0 && m.text ? msgHtml(own, true) : '') : msgHtml(own, true);
125
- if (m.source === 'jira') return `<div class="hr-tkt">${m.where ? `<div class="hr-kv"><span>${esc(m.where)}</span></div>` : ''}${msgs}</div>`;
126
- if (isMail(m.source)) return `<div class="hr-mail">${m.where ? `<b>${esc(m.where)}</b>` : ''}<span>${esc([whoOf(m), hm(m.at), thread && thread.length > 1 ? thread.length + ' messages' : ''].filter(Boolean).join(' · '))}</span></div>`
127
- + (m.text ? `<div class="hr-quote">${esc(m.text)}</div>` : '');
128
- if (isDoc(m.source)) return msgs;
310
+ const mine = (x) => !m.who || x.who === m.who;
311
+ const msgs = thread ? thread.map((x) => msgHtml(x, mine(x))).join('') : msgHtml(own, true);
312
+ if (isMail(m.source)) return `<div class="hr-mail">${m.where ? `<b>${esc(m.where)}</b>` : ''}</div><div class="hr-thr">${msgs}</div>`;
129
313
  return `<div class="hr-thr">${msgs}</div>`;
130
314
  }
131
- const checksHtml = (m) => (Array.isArray(m.checks) && m.checks.length
132
- ? `<div class="hr-chk"><b>What I checked</b>${m.checks.map((c) => `<div class="hr-cl"><span class="hr-ok">${svg(TICK, 15, 2.2)}</span><span>${esc(c)}</span></div>`).join('')}</div>` : '');
133
315
  function oneHtml(m, ctx) {
134
- const a = age(m.at);
135
- const line = m.reply ? 'Waiting on you' + (a ? ' · ' + a : '') : 'Mentioned you' + (a ? ' · ' + a + ' ago' : '');
136
- const text = whoOf(m) + (m.reply ? ' asks you something in ' : ' named you in ') + placeOf(m) + '.';
137
- const meta = [m.initiative ? ctx.iniTitle(m.initiative) : '', m.where && !isMail(m.source) ? m.where : ''].filter(Boolean).join(' · ');
138
- const sum = VW.czSummary({ line: m.read ? line + ' · read' : line, tone: m.reply && !m.read ? 'warn' : '', text, meta, primary: { label: 'Draft a reply', act: 'draft' } });
139
- const link = https(m.link);
140
- const secs = VW.czSections([
141
- link ? { id: 'src', title: 'Open in ' + srcName(m.source), on: 'src' } : null,
142
- m.initiative ? { id: 'ini', title: ctx.iniTitle(m.initiative), count: ctx.stageOf(m.initiative) || '', on: 'ini' } : null,
143
- ], { key: 'mention' });
144
- return '<div class="hr-vb">' + sum + excerptHtml(m) + checksHtml(m) + secs + '</div>';
316
+ const now = Date.now();
317
+ const line = m.waiting ? 'Waiting on you · ' + age(m.since, now) : m.status ? statusLine(m) : 'Mentioned you · ' + age(m.last, now) + ' ago';
318
+ const text = m.about || (m.ask ? askOf(m) + '.' : whoOf(m) + (m.fyi ? ' named you in ' : ' asks you something in ') + placeOf(m) + '.');
319
+ const meta = [m.where || srcName(m.source), m.initiative ? ctx.iniTitle(m.initiative) : '', m.initiative ? ctx.stageOf(m.initiative) : ''].filter(Boolean).join(' · ');
320
+ const icons = m.waiting ? [['answered', 'Mark answered', P.tick], ['snooze', 'Remind me tomorrow', P.clock], ['task', 'Make it a task', P.task], ['notask', 'Not an ask', P.x]]
321
+ .map(([k, l, d]) => `<button type="button" class="czs-ib hr-ia" data-hr-one="${k}" aria-label="${esc(l)}" title="${esc(l)}">${svg(d, 17, 2)}</button>`).join('') : '';
322
+ const sum = `<div class="czs-sum hr-one"><div class="czs-line${m.waiting ? ' warn' : ''}">${m.waiting ? '<span class="czs-dot" aria-hidden="true"></span>' : ''}<span>${esc(line)}</span></div>`
323
+ + `<p class="czs-p">${esc(text)}</p>${meta ? `<p class="czs-meta">${esc(meta)}</p>` : ''}${icons ? `<div class="czs-acts hr-acts">${icons}</div>` : ''}</div>`;
324
+ const found = Array.isArray(m.found) && m.found.length
325
+ ? `<div class="hr-card2 hr-found"><b class="hr-h">What I found</b><ul>${m.found.map((f) => `<li>${f.label ? `<b>${esc(f.label)}</b>${f.text ? ' ' + esc(f.text) : ''}` : esc(f.text)}</li>`).join('')}</ul></div>` : '';
326
+ const reply = m.waiting || m.draft
327
+ ? `<div class="hr-card2 hr-reply"><b class="hr-h">Proposed reply</b>${m.draft ? `<p class="hr-rtxt" data-hr-draft>${esc(m.draft)}</p>` : '<p class="hr-none">No reply proposed yet. Write it with Claude.</p>'}`
328
+ + `<div class="hr-racts"><button type="button" class="czs-ib" data-hr-one="pen" aria-label="${m.draft ? 'Change it with Claude' : 'Write it with Claude'}" title="${m.draft ? 'Change it with Claude' : 'Write it with Claude'}">${svg(P.pen, 16, 2)}</button>`
329
+ + (m.draft ? `<button type="button" class="hr-rp" data-hr-one="send" aria-label="${esc('Copy it and open ' + srcName(m.source))}" title="${esc('Copy it and open ' + srcName(m.source) + '. PMOS never posts.')}">${svg(P.send, 17, 2.2)}</button>` : '') + '</div></div>'
330
+ : '';
331
+ const n = Array.isArray(m.thread) ? m.thread.filter((x) => !m.who || x.who === m.who).length : 1;
332
+ const secs = VW.czSections([{ id: 'msgs', title: first(whoOf(m)) + '’s ' + (n === 1 ? 'message' : n + ' messages'), open: false, html: excerptHtml(m) },
333
+ !m.waiting && https(m.link) ? { id: 'src', title: 'Open in ' + srcName(m.source), on: 'src' } : null], { key: 'mention' });
334
+ return '<div class="hr-vb">' + sum + found + reply + secs + '</div>';
145
335
  }
146
- const taskLine = (m) => (m.reply ? 'Reply to ' + first(whoOf(m)) + ' (' + srcName(m.source) + ') by today' : 'Read ' + first(whoOf(m)) + '\'s note (' + srcName(m.source) + ')');
147
336
  export function openOne(m, ctx, o = {}) {
148
337
  sheet();
149
- const more = () => [
150
- { label: 'Make it a task', on: async () => {
151
- const r = await ctx.pmPost('/api/pm-items/add', { line: taskLine(m) });
152
- ctx.toast(r && r.ok !== false ? 'Added to your tasks: ' + taskLine(m).replace(/ by today$/, '') : 'That did not go through' + (r && r.error ? ': ' + r.error : '.'));
153
- if (r && r.ok !== false) ctx.reload();
154
- } },
155
- { label: m.read ? 'Mark unread' : 'Mark read', on: async () => {
156
- const to = !m.read;
157
- const r = await ctx.pmPost('/api/mentions/read', { id: m.id, read: to });
158
- if (!r || !r.ok) { ctx.toast('That did not go through' + (r && r.error ? ': ' + r.error : '.')); return; }
159
- m.read = to; ctx.toast(to ? 'Marked read.' : 'Marked unread.');
160
- const c = VW.current(); if (c && c.id === 'mention:' + m.id) openOne(m, ctx, { _again: true });
161
- ctx.reload();
162
- } },
163
- ];
338
+ const id = m.id;
339
+ const cur = () => { const L = mentionsOf(ctx.D()); return [...L.waiting, ...L.recent].find((x) => x.id === id) || m; };
340
+ if (m.fyi && !m.read) ctx.pmPost('/api/mentions/read', { id, read: true }).then((r) => { if (r && r.ok) { m.read = true; const c = cur(); c.read = true; redrawOpen(ctx); } });
341
+ let body = null;
164
342
  const draw = (b) => {
165
- b.innerHTML = oneHtml(m, ctx);
166
- b.onclick = (e) => {
167
- const t = e.target.closest('[data-czs-act]'); if (!t || !b.contains(t)) return;
168
- const k = t.dataset.czsAct;
169
- if (k === 'draft') ctx.draft(m);
170
- else if (k === 'src') { const l = https(m.link); if (l) window.open(l, '_blank', 'noopener'); }
171
- else if (k === 'ini') ctx.goIni(m.initiative);
343
+ body = b;
344
+ b.innerHTML = oneHtml(cur(), ctx);
345
+ b.onclick = async (e) => {
346
+ const t = e.target.closest('[data-hr-one],[data-czs-act]'); if (!t || !b.contains(t)) return;
347
+ const k = t.dataset.hrOne || t.dataset.czsAct, x = cur();
348
+ if (k === 'src') { const l = https(x.link); if (l) window.open(l, '_blank', 'noopener'); return; }
349
+ if (k === 'pen') { ctx.draft(x); return; }
350
+ if (k === 'send') { await sendReply(ctx, x); if (body && body.isConnected) draw(body); return; }
351
+ if (k === 'task') { await makeTask(ctx, x); return; }
352
+ if (k === 'answered' || k === 'snooze' || k === 'notask') await act(ctx, x, k);
172
353
  };
173
354
  };
174
- const args = { id: 'mention:' + m.id, kind: 'Mention', title: whoOf(m) + ' · ' + placeOf(m), icon: ICON[m.source] || 'at', render: draw, more: more() };
175
- // Mark read redraws in place: the item is replaced by itself, so ← still goes back to the list behind it
176
- if (o._again) return VW.open({ ...args, back: false, _back: true });
177
- return VW.open({ ...args, back: !!o.back });
355
+ const args = { id: 'mention:' + id, kind: 'Mention', title: whoOf(m) + ' · ' + (m.where || srcName(m.source)), icon: ICON[m.source] || 'at', render: draw };
356
+ const out = VW.open({ ...args, back: !!o.back });
357
+ // Claude changes the reply from the chat (pmos mention draft): read again while this mention is open, and show the new reply
358
+ const tick = async () => {
359
+ const c = VW.current(); if (!c || c.id !== 'mention:' + id || !body || !body.isConnected) return;
360
+ if (typeof document === 'undefined' || !document.hidden) {
361
+ const was = cur().draft;
362
+ await load(ctx);
363
+ const now = cur();
364
+ if (now.draft !== was && body.isConnected) { const p = body.querySelector('[data-hr-draft]'); if (p) p.textContent = now.draft; else draw(body); }
365
+ }
366
+ setTimeout(tick, 5000);
367
+ };
368
+ setTimeout(tick, 5000);
369
+ return out;
178
370
  }
179
371
 
180
372
  /* ── the look: cozy-home-rows.css, loaded once ── */
@@ -0,0 +1,65 @@
1
+ /* pm/home-ses-name.js — tap a session's name to rename it (session names A, canvas XmsNames; the agreed rename field of RnATask).
2
+ * The open session's name is the press in the phone's top bar and in the desktop chat header. A tap turns it into one field with a blue
3
+ * check: Enter saves, Esc cancels, an empty or unchanged name saves nothing, a refusal keeps the field with the reason. The PM's name locks
4
+ * the session's name: Claude never renames it again (lib/session-name.js). "Renamed" with Undo, and every row shows the new name at once.
5
+ *
6
+ * mountSesName({ esc, pmPost, toast, toastUndo, session(sid), shown(s), changed() })
7
+ * → { titleHtml(sid, title, cls), renaming(sid) }
8
+ * titleHtml: the press, or the field while that session is being renamed. changed() redraws the top bar, the header and the list. */
9
+ import { sessionRename } from './rename-press.js';
10
+
11
+ const CHECK = '<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>';
12
+
13
+ export function mountSesName(host) {
14
+ const { esc } = host;
15
+ const R = { sid: null, value: '', busy: false, err: '' };
16
+ const field = () => document.querySelector('[data-hm-ren] input');
17
+
18
+ function titleHtml(sid, title, cls = '') {
19
+ if (!sid) return esc(title || '');
20
+ if (R.sid !== sid) return `<button type="button" class="hm-rn ${cls}" data-hm-rn="${esc(sid)}" aria-label="${esc('Rename ' + (title || ''))}" title="Rename">${esc(title || '')}</button>`;
21
+ return `<form class="hm-ren" data-hm-ren data-esc-layer><input type="text" value="${esc(R.value)}" maxlength="60" aria-label="Session name" autocomplete="off"${R.busy ? ' disabled' : ''}>`
22
+ + `<button type="submit" class="sv" aria-label="Save the name" title="Save (Enter). Esc cancels."${R.busy ? ' disabled' : ''}>${CHECK}</button></form>`
23
+ + (R.err ? `<p class="hm-renerr" role="alert">${esc(R.err)}</p>` : '');
24
+ }
25
+ const focusField = () => { const i = field(); if (i) { i.focus(); i.select(); } };
26
+ function start(sid) {
27
+ const s = host.session(sid); if (!s) return;
28
+ Object.assign(R, { sid, value: host.shown(s), busy: false, err: '' });
29
+ host.changed(); focusField();
30
+ }
31
+ function end() {
32
+ const sid = R.sid; Object.assign(R, { sid: null, value: '', busy: false, err: '' }); host.changed();
33
+ const b = document.querySelector(`[data-hm-rn="${CSS.escape(sid || '')}"]:not([hidden])`); if (b && b.offsetParent) b.focus();
34
+ }
35
+ async function save() {
36
+ const sid = R.sid, s = host.session(sid); if (!s || R.busy) return;
37
+ const i = field(); const v = String((i && i.value) || '').replace(/\s+/g, ' ').trim();
38
+ if (!v) { if (i) i.focus(); return; } // an empty name is not saved: the field stays
39
+ const from = host.shown(s);
40
+ if (v === from) { end(); return; }
41
+ Object.assign(R, { value: v, busy: true, err: '' }); host.changed();
42
+ const r = await sessionRename({ pmPost: host.pmPost, session: s, shown: from }).save(v).catch(() => null);
43
+ if (R.sid !== sid) return;
44
+ if (!r || !r.ok) { Object.assign(R, { busy: false, err: (r && r.error) || 'The name was not saved.' }); host.changed(); focusField(); return; }
45
+ Object.assign(s, { name: r.name, name_by: r.name_by });
46
+ end();
47
+ host.toastUndo('Renamed', async () => {
48
+ const u = await r.undo();
49
+ if (u.ok) { const t = host.session(sid); if (t) Object.assign(t, { name: u.name, name_by: u.name_by }); host.changed(); }
50
+ return u;
51
+ });
52
+ }
53
+
54
+ document.addEventListener('click', (e) => {
55
+ const b = e.target.closest && e.target.closest('[data-hm-rn]');
56
+ if (b) { e.preventDefault(); start(b.dataset.hmRn); }
57
+ });
58
+ document.addEventListener('submit', (e) => { if (e.target.closest && e.target.closest('[data-hm-ren]')) { e.preventDefault(); save(); } });
59
+ document.addEventListener('keydown', (e) => {
60
+ if (e.key !== 'Escape' || !R.sid || !(e.target.closest && e.target.closest('[data-hm-ren]'))) return;
61
+ e.preventDefault(); e.stopPropagation(); end();
62
+ }, true);
63
+
64
+ return { titleHtml, renaming: (sid) => !!sid && R.sid === sid };
65
+ }