create-pmos 0.397.0 → 0.398.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- 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 +101 -52
- package/workspace/briefing-premium-board-test.js +252 -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 +86 -196
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +159 -296
- package/workspace/briefing-premium-insights-test.js +337 -219
- package/workspace/briefing-premium-metrics-test.js +53 -97
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +66 -48
- package/workspace/briefing-premium-test.js +150 -647
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +12 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +47 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +85 -19
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +62 -14
- package/workspace/lib/insights-records.js +101 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-insights-premium.js +12 -3
- package/workspace/lib/routes-insights-records.js +129 -0
- package/workspace/lib/routes-notes.js +1 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/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 +85 -75
- package/workspace/premium-briefing-depth-test.js +66 -53
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +35 -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 +32 -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 +50 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +7 -2
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +115 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -33
- package/workspace/premium-vw-cal-test.js +82 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +11 -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 +118 -187
- package/workspace/premium-vw-notes-test.js +85 -108
- package/workspace/premium-vw-rec-test.js +72 -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 +305 -0
- package/workspace/public/pm/bd-span.js +186 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- 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 +497 -230
- 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 +296 -167
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +17 -6
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +144 -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 +905 -0
- package/workspace/public/pm/home-around.js +515 -0
- package/workspace/public/pm/home-chat.js +459 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-more.js +249 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-work.js +519 -0
- package/workspace/public/pm/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 +423 -394
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-insights.js +792 -568
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +509 -480
- package/workspace/public/pm/premium-report-tab.js +87 -63
- package/workspace/public/pm/premium-shell.js +72 -119
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +187 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +731 -0
- package/workspace/public/pm/premium-vw-notes.js +56 -69
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -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/term-view.js +22 -0
- package/workspace/public/premium-board.html +28 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +22 -60
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +16 -107
- 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/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* forecast is drawn and no cause is given. One projection is said in words (initiative insights-one-list L2, amending briefing-premium-insights I6): for a
|
|
21
21
|
* measure short of its target with a target date ahead, a straight line through its last four readings carried to that date. Its method is stated. Run-based series (corrections per 100 runs, merges a week) belong to the Board's Metrics card and are not built here (PRD decision 4). */
|
|
22
22
|
|
|
23
|
+
const IG = require('./insights-goals.js');
|
|
23
24
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
24
25
|
const isoDay = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
25
26
|
const shortDate = (v) => { const t = isoDay(v); if (t === null) return ''; const d = new Date(t); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()]; };
|
|
@@ -192,6 +193,7 @@ function setupsOf(su, now) {
|
|
|
192
193
|
id: s.id, name: clip(s.name, 120), purpose: clip(s.purpose, 240), audience: s.audience || '', source: s.source || '', output: s.output || '', label: s.label || '',
|
|
193
194
|
next: s.next_draft ? shortDate(s.next_draft) : '', lastIssued: s.last_issued ? shortDate(s.last_issued) : '', status: s.status || '', cycles: fin(s.cycles) ? s.cycles : 0,
|
|
194
195
|
paused: s.status === 'paused', fromWork: s.source === 'work', structured: !!(s.structure && s.structure.saved), drafting: !!(s.draft && s.draft.state === 'drafting'),
|
|
196
|
+
builtFrom: s.structure && Array.isArray(s.structure.charts) ? [...new Set(s.structure.charts.map((c) => (typeof c === 'string' ? c : c && (c.title || c.name || c.chart || c.id))).filter((x) => typeof x === 'string' && x).map((x) => clip(x, 40)))].slice(0, 4) : [], // premium-agreed-design: Library "Built from"
|
|
195
197
|
}));
|
|
196
198
|
const found = (su.findings || []).slice(0, 3).map((x) => ({
|
|
197
199
|
id: x.id, name: clip(x.name, 120), why: clip(x.why, 240), evidence: (x.evidence || []).map((e) => ({ kind: e.kind || '', text: clip(e.text, 240) })),
|
|
@@ -276,15 +278,21 @@ function goalType(unit) {
|
|
|
276
278
|
return 'Count';
|
|
277
279
|
}
|
|
278
280
|
const STATE_TONE = { ok: 'ok', drift: 'late', off: 'red', unscored: 'q' };
|
|
281
|
+
/** The Agreed design's dates and amounts on Goals: "Dec 31", "16 pts". A pace is said to whole units from 10 up, to one decimal below. PURE. */
|
|
282
|
+
const mdDate = (v) => { const t = isoDay(v); if (t === null) return ''; const d = new Date(t); return MON[d.getUTCMonth()] + ' ' + d.getUTCDate(); };
|
|
283
|
+
const paceR = (v, tgt) => { const d = Math.max(Math.abs(v) < 10 ? 1 : 0, Math.min(2, (String(fin(tgt) ? tgt : '').split('.')[1] || '').length)), k = 10 ** d; return Math.round(v * k) / k; };
|
|
284
|
+
const ptsOf = (v, u) => (String(u).trim() === '%' ? r2(v) + (r2(v) === 1 ? ' pt' : ' pts') : num(v, u));
|
|
279
285
|
const anchorHits = (a, o) => !!a && (String(a) === String(o.id) || String(a) === String(o.name));
|
|
280
286
|
function initOf(r) {
|
|
281
287
|
const i = lifeIndex(r.stage);
|
|
282
288
|
return { id: String(r.id), title: clip(r.title || r.id, 120), stage: r.stage || '', idx: i, stageLabel: i >= 0 ? LIFE_LABEL[i] : (r.stage || ''), status: r.status || '', lane: r.lane || '',
|
|
283
|
-
owner: r.owner || '', end: r.end ? shortDate(r.end) : '', endAt: r.end ? String(r.end).slice(0, 10) : null, anchor: r.anchor || ''
|
|
289
|
+
owner: r.owner || '', end: r.end ? shortDate(r.end) : '', endAt: r.end ? String(r.end).slice(0, 10) : null, anchor: r.anchor || '',
|
|
290
|
+
startAt: r.start ? String(r.start).slice(0, 10) : null, skipped: IG.skippedOf(r.warnings) };
|
|
284
291
|
}
|
|
285
292
|
/** 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) {
|
|
293
|
+
function goalsOf(outcomes, charts, inits, today, meta) {
|
|
287
294
|
return outcomes.map((o) => {
|
|
295
|
+
const x = (meta && meta[o.id]) || {}; // the fields New goal keeps on the record (lib/insights-goals.js goalFields)
|
|
288
296
|
const c = charts.find((x) => x.id === o.id) || null;
|
|
289
297
|
const rs = (o.readings || []).filter((x) => x && fin(x.v) && isoDay(x.at) !== null);
|
|
290
298
|
const u = o.unit || '', base = fin(o.start) ? o.start : null, tgt = fin(o.target) ? o.target : null;
|
|
@@ -294,18 +302,33 @@ function goalsOf(outcomes, charts, inits, today) {
|
|
|
294
302
|
const t0 = isoDay(fromAt), t1 = isoDay(byAt);
|
|
295
303
|
const timeGone = t0 !== null && t1 !== null && t1 > t0 ? Math.max(0, Math.min(1, (today - t0) / (t1 - t0))) : null;
|
|
296
304
|
const done = now !== null && tgt !== null && base !== null && tgt !== base ? Math.max(0, Math.min(1, (now - base) / (tgt - base))) : null;
|
|
297
|
-
const
|
|
305
|
+
const p0 = c ? projectionOf(c) : null;
|
|
306
|
+
/* a percentage cannot pass 100: the pace is said at the cap, not as "≈100.3%" */
|
|
307
|
+
const p = p0 && /^%$/.test(u.trim()) && p0.atDue > 100 ? Object.assign({}, p0, { atDue: 100 }) : p0;
|
|
298
308
|
const reached = now !== null && tgt !== null && dir && (dir > 0 ? now >= tgt : now <= tgt);
|
|
299
309
|
let pace;
|
|
300
|
-
if (reached) pace = { tone: 'ok', head: 'Reached', sub: 'at ' + num(now, u) + (rs.length ? ' on ' +
|
|
310
|
+
if (reached) pace = { tone: 'ok', head: 'Reached', sub: 'at ' + num(now, u) + (rs.length ? ' on ' + mdDate(rs[rs.length - 1].at) : '') };
|
|
301
311
|
else if (p && !p.toward) pace = { tone: 'late', head: 'Never reaches ' + num(tgt, u), sub: p.perWeek === 0 ? 'not moving' : 'moving the wrong way' };
|
|
302
|
-
else if (p && !p.reaches) pace = { tone: 'late', head: '≈' + num(
|
|
303
|
-
else if (p) pace = { tone: 'ok', head: '≈' + num(
|
|
312
|
+
else if (p && !p.reaches) pace = { tone: 'late', head: '≈' + num(paceR(p.atDue, tgt), u) + ' by ' + mdDate(byAt), sub: ptsOf(paceR(p.short, tgt), u) + ' short at this pace' };
|
|
313
|
+
else if (p) pace = { tone: 'ok', head: '≈' + num(paceR(p.atDue, tgt), u) + ' by ' + mdDate(byAt), sub: done !== null && timeGone !== null ? (done > timeGone ? 'ahead: ' : 'on course: ') + Math.round(done * 100) + '% done, ' + Math.round(timeGone * 100) + '% of time gone' : 'on course' };
|
|
304
314
|
else pace = { tone: 'q', head: '—', sub: rs.length < 2 ? (rs.length ? 'needs a second reading' : 'no reading yet') : !byAt ? 'no target date' : t1 !== null && t1 <= isoDay(rs[rs.length - 1].at) ? 'its date has passed' : 'no pace to read' };
|
|
315
|
+
if (x.type === 'Stay within' && tgt !== null) { // a floor or a ceiling: within it or not, with the room left
|
|
316
|
+
const ceil = x.limit !== 'floor', inside = now === null ? null : ceil ? now <= tgt : now >= tgt;
|
|
317
|
+
pace = now === null ? { tone: 'q', head: '—', sub: 'no reading yet' }
|
|
318
|
+
: inside ? { tone: 'ok', head: 'Within its ' + (ceil ? 'ceiling' : 'floor'), sub: num(Math.abs(tgt - now), u) + ' of room left' }
|
|
319
|
+
: { tone: 'late', head: (ceil ? 'Over its ceiling' : 'Under its floor') + ' by ' + num(Math.abs(now - tgt), u), sub: 'since ' + mdDate(rs[rs.length - 1].at) };
|
|
320
|
+
} else if (x.type === 'Done or not' && tgt !== null) {
|
|
321
|
+
const n = now === null ? 0 : now, all = Array.isArray(x.steps) && x.steps.length ? x.steps.length : null;
|
|
322
|
+
pace = n >= tgt ? { tone: 'ok', head: 'Done', sub: rs.length ? 'on ' + mdDate(rs[rs.length - 1].at) : '' }
|
|
323
|
+
: { tone: byAt && t1 !== null && t1 < today ? 'late' : 'q', head: 'Not yet', sub: (all ? n + ' of ' + all + ' steps · ' : '') + (byAt ? 'due ' + mdDate(byAt) : 'no due date') };
|
|
324
|
+
}
|
|
305
325
|
const moves = (inits || []).filter((r) => anchorHits(r.anchor, o)).map(initOf);
|
|
306
326
|
return {
|
|
307
|
-
id: o.id, key: c ? c.key : null, title: clip(o.name, 120), pillar: o.pillar || '', unit: u, type: goalType(u),
|
|
308
|
-
|
|
327
|
+
id: o.id, key: c ? c.key : null, title: clip(o.name, 120), pillar: o.pillar || '', unit: u, type: IG.GOAL_TYPES.includes(x.type) ? x.type : goalType(u),
|
|
328
|
+
direction: x.direction || (dir > 0 ? 'up' : dir < 0 ? 'down' : ''),
|
|
329
|
+
dirTxt: x.type === 'Stay within' ? (x.limit === 'floor' ? 'stay above' : 'stay below') : x.direction === 'exact' ? 'exactly the target' : dir > 0 ? 'up is better' : dir < 0 ? 'down is better' : '',
|
|
330
|
+
period: x.period || null, checkpoints: Array.isArray(x.checkpoints) ? x.checkpoints : [], source: x.source || '', owner: x.owner || '', guardrail: x.guardrail || '',
|
|
331
|
+
steps: Array.isArray(x.steps) ? x.steps : null, items: Array.isArray(x.items) ? x.items.filter((s) => typeof s === 'string' && s.trim()).map((s) => clip(s.trim(), 60)) : null, limit: x.limit || null, alwaysOn: x.always_on === true, series: rs.map((r) => ({ at: String(r.at).slice(0, 10), v: r.v })), base, baseTxt: base !== null ? num(base, u) : '', from: fromAt ? shortDate(fromAt) : '',
|
|
309
332
|
now, nowTxt: now !== null ? num(now, u) : '', target: tgt, targetTxt: tgt !== null ? num(tgt, u) : '', by: byAt ? shortDate(byAt) : '', byAt, fromAt,
|
|
310
333
|
done, timeGone, tone: STATE_TONE[o.status] || 'q', state: o.status || 'unscored', chip: (CHIP[o.status] || ['No line scored'])[0], reason: o.reason || '',
|
|
311
334
|
proj: p ? { atDue: r1(p.atDue), reaches: p.reaches, toward: p.toward } : null, pace, readings: rs.length, moves,
|
|
@@ -313,16 +336,35 @@ function goalsOf(outcomes, charts, inits, today) {
|
|
|
313
336
|
});
|
|
314
337
|
}
|
|
315
338
|
/** Shipped work (Deliver, Monitor, Evaluate, or done) against what its anchor goal promised. PURE. */
|
|
316
|
-
function outcomesOf(inits, goals, outcomes) {
|
|
339
|
+
function outcomesOf(inits, goals, outcomes, verdicts, todayIso) {
|
|
317
340
|
const ORDER = ['verdict', 'window', 'decided'];
|
|
318
341
|
const rows = (inits || []).map(initOf).filter((r) => r.idx >= 5 || r.status === 'done');
|
|
319
342
|
return rows.map((r) => {
|
|
320
343
|
const g = goals.find((x) => anchorHits(r.anchor, { id: x.id, name: (outcomes.find((o) => o.id === x.id) || {}).name })) || null;
|
|
321
|
-
const
|
|
322
|
-
|
|
344
|
+
const vd = (verdicts && verdicts[r.id]) || null, o = g ? outcomes.find((x) => x.id === g.id) : null;
|
|
345
|
+
const group = vd || r.status === 'done' || r.status === 'cancelled' ? 'decided' : r.idx === 7 ? 'verdict' : 'window';
|
|
346
|
+
return Object.assign(r, { group, verdict: vd ? { verdict: vd.verdict, learned: vd.learned, at: vd.at ? String(vd.at).slice(0, 10) : null } : null,
|
|
347
|
+
window: IG.windowOf({ shipAt: r.endAt, byAt: g ? g.byAt : null, verdict: vd, today: todayIso }),
|
|
348
|
+
evidence: g && o ? IG.evidenceOf((o.readings || []).map((x) => ({ at: String(x.at), v: x.v })), r.endAt, g.unit) : [], goal: g ? { id: g.id, key: g.key, title: g.title, type: g.type, baseTxt: g.baseTxt, targetTxt: g.targetTxt, nowTxt: g.nowTxt, by: g.by, done: g.done, tone: g.tone, pace: g.pace } : null });
|
|
323
349
|
}).sort((a, b) => ORDER.indexOf(a.group) - ORDER.indexOf(b.group));
|
|
324
350
|
}
|
|
325
351
|
|
|
352
|
+
/** The health budgets the board's initiatives anchor to (D59: an anchor health:<id>). A budget's floor or ceiling and its weekly readings are not
|
|
353
|
+
* read on this page, so a budget holds only its id and what moves it. PURE. */
|
|
354
|
+
function budgetsOf(inits, registry) {
|
|
355
|
+
const by = new Map();
|
|
356
|
+
for (const b of registry || []) by.set(b.id, []);
|
|
357
|
+
for (const r of inits || []) {
|
|
358
|
+
const m = /^health:(.+)$/.exec(String((r && r.anchor) || '').trim()); if (!m) continue;
|
|
359
|
+
if (!by.has(m[1])) by.set(m[1], []);
|
|
360
|
+
by.get(m[1]).push(initOf(r));
|
|
361
|
+
}
|
|
362
|
+
return [...by.entries()].map(([id, moves]) => {
|
|
363
|
+
const b = (registry || []).find((x) => x.id === id) || null;
|
|
364
|
+
return { id, anchor: 'health:' + id, title: id, moves, covers: b ? b.covers : '', cap: b ? b.cap : null, declared: !!b, reading: b && Array.isArray(inits) ? IG.budgetReading(b, inits) : null };
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
326
368
|
function build(facts) {
|
|
327
369
|
const f = facts || {};
|
|
328
370
|
const outcomes = f.outcomes || [], missing = (f.missing || []).slice();
|
|
@@ -360,12 +402,18 @@ function build(facts) {
|
|
|
360
402
|
};
|
|
361
403
|
const today = isoDay(new Date(fin(f.now) ? f.now : Date.now()).toISOString()) || 0;
|
|
362
404
|
model.today = new Date(today).toISOString().slice(0, 10);
|
|
363
|
-
model.goals = goalsOf(outcomes, charts, f.initiatives || [], today);
|
|
405
|
+
model.goals = goalsOf(outcomes, charts, f.initiatives || [], today, f.goalMeta || {});
|
|
364
406
|
model.initiativesRead = Array.isArray(f.initiatives);
|
|
365
|
-
|
|
407
|
+
const ins = f.ins || { charts: {}, verdicts: {}, targets: {} }, bid = board.id || '';
|
|
408
|
+
model.outcomes = outcomesOf(f.initiatives || [], model.goals, outcomes, ins.verdicts[bid] || {}, model.today);
|
|
409
|
+
model.budgets = budgetsOf(f.initiatives || [], f.budgets || []);
|
|
410
|
+
model.budgetsRead = Array.isArray(f.budgets);
|
|
411
|
+
model.lateNow = Array.isArray(f.initiatives) ? f.initiatives.filter((r) => r && r.status === 'late').length : null;
|
|
412
|
+
model.trends = Object.assign(IG.trendsOf(Array.isArray(f.initiatives) ? f.initiatives : null, model.today), { targets: ins.targets || {} });
|
|
413
|
+
model.chartSet = ins.charts[bid] || {}; // { [dashboard]: { [goal]: { form, range, compare, target, forecast, note } } }
|
|
366
414
|
model.lifecycle = LIFE_LABEL.map((label, i) => ({ key: LIFE[i], label, milestone: i === 5 || i === 7 }));
|
|
367
415
|
last = model;
|
|
368
416
|
return model;
|
|
369
417
|
}
|
|
370
418
|
|
|
371
|
-
module.exports = { lifeIndex, goalType, goalsOf, outcomesOf, build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
419
|
+
module.exports = { lifeIndex, goalType, goalsOf, outcomesOf, budgetsOf, mdDate, build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
* fold(lines) → { charts: { [board]: { [dash]: { [goal]: chart } } }, verdicts: { [board]: { [ini]: verdict } }, targets: { [key]: number } } PURE
|
|
11
|
+
* read(root) → fold(readLines(ledgerFile(root)))
|
|
12
|
+
* append(root, ev, value, actor, { now }) → { ok, line } THE SINGLE WRITER. `v`, `ev`, `actor` and `at` are set here.
|
|
13
|
+
*
|
|
14
|
+
* THE LINES. { v: 1, ev: 'chart' | 'verdict' | 'target', ...value, actor, at }. The last line of each key wins: a chart per board, dashboard and goal;
|
|
15
|
+
* a verdict per board and initiative; a target per key. A torn line, or one without its key fields, is skipped.
|
|
16
|
+
* A verdict is recorded here only: it does not move the initiative on the Board and does not change its record. */
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
const LEDGER = 'insights-records.jsonl';
|
|
21
|
+
const FORMS = Object.freeze(['Line', 'Bars', 'Number', 'Meter']);
|
|
22
|
+
const RANGES = Object.freeze(['8w', 'Quarter', '26w']);
|
|
23
|
+
const COMPARES = Object.freeze(['', 'lq']);
|
|
24
|
+
const VERDICTS = Object.freeze(['Keep', 'Iterate', 'Stop']);
|
|
25
|
+
const TARGET_KEYS = Object.freeze(['late', 'scope']);
|
|
26
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/;
|
|
27
|
+
const NOTE_MAX = 160, LEARN_MAX = 600;
|
|
28
|
+
|
|
29
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
30
|
+
const refuse = (status, error) => ({ ok: false, status, error });
|
|
31
|
+
const tidy = (v, n) => (typeof v === 'string' ? v.trim().replace(/\s+/g, ' ').slice(0, n) : '');
|
|
32
|
+
const id = (v) => (typeof v === 'string' && ID_RE.test(v) ? v : null);
|
|
33
|
+
|
|
34
|
+
function ledgerFile(root) {
|
|
35
|
+
const abs = path.resolve(String(root));
|
|
36
|
+
return path.join(abs, require('./report-draft.js').stateRel(abs), LEDGER);
|
|
37
|
+
}
|
|
38
|
+
function readLines(file) {
|
|
39
|
+
let text = '';
|
|
40
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
41
|
+
const out = [];
|
|
42
|
+
for (const raw of text.split('\n')) {
|
|
43
|
+
if (!raw.trim()) continue;
|
|
44
|
+
try { const l = JSON.parse(raw); if (isObj(l) && typeof l.ev === 'string') out.push(l); } catch { /* a torn line is skipped */ }
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function checkChart(input) {
|
|
50
|
+
const i = isObj(input) ? input : {};
|
|
51
|
+
const board = id(i.board), dash = id(i.dash), goal = id(i.goal);
|
|
52
|
+
if (!board || !dash || !goal) return refuse(400, 'Name the board, the dashboard and the goal of the chart.');
|
|
53
|
+
if (dash === 'all' || dash.startsWith('p:')) return refuse(400, 'A chart is kept on a saved dashboard. Make one with New dashboard first.');
|
|
54
|
+
const form = FORMS.includes(i.form) ? i.form : null, range = RANGES.includes(i.range) ? i.range : null;
|
|
55
|
+
if (!form) return refuse(400, 'Pick a form: ' + FORMS.join(', ') + '.');
|
|
56
|
+
if (!range) return refuse(400, 'Pick a range: 8w, Quarter or 26w.');
|
|
57
|
+
const compare = COMPARES.includes(i.compare || '') ? i.compare || '' : null;
|
|
58
|
+
if (compare === null) return refuse(400, 'Compare with last quarter, or nothing.');
|
|
59
|
+
return { ok: true, value: { board, dash, goal, form, range, compare, target: i.target !== false, forecast: i.forecast === true, note: tidy(i.note, NOTE_MAX) } };
|
|
60
|
+
}
|
|
61
|
+
function checkVerdict(input) {
|
|
62
|
+
const i = isObj(input) ? input : {};
|
|
63
|
+
const board = id(i.board), ini = id(i.ini);
|
|
64
|
+
if (!board || !ini) return refuse(400, 'Name the board and the initiative.');
|
|
65
|
+
if (!VERDICTS.includes(i.verdict)) return refuse(400, 'Pick Keep, Iterate or Stop.');
|
|
66
|
+
const learned = tidy(i.learned, LEARN_MAX);
|
|
67
|
+
if (!learned) return refuse(400, 'Say what you learned, in a line.');
|
|
68
|
+
return { ok: true, value: { board, ini, verdict: i.verdict, learned, goal: id(i.goal) } };
|
|
69
|
+
}
|
|
70
|
+
function checkTarget(input) {
|
|
71
|
+
const i = isObj(input) ? input : {};
|
|
72
|
+
if (!TARGET_KEYS.includes(i.key)) return refuse(400, 'Name the tile: late or scope.');
|
|
73
|
+
const t = i.target === '' || i.target == null ? null : Number(i.target);
|
|
74
|
+
if (t !== null && !(Number.isFinite(t) && t >= 0)) return refuse(400, 'The target is a number of initiatives, 0 or more.');
|
|
75
|
+
return { ok: true, value: { key: i.key, target: t } };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function fold(lines) {
|
|
79
|
+
const charts = {}, verdicts = {}, targets = {};
|
|
80
|
+
for (const l of lines || []) {
|
|
81
|
+
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 }); }
|
|
82
|
+
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 }); }
|
|
83
|
+
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; }
|
|
84
|
+
}
|
|
85
|
+
return { charts, verdicts, targets };
|
|
86
|
+
}
|
|
87
|
+
const read = (root) => fold(readLines(ledgerFile(root)));
|
|
88
|
+
|
|
89
|
+
const CHECKS = { chart: checkChart, verdict: checkVerdict, target: checkTarget };
|
|
90
|
+
function append(root, ev, input, actor, { now } = {}) {
|
|
91
|
+
if (!CHECKS[ev]) return refuse(400, 'unknown record: ' + ev);
|
|
92
|
+
const c = CHECKS[ev](input);
|
|
93
|
+
if (!c.ok) return c;
|
|
94
|
+
const file = ledgerFile(root), t = now == null ? Date.now() : now;
|
|
95
|
+
const line = Object.assign({ v: 1, ev }, c.value, { actor: actor || null, at: new Date(t).toISOString() });
|
|
96
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
97
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
98
|
+
return { ok: true, line };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = { LEDGER, FORMS, RANGES, VERDICTS, TARGET_KEYS, ledgerFile, readLines, checkChart, checkVerdict, checkTarget, 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;
|
|
@@ -52,7 +52,9 @@ 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-board-trail', // premium-agreed-design: what the Agreed Board draws beside each initiative, derived from the repository (read-only)
|
|
55
56
|
'routes-insights-premium', // briefing-premium-insights: the premium Insights page's model from the KR metric records and report files (read-only)
|
|
57
|
+
'routes-home-desk', // premium-agreed-design (Home): seen marks, queued messages, the weekly update's recipients and sends, stakeholders (page press; file mode)
|
|
56
58
|
'routes-initiative-premium', // briefing-premium-initiative: the premium initiative page's model from the Initiatives sheet's own routes (read-only)
|
|
57
59
|
'routes-brief-page', // console3 Briefing as the brief: Today agenda, Needs you and Mentions (read-only; writes go through routes-pm-items)
|
|
58
60
|
'routes-mentions', // console3 Briefing Mentions: the PM's read marks (page press only)
|
|
@@ -77,6 +79,7 @@ const MODULES = Object.freeze([
|
|
|
77
79
|
'routes-meeting-focus', // console3 Meeting focus: the meeting, its note's talk, the companion's notes (GET); topic corrections and Ask PMOS quietly (page press)
|
|
78
80
|
'routes-meeting-replay', // meeting-material-replay: the note, the Focus state and the shots joined for the Replay page (GET, read-only)
|
|
79
81
|
'routes-meeting-material', // meeting-material-replay: the material the PM links to a meeting (GET list and suggest; page-press POST add and remove; meeting-material.jsonl)
|
|
82
|
+
'routes-viewer', // premium-agreed-design (viewer): agenda minutes, what recording listens to, a next step made a drafted ticket, the report's Issue checks
|
|
80
83
|
'routes-stage-tools', // stage-tools-records: the records the PM edits per stage, what PMOS holds per stage, the sprint burndown
|
|
81
84
|
'routes-orchestrator', // agent-orchestrator: the status of the capacity governor and the PM's stop switch (orchestrator-stop.json)
|
|
82
85
|
'routes-driver', // initiative-driver: the Agent strip's data, Keep, Send back, Drop, Pause and the board mode (driver.jsonl)
|
|
@@ -86,6 +89,7 @@ const MODULES = Object.freeze([
|
|
|
86
89
|
'routes-custom-docs', // briefing-premium-adddoc: the documents the PM adds beyond the core set, Add a document (custom-docs.jsonl)
|
|
87
90
|
'routes-premium-dashboards', // briefing-premium-reports: the dashboards the PM makes on premium Insights (premium-dashboards.jsonl; page-press POST save)
|
|
88
91
|
'routes-board-metric-targets', // briefing-premium-metrics option C: the targets of the Board's four measures, set on premium Insights (board-metric-targets.jsonl; page-press POST save)
|
|
92
|
+
'routes-insights-records', // premium-agreed-design: Insights' New goal, steps, dashboards with their charts, Save chart, describe, verdicts, tile targets, Export (insights-records.jsonl, kr-metrics.jsonl)
|
|
89
93
|
'routes-premium-charts', // premium-studio-chart: the charts the PM makes in the Insight Studio (premium-charts.jsonl; page-press POST save)
|
|
90
94
|
'routes-report-design', // report-design-studio: the design studio (describe, samples, turns, versions, This is it), cycle renders and decisions, speaker notes and pins
|
|
91
95
|
'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)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-board-trail.js — GET /api/board-trail?ws=<id>&board=<id>&ids=<id,id,…> (initiative premium-agreed-design).
|
|
3
|
+
*
|
|
4
|
+
* 200 { ok, at, usual, themes, items } — lib/board-trail.js trail() for the named initiatives of one board: days in the stage and the usual days,
|
|
5
|
+
* skipped stages and why, the parts of the step's output, what waits on the PM, tickets drafted in PMOS, links, dependencies and themes.
|
|
6
|
+
* 400 { ok: false, error } — no initiative named, or a bad id · 404 — the workspace is not registered
|
|
7
|
+
* Read-only, and apart from GET /api/board-premium so the Board draws first and this lands after. The rows (stage, lane, anchor, dates) come
|
|
8
|
+
* from the last Board model built (lib/board-premium.js peekModel), the board moves from the board ledger. */
|
|
9
|
+
const Trail = require('./board-trail.js');
|
|
10
|
+
const BoardP = require('./board-premium.js');
|
|
11
|
+
|
|
12
|
+
const ID_RE = /^[a-z0-9][\w.-]{0,80}$/i;
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
prefixes: ['/api/board-trail'],
|
|
16
|
+
handle: async (req, res, url, ctx) => {
|
|
17
|
+
if (url.pathname !== '/api/board-trail') return false;
|
|
18
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
19
|
+
const ids = String(url.searchParams.get('ids') || '').split(',').map((s) => s.trim()).filter(Boolean).slice(0, 150);
|
|
20
|
+
if (!ids.length || !ids.every((x) => ID_RE.test(x))) { ctx.json(res, { ok: false, error: 'name the initiatives: ids=<id,id,…>' }, 400); return true; }
|
|
21
|
+
const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
|
|
22
|
+
if (!w || !w.root) { ctx.json(res, { ok: false, error: 'that workspace is not registered' }, 404); return true; }
|
|
23
|
+
try {
|
|
24
|
+
const board = url.searchParams.get('board') || null;
|
|
25
|
+
let moves = [];
|
|
26
|
+
try { const fr = require('./routes-boards.js').frameFor(ctx, w); moves = (fr.folded.moves || []).filter((m) => !board || m.board === board); } catch { moves = []; }
|
|
27
|
+
const m = BoardP.peekModel();
|
|
28
|
+
const rows = m && Array.isArray(m.rows) ? m.rows.filter((r) => r && r.id && ids.includes(r.id)) : [];
|
|
29
|
+
ctx.json(res, Trail.trail({ root: w.root, ids, rows, moves, now: Date.now() }));
|
|
30
|
+
} catch (e) { ctx.json(res, { ok: false, error: String((e && e.message) || e).slice(0, 240) }, 500); }
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-home-desk.js — the records Home's desk reads and the PM's presses on it (initiative premium-agreed-design, Home).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/home-desk?ws=<id>
|
|
5
|
+
* → { ok, roles, seen, product: { recipients, sent }, stakeholders: { [initiative]: [person] }, queued: { [session]: [entry] } }
|
|
6
|
+
* POST /api/home-desk/seen { key, at? } the PM looked at a conversation: the "New since you left" marker
|
|
7
|
+
* POST /api/home-desk/recipients { ws, to: [string] } who the product's weekly update goes to
|
|
8
|
+
* POST /api/home-desk/update-sent { ws, week, to: [string], subject } the PM sent the weekly update from their own mail (a mailto draft)
|
|
9
|
+
* POST /api/home-desk/stakeholder { ws, initiative, name, role?, remove? }
|
|
10
|
+
* POST /api/home-desk/queue { session, text } a message the PM typed while the agent worked: "Queued"
|
|
11
|
+
* POST /api/home-desk/queue-drop { session, at } the queued message was read, sent now or deleted
|
|
12
|
+
* POST /api/home-desk/work-item { ws, initiative, text, key? } make a PMOS work item from a chat message (home-work-item.js)
|
|
13
|
+
*
|
|
14
|
+
* FILE MODE ONLY, append-only JSONL (D64/D66). Where each record lives:
|
|
15
|
+
* · seen and queued are the PM's per-machine marks, so they are runtime state: <runtime>/home/seen.jsonl, <runtime>/home/queued.jsonl
|
|
16
|
+
* · recipients, sent updates and stakeholders are product records, so they go in the workspace's state folder (stateDirFor):
|
|
17
|
+
* <state>/product-updates.jsonl and <state>/stakeholders.jsonl. The last line for a key wins when read back.
|
|
18
|
+
* Every POST is a page press (pm-guard requirePagePress): an agent session cannot write these. Nothing here sends mail, Slack or
|
|
19
|
+
* anything else: Send on the weekly update opens a mail draft in the PM's own mail app, and this route only records that it was opened. */
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const guard = require('./pm-guard.js');
|
|
22
|
+
const pmItems = require('./pm-items.js');
|
|
23
|
+
const roles = require('./agent-roles.js');
|
|
24
|
+
|
|
25
|
+
const KEY_RE = /^[A-Za-z0-9][A-Za-z0-9:._@/#-]{0,160}$/;
|
|
26
|
+
const SESS_RE = /^sess-\d+$/;
|
|
27
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
|
|
28
|
+
const WEEK_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
29
|
+
const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
|
|
30
|
+
const list = (v, n) => (Array.isArray(v) ? v : []).map((x) => str(x, 120)).filter(Boolean).slice(0, n);
|
|
31
|
+
|
|
32
|
+
const seenFile = (ctx) => path.join(ctx.runtimeDir, 'home', 'seen.jsonl');
|
|
33
|
+
const queueFile = (ctx) => path.join(ctx.runtimeDir, 'home', 'queued.jsonl');
|
|
34
|
+
function stateDir(ctx, w) {
|
|
35
|
+
let d = null;
|
|
36
|
+
try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create: true }) : null; } catch { d = null; }
|
|
37
|
+
return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
|
|
38
|
+
}
|
|
39
|
+
const read = (f) => { try { return pmItems.readLines(f).filter(Boolean); } catch { return []; } };
|
|
40
|
+
|
|
41
|
+
/** The last seen mark per conversation key. Pure over the lines. */
|
|
42
|
+
function foldSeen(lines) {
|
|
43
|
+
const out = {};
|
|
44
|
+
for (const l of lines) if (l && typeof l.key === 'string') out[l.key] = l.seen || l.at;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** Queued messages per session that are not dropped yet. Pure over the lines. */
|
|
48
|
+
function foldQueued(lines) {
|
|
49
|
+
const out = {};
|
|
50
|
+
for (const l of lines) {
|
|
51
|
+
if (!l || !SESS_RE.test(String(l.session || ''))) continue;
|
|
52
|
+
const q = out[l.session] || (out[l.session] = []);
|
|
53
|
+
if (l.kind === 'drop') { const i = q.findIndex((x) => x.at === l.of); if (i >= 0) q.splice(i, 1); }
|
|
54
|
+
else if (l.kind === 'queue' && l.text) q.push({ text: l.text, at: l.at });
|
|
55
|
+
}
|
|
56
|
+
for (const k of Object.keys(out)) if (!out[k].length) delete out[k];
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
/** Recipients (the last recipients line) and the sent updates, newest first. Pure over the lines. */
|
|
60
|
+
function foldProduct(lines, ws) {
|
|
61
|
+
let recipients = [];
|
|
62
|
+
const sent = [];
|
|
63
|
+
for (const l of lines) {
|
|
64
|
+
if (!l || (ws && l.ws && l.ws !== ws)) continue;
|
|
65
|
+
if (l.kind === 'recipients') recipients = Array.isArray(l.to) ? l.to : [];
|
|
66
|
+
if (l.kind === 'sent') sent.push({ week: l.week, to: l.to || [], subject: l.subject || '', at: l.at });
|
|
67
|
+
}
|
|
68
|
+
return { recipients, sent: sent.reverse().slice(0, 20) };
|
|
69
|
+
}
|
|
70
|
+
/** People per initiative: an add, then a remove of the same name takes them off. Pure over the lines. */
|
|
71
|
+
function foldStakeholders(lines) {
|
|
72
|
+
const out = {};
|
|
73
|
+
for (const l of lines) {
|
|
74
|
+
if (!l || !ID_RE.test(String(l.initiative || '')) || !l.name) continue;
|
|
75
|
+
const a = out[l.initiative] || (out[l.initiative] = []);
|
|
76
|
+
const i = a.findIndex((x) => x.name.toLowerCase() === String(l.name).toLowerCase());
|
|
77
|
+
if (l.kind === 'remove') { if (i >= 0) a.splice(i, 1); continue; }
|
|
78
|
+
const p = { name: l.name, role: l.role || '', note: l.note || '', at: l.at };
|
|
79
|
+
if (i >= 0) a[i] = p; else a.push(p);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function body(req, ctx, res) {
|
|
85
|
+
const got = await ctx.readJson(req);
|
|
86
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return null; }
|
|
87
|
+
const b = got.body || {};
|
|
88
|
+
const g = guard.requirePagePress(req, b);
|
|
89
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return null; }
|
|
90
|
+
return b;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = {
|
|
94
|
+
prefixes: ['/api/home-desk'],
|
|
95
|
+
foldSeen, foldQueued, foldProduct, foldStakeholders,
|
|
96
|
+
handle: async (req, res, url, ctx) => {
|
|
97
|
+
const p = url.pathname;
|
|
98
|
+
if (!p.startsWith('/api/home-desk')) return false;
|
|
99
|
+
const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
|
|
100
|
+
if (p === '/api/home-desk') {
|
|
101
|
+
if (req.method !== 'GET') return bad('GET only', 405);
|
|
102
|
+
const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
|
|
103
|
+
const sd = w ? stateDir(ctx, w) : null;
|
|
104
|
+
ctx.json(res, {
|
|
105
|
+
ok: true,
|
|
106
|
+
roles: roles.tableForPage(),
|
|
107
|
+
seen: ctx.runtimeDir ? foldSeen(read(seenFile(ctx))) : {},
|
|
108
|
+
queued: ctx.runtimeDir ? foldQueued(read(queueFile(ctx))) : {},
|
|
109
|
+
product: sd ? foldProduct(read(path.join(sd, 'product-updates.jsonl')), w.id) : { recipients: [], sent: [] },
|
|
110
|
+
stakeholders: sd ? foldStakeholders(read(path.join(sd, 'stakeholders.jsonl'))) : {},
|
|
111
|
+
ws: w ? w.id : null,
|
|
112
|
+
});
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (req.method !== 'POST') return bad('POST only', 405);
|
|
116
|
+
const b = await body(req, ctx, res);
|
|
117
|
+
if (!b) return true;
|
|
118
|
+
const now = new Date();
|
|
119
|
+
if (p === '/api/home-desk/seen') {
|
|
120
|
+
if (!KEY_RE.test(String(b.key || ''))) return bad('key must name a conversation');
|
|
121
|
+
if (!ctx.runtimeDir) return bad('no runtime folder', 500);
|
|
122
|
+
pmItems.appendEvent(seenFile(ctx), { key: String(b.key), seen: now.toISOString() }, now);
|
|
123
|
+
ctx.json(res, { ok: true, seen: now.toISOString() });
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (p === '/api/home-desk/queue' || p === '/api/home-desk/queue-drop') {
|
|
127
|
+
if (!SESS_RE.test(String(b.session || ''))) return bad('session must name a session');
|
|
128
|
+
if (!ctx.runtimeDir) return bad('no runtime folder', 500);
|
|
129
|
+
if (p === '/api/home-desk/queue') {
|
|
130
|
+
const t = str(b.text, 8000);
|
|
131
|
+
if (!t) return bad('text is empty');
|
|
132
|
+
pmItems.appendEvent(queueFile(ctx), { kind: 'queue', session: b.session, text: t }, now);
|
|
133
|
+
ctx.json(res, { ok: true, at: now.toISOString() });
|
|
134
|
+
} else {
|
|
135
|
+
if (!b.at) return bad('at names the queued message');
|
|
136
|
+
pmItems.appendEvent(queueFile(ctx), { kind: 'drop', session: b.session, of: String(b.at) }, now);
|
|
137
|
+
ctx.json(res, { ok: true });
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
|
|
142
|
+
if (!w) return bad('that workspace is not registered', 404);
|
|
143
|
+
const sd = stateDir(ctx, w);
|
|
144
|
+
if (!sd) return bad('this workspace has no state folder', 409);
|
|
145
|
+
if (p === '/api/home-desk/recipients') {
|
|
146
|
+
const to = list(b.to, 30);
|
|
147
|
+
pmItems.appendEvent(path.join(sd, 'product-updates.jsonl'), { kind: 'recipients', ws: w.id, to }, now);
|
|
148
|
+
ctx.json(res, { ok: true, recipients: to });
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if (p === '/api/home-desk/update-sent') {
|
|
152
|
+
if (!WEEK_RE.test(String(b.week || ''))) return bad('week must be a date (YYYY-MM-DD)');
|
|
153
|
+
const to = list(b.to, 30);
|
|
154
|
+
if (!to.length) return bad('the update goes to nobody yet: add who gets it');
|
|
155
|
+
pmItems.appendEvent(path.join(sd, 'product-updates.jsonl'), { kind: 'sent', ws: w.id, week: b.week, to, subject: str(b.subject, 200), how: 'mail draft' }, now);
|
|
156
|
+
ctx.json(res, { ok: true });
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
if (p === '/api/home-desk/work-item') {
|
|
160
|
+
const r = require('./home-work-item.js').makeFromChat(w.root, b.initiative, { text: b.text, key: b.key });
|
|
161
|
+
ctx.json(res, r.ok ? r : { ok: false, error: r.error }, r.ok ? 200 : r.status || 400);
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
if (p === '/api/home-desk/stakeholder') {
|
|
165
|
+
if (!ID_RE.test(String(b.initiative || ''))) return bad('initiative must name an initiative');
|
|
166
|
+
const name = str(b.name, 80);
|
|
167
|
+
if (!name) return bad('name the person');
|
|
168
|
+
pmItems.appendEvent(path.join(sd, 'stakeholders.jsonl'), b.remove ? { kind: 'remove', initiative: b.initiative, name }
|
|
169
|
+
: { kind: 'add', initiative: b.initiative, name, role: str(b.role, 80), note: str(b.note, 200) }, now);
|
|
170
|
+
ctx.json(res, { ok: true });
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
return bad('no such route', 404);
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
@@ -56,10 +56,12 @@ module.exports = {
|
|
|
56
56
|
const ws = pick ? pick.ws : wantWs;
|
|
57
57
|
const q = qs({ ws });
|
|
58
58
|
const rp = await via(reports, '/api/report' + q, req, ctx);
|
|
59
|
-
let outcomes;
|
|
59
|
+
let outcomes, goalMeta = {};
|
|
60
60
|
try {
|
|
61
61
|
const today = new Date(), pad = (n) => String(n).padStart(2, '0'), day = today.getFullYear() + '-' + pad(today.getMonth() + 1) + '-' + pad(today.getDate());
|
|
62
|
-
|
|
62
|
+
const krs = require(repoScript('records/index.js')).list(recordsDirFor(ctx, ws), 'kr-metrics');
|
|
63
|
+
outcomes = krs.map((k) => strategy.outcomeOf(k, day));
|
|
64
|
+
goalMeta = Object.fromEntries(krs.map((k) => [k.rid, k])); // premium-agreed-design: the fields New goal keeps (type, direction, period, owner, …)
|
|
63
65
|
} catch (e) { return fail('the KR metric records could not be read: ' + ((e && e.message) || e)); }
|
|
64
66
|
const reportsOk = !!(rp.body && rp.body.ok !== false);
|
|
65
67
|
const missing = reportsOk ? [] : ['reports'];
|
|
@@ -79,10 +81,17 @@ module.exports = {
|
|
|
79
81
|
if (bl.status === 200 && bl.body && Array.isArray(bl.body.rows)) initiatives = bl.body.rows;
|
|
80
82
|
else if (bl.status !== 202) missing.push('initiatives');
|
|
81
83
|
}
|
|
84
|
+
// premium-agreed-design: the page's own records (charts, verdicts, tile targets) and the health budget registry (D59)
|
|
85
|
+
let ins = null, budgets = null;
|
|
86
|
+
if (pick) {
|
|
87
|
+
const root = require('path').resolve(ctx.getWs(pick.ws).root);
|
|
88
|
+
try { ins = require('./insights-records.js').read(root); } catch { missing.push('insights records'); }
|
|
89
|
+
try { budgets = require('./insights-goals.js').parseBudgets(require('fs').readFileSync(require('path').join(root, 'planning', 'okrs', 'health-budgets.md'), 'utf8')); } catch { budgets = null; }
|
|
90
|
+
}
|
|
82
91
|
const model = Insights.build({
|
|
83
92
|
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 })),
|
|
84
93
|
outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
|
|
85
|
-
setups: setupsOk ? su.body : null, pinned, leads, archived, initiatives,
|
|
94
|
+
setups: setupsOk ? su.body : null, pinned, leads, archived, initiatives, goalMeta, ins, budgets,
|
|
86
95
|
});
|
|
87
96
|
ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
|
|
88
97
|
return true;
|