create-pmos 0.613.0 → 0.614.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 +14 -14
- 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/changelog.json +13 -0
- package/workspace/guide/cli.md +2 -1
- package/workspace/guide/layout.md +22 -8
- package/workspace/guide/settings-and-switches.md +1 -0
- package/workspace/lib/events-place.js +2 -2
- package/workspace/lib/mention-cli.js +6 -3
- package/workspace/lib/mention-store.js +49 -10
- package/workspace/lib/routes-events-place.js +2 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-home-rows.css +55 -0
- package/workspace/public/pm/cozy-nav.js +15 -2
- package/workspace/public/pm/cozy-pop-work.css +3 -0
- package/workspace/public/pm/cozy-pop-work.js +5 -3
- package/workspace/public/pm/cozy-today-app.js +119 -12
- package/workspace/public/pm/cozy-today-model.js +278 -21
- package/workspace/public/pm/cozy-today-page.css +74 -15
- package/workspace/public/pm/cozy-today-view.js +89 -31
- package/workspace/public/pm/home-app.js +14 -6
- package/workspace/public/pm/home-data.js +1 -1
- package/workspace/public/pm/home-ini.js +17 -1
- package/workspace/public/pm/home-mentions.js +121 -6
- package/workspace/public/pm/ini-edit.js +2 -0
- package/workspace/public/pm/ini-view.css +2 -0
- package/workspace/public/pm/mention-one-model.js +115 -0
- package/workspace/public/pm/pop-work-model.js +17 -11
- package/workspace/run-tests.js +11 -4
- package/workspace/server.js +8 -0
- package/workspace/skills/morning-brief.skill +1 -1
- package/workspace/test-run.js +2 -0
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
* Viewer no longer floats over a chat on a laptop. A row's press opens its work in the one popup (cozy-popup.js) with Home's chat beside it.
|
|
12
12
|
* The capture line adds a row and does nothing else: no popup, no session. Every write is a press: today-log marks and own entries
|
|
13
13
|
* (POST /api/today-log/*), a task's state or due day (the Board's own routes), an item's done, defer, due or remove (POST /api/pm-items/*),
|
|
14
|
-
* a Lab finding kept or dropped (POST /api/lab/*). Each says what it did in the toast, with Undo. Reads: GET /api/today-log
|
|
14
|
+
* a Lab finding kept or dropped (POST /api/lab/*). Each says what it did in the toast, with Undo. Reads: GET /api/today-log, and GET
|
|
15
|
+
* /api/events-place for the reports that go out today (placed at their time on the agenda). */
|
|
15
16
|
import * as TM from './cozy-today-model.js';
|
|
16
17
|
import * as TP from './cozy-today-view.js';
|
|
18
|
+
import * as OM from './mention-one-model.js'; // the one mention's title and the self check's proof line (Today round 3)
|
|
17
19
|
|
|
18
20
|
const ASK_SEND = new Set(['session']);
|
|
19
21
|
export function mountToday(ctx) {
|
|
20
|
-
const X = { log: { entries: [], marks: {} }, html: '', model: null, agenda: null, read: false, busy: new Set() };
|
|
22
|
+
const X = { log: { entries: [], marks: {} }, html: '', model: null, agenda: null, read: false, busy: new Set(), type: '', open: false, hide: new Set() };
|
|
21
23
|
const el = document.getElementById('tdPage');
|
|
22
24
|
const on = () => !!el && !ctx.isPhone();
|
|
23
25
|
const day = () => TM.dayKey(ctx.now());
|
|
@@ -27,7 +29,19 @@ export function mountToday(ctx) {
|
|
|
27
29
|
if (r && r.ok) X.log = { entries: r.entries || [], marks: r.marks || {} };
|
|
28
30
|
X.read = true;
|
|
29
31
|
draw();
|
|
32
|
+
readReports();
|
|
30
33
|
}
|
|
34
|
+
// the reports that go out today, at their time (GET /api/events-place; 202 while a Board is read: ask again in a moment, three times)
|
|
35
|
+
async function readReports(n = 0) {
|
|
36
|
+
const r = await ctx.pmGet('/api/events-place').catch(() => null);
|
|
37
|
+
if (r && r.state === 'reading' && n < 3) { setTimeout(() => readReports(n + 1), 4000); return; }
|
|
38
|
+
if (!r || !r.ok) return;
|
|
39
|
+
const today = day();
|
|
40
|
+
X.reports = (r.items || []).filter((x) => x && x.kind === 'report' && x.date === today && x.time).map((x) => ({ key: x.key, title: x.title, time: x.time }));
|
|
41
|
+
draw();
|
|
42
|
+
}
|
|
43
|
+
// the head's clock: the time on it moves each minute, and only its words change
|
|
44
|
+
setInterval(() => { const w = el && el.querySelector('.td-when'); if (w) w.textContent = TM.headModel(ctx.now()).when; }, 30000);
|
|
31
45
|
const tdItems = () => {
|
|
32
46
|
const tabs = (ctx.S.D.work && ctx.S.D.work.queue && ctx.S.D.work.queue.tabs) || [];
|
|
33
47
|
return ((tabs.find((t) => t.key === 'today') || { groups: [] }).groups || []).flatMap((g) => g.rows || []);
|
|
@@ -42,9 +56,12 @@ export function mountToday(ctx) {
|
|
|
42
56
|
const lab = (S.lab || []).flatMap((l) => (l.items || []).map((f) => ({ ...f, ws: l.ws, board: l.board })));
|
|
43
57
|
const L = TM.logModel({ rank: ctx.rank(), move, items: tdItems(), drafts, review: R && R.open && !R.done ? { title: 'Your weekly review' } : null,
|
|
44
58
|
own: X.log.entries, marks: X.log.marks, lab, titleOf: ctx.titleOf, now });
|
|
45
|
-
const
|
|
59
|
+
const lead = L.rows.find((r) => !r.done && r.src !== 'note' && r.src !== 'own' && r.src !== 'lab');
|
|
60
|
+
const A = TM.agendaModel({ meetings: ctx.meetings(), own: X.log.entries, reports: X.reports || [], focus: lead ? { key: lead.key, title: lead.title } : null, now,
|
|
46
61
|
iniOf: (m) => (m && (m.initiative || (m.level && m.level.kind === 'initiative' && m.level.id) || (m.about && m.about.kind === 'initiative' && m.about.id))) || null });
|
|
47
|
-
|
|
62
|
+
const O = TM.overviewModel(L, A);
|
|
63
|
+
O.suggest = O.suggest.filter((x) => !X.hide.has(x.key));
|
|
64
|
+
return { L, A, O };
|
|
48
65
|
}
|
|
49
66
|
function draw() {
|
|
50
67
|
document.body.classList.toggle('cz-today', on());
|
|
@@ -52,37 +69,72 @@ export function mountToday(ctx) {
|
|
|
52
69
|
if (!on()) { el.hidden = true; return; }
|
|
53
70
|
el.hidden = false;
|
|
54
71
|
if (!ctx.S.ready) { if (!el.firstChild) el.innerHTML = '<p class="td-none">Reading your day.</p>'; return; }
|
|
55
|
-
const { L, A } = models();
|
|
56
|
-
X.model = L; X.agenda = A;
|
|
72
|
+
const { L, A, O } = models();
|
|
73
|
+
X.model = L; X.agenda = A; X.overview = O;
|
|
74
|
+
autoClosed();
|
|
75
|
+
// the rail's number on every place: the lines for today (Do first and what waits today), the number the Overview says; kept for the
|
|
76
|
+
// other places with its day (pm/cozy-nav.js reads it there)
|
|
77
|
+
if (O.today !== X.calls) {
|
|
78
|
+
X.calls = O.today;
|
|
79
|
+
document.dispatchEvent(new CustomEvent('cz:calls', { detail: { count: O.today } }));
|
|
80
|
+
try { localStorage.setItem('pmos.today.count', JSON.stringify({ day: L.today, n: O.today })); } catch { /* a private window */ }
|
|
81
|
+
}
|
|
82
|
+
if (X.type && !(L.types || {})[X.type]) X.type = '';
|
|
57
83
|
const cap = document.getElementById('tdCap'), draft = cap ? cap.value : '', focus = !!cap && document.activeElement === cap;
|
|
58
|
-
const html = TP.pageHtml(L, A, {
|
|
84
|
+
const html = TP.pageHtml(L, A, { draft, overview: O, type: X.type, open: X.open || !!X.type, handled: X.type && X.type !== 'Ask' ? [] : handled(), hopen: X.hopen });
|
|
59
85
|
if (html === X.html && el.firstChild) return;
|
|
60
86
|
X.html = html;
|
|
61
87
|
const st = el.parentNode ? el.parentNode.scrollTop : 0;
|
|
62
|
-
el.innerHTML = html;
|
|
88
|
+
el.innerHTML = TP.headHtml(TM.headModel(ctx.now())) + html;
|
|
63
89
|
if (el.parentNode) el.parentNode.scrollTop = st;
|
|
64
90
|
const c2 = document.getElementById('tdCap'); if (c2 && focus) { c2.focus(); c2.setSelectionRange(c2.value.length, c2.value.length); }
|
|
65
91
|
}
|
|
66
92
|
const rowOf = (key) => (X.model ? X.model.rows.find((r) => r.key === key) : null);
|
|
67
|
-
const snap = (r) => ({ title: r.title, work: r.work, job: r.job });
|
|
68
|
-
async function
|
|
93
|
+
const snap = (r) => ({ title: r.title, work: r.work, job: r.job, type: r.type });
|
|
94
|
+
async function mark1(key, act, extra) {
|
|
69
95
|
const r = await ctx.pmPost('/api/today-log/mark', { key, act, day: day(), ...extra }).catch(() => null);
|
|
70
96
|
return r && r.ok ? r : { ok: false, error: (r && r.error) || 'the server did not answer' };
|
|
71
97
|
}
|
|
98
|
+
/** A mark goes to every key behind a line (the same ask from two people is one line with two keys). */
|
|
99
|
+
async function mark(key, act, extra = {}) {
|
|
100
|
+
const r = rowOf(key), keys = r && r.keys && r.keys.length ? r.keys : [key];
|
|
101
|
+
let res = null;
|
|
102
|
+
for (const k of keys) { res = await mark1(k, act, k === key ? extra : {}); if (!res.ok) return res; }
|
|
103
|
+
return res;
|
|
104
|
+
}
|
|
72
105
|
/** After a write: read the log again, and Home's own lists when the source changed. */
|
|
73
106
|
const after = async (src) => { if (src) await ctx.reload(); await read(); };
|
|
74
107
|
const pop = (r) => ctx.VW.popNext({ keep: true, id: r.ini || r.key, kind: r.ini ? 'initiative' : 'item', title: r.ini ? ctx.titleOf(r.ini) : r.title });
|
|
75
108
|
/** A chat-only press (a session that asks): the popup with that chat and the sessions on its left. */
|
|
76
109
|
const chatPop = () => setTimeout(() => { if (!ctx.VW.popOpen()) { ctx.VW.popNext(null); const t = ctx.chatNow(); if (t) ctx.POP.openCos(t); } }, 120);
|
|
77
110
|
|
|
111
|
+
/** The popup's chat hidden for this open (round 3 point 7), until the popup's own per-item rule does it. */
|
|
112
|
+
const chatOff = () => setTimeout(() => { const h = document.querySelector('.cz-pop:not([hidden]) [data-pop="hide"]'); if (h && !h.closest('.chat-off')) h.click(); }, 60);
|
|
113
|
+
/** The rows in the order Today shows them, the ones that open something. */
|
|
114
|
+
const order = () => { const L = X.model; if (!L) return []; return [...(L.first || []), ...(L.todayRows || []), ...(X.open || X.type ? L.wait || [] : [])].filter((r) => r && !r.done && r.src !== 'note' && r.src !== 'own'); };
|
|
115
|
+
/** ↑ ↓ (j k) in the popup: the previous or next Today row opens in its place. true when it stepped. */
|
|
116
|
+
function step(d) {
|
|
117
|
+
const list = order(), i = list.findIndex((r) => r.key === X.last);
|
|
118
|
+
const next = list[i < 0 ? 0 : i + d]; if (!next) return false;
|
|
119
|
+
open(next); return true;
|
|
120
|
+
}
|
|
78
121
|
function open(r) {
|
|
79
122
|
if (!r) return;
|
|
80
123
|
const ref = r.ref || {};
|
|
124
|
+
X.last = r.key; // ↑ ↓ (j k) step from here (round 3 point 6)
|
|
81
125
|
if (r.src === 'ask') {
|
|
126
|
+
// a mention opens that one mention in the popup, about it, with the chat hidden (round 3 points 1 to 7); never the Mentions list
|
|
127
|
+
if (ref.kind === 'mention' && ref.mention && ctx.openMention) {
|
|
128
|
+
const m = ref.mention;
|
|
129
|
+
ctx.VW.popNext({ id: 'mention:' + m.id, kind: 'mention', title: OM.askTitle(m) });
|
|
130
|
+
if (ctx.openMention(m.id, { step, m })) { chatOff(); return; } // m: the row's own copy when a fresh read no longer lists it
|
|
131
|
+
}
|
|
132
|
+
// a Check (did it work?) opens its initiative, where the verdict is asked, not the Intelligence list (round 3 point 8)
|
|
133
|
+
if (ref.kind === 'verdict') { const ini = ref.ini || (ref.verdict && ref.verdict.ini); if (ini && ctx.hasIni(ini)) { ctx.goIni(ini); return; } }
|
|
82
134
|
if (ref.kind === 'call') { const c = ref.call || {}; if (c.ini && ctx.hasIni(c.ini) && !ASK_SEND.has(c.kind)) { ctx.goIni(c.ini); return; } pop(r); ctx.select(c.id); if (ASK_SEND.has(c.kind)) chatPop(); return; }
|
|
83
135
|
pop(r); ctx.movePress({ dataset: { yd: 'mv-open', key: ref.key }, disabled: false }); return;
|
|
84
136
|
}
|
|
85
|
-
if (r.src === 'move') { if (ref.kind === 'task' && r.ini && ctx.hasIni(r.ini)) { ctx.goIni(r.ini); return; } pop(r); ctx.select(r.key); if (ref.kind === 'session') chatPop(); return; }
|
|
137
|
+
if (r.src === 'move') { if (ref.kind === 'task' && r.ini && ctx.hasIni(r.ini)) { ctx.goIni(r.ini, { task: (ref.task && ref.task.uid) || null }); return; } pop(r); ctx.select(r.key); if (ref.kind === 'session') chatPop(); return; }
|
|
86
138
|
if (r.src === 'item') { if (r.ini && ctx.hasIni(r.ini)) { ctx.goIni(r.ini); return; } pop(r); import('./home-work.js').then((M) => M.openWorkItem(ref.key)).catch(() => {}); return; }
|
|
87
139
|
if (r.src === 'draft') { pop(r); ctx.openFinished(ref.fin); return; }
|
|
88
140
|
if (r.src === 'review') { pop(r); ctx.openReviewVw(); return; }
|
|
@@ -172,6 +224,36 @@ export function mountToday(ctx) {
|
|
|
172
224
|
if (undo) ctx.toastUndo(said, undo); else ctx.toast(said);
|
|
173
225
|
return after(true);
|
|
174
226
|
}
|
|
227
|
+
/** ✦ Looks answered on an ask: ✓ closes it (answered, with Undo), ✕ keeps it waiting and PMOS does not ask again until the thread moves. */
|
|
228
|
+
async function looks(r, yes) {
|
|
229
|
+
const ids = (r.keys || [r.key]).filter((k) => /^mn:/.test(k)).map((k) => k.slice(3));
|
|
230
|
+
let ok = 0; for (const id of ids) { const m = await ctx.mentionAct(id, yes ? 'answered' : 'keep').catch(() => null); if (m && m.ok) ok++; }
|
|
231
|
+
if (!ok) return ctx.toast('It did not go through. Nothing changed.');
|
|
232
|
+
await ctx.reloadMentions();
|
|
233
|
+
if (!yes) return ctx.toast('Kept waiting. PMOS will not ask again unless the thread moves.');
|
|
234
|
+
ctx.toastUndo('Closed: ' + r.title + '.', async () => { let u = { ok: true }; for (const id of ids) u = await ctx.mentionAct(id, 'undo').catch(() => ({ ok: false })); await ctx.reloadMentions(); return u; });
|
|
235
|
+
}
|
|
236
|
+
/** The self check closed an ask he had answered already (his reply, a closed ticket, the ask taken back): it left Today by itself; the
|
|
237
|
+
* toast says how, once, with Undo (round 3 point 10c). The asks Today showed as waiting are kept on this computer to tell which left. */
|
|
238
|
+
/** PMOS handled · N: the asks the self check cleared today (design check of round 3, point 6). */
|
|
239
|
+
function handled() {
|
|
240
|
+
const M = ctx.mentions ? ctx.mentions() : null; if (!M || !M.loaded || M.failed) return [];
|
|
241
|
+
let c = null; try { c = JSON.parse(localStorage.getItem('pmos.today.cleared') || 'null'); } catch { c = null; }
|
|
242
|
+
return TM.handledModel(M.answered, { today: day(), now: ctx.now(), cleared: c && c.day === day() ? c.ids : [] });
|
|
243
|
+
}
|
|
244
|
+
function autoClosed() {
|
|
245
|
+
const L = ctx.mentions ? ctx.mentions() : null; if (!L || !L.loaded || L.failed) return;
|
|
246
|
+
let was = null; try { was = JSON.parse(localStorage.getItem('pmos.today.waits') || 'null'); } catch { was = null; }
|
|
247
|
+
try { localStorage.setItem('pmos.today.waits', JSON.stringify(L.waiting.map((m) => m.id))); } catch { /* a private window */ }
|
|
248
|
+
if (!Array.isArray(was)) return;
|
|
249
|
+
const gone = L.answered.filter((m) => m.auto && m.proof && was.includes(m.id)); if (!gone.length) return;
|
|
250
|
+
try { const c = JSON.parse(localStorage.getItem('pmos.today.cleared') || 'null'); const ids = c && c.day === day() ? c.ids : [];
|
|
251
|
+
localStorage.setItem('pmos.today.cleared', JSON.stringify({ day: day(), ids: [...new Set([...ids, ...gone.map((m) => m.id)])] })); } catch { /* a private window */ }
|
|
252
|
+
const nm = (m) => String((m.people && m.people[0]) || m.who || 'Someone').trim().split(/\s+/)[0];
|
|
253
|
+
const said = gone.length === 1 ? 'Answered already, so it left Today: ' + nm(gone[0]) + '. ' + OM.proofText(gone[0].proof, ctx.now()) + '.'
|
|
254
|
+
: gone.length + ' asks were answered already, so they left Today: ' + gone.map(nm).join(', ') + '.';
|
|
255
|
+
ctx.toastUndo(said, async () => { let u = { ok: true }; for (const m of gone) u = await ctx.mentionAct(m.id, 'reopen').catch(() => ({ ok: false })); await ctx.reloadMentions(); return u; });
|
|
256
|
+
}
|
|
175
257
|
/** The date chooser beside a row: one date field; Enter or a change sets it, Escape or a press outside closes it. */
|
|
176
258
|
function chooseDate(r, btn) {
|
|
177
259
|
document.querySelectorAll('.td-dp').forEach((x) => x.remove());
|
|
@@ -193,12 +275,36 @@ export function mountToday(ctx) {
|
|
|
193
275
|
try { i.showPicker(); } catch { /* the field itself is the chooser */ }
|
|
194
276
|
}
|
|
195
277
|
|
|
278
|
+
// j k with any Today row's item open in the popup: the next or previous row opens in its place (↑ ↓ too in the one-mention popup)
|
|
279
|
+
document.addEventListener('keydown', (e) => {
|
|
280
|
+
if (!on() || !X.last || e.metaKey || e.ctrlKey || e.altKey || (e.key !== 'j' && e.key !== 'k')) return;
|
|
281
|
+
if (!(ctx.VW.popOpen && ctx.VW.popOpen()) || (e.target && e.target.closest && e.target.closest('input,textarea,select,[contenteditable],.cz-pop-chat,[role="textbox"]'))) return;
|
|
282
|
+
if (step(e.key === 'j' ? 1 : -1)) e.preventDefault();
|
|
283
|
+
});
|
|
196
284
|
if (el) {
|
|
197
285
|
el.addEventListener('click', async (e) => {
|
|
198
286
|
const b = e.target.closest('[data-td]'); if (!b || b.disabled) return;
|
|
199
287
|
const act = b.dataset.td, key = b.dataset.key || '';
|
|
200
288
|
if (act === 'cal') { ctx.openCalendar(); return; }
|
|
201
|
-
if (act === '
|
|
289
|
+
if (act === 'fold') { X.open = !X.open; draw(); return; }
|
|
290
|
+
if (act === 'hfold') { X.hopen = !X.hopen; draw(); return; }
|
|
291
|
+
if (act === 'h-undo') {
|
|
292
|
+
b.disabled = true; const m = await ctx.mentionAct(key, 'reopen').catch(() => null);
|
|
293
|
+
if (!m || !m.ok) { b.disabled = false; return ctx.toast('It did not go through. Nothing changed.'); }
|
|
294
|
+
await ctx.reloadMentions(); ctx.toast('Back on Today: it still waits on you.'); return;
|
|
295
|
+
}
|
|
296
|
+
if (act === 'type') { X.type = X.type === key ? '' : key; draw(); return; }
|
|
297
|
+
if (act === 'ov-yes' || act === 'ov-no') {
|
|
298
|
+
const sg = X.overview && X.overview.suggest.find((x) => x.key === key); if (!sg || X.busy.has(key)) return;
|
|
299
|
+
X.busy.add(key); b.disabled = true;
|
|
300
|
+
try {
|
|
301
|
+
if (act === 'ov-no') { for (const k of sg.keys) await mark1(k, 'keep', {}); X.hide.add(key); ctx.toast('Kept. PMOS will not suggest it again for a month.'); return after(false); }
|
|
302
|
+
const done = []; for (const k of sg.keys) { const m = await mark1(k, 'drop', {}); if (m.ok) done.push(k); }
|
|
303
|
+
if (!done.length) return ctx.toast('Nothing was dropped. Nothing changed.');
|
|
304
|
+
ctx.toastUndo('Dropped ' + done.length + (done.length === 1 ? ' line' : ' lines') + ' from your log.', async () => { let u = { ok: true }; for (const k of done) u = await mark1(k, 'undrop', {}); after(false); return u; });
|
|
305
|
+
return after(false);
|
|
306
|
+
} finally { X.busy.delete(key); if (b.isConnected) b.disabled = false; }
|
|
307
|
+
}
|
|
202
308
|
if (act === 'ev') {
|
|
203
309
|
const x = X.agenda && X.agenda.items.find((y) => y.key === key); if (!x) return;
|
|
204
310
|
if (x.ini && ctx.hasIni(x.ini)) { ctx.goIni(x.ini); return; }
|
|
@@ -215,6 +321,7 @@ export function mountToday(ctx) {
|
|
|
215
321
|
else if (act === 'drop') await drop(r);
|
|
216
322
|
else if (act === 'keep') await keep(r);
|
|
217
323
|
else if (act === 'lab-keep' || act === 'lab-drop') await lab(r, act === 'lab-keep');
|
|
324
|
+
else if (act === 'lk-yes' || act === 'lk-no') await looks(r, act === 'lk-yes');
|
|
218
325
|
} finally { X.busy.delete(key); if (b.isConnected) b.disabled = false; }
|
|
219
326
|
});
|
|
220
327
|
// the first line: Enter adds the row, and nothing else happens (no popup, no session)
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
*
|
|
5
5
|
* The job of Today: show the few things only the PM can move today, and let them finish or move each one here, so nothing is left hanging.
|
|
6
6
|
*
|
|
7
|
-
* logModel(o) → { rows, done, counts, line } Today's log, kept the Bullet Journal way
|
|
7
|
+
* logModel(o) → { rows, first, todayRows, wait, done, counts, types, merged, line } Today's log, kept the Bullet Journal way, in
|
|
8
|
+
* three groups (Do first, Today, Can wait; groupLog) with a Type for each line
|
|
9
|
+
* overviewModel(L, A) → { said, suggest, chips } the Overview on top: where to start and why, PMOS's suggestions, the type chips
|
|
8
10
|
* agendaModel(o) → { items, from, to, now, sub, empty } today's agenda, one column of hours
|
|
11
|
+
* headModel(now) → { when, hello } the page head
|
|
9
12
|
* dayKey(ms) · addDays(day, n) · whenWord(...)
|
|
10
13
|
*
|
|
11
14
|
* WHERE THE ROWS COME FROM. Nothing here is invented: every row is a record PMOS already reads, or a line the PM typed.
|
|
@@ -25,6 +28,7 @@
|
|
|
25
28
|
* more, PMOS suggests to drop it (one ✦ line under the row, ✓ ✕), unless the PM kept it in the last CARRY_DROP days.
|
|
26
29
|
* FIRST ("!"). What the PM marked first, a verdict or a grill finding on shipped or late work (move-rank's ranks 1 and 2), and a send that
|
|
27
30
|
* goes out today. The rest follow in the rank's order. Done rows close the table. */
|
|
31
|
+
import { didLeft, notASentence, asWritten, askTitle, proofText } from './mention-one-model.js'; // what PMOS did on an ask, from records (round 3 point 13); the title when no sentence can be made
|
|
28
32
|
|
|
29
33
|
export const CARRY_DROP = 30; // days carried before PMOS suggests to drop it
|
|
30
34
|
export const LATE_DAYS = 14; // a row carried this long reads late (the one colour in the When column)
|
|
@@ -44,18 +48,91 @@ const between = (a, b) => { const x = dayMs(a), y = dayMs(b); return x == null |
|
|
|
44
48
|
/** "2 Nov", or "2 Nov 2025" outside this year. */
|
|
45
49
|
const dm = (k, today) => { const m = DAY_RE.exec(String(k || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] + (m[1] !== String(today).slice(0, 4) ? ' ' + m[1] : '') : ''; };
|
|
46
50
|
|
|
47
|
-
/** The words of the When column
|
|
51
|
+
/** The words of the When column: a date or a time only, else nothing (the why is said once, in the line under the title; design check of
|
|
52
|
+
* round 3). o: { late (days late of a dated task), due, carried (days), time, send } */
|
|
48
53
|
export function whenWord(o, today) {
|
|
49
54
|
if (o.time) return o.time;
|
|
50
|
-
if (o.late > 0) return dm(o.due, today)
|
|
51
|
-
if (o.carried > 0) return 'carried ' + plural(o.carried, 'day', 'days');
|
|
55
|
+
if (o.late > 0) return dm(o.due, today);
|
|
52
56
|
if (o.send) return o.send;
|
|
53
|
-
if (o.due && o.due === today) return 'today';
|
|
54
57
|
return '';
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
const SEND_KINDS = new Set(['outbox'
|
|
58
|
-
|
|
60
|
+
const SEND_KINDS = new Set(['outbox']);
|
|
61
|
+
// a call the PM makes up their mind on is Decide; a thing the PM does (draft, write, award, run) is Do
|
|
62
|
+
const DECIDE_RE = /^(decide|confirm|choose|pick|approve|accept|sign|agree|review|keep|did\b)/i;
|
|
63
|
+
const jobOfAsk = (r) => (r.kind === 'call' ? (r.call && r.call.kind === 'update' ? 'Send' : DECIDE_RE.test(String((r.call && r.call.name) || r.title || '')) ? 'Decide' : 'Do')
|
|
64
|
+
: r.kind === 'mention' ? 'Reply' : SEND_KINDS.has(r.kind) ? 'Send' : r.kind === 'kr' || r.kind === 'extra' ? 'Do' : 'Decide');
|
|
65
|
+
const cap1 = (s) => String(s || '').replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
66
|
+
/** An ask's What and Work, split as the board says them: the rank names a row "<work>: <what>" (a verdict, a grill finding, a meeting's or a
|
|
67
|
+
* program's milestone changes, the changes to keep); What is the thing to do, Work the initiative or program it is about. */
|
|
68
|
+
export function splitAsk(r, workName) {
|
|
69
|
+
const t = String(r.title || '');
|
|
70
|
+
if (r.kind === 'call') { const n = String((r.call && r.call.name) || t); return { what: /^draft\b/i.test(n) && !/let PMOS/i.test(n) ? n + ', or let PMOS draft it' : n, work: '' }; }
|
|
71
|
+
if (r.kind === 'verdict') {
|
|
72
|
+
const m = /^(.*): did it work\?/.exec(t);
|
|
73
|
+
if (!m) return { what: t, work: workName || '' };
|
|
74
|
+
// "Did the Okta migration work?"; a name that starts with its article keeps it once; a name that reads as a step is quoted
|
|
75
|
+
const n = m[1].trim(), art = /^(the|a|an)\s/i.test(n), step = /^\S+\s+(the|a|an|to|my|our|your)\s/i.test(n);
|
|
76
|
+
return { what: art ? 'Did ' + n.replace(/^\S+/, (w) => w.toLowerCase()) + ' work?' : step ? 'Did “' + n + '” work?' : 'Did the ' + n + ' work?', work: workName || '' };
|
|
77
|
+
}
|
|
78
|
+
if (!['grill', 'other', 'meeting'].includes(r.kind)) return { what: t, work: '' };
|
|
79
|
+
const i = t.indexOf(': ');
|
|
80
|
+
if (i < 1) return { what: t, work: '' };
|
|
81
|
+
const w = t.slice(0, i); let what = t.slice(i + 2);
|
|
82
|
+
let m;
|
|
83
|
+
if ((m = /^(.+) to confirm$/.exec(what))) what = 'Confirm ' + m[1];
|
|
84
|
+
else if ((m = /^(.+) to keep$/.exec(what))) what = 'Keep ' + m[1];
|
|
85
|
+
else if ((m = /^(.+) from your meetings$/.exec(what))) what = 'Confirm ' + m[1] + ' from your meetings';
|
|
86
|
+
return { what: cap1(what), work: w };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ── an ask from a person: who, then the ask (round 2 of Today, Wawan on his real data) ── */
|
|
90
|
+
const NOBODY = /^(someone|somebody|unknown|anyone|they|pm|me)$/i;
|
|
91
|
+
/** The first names of who asked: "Suhas,", "Someone" and the like are cleaned or left out. */
|
|
92
|
+
export function whoOf(m) {
|
|
93
|
+
const raw = Array.isArray(m && m.people) && m.people.length ? m.people : [(m && m.who) || ''];
|
|
94
|
+
const out = [];
|
|
95
|
+
for (const x of raw) { const n = String(x || '').trim().split(/\s+/)[0].replace(/[^\p{L}\p{N}'’-]+$/u, '').replace(/^[^\p{L}\p{N}]+/u, ''); if (n && !NOBODY.test(n) && !out.includes(n)) out.push(n); }
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
const names = (L) => (L.length <= 2 ? L.join(' and ') : L[0] + ' and ' + (L.length - 1) + ' others');
|
|
99
|
+
/** The ask in sentence case, said once: "asks asks" is one "asks", a stray "Someone:" goes. */
|
|
100
|
+
export function askText(m) {
|
|
101
|
+
// the ask itself first (round 3: a gist that describes the ask is the popup's sentence, not the row's title)
|
|
102
|
+
let t = String((m && ((m.ask ? 'asks ' + String(m.ask).replace(/^[A-Z](?=[a-z])/, (c) => c.toLowerCase()) : '') || m.gist || (m.text ? '“' + m.text + '”' : ''))) || '').replace(/\s+/g, ' ').trim();
|
|
103
|
+
t = t.replace(/^(?:[\p{L}'’-]+[\s,]*[:,][\s,:]*)?(?=asks\b)/iu, '').replace(/\b(asks?)(\s+\1\b)+/gi, '$1').replace(/^(someone|somebody)\s+/i, '').replace(/[.?!]+$/, '')
|
|
104
|
+
.replace(/^asks?\s+(?=\S)/i, ''); // the Type column says Ask: the title starts with the ask itself
|
|
105
|
+
if (notASentence(t)) return asWritten(m); // no clean sentence: the first words as written (design check of round 3)
|
|
106
|
+
return cap1(t);
|
|
107
|
+
}
|
|
108
|
+
const askWords = (t) => String(t || '').toLowerCase().replace(/^asks?\s+/, '').replace(/[^\p{L}\p{N}\s]+/gu, ' ').split(/\s+/).filter((w) => w.length > 2 && !/^(the|and|for|you|your|asks?|whether|does|can|what|when|with|that|this|from|pm)$/.test(w));
|
|
109
|
+
/** Two asks say the same thing: the same words, or most of them (at least four words, 80% shared). */
|
|
110
|
+
export function sameAsk(a, b) {
|
|
111
|
+
const x = askWords(a), y = askWords(b);
|
|
112
|
+
if (!x.length || !y.length) return false;
|
|
113
|
+
if (x.join(' ') === y.join(' ')) return true;
|
|
114
|
+
if (x.length < 4 || y.length < 4) return false;
|
|
115
|
+
const A = new Set(x), B = new Set(y); let n = 0; for (const w of A) if (B.has(w)) n++;
|
|
116
|
+
return n / Math.max(A.size, B.size) >= 0.8;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* ── the type of a line: one word and a small sign in the Type column; the chips of the Overview count them ── */
|
|
120
|
+
export const TYPES = ['Ask', 'Decision', 'Check', 'Milestone', 'Task', 'Report', 'Note'];
|
|
121
|
+
function typeOf(r) {
|
|
122
|
+
const ref = r.ref || {};
|
|
123
|
+
if (r.bullet === 'note' || r.src === 'note') return 'Note';
|
|
124
|
+
if (r.src === 'draft') return 'Report';
|
|
125
|
+
if (r.src === 'lab') return 'Decision';
|
|
126
|
+
if (r.src !== 'ask') return 'Task';
|
|
127
|
+
switch (ref.kind) {
|
|
128
|
+
case 'mention': return 'Ask';
|
|
129
|
+
case 'verdict': return 'Check';
|
|
130
|
+
case 'meeting': return ref.ms ? 'Milestone' : 'Decision';
|
|
131
|
+
case 'grill': case 'other': case 'owner': return 'Decision';
|
|
132
|
+
case 'call': return ref.call && ref.call.kind === 'update' ? 'Report' : r.job === 'Decide' ? 'Decision' : 'Task';
|
|
133
|
+
default: return r.job === 'Decide' ? 'Decision' : 'Task';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
59
136
|
|
|
60
137
|
/**
|
|
61
138
|
* o: { rank: { rows, wait } (rankMove), move: home-list move rows, items: my-work-premium Today rows ({ key, id, title, ini, at, due?, overdue }),
|
|
@@ -66,7 +143,7 @@ const jobOfAsk = (r) => (r.kind === 'call' ? (r.call && r.call.kind === 'update'
|
|
|
66
143
|
export function logModel(o = {}) {
|
|
67
144
|
const now = o.now || Date.now(), today = dayKey(now);
|
|
68
145
|
const marks = o.marks || {}, titleOf = typeof o.titleOf === 'function' ? o.titleOf : () => '';
|
|
69
|
-
const out = [], seen = new Set();
|
|
146
|
+
const out = [], seen = new Set(), old = [];
|
|
70
147
|
const work = (ini, fallback) => (ini ? titleOf(ini) || fallback || '' : fallback || '');
|
|
71
148
|
const put = (r) => {
|
|
72
149
|
if (!r.key || seen.has(r.key)) return;
|
|
@@ -75,8 +152,11 @@ export function logModel(o = {}) {
|
|
|
75
152
|
if (m.dropped) return;
|
|
76
153
|
if (m.until && m.until > today) return;
|
|
77
154
|
const done = !!m.done || !!r.done;
|
|
78
|
-
const
|
|
79
|
-
|
|
155
|
+
const kept = !!(m.kept && between(m.kept, today) < CARRY_DROP);
|
|
156
|
+
const drop = !done && r.carried >= CARRY_DROP && !kept && r.src !== 'lab';
|
|
157
|
+
const row = { first: false, bullet: 'task', work: '', ini: null, ws: '', job: '', when: '', late: false, carried: 0, dates: 'mark', keys: [r.key], ...r, done, drop, kept };
|
|
158
|
+
if (!row.type) row.type = typeOf(row);
|
|
159
|
+
out.push(row);
|
|
80
160
|
};
|
|
81
161
|
// the asks, in the rank's order: the first five, then Can wait
|
|
82
162
|
const rank = o.rank || {};
|
|
@@ -87,9 +167,26 @@ export function logModel(o = {}) {
|
|
|
87
167
|
const c = r.kind === 'call' ? r.call || {} : null;
|
|
88
168
|
if (c) callIds.add(c.id);
|
|
89
169
|
const carried = c ? 0 : Math.max(0, r.days || 0);
|
|
90
|
-
const send = c && c.when ?
|
|
91
|
-
|
|
92
|
-
|
|
170
|
+
const send = c && c.when ? c.when : '';
|
|
171
|
+
const sp = splitAsk(r, r.ini ? titleOf(r.ini) : '');
|
|
172
|
+
if (r.kind === 'mention') {
|
|
173
|
+
const m = r.mention || {}, who = whoOf(m), ask = askText(m) || String(r.title || '');
|
|
174
|
+
const twin = out.find((x) => x.type === 'Ask' && !x.done && sameAsk(x.ask, ask));
|
|
175
|
+
if (twin) { // the same ask once: the people together, the oldest wait, every key behind it (a mark goes to each)
|
|
176
|
+
for (const n of who) if (!twin.who.includes(n)) twin.who.push(n);
|
|
177
|
+
twin.title = (twin.who.length ? names(twin.who) + ': ' : '') + twin.ask;
|
|
178
|
+
if (carried > twin.carried) { twin.carried = carried; twin.late = carried >= LATE_DAYS; twin.when = whenWord({ carried }, today); }
|
|
179
|
+
if (!seen.has(r.key)) { seen.add(r.key); twin.keys.push(r.key); twin.merged = (twin.merged || 1) + 1; }
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
// Work: the record that links the mention to its work, its initiative or the task made from it (design check of round 3, point 4)
|
|
183
|
+
put({ key: r.key, keys: [r.key], src: 'ask', bullet: 'task', title: (who.length ? names(who) + ': ' : /^“/.test(ask) ? 'Someone: ' : '') + ask, who, ask, type: 'Ask', ini: r.ini || m.initiative || (m.task && m.task.initiative) || null, ws: r.ws || '',
|
|
184
|
+
work: work(r.ini || m.initiative || (m.task && m.task.initiative), (r.shared || [])[0] || ''), job: 'Reply', carried, late: carried >= LATE_DAYS, when: whenWord({ carried }, today), ref: r,
|
|
185
|
+
did: didLeft(m).did, ...(m.looks ? { looks: { who: String(m.looks.who || '').trim().split(/\s+/)[0], text: m.looks.text } } : {}) });
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
put({ key: c ? 'call:' + c.id : r.key, src: 'ask', bullet: 'task', title: sp.what || r.title || (c && c.name) || '', ini: r.ini || (c && c.ini) || null, ws: r.ws || '',
|
|
189
|
+
work: work(r.ini || (c && c.ini), c ? c.sub : (r.shared || [])[0] || '') || sp.work, job: jobOfAsk(r), carried, late: carried >= LATE_DAYS,
|
|
93
190
|
when: whenWord({ carried, send }, today), first: r.rank <= 2 || (c && c.kind === 'update' && /^(today|now)/i.test(String(c.when || ''))) || false, ref: r });
|
|
94
191
|
}
|
|
95
192
|
// the rest of Your move: the PM's own late tasks and the next steps (a call is in the asks already; an item is in the items)
|
|
@@ -97,6 +194,8 @@ export function logModel(o = {}) {
|
|
|
97
194
|
if (!r || !r.id || callIds.has(r.id) || r.call || r.kind === 'item' || r.kind === 'update' || r.kind === 'session') continue;
|
|
98
195
|
const due = r.due || (r.task && r.task.end) || '';
|
|
99
196
|
const late = r.kind === 'task' && due && due < today ? between(due, today) : 0;
|
|
197
|
+
// a task whose date passed long ago and nobody touched (an old import) is not a Today row: one ✦ line in the Overview (round 3 point 12)
|
|
198
|
+
if (late > OLD_TASK_DAYS) { const m = marks[r.id] || {}; if (!m.dropped && !(m.kept && between(m.kept, today) < CARRY_DROP)) old.push(r.id); if (!(m.kept && between(m.kept, today) < CARRY_DROP)) continue; }
|
|
100
199
|
put({ key: r.id, src: 'move', bullet: 'task', title: r.name, ini: r.ini || null, work: work(r.ini, r.sub), job: 'Do', late: late > 0, carried: late,
|
|
101
200
|
when: whenWord({ late, due }, today), dates: r.kind === 'task' ? 'task' : 'mark', ref: r });
|
|
102
201
|
}
|
|
@@ -108,7 +207,7 @@ export function logModel(o = {}) {
|
|
|
108
207
|
put({ key: 'work:' + it.id, src: 'item', bullet: 'task', title: it.title, ini: it.ini || null, work: work(it.ini, ''), job: 'Do', carried, late: !!it.overdue || carried >= LATE_DAYS,
|
|
109
208
|
when: whenWord({ carried, due: it.due }, today), dates: 'item', ref: it });
|
|
110
209
|
}
|
|
111
|
-
for (const d of o.drafts || []) if (d && d.id) put({ key: 'draft:' + d.id, src: 'draft', bullet: 'task', title: d.title, ini: d.ini || null, work: work(d.ini, ''), job: 'Send', ref: d });
|
|
210
|
+
for (const d of o.drafts || []) if (d && d.id) put({ key: 'draft:' + d.id, src: 'draft', bullet: 'task', title: d.title, ini: d.ini || null, work: work(d.ini, ''), job: 'Send', did: ['finished the draft'], ref: d });
|
|
112
211
|
if (o.review && o.review.title) put({ key: 'review:' + today, src: 'review', bullet: 'task', title: o.review.title, job: 'Do', ref: o.review });
|
|
113
212
|
// what the PM typed: a task, an event or a note, carried from the day it was written until it is done
|
|
114
213
|
for (const e of o.own || []) {
|
|
@@ -122,15 +221,128 @@ export function logModel(o = {}) {
|
|
|
122
221
|
for (const [k, m] of Object.entries(marks)) {
|
|
123
222
|
if (!m || !m.done || seen.has(k) || !m.snap) continue;
|
|
124
223
|
seen.add(k);
|
|
125
|
-
out.push({ key: k, src: 'gone', bullet: 'task', first: false, title: m.snap.title || '', work: m.snap.work || '', ini: null, ws: '', job: m.snap.job || '', when: '', late: false, carried: 0, done: true, drop: false, dates: 'mark', ref: null });
|
|
224
|
+
out.push({ key: k, keys: [k], src: 'gone', bullet: 'task', type: m.snap.type || 'Task', first: false, title: m.snap.title || '', work: m.snap.work || '', ini: null, ws: '', job: m.snap.job || '', when: '', late: false, carried: 0, done: true, drop: false, dates: 'mark', ref: null });
|
|
126
225
|
}
|
|
226
|
+
// PMOS's own note at the foot: the ✦ that expired after 14 days with no answer (move-rank's expired), said once, with no action
|
|
227
|
+
const ex = (rank.expired || []).length;
|
|
228
|
+
if (ex) out.push({ key: 'expired:' + today, keys: ['expired:' + today], src: 'note', bullet: 'note', type: 'Note', first: false, title: plural(ex, 'ask', 'asks') + ' expired after 14 days with no answer. PMOS wrote why in History',
|
|
229
|
+
work: '', ini: null, ws: '', job: 'Note', when: '', late: false, carried: 0, done: false, drop: false, dates: 'mark', ref: null });
|
|
127
230
|
const open = out.filter((r) => !r.done), done = out.filter((r) => r.done);
|
|
128
|
-
const rows = open.filter((r) => r.first).concat(open.filter((r) => !r.first));
|
|
129
231
|
const n = (j) => open.filter((r) => r.job === j).length;
|
|
130
|
-
const counts = { decide: n('Decide'), do: n('Do'), send: n('Send'), notes: open.filter((r) => r.bullet === 'note').length, events: open.filter((r) => r.bullet === 'event').length };
|
|
232
|
+
const counts = { decide: n('Decide'), do: n('Do'), reply: n('Reply'), send: n('Send'), notes: open.filter((r) => r.bullet === 'note').length, events: open.filter((r) => r.bullet === 'event').length };
|
|
131
233
|
// one quiet line counts the log; a part that is zero is left out
|
|
132
|
-
const line = [counts.decide && counts.decide + ' to decide', counts.do && counts.do + ' to do', counts.send && counts.send + ' to send'].filter(Boolean).join(' · ');
|
|
133
|
-
|
|
234
|
+
const line = [counts.decide && counts.decide + ' to decide', counts.do && counts.do + ' to do', counts.reply && counts.reply + ' to reply', counts.send && counts.send + ' to send'].filter(Boolean).join(' · ');
|
|
235
|
+
const types = {}; for (const r of open) types[r.type] = (types[r.type] || 0) + 1;
|
|
236
|
+
const G = groupLog(open, today);
|
|
237
|
+
// every row says why it is on Today, in a short phrase after its title (round 3 point 12); Do first keeps the reason that ranked it
|
|
238
|
+
for (const r of open) if (!r.reason) { const w = whyOf(r, today); if (w) r.reason = w; }
|
|
239
|
+
for (const r of G.first) r.group = 'first'; for (const r of G.today) r.group = 'today'; for (const r of G.wait) r.group = 'wait';
|
|
240
|
+
for (const r of done) r.group = 'today';
|
|
241
|
+
const merged = open.reduce((k, r) => k + (r.merged ? r.merged - 1 : 0), 0);
|
|
242
|
+
return { rows: G.first.concat(G.today, done, G.wait), first: G.first, todayRows: G.today.concat(done), wait: G.wait, open: open.length, done: done.length, counts, types, merged, line, today, old };
|
|
243
|
+
}
|
|
244
|
+
/** PMOS HANDLED (design check of round 3, point 6): the asks the self check cleared today from proof (his reply, a closed ticket, the ask
|
|
245
|
+
* taken back), as the folded last group, each with Undo. answered: the Mentions answered list; o: { today, now, cleared: ids PMOS saw
|
|
246
|
+
* leave Today today }. A row: { id, title, proof }. An ask whose proof is from today, or that PMOS saw leave today, is one of them. */
|
|
247
|
+
export function handledModel(answered, o = {}) {
|
|
248
|
+
const today = o.today || dayKey(o.now || Date.now()), cleared = new Set(o.cleared || []);
|
|
249
|
+
return (answered || []).filter((m) => m && m.auto && m.proof && (cleared.has(m.id) || dayKey(Date.parse(m.proof.at || '') || 0) === today))
|
|
250
|
+
.map((m) => { const who = (Array.isArray(m.people) && m.people.length ? m.people : [m.who || '']).map((x) => String(x).trim().split(/\s+/)[0]).filter(Boolean);
|
|
251
|
+
return { id: m.id, title: (who.length ? names(who) + ': ' : '') + askTitle(m), proof: proofText(m.proof, o.now) }; });
|
|
252
|
+
}
|
|
253
|
+
/** A task late more than this many days is an old import, not a Today row (round 3 point 12). */
|
|
254
|
+
export const OLD_TASK_DAYS = 30;
|
|
255
|
+
const addDay = (d, n) => { const t = new Date(d + 'T12:00:00'); t.setDate(t.getDate() + n); return dayKey(t.getTime()); };
|
|
256
|
+
/** Why a row is on Today, as a short phrase (round 3 point 12): Due today, 3 days late, Waits on you 13 days, You said today, … '' when
|
|
257
|
+
* nothing says why. */
|
|
258
|
+
export function whyOf(r, today) {
|
|
259
|
+
const ref = r.ref || {}, c = ref.call || null;
|
|
260
|
+
if (r.src === 'own') return r.bullet === 'note' ? '' : r.carried ? 'You said it ' + plural(r.carried, 'day', 'days') + ' ago' : 'You said today';
|
|
261
|
+
if (r.src === 'move' || r.src === 'item') {
|
|
262
|
+
const due = ref.due || (ref.task && ref.task.end) || '';
|
|
263
|
+
if (due && due < today) return plural(between(due, today), 'day', 'days') + ' late';
|
|
264
|
+
if (due === today) return r.ref && (r.ref.ms || (r.ref.task && r.ref.task.milestone)) ? 'Milestone today' : 'Due today';
|
|
265
|
+
if (due && due === addDay(today, 1)) return 'Due tomorrow';
|
|
266
|
+
if (r.src === 'item') return r.carried ? 'You put it on today ' + plural(r.carried, 'day', 'days') + ' ago' : 'You put it on today';
|
|
267
|
+
return '';
|
|
268
|
+
}
|
|
269
|
+
if (r.type === 'Ask') return r.carried ? (r.who && r.who.length ? names(r.who) + ' ' + (r.who.length > 1 ? 'wait' : 'waits') + ' on you ' : 'Waits on you ') + plural(r.carried, 'day', 'days') : 'Asked today';
|
|
270
|
+
if (r.src === 'draft') return 'PMOS finished it, needs your look';
|
|
271
|
+
if (r.src === 'review') return 'Your weekly review is open';
|
|
272
|
+
if (r.src === 'lab') return 'PMOS found it, keep or drop';
|
|
273
|
+
if (c) {
|
|
274
|
+
if (c.kind === 'update') return c.when ? 'Goes out ' + c.when : 'Ready to send';
|
|
275
|
+
if (c.kind === 'session' && (c.state === 'blocked' || c.state === 'needs')) return 'A session waits on you';
|
|
276
|
+
return r.job === 'Decide' ? 'Decision needed' : 'Waits on you';
|
|
277
|
+
}
|
|
278
|
+
if (r.type === 'Check') return r.carried ? 'Check due ' + plural(r.carried, 'day', 'days') + ' ago' : 'Check due today';
|
|
279
|
+
if (r.type === 'Milestone') return 'Milestone changes to confirm';
|
|
280
|
+
if (r.type === 'Decision') return 'Decision needed';
|
|
281
|
+
return '';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/* ── where to start: the three groups of the log (round 2 of Today) ──
|
|
285
|
+
* DO FIRST, five lines at most, each with the reason PMOS picked it, read from the line itself (never guessed):
|
|
286
|
+
* 1 the PM marked it first · 2 a date that is late · 3 a date that is today, or a send that goes out today · 4 a session that waits on the PM
|
|
287
|
+
* (its work is blocked) · 5 the person who waits longest (an ask, a day or more).
|
|
288
|
+
* A line PMOS suggests to drop, a note and a Lab finding are never in it.
|
|
289
|
+
* TODAY: the rest that is new today (carried 0 days: dated today, logged today, filed today), then what was done today.
|
|
290
|
+
* CAN WAIT: the rest, by type (the order of TYPES) and then the oldest first; folded to one line. */
|
|
291
|
+
export const FIRST_CAP = 5;
|
|
292
|
+
function reasonOf(r, today) {
|
|
293
|
+
const ref = r.ref || {}, c = ref.call || null;
|
|
294
|
+
if (r.first && r.src === 'own') return [1, 0, 'You marked it first'];
|
|
295
|
+
if (r.dates !== 'mark' && r.late && r.carried > 0) return [2, r.carried, plural(r.carried, 'day', 'days') + ' late'];
|
|
296
|
+
const due = ref.due || (ref.task && ref.task.end) || '';
|
|
297
|
+
if (due && due === today) return [3, 0, 'Due today'];
|
|
298
|
+
if (c && c.kind === 'update' && /^(today|now)/i.test(String(c.when || ''))) return [3, 0, 'Goes out ' + c.when];
|
|
299
|
+
if (c && (c.state === 'blocked' || c.state === 'needs') && c.kind === 'session') return [4, 0, 'A session waits on you; its work stops until you answer'];
|
|
300
|
+
if (r.type === 'Ask' && r.carried >= 1) return [5, r.carried, (r.who && r.who.length ? names(r.who) : 'They') + ' ' + (r.who && r.who.length > 1 ? 'wait' : 'waits') + ' on you ' + plural(r.carried, 'day', 'days')];
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
export function groupLog(open, today) {
|
|
304
|
+
const cand = [];
|
|
305
|
+
for (const r of open) {
|
|
306
|
+
// an ask that looks answered (someone else may have answered it, round 3 point 10d) is not first and not today: it waits for his ✓ ✕
|
|
307
|
+
if (r.drop || r.looks || r.bullet === 'note' || r.src === 'lab' || r.src === 'note' || (r.type === 'Ask' && !(r.who && r.who.length))) continue;
|
|
308
|
+
const w = reasonOf(r, today); if (w) cand.push({ r, k: w[0], d: w[1], why: w[2] });
|
|
309
|
+
}
|
|
310
|
+
cand.sort((a, b) => a.k - b.k || b.d - a.d);
|
|
311
|
+
const first = cand.slice(0, FIRST_CAP).map((x) => { x.r.reason = x.why; return x.r; });
|
|
312
|
+
const inFirst = new Set(first);
|
|
313
|
+
const rest = open.filter((r) => !inFirst.has(r));
|
|
314
|
+
// an ask with no person behind it can wait: nobody waits on the answer
|
|
315
|
+
const todayRows = rest.filter((r) => !r.drop && !r.looks && r.bullet !== 'note' && r.src !== 'note' && (r.carried || 0) === 0 && !r.late && !(r.type === 'Ask' && !(r.who && r.who.length)));
|
|
316
|
+
const inToday = new Set(todayRows);
|
|
317
|
+
const order = (t) => { const i = TYPES.indexOf(t); return i < 0 ? TYPES.length : i; };
|
|
318
|
+
const wait = rest.filter((r) => !inToday.has(r)).sort((a, b) => order(a.type) - order(b.type) || (b.carried || 0) - (a.carried || 0));
|
|
319
|
+
return { first, today: todayRows, wait };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** The Overview at the top of Today (written by PMOS, ✦): one or two sentences, the suggestions with ✓ ✕, and the type chips.
|
|
323
|
+
* Proven-only: the sentence names only the lines Do first picked, with their reasons; with none, it says only the counts and the free time.
|
|
324
|
+
* L: logModel(), A: agendaModel(). → { said, suggest: [{ key, text, act, keys }], chips: [{ type, n }], today: the lines for today } */
|
|
325
|
+
export const OLD_CHECK_DAYS = 60;
|
|
326
|
+
const clipT = (t, n) => { t = String(t || ''); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
|
|
327
|
+
export function overviewModel(L, A = {}) {
|
|
328
|
+
const parts = [];
|
|
329
|
+
// the lines for today: Do first and what waits today (not done, not a note); the rail's number on every place
|
|
330
|
+
const forToday = (L.first || []).length + (L.todayRows || []).filter((r) => !r.done && r.type !== 'Note').length;
|
|
331
|
+
if (L.open) parts.push(plural(L.open, 'line is', 'lines are') + ' open' + (forToday && forToday < L.open ? ', ' + forToday + ' of them for today.' : '.'));
|
|
332
|
+
// an ask is said by who asked ("Chen’s ask, 22 days"); another line by its title, clipped, with its reason
|
|
333
|
+
const said = new Set();
|
|
334
|
+
const top = (L.first || []).slice(0, 3).map((r) => (r.type === 'Ask' && r.who && r.who.length && !said.has(names(r.who)) && said.add(names(r.who)) ? names(r.who) + '’s ask (' + plural(r.carried, 'day', 'days') + ')'
|
|
335
|
+
: clipT(r.title, 48) + ' (' + r.reason.replace(/^(Late|Due|Goes|You|A)\b/, (w) => w.toLowerCase()) + ')'));
|
|
336
|
+
if (top.length) parts.push('Start with ' + (top.length === 1 ? top[0] : top.slice(0, -1).join(', ') + ' and ' + top[top.length - 1]) + '.');
|
|
337
|
+
const freeW = A.free ? 'You have ' + durWord(A.free) + ' free' : '';
|
|
338
|
+
const nextW = A.next ? (A.nextFirst ? 'your first meeting is at ' : 'your next meeting is at ') + A.next : '';
|
|
339
|
+
if (freeW || nextW) parts.push(cap1([freeW, nextW].filter(Boolean).join('; ')) + '.');
|
|
340
|
+
const suggest = [];
|
|
341
|
+
const old = (L.rows || []).filter((r) => !r.done && r.type === 'Check' && !r.kept && (r.carried || 0) > OLD_CHECK_DAYS);
|
|
342
|
+
if ((L.old || []).length) suggest.push({ key: 'old-tasks', text: plural(L.old.length, 'old task has', 'old tasks have') + ' passed dates by more than ' + OLD_TASK_DAYS + ' days, so they are not on Today. Clear them from Today', act: 'drop', keys: L.old });
|
|
343
|
+
if (old.length) suggest.push({ key: 'drop-old-checks', text: 'Drop the ' + plural(old.length, 'check', 'checks') + ' due more than ' + OLD_CHECK_DAYS + ' days ago', act: 'drop', keys: old.map((r) => r.key) });
|
|
344
|
+
const chips = TYPES.filter((t) => (L.types || {})[t]).map((t) => ({ type: t, n: L.types[t] }));
|
|
345
|
+
return { said: parts.join(' '), suggest, chips, today: forToday };
|
|
134
346
|
}
|
|
135
347
|
|
|
136
348
|
/* ── today's agenda ── */
|
|
@@ -163,14 +375,59 @@ export function agendaModel(o = {}) {
|
|
|
163
375
|
const [h, mi] = e.time.split(':').map(Number); const a = new Date(now); a.setHours(h, mi, 0, 0);
|
|
164
376
|
items.push({ key: e.key, kind: 'own', title: e.text, sub: e.time + ' · your event', a: a.getTime(), b: a.getTime() + 30 * 60000, ini: null, ref: e });
|
|
165
377
|
}
|
|
378
|
+
// the reports that go out today, at their time (GET /api/events-place: a schedule that fires today)
|
|
379
|
+
for (const r of o.reports || []) {
|
|
380
|
+
if (!r || !r.time || !/^\d{2}:\d{2}$/.test(r.time)) continue;
|
|
381
|
+
const [h, mi] = r.time.split(':').map(Number); const a = new Date(now); a.setHours(h, mi, 0, 0);
|
|
382
|
+
items.push({ key: 'r:' + (r.key || r.title), kind: 'report', title: r.title || 'A report', sub: r.time + ' · the report goes out', a: a.getTime(), b: a.getTime() + 30 * 60000, ini: null, ref: r });
|
|
383
|
+
}
|
|
166
384
|
items.sort((x, y) => x.a - y.a);
|
|
385
|
+
// focus time: the first open row of the log, in the first free stretch of 30 minutes or more from now until 18:00 (a dashed box)
|
|
386
|
+
const F = o.focus;
|
|
387
|
+
if (F && F.key && F.title) {
|
|
388
|
+
const end = new Date(now); end.setHours(18, 0, 0, 0);
|
|
389
|
+
const d8 = new Date(now); d8.setHours(8, 0, 0, 0); // focus time is in the working day: from now, never before 08:00
|
|
390
|
+
let at = Math.max(Math.ceil(now / (5 * 60000)) * 5 * 60000, d8.getTime()), got = null;
|
|
391
|
+
for (const x of items.filter((y) => y.kind !== 'report')) {
|
|
392
|
+
if (x.b <= at) continue;
|
|
393
|
+
if (x.a - at >= 30 * 60000) { got = [at, Math.min(x.a, end.getTime())]; break; }
|
|
394
|
+
at = Math.max(at, x.b);
|
|
395
|
+
}
|
|
396
|
+
if (!got && end.getTime() - at >= 30 * 60000) got = [at, end.getTime()];
|
|
397
|
+
if (got && got[1] - got[0] >= 30 * 60000) {
|
|
398
|
+
items.push({ key: 'f:' + F.key, kind: 'focus', title: F.title, sub: hm(got[0]) + ' to ' + hm(got[1]) + ' · focus time PMOS holds for this call', a: got[0], b: got[1], ini: null, ref: F, row: F.key });
|
|
399
|
+
items.sort((x, y) => x.a - y.a);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
167
402
|
const first = items.length ? new Date(items[0].a).getHours() : 8, last = items.length ? Math.max(...items.map((x) => new Date(x.b - 1).getHours() + 1)) : 18;
|
|
168
403
|
const from = Math.min(8, first), to = Math.max(18, Math.min(24, last));
|
|
169
404
|
const base = new Date(now); base.setHours(from, 0, 0, 0);
|
|
170
405
|
const H = 60 * 60000;
|
|
171
406
|
for (const x of items) { x.top = (x.a - base.getTime()) / H; x.h = Math.max(0.5, (x.b - x.a) / H); x.past = x.b <= now; x.nowOn = x.a <= now && now < x.b; }
|
|
407
|
+
// side by side, never on top of each other: items whose boxes meet share the width (a box is at least 40 px, about MIN_BOX minutes, tall, so a short
|
|
408
|
+
// meeting is never cut by the next one); each gets its column and the number of columns of its cluster
|
|
409
|
+
const MIN_BOX = 40 * 60000, endOf = (x) => Math.max(x.b, x.a + MIN_BOX);
|
|
410
|
+
let cluster = [], cEnd = -Infinity;
|
|
411
|
+
const close = () => { const n = Math.max(1, ...cluster.map((x) => x.col + 1)); for (const x of cluster) x.cols = n; cluster = []; };
|
|
412
|
+
for (const x of items) {
|
|
413
|
+
if (x.a >= cEnd) { close(); cEnd = -Infinity; }
|
|
414
|
+
const used = new Set(cluster.filter((y) => endOf(y) > x.a).map((y) => y.col));
|
|
415
|
+
let c = 0; while (used.has(c)) c++;
|
|
416
|
+
x.col = c; cluster.push(x); cEnd = Math.max(cEnd, endOf(x));
|
|
417
|
+
}
|
|
418
|
+
close();
|
|
172
419
|
const t = (now - base.getTime()) / H;
|
|
173
|
-
const d = new Date(now), free = freeMinutes(items, now);
|
|
420
|
+
const d = new Date(now), free = freeMinutes(items.filter((x) => x.kind !== 'focus' && x.kind !== 'report'), now);
|
|
174
421
|
const sub = DOW[d.getDay()] + ' ' + d.getDate() + ' ' + MON[d.getMonth()] + (free ? ' · ' + durWord(free) + ' free' : '');
|
|
175
|
-
|
|
422
|
+
const meets = items.filter((x) => x.kind === 'meeting' || x.kind === 'own');
|
|
423
|
+
const nx = meets.find((x) => x.a >= now);
|
|
424
|
+
return { items, from, to, now: t >= 0 && t <= to - from ? t : null, sub, empty: !items.length, free, next: nx ? hm(nx.a) : '', nextFirst: !!nx && !meets.some((x) => x.a < now) };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const DOW_LONG = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
428
|
+
const MON_LONG = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
429
|
+
/** The page head: "Wednesday 18 November · 16:23" and the greeting of the hour. */
|
|
430
|
+
export function headModel(now = Date.now()) {
|
|
431
|
+
const d = new Date(now), h = d.getHours();
|
|
432
|
+
return { when: DOW_LONG[d.getDay()] + ' ' + d.getDate() + ' ' + MON_LONG[d.getMonth()] + ' · ' + hm(now), hello: h < 5 || h >= 18 ? 'Good evening' : h < 12 ? 'Good morning' : 'Good afternoon' };
|
|
176
433
|
}
|