create-pmos 0.257.0 → 0.259.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 +1 -1
- 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-adddoc-test.js +171 -0
- package/workspace/briefing-premium-initiative-test.js +1 -1
- package/workspace/briefing-premium-insights-test.js +228 -0
- package/workspace/fixtures/insights-premium-facts.js +30 -0
- package/workspace/guide/briefing-premium.md +14 -2
- package/workspace/lib/board-premium.js +8 -5
- package/workspace/lib/briefing-premium-agent.js +2 -2
- package/workspace/lib/custom-docs.js +107 -0
- package/workspace/lib/initiative-premium.js +9 -4
- package/workspace/lib/insights-premium.js +133 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-board-premium.js +5 -1
- package/workspace/lib/routes-briefing-premium.js +2 -1
- package/workspace/lib/routes-custom-docs.js +62 -0
- package/workspace/lib/routes-initiative-premium.js +4 -1
- package/workspace/lib/routes-insights-premium.js +53 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/premium-board.js +7 -4
- package/workspace/public/pm/premium-initiative.js +8 -7
- package/workspace/public/pm/premium-insights.css +143 -0
- package/workspace/public/pm/premium-insights.js +143 -0
- package/workspace/public/pm/premium-shell.js +31 -2
- package/workspace/public/pm/premium.css +3 -1
- package/workspace/public/premium-board.html +2 -2
- package/workspace/public/premium-initiative.html +1 -1
- package/workspace/public/premium-insights.html +61 -0
- package/workspace/server.js +2 -2
- package/workspace/test-files.json +4 -0
- package/workspace/test-lists/briefing-premium.json +4 -0
|
@@ -16,7 +16,7 @@ const crypto = require('crypto');
|
|
|
16
16
|
const headless = require('./headless.js');
|
|
17
17
|
|
|
18
18
|
const THREADS = 'briefing-premium-threads.jsonl';
|
|
19
|
-
const KEY_RE = /^(decision|blocked|waited|src|ev|work|board|init|doc):[A-Za-z0-9][A-Za-z0-9._:-]{0,100}$/;
|
|
19
|
+
const KEY_RE = /^(decision|blocked|waited|src|ev|work|board|init|doc|ins):[A-Za-z0-9][A-Za-z0-9._:-]{0,100}$/;
|
|
20
20
|
const MAX_Q = 2000, MAX_A = 6000, MAX_QUESTIONS = 40, PROMPT_TURNS = 8;
|
|
21
21
|
const fail = (status, error) => ({ status, body: { ok: false, error } });
|
|
22
22
|
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
@@ -49,7 +49,7 @@ function threadOf(runtimeDir, key, now = Date.now()) {
|
|
|
49
49
|
/** The row as the server's own model has it, plus the files an answer should start from. null when the key names no row on the page. */
|
|
50
50
|
function rowFor(model, key) {
|
|
51
51
|
if (!model || !KEY_RE.test(String(key || ''))) return null;
|
|
52
|
-
if (/^(work|board|init|doc):/.test(key)) { // a My work item, a Board initiative, an initiative page or one of its documents: the item's own record is the context
|
|
52
|
+
if (/^(work|board|init|doc|ins):/.test(key)) { // a My work item, a Board initiative, an Insights measure, an initiative page or one of its documents: the item's own record is the context
|
|
53
53
|
const w = (model.rows || []).find((r) => r.key === key); if (!w) return null;
|
|
54
54
|
const d = w.dialog || {};
|
|
55
55
|
return { title: clip(w.title, 160), subject: clip(w.sub, 240), say: clip(d.say, 600), facts: (d.facts || []).slice(0, 12).map(([a, b]) => clip(a, 40) + ': ' + clip(b, 240)), files: (d.files || []).filter((f) => SAFE_PATH.test(f) && !f.includes('..')).slice(0, 4) };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* custom-docs.js — the documents the PM adds to a board or an initiative, beyond the core set (initiative briefing-premium-adddoc).
|
|
3
|
+
* THE ONE WRITER and THE ONE FOLD of <state>/custom-docs.jsonl.
|
|
4
|
+
*
|
|
5
|
+
* KINDS · PHASES · WRITERS · TITLE_MAX · URL_MAX
|
|
6
|
+
* ledgerFile(root) · readLines(file)
|
|
7
|
+
* check(input) → { ok: true, value } | { ok: false, status, error } PURE
|
|
8
|
+
* list(root, scope) → [{ id, scope, title, writer, phase, link, at }] in the order they were added
|
|
9
|
+
* add(root, input, actor, { now }) → { ok: true, doc } | { ok: false, status, error }
|
|
10
|
+
*
|
|
11
|
+
* THE LEDGER. Lines { v: 1, ev: 'add', id, scope, title, writer, phase, link, actor, at }. `scope` is board:<id> or initiative:<id>. `writer` is
|
|
12
|
+
* drafts | you. `phase` is a phase name for an initiative and null for a board. `link` is { kind, url } or null. `actor` is the actor of the call
|
|
13
|
+
* path (lib/actor.js), never an argument. Nothing here reads or syncs a linked page: the record holds the address and the date it was added.
|
|
14
|
+
* The file is never rewritten. A line that does not parse, or has no title, is skipped.
|
|
15
|
+
*/
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const LEDGER = 'custom-docs.jsonl';
|
|
20
|
+
const KINDS = Object.freeze(['Confluence', 'Google Docs', 'Google Slides']);
|
|
21
|
+
const PHASES = Object.freeze(['Discover', 'Plan', 'Build', 'Evaluate']);
|
|
22
|
+
const WRITERS = Object.freeze(['drafts', 'you']);
|
|
23
|
+
const TITLE_MAX = 80;
|
|
24
|
+
const URL_MAX = 300;
|
|
25
|
+
const SCOPE_RE = /^(board|initiative):[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/;
|
|
26
|
+
|
|
27
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
28
|
+
const refuse = (status, error) => ({ ok: false, status, error });
|
|
29
|
+
const norm = (t) => String(t).trim().replace(/\s+/g, ' ').toLowerCase();
|
|
30
|
+
|
|
31
|
+
function ledgerFile(root) {
|
|
32
|
+
const abs = path.resolve(String(root));
|
|
33
|
+
return path.join(abs, require('./report-draft.js').stateRel(abs), LEDGER);
|
|
34
|
+
}
|
|
35
|
+
function readLines(file) {
|
|
36
|
+
let text = '';
|
|
37
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const raw of text.split('\n')) {
|
|
40
|
+
if (!raw.trim()) continue;
|
|
41
|
+
try { const l = JSON.parse(raw); if (isObj(l) && l.ev === 'add' && typeof l.scope === 'string' && typeof l.title === 'string' && l.title && typeof l.id === 'string') out.push(l); } catch { /* a torn line is skipped */ }
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Check the fields of an add. The scope's existence is the route's check; this one is about the shape. */
|
|
47
|
+
function check(input) {
|
|
48
|
+
const i = isObj(input) ? input : {};
|
|
49
|
+
const scope = typeof i.scope === 'string' ? i.scope : '';
|
|
50
|
+
if (!SCOPE_RE.test(scope)) return refuse(400, 'scope must be board:<id> or initiative:<id>');
|
|
51
|
+
const level = scope.slice(0, scope.indexOf(':'));
|
|
52
|
+
const title = typeof i.title === 'string' ? i.title.trim().replace(/\s+/g, ' ') : '';
|
|
53
|
+
if (!title) return refuse(400, 'Give the document a title.');
|
|
54
|
+
if (title.length > TITLE_MAX) return refuse(400, `The title can be at most ${TITLE_MAX} characters.`);
|
|
55
|
+
const writer = i.writer == null || i.writer === '' ? 'drafts' : i.writer;
|
|
56
|
+
if (!WRITERS.includes(writer)) return refuse(400, 'Say who writes it: PMOS drafts it, or you write it.');
|
|
57
|
+
let phase = null;
|
|
58
|
+
if (level === 'initiative') {
|
|
59
|
+
phase = i.phase == null || i.phase === '' ? null : i.phase;
|
|
60
|
+
if (phase != null && !PHASES.includes(phase)) return refuse(400, 'The phase must be Discover, Plan, Build or Evaluate.');
|
|
61
|
+
}
|
|
62
|
+
let link = null;
|
|
63
|
+
const kind = i.kind == null || i.kind === '' ? null : i.kind;
|
|
64
|
+
if (kind != null) {
|
|
65
|
+
if (!KINDS.includes(kind)) return refuse(400, `Where it lives must be In PMOS, ${KINDS.join(', ')}.`);
|
|
66
|
+
const url = typeof i.url === 'string' ? i.url.trim() : '';
|
|
67
|
+
if (!url) return refuse(400, `Paste the address of the ${kind} page, or choose In PMOS.`);
|
|
68
|
+
if (url.length > URL_MAX) return refuse(400, `The address can be at most ${URL_MAX} characters.`);
|
|
69
|
+
let u = null; try { u = new URL(url); } catch { u = null; }
|
|
70
|
+
if (!u || (u.protocol !== 'https:' && u.protocol !== 'http:') || !u.hostname || u.username || u.password) return refuse(400, 'The address must be a web address that starts with http:// or https://.');
|
|
71
|
+
link = { kind, url };
|
|
72
|
+
}
|
|
73
|
+
return { ok: true, value: { scope, title, writer, phase, link } };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The documents of one scope, oldest first. */
|
|
77
|
+
function list(root, scope) {
|
|
78
|
+
return readLines(ledgerFile(root)).filter((l) => l.scope === scope).map((l) => ({
|
|
79
|
+
id: l.id, scope: l.scope, title: l.title, writer: WRITERS.includes(l.writer) ? l.writer : null, phase: PHASES.includes(l.phase) ? l.phase : null,
|
|
80
|
+
link: isObj(l.link) && KINDS.includes(l.link.kind) && typeof l.link.url === 'string' ? { kind: l.link.kind, url: l.link.url } : null, at: l.at || null,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** THE SINGLE WRITER of custom-docs.jsonl. `v`, `id` and `at` are set here. */
|
|
85
|
+
function add(root, input, actor, { now } = {}) {
|
|
86
|
+
const c = check(input);
|
|
87
|
+
if (!c.ok) return c;
|
|
88
|
+
const v = c.value;
|
|
89
|
+
const file = ledgerFile(root);
|
|
90
|
+
const have = readLines(file).filter((l) => l.scope === v.scope);
|
|
91
|
+
if (have.some((l) => norm(l.title) === norm(v.title))) return refuse(409, `“${v.title}” is already on this ${v.scope.startsWith('board:') ? 'board' : 'initiative'}.`);
|
|
92
|
+
const t = now == null ? Date.now() : now;
|
|
93
|
+
const line = { v: 1, ev: 'add', id: 'cd-' + t.toString(36) + '-' + (have.length + 1), scope: v.scope, title: v.title, writer: v.writer, phase: v.phase, link: v.link, actor: actor || null, at: new Date(t).toISOString() };
|
|
94
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
95
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
96
|
+
return { ok: true, doc: { id: line.id, scope: line.scope, title: line.title, writer: line.writer, phase: line.phase, link: line.link, at: line.at } };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** One added document as a row of the Core documents card. PURE. `st` is `missing` (no link) or `linked`; never `ok`: PMOS cannot read a linked page.
|
|
100
|
+
* `added` is the day it was added (YYYY-MM-DD) and the only date the row holds. */
|
|
101
|
+
function rowOf(d) {
|
|
102
|
+
const linked = !!d.link;
|
|
103
|
+
return { key: 'custom:' + d.id, title: d.title, what: linked ? 'Lives in ' + d.link.kind + ': ' + d.link.url : 'Added by you.', st: linked ? 'linked' : 'missing', state: linked ? 'Linked' : 'Not started',
|
|
104
|
+
by: d.writer === 'you' ? 'You write it' : d.writer === 'drafts' ? 'PMOS drafts it' : '', cat: d.phase || null, link: d.link, added: d.at ? String(d.at).slice(0, 10) : '', custom: true, act: null };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = { rowOf, KINDS, PHASES, WRITERS, TITLE_MAX, URL_MAX, ledgerFile, readLines, check, list, add };
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
const pad = (n) => String(n).padStart(2, '0');
|
|
20
20
|
const hhmm = (ms) => { const d = new Date(ms); return pad(d.getHours()) + ':' + pad(d.getMinutes()); };
|
|
21
|
+
const Custom = require('./custom-docs.js');
|
|
21
22
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
22
23
|
const isoDay = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
23
24
|
const shortDate = (v) => { const d = isoDay(v); return d ? d.getDate() + ' ' + MON[d.getMonth()] : ''; };
|
|
@@ -105,11 +106,15 @@ function build(f) {
|
|
|
105
106
|
when: d.when ? shortDate(d.when) : '', cat: d.cat === 'Do' ? 'Build' : d.cat === 'Learn' ? 'Evaluate' : d.cat || 'Board', path: d.open && d.open.path ? d.open.path : null, running: !!d.running, tech: TECH.has(d.key),
|
|
106
107
|
act: d.act && d.act.do === 'draft' ? { kind: 'draft', label: d.running ? 'Drafting' : d.act.label || 'Draft it' } : null,
|
|
107
108
|
})) : [];
|
|
108
|
-
const
|
|
109
|
+
const custom = (f.custom || []).map((d) => Object.assign(Custom.rowOf(d), { added: shortDate(d.at), cat: d.phase || 'Board' }));
|
|
110
|
+
const rows = all.concat(custom);
|
|
111
|
+
const core = rows.filter((d) => !d.tech);
|
|
109
112
|
const cnt = { all: core.length, none: core.filter((d) => d.st === 'missing').length, draft: core.filter((d) => d.st === 'draft').length, ok: core.filter((d) => d.st === 'ok' || d.st === 'live').length };
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
const nLinked = core.filter((d) => d.st === 'linked').length;
|
|
114
|
+
if (nLinked) cnt.linked = nLinked; // a key only when an added document is linked
|
|
115
|
+
const docs = dd || custom.length ? { rows, counts: cnt, techCount: rows.length - core.length,
|
|
116
|
+
cap: core.length ? [cnt.draft ? cnt.draft + ' ' + plural(cnt.draft, 'draft', 'drafts') + ' to review' : '', cnt.none ? cnt.none + ' not started' : '', cnt.ok ? cnt.ok + ' up to date' : '', nLinked ? nLinked + ' linked' : ''].filter(Boolean).join(' · ') : '',
|
|
117
|
+
scope: (dd && dd.scope) || 'initiative:' + id, missing: !dd } : { rows: [], counts: { all: 0, none: 0, draft: 0, ok: 0 }, techCount: 0, cap: '', missing: true };
|
|
113
118
|
if (!dd && !missing.includes('core documents')) missing.push('core documents');
|
|
114
119
|
|
|
115
120
|
// ── PMOS can help: only things a press can really do. A draft of a core document the initiative has not started (the existing read-only draft run), and a question for the read-only agent ──
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* lib/insights-premium.js — the premium Insights page's model, built from the KR metric records and the report files the console's Reports tab reads
|
|
3
|
+
* (initiative briefing-premium-insights).
|
|
4
|
+
*
|
|
5
|
+
* build(facts) → model PURE. facts = { now, board, boards, outcomes, reports, reportsOk, missing[] }
|
|
6
|
+
* peekModel() → the last model built, for the agent to find a chart in (null before the first)
|
|
7
|
+
*
|
|
8
|
+
* facts come from the routes of lib/routes-c3-strategy.js and lib/routes-reports.js:
|
|
9
|
+
* board { ws, id, name } the board the page shows (KR metric records belong to its workspace, PRD D2)
|
|
10
|
+
* outcomes GET /api/c3-strategy → .outcomes [{ id, name, pillar, unit, start (the baseline), target, by, now, expected, shortfall, status, pivot, reason, readings: [{ at, v }] }]
|
|
11
|
+
* reports GET /api/report → .reports [{ cadence, slot, path, status, issued: { at, by } | null, edited }]
|
|
12
|
+
*
|
|
13
|
+
* THE RULE THE FILE FOLLOWS (as the other premium models): a number, chip, line or date is made only from a field of a record. A measure with fewer than two
|
|
14
|
+
* readings gets no chart and says why. The time between two readings is drawn as the time it is, so a gap in a series shows as a gap and never as a zero. No
|
|
15
|
+
* forecast is drawn and no cause is given. 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). */
|
|
16
|
+
|
|
17
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
18
|
+
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; };
|
|
19
|
+
const shortDate = (v) => { const t = isoDay(v); if (t === null) return ''; const d = new Date(t); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()]; };
|
|
20
|
+
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
21
|
+
const fin = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
22
|
+
const r2 = (v) => Math.round(v * 100) / 100;
|
|
23
|
+
const num = (v, unit) => { const u = String(unit || '').trim(), s = String(r2(v)); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
|
|
24
|
+
const CHIP = { ok: ['On its line', 'ok'], drift: ['Behind its line', 'warn'], off: ['Well behind its line', 'bad'] };
|
|
25
|
+
const MAX_FINDINGS = 3;
|
|
26
|
+
const KR_FILE = 'planning/records/kr-metrics.jsonl';
|
|
27
|
+
|
|
28
|
+
let last = null;
|
|
29
|
+
const peekModel = () => last;
|
|
30
|
+
|
|
31
|
+
/** One KR metric outcome with two or more readings → a chart. null when it has no series. */
|
|
32
|
+
function chartOf(o) {
|
|
33
|
+
const rs = (o.readings || []).filter((x) => x && fin(x.v) && isoDay(x.at) !== null);
|
|
34
|
+
if (rs.length < 2) return null;
|
|
35
|
+
const u = o.unit || '', tgt = fin(o.target) ? o.target : null, base = fin(o.start) ? o.start : null;
|
|
36
|
+
const t0 = isoDay(rs[0].at), t1 = isoDay(rs[rs.length - 1].at), span = t1 - t0 || 1;
|
|
37
|
+
const ys = rs.map((x) => x.v).concat(tgt !== null ? [tgt] : []);
|
|
38
|
+
const lo = Math.min(...ys), hi = Math.max(...ys), range = hi - lo || 1;
|
|
39
|
+
const pts = rs.map((x) => ({ at: x.at, v: x.v, fx: (isoDay(x.at) - t0) / span, fy: (x.v - lo) / range, txt: num(x.v, u), d: shortDate(x.at) }));
|
|
40
|
+
const now = rs[rs.length - 1].v, prev = rs[rs.length - 2].v;
|
|
41
|
+
const dir = tgt !== null && base !== null && tgt !== base ? Math.sign(tgt - base) : tgt !== null ? Math.sign(tgt - now) : 0;
|
|
42
|
+
const step = now - prev, good = dir ? step * dir > 0 : null;
|
|
43
|
+
const chip = CHIP[o.status] || ['No line scored', 'mut'];
|
|
44
|
+
const rows = [
|
|
45
|
+
['Latest reading', num(now, u) + ' on ' + shortDate(rs[rs.length - 1].at)],
|
|
46
|
+
tgt !== null ? ['Target', num(tgt, u) + (o.by ? ' by ' + shortDate(o.by) : '')] : null,
|
|
47
|
+
base !== null ? ['Baseline', num(base, u)] : null,
|
|
48
|
+
fin(o.expected) ? ['On its line today', num(o.expected, u)] : null,
|
|
49
|
+
['Line status', chip[0] + (o.status === 'unscored' && o.reason ? ' — ' + o.reason : '')],
|
|
50
|
+
['Readings', rs.length + ' from ' + shortDate(rs[0].at) + ' to ' + shortDate(rs[rs.length - 1].at)],
|
|
51
|
+
o.pillar ? ['Pillar', o.pillar] : null,
|
|
52
|
+
].filter(Boolean);
|
|
53
|
+
const say = o.name + ' stands at ' + num(now, u) + (tgt !== null ? ' against a target of ' + num(tgt, u) : '') + '. ' + (CHIP[o.status] ? 'Against its own line the record says: ' + chip[0].toLowerCase() + '.' : 'The record cannot score it against a line.');
|
|
54
|
+
const rid = clip(o.id, 100);
|
|
55
|
+
return {
|
|
56
|
+
key: 'ins:' + rid, id: o.id, title: clip(o.name, 120), sub: [o.pillar, rs.length + ' readings'].filter(Boolean).join(' · '), pillar: o.pillar || '',
|
|
57
|
+
unit: u, v: num(now, u), at: shortDate(rs[rs.length - 1].at), target: tgt, targetTxt: tgt !== null ? 'target ' + num(tgt, u) : '', by: o.by ? shortDate(o.by) : '',
|
|
58
|
+
ty: tgt !== null ? (tgt - lo) / range : null, state: o.status || 'unscored', chip: chip[0], chipKind: chip[1], off: o.status === 'drift' || o.status === 'off', pivot: !!o.pivot,
|
|
59
|
+
step: r2(step), good, dir, first: rs[0].at, lastAt: rs[rs.length - 1].at, pts, range: [lo, hi],
|
|
60
|
+
ticks: [shortDate(rs[0].at), shortDate(rs[rs.length - 1].at)],
|
|
61
|
+
dialog: {
|
|
62
|
+
eye: 'Measure', logTitle: 'Read from the KR metric record', say, head: 'Where it stands', facts: rows, files: [KR_FILE],
|
|
63
|
+
log: ['Read the KR metric record ' + o.id, 'Took ' + rs.length + ' readings from the record', 'Took the line status from the record: ' + chip[0].toLowerCase()],
|
|
64
|
+
hold: 'Nothing here changes a record. A reading is added where the KR metric is kept, not on this page.',
|
|
65
|
+
pane: { label: 'KR metric record', file: KR_FILE, rows: rs.map((x) => [shortDate(x.at), num(x.v, u)]).reverse() },
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Up to three plain sentences about what stands out, from the series alone. No forecast and no cause. */
|
|
71
|
+
function findingsOf(charts) {
|
|
72
|
+
const out = [];
|
|
73
|
+
for (const c of charts) {
|
|
74
|
+
const u = c.unit, f = [];
|
|
75
|
+
const move = (a, b) => 'from ' + num(a, u) + ' to ' + num(b, u);
|
|
76
|
+
const prev = c.pts[c.pts.length - 2].v, now = c.pts[c.pts.length - 1].v;
|
|
77
|
+
const spread = (c.range[1] - c.range[0]) || 1;
|
|
78
|
+
if (c.pivot) f.push({ kind: 'stuck', score: 100, text: c.title + ' has been behind its line at three readings in a row, and the gap is not closing.' });
|
|
79
|
+
else if (c.off && c.good === false && c.step !== 0) f.push({ kind: 'worse', score: 90, text: c.title + ' is behind its line, and its last reading moved away from the target (' + move(prev, now) + ').' });
|
|
80
|
+
else if (c.off && c.good) f.push({ kind: 'closing', score: 60, text: c.title + ' is behind its line, and its last reading moved toward the target (' + move(prev, now) + ').' });
|
|
81
|
+
else if (c.off) f.push({ kind: 'off', score: 55, text: c.title + ' is behind its line at ' + num(now, u) + '.' });
|
|
82
|
+
else if (c.state === 'ok' && c.good === false && c.step !== 0) f.push({ kind: 'slip', score: 50, text: c.title + ' is on its line, but its last reading moved away from the target (' + move(prev, now) + ').' });
|
|
83
|
+
if (c.target !== null && c.dir && (c.dir > 0 ? now >= c.target : now <= c.target)) f.push({ kind: 'reached', score: 58, text: c.title + ' has reached its target of ' + num(c.target, u) + '.' });
|
|
84
|
+
if (Math.abs(now - prev) / spread >= 0.4 && !(f[0] && f[0].score >= 90)) f.push({ kind: 'move', score: 70, text: c.title + ' moved ' + move(prev, now) + ' in one reading.' });
|
|
85
|
+
f.sort((a, b) => b.score - a.score);
|
|
86
|
+
if (f[0]) out.push(Object.assign(f[0], { key: c.key, chart: c.key }));
|
|
87
|
+
}
|
|
88
|
+
out.sort((a, b) => b.score - a.score);
|
|
89
|
+
return out.slice(0, MAX_FINDINGS);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function reportRows(reports) {
|
|
93
|
+
return (reports || []).slice().sort((a, b) => String(b.slot).localeCompare(String(a.slot)) || String(a.cadence).localeCompare(String(b.cadence))).slice(0, 12).map((r) => {
|
|
94
|
+
const issued = !!r.issued;
|
|
95
|
+
return {
|
|
96
|
+
key: 'rep:' + r.cadence + ':' + r.slot, cadence: r.cadence, slot: r.slot, date: shortDate(r.slot), state: issued ? 'issued' : r.status === 'draft' ? 'draft' : 'file',
|
|
97
|
+
stateLabel: issued ? 'Issued' + (r.issued.at ? ' ' + shortDate(r.issued.at) : '') : r.status === 'draft' ? 'Draft' : 'Report file', path: r.path || '',
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function build(facts) {
|
|
103
|
+
const f = facts || {};
|
|
104
|
+
const outcomes = f.outcomes || [], missing = (f.missing || []).slice();
|
|
105
|
+
const charts = outcomes.map(chartOf).filter(Boolean);
|
|
106
|
+
const noSeries = outcomes.filter((o) => !chartOf(o)).map((o) => ({
|
|
107
|
+
key: 'nos:' + o.id, title: clip(o.name, 120), pillar: o.pillar || '',
|
|
108
|
+
why: (o.readings || []).length === 1 ? 'Only one reading is recorded.' : (o.readings || []).length === 0 ? (o.reason && /reading/i.test(o.reason) ? o.reason : 'No reading is recorded yet.') : 'Its readings do not form a series.',
|
|
109
|
+
}));
|
|
110
|
+
const pillars = [...new Set(charts.map((c) => c.pillar).filter(Boolean))];
|
|
111
|
+
const offOf = (L) => L.filter((c) => c.off).length;
|
|
112
|
+
const dash = (id, name, L) => ({ id, name, keys: L.map((c) => c.key), total: L.length, off: offOf(L), chip: !L.length ? '' : offOf(L) ? offOf(L) + ' off its line' : 'On their lines' });
|
|
113
|
+
const dashboards = [dash('all', 'All measures', charts)].concat(pillars.length > 1 ? pillars.map((p) => dash('p:' + p, p, charts.filter((c) => c.pillar === p))) : []);
|
|
114
|
+
const findings = findingsOf(charts);
|
|
115
|
+
const rep = reportRows(f.reports);
|
|
116
|
+
const off = offOf(charts);
|
|
117
|
+
const board = f.board || {};
|
|
118
|
+
const model = {
|
|
119
|
+
header: { text: (f.pending ? 'Reading the records · ' : '') + 'Real data' + (missing.length ? ' · not read: ' + missing.join(', ') : '') },
|
|
120
|
+
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 })) },
|
|
121
|
+
charts, noSeries, dashboards, rows: charts,
|
|
122
|
+
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.') : '' }],
|
|
123
|
+
calm: !findings.length && charts.length > 0,
|
|
124
|
+
reports: { rows: rep, ok: f.reportsOk !== false, counts: { draft: rep.filter((r) => r.state === 'draft').length, issued: rep.filter((r) => r.state === 'issued').length }, missing: f.reportsOk === false },
|
|
125
|
+
empty: !outcomes.length ? 'No KR metric is recorded for this workspace, so there is nothing to chart. Add one where the KR metrics are kept.' : !charts.length ? 'No KR metric holds two readings yet, so nothing is drawn.' : '',
|
|
126
|
+
dock: { needs: off, label: off === 1 ? 'measure off its line' : 'measures off their line', next: findings[0] && findings[0].chart ? (charts.find((c) => c.key === findings[0].chart) || {}).title || null : null },
|
|
127
|
+
counts: { charts: charts.length, noSeries: noSeries.length, off, total: outcomes.length },
|
|
128
|
+
};
|
|
129
|
+
last = model;
|
|
130
|
+
return model;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = { build, peekModel, chartOf, findingsOf, shortDate, num };
|
|
@@ -52,6 +52,7 @@ const MODULES = Object.freeze([
|
|
|
52
52
|
'routes-briefing-premium', // briefing-premium: the premium Briefing's page model from repository state (read-only)
|
|
53
53
|
'routes-my-work-premium', // briefing-premium-work: the premium My work page's model from the Work page's own list (read-only)
|
|
54
54
|
'routes-board-premium', // briefing-premium-board: the premium Board page's model from the Initiatives page's own routes (read-only)
|
|
55
|
+
'routes-insights-premium', // briefing-premium-insights: the premium Insights page's model from the KR metric records and report files (read-only)
|
|
55
56
|
'routes-initiative-premium', // briefing-premium-initiative: the premium initiative page's model from the Initiatives sheet's own routes (read-only)
|
|
56
57
|
'routes-brief-page', // console3 Briefing as the brief: Today agenda, Needs you and Mentions (read-only; writes go through routes-pm-items)
|
|
57
58
|
'routes-mentions', // console3 Briefing Mentions: the PM's read marks (page press only)
|
|
@@ -80,6 +81,7 @@ const MODULES = Object.freeze([
|
|
|
80
81
|
'routes-scan', // horizon-scan-portfolio: one scan for the workspace: the watch list and setting, Scan now and Stop, report documents and their proposals (approve, change, dismiss, undo), plus the first scan's per-board and Briefing reads (scan.jsonl)
|
|
81
82
|
'routes-report-setups', // report-workspace: recurring reports, the Ask box, the finder, the report documents and their export (report-setups.jsonl)
|
|
82
83
|
'routes-core-docs', // core-documents: the core documents of each level, Draft it (a core-doc run), Issue it and Drop (core-docs.jsonl)
|
|
84
|
+
'routes-custom-docs', // briefing-premium-adddoc: the documents the PM adds beyond the core set, Add a document (custom-docs.jsonl)
|
|
83
85
|
'routes-report-design', // report-design-studio: the design studio (describe, samples, turns, versions, This is it), cycle renders and decisions, speaker notes and pins
|
|
84
86
|
'routes-report-structure', // report-structure: the structure step (turns, versions, Use this structure, sources and their checks, dry run) and the chart store (GET /api/charts)
|
|
85
87
|
'routes-refresh', // data-refresh-settings: Settings › Data refresh: what refreshes, when, the refresh log, Refresh now
|
|
@@ -10,6 +10,7 @@ const BoardPremium = require('./board-premium.js');
|
|
|
10
10
|
const BoardP = BoardPremium;
|
|
11
11
|
const boards = require('./routes-boards.js');
|
|
12
12
|
const coreDocs = require('./routes-core-docs.js');
|
|
13
|
+
const Custom = require('./custom-docs.js');
|
|
13
14
|
const path = require('path');
|
|
14
15
|
const fs = require('fs');
|
|
15
16
|
const Metrics = require('./board-metrics-premium.js');
|
|
@@ -73,10 +74,13 @@ module.exports = {
|
|
|
73
74
|
]);
|
|
74
75
|
const ok = (r, name) => { if (r.status === 202 || !r.body || r.body.ok === false || r.body.pending) { missing.push(name); return null; } return r.body; };
|
|
75
76
|
const rk = ok(risk, 'initiatives'), nw = ok(now, 'initiatives'), c = ok(cols, 'stages'), s = ok(spr, 'sprints'), d = ok(docs, 'core documents');
|
|
77
|
+
// the documents the PM added (lib/custom-docs.js): one file read, no route
|
|
78
|
+
let custom = [];
|
|
79
|
+
try { const w = ctx.getWs ? ctx.getWs(pick.ws) : null; custom = w ? Custom.list(w.root, 'board:' + pick.id) : []; } catch { custom = []; missing.push('added documents'); }
|
|
76
80
|
const model = BoardPremium.build({
|
|
77
81
|
now: Date.now(), pending: false, missing: missing.filter((m) => m !== 'core documents'), boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })),
|
|
78
82
|
board: head.body.board, counts: head.body.counts, nextRelease: head.body.nextRelease || null,
|
|
79
|
-
rows: listOf(rk, nw), columns: c ? c.columns : [], sprints: s || { source: 'none', sprints: [] }, docs: d,
|
|
83
|
+
rows: listOf(rk, nw), columns: c ? c.columns : [], sprints: s || { source: 'none', sprints: [] }, docs: d, custom,
|
|
80
84
|
});
|
|
81
85
|
ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
|
|
82
86
|
return true;
|
|
@@ -16,6 +16,7 @@ const Ag = require('./briefing-premium-agent.js');
|
|
|
16
16
|
const WP = require('./my-work-premium.js');
|
|
17
17
|
const BoardP = require('./board-premium.js');
|
|
18
18
|
const InitP = require('./initiative-premium.js');
|
|
19
|
+
const InsP = require('./insights-premium.js');
|
|
19
20
|
const { repoScript } = require('./repo-script.js');
|
|
20
21
|
const { correctionEvent } = require(repoScript('card-state.js'));
|
|
21
22
|
const { appendOutbox } = require(repoScript('outbox.js'));
|
|
@@ -66,7 +67,7 @@ async function post(req, res, url, ctx) {
|
|
|
66
67
|
}
|
|
67
68
|
if (act === 'ask') {
|
|
68
69
|
let wsId; try { const w = merged && sk ? { id: sk.ws } : ctx.getWs && ctx.getWs(url.searchParams.get('ws') || null); wsId = w && w.id; } catch { wsId = undefined; }
|
|
69
|
-
const a = Ag.ask({ runtimeDir, key: b.key, text: b.text, model: /^work:/.test(String(b.key || '')) ? WP.peekModel() : /^board:/.test(String(b.key || '')) ? BoardP.peekModel() : /^(init|doc):/.test(String(b.key || '')) ? InitP.peekModel() : sk || /^src:/.test(String(b.key || '')) ? Prod.peekModel() : BP.peekModel(root), spawnSession: ctx.spawnSession, wsId });
|
|
70
|
+
const a = Ag.ask({ runtimeDir, key: b.key, text: b.text, model: /^work:/.test(String(b.key || '')) ? WP.peekModel() : /^board:/.test(String(b.key || '')) ? BoardP.peekModel() : /^ins:/.test(String(b.key || '')) ? InsP.peekModel() : /^(init|doc):/.test(String(b.key || '')) ? InitP.peekModel() : sk || /^src:/.test(String(b.key || '')) ? Prod.peekModel() : BP.peekModel(root), spawnSession: ctx.spawnSession, wsId });
|
|
70
71
|
ctx.json(res, a.body, a.status);
|
|
71
72
|
return true;
|
|
72
73
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-custom-docs.js — the documents the PM adds beyond the core set (initiative briefing-premium-adddoc).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/custom-docs?ws&scope → { ok, scope, docs: [{ id, title, writer, phase, link, at }] }
|
|
5
|
+
* POST /api/custom-docs/add { ws, scope, title, writer, phase, kind, url } → { ok, doc } one `add` line in custom-docs.jsonl
|
|
6
|
+
*
|
|
7
|
+
* WHO WRITES. The POST refuses a request that carries an agent session header (403), as routes-core-docs.js does, and passes pm-guard
|
|
8
|
+
* requirePagePress: the launch nonce and the page's origin. The scope must be a board or an initiative the workspace knows (lib/core-docs.js
|
|
9
|
+
* gather). The route stores what the PM typed and nothing else: it never reads a linked page. */
|
|
10
|
+
const guard = require('./pm-guard.js');
|
|
11
|
+
const CD = require('./core-docs.js');
|
|
12
|
+
const Custom = require('./custom-docs.js');
|
|
13
|
+
|
|
14
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
15
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
16
|
+
|
|
17
|
+
function wsOf(ctx, id) {
|
|
18
|
+
const w = ctx.getWs(id || null);
|
|
19
|
+
return w && (!id || w.id === id) ? w : null;
|
|
20
|
+
}
|
|
21
|
+
/** The scope must name a board or an initiative this workspace holds. → null | refusal */
|
|
22
|
+
function known(ctx, w, scope) {
|
|
23
|
+
const p = CD.parseScope(scope);
|
|
24
|
+
if (!p || p.level === 'portfolio') return bad(400, 'scope must be board:<id> or initiative:<id>');
|
|
25
|
+
const g = CD.gather(ctx, w, { level: p.level, board: p.level === 'board' ? p.id : null, id: p.level === 'initiative' ? p.id : null, now: Date.now() });
|
|
26
|
+
if (g.pending) return bad(202, 'The initiatives are being read. Ask again in a few seconds.');
|
|
27
|
+
if (!g.ok) return bad(g.status || 404, g.error || 'no such board or initiative');
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function handle(req, res, url, ctx) {
|
|
32
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
33
|
+
const sub = url.pathname.replace(/^\/api\/custom-docs\/?/, '');
|
|
34
|
+
if (sub === '') {
|
|
35
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
36
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
37
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
38
|
+
const scope = text(url.searchParams.get('scope'));
|
|
39
|
+
if (!Custom.check({ scope, title: 'x' }).ok) return send(bad(400, 'scope must be board:<id> or initiative:<id>'));
|
|
40
|
+
return send({ status: 200, body: { ok: true, scope, docs: Custom.list(w.root, scope) } });
|
|
41
|
+
}
|
|
42
|
+
if (sub !== 'add') return send(bad(404, 'no such custom-docs route'));
|
|
43
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
44
|
+
const read = await ctx.readJson(req);
|
|
45
|
+
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
46
|
+
const body = read.body || {};
|
|
47
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot add a document. Only a press on the page does'));
|
|
48
|
+
const g = guard.requirePagePress(req, body);
|
|
49
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
50
|
+
const w = wsOf(ctx, text(body.ws));
|
|
51
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
52
|
+
const c = Custom.check(body);
|
|
53
|
+
if (!c.ok) return send(bad(c.status, c.error));
|
|
54
|
+
const miss = known(ctx, w, c.value.scope);
|
|
55
|
+
if (miss) return send(miss);
|
|
56
|
+
const r = Custom.add(w.root, body, g.actor, { now: Date.now() });
|
|
57
|
+
if (!r.ok) return send(bad(r.status, r.error));
|
|
58
|
+
try { if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg(w.id); } catch { /* the next poll recounts */ }
|
|
59
|
+
return send({ status: 200, body: { ok: true, doc: r.doc } });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { prefixes: ['/api/custom-docs'], handle };
|
|
@@ -10,6 +10,7 @@ const InitPremium = require('./initiative-premium.js');
|
|
|
10
10
|
const boards = require('./routes-boards.js');
|
|
11
11
|
const initiatives = require('./routes-initiatives.js');
|
|
12
12
|
const coreDocs = require('./routes-core-docs.js');
|
|
13
|
+
const Custom = require('./custom-docs.js');
|
|
13
14
|
|
|
14
15
|
/** GET `pathAndQuery` from a route module's own handler, as the Work page's route does, and return { status, body }. */
|
|
15
16
|
async function via(mod, pathAndQuery, req, ctx) {
|
|
@@ -55,10 +56,12 @@ module.exports = {
|
|
|
55
56
|
let lad = null;
|
|
56
57
|
try { const w = ctx.getWs ? ctx.getWs(pick.ws) : null; const r = w && ctx.consoleState && ctx.consoleState.ladder ? ctx.consoleState.ladder({ root: w.root, id }) : null; lad = r && r.ok && r.row ? r.row : null; } catch { lad = null; }
|
|
57
58
|
if (!lad) missing.push('workflow steps');
|
|
59
|
+
let custom = [];
|
|
60
|
+
try { const w = ctx.getWs ? ctx.getWs(pick.ws) : null; custom = w ? Custom.list(w.root, 'initiative:' + id) : []; } catch { custom = []; missing.push('added documents'); }
|
|
58
61
|
const model = InitPremium.build({
|
|
59
62
|
now: Date.now(), pending: false, missing: missing.filter((m) => m !== 'core documents'),
|
|
60
63
|
board: { ws: own.ws || pick.ws, id: own.id, name: own.name, workflow: own.workflow },
|
|
61
|
-
row: head.body.row, sheet: sh, items: it ? it.items : [], docs: dd, ladder: lad,
|
|
64
|
+
row: head.body.row, sheet: sh, items: it ? it.items : [], docs: dd, custom, ladder: lad,
|
|
62
65
|
boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })), siblings: it ? (it.initiatives || []).map((x) => ({ id: x.id, title: x.title })) : [],
|
|
63
66
|
});
|
|
64
67
|
ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-insights-premium.js — GET /api/insights-premium[?ws=<id>&board=<id>] (initiative briefing-premium-insights).
|
|
3
|
+
*
|
|
4
|
+
* 200 { ok, state: 'ready', model, as_of } | 500 { ok: false, state: 'error', error }
|
|
5
|
+
* model is lib/insights-premium.js build(), made from what the console's Reports tab reads: /api/boards (the board list), the KR metric records of the
|
|
6
|
+
* workspace with the line status the Calendar's Quarter pane computes from them (routes-c3-strategy.js outcomeOf; /api/c3-strategy itself drops the dated
|
|
7
|
+
* readings, so the records are read here), and /api/report (the report files). None starts a cold repository read, so this route does not answer 202. Read-only: it writes nothing and the page posts nothing. */
|
|
8
|
+
const Insights = require('./insights-premium.js');
|
|
9
|
+
const boards = require('./routes-boards.js');
|
|
10
|
+
const strategy = require('./routes-c3-strategy.js');
|
|
11
|
+
const { repoScript } = require('./repo-script.js');
|
|
12
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
13
|
+
const reports = require('./routes-reports.js');
|
|
14
|
+
|
|
15
|
+
/** GET `pathAndQuery` from a route module's own handler, as the Board page's route does, and return { status, body }. */
|
|
16
|
+
async function via(mod, pathAndQuery, req, ctx) {
|
|
17
|
+
let out = { status: 500, body: null };
|
|
18
|
+
const c = Object.assign({}, ctx, { json: (res, obj, code) => { out = { status: code || 200, body: obj }; } });
|
|
19
|
+
const u = new URL('http://local' + pathAndQuery);
|
|
20
|
+
const handled = await mod.handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, u, c);
|
|
21
|
+
return handled === false ? { status: 404, body: null } : out;
|
|
22
|
+
}
|
|
23
|
+
const qs = (o) => '?' + Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
prefixes: ['/api/insights-premium'],
|
|
27
|
+
handle: async (req, res, url, ctx) => {
|
|
28
|
+
if (url.pathname !== '/api/insights-premium') return false;
|
|
29
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
30
|
+
const fail = (error) => { ctx.json(res, { ok: false, state: 'error', error: String(error).slice(0, 240) }, 500); return true; };
|
|
31
|
+
try {
|
|
32
|
+
const list = await via(boards, '/api/boards', req, ctx);
|
|
33
|
+
const all = list.body && list.body.ok !== false ? list.body.boards || [] : [];
|
|
34
|
+
const wantWs = url.searchParams.get('ws'), wantId = url.searchParams.get('board');
|
|
35
|
+
const pick = all.find((b) => (!wantWs || b.ws === wantWs) && (!wantId || b.id === wantId)) || all[0] || null;
|
|
36
|
+
const ws = pick ? pick.ws : wantWs;
|
|
37
|
+
const q = qs({ ws });
|
|
38
|
+
const rp = await via(reports, '/api/report' + q, req, ctx);
|
|
39
|
+
let outcomes;
|
|
40
|
+
try {
|
|
41
|
+
const today = new Date(), pad = (n) => String(n).padStart(2, '0'), day = today.getFullYear() + '-' + pad(today.getMonth() + 1) + '-' + pad(today.getDate());
|
|
42
|
+
outcomes = require(repoScript('records/index.js')).list(recordsDirFor(ctx, ws), 'kr-metrics').map((k) => strategy.outcomeOf(k, day));
|
|
43
|
+
} catch (e) { return fail('the KR metric records could not be read: ' + ((e && e.message) || e)); }
|
|
44
|
+
const reportsOk = !!(rp.body && rp.body.ok !== false);
|
|
45
|
+
const model = Insights.build({
|
|
46
|
+
now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Insights' }, boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })),
|
|
47
|
+
outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing: reportsOk ? [] : ['reports'],
|
|
48
|
+
});
|
|
49
|
+
ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
|
|
50
|
+
return true;
|
|
51
|
+
} catch (e) { return fail((e && e.message) || e); }
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.259.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.259.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Coming up cards, Core documents, the dock and the standard dialog. The one press is Draft it on a core document, through POST /api/core-docs/draft.
|
|
4
4
|
* Nothing here moves an initiative or issues a document. */
|
|
5
5
|
import { pmPost } from './http.js';
|
|
6
|
-
import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, CHECK, store, crumbHtml, wireCrumb, kv, H } from './premium-shell.js';
|
|
6
|
+
import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, CHECK, store, crumbHtml, wireCrumb, kv, H, openAddDoc } from './premium-shell.js';
|
|
7
7
|
|
|
8
8
|
const MODE_KEY = 'pmos.premium.openAs';
|
|
9
9
|
let M = null; // the model
|
|
@@ -13,7 +13,7 @@ let readTimer = null;
|
|
|
13
13
|
wireRail('init');
|
|
14
14
|
const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
|
|
15
15
|
const DOCI = '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>';
|
|
16
|
-
const STATE_ICO = { Live: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>', 'Up to date': '<path d="M5 12.5l4.5 4.5L19 7.5"/>', Draft: '<path d="M4 20l4-1 11-11-3-3L5 16z"/>', 'Not started': '<circle cx="12" cy="12" r="9"/><path d="M12 8v5M12 16.5v.5"/>', Stale: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>', Due: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>' };
|
|
16
|
+
const STATE_ICO = { Linked: '<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>', Live: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>', 'Up to date': '<path d="M5 12.5l4.5 4.5L19 7.5"/>', Draft: '<path d="M4 20l4-1 11-11-3-3L5 16z"/>', 'Not started': '<circle cx="12" cy="12" r="9"/><path d="M12 8v5M12 16.5v.5"/>', Stale: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>', Due: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>' };
|
|
17
17
|
|
|
18
18
|
/* ── header ───────────────────────────────────────────────────────────────────────────────────────────── */
|
|
19
19
|
let crumbed = false;
|
|
@@ -89,7 +89,7 @@ function drawSide() {
|
|
|
89
89
|
}
|
|
90
90
|
function docRow(d) {
|
|
91
91
|
const act = !d.act ? '' : d.act.kind === 'draft' ? `<button class="dmcta alt" data-draft="${esc(d.key)}"${d.running ? ' disabled' : ''}>${d.running ? '<span class="spin"></span>' : ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}${esc(d.act.label)}</button>` : `<button class="dmcta alt" data-tab="${esc(d.act.tab)}">${esc(d.act.label)}</button>`;
|
|
92
|
-
return `<div class="dmr" role="listitem"><span class="dmo"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(d.title)}</b><small>${esc(d.what)}</small><span class="dmm"><span class="s ${esc(d.st || 'live')}">${ICO(STATE_ICO[d.state] || STATE_ICO['Not started'])}${esc(d.state)}</span>${d.cadence ? `<span>${ICO('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')}${esc(d.cadence)}</span>` : ''}${d.by ? `<span>${ICO('<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>')}${esc(d.by)}</span>` : ''}</span></span></span><span class="dmq">${act}</span></div>`;
|
|
92
|
+
return `<div class="dmr" role="listitem"><span class="dmo"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(d.title)}</b><small>${esc(d.what)}</small><span class="dmm"><span class="s ${esc(d.st || 'live')}">${ICO(STATE_ICO[d.state] || STATE_ICO['Not started'])}${esc(d.state)}</span>${d.added ? `<span>${ICO('<rect x="3" y="5" width="18" height="16" rx="3"/><path d="M3 10h18M8 3v4M16 3v4"/>')}added ${esc(d.added)}</span>` : ''}${d.cadence ? `<span>${ICO('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')}${esc(d.cadence)}</span>` : ''}${d.by ? `<span>${ICO('<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>')}${esc(d.by)}</span>` : ''}</span></span></span><span class="dmq">${act}</span></div>`;
|
|
93
93
|
}
|
|
94
94
|
let docFilter = 'all', docQuery = '';
|
|
95
95
|
const draftable = () => (M.docs.rows || []).filter((d) => d.st === 'missing' && d.act && d.act.kind === 'draft' && !d.running);
|
|
@@ -101,11 +101,12 @@ function drawDocList() {
|
|
|
101
101
|
}
|
|
102
102
|
function drawDocs() {
|
|
103
103
|
const D = M.docs, c = D.counts;
|
|
104
|
+
$('#addDoc').hidden = !D.scope;
|
|
104
105
|
$('#docCap').textContent = D.rows.length ? String(c.all) : '';
|
|
105
106
|
if (!D.rows.length) { $('#docTop').innerHTML = ''; $('#docBody').innerHTML = `<p class="empty3 plain">${D.missing ? 'The core documents could not be read, so none is shown.' : 'No core documents are on record for this board.'}</p>`; $('#docNote').textContent = ''; return; }
|
|
106
107
|
const dot = { ok: 'ok', draft: 'warn', missing: 'mut' };
|
|
107
108
|
const hadQ = $('#dmQ') && document.activeElement === $('#dmQ');
|
|
108
|
-
$('#docTop').innerHTML = `<p class="dsum"><span><b>${c.draft}</b> ${c.draft === 1 ? 'draft' : 'drafts'} to review</span><span><b>${c.none}</b> not started</span><span><b>${c.ok}</b> up to date</span>${draftable().length > 1 ? `<button class="dlink" data-draftall="1">${ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}Draft the ${draftable().length} not started</button>` : ''}</p>
|
|
109
|
+
$('#docTop').innerHTML = `<p class="dsum"><span><b>${c.draft}</b> ${c.draft === 1 ? 'draft' : 'drafts'} to review</span><span><b>${c.none}</b> not started</span><span><b>${c.ok}</b> up to date</span>${c.linked ? `<span><b>${c.linked}</b> linked</span>` : ''}${draftable().length > 1 ? `<button class="dlink" data-draftall="1">${ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}Draft the ${draftable().length} not started</button>` : ''}</p>
|
|
109
110
|
<div class="dprog" role="img" aria-label="${c.ok} of ${c.all} up to date">${D.rows.map((d) => `<i class="${dot[d.st] || (d.st === 'live' ? 'ok' : 'mut')}"></i>`).join('')}</div>
|
|
110
111
|
<div class="dtool"><div class="seg" id="dmF" role="group" aria-label="Filter documents"><i class="pill"></i>${[['all', 'All', c.all], ['none', 'Not started', c.none], ['draft', 'Draft', c.draft], ['ok', 'Up to date', c.ok]].map(([k, l, n]) => `<button data-dmf="${k}" aria-pressed="${docFilter === k}">${l}<em>${n}</em></button>`).join('')}</div>
|
|
111
112
|
<label class="dmsr">${ICO('<circle cx="11" cy="11" r="6.5"/><path d="m20 20-4-4"/>')}<input id="dmQ" type="search" placeholder="Find a document" aria-label="Find a document" value="${esc(docQuery)}"></label></div>`;
|
|
@@ -134,6 +135,8 @@ $('#docBody').addEventListener('click', async (e) => {
|
|
|
134
135
|
await load();
|
|
135
136
|
});
|
|
136
137
|
|
|
138
|
+
$('#addDoc').onclick = () => openAddDoc({ ws: M.board.ws, scope: M.docs.scope, sub: M.board.name, onAdded: load });
|
|
139
|
+
|
|
137
140
|
/* ── dock ───────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
138
141
|
function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.label; $('#dNext').innerHTML = M.dock.next ? `<i></i>First <b>${esc(M.dock.next)}</b>` : 'Nothing is late or at risk'; }
|
|
139
142
|
|