create-pmos 0.433.0 → 0.435.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/briefing-premium-insights-test.js +63 -58
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/ready-reports.js +145 -0
- package/workspace/guide/index.md +2 -0
- package/workspace/guide/metric-drafts.md +21 -1
- package/workspace/guide/ready-made-dashboards.md +62 -0
- package/workspace/guide/your-impact.md +58 -0
- package/workspace/impact-screens-test.js +149 -0
- package/workspace/intel-report-ui-test.js +1 -1
- package/workspace/intelligence-gaps-ui-test.js +13 -9
- package/workspace/lib/board-premium.js +1 -1
- package/workspace/lib/engine/outbox.js +1 -1
- package/workspace/lib/engine/records/index.js +11 -3
- package/workspace/lib/goal-status.js +199 -0
- package/workspace/lib/goal-watch.js +71 -0
- package/workspace/lib/headless.js +24 -2
- package/workspace/lib/impact-cli.js +72 -0
- package/workspace/lib/impact-runs.js +114 -0
- package/workspace/lib/impact.js +195 -0
- package/workspace/lib/insights-premium.js +43 -4
- package/workspace/lib/intel-report.js +36 -5
- package/workspace/lib/metric-draft-runs.js +33 -10
- package/workspace/lib/metric-drafts.js +118 -15
- package/workspace/lib/metric-read-runs.js +132 -0
- package/workspace/lib/metric-reads.js +129 -0
- package/workspace/lib/metrics-cli.js +100 -5
- package/workspace/lib/pmos-verbs.js +4 -1
- 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 +4 -0
- package/workspace/lib/routes-board-premium.js +5 -0
- package/workspace/lib/routes-boards.js +1 -1
- package/workspace/lib/routes-goal-status.js +111 -0
- package/workspace/lib/routes-impact-views.js +58 -0
- package/workspace/lib/routes-impact.js +91 -0
- package/workspace/lib/routes-insights-premium.js +20 -0
- package/workspace/lib/routes-metric-drafts.js +55 -4
- package/workspace/lib/routes-ready-reports.js +455 -0
- package/workspace/lib/routes-records.js +2 -0
- package/workspace/lib/routes-report-setups.js +4 -3
- package/workspace/lib/settings-store.js +3 -0
- package/workspace/okr-goals-ui-test.js +175 -0
- 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 +33 -8
- package/workspace/public/pm/bd-prog-panel.js +58 -10
- package/workspace/public/pm/cozy-adler.css +5 -0
- package/workspace/public/pm/cozy-adler.js +17 -9
- package/workspace/public/pm/cozy-insights.css +84 -0
- package/workspace/public/pm/cozy-settings.js +11 -1
- 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 +87 -8
- package/workspace/public/pm/home-data.js +3 -2
- package/workspace/public/pm/home-impact.css +16 -0
- package/workspace/public/pm/home-impact.js +72 -0
- package/workspace/public/pm/home-ini.js +19 -1
- package/workspace/public/pm/home-today.js +4 -2
- package/workspace/public/pm/impact.css +37 -0
- package/workspace/public/pm/impact.js +201 -0
- package/workspace/public/pm/okr-list.js +249 -0
- package/workspace/public/pm/premium-insights.js +232 -240
- package/workspace/public/pm/premium-report-read.js +36 -5
- package/workspace/public/pm/premium-vw-mtg.js +4 -1
- package/workspace/public/pm/ready-lib.css +29 -0
- package/workspace/public/pm/ready-lib.js +62 -0
- package/workspace/public/premium-intelligence.html +3 -2
- package/workspace/public/premium.html +1 -0
- package/workspace/ready-dash-ui-test.js +227 -0
- package/workspace/server.js +58 -2
- package/workspace/skills/impact-detect.skill +46 -0
- package/workspace/skills/metric-read.skill +32 -0
- package/workspace/test-lists/batch17-ready-reports.json +9 -0
- package/workspace/test-lists/goal-watch.json +9 -0
- package/workspace/test-lists/impact-screens.json +5 -0
- package/workspace/test-lists/impact-ui.json +9 -0
- package/workspace/test-lists/impact.json +9 -0
- package/workspace/test-lists/okr-goals-ui.json +5 -0
- package/workspace/test-lists/ready-reports-ui.json +6 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* impact.js — "Your impact" (feedback batch 16 item 7, the gamification design; brief next16/briefs/7-your-impact-build.md, contract
|
|
3
|
+
* 7-impact-api.md; canvas In development GmP1Ledger, GmP1Switch). THE ONE WRITER and THE ONE FOLD of <runtime>/impact/impact.jsonl.
|
|
4
|
+
* lib/routes-impact.js does the I/O; lib/impact-runs.js starts the detection run; lib/impact-cli.js is what that run files with.
|
|
5
|
+
* Pure, with no clock of its own: every time comes in.
|
|
6
|
+
*
|
|
7
|
+
* PRIVATE. The ledger is per person, in the runtime folder beside settings.json: outside every repository, so no commit, sync or teammate
|
|
8
|
+
* reads it. Nothing here sends anything. An item is something a person or a system outside you did in reaction to your work (a thanks, a
|
|
9
|
+
* ticket that moved after your decision, a spec used, a KR that moved after your initiative delivered), with the source to open it. Never
|
|
10
|
+
* logins, ticks, time, messages sent, or Claude's own work.
|
|
11
|
+
*
|
|
12
|
+
* NO NUMBERS LEAVE THIS FILE. The views carry words: grow is rest · bud · leaf · full; the gate is measuring · open · short. The gate's rate
|
|
13
|
+
* is written to the ledger (the brief's "record the rate") and never shown.
|
|
14
|
+
*
|
|
15
|
+
* THE LEDGER. One line per event, { at, by, kind, ... }:
|
|
16
|
+
* run { run } the detection run started
|
|
17
|
+
* item { run, item } one item it filed (clean() shape); the last line for an id wins until it is checked
|
|
18
|
+
* end { run, ok, error? } the run ended
|
|
19
|
+
* verdict { id, real: true | false } the PM's ✓ or ✕ in the weekly check
|
|
20
|
+
* undo { id } a row back to unchecked
|
|
21
|
+
* seen { ids } read on a Phase 2 surface; ends its celebration
|
|
22
|
+
* gate { state, real, judged, weeks } the gate changed: measuring → open (and stays), or → short
|
|
23
|
+
*
|
|
24
|
+
* dirOf(runtime) · ledgerFile(dir) · readLines(file) · read(dir) → fold · append(dir, actor, line, at)
|
|
25
|
+
* fold(lines) PURE → { items: Map id → item, runs: [run], gate }
|
|
26
|
+
* clean(input) → { item } | { error } what `pmos impact add` checks
|
|
27
|
+
* weekOf(day, start) · labelOf(week, thisWeek) · dayOf(ms)
|
|
28
|
+
* gateOf(F, thisWeek) PURE → { state, real, judged, weeks }
|
|
29
|
+
* weekView(F, o) · weeksView(F, o) · checkView(F, o) PURE → the GET bodies (no ok, no on)
|
|
30
|
+
* KINDS · SOURCE_TYPES · GROW
|
|
31
|
+
*/
|
|
32
|
+
const fs = require('fs');
|
|
33
|
+
const path = require('path');
|
|
34
|
+
const crypto = require('crypto');
|
|
35
|
+
|
|
36
|
+
const LEDGER = 'impact.jsonl';
|
|
37
|
+
const LINES = new Set(['run', 'item', 'end', 'verdict', 'undo', 'seen', 'gate']);
|
|
38
|
+
const KINDS = ['thanks', 'unblock', 'used', 'kr'];
|
|
39
|
+
const SOURCE_TYPES = ['slack', 'mail', 'jira', 'doc', 'meeting', 'kr', 'board', 'initiative'];
|
|
40
|
+
const GROW = ['rest', 'bud', 'leaf', 'full'];
|
|
41
|
+
const GATE_ITEMS = 10, GATE_WEEKS = 2; // at least 9 of 10 items real, across two weekly checks
|
|
42
|
+
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
43
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
44
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
45
|
+
const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
46
|
+
const hash = (s) => crypto.createHash('sha1').update(String(s)).digest('hex').slice(0, 10);
|
|
47
|
+
const p2 = (n) => String(n).padStart(2, '0');
|
|
48
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
49
|
+
|
|
50
|
+
/* ── days and weeks (local days, YYYY-MM-DD; a week is named by its first day) ── */
|
|
51
|
+
const dayOf = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + p2(d.getMonth() + 1) + '-' + p2(d.getDate()); };
|
|
52
|
+
const utc = (day) => { const m = DAY_RE.exec(day) ? day.split('-').map(Number) : null; return m ? Date.UTC(m[0], m[1] - 1, m[2]) : NaN; };
|
|
53
|
+
const addDays = (day, n) => new Date(utc(day) + n * 864e5).toISOString().slice(0, 10);
|
|
54
|
+
/** The first day of the week `day` is in. start: 'mon' (default) or 'sun' (Settings › Time › week start). */
|
|
55
|
+
function weekOf(day, start = 'mon') {
|
|
56
|
+
const t = utc(day); if (!Number.isFinite(t)) return '';
|
|
57
|
+
const dow = new Date(t).getUTCDay(), back = start === 'sun' ? dow : (dow + 6) % 7;
|
|
58
|
+
return addDays(day, -back);
|
|
59
|
+
}
|
|
60
|
+
function labelOf(week, thisWeek) {
|
|
61
|
+
if (week === thisWeek) return 'This week';
|
|
62
|
+
if (week === addDays(thisWeek, -7)) return 'Last week';
|
|
63
|
+
const m = week.split('-').map(Number);
|
|
64
|
+
return 'Week of ' + m[2] + ' ' + MON[m[1] - 1] + (week.slice(0, 4) === thisWeek.slice(0, 4) ? '' : ' ' + m[0]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* ── the ledger ── */
|
|
68
|
+
const dirOf = (runtime) => (runtime ? path.join(runtime, 'impact') : null);
|
|
69
|
+
function ledgerFile(dir) { return dir ? path.join(dir, LEDGER) : null; }
|
|
70
|
+
function readLines(file) {
|
|
71
|
+
if (!file) return [];
|
|
72
|
+
let text = '';
|
|
73
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
74
|
+
const out = [];
|
|
75
|
+
for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (isObj(l) && LINES.has(l.kind)) out.push(l); } catch { /* a torn line is skipped */ } }
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
function read(dir) { return fold(readLines(ledgerFile(dir))); }
|
|
79
|
+
/** One line. `at` is the caller's clock (an ISO string). The folder and the file are the person's own: mode 0700 and 0600. */
|
|
80
|
+
function append(dir, actor, ev, at) {
|
|
81
|
+
const line = { at: at || null, by: (actor && actor.by) || null, ...ev };
|
|
82
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
83
|
+
fs.appendFileSync(ledgerFile(dir), JSON.stringify(line) + '\n', { mode: 0o600 });
|
|
84
|
+
return line;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* ── what the run may file (`pmos impact add`) ── */
|
|
88
|
+
const LIM = { text: 200, who: 60, label: 80, url: 600 };
|
|
89
|
+
// A count of what you did or who you helped is a score by another name (rule 3). A KR's own reading ("31% to 35%") is the KR, not a count.
|
|
90
|
+
const COUNT_RE = /\b\d+\s*(?:people|persons?|engineers?|devs?|developers?|teams?|leaves|leaf|points?|times|thanks|items?|helped|tickets?|stakeholders?|users? helped)\b|\b(?:streak|score|level|rank)\b/i;
|
|
91
|
+
const urlOk = (u) => /^https:\/\/[^\s]+$/i.test(u) || /^\/[^\s/][^\s]*$/.test(u);
|
|
92
|
+
/** → { item } | { error }. input: { kind, text, who, at, source: { url, type, label } } */
|
|
93
|
+
function clean(input) {
|
|
94
|
+
if (!isObj(input)) return { error: 'an item is a JSON object' };
|
|
95
|
+
const kind = str(input.kind);
|
|
96
|
+
if (!KINDS.includes(kind)) return { error: 'kind is one of: ' + KINDS.join(', ') };
|
|
97
|
+
const text = one(input.text, LIM.text);
|
|
98
|
+
if (!text) return { error: 'text is one plain sentence: what happened because of your work' };
|
|
99
|
+
if (COUNT_RE.test(text)) return { error: 'text has a count or a score. Say what happened in plain words, with no number of people or things.' };
|
|
100
|
+
const s = input.source;
|
|
101
|
+
if (!isObj(s)) return { error: 'source is { url, type, label }: no source, no item' };
|
|
102
|
+
const url = one(s.url, LIM.url);
|
|
103
|
+
if (!url || !urlOk(url)) return { error: 'source.url is the https link to the message, ticket or document (or a PMOS link that starts with /)' };
|
|
104
|
+
const type = str(s.type);
|
|
105
|
+
if (!SOURCE_TYPES.includes(type)) return { error: 'source.type is one of: ' + SOURCE_TYPES.join(', ') };
|
|
106
|
+
const label = one(s.label, LIM.label);
|
|
107
|
+
if (!label) return { error: 'source.label says where it is, for example "Slack · #idpf-data"' };
|
|
108
|
+
const at = str(input.at);
|
|
109
|
+
if (!at || !Number.isFinite(Date.parse(at))) return { error: 'at is when it happened (ISO 8601)' };
|
|
110
|
+
const who = one(input.who, LIM.who);
|
|
111
|
+
if (/\d/.test(who)) return { error: 'who is a name only' };
|
|
112
|
+
const id = 'im-' + hash(kind + '|' + url);
|
|
113
|
+
return { item: { id, kind, text, who, at: new Date(Date.parse(at)).toISOString(), source: { url, type, label } } };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* ── the fold ── */
|
|
117
|
+
function fold(lines) {
|
|
118
|
+
const items = new Map(), runs = [];
|
|
119
|
+
let gate = { state: 'measuring' };
|
|
120
|
+
const runOf = (id) => runs.find((r) => r.run === id);
|
|
121
|
+
for (const l of lines || []) {
|
|
122
|
+
if (!isObj(l) || !LINES.has(l.kind)) continue;
|
|
123
|
+
if (l.kind === 'run' && str(l.run)) runs.push({ run: l.run, at: str(l.at), ended: false, ok: null, error: '' });
|
|
124
|
+
else if (l.kind === 'end' && str(l.run)) { const r = runOf(l.run); if (r && !r.ended) Object.assign(r, { ended: true, ok: !!l.ok, error: one(l.error, 200), endAt: str(l.at) }); }
|
|
125
|
+
else if (l.kind === 'item' && isObj(l.item) && str(l.item.id)) {
|
|
126
|
+
const c = clean(l.item); if (!c.item || c.item.id !== l.item.id) continue; // a line that does not pass today's rules is not an item
|
|
127
|
+
const was = items.get(c.item.id);
|
|
128
|
+
if (was && was.real !== null) continue; // the PM checked it: a later run never changes it
|
|
129
|
+
items.set(c.item.id, { ...c.item, real: null, read: false, filed: str(l.at), run: str(l.run) });
|
|
130
|
+
} else if (l.kind === 'verdict' && str(l.id)) { const it = items.get(l.id); if (it && typeof l.real === 'boolean') { it.real = l.real; it.checkedAt = str(l.at); } }
|
|
131
|
+
else if (l.kind === 'undo' && str(l.id)) { const it = items.get(l.id); if (it) { it.real = null; it.read = false; } }
|
|
132
|
+
else if (l.kind === 'seen' && Array.isArray(l.ids)) { for (const id of l.ids) { const it = items.get(String(id)); if (it && it.real === true) it.read = true; } }
|
|
133
|
+
else if (l.kind === 'gate' && ['measuring', 'open', 'short'].includes(l.state)) { if (gate.state !== 'open') gate = { state: l.state, at: str(l.at) }; }
|
|
134
|
+
}
|
|
135
|
+
return { items, runs, gate };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const weekIs = (it, start) => weekOf(dayOf(Date.parse(it.at)), start);
|
|
139
|
+
const byNewest = (a, b) => (a.at < b.at ? 1 : a.at > b.at ? -1 : 0);
|
|
140
|
+
const shown = (it) => ({ id: it.id, week: it.week, kind: it.kind, text: it.text, who: it.who, source: { ...it.source }, at: it.at, real: it.real, read: !!it.read });
|
|
141
|
+
function itemsByWeek(F, start) {
|
|
142
|
+
const m = new Map();
|
|
143
|
+
for (const it of F.items.values()) { const w = weekIs(it, start); if (!m.has(w)) m.set(w, []); m.get(w).push({ ...it, week: w }); }
|
|
144
|
+
return m;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** PURE. The gate before Phase 2: a checked week is a finished week whose every item has ✓ or ✕. Across the checked weeks, at least 9 of 10
|
|
148
|
+
* judged items real, over at least two weeks and ten items: open (and it stays open once written). Ten or more judged and under 9 of 10: short. */
|
|
149
|
+
function gateOf(F, thisWeek, start = 'mon') {
|
|
150
|
+
const W = itemsByWeek(F, start);
|
|
151
|
+
let real = 0, judged = 0, weeks = 0;
|
|
152
|
+
for (const [w, list] of W) {
|
|
153
|
+
if (w >= thisWeek || !list.length || list.some((x) => x.real === null)) continue;
|
|
154
|
+
weeks++; judged += list.length; real += list.filter((x) => x.real === true).length;
|
|
155
|
+
}
|
|
156
|
+
if (F.gate && F.gate.state === 'open') return { state: 'open', real, judged, weeks };
|
|
157
|
+
const state = weeks < GATE_WEEKS || judged < GATE_ITEMS ? 'measuring' : real * 10 >= judged * 9 ? 'open' : 'short';
|
|
158
|
+
return { state, real, judged, weeks };
|
|
159
|
+
}
|
|
160
|
+
const growOf = (n) => GROW[n <= 0 ? 0 : n === 1 ? 1 : n <= 3 ? 2 : 3];
|
|
161
|
+
|
|
162
|
+
/** PURE. GET /api/impact/week. o: { week?, today, start } */
|
|
163
|
+
function weekView(F, o) {
|
|
164
|
+
const thisWeek = weekOf(o.today, o.start), week = o.week && DAY_RE.test(o.week) ? weekOf(o.week, o.start) : thisWeek;
|
|
165
|
+
const live = gateOf(F, thisWeek, o.start).state === 'open';
|
|
166
|
+
const real = live ? (itemsByWeek(F, o.start).get(week) || []).filter((x) => x.real === true).sort(byNewest) : [];
|
|
167
|
+
const cel = real.find((x) => !x.read);
|
|
168
|
+
return { live, first: F.items.size === 0, week, from: week, to: addDays(week, 6), label: labelOf(week, thisWeek), grow: growOf(real.length),
|
|
169
|
+
celebrate: cel ? cel.id : null, quiet: real.length === 0, items: real.map(shown) };
|
|
170
|
+
}
|
|
171
|
+
/** PURE. GET /api/impact/weeks: newest first, from the first week the ledger has to this week. Quiet weeks rest; nothing is lost. */
|
|
172
|
+
function weeksView(F, o) {
|
|
173
|
+
const thisWeek = weekOf(o.today, o.start);
|
|
174
|
+
const live = gateOf(F, thisWeek, o.start).state === 'open';
|
|
175
|
+
if (!live) return { live, weeks: [] };
|
|
176
|
+
const W = itemsByWeek(F, o.start), all = [...W.keys()].filter((w) => w <= thisWeek).sort();
|
|
177
|
+
const weeks = [];
|
|
178
|
+
if (all.length) for (let w = thisWeek; w >= all[0]; w = addDays(w, -7)) {
|
|
179
|
+
const real = (W.get(w) || []).filter((x) => x.real === true).sort(byNewest);
|
|
180
|
+
weeks.push({ week: w, from: w, to: addDays(w, 6), label: labelOf(w, thisWeek), quiet: real.length === 0, items: real.map(shown) });
|
|
181
|
+
}
|
|
182
|
+
return { live, weeks };
|
|
183
|
+
}
|
|
184
|
+
/** PURE. GET /api/impact/check: the oldest finished week with a row not checked yet, all its rows (checked ones keep their mark). */
|
|
185
|
+
function checkView(F, o) {
|
|
186
|
+
const thisWeek = weekOf(o.today, o.start), W = itemsByWeek(F, o.start);
|
|
187
|
+
const gate = gateOf(F, thisWeek, o.start).state;
|
|
188
|
+
const open = [...W.keys()].filter((w) => w < thisWeek && W.get(w).some((x) => x.real === null)).sort();
|
|
189
|
+
if (!open.length) return { due: false, week: null, label: '', items: [], gate };
|
|
190
|
+
const week = open[0];
|
|
191
|
+
return { due: true, week, label: labelOf(week, thisWeek), items: W.get(week).sort(byNewest).map(shown), gate };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
module.exports = { LEDGER, KINDS, SOURCE_TYPES, GROW, GATE_ITEMS, GATE_WEEKS, COUNT_RE, dirOf, ledgerFile, readLines, read, append, clean, fold,
|
|
195
|
+
weekOf, labelOf, dayOf, addDays, gateOf, weekView, weeksView, checkView };
|
|
@@ -21,6 +21,7 @@
|
|
|
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
23
|
const IG = require('./insights-goals.js');
|
|
24
|
+
const GS = require('./goal-status.js'); // batch 16 item 6: the one status of a goal, from its readings
|
|
24
25
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
25
26
|
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; };
|
|
26
27
|
const shortDate = (v) => { const t = isoDay(v); if (t === null) return ''; const d = new Date(t); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()]; };
|
|
@@ -302,8 +303,23 @@ function milestoneOf(r, i) {
|
|
|
302
303
|
/** One goal per KR metric record, with or without a series. `today` is a day in ms (UTC midnight). */
|
|
303
304
|
/** A KR metric record's role on Intelligence (batch 15 item 1): the North Star, an input or a guardrail of it, a key result, or a program's or an
|
|
304
305
|
* initiative's own measure (lib/metric-drafts.js writes them on a ✓). A record with none is a key result. */
|
|
305
|
-
const ROLES = ['north-star', 'input', 'guardrail', 'kr', 'program-goal', 'rollup', 'success', 'signal'];
|
|
306
|
-
|
|
306
|
+
const ROLES = ['north-star', 'input', 'guardrail', 'kr', 'program-goal', 'rollup', 'success', 'signal', 'watch'];
|
|
307
|
+
const NOTIFY = ['push', 'intel', 'quiet'];
|
|
308
|
+
/** batch 16 item 6 ("Claude runs the OKRs"): what the goal list and the goal Viewer read on each goal, beside today's fields. The dot is the
|
|
309
|
+
* reading's (lib/goal-status.js), never an initiative's delivery status. w: { reads (lib/metric-reads.js fold), history: { rid: [{ at, text }] } } */
|
|
310
|
+
function watchFields(x, o, todayIso, w) {
|
|
311
|
+
// the outcome's own baseline, target, date and unit first: a goal's meta may hold only what New goal keeps (6-B, 2026-10-28)
|
|
312
|
+
const rec = Object.assign({ target: o.target, baseline: o.start, by: o.by, unit: o.unit }, x, { readings: (x && x.readings) || (o.readings || []).map((r) => ({ at: r.at, value: r.v })) });
|
|
313
|
+
const R = w && w.reads ? w.reads.rids.get(o.id) : null;
|
|
314
|
+
const recipe = x && x.recipe && typeof x.recipe === 'object' && x.recipe.connector ? { connector: String(x.recipe.connector), query: String(x.recipe.query || ''), cadence: x.recipe.cadence || 'weekly',
|
|
315
|
+
last: R && R.last ? { at: R.last.at, ok: R.last.ok, ...(R.last.ok ? {} : { error: R.last.error }) } : null } : null;
|
|
316
|
+
return { reading: GS.readingOf(rec, todayIso), recipe, who: GS.whoOf(x || {}), notify: NOTIFY.includes(x && x.notify) ? x.notify : 'intel',
|
|
317
|
+
was: x && typeof x.was === 'string' && x.was ? clip(x.was, 200) : null, defn: x && typeof x.defn === 'string' ? clip(x.defn, 400) : '',
|
|
318
|
+
history: (w && w.history && w.history[o.id]) || [], kr: x && typeof x.kr === 'string' ? x.kr : null, budget: x && typeof x.budget === 'string' ? x.budget : null,
|
|
319
|
+
alert: R && R.alert && R.alert.open ? { day: R.alert.day, value: R.alert.value, limit: R.alert.limit } : null };
|
|
320
|
+
}
|
|
321
|
+
function goalsOf(outcomes, charts, inits, today, meta, w) {
|
|
322
|
+
const todayIso = new Date(today).toISOString().slice(0, 10);
|
|
307
323
|
return outcomes.map((o) => {
|
|
308
324
|
const x = (meta && meta[o.id]) || {}; // the fields New goal keeps on the record (lib/insights-goals.js goalFields)
|
|
309
325
|
const c = charts.find((x) => x.id === o.id) || null;
|
|
@@ -346,9 +362,19 @@ function goalsOf(outcomes, charts, inits, today, meta) {
|
|
|
346
362
|
now, nowTxt: now !== null ? num(now, u) : '', target: tgt, targetTxt: tgt !== null ? num(tgt, u) : '', by: byAt ? shortDate(byAt) : '', byAt, fromAt,
|
|
347
363
|
done, timeGone, tone: STATE_TONE[o.status] || 'q', state: o.status || 'unscored', chip: (CHIP[o.status] || ['No line scored'])[0], reason: o.reason || '',
|
|
348
364
|
proj: p ? { atDue: r1(p.atDue), reaches: p.reaches, toward: p.toward } : null, pace, readings: rs.length, moves,
|
|
365
|
+
...watchFields(x, o, todayIso, w),
|
|
349
366
|
};
|
|
350
367
|
});
|
|
351
368
|
}
|
|
369
|
+
/** The ✦ line and the open limit alert (batch 16 item 6). drafts: the product's open drafts (lib/metric-drafts.js), counted by the route. */
|
|
370
|
+
function okrOf(model, drafts) {
|
|
371
|
+
const goals = (model.goals || []).filter((g) => g.role !== 'watch');
|
|
372
|
+
const a = goals.find((g) => g.alert);
|
|
373
|
+
const alert = a ? { rid: a.id, title: a.title, at: a.alert.day, txt: a.reading.txt, line: a.reading.line } : null;
|
|
374
|
+
// the owner the page shows is the goal's owner string: a goal with one has an owner on the ✦ line too
|
|
375
|
+
const named = goals.map((g) => (g.who || !g.owner ? g : Object.assign({}, g, { who: { name: g.owner, initials: GS.initials(g.owner), from: 'pm' } })));
|
|
376
|
+
return { line: GS.lineOf({ goals: named, drafts, alert, moved: GS.movedOf(named) }), alert };
|
|
377
|
+
}
|
|
352
378
|
/** Shipped work (Deliver, Monitor, Evaluate, or done) against what its anchor goal promised. PURE. */
|
|
353
379
|
function outcomesOf(inits, goals, outcomes, verdicts, todayIso) {
|
|
354
380
|
const ORDER = ['verdict', 'window', 'decided'];
|
|
@@ -378,6 +404,16 @@ function budgetsOf(inits, registry) {
|
|
|
378
404
|
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 };
|
|
379
405
|
});
|
|
380
406
|
}
|
|
407
|
+
/** batch 16 item 6: a budget's limit reading comes from the kr-metrics record that names it (budget: <id>, a Stay within). With none, its dot is
|
|
408
|
+
* none. `reading` stays today's initiative share (lib/insights-goals.js budgetReading); the limit reading is `limit`. */
|
|
409
|
+
function budgetWatch(budgets, goals) {
|
|
410
|
+
for (const b of budgets || []) {
|
|
411
|
+
const g = (goals || []).find((x) => x.budget === b.id) || null;
|
|
412
|
+
Object.assign(b, { goal: g ? g.id : null, limit: g ? g.reading : { dot: 'none', at: null, ageDays: null, stale: false, txt: '', line: '', value: null }, recipe: g ? g.recipe : null,
|
|
413
|
+
who: g ? g.who : null, notify: g ? g.notify : 'intel', outcome: b.covers || (g ? g.title : '') });
|
|
414
|
+
}
|
|
415
|
+
return budgets;
|
|
416
|
+
}
|
|
381
417
|
|
|
382
418
|
function build(facts) {
|
|
383
419
|
const f = facts || {};
|
|
@@ -416,12 +452,15 @@ function build(facts) {
|
|
|
416
452
|
};
|
|
417
453
|
const today = isoDay(new Date(fin(f.now) ? f.now : Date.now()).toISOString()) || 0;
|
|
418
454
|
model.today = new Date(today).toISOString().slice(0, 10);
|
|
419
|
-
model.goals = goalsOf(outcomes, charts, f.initiatives || [], today, f.goalMeta || {});
|
|
455
|
+
model.goals = goalsOf(outcomes, charts, f.initiatives || [], today, f.goalMeta || {}, f.watch || null);
|
|
420
456
|
model.initiativesRead = Array.isArray(f.initiatives);
|
|
421
457
|
const ins = f.ins || { charts: {}, verdicts: {}, targets: {} }, bid = board.id || '';
|
|
422
458
|
model.outcomes = outcomesOf(f.initiatives || [], model.goals, outcomes, ins.verdicts[bid] || {}, model.today);
|
|
423
459
|
model.budgets = budgetsOf(f.initiatives || [], f.budgets || []);
|
|
424
460
|
model.budgetsRead = Array.isArray(f.budgets);
|
|
461
|
+
budgetWatch(model.budgets, model.goals);
|
|
462
|
+
model.metrics = GS.metricsOf(model.goals);
|
|
463
|
+
model.okr = okrOf(model, (f.watch && f.watch.drafts) || 0);
|
|
425
464
|
model.lateNow = Array.isArray(f.initiatives) ? f.initiatives.filter((r) => r && r.status === 'late').length : null;
|
|
426
465
|
model.trends = Object.assign(IG.trendsOf(Array.isArray(f.initiatives) ? f.initiatives : null, model.today), { targets: ins.targets || {}, tiles: ins.tiles || {} });
|
|
427
466
|
model.chartSet = ins.charts[bid] || {}; // { [dashboard]: { [goal]: { form, range, compare, target, forecast, note } } }
|
|
@@ -430,4 +469,4 @@ function build(facts) {
|
|
|
430
469
|
return model;
|
|
431
470
|
}
|
|
432
471
|
|
|
433
|
-
module.exports = { lifeIndex, goalType, goalsOf, outcomesOf, budgetsOf, mdDate, build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
472
|
+
module.exports = { okrOf, watchFields, budgetWatch, lifeIndex, goalType, goalsOf, outcomesOf, budgetsOf, mdDate, build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* SCOPE_RE · scopeOf(source) · sourceOf(scope) a report covers the whole view, one dashboard, or one key result or outcome:
|
|
6
6
|
* source "intelligence:view" | "intelligence:dashboard:<id>" | "intelligence:goal:<id>" | "intelligence:outcome:<id>"
|
|
7
|
+
* and, for a ready-made report (batch 17 item 1, lib/ready-reports.js), "intelligence:product",
|
|
8
|
+
* "intelligence:program:<id>" or "intelligence:initiative:<id>". A program's goals are its own and the ones
|
|
9
|
+
* its initiatives move (model.members[<id>] lists them); an initiative's are its own and the ones it moves
|
|
7
10
|
* goalsIn(model, scope) → the goals the scope covers
|
|
8
11
|
* storylineOf(model, { scope, ask, items }) → { answer, points, items: [{ id, kind, title, sub, on, bind }], scope, name } the draft (RfA2)
|
|
9
12
|
* checkStoryline(input) → { ok, storyline } | { ok: false, error } the shape the setup line keeps
|
|
@@ -23,8 +26,8 @@
|
|
|
23
26
|
* Every number is a reading, a target or a line through readings. No data, no line: a goal with no reading is never given a number.
|
|
24
27
|
* Plan today is the straight line from the first reading to the target on its date, as the design's footnote says. */
|
|
25
28
|
|
|
26
|
-
const SCOPE_RE = /^(view|(dashboard|goal|outcome):[A-Za-z0-9._:-]{1,100})$/;
|
|
27
|
-
const SOURCE_RE = /^intelligence:(view|(dashboard|goal|outcome):[A-Za-z0-9._:-]{1,100})$/;
|
|
29
|
+
const SCOPE_RE = /^(view|product|(dashboard|goal|outcome|program|initiative):[A-Za-z0-9._:-]{1,100})$/;
|
|
30
|
+
const SOURCE_RE = /^intelligence:(view|product|(dashboard|goal|outcome|program|initiative):[A-Za-z0-9._:-]{1,100})$/;
|
|
28
31
|
const MON = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
29
32
|
const DAY = 864e5;
|
|
30
33
|
const ITEM_KINDS = ['ask', 'scorecard', 'exhibit', 'verdict', 'unknown', 'appendix'];
|
|
@@ -57,6 +60,11 @@ function goalsIn(model, scope) {
|
|
|
57
60
|
const s = String(scope || 'view');
|
|
58
61
|
if (s.startsWith('goal:')) return G.filter((g) => g.id === s.slice(5));
|
|
59
62
|
if (s.startsWith('outcome:')) { const o = ((model && model.outcomes) || []).find((x) => x.id === s.slice(8)); return o && o.goal ? G.filter((g) => g.id === o.goal.id) : []; }
|
|
63
|
+
if (s.startsWith('program:')) {
|
|
64
|
+
const id = s.slice(8), mem = new Set(((model && model.members) || {})[id] || []);
|
|
65
|
+
return G.filter((g) => g.program === id || (!g.initiative && !g.program && (g.moves || []).some((m) => mem.has(m.id))) || (g.initiative && mem.has(g.initiative)));
|
|
66
|
+
}
|
|
67
|
+
if (s.startsWith('initiative:')) { const id = s.slice(11); return G.filter((g) => g.initiative === id || (!g.initiative && !g.program && (g.moves || []).some((m) => m.id === id))); }
|
|
60
68
|
if (s.startsWith('dashboard:')) {
|
|
61
69
|
const D = ((model && model.dashboards) || []).find((d) => d.id === s.slice(10));
|
|
62
70
|
if (!D) return [];
|
|
@@ -72,6 +80,7 @@ function scopeName(model, scope) {
|
|
|
72
80
|
if (s.startsWith('goal:')) { const g = goalsIn(model, s)[0]; return g ? clip(g.title, 60) : board; }
|
|
73
81
|
if (s.startsWith('outcome:')) { const o = ((model && model.outcomes) || []).find((x) => x.id === s.slice(8)); return o ? clip(o.title, 60) : board; }
|
|
74
82
|
if (s.startsWith('dashboard:')) { const D = ((model && model.dashboards) || []).find((d) => d.id === s.slice(10)); return D ? clip(D.name, 60) : board; }
|
|
83
|
+
if (s.startsWith('program:') || s.startsWith('initiative:')) { const n = ((model && model.names) || {})[s]; return n ? clip(n, 60) : s.slice(s.indexOf(':') + 1); }
|
|
75
84
|
return board;
|
|
76
85
|
}
|
|
77
86
|
|
|
@@ -151,7 +160,7 @@ const GROUPS = ['North Star', 'Inputs', 'Key results', 'Health budget'];
|
|
|
151
160
|
function scoreRows(model, scope) {
|
|
152
161
|
const todayMs = dayMs(model && model.today) || Date.now();
|
|
153
162
|
const rows = goalsIn(model, scope).map((g) => rowOf(g, todayMs));
|
|
154
|
-
if (String(scope || 'view')
|
|
163
|
+
if (['view', 'product'].includes(String(scope || 'view'))) for (const b of (model && model.budgets) || []) { const r = budgetRowOf(b); if (r) rows.push(r); }
|
|
155
164
|
return GROUPS.map((name) => ({ name, rows: rows.filter((r) => r.group === name) })).filter((x) => x.rows.length);
|
|
156
165
|
}
|
|
157
166
|
|
|
@@ -175,7 +184,7 @@ function pointOf(r) {
|
|
|
175
184
|
}
|
|
176
185
|
function verdictsIn(model, scope) {
|
|
177
186
|
const ids = new Set(goalsIn(model, scope).map((g) => g.id));
|
|
178
|
-
return ((model && model.outcomes) || []).filter((o) => o.verdict && o.verdict.verdict && (!o.goal || ids.has(o.goal.id)) && (!String(scope).startsWith('outcome:') || o.id === String(scope).slice(8)));
|
|
187
|
+
return ((model && model.outcomes) || []).filter((o) => o.verdict && o.verdict.verdict && (!o.goal || ids.has(o.goal.id)) && (!String(scope).startsWith('outcome:') || o.id === String(scope).slice(8)) && (!String(scope).startsWith('initiative:') || o.id === String(scope).slice(11)));
|
|
179
188
|
}
|
|
180
189
|
const VERDICT_SAY = { kept: 'is kept', keep: 'is kept', iterate: 'is iterated on', revert: 'is reverted', rolled_back: 'is rolled back', retire: 'is retired' };
|
|
181
190
|
const verdictTitle = (o) => clip(o.title, 60) + ' ' + (VERDICT_SAY[String(o.verdict.verdict).toLowerCase()] || 'has a verdict: ' + clip(o.verdict.verdict, 30)) + (o.verdict.learned ? ': ' + clip(o.verdict.learned, 80) : '');
|
|
@@ -385,10 +394,32 @@ function documentOf(model, setup, opts = {}) {
|
|
|
385
394
|
out.push(sourceLine(model), '');
|
|
386
395
|
}
|
|
387
396
|
}
|
|
397
|
+
if (isObj(opts.ready)) out.push(...readyMd(opts.ready, issue, S.items.some((x) => x.kind === 'unknown' && x.on)));
|
|
388
398
|
out.push('Every number is frozen when this issue goes out. Changes go into the next issue.', '');
|
|
389
399
|
return out.join('\n');
|
|
390
400
|
}
|
|
391
401
|
|
|
402
|
+
/** The sections a ready-made report adds (batch 17 item 1, canvas PbA8): the milestones with promised and forecast, what was done since the issue
|
|
403
|
+
* before, what we don't know yet beyond the goals (a product that could not be read), and a note on a held source. Each line comes from a record the
|
|
404
|
+
* caller read (lib/ready-reports.js); nothing is drawn for an empty list. */
|
|
405
|
+
function readyMd(R, issue, hadUnknown) {
|
|
406
|
+
const out = [];
|
|
407
|
+
if (R.note) out.push(`> ${one(R.note)}`, '');
|
|
408
|
+
const ms = Array.isArray(R.milestones) ? R.milestones : [];
|
|
409
|
+
if (ms.length) {
|
|
410
|
+
const late = ms.filter((m) => m.status === 'Behind').length;
|
|
411
|
+
out.push(`## ${late ? late + ' of ' + ms.length + (ms.length === 1 ? ' milestone' : ' milestones') + (late === 1 ? ' is behind its promise' : ' are behind their promise') : ms.length === 1 ? 'The milestone is on its promise' : 'All ' + ms.length + ' milestones are on their promise'}`, '',
|
|
412
|
+
'| Milestone | Promised | Forecast | Status |', '|---|---|---|---|');
|
|
413
|
+
for (const m of ms) out.push(`| ${one(m.name)} | ${m.promised ? full(m.promised) : MISSING} | ${one(m.forecast || MISSING)} | ${one(m.status || MISSING)} |`);
|
|
414
|
+
out.push('', `Source: ${one(R.msSource || 'the stage and milestone dates, and Jira')}.`, '');
|
|
415
|
+
}
|
|
416
|
+
const done = Array.isArray(R.done) ? R.done : [];
|
|
417
|
+
if (done.length) { out.push(`## ${done.length} ${done.length === 1 ? 'thing was' : 'things were'} done since ${issue > 1 ? 'issue ' + (issue - 1) : 'last week'}`, ''); for (const d of done) out.push(`- ${one(d)}`); out.push('', `Source: ${one(R.doneSource || 'Jira and the tasks')}.`, ''); }
|
|
418
|
+
const unk = Array.isArray(R.unknown) ? R.unknown : [];
|
|
419
|
+
if (unk.length) { out.push(hadUnknown ? "## What we don't know yet about the products" : "## What we don't know yet", ''); for (const u of unk) out.push(`- ${one(u)}`); out.push('', 'Source: the connections PMOS reads for each product.', ''); }
|
|
420
|
+
return out;
|
|
421
|
+
}
|
|
422
|
+
|
|
392
423
|
// ── the five checks before it goes out ───────────────────────────────────────────────────────────────────────────────────────
|
|
393
424
|
const body = (t) => String(t || '').replace(/\r/g, '').replace(/^---\n[\s\S]*?\n---\n?/, '');
|
|
394
425
|
function sections(text) {
|
|
@@ -429,4 +460,4 @@ function storyChecks(markdown) {
|
|
|
429
460
|
return out;
|
|
430
461
|
}
|
|
431
462
|
|
|
432
|
-
module.exports = { SCOPE_RE, SOURCE_RE, ITEM_KINDS, scopeOf, sourceOf, isIntelligence, goalsIn, scopeName, scoreRows, storylineOf, checkStoryline, defaultsOf, proposalsOf, documentOf, storyChecks, actionsOf, rangeOf, planToday };
|
|
463
|
+
module.exports = { SCOPE_RE, SOURCE_RE, ITEM_KINDS, scopeOf, sourceOf, isIntelligence, goalsIn, scopeName, scoreRows, rowOf, storylineOf, checkStoryline, defaultsOf, proposalsOf, documentOf, storyChecks, actionsOf, rangeOf, planToday };
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* off(env) → true when PMOS_METRIC_DRAFT=off (or 0, false, no)
|
|
5
5
|
* quarterOf(day) → { start, end, prevStart, prevEnd } of the quarter `day` (YYYY-MM-DD) is in
|
|
6
|
-
* dueOf(o) PURE → [{ scope, id, why, title }] the scopes of one workspace that need a draft now, in the order they start
|
|
6
|
+
* dueOf(o) PURE → [{ scope, id, why, title, gaps? }] the scopes of one workspace that need a draft now, in the order they start
|
|
7
|
+
* gapsOf({ krs, records }) PURE → [{ key, line }] the OKR review's gaps: a declared key result with no metric, a goal with no recipe
|
|
7
8
|
* promptOf(skill, o) → the prompt of one run. o: { run, scope, id, why, title, today, facts: [line], kept: [line], dropped: [line] }
|
|
8
9
|
* create(deps) → { tick(opts), start({ ws, scope, id, why, press, now }), stop(run), active() }
|
|
9
10
|
*
|
|
@@ -13,6 +14,9 @@
|
|
|
13
14
|
* goal a program charter (in this workspace) has no goal and no kr-metrics record with role program-goal for it
|
|
14
15
|
* success an initiative has a PRD and no kr-metrics record with initiative: <id>. The first scan writes the epoch: an initiative that
|
|
15
16
|
* had its PRD then is history, so only one that gets its PRD later is drafted unasked (the PM can press Draft again on any)
|
|
17
|
+
* review the OKR review (batch 16 item 6, "Claude runs the OKRs"): a key result the OKR files declare has no metric (a project-shaped
|
|
18
|
+
* goal), or a goal has no recipe to read it. The run drafts fixes (outcome, recipe, connect, …) with `pmos metrics draft fix`.
|
|
19
|
+
* It runs again only when the gaps change (their signature is on the start line), or the next day after a failed run.
|
|
16
20
|
* A scope that was drafted once is not drafted again unasked; one whose last run failed tries again the next day. A retired record counts
|
|
17
21
|
* as no record. "Draft again" (POST /api/metric-drafts/start) starts a run at once, why `press`.
|
|
18
22
|
*
|
|
@@ -47,6 +51,16 @@ function quarterOf(day) {
|
|
|
47
51
|
return { start: `${y}-${p2(q0)}-01`, end: `${y}-${p2(q0 + 2)}-${p2(lastDay(y, q0 + 2))}`, prevStart: `${py}-${p2(pq)}-01`, prevEnd: `${py}-${p2(pq + 2)}-${p2(lastDay(py, pq + 2))}` };
|
|
48
52
|
}
|
|
49
53
|
const live = (records) => (records || []).filter((r) => r && r.retired !== true);
|
|
54
|
+
/** The OKR review's gaps. krs: the key results the OKR files declare, [{ value, label }] (lib/initiative-rows.js anchorsOf list). A record names a
|
|
55
|
+
* key result by kr (its anchor), its rid, or its metric name. */
|
|
56
|
+
function gapsOf({ krs, records } = {}) {
|
|
57
|
+
const R = live(records), out = [];
|
|
58
|
+
const named = (k) => R.some((r) => [r.kr, r.rid, r.metric].some((x) => x && (String(x) === k.value || String(x) === k.label || String(x).toLowerCase() === String(k.label || '').replace(/^\S+\s+/, '').toLowerCase())));
|
|
59
|
+
for (const k of krs || []) if (k && k.value && !named(k)) out.push({ key: 'kr:' + k.value, line: 'Key result ' + one(k.value, 60) + ' has no metric. Its text: "' + one(k.label, 160) + '". If it names a project, draft it as an outcome.' });
|
|
60
|
+
for (const r of R) if (r.role !== 'watch' && !(r.recipe && r.recipe.connector)) out.push({ key: 'recipe:' + r.rid, line: 'Goal ' + r.rid + ' · ' + one(r.metric, 100) + ' has no recipe, so I cannot read it by myself.' });
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
const sigOfGaps = (gaps) => crypto.createHash('sha1').update((gaps || []).map((g) => g.key).sort().join('|')).digest('hex').slice(0, 12);
|
|
50
64
|
/** Unasked, a scope is drafted once; a failed run tries again on a later day. */
|
|
51
65
|
function mayDraft(s, why, day) {
|
|
52
66
|
const runs = s ? s.runs.filter((r) => why === 'quarter' ? r.why === 'quarter' : r.why !== 'quarter') : [];
|
|
@@ -74,6 +88,11 @@ function dueOf(o) {
|
|
|
74
88
|
if (R.some((r) => r.program === p.id && r.role === 'program-goal')) continue;
|
|
75
89
|
if (mayDraft(sOf('program', p.id), 'goal', day)) out.push({ scope: 'program', id: p.id, why: 'goal', title: p.title || p.id });
|
|
76
90
|
}
|
|
91
|
+
// the OKR review: once per set of gaps; a failed run tries again the next day
|
|
92
|
+
if ((o.gaps || []).length && !out.some((x) => x.scope === 'product')) {
|
|
93
|
+
const sig = sigOfGaps(o.gaps), s = sOf('product', o.ws), runs = s ? s.runs.filter((r) => r.why === 'review' && r.gaps === sig) : [], last = runs[runs.length - 1];
|
|
94
|
+
if (!last || (last.ended && !last.ok && !last.stopped && String(last.at).slice(0, 10) !== day)) out.push({ scope: 'product', id: o.ws, why: 'review', title: o.wsTitle || o.ws, gaps: o.gaps, sig });
|
|
95
|
+
}
|
|
77
96
|
const known = new Set((F.epoch && F.epoch.known) || []);
|
|
78
97
|
if (F.epoch) for (const i of o.initiatives || []) {
|
|
79
98
|
if (!i || !i.id || known.has(i.id)) continue;
|
|
@@ -89,12 +108,14 @@ const SHAPE = {
|
|
|
89
108
|
quarter: 'next quarter\'s Key results (at most 5), from how the last quarter ended',
|
|
90
109
|
program: 'a Program goal (1, with checkpoints at its milestones), Rolls up from (one per product) and a Guardrail (at most 1)',
|
|
91
110
|
initiative: 'Proves it worked (1, read 4 weeks after release), an Early signal (at most 1) and a Guardrail (at most 1)',
|
|
111
|
+
review: 'fixes for the gaps below (at most 12), filed with `pmos metrics draft fix`: an outcome for a key result that names a project, a recipe for a goal with no way to be read, connect for a source that is not connected',
|
|
92
112
|
};
|
|
93
113
|
function promptOf(skill, o) {
|
|
94
114
|
const list = (a, none) => (a && a.length ? a.map((x) => '- ' + x).join('\n') : '- ' + none);
|
|
95
|
-
const shape = o.why === 'quarter' ? SHAPE.quarter : SHAPE[o.scope];
|
|
115
|
+
const shape = o.why === 'quarter' ? SHAPE.quarter : o.why === 'review' ? SHAPE.review : SHAPE[o.scope];
|
|
96
116
|
return `${skill}\n\nThis run:\n- Run: ${o.run}\n- Scope: ${o.scope} ${o.id} · ${one(o.title, 140)}\n- Why it runs: ${MD.WHEN[o.why] || MD.WHEN.press} (${o.why})\n- Today: ${o.today}\n`
|
|
97
|
-
+ `- Draft: ${shape}. Groups:
|
|
117
|
+
+ `- Draft: ${shape}.${o.why === 'review' ? ' Fix kinds: ' + MD.FIXES.join(', ') + '.' : ' Groups: ' + (o.why === 'quarter' ? ['Key results'] : MD.GROUPS[o.scope].filter((g) => g !== 'Key results')).join(', ') + '.'}\n`
|
|
118
|
+
+ (o.why === 'review' ? `- The gaps:\n${list((o.gaps || []).map((g) => g.line), 'none')}\n` : '')
|
|
98
119
|
+ `- What PMOS knows:\n${list(o.facts, 'nothing more')}\n`
|
|
99
120
|
+ `- Already kept by the PM (do not draft these again):\n${list(o.kept, 'none')}\n`
|
|
100
121
|
+ `- Dropped by the PM (do not draft these again unless the evidence is new):\n${list(o.dropped, 'none')}\n\n`
|
|
@@ -117,7 +138,7 @@ function create(deps) {
|
|
|
117
138
|
}
|
|
118
139
|
|
|
119
140
|
/** Start one run now. → { ok, run } | { ok: false, error, held? } */
|
|
120
|
-
function start({ ws, scope, id, why = 'press', press = true, now = Date.now() } = {}) {
|
|
141
|
+
function start({ ws, scope, id, why = 'press', press = true, now = Date.now(), gaps = null, sig = null } = {}) {
|
|
121
142
|
if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { ok: false, error: 'Claude\'s metric drafts are off (PMOS_METRIC_DRAFT or PMOS_HEADLESS).' };
|
|
122
143
|
if (!MD.SCOPES.includes(scope) || !id) return { ok: false, error: 'Say which product, program or initiative to draft for.' };
|
|
123
144
|
const w = (deps.workspaces() || []).find((x) => x.id === ws);
|
|
@@ -135,7 +156,8 @@ function create(deps) {
|
|
|
135
156
|
const line = (r) => r.group + ' · ' + r.name + (r.targetTxt ? ' · ' + r.targetTxt : '');
|
|
136
157
|
let facts = [];
|
|
137
158
|
try { facts = (deps.facts && deps.facts(w, scope, id)) || []; } catch { facts = []; }
|
|
138
|
-
const
|
|
159
|
+
const shown = (r) => (r.kind && r.kind !== 'metric' ? r.kind + ' · ' + r.text : line(r));
|
|
160
|
+
const prompt = promptOf(skill, { run, scope, id, why, title, today: localDay(now), facts, gaps, kept: rows.filter((r) => r.state === 'kept').map(shown), dropped: rows.filter((r) => r.state === 'dropped').map(shown) });
|
|
139
161
|
const go = press && deps.spawnNow ? deps.spawnNow : deps.spawn;
|
|
140
162
|
active.set(run, { ws, scope, id, dir, session: null });
|
|
141
163
|
let session = null;
|
|
@@ -145,7 +167,7 @@ function create(deps) {
|
|
|
145
167
|
} catch (e) { warn('metric draft run', e); }
|
|
146
168
|
if (session && session.held) { active.delete(run); return { ok: false, held: true, error: 'Claude is busy with other runs. It tries again in a minute.' }; }
|
|
147
169
|
// the start line lands before the run's first `pmos metrics draft` (the run starts reading after this returns), stamped with the tick's clock
|
|
148
|
-
MD.append(dir, null, { kind: 'start', scope, id, run, why, title, when: MD.WHEN[why] || '' }, new Date(now).toISOString());
|
|
170
|
+
MD.append(dir, null, { kind: 'start', scope, id, run, why, title, when: MD.WHEN[why] || '', ...(sig ? { gaps: sig } : {}) }, new Date(now).toISOString());
|
|
149
171
|
if (!session || session.state === 'exited' || session.headless !== 'metric-draft') {
|
|
150
172
|
if (session && session.headless !== 'metric-draft' && session.state !== 'exited' && deps.stop) { try { deps.stop(session); } catch { /* best effort */ } }
|
|
151
173
|
ended(run, { code: 1, note: (session && session.note) || 'the run could not start in the background', result: {} }, now);
|
|
@@ -170,16 +192,17 @@ function create(deps) {
|
|
|
170
192
|
const dir = deps.stateDirFor(w); if (!dir) continue;
|
|
171
193
|
lastScan.set(w.id, now);
|
|
172
194
|
const F = MD.read(dir);
|
|
173
|
-
let records = [], programs = [], initiatives = [];
|
|
195
|
+
let records = [], programs = [], initiatives = [], krs = [];
|
|
174
196
|
try { records = deps.records(w) || []; } catch (e) { warn('metric draft records', e); continue; }
|
|
175
197
|
try { programs = (deps.programs && deps.programs(w)) || []; } catch { programs = []; }
|
|
176
198
|
try { initiatives = (deps.initiatives && deps.initiatives(w)) || []; } catch { initiatives = []; }
|
|
199
|
+
try { krs = (deps.krs && deps.krs(w)) || []; } catch { krs = []; }
|
|
177
200
|
// the first scan writes the epoch: the initiatives that have a PRD now are history (an old PRD is not a new one)
|
|
178
201
|
if (!F.epoch) { MD.append(dir, null, { kind: 'epoch', scope: null, id: null, known: initiatives.map((i) => i.id) }, new Date(now).toISOString()); F.epoch = { known: initiatives.map((i) => i.id) }; }
|
|
179
|
-
const due = dueOf({ ws: w.id, wsTitle: w.name || w.id, records, programs, initiatives, F, today: day });
|
|
202
|
+
const due = dueOf({ ws: w.id, wsTitle: w.name || w.id, records, programs, initiatives, F, today: day, gaps: gapsOf({ krs, records }) });
|
|
180
203
|
for (const d of due) {
|
|
181
204
|
if ([...active.values()].some((a) => a.ws === w.id && a.scope === d.scope && a.id === d.id)) continue;
|
|
182
|
-
const r = start({ ws: w.id, scope: d.scope, id: d.id, why: d.why, press: false, now });
|
|
205
|
+
const r = start({ ws: w.id, scope: d.scope, id: d.id, why: d.why, press: false, now, gaps: d.gaps || null, sig: d.sig || null });
|
|
183
206
|
if (r.ok) return { started: d.scope + ':' + d.id, why: d.why };
|
|
184
207
|
if (r.held) { lastScan.delete(w.id); return { held: true }; }
|
|
185
208
|
}
|
|
@@ -190,4 +213,4 @@ function create(deps) {
|
|
|
190
213
|
return { tick, start, stop, active: () => [...active.keys()], runOf: (ws, scope, id) => { for (const [r, a] of active) if (a.ws === ws && a.scope === scope && a.id === id) return r; return null; } };
|
|
191
214
|
}
|
|
192
215
|
|
|
193
|
-
module.exports = { off, quarterOf, dueOf, promptOf, create, MAX, SCAN_MS, QUARTER_DAYS };
|
|
216
|
+
module.exports = { off, quarterOf, dueOf, gapsOf, promptOf, create, MAX, SCAN_MS, QUARTER_DAYS };
|