create-pmos 0.397.0 → 0.399.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/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +105 -52
- package/workspace/briefing-premium-board-test.js +284 -128
- package/workspace/briefing-premium-calendar-2-test.js +135 -198
- package/workspace/briefing-premium-calendar-3-test.js +143 -418
- package/workspace/briefing-premium-calendar-test.js +85 -196
- package/workspace/briefing-premium-doc-edit-test.js +99 -83
- package/workspace/briefing-premium-initiative-test.js +175 -290
- package/workspace/briefing-premium-insights-test.js +414 -219
- package/workspace/briefing-premium-metrics-test.js +55 -97
- package/workspace/briefing-premium-products-test.js +44 -28
- package/workspace/briefing-premium-sources-test.js +70 -49
- package/workspace/briefing-premium-test.js +155 -648
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +24 -0
- package/workspace/ev-everywhere-test.js +210 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +187 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +68 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-grill.js +63 -0
- package/workspace/lib/board-premium.js +121 -24
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/initiative-layout.js +77 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +64 -15
- package/workspace/lib/insights-records.js +115 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/meeting-points.js +52 -0
- package/workspace/lib/news-for-you.js +88 -0
- package/workspace/lib/notes-series.js +29 -6
- package/workspace/lib/report-confirm.js +48 -0
- package/workspace/lib/route-modules.js +12 -0
- package/workspace/lib/routes-board-docs.js +46 -0
- package/workspace/lib/routes-board-grill.js +90 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-home-review.js +108 -0
- package/workspace/lib/routes-initiative-layout.js +57 -0
- package/workspace/lib/routes-insights-premium.js +16 -4
- package/workspace/lib/routes-insights-records.js +133 -0
- package/workspace/lib/routes-meeting-points.js +37 -0
- package/workspace/lib/routes-news.js +57 -0
- package/workspace/lib/routes-notes.js +3 -1
- package/workspace/lib/routes-report-confirm.js +31 -0
- package/workspace/lib/routes-search.js +38 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/search-index.js +176 -0
- package/workspace/lib/transcript-steps.js +123 -0
- 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-board-actions-test.js +128 -82
- package/workspace/premium-briefing-depth-test.js +104 -90
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +37 -37
- package/workspace/premium-chat-context-test.js +19 -18
- package/workspace/premium-chat-goal-view-test.js +23 -23
- package/workspace/premium-chat-notes-test.js +26 -31
- package/workspace/premium-chat-report-tab-test.js +46 -28
- package/workspace/premium-chat-term-test.js +16 -16
- package/workspace/premium-chat-viewer-test.js +60 -59
- package/workspace/premium-core-doc-issue-test.js +52 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +10 -3
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +152 -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 -33
- package/workspace/premium-vw-cal-test.js +97 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +17 -10
- package/workspace/premium-vw-item-test.js +50 -49
- package/workspace/premium-vw-jira-test.js +53 -27
- package/workspace/premium-vw-meet-test.js +115 -187
- package/workspace/premium-vw-notes-test.js +88 -109
- package/workspace/premium-vw-rec-test.js +71 -194
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +61 -53
- package/workspace/public/pm/bd-acts.js +383 -0
- package/workspace/public/pm/bd-asks.js +261 -0
- package/workspace/public/pm/bd-pop.js +59 -0
- package/workspace/public/pm/bd-span.js +222 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- package/workspace/public/pm/bd-views.js +169 -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 +798 -230
- package/workspace/public/pm/cozy-ev.css +228 -0
- package/workspace/public/pm/cozy-evmodel.js +106 -0
- package/workspace/public/pm/cozy-evui.js +47 -0
- package/workspace/public/pm/cozy-home.css +570 -142
- package/workspace/public/pm/cozy-home.js +5 -3
- package/workspace/public/pm/cozy-insights.css +437 -170
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +104 -29
- package/workspace/public/pm/cozy-news.js +140 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-search.js +203 -0
- package/workspace/public/pm/cozy-settings.js +198 -0
- package/workspace/public/pm/cozy-sources.js +89 -0
- package/workspace/public/pm/cozy-today.css +217 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +145 -0
- package/workspace/public/pm/cozy-vw-mtg.css +350 -0
- package/workspace/public/pm/cozy-vw-rp.css +152 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +83 -1
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +1179 -0
- package/workspace/public/pm/home-around.js +413 -0
- package/workspace/public/pm/home-chat.js +512 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-dictate.js +54 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-ini-model.js +190 -0
- package/workspace/public/pm/home-ini.css +171 -0
- package/workspace/public/pm/home-ini.js +456 -0
- package/workspace/public/pm/home-list.js +276 -0
- package/workspace/public/pm/home-more.js +132 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-review.js +104 -0
- package/workspace/public/pm/home-task.js +67 -0
- package/workspace/public/pm/home-today.js +144 -0
- package/workspace/public/pm/home-work.js +547 -0
- 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 +548 -395
- package/workspace/public/pm/premium-chart-tab.js +109 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +23 -21
- package/workspace/public/pm/premium-insights.js +1102 -581
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-mtg-present.js +138 -0
- package/workspace/public/pm/premium-mtg-replay.js +142 -0
- 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 +669 -476
- package/workspace/public/pm/premium-report-tab.js +116 -67
- package/workspace/public/pm/premium-shell.js +76 -123
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +277 -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-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +958 -0
- package/workspace/public/pm/premium-vw-notes.js +116 -68
- 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 -218
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/rp-parts.js +269 -0
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +29 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +26 -64
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +18 -107
- package/workspace/r/m1.png +0 -0
- package/workspace/r/m2.png +0 -0
- package/workspace/r/m3.png +0 -0
- package/workspace/r/nl.png +0 -0
- package/workspace/server.js +18 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/initiative-layout.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
- package/workspace/test-lists/premium-uncovered-reports.json +9 -0
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/test-lists/uf-everywhere.json +15 -0
- package/workspace/test-lists/uf-home.json +9 -0
- package/workspace/test-lists/uncovered-board.json +9 -0
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -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,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* lib/initiative-layout.js — the PM's own choices about one initiative's layout inside Home (initiative premium-uncovered-features, Initiative;
|
|
3
|
+
* canvas InStage, InTasks, InDocs, InPhone).
|
|
4
|
+
*
|
|
5
|
+
* fold(lines, initiative) → { auto, held, by, names, of, stage } PURE. The last line of each kind for the initiative wins.
|
|
6
|
+
* foldSets(lines) → [{ name, names }] PURE. The saved group sets, for every initiative of the workspace.
|
|
7
|
+
* eventOf(body) → { ok, event } | { ok: false, error } PURE. Checks one press and turns it into the line to append.
|
|
8
|
+
*
|
|
9
|
+
* What it holds:
|
|
10
|
+
* auto "Moves on by itself": true unless the PM turned it off (default on)
|
|
11
|
+
* held the stages the PM undid a move by itself out of: the page does not move out of them by itself again
|
|
12
|
+
* by how the Tasks card groups: 'stage' | 'mine' (the groups the PM names) | 'owner' | 'status' | 'none'
|
|
13
|
+
* names the PM's group names, in order
|
|
14
|
+
* of task key → the PM's group name
|
|
15
|
+
* stage task key → the stage the task belongs to (a task records none of its own)
|
|
16
|
+
* The stage move itself is not here: it is a move of POST /api/boards/move, with its note or reason as the move's why. */
|
|
17
|
+
|
|
18
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
|
|
19
|
+
const TASK_RE = /^(task|req):[A-Za-z0-9][A-Za-z0-9._:#/-]{0,120}$/;
|
|
20
|
+
const BY = ['stage', 'mine', 'owner', 'status', 'none'];
|
|
21
|
+
const KINDS = ['auto', 'hold', 'by', 'groups', 'rename', 'place', 'stage', 'set', 'unset'];
|
|
22
|
+
const name = (v, n = 40) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
23
|
+
const names = (v) => { const out = []; for (const x of Array.isArray(v) ? v : []) { const s = name(x); if (s && !out.some((y) => y.toLowerCase() === s.toLowerCase())) out.push(s); } return out.slice(0, 12); };
|
|
24
|
+
|
|
25
|
+
function empty() { return { auto: true, held: [], by: 'stage', names: [], of: {}, stage: {} }; }
|
|
26
|
+
|
|
27
|
+
function fold(lines, initiative) {
|
|
28
|
+
const o = empty();
|
|
29
|
+
for (const l of lines || []) {
|
|
30
|
+
if (!l || l.initiative !== initiative) continue;
|
|
31
|
+
if (l.kind === 'auto') { o.auto = l.on !== false; if (o.auto) o.held = []; }
|
|
32
|
+
else if (l.kind === 'hold' && l.stage && !o.held.includes(l.stage)) o.held.push(l.stage);
|
|
33
|
+
else if (l.kind === 'by' && BY.includes(l.by)) o.by = l.by;
|
|
34
|
+
else if (l.kind === 'groups') {
|
|
35
|
+
o.names = names(l.names);
|
|
36
|
+
for (const k of Object.keys(o.of)) if (!o.names.includes(o.of[k])) delete o.of[k]; // a deleted group lets its tasks go
|
|
37
|
+
} else if (l.kind === 'rename') {
|
|
38
|
+
const i = o.names.indexOf(l.from);
|
|
39
|
+
if (i >= 0 && l.to && !o.names.includes(l.to)) { o.names[i] = l.to; for (const k of Object.keys(o.of)) if (o.of[k] === l.from) o.of[k] = l.to; }
|
|
40
|
+
} else if (l.kind === 'place' && l.task) { if (l.group && o.names.includes(l.group)) o.of[l.task] = l.group; else delete o.of[l.task]; }
|
|
41
|
+
else if (l.kind === 'stage' && l.task) { if (l.stage) o.stage[l.task] = l.stage; else delete o.stage[l.task]; }
|
|
42
|
+
}
|
|
43
|
+
return o;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function foldSets(lines) {
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const l of lines || []) {
|
|
49
|
+
if (!l || (l.kind !== 'set' && l.kind !== 'unset') || !l.name) continue;
|
|
50
|
+
const i = out.findIndex((s) => s.name.toLowerCase() === String(l.name).toLowerCase());
|
|
51
|
+
if (i >= 0) out.splice(i, 1);
|
|
52
|
+
if (l.kind === 'set') out.push({ name: l.name, names: names(l.names) });
|
|
53
|
+
}
|
|
54
|
+
return out.slice(-20);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function eventOf(b) {
|
|
58
|
+
const o = b || {};
|
|
59
|
+
if (!KINDS.includes(o.kind)) return { ok: false, error: 'kind is one of ' + KINDS.join(', ') };
|
|
60
|
+
if (o.kind !== 'set' && o.kind !== 'unset' && !ID_RE.test(String(o.initiative || ''))) return { ok: false, error: 'initiative must name an initiative' };
|
|
61
|
+
const base = { kind: o.kind };
|
|
62
|
+
if (o.kind !== 'set' && o.kind !== 'unset') base.initiative = o.initiative;
|
|
63
|
+
switch (o.kind) {
|
|
64
|
+
case 'auto': if (typeof o.on !== 'boolean') return { ok: false, error: 'on is true or false' }; return { ok: true, event: { ...base, on: o.on } };
|
|
65
|
+
case 'hold': { const s = name(o.stage); if (!s) return { ok: false, error: 'stage names the stage' }; return { ok: true, event: { ...base, stage: s } }; }
|
|
66
|
+
case 'by': if (!BY.includes(o.by)) return { ok: false, error: 'by is one of ' + BY.join(', ') }; return { ok: true, event: { ...base, by: o.by } };
|
|
67
|
+
case 'groups': if (!Array.isArray(o.names)) return { ok: false, error: 'names is a list of group names' }; return { ok: true, event: { ...base, names: names(o.names) } };
|
|
68
|
+
case 'rename': { const f = name(o.from), t = name(o.to); if (!f || !t) return { ok: false, error: 'from and to name the group' }; return { ok: true, event: { ...base, from: f, to: t } }; }
|
|
69
|
+
case 'place': if (!TASK_RE.test(String(o.task || ''))) return { ok: false, error: 'task names a task' }; return { ok: true, event: { ...base, task: o.task, group: name(o.group) } };
|
|
70
|
+
case 'stage': if (!TASK_RE.test(String(o.task || ''))) return { ok: false, error: 'task names a task' }; return { ok: true, event: { ...base, task: o.task, stage: name(o.stage) } };
|
|
71
|
+
case 'set': { const n = name(o.name, 80); const l = names(o.names); if (!n) return { ok: false, error: 'name the set' }; if (!l.length) return { ok: false, error: 'a set holds at least one group' }; return { ok: true, event: { ...base, name: n, names: l } }; }
|
|
72
|
+
case 'unset': { const n = name(o.name, 80); if (!n) return { ok: false, error: 'name the set' }; return { ok: true, event: { ...base, name: n } }; }
|
|
73
|
+
default: return { ok: false, error: 'unknown kind' };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = { fold, foldSets, eventOf, BY, KINDS };
|
|
@@ -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,8 @@ 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
|
+
sections: s.structure && Array.isArray(s.structure.sections) ? s.structure.sections.map((x) => (typeof x === 'string' ? x : x && (x.title || x.heading || x.name))).filter((x) => typeof x === 'string' && x.trim()).map((x) => clip(x, 80)).slice(0, 8) : [], // premium-uncovered-features: IsLibrary "Sections"
|
|
197
|
+
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
198
|
}));
|
|
196
199
|
const found = (su.findings || []).slice(0, 3).map((x) => ({
|
|
197
200
|
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) })),
|
|
@@ -276,15 +279,21 @@ function goalType(unit) {
|
|
|
276
279
|
return 'Count';
|
|
277
280
|
}
|
|
278
281
|
const STATE_TONE = { ok: 'ok', drift: 'late', off: 'red', unscored: 'q' };
|
|
282
|
+
/** 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. */
|
|
283
|
+
const mdDate = (v) => { const t = isoDay(v); if (t === null) return ''; const d = new Date(t); return MON[d.getUTCMonth()] + ' ' + d.getUTCDate(); };
|
|
284
|
+
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; };
|
|
285
|
+
const ptsOf = (v, u) => (String(u).trim() === '%' ? r2(v) + (r2(v) === 1 ? ' pt' : ' pts') : num(v, u));
|
|
279
286
|
const anchorHits = (a, o) => !!a && (String(a) === String(o.id) || String(a) === String(o.name));
|
|
280
287
|
function initOf(r) {
|
|
281
288
|
const i = lifeIndex(r.stage);
|
|
282
289
|
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 || '',
|
|
283
|
-
owner: r.owner || '', end: r.end ? shortDate(r.end) : '', endAt: r.end ? String(r.end).slice(0, 10) : null, anchor: r.anchor || ''
|
|
290
|
+
owner: r.owner || '', end: r.end ? shortDate(r.end) : '', endAt: r.end ? String(r.end).slice(0, 10) : null, anchor: r.anchor || '',
|
|
291
|
+
startAt: r.start ? String(r.start).slice(0, 10) : null, skipped: IG.skippedOf(r.warnings) };
|
|
284
292
|
}
|
|
285
293
|
/** One goal per KR metric record, with or without a series. `today` is a day in ms (UTC midnight). */
|
|
286
|
-
function goalsOf(outcomes, charts, inits, today) {
|
|
294
|
+
function goalsOf(outcomes, charts, inits, today, meta) {
|
|
287
295
|
return outcomes.map((o) => {
|
|
296
|
+
const x = (meta && meta[o.id]) || {}; // the fields New goal keeps on the record (lib/insights-goals.js goalFields)
|
|
288
297
|
const c = charts.find((x) => x.id === o.id) || null;
|
|
289
298
|
const rs = (o.readings || []).filter((x) => x && fin(x.v) && isoDay(x.at) !== null);
|
|
290
299
|
const u = o.unit || '', base = fin(o.start) ? o.start : null, tgt = fin(o.target) ? o.target : null;
|
|
@@ -294,18 +303,33 @@ function goalsOf(outcomes, charts, inits, today) {
|
|
|
294
303
|
const t0 = isoDay(fromAt), t1 = isoDay(byAt);
|
|
295
304
|
const timeGone = t0 !== null && t1 !== null && t1 > t0 ? Math.max(0, Math.min(1, (today - t0) / (t1 - t0))) : null;
|
|
296
305
|
const done = now !== null && tgt !== null && base !== null && tgt !== base ? Math.max(0, Math.min(1, (now - base) / (tgt - base))) : null;
|
|
297
|
-
const
|
|
306
|
+
const p0 = c ? projectionOf(c) : null;
|
|
307
|
+
/* a percentage cannot pass 100: the pace is said at the cap, not as "≈100.3%" */
|
|
308
|
+
const p = p0 && /^%$/.test(u.trim()) && p0.atDue > 100 ? Object.assign({}, p0, { atDue: 100 }) : p0;
|
|
298
309
|
const reached = now !== null && tgt !== null && dir && (dir > 0 ? now >= tgt : now <= tgt);
|
|
299
310
|
let pace;
|
|
300
|
-
if (reached) pace = { tone: 'ok', head: 'Reached', sub: 'at ' + num(now, u) + (rs.length ? ' on ' +
|
|
311
|
+
if (reached) pace = { tone: 'ok', head: 'Reached', sub: 'at ' + num(now, u) + (rs.length ? ' on ' + mdDate(rs[rs.length - 1].at) : '') };
|
|
301
312
|
else if (p && !p.toward) pace = { tone: 'late', head: 'Never reaches ' + num(tgt, u), sub: p.perWeek === 0 ? 'not moving' : 'moving the wrong way' };
|
|
302
|
-
else if (p && !p.reaches) pace = { tone: 'late', head: '≈' + num(
|
|
303
|
-
else if (p) pace = { tone: 'ok', head: '≈' + num(
|
|
313
|
+
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' };
|
|
314
|
+
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' };
|
|
304
315
|
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' };
|
|
316
|
+
if (x.type === 'Stay within' && tgt !== null) { // a floor or a ceiling: within it or not, with the room left
|
|
317
|
+
const ceil = x.limit !== 'floor', inside = now === null ? null : ceil ? now <= tgt : now >= tgt;
|
|
318
|
+
pace = now === null ? { tone: 'q', head: '—', sub: 'no reading yet' }
|
|
319
|
+
: inside ? { tone: 'ok', head: 'Within its ' + (ceil ? 'ceiling' : 'floor'), sub: num(Math.abs(tgt - now), u) + ' of room left' }
|
|
320
|
+
: { 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) };
|
|
321
|
+
} else if (x.type === 'Done or not' && tgt !== null) {
|
|
322
|
+
const n = now === null ? 0 : now, all = Array.isArray(x.steps) && x.steps.length ? x.steps.length : null;
|
|
323
|
+
pace = n >= tgt ? { tone: 'ok', head: 'Done', sub: rs.length ? 'on ' + mdDate(rs[rs.length - 1].at) : '' }
|
|
324
|
+
: { tone: byAt && t1 !== null && t1 < today ? 'late' : 'q', head: 'Not yet', sub: (all ? n + ' of ' + all + ' steps · ' : '') + (byAt ? 'due ' + mdDate(byAt) : 'no due date') };
|
|
325
|
+
}
|
|
305
326
|
const moves = (inits || []).filter((r) => anchorHits(r.anchor, o)).map(initOf);
|
|
306
327
|
return {
|
|
307
|
-
id: o.id, key: c ? c.key : null, title: clip(o.name, 120), pillar: o.pillar || '', unit: u, type: goalType(u),
|
|
308
|
-
|
|
328
|
+
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),
|
|
329
|
+
direction: x.direction || (dir > 0 ? 'up' : dir < 0 ? 'down' : ''),
|
|
330
|
+
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' : '',
|
|
331
|
+
period: x.period || null, checkpoints: Array.isArray(x.checkpoints) ? x.checkpoints : [], source: x.source || '', owner: x.owner || '', guardrail: x.guardrail || '',
|
|
332
|
+
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) : '',
|
|
309
333
|
now, nowTxt: now !== null ? num(now, u) : '', target: tgt, targetTxt: tgt !== null ? num(tgt, u) : '', by: byAt ? shortDate(byAt) : '', byAt, fromAt,
|
|
310
334
|
done, timeGone, tone: STATE_TONE[o.status] || 'q', state: o.status || 'unscored', chip: (CHIP[o.status] || ['No line scored'])[0], reason: o.reason || '',
|
|
311
335
|
proj: p ? { atDue: r1(p.atDue), reaches: p.reaches, toward: p.toward } : null, pace, readings: rs.length, moves,
|
|
@@ -313,16 +337,35 @@ function goalsOf(outcomes, charts, inits, today) {
|
|
|
313
337
|
});
|
|
314
338
|
}
|
|
315
339
|
/** Shipped work (Deliver, Monitor, Evaluate, or done) against what its anchor goal promised. PURE. */
|
|
316
|
-
function outcomesOf(inits, goals, outcomes) {
|
|
340
|
+
function outcomesOf(inits, goals, outcomes, verdicts, todayIso) {
|
|
317
341
|
const ORDER = ['verdict', 'window', 'decided'];
|
|
318
342
|
const rows = (inits || []).map(initOf).filter((r) => r.idx >= 5 || r.status === 'done');
|
|
319
343
|
return rows.map((r) => {
|
|
320
344
|
const g = goals.find((x) => anchorHits(r.anchor, { id: x.id, name: (outcomes.find((o) => o.id === x.id) || {}).name })) || null;
|
|
321
|
-
const
|
|
322
|
-
|
|
345
|
+
const vd = (verdicts && verdicts[r.id]) || null, o = g ? outcomes.find((x) => x.id === g.id) : null;
|
|
346
|
+
const group = vd || r.status === 'done' || r.status === 'cancelled' ? 'decided' : r.idx === 7 ? 'verdict' : 'window';
|
|
347
|
+
return Object.assign(r, { group, verdict: vd ? { verdict: vd.verdict, learned: vd.learned, at: vd.at ? String(vd.at).slice(0, 10) : null } : null,
|
|
348
|
+
window: IG.windowOf({ shipAt: r.endAt, byAt: g ? g.byAt : null, verdict: vd, today: todayIso }),
|
|
349
|
+
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 });
|
|
323
350
|
}).sort((a, b) => ORDER.indexOf(a.group) - ORDER.indexOf(b.group));
|
|
324
351
|
}
|
|
325
352
|
|
|
353
|
+
/** 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
|
|
354
|
+
* read on this page, so a budget holds only its id and what moves it. PURE. */
|
|
355
|
+
function budgetsOf(inits, registry) {
|
|
356
|
+
const by = new Map();
|
|
357
|
+
for (const b of registry || []) by.set(b.id, []);
|
|
358
|
+
for (const r of inits || []) {
|
|
359
|
+
const m = /^health:(.+)$/.exec(String((r && r.anchor) || '').trim()); if (!m) continue;
|
|
360
|
+
if (!by.has(m[1])) by.set(m[1], []);
|
|
361
|
+
by.get(m[1]).push(initOf(r));
|
|
362
|
+
}
|
|
363
|
+
return [...by.entries()].map(([id, moves]) => {
|
|
364
|
+
const b = (registry || []).find((x) => x.id === id) || null;
|
|
365
|
+
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 };
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
326
369
|
function build(facts) {
|
|
327
370
|
const f = facts || {};
|
|
328
371
|
const outcomes = f.outcomes || [], missing = (f.missing || []).slice();
|
|
@@ -346,7 +389,7 @@ function build(facts) {
|
|
|
346
389
|
const board = f.board || {};
|
|
347
390
|
const model = {
|
|
348
391
|
header: { text: (f.pending ? 'Reading the records · ' : '') + 'Real data' + (missing.length ? ' · not read: ' + missing.join(', ') : ''), missing },
|
|
349
|
-
board: { ws: board.ws || null, id: board.id || null, name: board.name || 'Insights', switcher: (f.boards || []).map((b) => ({ ws: b.ws, id: b.id, name: b.name })) },
|
|
392
|
+
board: { ws: board.ws || null, id: board.id || null, name: board.name || 'Insights', switcher: (f.boards || []).map((b) => Object.assign({ ws: b.ws, id: b.id, name: b.name }, fin(b.goals) ? { goals: b.goals } : {})) },
|
|
350
393
|
charts, mine, mineGone, mineSaved: mineAll, noSeries, dashboards, rows: charts,
|
|
351
394
|
findings: findings.length ? findings : [{ kind: 'calm', key: null, text: charts.length ? (charts.some((c) => c.target !== null) ? 'Nothing stands out. No measure moved much, and none is far behind its line.' : 'Nothing stands out. No measure here has a target, so the series can only be described.') : '' }],
|
|
352
395
|
calm: !findings.length && charts.length > 0,
|
|
@@ -360,12 +403,18 @@ function build(facts) {
|
|
|
360
403
|
};
|
|
361
404
|
const today = isoDay(new Date(fin(f.now) ? f.now : Date.now()).toISOString()) || 0;
|
|
362
405
|
model.today = new Date(today).toISOString().slice(0, 10);
|
|
363
|
-
model.goals = goalsOf(outcomes, charts, f.initiatives || [], today);
|
|
406
|
+
model.goals = goalsOf(outcomes, charts, f.initiatives || [], today, f.goalMeta || {});
|
|
364
407
|
model.initiativesRead = Array.isArray(f.initiatives);
|
|
365
|
-
|
|
408
|
+
const ins = f.ins || { charts: {}, verdicts: {}, targets: {} }, bid = board.id || '';
|
|
409
|
+
model.outcomes = outcomesOf(f.initiatives || [], model.goals, outcomes, ins.verdicts[bid] || {}, model.today);
|
|
410
|
+
model.budgets = budgetsOf(f.initiatives || [], f.budgets || []);
|
|
411
|
+
model.budgetsRead = Array.isArray(f.budgets);
|
|
412
|
+
model.lateNow = Array.isArray(f.initiatives) ? f.initiatives.filter((r) => r && r.status === 'late').length : null;
|
|
413
|
+
model.trends = Object.assign(IG.trendsOf(Array.isArray(f.initiatives) ? f.initiatives : null, model.today), { targets: ins.targets || {}, tiles: ins.tiles || {} });
|
|
414
|
+
model.chartSet = ins.charts[bid] || {}; // { [dashboard]: { [goal]: { form, range, compare, target, forecast, note } } }
|
|
366
415
|
model.lifecycle = LIFE_LABEL.map((label, i) => ({ key: LIFE[i], label, milestone: i === 5 || i === 7 }));
|
|
367
416
|
last = model;
|
|
368
417
|
return model;
|
|
369
418
|
}
|
|
370
419
|
|
|
371
|
-
module.exports = { lifeIndex, goalType, goalsOf, outcomesOf, build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
420
|
+
module.exports = { lifeIndex, goalType, goalsOf, outcomesOf, budgetsOf, mdDate, build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* insights-records.js — the premium Insights page's own records (initiative premium-agreed-design G1, G2).
|
|
3
|
+
* THE ONE WRITER and THE ONE FOLD of <state>/insights-records.jsonl. Append-only: the file is never rewritten.
|
|
4
|
+
*
|
|
5
|
+
* FORMS · RANGES · VERDICTS · TARGET_KEYS
|
|
6
|
+
* ledgerFile(root) · readLines(file)
|
|
7
|
+
* checkChart(input) → { ok, value } | refusal one chart on one dashboard: { board, dash, goal, form, range, compare, target, forecast, note }
|
|
8
|
+
* checkVerdict(input) → { ok, value } | refusal { board, ini, verdict: Keep | Iterate | Stop, learned, goal }
|
|
9
|
+
* checkTarget(input) → { ok, value } | refusal a Delivery trends target of the page's own tiles: { key: late | scope, target: number | null }
|
|
10
|
+
* checkTile(input) → { ok, value } | refusal how any Delivery trends target is read (premium-uncovered-features, IsTarget): { key: one of
|
|
11
|
+
* TILE_KEYS, dir: 'at least' | 'at most' | 'none', from: 'YYYY-MM-DD' | '', chip: bool }. The number stays where it was kept.
|
|
12
|
+
* fold(lines) → { charts: { [board]: { [dash]: { [goal]: chart } } }, verdicts: { [board]: { [ini]: verdict } }, targets: { [key]: number },
|
|
13
|
+
* tiles: { [key]: { dir, from, chip, at } } } PURE
|
|
14
|
+
* read(root) → fold(readLines(ledgerFile(root)))
|
|
15
|
+
* append(root, ev, value, actor, { now }) → { ok, line } THE SINGLE WRITER. `v`, `ev`, `actor` and `at` are set here.
|
|
16
|
+
*
|
|
17
|
+
* THE LINES. { v: 1, ev: 'chart' | 'verdict' | 'target' | 'tile', ...value, actor, at }. The last line of each key wins: a chart per board, dashboard and goal;
|
|
18
|
+
* a verdict per board and initiative; a target per key; a tile setting per key. A torn line, or one without its key fields, is skipped.
|
|
19
|
+
* A verdict is recorded here only: it does not move the initiative on the Board and does not change its record. */
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
|
|
23
|
+
const LEDGER = 'insights-records.jsonl';
|
|
24
|
+
const FORMS = Object.freeze(['Line', 'Bars', 'Number', 'Meter']);
|
|
25
|
+
const RANGES = Object.freeze(['8w', 'Quarter', '26w']);
|
|
26
|
+
const COMPARES = Object.freeze(['', 'lq']);
|
|
27
|
+
const VERDICTS = Object.freeze(['Keep', 'Iterate', 'Stop']);
|
|
28
|
+
const TARGET_KEYS = Object.freeze(['late', 'scope']);
|
|
29
|
+
const TILE_KEYS = Object.freeze(['blocked', 'late', 'idle', 'scope', 'merges', 'corrections']);
|
|
30
|
+
const TILE_DIRS = Object.freeze(['at least', 'at most', 'none']);
|
|
31
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/;
|
|
32
|
+
const NOTE_MAX = 160, LEARN_MAX = 600;
|
|
33
|
+
|
|
34
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
35
|
+
const refuse = (status, error) => ({ ok: false, status, error });
|
|
36
|
+
const tidy = (v, n) => (typeof v === 'string' ? v.trim().replace(/\s+/g, ' ').slice(0, n) : '');
|
|
37
|
+
const id = (v) => (typeof v === 'string' && ID_RE.test(v) ? v : null);
|
|
38
|
+
|
|
39
|
+
function ledgerFile(root) {
|
|
40
|
+
const abs = path.resolve(String(root));
|
|
41
|
+
return path.join(abs, require('./report-draft.js').stateRel(abs), LEDGER);
|
|
42
|
+
}
|
|
43
|
+
function readLines(file) {
|
|
44
|
+
let text = '';
|
|
45
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const raw of text.split('\n')) {
|
|
48
|
+
if (!raw.trim()) continue;
|
|
49
|
+
try { const l = JSON.parse(raw); if (isObj(l) && typeof l.ev === 'string') out.push(l); } catch { /* a torn line is skipped */ }
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function checkChart(input) {
|
|
55
|
+
const i = isObj(input) ? input : {};
|
|
56
|
+
const board = id(i.board), dash = id(i.dash), goal = id(i.goal);
|
|
57
|
+
if (!board || !dash || !goal) return refuse(400, 'Name the board, the dashboard and the goal of the chart.');
|
|
58
|
+
if (dash === 'all' || dash.startsWith('p:')) return refuse(400, 'A chart is kept on a saved dashboard. Make one with New dashboard first.');
|
|
59
|
+
const form = FORMS.includes(i.form) ? i.form : null, range = RANGES.includes(i.range) ? i.range : null;
|
|
60
|
+
if (!form) return refuse(400, 'Pick a form: ' + FORMS.join(', ') + '.');
|
|
61
|
+
if (!range) return refuse(400, 'Pick a range: 8w, Quarter or 26w.');
|
|
62
|
+
const compare = COMPARES.includes(i.compare || '') ? i.compare || '' : null;
|
|
63
|
+
if (compare === null) return refuse(400, 'Compare with last quarter, or nothing.');
|
|
64
|
+
return { ok: true, value: { board, dash, goal, form, range, compare, target: i.target !== false, forecast: i.forecast === true, note: tidy(i.note, NOTE_MAX) } };
|
|
65
|
+
}
|
|
66
|
+
function checkVerdict(input) {
|
|
67
|
+
const i = isObj(input) ? input : {};
|
|
68
|
+
const board = id(i.board), ini = id(i.ini);
|
|
69
|
+
if (!board || !ini) return refuse(400, 'Name the board and the initiative.');
|
|
70
|
+
if (!VERDICTS.includes(i.verdict)) return refuse(400, 'Pick Keep, Iterate or Stop.');
|
|
71
|
+
const learned = tidy(i.learned, LEARN_MAX);
|
|
72
|
+
if (!learned) return refuse(400, 'Say what you learned, in a line.');
|
|
73
|
+
return { ok: true, value: { board, ini, verdict: i.verdict, learned, goal: id(i.goal) } };
|
|
74
|
+
}
|
|
75
|
+
function checkTarget(input) {
|
|
76
|
+
const i = isObj(input) ? input : {};
|
|
77
|
+
if (!TARGET_KEYS.includes(i.key)) return refuse(400, 'Name the tile: late or scope.');
|
|
78
|
+
const t = i.target === '' || i.target == null ? null : Number(i.target);
|
|
79
|
+
if (t !== null && !(Number.isFinite(t) && t >= 0)) return refuse(400, 'The target is a number of initiatives, 0 or more.');
|
|
80
|
+
return { ok: true, value: { key: i.key, target: t } };
|
|
81
|
+
}
|
|
82
|
+
function checkTile(input) {
|
|
83
|
+
const i = isObj(input) ? input : {};
|
|
84
|
+
if (!TILE_KEYS.includes(i.key)) return refuse(400, 'Name the tile: ' + TILE_KEYS.join(', ') + '.');
|
|
85
|
+
if (!TILE_DIRS.includes(i.dir)) return refuse(400, 'Pick At least, At most or No target.');
|
|
86
|
+
const from = typeof i.from === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(i.from) ? i.from : '';
|
|
87
|
+
if (i.from && !from) return refuse(400, 'The start is a date: YYYY-MM-DD.');
|
|
88
|
+
return { ok: true, value: { key: i.key, dir: i.dir, from, chip: i.chip === true } };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function fold(lines) {
|
|
92
|
+
const charts = {}, verdicts = {}, targets = {}, tiles = {};
|
|
93
|
+
for (const l of lines || []) {
|
|
94
|
+
if (l.ev === 'chart') { const c = checkChart(l); if (!c.ok) continue; const v = c.value; ((charts[v.board] = charts[v.board] || {})[v.dash] = charts[v.board][v.dash] || {})[v.goal] = Object.assign({}, v, { at: l.at || null }); }
|
|
95
|
+
else if (l.ev === 'verdict') { const c = checkVerdict(l); if (!c.ok) continue; const v = c.value; (verdicts[v.board] = verdicts[v.board] || {})[v.ini] = Object.assign({}, v, { at: l.at || null, by: l.actor && l.actor.by ? l.actor.by : null }); }
|
|
96
|
+
else if (l.ev === 'target') { const c = checkTarget(l); if (!c.ok) continue; if (c.value.target === null) delete targets[c.value.key]; else targets[c.value.key] = c.value.target; }
|
|
97
|
+
else if (l.ev === 'tile') { const c = checkTile(l); if (!c.ok) continue; tiles[c.value.key] = { dir: c.value.dir, from: c.value.from, chip: c.value.chip, at: l.at ? String(l.at).slice(0, 10) : null }; }
|
|
98
|
+
}
|
|
99
|
+
return { charts, verdicts, targets, tiles };
|
|
100
|
+
}
|
|
101
|
+
const read = (root) => fold(readLines(ledgerFile(root)));
|
|
102
|
+
|
|
103
|
+
const CHECKS = { chart: checkChart, verdict: checkVerdict, target: checkTarget, tile: checkTile };
|
|
104
|
+
function append(root, ev, input, actor, { now } = {}) {
|
|
105
|
+
if (!CHECKS[ev]) return refuse(400, 'unknown record: ' + ev);
|
|
106
|
+
const c = CHECKS[ev](input);
|
|
107
|
+
if (!c.ok) return c;
|
|
108
|
+
const file = ledgerFile(root), t = now == null ? Date.now() : now;
|
|
109
|
+
const line = Object.assign({ v: 1, ev }, c.value, { actor: actor || null, at: new Date(t).toISOString() });
|
|
110
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
111
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
112
|
+
return { ok: true, line };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = { LEDGER, FORMS, RANGES, VERDICTS, TARGET_KEYS, TILE_KEYS, TILE_DIRS, ledgerFile, readLines, checkChart, checkVerdict, checkTarget, checkTile, fold, read, append };
|
|
@@ -435,7 +435,7 @@ function view(root, initiative, { snapshot } = {}) {
|
|
|
435
435
|
const it = byItem.get(t.id);
|
|
436
436
|
const missing = missingOf(t);
|
|
437
437
|
const prdChanged = !!(it && t.source && it.hash !== t.source);
|
|
438
|
-
const removed = !!(st.ok && !it);
|
|
438
|
+
const removed = !!(st.ok && !it && t.source); // a ticket with no PRD item it was drafted from (a meeting's next step, lib/viewer-meeting.js) is not 'removed'
|
|
439
439
|
const edited = !!(t.jira && t.pushed && t.pushed !== h);
|
|
440
440
|
const waiting = !!(t.approved === h && (!t.jira || t.pushed !== h));
|
|
441
441
|
const r = t.jira ? reading.get(t.jira) || null : null;
|