create-pmos 0.396.0 → 0.398.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 +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/nine-stages.js +49 -20
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +103 -74
- package/workspace/briefing-premium-board-test.js +316 -154
- package/workspace/briefing-premium-calendar-2-test.js +135 -195
- package/workspace/briefing-premium-calendar-3-test.js +143 -413
- package/workspace/briefing-premium-calendar-test.js +86 -185
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +166 -294
- package/workspace/briefing-premium-insights-test.js +351 -214
- package/workspace/briefing-premium-metrics-test.js +53 -118
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +91 -52
- package/workspace/briefing-premium-test.js +150 -633
- package/workspace/briefing-premium-work-test.js +88 -269
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-premium-facts.js +2 -1
- package/workspace/fixtures/board-premium-jira.js +28 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/initiative-premium-facts.js +2 -1
- package/workspace/fixtures/initiatives-api/list.json +30 -42
- package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
- package/workspace/fixtures/initiatives-api/sheet.json +10 -14
- package/workspace/fixtures/insights-premium-facts.js +11 -2
- package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +47 -0
- package/workspace/guide/index.md +2 -0
- package/workspace/guide/lifecycle.md +51 -0
- package/workspace/home-shot.js +38 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +160 -3
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/engine/boards.js +15 -14
- package/workspace/lib/engine/nine-stages.js +49 -20
- package/workspace/lib/engine/signals/detectors.js +13 -11
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +126 -1
- package/workspace/lib/insights-records.js +101 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-board-premium.js +3 -2
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-initiatives.js +1 -1
- package/workspace/lib/routes-insights-premium.js +19 -3
- package/workspace/lib/routes-insights-records.js +129 -0
- package/workspace/lib/routes-notes.js +1 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/vendor/scripts/nine-stages.js +49 -20
- package/workspace/lib/viewer-meeting.js +205 -0
- package/workspace/lib/viewer-report.js +89 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-agreed-viewer-shots.js +76 -0
- package/workspace/premium-board-actions-test.js +85 -73
- package/workspace/premium-briefing-depth-test.js +66 -53
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +35 -36
- package/workspace/premium-chat-context-test.js +22 -19
- package/workspace/premium-chat-goal-view-test.js +28 -26
- package/workspace/premium-chat-notes-test.js +29 -33
- package/workspace/premium-chat-report-tab-test.js +35 -25
- package/workspace/premium-chat-term-test.js +16 -14
- package/workspace/premium-chat-viewer-test.js +60 -53
- package/workspace/premium-core-doc-issue-test.js +50 -41
- package/workspace/premium-html-viewer-test.js +17 -18
- package/workspace/premium-phone-card-test.js +8 -2
- package/workspace/premium-phone-room-test.js +42 -31
- package/workspace/premium-report-read-test.js +115 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -31
- package/workspace/premium-vw-cal-test.js +82 -123
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +12 -11
- package/workspace/premium-vw-item-test.js +50 -48
- package/workspace/premium-vw-jira-test.js +55 -26
- package/workspace/premium-vw-meet-test.js +118 -187
- package/workspace/premium-vw-notes-test.js +85 -107
- package/workspace/premium-vw-rec-test.js +72 -193
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +63 -51
- package/workspace/public/pm/bd-acts.js +305 -0
- package/workspace/public/pm/bd-span.js +224 -0
- package/workspace/public/pm/bd-stages.js +47 -0
- package/workspace/public/pm/c3-doc-sheet.js +1 -1
- package/workspace/public/pm/c3-md.js +3 -395
- package/workspace/public/pm/c3-phone-detail.js +1 -1
- package/workspace/public/pm/c3-phone-model.js +3 -68
- package/workspace/public/pm/chat-term.js +3 -3
- package/workspace/public/pm/cozy-board.css +640 -0
- package/workspace/public/pm/cozy-home.css +580 -0
- package/workspace/public/pm/cozy-home.js +172 -0
- package/workspace/public/pm/cozy-initiative.css +138 -0
- package/workspace/public/pm/cozy-insights.css +421 -0
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +65 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +143 -0
- package/workspace/public/pm/cozy-viewer.js +144 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +254 -0
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +905 -0
- package/workspace/public/pm/home-around.js +515 -0
- package/workspace/public/pm/home-chat.js +459 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-more.js +249 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-work.js +519 -0
- package/workspace/public/pm/lifecycle-lens-model.js +45 -27
- package/workspace/public/pm/lifecycle-lens.js +22 -11
- package/workspace/public/pm/phone-moment.js +69 -0
- package/workspace/public/pm/pm-work-view.js +1 -1
- package/workspace/public/pm/premium-attach.js +4 -0
- package/workspace/public/pm/premium-board.js +544 -253
- package/workspace/public/pm/premium-brief.js +1 -1
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-chat.js +17 -10
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-initiative-head.js +138 -0
- package/workspace/public/pm/premium-initiative.js +28 -4
- package/workspace/public/pm/premium-insights.js +950 -440
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +509 -480
- package/workspace/public/pm/premium-report-tab.js +87 -63
- package/workspace/public/pm/premium-shell.js +107 -124
- package/workspace/public/pm/premium-viewer.js +27 -1
- package/workspace/public/pm/premium-vw-cal.js +187 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-jira-model.js +22 -5
- package/workspace/public/pm/premium-vw-jira.css +11 -0
- package/workspace/public/pm/premium-vw-jira.js +11 -4
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +731 -0
- package/workspace/public/pm/premium-vw-notes.js +56 -69
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -215
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +57 -64
- package/workspace/public/premium-chat.html +7 -33
- package/workspace/public/premium-initiative.html +8 -41
- package/workspace/public/premium-insights.html +63 -62
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium-work.html +6 -72
- package/workspace/public/premium.html +21 -66
- package/workspace/public/vendor/nunito-var.woff2 +0 -0
- package/workspace/server.js +25 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/premium-agreed-viewer.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/third-party/README.md +1 -0
- package/workspace/public/pm/premium-work.js +0 -719
- package/workspace/public/pm/premium.js +0 -1133
|
@@ -1,40 +1,63 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/*
|
|
3
|
-
* The
|
|
3
|
+
* The lifecycle label layer over the workflow engine's derived stage: six stages and two milestones
|
|
4
|
+
* (premium-agreed-design L1, PM decision 2026-10-22). The file keeps its old name and export names
|
|
5
|
+
* (`nineStages`, `STAGES`, `LABELS`, `LANE_STAGES`) so that every caller keeps working; the
|
|
6
|
+
* `nine_stages` field on a row keeps its name for the same reason. It now carries eight entries.
|
|
7
|
+
*
|
|
8
|
+
* Triage (BRD) → Discover (PRD) → Plan (scope, timeline, WBS; the PM's Commit pushes tickets to Jira)
|
|
9
|
+
* → Prioritize (ranked on the roadmap) → Build (features delivered, Jira) → ◆ Deliver (milestone:
|
|
10
|
+
* release shipped, PM sign-off) → Monitor (outcome report) → ◆ Evaluate (milestone: keep, iterate or stop)
|
|
4
11
|
*
|
|
5
12
|
* The engine derives one of six rungs (intake, spec, contract, build, eval, accepted) from the steps
|
|
6
|
-
* it found. This file names the
|
|
7
|
-
*
|
|
8
|
-
*
|
|
13
|
+
* it found. This file names the stages the PM sees and says which of them each lane uses. It never
|
|
14
|
+
* decides a stage itself: a stage is `done` only when a derived signal shows it, and a stage no record
|
|
15
|
+
* can yet show is `no-signal`, not guessed.
|
|
9
16
|
*
|
|
10
|
-
*
|
|
17
|
+
* Migration: the old nine had Ideate and Strategize. Stage is derived, never stored, so there is no
|
|
18
|
+
* stored stage to rewrite. Records that signalled Ideate (ideas, hypotheses) now count for Discover;
|
|
19
|
+
* records that signalled Strategize (decisions, bets) now count for Prioritize. `stageKey` maps an
|
|
20
|
+
* old key read from anywhere (a stored payload, a URL, a fixture) to its new key at read time.
|
|
11
21
|
*/
|
|
12
22
|
|
|
13
|
-
const STAGES = ['
|
|
23
|
+
const STAGES = ['triage', 'discover', 'plan', 'prioritize', 'build', 'deliver', 'monitor', 'evaluate'];
|
|
14
24
|
|
|
15
25
|
const LABELS = {
|
|
16
|
-
|
|
26
|
+
triage: 'Triage', discover: 'Discover', plan: 'Plan', prioritize: 'Prioritize',
|
|
17
27
|
build: 'Build', deliver: 'Deliver', monitor: 'Monitor', evaluate: 'Evaluate',
|
|
18
28
|
};
|
|
19
29
|
|
|
30
|
+
// What each stage produces (the PM's words on the Agreed design).
|
|
31
|
+
const OUTPUTS = {
|
|
32
|
+
triage: 'BRD', discover: 'PRD', plan: 'Scope, timeline and work breakdown', prioritize: 'Ranked on the roadmap',
|
|
33
|
+
build: 'Features delivered (Jira)', deliver: 'Release shipped, PM sign-off', monitor: 'Outcome report', evaluate: 'Keep, iterate or stop',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Deliver and Evaluate are milestones (drawn as a diamond), not stages with duration.
|
|
37
|
+
const MILESTONES = new Set(['deliver', 'evaluate']);
|
|
38
|
+
|
|
39
|
+
// The removed keys and where they went. Read-time only: nothing stored is rewritten.
|
|
40
|
+
const LEGACY = { ideate: 'discover', strategize: 'prioritize' };
|
|
41
|
+
const stageKey = (k) => (k == null ? k : LEGACY[k] || k);
|
|
42
|
+
|
|
20
43
|
// Which stages each product-code lane uses. Stages not listed read `skipped`.
|
|
21
44
|
const LANE_STAGES = {
|
|
22
45
|
feature: STAGES,
|
|
23
|
-
discovery: ['
|
|
24
|
-
chore: ['plan', 'build', 'evaluate'],
|
|
46
|
+
discovery: ['triage', 'discover', 'prioritize', 'evaluate'],
|
|
47
|
+
chore: ['plan', 'build', 'deliver', 'evaluate'],
|
|
25
48
|
incident: ['build', 'deliver', 'monitor', 'evaluate'],
|
|
26
|
-
content: ['
|
|
27
|
-
prototype: ['
|
|
49
|
+
content: ['discover', 'plan', 'build', 'deliver'],
|
|
50
|
+
prototype: ['triage', 'discover', 'evaluate'],
|
|
28
51
|
};
|
|
29
52
|
|
|
30
53
|
// Stages that have a derived signal today. Every other stage reads `no-signal` until its record exists.
|
|
31
|
-
const SIGNALLED = new Set(['discover', 'plan', 'build', 'evaluate']);
|
|
54
|
+
const SIGNALLED = new Set(['triage', 'discover', 'plan', 'build', 'evaluate']);
|
|
32
55
|
|
|
33
56
|
const RANK = { intake: 0, spec: 1, contract: 2, build: 3, eval: 4, accepted: 5 };
|
|
34
57
|
|
|
35
58
|
// Stages that gain a signal only when the caller passes the records (scripts/records readAll plus optional `releases`).
|
|
36
|
-
// With no records the output is exactly the
|
|
37
|
-
const RECORD_SIGNALLED = new Set(['
|
|
59
|
+
// With no records the output is exactly the records-free output, so the lifecycle-lens mirror stays equal.
|
|
60
|
+
const RECORD_SIGNALLED = new Set(['discover', 'prioritize', 'monitor', 'deliver']);
|
|
38
61
|
|
|
39
62
|
// records: { initiative?, anchor?, ideas, hypotheses, decisions, bets, 'kr-metrics', releases } (every list optional).
|
|
40
63
|
// The initiative id and anchor come from `derived` (id, anchor) or from records.initiative / records.anchor.
|
|
@@ -43,10 +66,12 @@ function recordSignals(derived, records, buildDone) {
|
|
|
43
66
|
const anchor = (derived && derived.anchor) || records.anchor || null;
|
|
44
67
|
const mine = (list) => (list || []).filter((r) => id && r.initiative === id);
|
|
45
68
|
const kr = (records['kr-metrics'] || []).filter((m) => anchor && (m.rid === anchor || m.parent_kr === anchor || 'kr:' + m.rid === anchor));
|
|
69
|
+
const ranked = mine(records.bets).some((b) => ['now', 'next', 'later'].includes(b.horizon) && Number.isInteger(b.rank));
|
|
46
70
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
// was Ideate: an idea or hypothesis on the initiative
|
|
72
|
+
discover: mine(records.ideas).length + mine(records.hypotheses).length > 0,
|
|
73
|
+
// was Strategize (a decision or bet) or the old Prioritize (a ranked bet)
|
|
74
|
+
prioritize: ranked || mine(records.decisions).length + mine(records.bets).length > 0,
|
|
50
75
|
monitor: !!buildDone && kr.some((m) => (m.readings || []).length > 0),
|
|
51
76
|
deliver: mine(records.releases).length > 0,
|
|
52
77
|
};
|
|
@@ -57,6 +82,7 @@ function nineStages(lane, derived, records) {
|
|
|
57
82
|
const rank = RANK[derived && derived.stage] ?? 0;
|
|
58
83
|
const step = (key) => (derived && derived.steps || []).find((s) => s.key === key);
|
|
59
84
|
const done = {
|
|
85
|
+
triage: rank >= 1,
|
|
60
86
|
discover: rank >= 1,
|
|
61
87
|
plan: rank >= 2,
|
|
62
88
|
build: rank >= 3 || (step('build') && step('build').status === 'done'),
|
|
@@ -64,18 +90,21 @@ function nineStages(lane, derived, records) {
|
|
|
64
90
|
};
|
|
65
91
|
const accepted = rank >= 5;
|
|
66
92
|
const fromRecords = records && typeof records === 'object' ? recordSignals(derived, records, done.build) : null;
|
|
93
|
+
const signalled = (key) => SIGNALLED.has(key) || (fromRecords && RECORD_SIGNALLED.has(key) && (key !== 'deliver' || fromRecords.deliver));
|
|
67
94
|
const out = [];
|
|
68
95
|
let currentSet = false;
|
|
69
96
|
for (const key of STAGES) {
|
|
70
97
|
let status;
|
|
71
98
|
if (!laneSet.has(key)) status = 'skipped';
|
|
72
|
-
else if (!
|
|
99
|
+
else if (!signalled(key)) status = 'no-signal';
|
|
73
100
|
else if (done[key] || (fromRecords && fromRecords[key])) status = 'done';
|
|
74
101
|
else status = 'pending';
|
|
75
102
|
if (status === 'pending' && !currentSet) { status = 'current'; currentSet = true; }
|
|
76
|
-
|
|
103
|
+
const entry = { key, label: LABELS[key], status, accepted: key === 'evaluate' ? accepted : undefined };
|
|
104
|
+
if (MILESTONES.has(key)) entry.milestone = true;
|
|
105
|
+
out.push(entry);
|
|
77
106
|
}
|
|
78
107
|
return out;
|
|
79
108
|
}
|
|
80
109
|
|
|
81
|
-
module.exports = { STAGES, LABELS, LANE_STAGES, nineStages };
|
|
110
|
+
module.exports = { STAGES, LABELS, OUTPUTS, MILESTONES, LEGACY, LANE_STAGES, stageKey, nineStages, lifecycleStages: nineStages };
|
|
@@ -202,6 +202,8 @@ reg('work', 'work.mis-lensed', (f) => f.work.filter((w) => w.lens === 'later' &&
|
|
|
202
202
|
})));
|
|
203
203
|
|
|
204
204
|
// ---------- INITIATIVES: lifecycle lenses ----------
|
|
205
|
+
// premium-agreed-design L1: Ideate folded into Discover and Strategize into Prioritize. The detector ids (ideate.*, strategize.*) are kept as
|
|
206
|
+
// stable identifiers, because kinds.js and recorded dismissals name them; only the page they belong to moved.
|
|
205
207
|
reg('discover', 'discover.untraced-evidence', (f) => f.hyps.flatMap((h) => {
|
|
206
208
|
const miss = h.evidence.filter((e) => !f.docs[e.src]);
|
|
207
209
|
const tot = sum(h.evidence.map((e) => e.w)) || 1;
|
|
@@ -217,27 +219,27 @@ reg('discover', 'discover.stale-evidence', (f) => Object.entries(f.docs).filter(
|
|
|
217
219
|
reg('discover', 'discover.open-hypothesis', (f) => f.hyps.filter((h) => { const n = sum(h.evidence.map((e) => (e.dir === 'supports' ? e.w : -e.w))); return n < 3 && n > -2; }).map((h) => s({
|
|
218
220
|
id: 'discover.open:' + h.slug, page: 'discover', key: 'hyp:' + h.slug, entity: h.slug, magnitude: 0.4, deadlineDays: 21, child: true, title: `"${h.title}" is still open`, facts: [],
|
|
219
221
|
})));
|
|
220
|
-
reg('
|
|
221
|
-
id: 'ideate.quick:' + i.slug, page: '
|
|
222
|
+
reg('discover', 'ideate.quick-win', (f) => f.ideas.filter((i) => i.effort <= 2 && i.score >= 1.5).map((i) => s({
|
|
223
|
+
id: 'ideate.quick:' + i.slug, page: 'discover', key: 'idea:' + i.slug, entity: i.slug, magnitude: Math.min(1, i.score / 3), deadlineDays: 30, shape: 'rows',
|
|
222
224
|
title: `${i.title}: score ${i.score} for effort ${i.effort}, not on the roadmap`, facts: ['impact ' + i.impact, 'confidence ' + i.confidence],
|
|
223
225
|
})));
|
|
224
|
-
reg('
|
|
225
|
-
id: 'ideate.unanchored:' + i.slug, page: '
|
|
226
|
+
reg('discover', 'ideate.unanchored', (f) => f.ideas.filter((i) => !i.parent_kr).map((i) => s({
|
|
227
|
+
id: 'ideate.unanchored:' + i.slug, page: 'discover', key: 'idea:' + i.slug, entity: i.slug, magnitude: 0.5, deadlineDays: 14, title: `${i.title} has no KR anchor`, facts: [],
|
|
226
228
|
})));
|
|
227
|
-
reg('
|
|
229
|
+
reg('discover', 'ideate.concentration', (f) => {
|
|
228
230
|
if (f.ideas.length < 4) return [];
|
|
229
231
|
const by = {}; f.ideas.forEach((i) => { by[i.parent_kr] = (by[i.parent_kr] || 0) + 1; });
|
|
230
232
|
const [k, n] = Object.entries(by).sort((a, b) => b[1] - a[1])[0];
|
|
231
|
-
return n === f.ideas.length ? [s({ id: 'ideate.concentration', page: '
|
|
233
|
+
return n === f.ideas.length ? [s({ id: 'ideate.concentration', page: 'discover', key: 'concentration', entity: k, magnitude: 0.4, deadlineDays: 30, title: `All ${n} ideas aim at one KR (${k}); nothing explores the others`, facts: [] })] : [];
|
|
232
234
|
});
|
|
233
|
-
reg('
|
|
234
|
-
reg('
|
|
235
|
-
id: 'strategize.unanchored:' + i.id, page: '
|
|
235
|
+
reg('prioritize', 'strategize.kr-deviation', (f) => REG.find((d) => d.id === 'cal.kr-deviation').fn(f).map((x) => ({ ...x, page: 'prioritize' })));
|
|
236
|
+
reg('prioritize', 'strategize.unanchored', (f) => f.inis.filter((i) => !i.done && !i.parent_kr).map((i) => s({
|
|
237
|
+
id: 'strategize.unanchored:' + i.id, page: 'prioritize', key: 'anchor:' + i.id, entity: i.id, magnitude: 0.5, deadlineDays: 14, policyCritical: true, shape: 'rows',
|
|
236
238
|
title: `${i.title} has no KR or health budget`, facts: ['horizon ' + i.horizon],
|
|
237
239
|
})));
|
|
238
|
-
reg('
|
|
240
|
+
reg('prioritize', 'strategize.single-bet', (f) => {
|
|
239
241
|
const now = f.inis.filter((i) => i.horizon === 'now');
|
|
240
|
-
return now.length === 1 && f.inis.length >= 3 ? [s({ id: 'strategize.single-bet', page: '
|
|
242
|
+
return now.length === 1 && f.inis.length >= 3 ? [s({ id: 'strategize.single-bet', page: 'prioritize', key: 'bets', entity: 'portfolio', magnitude: 0.4, deadlineDays: 30, strategic: true, title: `Everything in flight rides on one bet (${now[0].title}); ${f.inis.length - 1} others are Next or Later`, facts: [] })] : [];
|
|
241
243
|
});
|
|
242
244
|
reg('prioritize', 'prioritize.capacity-free', (f) => {
|
|
243
245
|
const inflight = f.inis.filter((i) => i.horizon === 'now').length, CAP = 4;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* home-work-item.js — "Make a work-item" under a message in Home's chat (initiative premium-agreed-design, Home).
|
|
3
|
+
*
|
|
4
|
+
* makeFromChat(root, initiative, { text, key }) → { ok, ticket, created, draft } | { ok: false, status, error }
|
|
5
|
+
*
|
|
6
|
+
* The message's first line becomes a ticket Drafted in PMOS on the initiative (lib/jira-tickets.js's draft file), in the same form a
|
|
7
|
+
* meeting's next step takes (lib/viewer-meeting.js makeWorkItem): not approved and not pushed. Only the Commit gate pushes a ticket to
|
|
8
|
+
* Jira. The ticket's References name the chat it came from; a second press on the same text in the same chat makes no second ticket. */
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const crypto = require('crypto');
|
|
12
|
+
const VM = require('./viewer-meeting.js');
|
|
13
|
+
|
|
14
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
|
|
15
|
+
const KEY_RE = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,120}$/;
|
|
16
|
+
const line = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
17
|
+
const hashOf = (t) => crypto.createHash('sha256').update(line(t, 2000).toLowerCase()).digest('hex').slice(0, 8);
|
|
18
|
+
const REF = (key, h) => `- Chat: ${key} · message ${h}`;
|
|
19
|
+
|
|
20
|
+
function makeFromChat(root, initiative, { text, key } = {}) {
|
|
21
|
+
const T = require('./jira-tickets.js');
|
|
22
|
+
if (!root) return { ok: false, status: 409, error: 'the repository is not registered here' };
|
|
23
|
+
if (!ID_RE.test(String(initiative || ''))) return { ok: false, status: 400, error: 'this chat is not in an initiative: link it to one first' };
|
|
24
|
+
const k = KEY_RE.test(String(key || '')) ? String(key) : 'chat';
|
|
25
|
+
const first = String(text || '').split('\n').map((x) => x.replace(/^[#>*\-\s]+/, '')).find((x) => x.trim()) || '';
|
|
26
|
+
const summary = line(first, 200);
|
|
27
|
+
if (!summary) return { ok: false, status: 400, error: 'the message has no text' };
|
|
28
|
+
const rfm = T.recordFm(root, initiative);
|
|
29
|
+
if (!rfm) return { ok: false, status: 404, error: `no initiative ${initiative} in this repository` };
|
|
30
|
+
const h = hashOf(text);
|
|
31
|
+
const d = T.readDraft(root, initiative);
|
|
32
|
+
const had = ((d && d.tickets) || []).find((t) => String((t.sections && t.sections.refs) || '').includes(REF(k, h)));
|
|
33
|
+
if (had) return { ok: true, ticket: had.id, created: false };
|
|
34
|
+
const id = VM.nextTicketId(d ? d.tickets.map((x) => x.id) : [], rfm.title || initiative);
|
|
35
|
+
const t = { id, summary, type: 'Task', priority: 'Medium', sections: {} };
|
|
36
|
+
for (const [s] of T.SECTIONS) t.sections[s] = '';
|
|
37
|
+
t.sections.context = line(String(text).replace(/^\s*#+\s*/gm, ''), 1500); // a heading mark would read as a new ticket or section in the draft
|
|
38
|
+
t.sections.refs = REF(k, h);
|
|
39
|
+
t.drafted = T.contentHash(t);
|
|
40
|
+
const block = [`## ${t.id} · ${summary}`, `- type: ${t.type}`, `- priority: ${t.priority}`, `- drafted: ${t.drafted}`, ''];
|
|
41
|
+
for (const [s, head] of T.SECTIONS) block.push(`### ${head}`, '', String(t.sections[s] || '').trim() || '—', '');
|
|
42
|
+
const file = T.draftPath(root, initiative);
|
|
43
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
44
|
+
let text0 = '';
|
|
45
|
+
try { text0 = fs.readFileSync(file, 'utf8'); } catch { text0 = ''; }
|
|
46
|
+
if (!text0) {
|
|
47
|
+
const ts = new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
48
|
+
text0 = ['---', 'type: Reference', `title: "Jira tickets: ${initiative}"`, `timestamp: ${ts}`, '---', '', `# Jira tickets: ${initiative}`, '',
|
|
49
|
+
'Drafted in PMOS. Read and edit them on the initiative\'s Jira tickets tab, or here. Check the ones that are ready and press Push: only checked tickets are sent.', '',
|
|
50
|
+
'PMOS owns the text of these tickets and Jira owns their status.', ''].join('\n');
|
|
51
|
+
}
|
|
52
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
53
|
+
fs.writeFileSync(tmp, text0.replace(/\n*$/, '\n') + '\n' + block.join('\n'));
|
|
54
|
+
fs.renameSync(tmp, file);
|
|
55
|
+
return { ok: true, ticket: id, created: true, draft: T.draftRel(root, initiative) };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = { makeFromChat };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* insights-goals.js — the pure rules behind the premium Insights page's goals, budgets, trends and outcomes (initiative premium-agreed-design G1, G2).
|
|
3
|
+
* PURE: no I/O, no clock of its own. The route reads the files and passes `today` (a 'YYYY-MM-DD' day).
|
|
4
|
+
*
|
|
5
|
+
* GOAL_TYPES · DIRECTIONS · SOURCES
|
|
6
|
+
* goalFields(input, { today }) → { ok, fields } | { ok: false, error } the New goal form → the fields of one KR metric record (its date is `due`)
|
|
7
|
+
* checkpointsOf(base, target, from, by) → [{ by, target }] a yearly goal's quarter-end checkpoints, on the straight line
|
|
8
|
+
* describe(text, goals) → { name, question, goals: [id], range, said: [] } "Describe it, and PMOS fills this in", word for word
|
|
9
|
+
* parseBudgets(md) → [{ id, covers, cap }] the D59 registry (planning/okrs/health-budgets.md)
|
|
10
|
+
* budgetReading(budget, inits) → { n, total, share, over } the budget's share of the board's open initiatives, against its cap
|
|
11
|
+
* trendsOf(rows, today, weeks) → { late: { value, ser }, scope: { value, ser } } Late initiatives and Scope added for Delivery trends
|
|
12
|
+
* skippedOf(warnings) → [stage] the stages the Board recorded as skipped ("Skipped <stage>")
|
|
13
|
+
* windowOf({ shipAt, byAt, verdict, today }) → { opens, closes, state } an outcome's judgement window: from the ship date to the promise date
|
|
14
|
+
* evidenceOf(readings, shipAt, unit) → [text] what the readings say since the ship date
|
|
15
|
+
* periodHits(goals, from, to) → { n, hit } the goals due in a past period, and how many reached their target by then
|
|
16
|
+
* exportCsv(goals) → text the goals as CSV (Export in ⋯)
|
|
17
|
+
*
|
|
18
|
+
* NOTHING HERE MAKES A NUMBER UP. A checkpoint is the straight line from the baseline to the target, said as that. A budget reading is a count of
|
|
19
|
+
* initiatives. Scope added counts the initiatives whose planned start falls in a week. Evidence is the readings themselves. */
|
|
20
|
+
|
|
21
|
+
const GOAL_TYPES = Object.freeze(['Done or not', 'Percentage', 'Count', 'Amount', 'Duration', 'Stay within']);
|
|
22
|
+
const DIRECTIONS = Object.freeze({ Up: 'up', Down: 'down', 'Exactly the target': 'exact' });
|
|
23
|
+
const SOURCES = Object.freeze({ analytics: 'Product analytics', jira: 'Jira query', file: 'A file or export', typed: 'You type it in' });
|
|
24
|
+
const UNIT_OF = Object.freeze({ Percentage: '%', Duration: 'days', Amount: '$', Count: '' });
|
|
25
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
26
|
+
const STEPS_MAX = 12, TEXT_MAX = 120;
|
|
27
|
+
|
|
28
|
+
const fin = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
29
|
+
const tidy = (v, n = TEXT_MAX) => (typeof v === 'string' ? v.trim().replace(/\s+/g, ' ').slice(0, n) : '');
|
|
30
|
+
const toNum = (v) => (v === '' || v == null ? NaN : Number(v));
|
|
31
|
+
const ms = (d) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(d || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
32
|
+
const iso = (t) => new Date(t).toISOString().slice(0, 10);
|
|
33
|
+
const decimals = (v) => (String(v).split('.')[1] || '').length;
|
|
34
|
+
const round = (v, d) => { const k = 10 ** d; return Math.round(v * k) / k; };
|
|
35
|
+
const no = (error) => ({ ok: false, error });
|
|
36
|
+
|
|
37
|
+
/** A yearly goal's checkpoints: the end of each quarter after `from` and before `by`, with the target the straight line reaches there. */
|
|
38
|
+
function checkpointsOf(base, target, from, by) {
|
|
39
|
+
const t0 = ms(from), t1 = ms(by);
|
|
40
|
+
if (!fin(base) || !fin(target) || t0 === null || t1 === null || t1 <= t0) return [];
|
|
41
|
+
const d = Math.max(decimals(base), decimals(target), Math.abs(target - base) < 10 ? 1 : 0), out = [];
|
|
42
|
+
const y0 = new Date(t0).getUTCFullYear();
|
|
43
|
+
for (let y = y0; y <= new Date(t1).getUTCFullYear(); y++) {
|
|
44
|
+
for (const m of [3, 6, 9, 12]) {
|
|
45
|
+
const t = Date.UTC(y, m, 0);
|
|
46
|
+
if (t <= t0 || t >= t1) continue;
|
|
47
|
+
out.push({ by: iso(t), target: round(base + (target - base) * ((t - t0) / (t1 - t0)), d) });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The New goal form → the fields of one KR metric record. A KR metric needs a baseline, a target and a date, so:
|
|
54
|
+
* Done or not is stored as steps done, from 0 to the number of steps (1 when it has none), due on its date;
|
|
55
|
+
* Stay within is stored with its reading now as the baseline and its floor or ceiling as the target; always_on when it has no end. */
|
|
56
|
+
function goalFields(input, { today } = {}) {
|
|
57
|
+
const i = input && typeof input === 'object' ? input : {};
|
|
58
|
+
const name = tidy(i.name);
|
|
59
|
+
if (!name) return no('Give the goal a name.');
|
|
60
|
+
const type = GOAL_TYPES.includes(i.type) ? i.type : null;
|
|
61
|
+
if (!type) return no('Pick a type: ' + GOAL_TYPES.join(', ') + '.');
|
|
62
|
+
const dir = DIRECTIONS[i.direction] || null;
|
|
63
|
+
const always = type === 'Stay within' && i.always_on === true;
|
|
64
|
+
const due = i.due != null ? i.due : i.by; // the page sends `due`: a page press may not carry `by`, which names the writer (pm-guard)
|
|
65
|
+
const by = always ? (DATE.test(String(due || '')) ? due : (String(today || '').slice(0, 4) || new Date().getUTCFullYear()) + '-12-31') : String(due || '');
|
|
66
|
+
if (!DATE.test(by)) return no('Pick the date it is due.');
|
|
67
|
+
const f = { metric: name, type, by };
|
|
68
|
+
if (type === 'Done or not') {
|
|
69
|
+
const steps = (Array.isArray(i.steps) ? i.steps : []).map((s) => tidy(typeof s === 'string' ? s : s && s.text)).filter(Boolean);
|
|
70
|
+
if (steps.length > STEPS_MAX) return no(`A goal can have at most ${STEPS_MAX} steps.`);
|
|
71
|
+
Object.assign(f, { baseline: 0, target: Math.max(1, steps.length), unit: steps.length ? 'steps' : 'done', direction: 'up', steps: steps.map((text) => ({ text, done: false })) });
|
|
72
|
+
} else if (type === 'Stay within') {
|
|
73
|
+
const now = toNum(i.baseline), lim = toNum(i.target), kind = i.limit === 'floor' ? 'floor' : i.limit === 'ceiling' ? 'ceiling' : null;
|
|
74
|
+
if (!fin(now) || !fin(lim)) return no('Type a number for the reading now and for the limit.');
|
|
75
|
+
if (!kind) return no('Say whether the limit is a floor or a ceiling.');
|
|
76
|
+
if (now === lim) return no('The reading now must differ from the limit, so the room left can be read.');
|
|
77
|
+
Object.assign(f, { baseline: now, target: lim, unit: tidy(i.unit, 12), direction: kind === 'ceiling' ? 'down' : 'up', limit: kind, always_on: always });
|
|
78
|
+
} else {
|
|
79
|
+
const base = toNum(i.baseline), tgt = toNum(i.target);
|
|
80
|
+
if (!fin(base) || !fin(tgt)) return no('Type a number for the baseline and the target.');
|
|
81
|
+
if (base === tgt) return no('The target must differ from the baseline.');
|
|
82
|
+
if (!dir) return no('Say whether up or down is better.');
|
|
83
|
+
if ((dir === 'up' && tgt < base) || (dir === 'down' && tgt > base)) return no((dir === 'up' ? 'Up' : 'Down') + ' is better, so the target must be ' + (dir === 'up' ? 'above' : 'below') + ' the baseline.');
|
|
84
|
+
Object.assign(f, { baseline: base, target: tgt, unit: UNIT_OF[type], direction: dir });
|
|
85
|
+
}
|
|
86
|
+
const pillar = tidy(i.objective, 80); if (pillar) f.pillar = pillar;
|
|
87
|
+
const kind = ['Quarter', 'Half', 'Year', 'Custom'].includes(i.period_kind) ? i.period_kind : null;
|
|
88
|
+
if (kind) f.period = { kind, label: tidy(i.period_label, 20) || kind };
|
|
89
|
+
if (kind === 'Year' && type !== 'Done or not' && today) { const cp = checkpointsOf(f.baseline, f.target, today, by); if (cp.length) f.checkpoints = cp; }
|
|
90
|
+
if (SOURCES[i.source]) f.source = i.source;
|
|
91
|
+
const owner = tidy(i.owner, 60); if (owner) f.owner = owner;
|
|
92
|
+
const guard = tidy(i.guardrail, 120); if (guard) f.guardrail = guard;
|
|
93
|
+
return { ok: true, fields: f };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** "Describe it, and PMOS fills this in": the words of the description, matched to the goals by name and objective. Nothing is guessed: a goal is
|
|
97
|
+
* picked only when its name or objective is in the text, and `said` lists the words that matched. */
|
|
98
|
+
const STOP = new Set(['the', 'a', 'an', 'of', 'and', 'or', 'for', 'to', 'in', 'on', 'my', 'our', 'is', 'are', 'how', 'what', 'with', 'by', 'dashboard', 'show', 'me', 'make', 'that', 'this', 'it', 'week', 'weeks', 'first']);
|
|
99
|
+
function describe(text, goals) {
|
|
100
|
+
const t = tidy(text, 300), low = t.toLowerCase();
|
|
101
|
+
if (!t) return { ok: false, error: 'Describe the dashboard in a few words.' };
|
|
102
|
+
const words = new Set(low.split(/[^a-z0-9%]+/).filter((w) => w.length > 2 && !STOP.has(w)));
|
|
103
|
+
const said = [], picked = [];
|
|
104
|
+
for (const g of goals || []) {
|
|
105
|
+
const title = String(g.title || '').toLowerCase(), pillar = String(g.pillar || '').toLowerCase();
|
|
106
|
+
const hitTitle = title && (low.includes(title) || title.split(/[^a-z0-9%]+/).filter((w) => w.length > 2 && !STOP.has(w)).some((w) => words.has(w)));
|
|
107
|
+
const hitPillar = pillar && words.has(pillar);
|
|
108
|
+
if (hitTitle || hitPillar) { picked.push(g.id); said.push(hitTitle ? g.title : g.pillar); }
|
|
109
|
+
}
|
|
110
|
+
const range = /\b(8|eight)\s*weeks?\b|\btwo months?\b/.test(low) ? '8w' : /\b(26|twenty[- ]six)\s*weeks?\b|\bhalf\b|\bsix months?\b/.test(low) ? '26w' : 'Quarter';
|
|
111
|
+
const first = (/^[^?.!]+[?.!]?/.exec(t) || [t])[0].trim(), head = first.replace(/[?.!]+$/, '');
|
|
112
|
+
const name = (head.length > 40 ? head.slice(0, 40).replace(/\s+\S*$/, '') : head).replace(/^./, (c) => c.toUpperCase());
|
|
113
|
+
const asked = /[^?.!]*\?/.exec(t);
|
|
114
|
+
const question = asked ? asked[0].trim() : (/^(are|is|do|does|did|can|will|how|what|which|why|who|where|when)\b/i.test(t) ? head + '?' : '');
|
|
115
|
+
return { ok: true, name, question, goals: picked, range, said: [...new Set(said)] };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The health budgets of planning/okrs/health-budgets.md: one table row per budget, `health:<id>` | covers | cap % | trigger. */
|
|
119
|
+
function parseBudgets(md) {
|
|
120
|
+
const out = [];
|
|
121
|
+
for (const line of String(md || '').split('\n')) {
|
|
122
|
+
const m = /^\|\s*`health:([a-z0-9-]+)`\s*\|\s*([^|]*)\|\s*(\d+(?:\.\d+)?)\s*%\s*\|/.exec(line);
|
|
123
|
+
if (m) out.push({ id: m[1], covers: m[2].trim(), cap: Number(m[3]) / 100 });
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
/** A budget's reading: of the board's open initiatives, the share anchored to it, against its cap. An initiative that is done or stopped is not counted. */
|
|
128
|
+
function budgetReading(budget, inits) {
|
|
129
|
+
const open = (inits || []).filter((r) => r && r.status !== 'done' && r.status !== 'cancelled' && !r.stopped);
|
|
130
|
+
const n = open.filter((r) => String(r.anchor || '') === 'health:' + budget.id).length;
|
|
131
|
+
const total = open.length, share = total ? n / total : null;
|
|
132
|
+
return { n, total, share, over: share !== null && fin(budget.cap) ? share > budget.cap : null };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Late initiatives (status late) and Scope added (initiatives whose planned start falls in each of the last `weeks` weeks, the last one this week). */
|
|
136
|
+
function trendsOf(rows, today, weeks = 8) {
|
|
137
|
+
const R = Array.isArray(rows) ? rows : null;
|
|
138
|
+
if (!R) return { late: { value: null, ser: [] }, scope: { value: null, ser: [] } };
|
|
139
|
+
const t = ms(today) || Date.now(), W = 7 * 864e5, ser = [], late = R.filter((r) => r.status === 'late'), lser = [];
|
|
140
|
+
for (let k = weeks - 1; k >= 0; k--) {
|
|
141
|
+
const hi = t - k * W, lo = hi - W;
|
|
142
|
+
ser.push(R.filter((r) => { const s = ms(r.start); return s !== null && s > lo && s <= hi; }).length);
|
|
143
|
+
/* a week before this one: the initiatives late today whose end date had already passed by then. The Board keeps no history of a status,
|
|
144
|
+
* so one that was late then and is no longer late is not counted; this week is today's count. */
|
|
145
|
+
lser.push(k === 0 ? late.length : late.filter((r) => { const e = ms(r.end); return e !== null && e < hi; }).length);
|
|
146
|
+
}
|
|
147
|
+
return { late: { value: late.length, ser: lser }, scope: { value: ser[ser.length - 1], ser } };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The stages the Board recorded as skipped when an initiative was moved past them. */
|
|
151
|
+
function skippedOf(warnings) {
|
|
152
|
+
const out = [];
|
|
153
|
+
for (const w of warnings || []) { const m = /^Skipped (.+?)\.?$/.exec(String(w)); if (m) for (const s of m[1].split(/,\s*|\s+and\s+/)) if (s.trim()) out.push(s.trim()); }
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** An outcome's judgement window: it opens on the ship date and closes on the promise's date. Judged once a verdict is recorded. */
|
|
158
|
+
function windowOf({ shipAt, byAt, verdict, today }) {
|
|
159
|
+
const o = ms(shipAt), c = ms(byAt), t = ms(today);
|
|
160
|
+
const state = verdict ? 'judged' : o === null ? 'none' : c !== null && t !== null && t > c ? 'closed' : t !== null && t < o ? 'not open' : 'open';
|
|
161
|
+
return { opens: o === null ? null : iso(o), closes: c === null ? null : iso(c), share: o !== null && c !== null && c > o && t !== null ? Math.max(0, Math.min(1, (t - o) / (c - o))) : null, state };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** What the readings say since the ship date: the reading at ship, the latest, and how many came after. */
|
|
165
|
+
function evidenceOf(readings, shipAt, unit) {
|
|
166
|
+
const rs = (readings || []).filter((r) => r && fin(r.v) && ms(r.at) !== null).sort((a, b) => ms(a.at) - ms(b.at));
|
|
167
|
+
const s = ms(shipAt), u = String(unit || '').trim(), fmt = (v) => round(v, 2) + (u ? (/^[A-Za-z]/.test(u) ? ' ' + u : u) : '');
|
|
168
|
+
if (!rs.length) return [];
|
|
169
|
+
if (s === null) return [`${rs.length} reading${rs.length === 1 ? '' : 's'} recorded; no ship date, so none is read as after it`];
|
|
170
|
+
const before = rs.filter((r) => ms(r.at) <= s), after = rs.filter((r) => ms(r.at) > s), out = [];
|
|
171
|
+
if (before.length) out.push(`${fmt(before[before.length - 1].v)} on ${before[before.length - 1].at.slice(0, 10)}, the last reading before it shipped`);
|
|
172
|
+
if (after.length) out.push(`${fmt(after[after.length - 1].v)} on ${after[after.length - 1].at.slice(0, 10)}, ${after.length} reading${after.length === 1 ? '' : 's'} after it shipped`);
|
|
173
|
+
else out.push('No reading since it shipped');
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The goals due in [from, to], and how many reached their target by their date (a reading on or before the date at or past the target). */
|
|
178
|
+
function periodHits(goals, from, to) {
|
|
179
|
+
const a = ms(from), b = ms(to); let n = 0, hit = 0;
|
|
180
|
+
for (const g of goals || []) {
|
|
181
|
+
const by = ms(g.byAt || g.by); if (by === null || by < a || by > b) continue;
|
|
182
|
+
n++;
|
|
183
|
+
const dir = fin(g.target) && fin(g.base) ? Math.sign(g.target - g.base) : 0;
|
|
184
|
+
if (dir && (g.series || []).some((r) => ms(r.at) !== null && ms(r.at) <= by && (dir > 0 ? r.v >= g.target : r.v <= g.target))) hit++;
|
|
185
|
+
}
|
|
186
|
+
return { n, hit };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The goals as CSV, one row each, with what the page shows. */
|
|
190
|
+
function exportCsv(goals) {
|
|
191
|
+
const q = (v) => { const s = v == null ? '' : String(v); return /[",\n]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s; };
|
|
192
|
+
const head = ['id', 'goal', 'objective', 'type', 'direction', 'baseline', 'target', 'unit', 'by', 'now', 'readings', 'owner', 'pace'];
|
|
193
|
+
return [head.join(',')].concat((goals || []).map((g) => [g.id, g.title, g.pillar, g.type, g.direction || '', g.base, g.target, g.unit, g.byAt, g.now, g.readings, g.owner || '', g.pace ? g.pace.head + ' ' + g.pace.sub : ''].map(q).join(','))).join('\n') + '\n';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = { GOAL_TYPES, DIRECTIONS, SOURCES, UNIT_OF, goalFields, checkpointsOf, describe, parseBudgets, budgetReading, trendsOf, skippedOf, windowOf, evidenceOf, periodHits, exportCsv };
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* forecast is drawn and no cause is given. One projection is said in words (initiative insights-one-list L2, amending briefing-premium-insights I6): for a
|
|
21
21
|
* measure short of its target with a target date ahead, a straight line through its last four readings carried to that date. Its method is stated. Run-based series (corrections per 100 runs, merges a week) belong to the Board's Metrics card and are not built here (PRD decision 4). */
|
|
22
22
|
|
|
23
|
+
const IG = require('./insights-goals.js');
|
|
23
24
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
24
25
|
const isoDay = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
25
26
|
const shortDate = (v) => { const t = isoDay(v); if (t === null) return ''; const d = new Date(t); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()]; };
|
|
@@ -192,6 +193,7 @@ function setupsOf(su, now) {
|
|
|
192
193
|
id: s.id, name: clip(s.name, 120), purpose: clip(s.purpose, 240), audience: s.audience || '', source: s.source || '', output: s.output || '', label: s.label || '',
|
|
193
194
|
next: s.next_draft ? shortDate(s.next_draft) : '', lastIssued: s.last_issued ? shortDate(s.last_issued) : '', status: s.status || '', cycles: fin(s.cycles) ? s.cycles : 0,
|
|
194
195
|
paused: s.status === 'paused', fromWork: s.source === 'work', structured: !!(s.structure && s.structure.saved), drafting: !!(s.draft && s.draft.state === 'drafting'),
|
|
196
|
+
builtFrom: s.structure && Array.isArray(s.structure.charts) ? [...new Set(s.structure.charts.map((c) => (typeof c === 'string' ? c : c && (c.title || c.name || c.chart || c.id))).filter((x) => typeof x === 'string' && x).map((x) => clip(x, 40)))].slice(0, 4) : [], // premium-agreed-design: Library "Built from"
|
|
195
197
|
}));
|
|
196
198
|
const found = (su.findings || []).slice(0, 3).map((x) => ({
|
|
197
199
|
id: x.id, name: clip(x.name, 120), why: clip(x.why, 240), evidence: (x.evidence || []).map((e) => ({ kind: e.kind || '', text: clip(e.text, 240) })),
|
|
@@ -252,6 +254,117 @@ function leadOf(text) {
|
|
|
252
254
|
return '';
|
|
253
255
|
}
|
|
254
256
|
|
|
257
|
+
|
|
258
|
+
/* ── premium-agreed-design (G1, G2): Goals and Outcomes ───────────────────────────────────────────────────────────────────────────────────────────
|
|
259
|
+
* A goal is one KR metric record. Its type is read from its unit, its direction from baseline to target, and its pace is the projection above said
|
|
260
|
+
* in words. What moves it is every initiative of the board whose anchor names the record (its id or its metric name, as the Calendar's synergy does).
|
|
261
|
+
* Outcomes lists the initiatives past Build (Deliver, Monitor, Evaluate) with what their anchor goal promised and where it stands. No verdict is
|
|
262
|
+
* invented: an initiative in Evaluate needs one, and a done one is listed as decided. */
|
|
263
|
+
const LIFE = ['triage', 'discover', 'plan', 'prioritize', 'build', 'deliver', 'monitor', 'evaluate'];
|
|
264
|
+
const LIFE_LABEL = ['Triage', 'Discover', 'Plan', 'Prioritize', 'Build', 'Deliver', 'Monitor', 'Evaluate'];
|
|
265
|
+
const LIFE_ALIAS = { ideate: 1, strategize: 3, intake: 0, spec: 1, contract: 2, eval: 7, accepted: 7 };
|
|
266
|
+
/** The lifecycle index (0 Triage … 7 Evaluate) of a stage name, or -1 when the name is not a lifecycle stage. PURE. */
|
|
267
|
+
function lifeIndex(stage) {
|
|
268
|
+
const k = String(stage || '').trim().toLowerCase();
|
|
269
|
+
const i = LIFE.indexOf(k);
|
|
270
|
+
return i >= 0 ? i : (k in LIFE_ALIAS ? LIFE_ALIAS[k] : -1);
|
|
271
|
+
}
|
|
272
|
+
/** The goal type the Agreed design names, read from the unit. A record holds no type field, so the unit is the only honest signal. PURE. */
|
|
273
|
+
function goalType(unit) {
|
|
274
|
+
const u = String(unit || '').trim();
|
|
275
|
+
if (u === '%' || /^(pct|percent|pts?|points?)$/i.test(u)) return 'Percentage';
|
|
276
|
+
if (/^(s|sec|secs|seconds?|mins?|minutes?|h|hrs?|hours?|d|days?|weeks?|months?|ms)$/i.test(u)) return 'Duration';
|
|
277
|
+
if (/[$€£¥]/.test(u) || /^(usd|eur|gbp|arr|mrr)$/i.test(u)) return 'Amount';
|
|
278
|
+
return 'Count';
|
|
279
|
+
}
|
|
280
|
+
const STATE_TONE = { ok: 'ok', drift: 'late', off: 'red', unscored: 'q' };
|
|
281
|
+
/** The Agreed design's dates and amounts on Goals: "Dec 31", "16 pts". A pace is said to whole units from 10 up, to one decimal below. PURE. */
|
|
282
|
+
const mdDate = (v) => { const t = isoDay(v); if (t === null) return ''; const d = new Date(t); return MON[d.getUTCMonth()] + ' ' + d.getUTCDate(); };
|
|
283
|
+
const paceR = (v, tgt) => { const d = Math.max(Math.abs(v) < 10 ? 1 : 0, Math.min(2, (String(fin(tgt) ? tgt : '').split('.')[1] || '').length)), k = 10 ** d; return Math.round(v * k) / k; };
|
|
284
|
+
const ptsOf = (v, u) => (String(u).trim() === '%' ? r2(v) + (r2(v) === 1 ? ' pt' : ' pts') : num(v, u));
|
|
285
|
+
const anchorHits = (a, o) => !!a && (String(a) === String(o.id) || String(a) === String(o.name));
|
|
286
|
+
function initOf(r) {
|
|
287
|
+
const i = lifeIndex(r.stage);
|
|
288
|
+
return { id: String(r.id), title: clip(r.title || r.id, 120), stage: r.stage || '', idx: i, stageLabel: i >= 0 ? LIFE_LABEL[i] : (r.stage || ''), status: r.status || '', lane: r.lane || '',
|
|
289
|
+
owner: r.owner || '', end: r.end ? shortDate(r.end) : '', endAt: r.end ? String(r.end).slice(0, 10) : null, anchor: r.anchor || '',
|
|
290
|
+
startAt: r.start ? String(r.start).slice(0, 10) : null, skipped: IG.skippedOf(r.warnings) };
|
|
291
|
+
}
|
|
292
|
+
/** One goal per KR metric record, with or without a series. `today` is a day in ms (UTC midnight). */
|
|
293
|
+
function goalsOf(outcomes, charts, inits, today, meta) {
|
|
294
|
+
return outcomes.map((o) => {
|
|
295
|
+
const x = (meta && meta[o.id]) || {}; // the fields New goal keeps on the record (lib/insights-goals.js goalFields)
|
|
296
|
+
const c = charts.find((x) => x.id === o.id) || null;
|
|
297
|
+
const rs = (o.readings || []).filter((x) => x && fin(x.v) && isoDay(x.at) !== null);
|
|
298
|
+
const u = o.unit || '', base = fin(o.start) ? o.start : null, tgt = fin(o.target) ? o.target : null;
|
|
299
|
+
const now = rs.length ? rs[rs.length - 1].v : null;
|
|
300
|
+
const dir = tgt !== null && base !== null && tgt !== base ? Math.sign(tgt - base) : 0;
|
|
301
|
+
const fromAt = rs.length ? rs[0].at : null, byAt = isoDay(o.by) !== null ? String(o.by).slice(0, 10) : null;
|
|
302
|
+
const t0 = isoDay(fromAt), t1 = isoDay(byAt);
|
|
303
|
+
const timeGone = t0 !== null && t1 !== null && t1 > t0 ? Math.max(0, Math.min(1, (today - t0) / (t1 - t0))) : null;
|
|
304
|
+
const done = now !== null && tgt !== null && base !== null && tgt !== base ? Math.max(0, Math.min(1, (now - base) / (tgt - base))) : null;
|
|
305
|
+
const p0 = c ? projectionOf(c) : null;
|
|
306
|
+
/* a percentage cannot pass 100: the pace is said at the cap, not as "≈100.3%" */
|
|
307
|
+
const p = p0 && /^%$/.test(u.trim()) && p0.atDue > 100 ? Object.assign({}, p0, { atDue: 100 }) : p0;
|
|
308
|
+
const reached = now !== null && tgt !== null && dir && (dir > 0 ? now >= tgt : now <= tgt);
|
|
309
|
+
let pace;
|
|
310
|
+
if (reached) pace = { tone: 'ok', head: 'Reached', sub: 'at ' + num(now, u) + (rs.length ? ' on ' + mdDate(rs[rs.length - 1].at) : '') };
|
|
311
|
+
else if (p && !p.toward) pace = { tone: 'late', head: 'Never reaches ' + num(tgt, u), sub: p.perWeek === 0 ? 'not moving' : 'moving the wrong way' };
|
|
312
|
+
else if (p && !p.reaches) pace = { tone: 'late', head: '≈' + num(paceR(p.atDue, tgt), u) + ' by ' + mdDate(byAt), sub: ptsOf(paceR(p.short, tgt), u) + ' short at this pace' };
|
|
313
|
+
else if (p) pace = { tone: 'ok', head: '≈' + num(paceR(p.atDue, tgt), u) + ' by ' + mdDate(byAt), sub: done !== null && timeGone !== null ? (done > timeGone ? 'ahead: ' : 'on course: ') + Math.round(done * 100) + '% done, ' + Math.round(timeGone * 100) + '% of time gone' : 'on course' };
|
|
314
|
+
else pace = { tone: 'q', head: '—', sub: rs.length < 2 ? (rs.length ? 'needs a second reading' : 'no reading yet') : !byAt ? 'no target date' : t1 !== null && t1 <= isoDay(rs[rs.length - 1].at) ? 'its date has passed' : 'no pace to read' };
|
|
315
|
+
if (x.type === 'Stay within' && tgt !== null) { // a floor or a ceiling: within it or not, with the room left
|
|
316
|
+
const ceil = x.limit !== 'floor', inside = now === null ? null : ceil ? now <= tgt : now >= tgt;
|
|
317
|
+
pace = now === null ? { tone: 'q', head: '—', sub: 'no reading yet' }
|
|
318
|
+
: inside ? { tone: 'ok', head: 'Within its ' + (ceil ? 'ceiling' : 'floor'), sub: num(Math.abs(tgt - now), u) + ' of room left' }
|
|
319
|
+
: { tone: 'late', head: (ceil ? 'Over its ceiling' : 'Under its floor') + ' by ' + num(Math.abs(now - tgt), u), sub: 'since ' + mdDate(rs[rs.length - 1].at) };
|
|
320
|
+
} else if (x.type === 'Done or not' && tgt !== null) {
|
|
321
|
+
const n = now === null ? 0 : now, all = Array.isArray(x.steps) && x.steps.length ? x.steps.length : null;
|
|
322
|
+
pace = n >= tgt ? { tone: 'ok', head: 'Done', sub: rs.length ? 'on ' + mdDate(rs[rs.length - 1].at) : '' }
|
|
323
|
+
: { tone: byAt && t1 !== null && t1 < today ? 'late' : 'q', head: 'Not yet', sub: (all ? n + ' of ' + all + ' steps · ' : '') + (byAt ? 'due ' + mdDate(byAt) : 'no due date') };
|
|
324
|
+
}
|
|
325
|
+
const moves = (inits || []).filter((r) => anchorHits(r.anchor, o)).map(initOf);
|
|
326
|
+
return {
|
|
327
|
+
id: o.id, key: c ? c.key : null, title: clip(o.name, 120), pillar: o.pillar || '', unit: u, type: IG.GOAL_TYPES.includes(x.type) ? x.type : goalType(u),
|
|
328
|
+
direction: x.direction || (dir > 0 ? 'up' : dir < 0 ? 'down' : ''),
|
|
329
|
+
dirTxt: x.type === 'Stay within' ? (x.limit === 'floor' ? 'stay above' : 'stay below') : x.direction === 'exact' ? 'exactly the target' : dir > 0 ? 'up is better' : dir < 0 ? 'down is better' : '',
|
|
330
|
+
period: x.period || null, checkpoints: Array.isArray(x.checkpoints) ? x.checkpoints : [], source: x.source || '', owner: x.owner || '', guardrail: x.guardrail || '',
|
|
331
|
+
steps: Array.isArray(x.steps) ? x.steps : null, items: Array.isArray(x.items) ? x.items.filter((s) => typeof s === 'string' && s.trim()).map((s) => clip(s.trim(), 60)) : null, limit: x.limit || null, alwaysOn: x.always_on === true, series: rs.map((r) => ({ at: String(r.at).slice(0, 10), v: r.v })), base, baseTxt: base !== null ? num(base, u) : '', from: fromAt ? shortDate(fromAt) : '',
|
|
332
|
+
now, nowTxt: now !== null ? num(now, u) : '', target: tgt, targetTxt: tgt !== null ? num(tgt, u) : '', by: byAt ? shortDate(byAt) : '', byAt, fromAt,
|
|
333
|
+
done, timeGone, tone: STATE_TONE[o.status] || 'q', state: o.status || 'unscored', chip: (CHIP[o.status] || ['No line scored'])[0], reason: o.reason || '',
|
|
334
|
+
proj: p ? { atDue: r1(p.atDue), reaches: p.reaches, toward: p.toward } : null, pace, readings: rs.length, moves,
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/** Shipped work (Deliver, Monitor, Evaluate, or done) against what its anchor goal promised. PURE. */
|
|
339
|
+
function outcomesOf(inits, goals, outcomes, verdicts, todayIso) {
|
|
340
|
+
const ORDER = ['verdict', 'window', 'decided'];
|
|
341
|
+
const rows = (inits || []).map(initOf).filter((r) => r.idx >= 5 || r.status === 'done');
|
|
342
|
+
return rows.map((r) => {
|
|
343
|
+
const g = goals.find((x) => anchorHits(r.anchor, { id: x.id, name: (outcomes.find((o) => o.id === x.id) || {}).name })) || null;
|
|
344
|
+
const vd = (verdicts && verdicts[r.id]) || null, o = g ? outcomes.find((x) => x.id === g.id) : null;
|
|
345
|
+
const group = vd || r.status === 'done' || r.status === 'cancelled' ? 'decided' : r.idx === 7 ? 'verdict' : 'window';
|
|
346
|
+
return Object.assign(r, { group, verdict: vd ? { verdict: vd.verdict, learned: vd.learned, at: vd.at ? String(vd.at).slice(0, 10) : null } : null,
|
|
347
|
+
window: IG.windowOf({ shipAt: r.endAt, byAt: g ? g.byAt : null, verdict: vd, today: todayIso }),
|
|
348
|
+
evidence: g && o ? IG.evidenceOf((o.readings || []).map((x) => ({ at: String(x.at), v: x.v })), r.endAt, g.unit) : [], goal: g ? { id: g.id, key: g.key, title: g.title, type: g.type, baseTxt: g.baseTxt, targetTxt: g.targetTxt, nowTxt: g.nowTxt, by: g.by, done: g.done, tone: g.tone, pace: g.pace } : null });
|
|
349
|
+
}).sort((a, b) => ORDER.indexOf(a.group) - ORDER.indexOf(b.group));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** The health budgets the board's initiatives anchor to (D59: an anchor health:<id>). A budget's floor or ceiling and its weekly readings are not
|
|
353
|
+
* read on this page, so a budget holds only its id and what moves it. PURE. */
|
|
354
|
+
function budgetsOf(inits, registry) {
|
|
355
|
+
const by = new Map();
|
|
356
|
+
for (const b of registry || []) by.set(b.id, []);
|
|
357
|
+
for (const r of inits || []) {
|
|
358
|
+
const m = /^health:(.+)$/.exec(String((r && r.anchor) || '').trim()); if (!m) continue;
|
|
359
|
+
if (!by.has(m[1])) by.set(m[1], []);
|
|
360
|
+
by.get(m[1]).push(initOf(r));
|
|
361
|
+
}
|
|
362
|
+
return [...by.entries()].map(([id, moves]) => {
|
|
363
|
+
const b = (registry || []).find((x) => x.id === id) || null;
|
|
364
|
+
return { id, anchor: 'health:' + id, title: id, moves, covers: b ? b.covers : '', cap: b ? b.cap : null, declared: !!b, reading: b && Array.isArray(inits) ? IG.budgetReading(b, inits) : null };
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
255
368
|
function build(facts) {
|
|
256
369
|
const f = facts || {};
|
|
257
370
|
const outcomes = f.outcomes || [], missing = (f.missing || []).slice();
|
|
@@ -287,8 +400,20 @@ function build(facts) {
|
|
|
287
400
|
dock: { needs: off, label: off === 1 ? 'measure off its line' : 'measures off their line', next: findings[0] && findings[0].chart ? (charts.find((c) => c.key === findings[0].chart) || {}).title || null : null },
|
|
288
401
|
counts: { charts: charts.length, noSeries: noSeries.length, off, total: outcomes.length },
|
|
289
402
|
};
|
|
403
|
+
const today = isoDay(new Date(fin(f.now) ? f.now : Date.now()).toISOString()) || 0;
|
|
404
|
+
model.today = new Date(today).toISOString().slice(0, 10);
|
|
405
|
+
model.goals = goalsOf(outcomes, charts, f.initiatives || [], today, f.goalMeta || {});
|
|
406
|
+
model.initiativesRead = Array.isArray(f.initiatives);
|
|
407
|
+
const ins = f.ins || { charts: {}, verdicts: {}, targets: {} }, bid = board.id || '';
|
|
408
|
+
model.outcomes = outcomesOf(f.initiatives || [], model.goals, outcomes, ins.verdicts[bid] || {}, model.today);
|
|
409
|
+
model.budgets = budgetsOf(f.initiatives || [], f.budgets || []);
|
|
410
|
+
model.budgetsRead = Array.isArray(f.budgets);
|
|
411
|
+
model.lateNow = Array.isArray(f.initiatives) ? f.initiatives.filter((r) => r && r.status === 'late').length : null;
|
|
412
|
+
model.trends = Object.assign(IG.trendsOf(Array.isArray(f.initiatives) ? f.initiatives : null, model.today), { targets: ins.targets || {} });
|
|
413
|
+
model.chartSet = ins.charts[bid] || {}; // { [dashboard]: { [goal]: { form, range, compare, target, forecast, note } } }
|
|
414
|
+
model.lifecycle = LIFE_LABEL.map((label, i) => ({ key: LIFE[i], label, milestone: i === 5 || i === 7 }));
|
|
290
415
|
last = model;
|
|
291
416
|
return model;
|
|
292
417
|
}
|
|
293
418
|
|
|
294
|
-
module.exports = { build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
419
|
+
module.exports = { lifeIndex, goalType, goalsOf, outcomesOf, budgetsOf, mdDate, build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|