create-pmos 0.434.0 → 0.436.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 -25
- 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 +24 -0
- package/workspace/fixtures/ready-reports.js +145 -0
- package/workspace/guide/home.md +1 -1
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/initiative-boards.md +1 -1
- package/workspace/guide/ready-made-dashboards.md +62 -0
- package/workspace/lib/board-premium.js +1 -1
- package/workspace/lib/engine/boards.js +1 -1
- package/workspace/lib/intel-report.js +36 -5
- package/workspace/lib/ready-reports.js +616 -0
- package/workspace/lib/report-dashboards.js +5 -0
- package/workspace/lib/report-setups.js +16 -7
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-board-premium.js +5 -0
- package/workspace/lib/routes-boards.js +3 -2
- package/workspace/lib/routes-ready-reports.js +455 -0
- package/workspace/lib/routes-report-setups.js +4 -3
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/program-charter-test.js +11 -7
- package/workspace/program-panel-test.js +1 -1
- package/workspace/public/pm/bd-ini-panel.js +23 -6
- package/workspace/public/pm/bd-prog-panel.js +58 -10
- package/workspace/public/pm/cozy-viewer.js +2 -2
- package/workspace/public/pm/cozy-vw-rp.css +13 -0
- package/workspace/public/pm/dash-view.css +111 -0
- package/workspace/public/pm/dash-view.js +261 -0
- package/workspace/public/pm/home-app.js +26 -0
- package/workspace/public/pm/home-data.js +3 -2
- package/workspace/public/pm/home-ini.js +19 -1
- package/workspace/public/pm/home-task.js +4 -2
- package/workspace/public/pm/ini-tasks.js +34 -6
- package/workspace/public/pm/ini-view.css +4 -0
- package/workspace/public/pm/premium-insights.js +10 -2
- package/workspace/public/pm/premium-report-read.js +36 -5
- package/workspace/public/pm/premium-vw-item.js +2 -0
- package/workspace/public/pm/ready-lib.css +29 -0
- package/workspace/public/pm/ready-lib.js +62 -0
- package/workspace/public/pm/task-card.css +1 -0
- package/workspace/public/pm/task-card.js +8 -3
- package/workspace/ready-dash-ui-test.js +227 -0
- package/workspace/server.js +2 -0
- package/workspace/task-delete-test.js +31 -0
- package/workspace/task-views-test.js +16 -0
- package/workspace/test-lists/batch17-ready-reports.json +9 -0
- package/workspace/test-lists/ready-reports-ui.json +6 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* ready-reports.js — the ready-made dashboard and reports of every program, product and initiative (feedback batch 17 item 1, design A+:
|
|
3
|
+
* PbSet, PbGrill, PbH1Header, PbS1Discover, PbS2Monitor, PbG1–PbG10, PbA1–PbA8 on the main canvas, page In development, band from y 12300).
|
|
4
|
+
* THE ONE WRITER and THE ONE FOLD of <state>/ready-reports.jsonl, and the pure engines the dashboard and the Library read.
|
|
5
|
+
* lib/routes-ready-reports.js does the I/O; a ready report is drafted, issued and kept like any other report (lib/report-setups.js setups with a
|
|
6
|
+
* `ready` key, lib/intel-report.js documentOf, lib/issues.js). Nothing here sends anything: Send is the PM's Issue press.
|
|
7
|
+
*
|
|
8
|
+
* THE SET (PbSet). Every scope has the same skeleton: a Dashboard view and three ready reports.
|
|
9
|
+
* scope 'program:<id>' | 'product' | 'initiative:<id>'. An epic and a portfolio are not levels (grill rows 5 and 6).
|
|
10
|
+
* kinds weekly (Weekly update) · checkpoint (program: Milestone review, product: Quarter review, initiative: Stage review) · did-it-work (Did it work?)
|
|
11
|
+
* It reads only what every scope has: goals and health budgets with their readings, stage and milestone dates, Jira tickets, the open proposals,
|
|
12
|
+
* outcomes and verdicts. Nothing to set up.
|
|
13
|
+
*
|
|
14
|
+
* parseScope(s) → { level, id } | null · setupIdOf(scope, kind) → 'rr-<10 hex>' · kindName(level, kind)
|
|
15
|
+
* forecastOf(jira, today, promised) → { lo, hi, done, total, at, dot, why } the ship range from ticket throughput (PbA1, PbG9)
|
|
16
|
+
* usualDays(rows, except) → the median planned days of the other initiatives, or null with fewer than 3
|
|
17
|
+
* stageOf(level, f) → the stage block for where the scope is in its lifecycle (PbS1, PbA1, PbA2, PbS2, PbG7), or null
|
|
18
|
+
* dashboardOf(f) → the Dashboard view's model (1-B renders it; the shape is agreed in the build threads)
|
|
19
|
+
* looksGreen(f) → { text } | null Jira says done and the goal is flat (grill row 18)
|
|
20
|
+
* headsUpOf(f) → [{ id, why, title, sub }] a broken health budget or a critical slip (PbG3)
|
|
21
|
+
* rowsFor(o) → the Reports block's rows for one scope, each with its state (PbA1, PbG2, PbG7, PbG8)
|
|
22
|
+
* picksOf(scopes, st) → which weekly reports Claude schedules, and why (PbA6)
|
|
23
|
+
* libraryOf(o) → ⋯ › Reports and dashboards: the Ready-made groups, then Yours (PbA6)
|
|
24
|
+
* overlapOf(list) → one person, one update a week: the wider carries the narrower (PbG4)
|
|
25
|
+
* trustOf(history, st, key) → the "Send by itself" offer after 4 issues sent unchanged (PbG6)
|
|
26
|
+
* autoOk(markdown) → true for a calm week: no miss and no decision (PbG6)
|
|
27
|
+
* sponsorsCut(markdown) → the 1-minute cut of a team draft, the same numbers (PbG5)
|
|
28
|
+
* momentsOf(level, f) → the checkpoint and Did it work? moments due today (PbSet "drafts at its moment")
|
|
29
|
+
*
|
|
30
|
+
* THE LEDGER. One line per event, { v: 1, ev, …, at, by }. `by` is the call path's actor (lib/actor.js), never an argument of the page:
|
|
31
|
+
* switch { key, on } the PM's switch on one ready report (key '<scope>|<kind>'; scope 'initiative:*' is every initiative)
|
|
32
|
+
* picks { keys } ✓ on the Library's lead card: the PM kept Claude's picks (PbA6)
|
|
33
|
+
* trust { key, on } Send by itself on or off (PbG6). Off by default
|
|
34
|
+
* trust-no { key } ✕ on the offer: not offered again for that report
|
|
35
|
+
* hold { key, slot, act } a held report: send-note | wait | skip (PbG2)
|
|
36
|
+
* overlap { on } ✓ on "Lee would get 3 updates" (PbG4)
|
|
37
|
+
* promise { scope, act, date } keep or drop the drafted promise date (PbA5)
|
|
38
|
+
* moment { key, slot, why } a checkpoint or Did it work? was drafted at its moment (never twice for one moment)
|
|
39
|
+
* quiet { key, slot } a weekly was skipped because nothing moved (grill row 24; Your day says it in one line)
|
|
40
|
+
* heads-up { key, id, slot, path } an off-cycle note was drafted (PbG3)
|
|
41
|
+
* A later line wins for the same key; a line that does not parse is skipped.
|
|
42
|
+
*
|
|
43
|
+
* THE RULE THE FILE FOLLOWS (as the premium models): a number, dot, range or date is made only from a field of a record. A guess says it is a
|
|
44
|
+
* guess. No forecast range before 3 weeks of tickets. A goal with no reading gets a hollow dot, never a number. Zero is silence: an empty block
|
|
45
|
+
* is null or [] and is not drawn. */
|
|
46
|
+
|
|
47
|
+
const fs = require('fs');
|
|
48
|
+
const path = require('path');
|
|
49
|
+
const crypto = require('crypto');
|
|
50
|
+
const IR = require('./intel-report.js');
|
|
51
|
+
const BP = require('./board-premium.js');
|
|
52
|
+
|
|
53
|
+
const LEDGER = 'ready-reports.jsonl';
|
|
54
|
+
const EVENTS = Object.freeze(['switch', 'picks', 'trust', 'trust-no', 'hold', 'overlap', 'promise', 'moment', 'quiet', 'heads-up']);
|
|
55
|
+
const LEVELS = Object.freeze(['program', 'product', 'initiative']);
|
|
56
|
+
const KINDS = Object.freeze(['weekly', 'checkpoint', 'did-it-work']);
|
|
57
|
+
const HOLD_ACTS = Object.freeze(['send-note', 'wait', 'skip']);
|
|
58
|
+
const SCOPE_RE = /^(product|(program|initiative):[A-Za-z0-9._-]{1,80})$/;
|
|
59
|
+
const KEY_RE = /^(product|(program|initiative):([A-Za-z0-9._-]{1,80}|\*))\|(weekly|checkpoint|did-it-work|heads-up)$/;
|
|
60
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
61
|
+
const DAY = 864e5;
|
|
62
|
+
const STALE_MS = 2 * DAY; // a source not read for two days holds a report (PbG2)
|
|
63
|
+
const TRUST_N = 4; // issues sent unchanged before "Send by itself" is offered (PbG6)
|
|
64
|
+
const REFRESH_HOUR = 14, EVENING_HOUR = 18; // a late report: refreshed after 14:00, skipped by evening (PbG8)
|
|
65
|
+
const WINDOW_DAYS = 28; // Did it work? drafts 4 weeks after launch
|
|
66
|
+
const MS_SHOWN = 3; // a program's milestone track caps at 3 with "N more" (grill row 4)
|
|
67
|
+
const NEXT_SHOWN = 2; // a product's ships list: late ones, then 2 next, the rest folded (grill row 3)
|
|
68
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
69
|
+
const WEEKDAY = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
70
|
+
const DAYS3 = { Mon: 'Mondays', Tue: 'Tuesdays', Wed: 'Wednesdays', Thu: 'Thursdays', Fri: 'Fridays', Sat: 'Saturdays', Sun: 'Sundays' };
|
|
71
|
+
const DAY1 = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
|
|
72
|
+
|
|
73
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
74
|
+
const fin = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
75
|
+
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
76
|
+
const dayMs = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
77
|
+
const isoOf = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
78
|
+
const days = (a, b) => { const x = dayMs(a), y = dayMs(b); return x === null || y === null ? null : Math.round((y - x) / DAY); };
|
|
79
|
+
const addDays = (iso, n) => isoOf(dayMs(iso) + n * DAY);
|
|
80
|
+
const short = (iso) => { const t = dayMs(iso); if (t === null) return ''; const d = new Date(t); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()]; };
|
|
81
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
82
|
+
const hhmm = (ms) => { const d = new Date(ms); return pad(d.getHours()) + ':' + pad(d.getMinutes()); };
|
|
83
|
+
const localIso = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); };
|
|
84
|
+
const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
|
|
85
|
+
const median = (xs) => { const s = xs.slice().sort((a, b) => a - b); return s.length ? s[Math.floor((s.length - 1) / 2)] : null; };
|
|
86
|
+
|
|
87
|
+
// ── scopes and kinds ─────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
88
|
+
function parseScope(s) {
|
|
89
|
+
const v = String(s || '');
|
|
90
|
+
if (!SCOPE_RE.test(v)) return null;
|
|
91
|
+
if (v === 'product') return { level: 'product', id: null };
|
|
92
|
+
const i = v.indexOf(':');
|
|
93
|
+
return { level: v.slice(0, i), id: v.slice(i + 1) };
|
|
94
|
+
}
|
|
95
|
+
const keyOf = (scope, kind) => scope + '|' + kind;
|
|
96
|
+
const KIND_NAME = {
|
|
97
|
+
program: { weekly: 'Weekly update', checkpoint: 'Milestone review', 'did-it-work': 'Did it work?' },
|
|
98
|
+
product: { weekly: 'Weekly update', checkpoint: 'Quarter review', 'did-it-work': 'Did it work?' },
|
|
99
|
+
initiative: { weekly: 'Weekly update', checkpoint: 'Stage review', 'did-it-work': 'Did it work?' },
|
|
100
|
+
};
|
|
101
|
+
const kindName = (level, kind) => (kind === 'heads-up' ? 'Heads-up' : (KIND_NAME[level] || KIND_NAME.product)[kind] || kind);
|
|
102
|
+
const MOMENT_SUB = {
|
|
103
|
+
program: { checkpoint: 'Drafts at each milestone', 'did-it-work': 'Drafts when the program closes' },
|
|
104
|
+
product: { checkpoint: 'Drafts at quarter end from the quarter score', 'did-it-work': 'Drafts after each launch' },
|
|
105
|
+
initiative: { checkpoint: "Drafts when a stage's checklist is done", 'did-it-work': 'Drafts 4 weeks after each launch' },
|
|
106
|
+
};
|
|
107
|
+
/** The setup id of a ready report: a hash of its key, so a program id of any length makes a valid setup id (lib/report-setups.js ID_RE). */
|
|
108
|
+
const setupIdOf = (scope, kind) => 'rr-' + crypto.createHash('sha1').update(keyOf(scope, kind)).digest('hex').slice(0, 10);
|
|
109
|
+
|
|
110
|
+
// ── the ledger ───────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
111
|
+
const ledgerFile = (stateDir) => path.join(String(stateDir), LEDGER);
|
|
112
|
+
function readLines(file) {
|
|
113
|
+
let text;
|
|
114
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const l of text.split('\n')) { if (!l.trim()) continue; try { out.push(JSON.parse(l)); } catch { /* a torn line is skipped */ } }
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
/** THE SINGLE WRITER. Checks the line's shape; `v`, `at` and `by` are set here. → { ok, line } | { ok: false, status, error } */
|
|
120
|
+
function append(file, line, { now, actor } = {}) {
|
|
121
|
+
const c = checkLine(line);
|
|
122
|
+
if (!c.ok) return { ok: false, status: 400, error: c.error };
|
|
123
|
+
const out = { v: 1, ...c.line, at: new Date(now == null ? Date.now() : now).toISOString(), ...(actor && actor.by ? { by: actor.by } : {}) };
|
|
124
|
+
try { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.appendFileSync(file, JSON.stringify(out) + '\n'); } catch (e) { return { ok: false, status: 500, error: 'could not write the ledger: ' + String((e && e.message) || e).slice(0, 120) }; }
|
|
125
|
+
return { ok: true, line: out };
|
|
126
|
+
}
|
|
127
|
+
function checkLine(l) {
|
|
128
|
+
if (!isObj(l) || !EVENTS.includes(l.ev)) return { ok: false, error: `ev is one of ${EVENTS.join(', ')}` };
|
|
129
|
+
const key = () => KEY_RE.test(String(l.key || ''));
|
|
130
|
+
switch (l.ev) {
|
|
131
|
+
case 'switch': case 'trust':
|
|
132
|
+
if (!key() || typeof l.on !== 'boolean') return { ok: false, error: 'a switch is { key: "<scope>|<kind>", on: true|false }' };
|
|
133
|
+
return { ok: true, line: { ev: l.ev, key: l.key, on: l.on } };
|
|
134
|
+
case 'trust-no': if (!key()) return { ok: false, error: 'key is "<scope>|<kind>"' }; return { ok: true, line: { ev: l.ev, key: l.key } };
|
|
135
|
+
case 'picks':
|
|
136
|
+
if (!Array.isArray(l.keys) || l.keys.length > 200 || !l.keys.every((k) => KEY_RE.test(String(k)))) return { ok: false, error: 'keys is a list of "<scope>|<kind>"' };
|
|
137
|
+
return { ok: true, line: { ev: 'picks', keys: l.keys.slice() } };
|
|
138
|
+
case 'hold':
|
|
139
|
+
if (!key() || !DATE_RE.test(String(l.slot || '')) || !HOLD_ACTS.includes(l.act)) return { ok: false, error: `a hold is { key, slot: YYYY-MM-DD, act: ${HOLD_ACTS.join(' | ')} }` };
|
|
140
|
+
return { ok: true, line: { ev: 'hold', key: l.key, slot: l.slot, act: l.act } };
|
|
141
|
+
case 'overlap': if (typeof l.on !== 'boolean') return { ok: false, error: 'on is true or false' }; return { ok: true, line: { ev: 'overlap', on: l.on } };
|
|
142
|
+
case 'promise':
|
|
143
|
+
if (!SCOPE_RE.test(String(l.scope || '')) || !['keep', 'drop'].includes(l.act) || !DATE_RE.test(String(l.date || ''))) return { ok: false, error: 'a promise is { scope, act: keep | drop, date: YYYY-MM-DD }' };
|
|
144
|
+
return { ok: true, line: { ev: 'promise', scope: l.scope, act: l.act, date: l.date } };
|
|
145
|
+
case 'moment': case 'quiet': case 'heads-up':
|
|
146
|
+
if (!key() || !DATE_RE.test(String(l.slot || ''))) return { ok: false, error: 'a draft line is { key, slot: YYYY-MM-DD }' };
|
|
147
|
+
return { ok: true, line: { ev: l.ev, key: l.key, slot: l.slot, ...(typeof l.why === 'string' ? { why: clip(l.why, 120) } : {}), ...(typeof l.id === 'string' ? { id: clip(l.id, 120) } : {}), ...(typeof l.path === 'string' ? { path: clip(l.path, 300) } : {}) } };
|
|
148
|
+
default: return { ok: false, error: 'unknown event' };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** → { switches: Map key→on, picks: { at, keys } | null, trust: Map key→on, trustNo: Set, holds: Map 'key|slot'→act, overlap: bool|null,
|
|
152
|
+
* promises: Map scope→{ act, date }, moments: Map 'key|why'→slot, quiet: Map key→[slot], headsUps: Map id→{ key, slot, path } } */
|
|
153
|
+
function fold(lines) {
|
|
154
|
+
const st = { switches: new Map(), picks: null, trust: new Map(), trustNo: new Set(), holds: new Map(), overlap: null, promises: new Map(), moments: new Map(), quiet: new Map(), headsUps: new Map() };
|
|
155
|
+
for (const l of lines || []) {
|
|
156
|
+
if (!isObj(l) || !checkLine(l).ok) continue;
|
|
157
|
+
switch (l.ev) {
|
|
158
|
+
case 'switch': st.switches.set(l.key, l.on); break;
|
|
159
|
+
case 'picks': st.picks = { at: l.at, keys: l.keys }; break;
|
|
160
|
+
case 'trust': st.trust.set(l.key, l.on); if (l.on) st.trustNo.delete(l.key); break;
|
|
161
|
+
case 'trust-no': st.trustNo.add(l.key); break;
|
|
162
|
+
case 'hold': st.holds.set(l.key + '|' + l.slot, l.act); break;
|
|
163
|
+
case 'overlap': st.overlap = l.on; break;
|
|
164
|
+
case 'promise': st.promises.set(l.scope, { act: l.act, date: l.date }); break;
|
|
165
|
+
case 'moment': st.moments.set(l.key + '|' + (l.why || l.slot), l.slot); break;
|
|
166
|
+
case 'quiet': { const a = st.quiet.get(l.key) || []; a.push(l.slot); st.quiet.set(l.key, a); break; }
|
|
167
|
+
case 'heads-up': st.headsUps.set(l.id || l.key + '|' + l.slot, { key: l.key, slot: l.slot, path: l.path || null, why: l.why || '' }); break;
|
|
168
|
+
default: break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return st;
|
|
172
|
+
}
|
|
173
|
+
const stateOf = (stateDir) => fold(readLines(ledgerFile(stateDir)));
|
|
174
|
+
/** A switch for one report: its own line, else the all-initiatives line ('initiative:*'), else undefined. */
|
|
175
|
+
function switchOf(st, scope, kind) {
|
|
176
|
+
if (st.switches.has(keyOf(scope, kind))) return st.switches.get(keyOf(scope, kind));
|
|
177
|
+
if (scope.startsWith('initiative:') && st.switches.has(keyOf('initiative:*', kind))) return st.switches.get(keyOf('initiative:*', kind));
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── forecast: the ship range from ticket throughput ──────────────────────────────────────────────────────────────────────────
|
|
182
|
+
/** jira { at, tickets: [{ category: todo|doing|done, resolved: YYYY-MM-DD|null }] }. The range is the remaining tickets at the fastest and the
|
|
183
|
+
* slowest of two rates (the mean of every full week since the first close, at most 6, and the mean of the last 3), carried from today.
|
|
184
|
+
* No range before 3 weeks of tickets (PbG9); none when no ticket closed in those weeks. The dot compares the range with the promise. */
|
|
185
|
+
function forecastOf(J, today, promised) {
|
|
186
|
+
if (!J || !Array.isArray(J.tickets) || !J.tickets.length) return null;
|
|
187
|
+
const T = J.tickets, total = T.length, done = T.filter((t) => t && t.category === 'done').length;
|
|
188
|
+
const res = T.map((t) => t && t.category === 'done' && dayMs(t.resolved) !== null ? String(t.resolved).slice(0, 10) : null).filter(Boolean).sort();
|
|
189
|
+
const base = { done, total, at: J.at || null, lo: null, hi: null, dot: 'none', why: '' };
|
|
190
|
+
if (done === total) { const last = res.length ? res[res.length - 1] : null; return { ...base, lo: last, hi: last, dot: 'on', finished: true }; }
|
|
191
|
+
if (!res.length || days(res[0], today) < 21) return { ...base, why: 'No forecast range before 3 weeks of tickets' };
|
|
192
|
+
const weeks = Math.min(6, Math.floor(days(res[0], today) / 7));
|
|
193
|
+
const per = [];
|
|
194
|
+
for (let i = 0; i < weeks; i++) { const hi = dayMs(today) - i * 7 * DAY, lo = hi - 7 * DAY; per.push(res.filter((r) => { const t = dayMs(r); return t > lo && t <= hi; }).length); }
|
|
195
|
+
const all = per.reduce((a, b) => a + b, 0) / weeks, last3 = per.slice(0, 3).reduce((a, b) => a + b, 0) / Math.min(3, weeks);
|
|
196
|
+
const fast = Math.max(all, last3), slow = Math.min(all, last3), left = total - done;
|
|
197
|
+
if (!(fast > 0)) return { ...base, why: 'No ticket closed in the last ' + plural(weeks, 'week', 'weeks') };
|
|
198
|
+
const lo = addDays(today, Math.ceil(left / fast * 7)), hi = slow > 0 ? addDays(today, Math.ceil(left / slow * 7)) : null;
|
|
199
|
+
return { ...base, lo, hi, dot: dotOf(lo, hi, promised), why: hi ? '' : 'The slower rate closed nothing, so the range has no end' };
|
|
200
|
+
}
|
|
201
|
+
function dotOf(lo, hi, promised) {
|
|
202
|
+
if (!promised || !lo) return 'none';
|
|
203
|
+
if (hi && dayMs(hi) <= dayMs(promised)) return 'on';
|
|
204
|
+
if (dayMs(lo) > dayMs(promised)) return 'behind';
|
|
205
|
+
return 'risk';
|
|
206
|
+
}
|
|
207
|
+
/** The median planned days (start to end) of the other initiatives that hold both dates, or null with fewer than 3 of them (PbA5). */
|
|
208
|
+
function usualDays(rows, except) {
|
|
209
|
+
const d = (rows || []).filter((r) => r && r.id !== except && dayMs(r.start) !== null && dayMs(r.end) !== null).map((r) => days(r.start, r.end)).filter((n) => n > 0);
|
|
210
|
+
return d.length >= 3 ? median(d) : null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ── the blocks ───────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
214
|
+
const idxOf = (row) => (row ? BP.stepIndex(row.stage, row.cat) : -1);
|
|
215
|
+
const paused = (row) => !!row && ['on hold', 'cancelled', "won't do"].includes(String(row.status || '').toLowerCase());
|
|
216
|
+
const STEP_NAMES = BP.STEPS.map((s) => s.label);
|
|
217
|
+
|
|
218
|
+
/** The promise date of one initiative: the PM's kept date, else its planned end, else a guess from the usual time (marked a guess). */
|
|
219
|
+
function promiseOf(row, rows, kept) {
|
|
220
|
+
if (kept && kept.act === 'keep') return { date: kept.date, guess: false };
|
|
221
|
+
if (row && dayMs(row.end) !== null) return { date: String(row.end).slice(0, 10), guess: false };
|
|
222
|
+
const u = usualDays(rows, row && row.id);
|
|
223
|
+
if (u === null || !row || dayMs(row.start) === null || (kept && kept.act === 'drop' && kept.date)) return null;
|
|
224
|
+
return { date: addDays(row.start, u), guess: true, usual: u };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function goalDot(r) { return r.now === null ? 'none' : r.off ? 'behind' : r.ahead ? 'ahead' : 'on'; }
|
|
228
|
+
/** The goal rows of a scope (the Claude-runs-the-OKRs goal row; the UI opens GsViewer on tap). Guardrails go to their own list. */
|
|
229
|
+
function goalsOf(intel, scope, todayMs, multi) {
|
|
230
|
+
if (!intel) return { goals: [], guardrails: [] };
|
|
231
|
+
const G = IR.goalsIn(intel, scope);
|
|
232
|
+
const row = (g) => {
|
|
233
|
+
const r = IR.rowOf(g, todayMs);
|
|
234
|
+
const sub = r.now === null ? (g.firstAt ? 'first reading ' + short(g.firstAt) : 'no reading yet') : r.planTxt !== '—' && r.vsTxt !== '—' ? r.nowTxt + ' now · its line says ' + r.planTxt : r.nowTxt + ' now';
|
|
235
|
+
return { id: g.id, title: g.title, owner: g.owner || '', dot: goalDot(r), sub, ...(multi && g.product ? { product: g.product } : {}) };
|
|
236
|
+
};
|
|
237
|
+
return { goals: G.filter((g) => g.role !== 'guardrail').map(row), guardrails: G.filter((g) => g.role === 'guardrail').map(row) };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function stepsOf(i) { return STEP_NAMES.map((name, k) => ({ name, state: k < i ? 'done' : k === i ? 'current' : 'todo' })); }
|
|
241
|
+
|
|
242
|
+
/** The stage block. f: { today, row, rows, jira, checklist, program, intel, kept, outcome }. */
|
|
243
|
+
function stageOf(level, f) {
|
|
244
|
+
const today = f.today;
|
|
245
|
+
if (level === 'initiative') {
|
|
246
|
+
const row = f.row; if (!row) return null;
|
|
247
|
+
if (paused(row)) return { kind: 'on-hold', since: dayMs(row.updated) !== null ? String(row.updated).slice(0, 10) : null, status: row.status };
|
|
248
|
+
const i = idxOf(row);
|
|
249
|
+
if (i >= 0 && i < 4) {
|
|
250
|
+
const items = (f.checklist || []).filter(isObj).map((c) => ({ text: clip(c.text, 120), done: !!c.done, who: c.who || '', when: c.when || '' }));
|
|
251
|
+
if (!items.length) return null;
|
|
252
|
+
return { kind: 'ready', stage: BP.STEPS[i].label, done: items.filter((x) => x.done).length, total: items.length, day: fin(f.stageDay) ? f.stageDay : null, usual: fin(f.usualStage) ? f.usualStage : null, items };
|
|
253
|
+
}
|
|
254
|
+
if (i === 4 || i === 5) {
|
|
255
|
+
const P = promiseOf(row, f.rows, f.kept);
|
|
256
|
+
const F = forecastOf(f.jira, today, P && P.date);
|
|
257
|
+
return { kind: 'ships', lo: F ? F.lo : null, hi: F ? F.hi : null, promised: P ? P.date : null, guess: !!(P && P.guess), dot: F ? F.dot : 'none', why: F ? F.why : 'No Jira tickets are read for it', steps: stepsOf(i), today,
|
|
258
|
+
jira: F ? { done: F.done, total: F.total, at: F.at } : null };
|
|
259
|
+
}
|
|
260
|
+
if (i >= 6) {
|
|
261
|
+
const o = ((f.intel && f.intel.outcomes) || []).find((x) => x.id === row.id) || null;
|
|
262
|
+
const launch = dayMs(row.end) !== null ? String(row.end).slice(0, 10) : null;
|
|
263
|
+
const g = o && o.goal ? o.goal : null;
|
|
264
|
+
return { kind: 'did-it-work', head: g ? (g.nowTxt ? g.nowTxt + ' of ' + (g.targetTxt || 'its target') : 'No reading yet') : 'No goal to read', day: launch ? Math.max(0, days(launch, today)) : null, window: WINDOW_DAYS,
|
|
265
|
+
dot: !g || !g.nowTxt ? 'none' : g.pace && g.pace.tone === 'late' ? 'behind' : 'on', promise: g ? g.targetTxt || '' : '', note: g && g.pace ? clip(g.pace.sub || '', 80) : '', verdictAt: o && o.verdict ? o.verdict.at : null };
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
if (level === 'program') {
|
|
270
|
+
const p = f.program; if (!p) return null;
|
|
271
|
+
if (p.archived || p.closed) return { kind: 'closed', at: p.closedAt || null };
|
|
272
|
+
const fc = new Map((f.rows || []).map((r) => [r.id, forecastOf((f.jiraOf || {})[r.id], today, r.end)]));
|
|
273
|
+
const items = (p.milestones || []).filter(isObj).map((m) => {
|
|
274
|
+
const waits = (m.waits || []).map((id) => fc.get(id)).filter(Boolean);
|
|
275
|
+
const his = waits.map((x) => x.hi || x.lo).filter(Boolean).sort();
|
|
276
|
+
const when = m.done ? 'done' : m.date ? short(m.date) : 'no date';
|
|
277
|
+
const dot = m.done ? 'on' : !m.date ? 'none' : !his.length ? (dayMs(m.date) < dayMs(today) ? 'behind' : 'none') : dotOf(waits.map((x) => x.lo).filter(Boolean).sort().pop(), his[his.length - 1], m.date);
|
|
278
|
+
const product = (m.waits || []).map((id) => (f.rows || []).find((r) => r.id === id)).filter(Boolean).map((r) => r.product).filter(Boolean)[0] || null;
|
|
279
|
+
return { id: m.id, name: clip(m.name, 80), dot, when, date: m.date || null, ...(f.multi && product ? { product } : {}) };
|
|
280
|
+
});
|
|
281
|
+
if (!items.length) return null;
|
|
282
|
+
const open = items.filter((x) => x.when !== 'done');
|
|
283
|
+
const shown = (open.length ? open : items).slice(0, MS_SHOWN);
|
|
284
|
+
const pool = open.length ? open : items;
|
|
285
|
+
return { kind: 'milestones', items: shown, note: pool.length > shown.length ? (pool.length - shown.length) + ' more' : '' };
|
|
286
|
+
}
|
|
287
|
+
// product: the launches by promised date, late first, then the next 2, the rest folded
|
|
288
|
+
const all = (f.rows || []).filter((r) => { const i = idxOf(r); return (i === 4 || i === 5) && !paused(r); }).map((r) => {
|
|
289
|
+
const F = forecastOf((f.jiraOf || {})[r.id], today, r.end);
|
|
290
|
+
return { id: r.id, name: clip(r.title || r.id, 80), dot: F ? F.dot : 'none', promised: dayMs(r.end) !== null ? String(r.end).slice(0, 10) : null, lo: F ? F.lo : null, hi: F ? F.hi : null, when: r.end ? short(r.end) : 'no date' };
|
|
291
|
+
});
|
|
292
|
+
if (!all.length) return null;
|
|
293
|
+
const late = all.filter((x) => x.dot === 'behind' || x.dot === 'risk' || (x.promised && dayMs(x.promised) < dayMs(today)));
|
|
294
|
+
const rest = all.filter((x) => !late.includes(x)).sort((a, b) => String(a.promised || '9').localeCompare(String(b.promised || '9')));
|
|
295
|
+
const items = late.concat(rest.slice(0, NEXT_SHOWN)), folded = rest.slice(NEXT_SHOWN);
|
|
296
|
+
return { kind: 'ships-next', items, more: folded.length ? { count: folded.length, text: folded.length + ' more' + (folded.every((x) => x.dot === 'on') ? ', all on their dates' : ''), items: folded } : null };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** "Looks green but isn't" (grill row 18): Jira says every ticket is done and the scope's goal has not moved in its last two readings, or
|
|
300
|
+
* has no reading after the work landed. → { text } | null. The report's checks refuse a green status while it holds. */
|
|
301
|
+
function looksGreen(f) {
|
|
302
|
+
const F = f.jira && Array.isArray(f.jira.tickets) && f.jira.tickets.length && f.jira.tickets.every((t) => t && t.category === 'done');
|
|
303
|
+
if (!F || !f.goal) return null;
|
|
304
|
+
const S = (f.goal.series || []).filter((r) => fin(r.v));
|
|
305
|
+
const landed = (f.jira.tickets.map((t) => t.resolved).filter(Boolean).sort().pop()) || null;
|
|
306
|
+
const flat = S.length < 2 ? true : S[S.length - 1].v === S[S.length - 2].v;
|
|
307
|
+
const after = landed ? S.filter((r) => dayMs(r.at) >= dayMs(landed)).length : S.length;
|
|
308
|
+
if (!flat && after) return null;
|
|
309
|
+
return { text: 'Jira says done, but ' + clip(f.goal.title, 60) + (after ? ' has not moved' : ' has no reading since the work landed') + ', so I will not call it green.' };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** A heads-up (PbG3): a health budget over its cap, or a ship whose whole range is a week or more past its promise. → [{ id, why, title, sub }] */
|
|
313
|
+
function headsUpOf(f) {
|
|
314
|
+
const out = [];
|
|
315
|
+
for (const b of f.budgets || []) {
|
|
316
|
+
const R = b && b.reading; if (!R || !fin(R.share) || !fin(b.cap) || R.share <= b.cap) continue;
|
|
317
|
+
out.push({ id: 'budget:' + b.id, why: 'budget', title: clip(b.title || b.id, 60) + ' is over its health budget', sub: Math.round(R.share * 100) + '% against a ' + Math.round(b.cap * 100) + '% cap' });
|
|
318
|
+
}
|
|
319
|
+
const S = f.ships;
|
|
320
|
+
if (S && S.kind === 'ships' && S.promised && S.lo && days(S.promised, S.lo) >= 7)
|
|
321
|
+
out.push({ id: 'slip:' + S.promised + ':' + S.lo, why: 'slip', title: clip(f.name || 'It', 60) + ' will ship after its promise', sub: 'now ' + short(S.lo) + (S.hi && S.hi !== S.lo ? ' to ' + short(S.hi) : '') + ', promised ' + short(S.promised) });
|
|
322
|
+
return out;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** The ✦ line: what Claude handled, in a human voice, never cheerful on a bad week (PbA1, PbG1, PbG2). null when there is nothing to say. */
|
|
326
|
+
function handledOf(f) {
|
|
327
|
+
const H = f.heldBy;
|
|
328
|
+
if (H) return { lead: "I can't read " + H.source + ' since ' + whenTxt(H.since, f.now) + ", so I'm holding " + (f.heldDay ? f.heldDay + "'s" : 'the') + ' update.', rest: 'Its ship date and tickets would be ' + plural(Math.max(1, Math.round((f.now - Date.parse(H.since)) / DAY)), 'day', 'days') + ' old. The rest of the dashboard is fresh.', tone: 'warn' };
|
|
329
|
+
if (f.green) return { lead: f.green.text, rest: '', tone: 'warn' };
|
|
330
|
+
const behind = (f.behind || []).filter(Boolean);
|
|
331
|
+
const read = f.readAt && localIso(Date.parse(f.readAt)) === localIso(f.now) ? 'I read Jira at ' + hhmm(Date.parse(f.readAt)) : '';
|
|
332
|
+
const drafted = f.drafted ? (read ? ' and drafted your ' : 'I drafted your ') + f.drafted + ' update.' : read ? '.' : '';
|
|
333
|
+
if (behind.length) return { lead: plural(behind.length, 'thing', 'things') + (behind.length === 1 ? ' is' : ' are') + ' behind this week: ' + behind.slice(0, 2).join(', ') + (behind.length > 2 ? ' and ' + (behind.length - 2) + ' more' : '') + '.', rest: [read || f.drafted ? (read + drafted).trim() : '', f.deskReady ? 'Your weekly update is ready to send.' : ''].filter(Boolean).join(' '), tone: 'warn' };
|
|
334
|
+
if (!read && !f.drafted && f.deskReady) return { lead: 'Your weekly update is ready to send.', rest: f.closed ? plural(f.closed, 'ticket', 'tickets') + ' closed this week.' : '', tone: 'calm' };
|
|
335
|
+
if (!read && !f.drafted) return null;
|
|
336
|
+
return { lead: (read + drafted).trim(), rest: f.closed ? plural(f.closed, 'ticket', 'tickets') + ' closed this week.' : '', tone: 'calm' };
|
|
337
|
+
}
|
|
338
|
+
function whenTxt(iso, now) { const t = Date.parse(iso); if (!fin(t)) return 'a while'; const d = new Date(t); return (now - t < 7 * DAY ? WEEKDAY[d.getDay()].slice(0, 3) : d.getDate() + ' ' + MON[d.getMonth()]) + ' ' + hhmm(t); }
|
|
339
|
+
|
|
340
|
+
/** The Dashboard view (PbA1, PbA2, PbA3, PbA7). f: {
|
|
341
|
+
* scope, from: read|act, now (ms), today (YYYY-MM-DD), name, sub,
|
|
342
|
+
* intel the Intelligence model, with members { [program id]: [initiative id] } and names { scope: name } set by the route
|
|
343
|
+
* rows the scope's initiative rows (the Board's backlog rows; on a program each carries ws and product { tag, name })
|
|
344
|
+
* program the program record (lib/programs.js), on a program scope
|
|
345
|
+
* jiraOf { [initiative id]: { at, tickets: [{ category, resolved }] } }
|
|
346
|
+
* checklist the initiative's exit checklist [{ text, done, who, when }] (its stepper), before Build
|
|
347
|
+
* needs [{ id, q, sub, pick, from, ini, keep, drop }] the open proposals, the slips first
|
|
348
|
+
* products [{ ws, name, read, why, asked }] on a program
|
|
349
|
+
* reports the Reports block's rows (rowsFor)
|
|
350
|
+
* trust { reportId } | null goalDraft { title, sub, anchor } | null kept the PM's promise line for the scope
|
|
351
|
+
* stale { source, since, why } | null a source not read in time
|
|
352
|
+
* } */
|
|
353
|
+
function dashboardOf(f) {
|
|
354
|
+
const P = parseScope(f.scope); if (!P) return null;
|
|
355
|
+
const now = fin(f.now) ? f.now : Date.now(), today = f.today || localIso(now), todayMs = dayMs(today);
|
|
356
|
+
const rows = (f.rows || []).filter(isObj);
|
|
357
|
+
const row = P.level === 'initiative' ? rows.find((r) => r.id === P.id) || null : null;
|
|
358
|
+
const multi = P.level === 'program' && new Set(rows.map((r) => r.ws).filter(Boolean)).size > 1;
|
|
359
|
+
const G0 = goalsOf(f.intel, f.scope, todayMs, multi), guardrails = G0.guardrails;
|
|
360
|
+
const covered = new Set(((f.intel && IR.goalsIn(f.intel, f.scope)) || []).flatMap((g) => [g.id, g.key, g.title].filter(Boolean)));
|
|
361
|
+
const goals = G0.goals.concat(anchorGoalsOf(P.level === 'initiative' ? rows.filter((r) => r.id === P.id) : rows, covered));
|
|
362
|
+
const jira = row ? (f.jiraOf || {})[row.id] || null : null;
|
|
363
|
+
const stage = stageOf(P.level, { today, row, rows, jira, jiraOf: f.jiraOf, checklist: f.checklist, program: f.program, intel: f.intel, kept: f.kept, stageDay: f.stageDay, usualStage: f.usualStage, multi });
|
|
364
|
+
const drafts = {};
|
|
365
|
+
if (!goals.length && f.goalDraft) drafts.goal = f.goalDraft;
|
|
366
|
+
if (P.level === 'initiative' && row && !row.end && (!f.kept || f.kept.act !== 'keep')) { const pr = promiseOf(row, rows, f.kept); if (pr && pr.guess) drafts.promise = { date: pr.date, sub: 'A guess from your usual ' + pr.usual + ' days from start to finish' }; }
|
|
367
|
+
const inScope = P.level === 'initiative' ? (row ? [row] : []) : rows;
|
|
368
|
+
const closedWeek = inScope.reduce((n, r) => n + (((f.jiraOf || {})[r.id] || {}).tickets || []).filter((t) => t && t.category === 'done' && dayMs(t.resolved) !== null && todayMs - dayMs(t.resolved) < 7 * DAY && todayMs >= dayMs(t.resolved)).length, 0);
|
|
369
|
+
const readAt = inScope.map((r) => ((f.jiraOf || {})[r.id] || {}).at).filter(Boolean).sort().pop() || null;
|
|
370
|
+
const green = row && (idxOf(row) === 4 || idxOf(row) === 5) ? looksGreen({ jira, goal: f.intel ? IR.goalsIn(f.intel, f.scope)[0] : null }) : null;
|
|
371
|
+
const behind = goals.filter((g) => g.dot === 'behind').map((g) => clip(g.title, 50)).concat(stage && stage.kind === 'ships' && stage.dot === 'behind' ? ['the ship date'] : [])
|
|
372
|
+
.concat(stage && stage.kind === 'milestones' ? stage.items.filter((m) => m.dot === 'behind').map((m) => clip(m.name, 40)) : []);
|
|
373
|
+
const reports = (f.reports || []).filter(isObj);
|
|
374
|
+
const drafted = reports.find((r) => r.kind === 'weekly' && r.state === 'drafted' && !r.desk);
|
|
375
|
+
const deskReady = reports.find((r) => r.kind === 'weekly' && r.state === 'drafted' && r.desk);
|
|
376
|
+
const handled = handledOf({ deskReady: !!deskReady, now, heldBy: f.stale, heldDay: drafted || reports.find((r) => r.state === 'held') ? dayName(reports.find((r) => r.state === 'held' || r.state === 'drafted')) : '', green, behind, readAt, drafted: drafted ? dayName(drafted) : '', closed: closedWeek });
|
|
377
|
+
const needs = (f.needs || []).filter(isObj)[0] || null;
|
|
378
|
+
return {
|
|
379
|
+
scope: f.scope, level: P.level, name: f.name || '', sub: f.sub || '',
|
|
380
|
+
opens: f.from === 'act' ? 'work' : 'dashboard',
|
|
381
|
+
handled, goals, drafts: Object.keys(drafts).length ? drafts : null, stage, guardrails: stage && (stage.kind === 'did-it-work' || P.level === 'product') ? guardrails : [],
|
|
382
|
+
needs, reports, heldBy: f.stale || null, trust: f.trust || null,
|
|
383
|
+
done: closedWeek ? { text: plural(closedWeek, 'ticket', 'tickets') + ' closed this week' } : null,
|
|
384
|
+
products: P.level === 'program' && multi ? (f.products || []) : [],
|
|
385
|
+
asOf: today,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const dayName = (r) => (r && r.day ? DAY1[r.day] || '' : '');
|
|
389
|
+
|
|
390
|
+
// ── reports: picks, states, the Library ──────────────────────────────────────────────────────────────────────────────────────
|
|
391
|
+
/** Claude's picks (PbA6): a weekly is scheduled only where the PM already sends it by hand (`hand`: a finding of the report finder), or where it
|
|
392
|
+
* carries news (`news`: a decision or a slip). The rest draft at their moment. scopes: [{ scope, level, name, hand?: { name, audience, schedule, n }, news?: [why] }] */
|
|
393
|
+
function picksOf(scopes) {
|
|
394
|
+
return (scopes || []).filter(isObj).map((s) => {
|
|
395
|
+
const why = s.hand ? 'you sent this by hand ' + (s.hand.n ? s.hand.n + ' times' : 'before') : s.news && s.news.length ? 'it has ' + s.news.join(' and ') : '';
|
|
396
|
+
return { key: keyOf(s.scope, 'weekly'), scope: s.scope, pick: !!why, why };
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** The state of one ready report. o: { kind, on, setup, doc: { slot, path, issued, sha, at } | null, now, stale, hold, paused, closed, quiet, auto }
|
|
401
|
+
* → { state, sub } */
|
|
402
|
+
function stateOfReport(o) {
|
|
403
|
+
const now = fin(o.now) ? o.now : Date.now();
|
|
404
|
+
const s = o.setup, sch = s && s.schedule ? s.schedule : null, time = (sch && sch.time) || '09:00';
|
|
405
|
+
if (o.closed) return { state: 'stopped', sub: o.doc ? 'The program closed. This is the last report' : 'The program closed, so it stopped' };
|
|
406
|
+
if (o.paused) return { state: 'paused', sub: 'Paused while it is on hold' };
|
|
407
|
+
const D = o.doc;
|
|
408
|
+
if (D && D.issued) {
|
|
409
|
+
const at = Date.parse(D.issued.at || '') || null;
|
|
410
|
+
if (at && now - at < 7 * DAY) return { state: 'sent', sub: 'Sent ' + whenTxt(D.issued.at, now) + (o.auto ? ' by itself' : '') + (s && s.audience ? ' · ' + clip(s.audience, 40) : '') };
|
|
411
|
+
}
|
|
412
|
+
if (D && !D.issued) {
|
|
413
|
+
if (o.hold === 'skip') return { state: 'skipped', sub: 'You skipped it. The next issue covers both weeks' };
|
|
414
|
+
if (o.stale && o.hold !== 'send-note') return { state: 'held', sub: o.hold === 'wait' ? 'Waits for ' + o.stale.source + ". It goes out once it reads again, if nothing changed" : 'Send it now with "' + o.stale.source + ' as of ' + whenTxt(o.stale.since, now) + '" written on it, or wait' };
|
|
415
|
+
const due = dueAt(D.slot, time);
|
|
416
|
+
if (due === null || now < due) return { state: 'drafted', sub: 'Drafted · goes ' + (sch && sch.day ? DAY1[sch.day] + ' ' : '') + time + (s && s.audience ? ' to ' + clip(s.audience, 40) : '') };
|
|
417
|
+
const d = new Date(now), sameDay = localIso(now) === D.slot;
|
|
418
|
+
if (!sameDay || d.getHours() >= EVENING_HOUR) return { state: 'skipped', sub: 'Not sent by evening, so it is skipped. The next issue covers both weeks' };
|
|
419
|
+
return { state: 'late', sub: 'Waits for you since ' + time + (d.getHours() >= REFRESH_HOUR ? ' · numbers refreshed after 14:00' : ''), refresh: d.getHours() >= REFRESH_HOUR };
|
|
420
|
+
}
|
|
421
|
+
if (o.quiet) return { state: 'skipped', sub: 'Nothing moved this week, so I skipped it' };
|
|
422
|
+
if (!o.on) return { state: 'off', sub: o.kind === 'weekly' ? 'Off · drafts only in a week with news' : 'Off' };
|
|
423
|
+
if (o.kind === 'weekly') return { state: 'scheduled', sub: sch ? (DAYS3[sch.day] || 'Weekly') + ' ' + time + (s.audience ? ' · ' + clip(s.audience, 40) : '') : 'Weekly' };
|
|
424
|
+
return { state: 'scheduled', sub: (MOMENT_SUB[o.level] || MOMENT_SUB.product)[o.kind] || 'Drafts at its moment' };
|
|
425
|
+
}
|
|
426
|
+
function dueAt(slot, time) { const t = dayMs(slot); if (t === null) return null; const m = /^(\d{1,2}):(\d{2})$/.exec(String(time || '09:00')) || [0, 9, 0]; const d = new Date(slot + 'T00:00:00'); d.setHours(+m[1], +m[2], 0, 0); return d.getTime(); }
|
|
427
|
+
|
|
428
|
+
/** The Reports block's rows for one scope (PbA1 "Weekly update · Drafted · goes Mon 09:00 to 6 people", then "N more").
|
|
429
|
+
* o: { scope, level, name, st (fold), setups: [setup with ready], docsOf(setupId) → [doc] newest last, now, stale, paused, closed, picked, headsUps: [{ id, title, sub, audience, channel, cadence, slot, path, sha }] } */
|
|
430
|
+
function rowsFor(o) {
|
|
431
|
+
const out = [];
|
|
432
|
+
for (const kind of KINDS) {
|
|
433
|
+
const setup = (o.setups || []).find((s) => s && s.ready && s.ready.scope === o.scope && s.ready.kind === kind) || null;
|
|
434
|
+
const sw = switchOf(o.st, o.scope, kind);
|
|
435
|
+
const on = sw !== undefined ? sw : kind === 'weekly' ? !!o.picked : true;
|
|
436
|
+
const docs = setup && typeof o.docsOf === 'function' ? o.docsOf(setup.id) : [];
|
|
437
|
+
const doc = docs.length ? docs[docs.length - 1] : null;
|
|
438
|
+
const key = keyOf(o.scope, kind);
|
|
439
|
+
const quiet = (o.st.quiet.get(key) || []).includes(localIso(fin(o.now) ? o.now : Date.now()));
|
|
440
|
+
const S = stateOfReport({ kind, level: o.level, on: on && (!setup || setup.status !== 'paused'), setup, doc, now: o.now, stale: o.stale, hold: doc ? o.st.holds.get(key + '|' + doc.slot) : null, paused: o.paused, closed: o.closed && kind !== 'did-it-work' ? true : o.closed && !doc, quiet, auto: !!(doc && doc.auto) });
|
|
441
|
+
out.push({ id: setup ? setup.id : setupIdOf(o.scope, kind), key, kind, name: kindName(o.level, kind), state: S.state, sub: S.sub, on,
|
|
442
|
+
...(doc ? { path: doc.path, cadence: setup.id, slot: doc.slot, sha: doc.sha || null } : {}), ...(setup && setup.schedule && setup.schedule.day ? { day: setup.schedule.day } : {}),
|
|
443
|
+
...(S.refresh ? { refresh: true } : {}), trust: o.st.trust.get(key) === true });
|
|
444
|
+
}
|
|
445
|
+
for (const h of o.headsUps || []) out.unshift({ id: h.id, key: keyOf(o.scope, 'heads-up'), kind: 'heads-up', name: 'Heads-up', state: h.issued ? 'sent' : 'drafted', title: h.title, sub: h.sub, audience: h.audience || 'sponsors', channel: h.channel || 'mail', path: h.path, cadence: h.cadence, slot: h.slot, sha: h.sha || null, on: true });
|
|
446
|
+
// the block shows what is live first; a row that is off is folded by the UI under "N more"
|
|
447
|
+
const rank = { 'heads-up': 0, held: 1, late: 2, drafted: 3, sent: 4, scheduled: 5, skipped: 6, paused: 7, stopped: 8, off: 9 };
|
|
448
|
+
return out.sort((a, b) => (a.kind === 'heads-up' ? -1 : b.kind === 'heads-up' ? 1 : (rank[a.state] - rank[b.state])));
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** The product's weekly update is the one Home already keeps (lib/routes-home-desk.js: recipients and the weeks sent). Until a ready weekly is set up,
|
|
452
|
+
* the product's weekly row reads it: ready to send this week, or sent. `desk: true` says the page opens Home's own update, not a document. */
|
|
453
|
+
function withDesk(rows, desk, { now = Date.now(), hasSetup = false, off = false } = {}) {
|
|
454
|
+
if (!desk || hasSetup || off) return rows; // Home offers the product's weekly update every week, with or without recipients (pm/home-data.js productCard)
|
|
455
|
+
const wk = mondayOf(now), sent = desk.sent.find((x) => x && x.week === wk);
|
|
456
|
+
const to = desk.recipients.length ? ' to ' + clip(desk.recipients.slice(0, 2).join(', ') + (desk.recipients.length > 2 ? ' and ' + (desk.recipients.length - 2) + ' more' : ''), 60) : '';
|
|
457
|
+
return rows.map((r) => (r.kind !== 'weekly' ? r : { ...r, on: true, desk: true, state: sent ? 'sent' : 'drafted', sub: sent ? 'Sent ' + whenTxt(sent.at, now) + (sent.to && sent.to.length ? ' to ' + clip(sent.to.join(', '), 40) : '') : 'Ready to send this week' + to, week: wk }));
|
|
458
|
+
}
|
|
459
|
+
function mondayOf(now) { const d = new Date(now); d.setHours(0, 0, 0, 0); d.setDate(d.getDate() - ((d.getDay() + 6) % 7)); return localIso(d.getTime()); }
|
|
460
|
+
|
|
461
|
+
/** The goals a scope's initiatives anchor to that have no KR metric record of their own (a KR id or a health budget, as Home's product card counts
|
|
462
|
+
* them, pm/home-data.js productCard): one row per anchor, behind when one of its initiatives is late, at risk, stalled or blocked. No number: it
|
|
463
|
+
* has no reading. */
|
|
464
|
+
function anchorGoalsOf(rows, covered) {
|
|
465
|
+
const by = new Map();
|
|
466
|
+
for (const r of rows || []) {
|
|
467
|
+
if (!r || ['done', 'cancelled'].includes(String(r.status || '').toLowerCase()) || r.archived) continue;
|
|
468
|
+
const full = String(r.anchor || '').trim(), a = String(r.kr || BP.krShort(full) || '').trim(); // grouped as Home groups them: "KR 1.2", "Health budget"
|
|
469
|
+
if (!a || covered.has(full) || covered.has(a)) continue;
|
|
470
|
+
if (!by.has(a)) by.set(a, []);
|
|
471
|
+
by.get(a).push(r);
|
|
472
|
+
}
|
|
473
|
+
return [...by.entries()].map(([a, L]) => {
|
|
474
|
+
const bad = L.filter((r) => r.late || /risk|late|stalled|blocked/.test(String(r.status || '').toLowerCase()));
|
|
475
|
+
const health = a === 'Health budget' || /^health:/.test(a);
|
|
476
|
+
return { id: a, title: /^health:/.test(a) ? a.slice(7) + ' health budget' : a, ...(health ? { budget: true } : {}), owner: '', dot: bad.length ? 'behind' : 'on', from: 'anchor',
|
|
477
|
+
sub: bad.length ? clip(bad[0].title || bad[0].id, 50) + ' is ' + (bad[0].late ? 'running late' : String(bad[0].status || 'at risk').toLowerCase()) : 'No reading yet · ' + plural(L.length, 'initiative is', 'initiatives are') + ' on their dates' };
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** ⋯ › Reports and dashboards (PbA6). o: { scopes: [{ scope, level, name, hand?, news? }], st, setups, yours: [setup] }
|
|
482
|
+
* → { lead, groups: [{ scope, level, name, rows, more? }], yours, overlap } */
|
|
483
|
+
function libraryOf(o) {
|
|
484
|
+
const st = o.st, scopes = (o.scopes || []).filter(isObj);
|
|
485
|
+
const picks = new Map(picksOf(scopes).map((p) => [p.scope, p]));
|
|
486
|
+
const row = (s, kind) => {
|
|
487
|
+
const sw = switchOf(st, s.scope, kind), p = picks.get(s.scope);
|
|
488
|
+
const on = sw !== undefined ? sw : kind === 'weekly' ? p.pick : true;
|
|
489
|
+
const setup = (o.setups || []).find((x) => x && x.ready && x.ready.scope === s.scope && x.ready.kind === kind) || null;
|
|
490
|
+
const sub = kind === 'weekly' ? (on ? [setup && setup.schedule ? DAYS3[setup.schedule.day] || 'Weekly' : s.hand && s.hand.schedule && s.hand.schedule.day ? DAYS3[s.hand.schedule.day] : 'Mondays', setup && setup.audience ? clip(setup.audience, 40) : s.hand ? clip(s.hand.audience || '', 40) : '', p.why].filter(Boolean).join(' · ') : 'Off · drafts only in a week with news')
|
|
491
|
+
: on ? (s.level === 'product' && kind === 'checkpoint' && s.quarterEnd ? 'Drafts ' + short(s.quarterEnd) + ' from the quarter score' : MOMENT_SUB[s.level][kind]) : 'Off';
|
|
492
|
+
return { scope: s.scope, kind, name: kind === 'weekly' && s.hand && s.hand.name ? clip(s.hand.name, 60) : kindName(s.level, kind), sub, pick: kind === 'weekly' && p.pick, on, trust: st.trust.get(keyOf(s.scope, kind)) === true };
|
|
493
|
+
};
|
|
494
|
+
const groups = [];
|
|
495
|
+
for (const s of scopes.filter((x) => x.level !== 'initiative')) groups.push({ scope: s.scope, level: s.level, name: s.name, rows: KINDS.map((k) => row(s, k)) });
|
|
496
|
+
const inis = scopes.filter((x) => x.level === 'initiative');
|
|
497
|
+
if (inis.length) {
|
|
498
|
+
const weekly = inis.map((s) => ({ s, r: row(s, 'weekly') }));
|
|
499
|
+
const shown = weekly.filter((x) => x.r.on).map((x) => Object.assign(x.r, { name: 'Weekly update', sub: (inis.length > 1 ? 'Only ' + clip(x.s.name, 40) + ': ' : '') + (picks.get(x.s.scope).why || x.r.sub) }));
|
|
500
|
+
const off = weekly.filter((x) => !x.r.on);
|
|
501
|
+
const all = (kind) => { const sw = st.switches.has(keyOf('initiative:*', kind)) ? st.switches.get(keyOf('initiative:*', kind)) : true; return { scope: 'initiative:*', kind, name: kindName('initiative', kind), sub: sw ? MOMENT_SUB.initiative[kind] : 'Off', pick: false, on: sw, trust: false }; };
|
|
502
|
+
groups.push({ scope: 'initiative:*', level: 'initiative', name: plural(inis.length, 'initiative', 'initiatives'), rows: shown.concat([all('checkpoint'), all('did-it-work')]),
|
|
503
|
+
...(off.length ? { more: { count: off.length, text: (shown.length ? off.length + ' more weekly updates' : off.length === 1 ? '1 weekly update' : off.length + ' weekly updates'), sub: 'Off · they draft only in a week with news', rows: off.map((x) => Object.assign(x.r, { name: clip(x.s.name, 60) })) } } : {}) });
|
|
504
|
+
}
|
|
505
|
+
const total = scopes.length * KINDS.length;
|
|
506
|
+
const picked = [...picks.values()].filter((p) => p.pick).length;
|
|
507
|
+
const parts = [scopes.some((s) => s.level === 'program') ? 'program' : '', scopes.some((s) => s.level === 'product') ? 'product' : '', inis.length ? plural(inis.length, 'initiative', 'initiatives') : ''].filter(Boolean);
|
|
508
|
+
const lead = st.picks || !scopes.length ? null : { text: 'Your ' + (parts.length > 1 ? parts.slice(0, -1).join(', ') + ' and ' + parts[parts.length - 1] : parts[0]) + (scopes.length === 1 ? ' has' : ' each have') + ' a dashboard and 3 ready reports.',
|
|
509
|
+
rest: 'That is ' + plural(total, 'report', 'reports') + '. ' + (picked ? 'To keep your week light I\'d schedule only ' + picked + '; the rest draft when their moment comes, never on a timer.' : 'Each one drafts when its moment comes, never on a timer.'), keys: [...picks.values()].filter((p) => p.pick).map((p) => p.key) };
|
|
510
|
+
return { lead, groups, yours: (o.yours || []).filter((s) => s && !s.ready).map((s) => ({ id: s.id, name: s.name, sub: s.sub || '' })), overlap: o.overlap || null };
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** One person gets at most one update a week (PbG4). list: [{ key, scope, level, name, audience, day }] of the weekly reports that are on.
|
|
514
|
+
* A reader is a name in an audience ("Lee and 3 sponsors" names Lee; a count names nobody). The widest report (program, then product, then
|
|
515
|
+
* initiative) carries the narrower ones as short sections. → { lead, people: [{ who, sub }], carries: { [key]: [key] } } | null */
|
|
516
|
+
function overlapOf(list) {
|
|
517
|
+
const W = { program: 0, product: 1, initiative: 2 };
|
|
518
|
+
const by = new Map();
|
|
519
|
+
for (const r of (list || []).filter(isObj)) for (const who of readersOf(r.audience)) { if (!by.has(who)) by.set(who, []); by.get(who).push(r); }
|
|
520
|
+
const people = [], carries = {};
|
|
521
|
+
let first = null;
|
|
522
|
+
for (const [who, rs] of by) {
|
|
523
|
+
if (rs.length < 2) continue;
|
|
524
|
+
const sorted = rs.slice().sort((a, b) => W[a.level] - W[b.level]);
|
|
525
|
+
const top = sorted[0];
|
|
526
|
+
carries[top.key] = [...new Set((carries[top.key] || []).concat(sorted.slice(1).map((x) => x.key)))];
|
|
527
|
+
people.push({ who, sub: '1 update instead of ' + rs.length + ' · ' + clip(top.name, 40) + ', with ' + sorted.slice(1).map((x) => clip(x.name, 30)).join(' and ') + ' inside' });
|
|
528
|
+
if (!first) first = { who, rs: sorted };
|
|
529
|
+
}
|
|
530
|
+
if (!people.length) return null;
|
|
531
|
+
const others = (list || []).filter((r) => !Object.values(carries).flat().includes(r.key) && !carries[r.key]);
|
|
532
|
+
const allPeople = people.concat(others.map((r) => ({ who: clip(r.audience || r.name, 40), sub: clip(r.name, 40) + ' · as now' })));
|
|
533
|
+
return { lead: { text: first.who + ' would get ' + first.rs.length + ' updates from you' + (first.rs[0].day ? ' on ' + (DAY1[first.rs[0].day] || first.rs[0].day) : '') + ': ' + first.rs.map((x) => clip(x.name, 30)).join(', ') + '.',
|
|
534
|
+
rest: "I'd send " + first.who + ' one: the ' + first.rs[0].level + ' update, with the other' + (first.rs.length > 2 ? 's' : '') + ' as short sections in it.' }, people: allPeople, carries };
|
|
535
|
+
}
|
|
536
|
+
function readersOf(audience) {
|
|
537
|
+
return String(audience || '').split(/,|;|\band\b|&/i).map((s) => s.trim()).filter((s) => s && !/^\d+\b/.test(s) && !/\b(team|stakeholders|sponsors|people|everyone|all)\b/i.test(s) && s.length <= 40);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** "Send by itself" (PbG6). history: the issued documents of the report, oldest first, each { sha, draftSha }. Offered after 4 sent exactly as
|
|
541
|
+
* drafted, unless it is on already or the PM said no to it. → { offer: bool, on: bool } */
|
|
542
|
+
function trustOf(history, st, key) {
|
|
543
|
+
const on = st.trust.get(key) === true;
|
|
544
|
+
if (on || st.trustNo.has(key)) return { offer: false, on };
|
|
545
|
+
const last = (history || []).filter((h) => h && h.sha).slice(-TRUST_N);
|
|
546
|
+
return { offer: last.length === TRUST_N && last.every((h) => h.draftSha && h.draftSha === h.sha), on };
|
|
547
|
+
}
|
|
548
|
+
/** A calm week: no scorecard row off plan, no miss comment, no decision asked, no "looks green" refusal. Any of those holds it for the PM. */
|
|
549
|
+
function autoOk(markdown) {
|
|
550
|
+
const t = String(markdown || '');
|
|
551
|
+
if (/^## Your decision/m.test(t)) return false;
|
|
552
|
+
if (/^> \*\*[^*]+\*\* · Why:/m.test(t)) return false;
|
|
553
|
+
if (/\| (Behind|Over)[^|]*\|\s*$/m.test(t)) return false;
|
|
554
|
+
if (/^> .*will not call it green/m.test(t)) return false;
|
|
555
|
+
return true;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/** The sponsors' cut (PbG5): the answer, the three points, Your decision, and only the scorecard rows off plan with their comments. Made from
|
|
559
|
+
* the team draft's own text, so the numbers are the same. */
|
|
560
|
+
function sponsorsCut(markdown) {
|
|
561
|
+
const t = String(markdown || '').replace(/\r/g, '');
|
|
562
|
+
const fm = /^---\n[\s\S]*?\n---\n?/.exec(t), head = fm ? fm[0] : '', body = t.slice(head.length);
|
|
563
|
+
const lines = body.split('\n');
|
|
564
|
+
const out = [];
|
|
565
|
+
let i = 0;
|
|
566
|
+
while (i < lines.length && !/^## /.test(lines[i])) { out.push(lines[i]); i++; } // the title, the line under it, the three points
|
|
567
|
+
const secs = []; let cur = null;
|
|
568
|
+
for (; i < lines.length; i++) { const h = /^## (.*)$/.exec(lines[i]); if (h) { cur = { h: h[1], lines: [] }; secs.push(cur); } else if (cur) cur.lines.push(lines[i]); }
|
|
569
|
+
for (const s of secs) {
|
|
570
|
+
if (/^Your decision/i.test(s.h)) { out.push('## ' + s.h, ...s.lines); continue; }
|
|
571
|
+
const misses = s.lines.filter((l) => /^> \*\*/.test(l));
|
|
572
|
+
const offRows = s.lines.filter((l) => /^\| /.test(l) && /\| (Behind|Over)[^|]*\|\s*$/.test(l));
|
|
573
|
+
if (offRows.length) {
|
|
574
|
+
const hdr = s.lines.filter((l) => /^\| Metric \|/.test(l) || /^\|---/.test(l));
|
|
575
|
+
out.push('## ' + s.h, '', ...hdr, ...offRows, '', ...misses.flatMap((m) => [m, '']), ...s.lines.filter((l) => /^Source:/i.test(l)), '');
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
out.push('The team cut has every measure, milestone and source.', '');
|
|
579
|
+
return head.replace(/^status: draft$/m, 'status: draft').replace(/^title: "(.*)"$/m, (m, x) => `title: "${x} (sponsors)"`) + out.join('\n').replace(/\n{3,}/g, '\n\n');
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** The moments a checkpoint or Did it work? drafts at (PbSet). f: { today, row, rows, program, checklist, quarterEnd, launches }
|
|
583
|
+
* → [{ kind, why, slot }]; the caller drafts each one once (the `moment` line keeps it). */
|
|
584
|
+
function momentsOf(level, f) {
|
|
585
|
+
const today = f.today, out = [];
|
|
586
|
+
if (level === 'initiative' && f.row) {
|
|
587
|
+
const i = idxOf(f.row);
|
|
588
|
+
const items = (f.checklist || []).filter(isObj);
|
|
589
|
+
if (i >= 0 && i < 4 && items.length && items.every((c) => c.done)) out.push({ kind: 'checkpoint', why: 'stage:' + BP.STEPS[i].key, slot: today });
|
|
590
|
+
if (i >= 6 && dayMs(f.row.end) !== null && days(f.row.end, today) >= WINDOW_DAYS) out.push({ kind: 'did-it-work', why: 'launch:' + String(f.row.end).slice(0, 10), slot: today });
|
|
591
|
+
}
|
|
592
|
+
if (level === 'program' && f.program) {
|
|
593
|
+
for (const m of f.program.milestones || []) if (m && (m.done || (m.date && dayMs(m.date) <= dayMs(today) && days(m.date, today) <= 7))) out.push({ kind: 'checkpoint', why: 'milestone:' + m.id, slot: today });
|
|
594
|
+
if (f.program.archived || f.program.closed) out.push({ kind: 'did-it-work', why: 'closed', slot: today });
|
|
595
|
+
}
|
|
596
|
+
if (level === 'product') {
|
|
597
|
+
if (f.quarterEnd && dayMs(f.quarterEnd) >= dayMs(today) && days(today, f.quarterEnd) <= 14) out.push({ kind: 'checkpoint', why: 'quarter:' + f.quarterEnd, slot: today });
|
|
598
|
+
for (const r of f.rows || []) if (idxOf(r) >= 6 && dayMs(r.end) !== null && days(r.end, today) >= 0 && days(r.end, today) <= 7) out.push({ kind: 'did-it-work', why: 'launch:' + r.id, slot: today });
|
|
599
|
+
}
|
|
600
|
+
return out;
|
|
601
|
+
}
|
|
602
|
+
/** The end of the quarter `today` is in. */
|
|
603
|
+
function quarterEndOf(today) { const t = dayMs(today); if (t === null) return null; const d = new Date(t); const m = Math.floor(d.getUTCMonth() / 3) * 3 + 3; return isoOf(Date.UTC(d.getUTCFullYear(), m, 0)); }
|
|
604
|
+
|
|
605
|
+
/** Did anything move in the week before `today`: a ticket closed, a goal read, or an open decision. A weekly with nothing moved is skipped. */
|
|
606
|
+
function movedOf({ today, tickets, goals, needs }) {
|
|
607
|
+
const t = dayMs(today), wk = (iso) => { const x = dayMs(iso); return x !== null && x <= t && t - x < 7 * DAY; };
|
|
608
|
+
return (tickets || []).some((x) => x && x.category === 'done' && wk(x.resolved)) || (goals || []).some((g) => (g.series || []).some((r) => wk(r.at))) || !!(needs && needs.length);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
module.exports = {
|
|
612
|
+
LEDGER, EVENTS, LEVELS, KINDS, HOLD_ACTS, SCOPE_RE, KEY_RE, STALE_MS, TRUST_N,
|
|
613
|
+
parseScope, keyOf, kindName, setupIdOf, ledgerFile, readLines, append, checkLine, fold, stateOf, switchOf,
|
|
614
|
+
forecastOf, dotOf, usualDays, promiseOf, goalsOf, stageOf, looksGreen, headsUpOf, handledOf, dashboardOf,
|
|
615
|
+
picksOf, stateOfReport, rowsFor, withDesk, anchorGoalsOf, libraryOf, overlapOf, readersOf, trustOf, autoOk, sponsorsCut, momentsOf, quarterEndOf, movedOf,
|
|
616
|
+
};
|