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.
- package/package.json +25 -30
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +2 -2
- package/workspace/briefing-premium-initiative-test.js +9 -15
- package/workspace/briefing-premium-insights-test.js +2 -2
- package/workspace/briefing-premium-test.js +3 -3
- package/workspace/changelog.json +24 -0
- package/workspace/chat-asks-test.js +146 -0
- package/workspace/guide/board.md +1 -1
- package/workspace/guide/breakdown.md +6 -13
- package/workspace/guide/briefing-premium.md +1 -1
- package/workspace/guide/home.md +24 -0
- package/workspace/guide/index.md +1 -1
- package/workspace/guide/initiative-driver.md +1 -1
- package/workspace/guide/initiatives-screen.md +1 -1
- package/workspace/guide/pm-only-acts.md +23 -24
- package/workspace/guide/today.md +1 -1
- package/workspace/home-rows-test.js +149 -56
- package/workspace/ini-workflow-test.js +4 -4
- package/workspace/lib/briefing-premium-agent.js +8 -1
- package/workspace/lib/briefing-premium-writes.js +5 -4
- package/workspace/lib/coredoc-cli.js +1 -1
- package/workspace/lib/driver-cli.js +2 -1
- package/workspace/lib/driver-decide.js +3 -2
- package/workspace/lib/driver.js +2 -1
- package/workspace/lib/engine/boards.js +3 -1
- package/workspace/lib/goal-chat.js +94 -30
- package/workspace/lib/grant-mint.js +3 -2
- package/workspace/lib/initiative-cli.js +9 -9
- package/workspace/lib/issues.js +5 -4
- package/workspace/lib/mention-cli.js +70 -0
- package/workspace/lib/mention-store.js +307 -0
- package/workspace/lib/people-store.js +1 -1
- package/workspace/lib/people.js +3 -1
- package/workspace/lib/placements.js +13 -15
- package/workspace/lib/plan-items.js +17 -48
- package/workspace/lib/pm-guard.js +18 -5
- package/workspace/lib/pm-lines-needs.js +9 -5
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/report-cli.js +2 -2
- package/workspace/lib/routes-board-metric-targets.js +0 -1
- package/workspace/lib/routes-boards.js +12 -0
- package/workspace/lib/routes-briefing-premium.js +5 -7
- package/workspace/lib/routes-core-docs.js +0 -1
- package/workspace/lib/routes-custom-docs.js +0 -1
- package/workspace/lib/routes-driver.js +0 -1
- package/workspace/lib/routes-home-desk.js +1 -1
- package/workspace/lib/routes-home-review.js +1 -1
- package/workspace/lib/routes-initiative-layout.js +1 -1
- package/workspace/lib/routes-insights-records.js +0 -1
- package/workspace/lib/routes-meeting-material.js +0 -1
- package/workspace/lib/routes-mentions.js +62 -9
- package/workspace/lib/routes-onboarding.js +3 -1
- package/workspace/lib/routes-orchestrator.js +0 -1
- package/workspace/lib/routes-premium-charts.js +0 -1
- package/workspace/lib/routes-premium-dashboards.js +0 -1
- package/workspace/lib/routes-programs.js +1 -1
- package/workspace/lib/routes-records.js +1 -1
- package/workspace/lib/routes-report-design.js +7 -3
- package/workspace/lib/routes-report-setups.js +0 -1
- package/workspace/lib/routes-report-structure.js +0 -1
- package/workspace/lib/routes-runs.js +2 -5
- package/workspace/lib/routes-scan.js +0 -1
- package/workspace/lib/routes-sources.js +1 -1
- package/workspace/lib/run-answers.js +14 -5
- package/workspace/lib/scan-cli.js +2 -1
- package/workspace/lib/scan.js +2 -1
- package/workspace/lib/session-files.js +132 -0
- package/workspace/lib/session-name.js +103 -0
- package/workspace/lib/source-reads.js +4 -1
- package/workspace/lib/vendor/scripts/onboarding/proposals.js +7 -3
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +10 -8
- package/workspace/premium-chat-goal-setup-test.js +203 -0
- package/workspace/premium-chat-goal-view-test.js +28 -23
- package/workspace/premium-chat-line-test.js +189 -0
- package/workspace/premium-core-doc-issue-test.js +1 -1
- package/workspace/premium-viewer-share-test.js +5 -2
- package/workspace/premium-vw-backlog-test.js +1 -1
- package/workspace/premium-vw-item-test.js +1 -1
- package/workspace/premium-vw-jira-test.js +1 -1
- package/workspace/public/pm/chat-ask.js +17 -9
- package/workspace/public/pm/cozy-home-rows.css +39 -1
- package/workspace/public/pm/cozy-home.css +112 -12
- package/workspace/public/pm/cozy-search.js +2 -1
- package/workspace/public/pm/cozy-steps.css +69 -0
- package/workspace/public/pm/cozy-steps.js +90 -0
- package/workspace/public/pm/goal-chat.js +141 -23
- package/workspace/public/pm/home-app.js +68 -35
- package/workspace/public/pm/home-ask.js +121 -0
- package/workspace/public/pm/home-chat.js +120 -68
- package/workspace/public/pm/home-data.js +10 -2
- package/workspace/public/pm/home-goal.js +159 -0
- package/workspace/public/pm/home-ini.css +35 -0
- package/workspace/public/pm/home-ini.js +50 -19
- package/workspace/public/pm/home-line.css +59 -0
- package/workspace/public/pm/home-line.js +200 -0
- package/workspace/public/pm/home-list.js +2 -2
- package/workspace/public/pm/home-mentions.js +303 -111
- package/workspace/public/pm/home-ses-name.js +65 -0
- package/workspace/public/pm/home-stage-card.js +94 -0
- package/workspace/public/pm/home-sweep.js +112 -0
- package/workspace/public/pm/home-today.js +7 -2
- package/workspace/public/pm/premium-initiative-head.js +8 -4
- package/workspace/public/pm/rename-press.js +24 -0
- package/workspace/public/pm/wf-page.css +3 -0
- package/workspace/public/pm/wf-page.js +2 -1
- package/workspace/public/premium-workflows.html +1 -0
- package/workspace/replaced-tests.json +101 -0
- package/workspace/server.js +133 -20
- package/workspace/session-names-test.js +144 -0
- package/workspace/skills/jira-push.skill +1 -0
- package/workspace/skills/morning-brief.skill +2 -1
- package/workspace/skills/report-daily.skill +1 -0
- package/workspace/skills/report-monthly.skill +1 -0
- package/workspace/skills/report-weekly.skill +1 -0
- package/workspace/skills/sources-read.skill +3 -2
- package/workspace/stage-card-test.js +203 -0
- package/workspace/test-lists/chat-asks.json +13 -0
- package/workspace/test-lists/chat-progress.json +13 -0
- package/workspace/test-lists/mentions-a-plus.json +9 -0
- package/workspace/test-lists/premium-chat-goal-setup.json +9 -0
- package/workspace/test-lists/session-files.json +5 -0
- package/workspace/test-lists/session-names.json +13 -0
- package/workspace/test-lists/stage-card.json +6 -0
- package/workspace/tk-tasks-test.js +1 -1
- 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 ? (
|
|
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 (
|
|
2
|
-
*
|
|
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
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* ctx:
|
|
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
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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
|
|
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
|
-
/**
|
|
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
|
|
34
|
-
return {
|
|
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 =
|
|
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.
|
|
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
|
|
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 (
|
|
107
|
+
/* ── the row on Home (XmsMentionsGrill 4) ── */
|
|
57
108
|
export function rowHtml(D, o = {}) {
|
|
58
|
-
const
|
|
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 + '
|
|
62
|
-
+
|
|
63
|
-
+ (n ? `<span class="
|
|
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 (
|
|
67
|
-
function
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
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
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
const sum =
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
-
|
|
93
|
-
b.
|
|
94
|
-
|
|
95
|
-
const
|
|
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.
|
|
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 {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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 (
|
|
114
|
-
const hm = (at) =>
|
|
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
|
|
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.
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
if (
|
|
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
|
|
135
|
-
const line = m.
|
|
136
|
-
const text = whoOf(m) + (m.
|
|
137
|
-
const meta = [m.initiative ? ctx.iniTitle(m.initiative) : '', m.
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
166
|
-
b.
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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:' +
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
+
}
|