create-pmos 0.396.0 → 0.398.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/scripts/nine-stages.js +49 -20
  6. package/payload/state/discoveries.md +1 -1
  7. package/payload/state/log.md +1 -1
  8. package/workspace/briefing-premium-adddoc-test.js +103 -74
  9. package/workspace/briefing-premium-board-test.js +316 -154
  10. package/workspace/briefing-premium-calendar-2-test.js +135 -195
  11. package/workspace/briefing-premium-calendar-3-test.js +143 -413
  12. package/workspace/briefing-premium-calendar-test.js +86 -185
  13. package/workspace/briefing-premium-doc-edit-test.js +95 -83
  14. package/workspace/briefing-premium-initiative-test.js +166 -294
  15. package/workspace/briefing-premium-insights-test.js +351 -214
  16. package/workspace/briefing-premium-metrics-test.js +53 -118
  17. package/workspace/briefing-premium-products-test.js +40 -27
  18. package/workspace/briefing-premium-sources-test.js +91 -52
  19. package/workspace/briefing-premium-test.js +150 -633
  20. package/workspace/briefing-premium-work-test.js +88 -269
  21. package/workspace/changelog.json +24 -0
  22. package/workspace/fixtures/board-premium-facts.js +2 -1
  23. package/workspace/fixtures/board-premium-jira.js +28 -0
  24. package/workspace/fixtures/board-premium-trail.js +32 -0
  25. package/workspace/fixtures/initiative-premium-facts.js +2 -1
  26. package/workspace/fixtures/initiatives-api/list.json +30 -42
  27. package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
  28. package/workspace/fixtures/initiatives-api/sheet.json +10 -14
  29. package/workspace/fixtures/insights-premium-facts.js +11 -2
  30. package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
  31. package/workspace/guide/briefing-premium.md +3 -1
  32. package/workspace/guide/home.md +47 -0
  33. package/workspace/guide/index.md +2 -0
  34. package/workspace/guide/lifecycle.md +51 -0
  35. package/workspace/home-shot.js +38 -0
  36. package/workspace/lib/agent-roles.js +71 -0
  37. package/workspace/lib/board-premium.js +160 -3
  38. package/workspace/lib/board-trail.js +223 -0
  39. package/workspace/lib/engine/boards.js +15 -14
  40. package/workspace/lib/engine/nine-stages.js +49 -20
  41. package/workspace/lib/engine/signals/detectors.js +13 -11
  42. package/workspace/lib/home-work-item.js +58 -0
  43. package/workspace/lib/insights-goals.js +196 -0
  44. package/workspace/lib/insights-premium.js +126 -1
  45. package/workspace/lib/insights-records.js +101 -0
  46. package/workspace/lib/jira-tickets.js +1 -1
  47. package/workspace/lib/route-modules.js +4 -0
  48. package/workspace/lib/routes-board-premium.js +3 -2
  49. package/workspace/lib/routes-board-trail.js +33 -0
  50. package/workspace/lib/routes-home-desk.js +176 -0
  51. package/workspace/lib/routes-initiatives.js +1 -1
  52. package/workspace/lib/routes-insights-premium.js +19 -3
  53. package/workspace/lib/routes-insights-records.js +129 -0
  54. package/workspace/lib/routes-notes.js +1 -0
  55. package/workspace/lib/routes-viewer.js +108 -0
  56. package/workspace/lib/transcript-steps.js +123 -0
  57. package/workspace/lib/vendor/scripts/nine-stages.js +49 -20
  58. package/workspace/lib/viewer-meeting.js +205 -0
  59. package/workspace/lib/viewer-report.js +89 -0
  60. package/workspace/package-lock.json +2 -2
  61. package/workspace/package.json +1 -1
  62. package/workspace/premium-agreed-viewer-shots.js +76 -0
  63. package/workspace/premium-board-actions-test.js +85 -73
  64. package/workspace/premium-briefing-depth-test.js +66 -53
  65. package/workspace/premium-chat-attach-test.js +54 -63
  66. package/workspace/premium-chat-chart-tab-test.js +35 -36
  67. package/workspace/premium-chat-context-test.js +22 -19
  68. package/workspace/premium-chat-goal-view-test.js +28 -26
  69. package/workspace/premium-chat-notes-test.js +29 -33
  70. package/workspace/premium-chat-report-tab-test.js +35 -25
  71. package/workspace/premium-chat-term-test.js +16 -14
  72. package/workspace/premium-chat-viewer-test.js +60 -53
  73. package/workspace/premium-core-doc-issue-test.js +50 -41
  74. package/workspace/premium-html-viewer-test.js +17 -18
  75. package/workspace/premium-phone-card-test.js +8 -2
  76. package/workspace/premium-phone-room-test.js +42 -31
  77. package/workspace/premium-report-read-test.js +115 -197
  78. package/workspace/premium-viewer-download-test.js +19 -22
  79. package/workspace/premium-viewer-flicker-test.js +11 -16
  80. package/workspace/premium-viewer-share-test.js +6 -9
  81. package/workspace/premium-viewer-test.js +41 -60
  82. package/workspace/premium-vw-backlog-test.js +53 -31
  83. package/workspace/premium-vw-cal-test.js +82 -123
  84. package/workspace/premium-vw-copy-test.js +17 -33
  85. package/workspace/premium-vw-doc-test.js +12 -11
  86. package/workspace/premium-vw-item-test.js +50 -48
  87. package/workspace/premium-vw-jira-test.js +55 -26
  88. package/workspace/premium-vw-meet-test.js +118 -187
  89. package/workspace/premium-vw-notes-test.js +85 -107
  90. package/workspace/premium-vw-rec-test.js +72 -193
  91. package/workspace/premium-vw-slides-test.js +46 -50
  92. package/workspace/premium-welcome-test.js +3 -2
  93. package/workspace/premium-work-depth-test.js +63 -51
  94. package/workspace/public/pm/bd-acts.js +305 -0
  95. package/workspace/public/pm/bd-span.js +224 -0
  96. package/workspace/public/pm/bd-stages.js +47 -0
  97. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  98. package/workspace/public/pm/c3-md.js +3 -395
  99. package/workspace/public/pm/c3-phone-detail.js +1 -1
  100. package/workspace/public/pm/c3-phone-model.js +3 -68
  101. package/workspace/public/pm/chat-term.js +3 -3
  102. package/workspace/public/pm/cozy-board.css +640 -0
  103. package/workspace/public/pm/cozy-home.css +580 -0
  104. package/workspace/public/pm/cozy-home.js +172 -0
  105. package/workspace/public/pm/cozy-initiative.css +138 -0
  106. package/workspace/public/pm/cozy-insights.css +421 -0
  107. package/workspace/public/pm/cozy-md.js +396 -0
  108. package/workspace/public/pm/cozy-nav.js +65 -0
  109. package/workspace/public/pm/cozy-placeholder.js +26 -0
  110. package/workspace/public/pm/cozy-viewer.css +143 -0
  111. package/workspace/public/pm/cozy-viewer.js +144 -0
  112. package/workspace/public/pm/cozy-vw.css +485 -0
  113. package/workspace/public/pm/cozy.css +254 -0
  114. package/workspace/public/pm/home-adddoc.js +48 -0
  115. package/workspace/public/pm/home-app.js +905 -0
  116. package/workspace/public/pm/home-around.js +515 -0
  117. package/workspace/public/pm/home-chat.js +459 -0
  118. package/workspace/public/pm/home-data.js +312 -0
  119. package/workspace/public/pm/home-draft.js +68 -0
  120. package/workspace/public/pm/home-more.js +249 -0
  121. package/workspace/public/pm/home-phone-card.js +109 -0
  122. package/workspace/public/pm/home-work.js +519 -0
  123. package/workspace/public/pm/lifecycle-lens-model.js +45 -27
  124. package/workspace/public/pm/lifecycle-lens.js +22 -11
  125. package/workspace/public/pm/phone-moment.js +69 -0
  126. package/workspace/public/pm/pm-work-view.js +1 -1
  127. package/workspace/public/pm/premium-attach.js +4 -0
  128. package/workspace/public/pm/premium-board.js +544 -253
  129. package/workspace/public/pm/premium-brief.js +1 -1
  130. package/workspace/public/pm/premium-chart-tab.js +110 -62
  131. package/workspace/public/pm/premium-chat.js +17 -10
  132. package/workspace/public/pm/premium-deck.js +3 -3
  133. package/workspace/public/pm/premium-first.js +25 -21
  134. package/workspace/public/pm/premium-initiative-head.js +138 -0
  135. package/workspace/public/pm/premium-initiative.js +28 -4
  136. package/workspace/public/pm/premium-insights.js +950 -440
  137. package/workspace/public/pm/premium-meeting.js +61 -549
  138. package/workspace/public/pm/premium-notes.js +1 -1
  139. package/workspace/public/pm/premium-report-frame.css +20 -0
  140. package/workspace/public/pm/premium-report-read.js +509 -480
  141. package/workspace/public/pm/premium-report-tab.js +87 -63
  142. package/workspace/public/pm/premium-shell.js +107 -124
  143. package/workspace/public/pm/premium-viewer.js +27 -1
  144. package/workspace/public/pm/premium-vw-cal.js +187 -48
  145. package/workspace/public/pm/premium-vw-doc.css +6 -0
  146. package/workspace/public/pm/premium-vw-doc.js +40 -2
  147. package/workspace/public/pm/premium-vw-file.js +2 -2
  148. package/workspace/public/pm/premium-vw-jira-model.js +22 -5
  149. package/workspace/public/pm/premium-vw-jira.css +11 -0
  150. package/workspace/public/pm/premium-vw-jira.js +11 -4
  151. package/workspace/public/pm/premium-vw-meet.js +6 -83
  152. package/workspace/public/pm/premium-vw-mtg.js +731 -0
  153. package/workspace/public/pm/premium-vw-notes.js +56 -69
  154. package/workspace/public/pm/premium-vw-open.js +35 -0
  155. package/workspace/public/pm/premium-vw-page.js +16 -0
  156. package/workspace/public/pm/premium-vw-rec.js +11 -215
  157. package/workspace/public/pm/premium-vw-slides.css +5 -0
  158. package/workspace/public/pm/premium-vw-slides.js +44 -8
  159. package/workspace/public/pm/term-view.js +22 -0
  160. package/workspace/public/premium-board.html +57 -64
  161. package/workspace/public/premium-chat.html +7 -33
  162. package/workspace/public/premium-initiative.html +8 -41
  163. package/workspace/public/premium-insights.html +63 -62
  164. package/workspace/public/premium-viewer.html +20 -0
  165. package/workspace/public/premium-work.html +6 -72
  166. package/workspace/public/premium.html +21 -66
  167. package/workspace/public/vendor/nunito-var.woff2 +0 -0
  168. package/workspace/server.js +25 -3
  169. package/workspace/test-files.json +1 -0
  170. package/workspace/test-lists/home-libs.json +9 -0
  171. package/workspace/test-lists/premium-agreed-viewer.json +9 -0
  172. package/workspace/test-lists/premium-report-read.json +1 -1
  173. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  174. package/workspace/test-lists/premium-vw-notes.json +1 -1
  175. package/workspace/third-party/README.md +1 -0
  176. package/workspace/public/pm/premium-work.js +0 -719
  177. package/workspace/public/pm/premium.js +0 -1133
@@ -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)
@@ -66,7 +66,7 @@ module.exports = {
66
66
  const missing = [];
67
67
  // the late and at-risk initiatives first (the board's own `risk` view, late before at risk), then its `now` view, each initiative once
68
68
  const listOf = (a, n) => { const seen = new Set(), out = []; const rank = (r) => (r.status === 'late' ? 0 : 1); for (const r of [...((a && a.rows) || [])].sort((x, y) => rank(x) - rank(y))) { if (!seen.has(r.id)) { seen.add(r.id); out.push(r); } } for (const r of (n && n.rows) || []) if (!seen.has(r.id)) { seen.add(r.id); out.push(r); } return out.slice(0, 100); };
69
- const [risk, now, cols, spr, docs, held, can, arc, asks] = await Promise.all([
69
+ const [risk, now, cols, spr, docs, held, can, arc, asks, its] = await Promise.all([
70
70
  via(boards, '/api/boards/backlog' + q + '&view=risk&limit=100', req, ctx),
71
71
  via(boards, '/api/boards/backlog' + q + '&view=now&limit=100', req, ctx),
72
72
  via(boards, '/api/boards/columns' + q, req, ctx),
@@ -76,6 +76,7 @@ module.exports = {
76
76
  via(boards, '/api/boards/backlog' + q + '&view=all&status=cancelled&limit=100', req, ctx),
77
77
  via(boards, '/api/boards/backlog' + q + '&archived=1&limit=100', req, ctx),
78
78
  via(boards, '/api/boards/asks' + q, req, ctx),
79
+ via(boards, '/api/boards/items' + q, req, ctx), // the Jira tickets of each initiative, for the stage track (premium-agreed-design B1)
79
80
  ]);
80
81
  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; };
81
82
  const rk = ok(risk, 'initiatives'), nw = ok(now, 'initiatives'), c = ok(cols, 'stages'), s = ok(spr, 'sprints'), d = ok(docs, 'core documents');
@@ -87,7 +88,7 @@ module.exports = {
87
88
  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 })),
88
89
  board: head.body.board, counts: head.body.counts, nextRelease: head.body.nextRelease || null, pastReleases: head.body.pastReleases || [],
89
90
  rows: listOf(rk, nw), columns: c ? c.columns : [], sprints: s || { source: 'none', sprints: [] }, docs: d, custom,
90
- held: hd ? hd.rows : [], cancelled: cn ? cn.rows : [], archived: ar ? ar.rows : [], asks: ak ? ak.asks || [] : null,
91
+ items: its && its.body && its.body.ok !== false && Array.isArray(its.body.items) ? its.body.items : [], held: hd ? hd.rows : [], cancelled: cn ? cn.rows : [], archived: ar ? ar.rows : [], asks: ak ? ak.asks || [] : null,
91
92
  });
92
93
  // a press re-derives the rows in the background; while the answer is stale the page asks again (initiative premium-board-actions)
93
94
  let stale = false;
@@ -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
+
@@ -180,7 +180,7 @@ function rowOf(F, rec) {
180
180
  progress: { done: pr.done, total: pr.total, label: pr.label },
181
181
  next_due: nextDue(F, id),
182
182
  last_activity: rec.last_activity || null,
183
- // The nine stage names over the engine's rung (scripts/nine-stages.js); on every row so Roadmap, List and sheet share one key set.
183
+ // The eight lifecycle steps (six stages, two milestones) over the engine's rung (scripts/nine-stages.js); on every row so Roadmap, List and sheet share one key set.
184
184
  nine_stages: nineStages(rec.lane, { stage: rec.stage, steps: Array.isArray(rec.steps) ? rec.steps : [] }),
185
185
  };
186
186
  }
@@ -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
- outcomes = require(repoScript('records/index.js')).list(recordsDirFor(ctx, ws), 'kr-metrics').map((k) => strategy.outcomeOf(k, day));
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'];
@@ -72,10 +74,24 @@ module.exports = {
72
74
  const setupsOk = su.status === 200 && !!su.body && Array.isArray(su.body.setups);
73
75
  if (!setupsOk) missing.push('report setups');
74
76
  const leads = reportsOk ? leadsOf(ctx, ws, rp.body.reports || []) : {};
77
+ // premium-agreed-design (G1, G2): the board's initiatives, so a goal can name what moves it and Outcomes can list shipped work. Read-only.
78
+ let initiatives = null;
79
+ if (pick && pick.id) {
80
+ const bl = await via(boards, '/api/boards/backlog' + qs({ ws: pick.ws, board: pick.id }) + '&view=all&limit=200', req, ctx).catch(() => ({ status: 500, body: null }));
81
+ if (bl.status === 200 && bl.body && Array.isArray(bl.body.rows)) initiatives = bl.body.rows;
82
+ else if (bl.status !== 202) missing.push('initiatives');
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
+ }
75
91
  const model = Insights.build({
76
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 })),
77
93
  outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
78
- setups: setupsOk ? su.body : null, pinned, leads, archived,
94
+ setups: setupsOk ? su.body : null, pinned, leads, archived, initiatives, goalMeta, ins, budgets,
79
95
  });
80
96
  ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
81
97
  return true;
@@ -0,0 +1,129 @@
1
+ 'use strict';
2
+ /* routes-insights-records.js — the presses of the premium Insights page that the Agreed design adds (initiative premium-agreed-design G1, G2).
3
+ *
4
+ * POST /api/insights-records/goal { ws, name, type, direction, baseline, target, due, period_kind, period_label, objective, source, owner, guardrail, steps, limit, always_on }
5
+ * → { ok, rid } one KR metric record (planning/records/kr-metrics.jsonl, through scripts/records); lib/insights-goals.js goalFields says what is kept
6
+ * POST /api/insights-records/steps { ws, rid, done: [bool] } → { ok } a Done-or-not goal's steps ticked: one edit of its steps and one reading (steps done)
7
+ * POST /api/insights-records/dashboard { ws, board, id?, name, purpose, charts: [{ goal, form }], range, pin }
8
+ * → { ok, dashboard } the dashboard (lib/premium-dashboards.js save), one chart line per goal and, with pin, a pin line
9
+ * POST /api/insights-records/chart { ws, board, dash, goal, form, range, compare, target, forecast, note, add } → { ok }
10
+ * one chart line (lib/insights-records.js); with add, the goal is first added to the dashboard
11
+ * POST /api/insights-records/describe { ws, text } → { ok, name, question, goals, range, said } reads the goals; writes nothing
12
+ * POST /api/insights-records/verdict { ws, board, ini, verdict, learned, goal } → { ok, verdict } one verdict line; the Board is not changed
13
+ * POST /api/insights-records/target { ws, key: late | scope, target } → { ok, targets }
14
+ * GET /api/insights-records/export?ws=&board= → text/csv of the goals the page shows
15
+ *
16
+ * WHO WRITES. As routes-premium-dashboards.js: an agent session header is refused (403), and pm-guard requirePagePress checks the launch nonce and the
17
+ * page's origin. Describe and Export write nothing. */
18
+ const guard = require('./pm-guard.js');
19
+ const IG = require('./insights-goals.js');
20
+ const IR = require('./insights-records.js');
21
+ const PD = require('./premium-dashboards.js');
22
+ const dashRoutes = require('./routes-premium-dashboards.js');
23
+ const { repoScript } = require('./repo-script.js');
24
+ const { recordsDirFor } = require('./records-dir.js');
25
+
26
+ const text = (v) => (typeof v === 'string' ? v : '');
27
+ const bad = (status, error) => ({ status, body: { ok: false, error } });
28
+ const today = () => new Date().toISOString().slice(0, 10);
29
+ const records = () => require(repoScript('records/index.js'));
30
+ const UI = () => require(repoScript('trust/ledger.js')).actorFrom({ ui: true });
31
+ const krList = (ctx, ws) => records().list(recordsDirFor(ctx, ws), 'kr-metrics');
32
+
33
+ /** The Insights model, through the page's own read, so Export says what the page shows. */
34
+ async function modelOf(req, ctx, ws, board) {
35
+ let out = null;
36
+ const c = Object.assign({}, ctx, { json: (res, obj) => { out = obj; } });
37
+ const u = new URL('http://local/api/insights-premium?' + new URLSearchParams(Object.entries({ ws, board }).filter(([, v]) => v)).toString());
38
+ await require('./routes-insights-premium.js').handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, u, c);
39
+ return out && out.ok ? out.model : null;
40
+ }
41
+
42
+ async function handle(req, res, url, ctx) {
43
+ const send = (r) => { ctx.json(res, r.body, r.status); return true; };
44
+ const what = url.pathname.replace(/^\/api\/insights-records\/?/, '');
45
+ if (what === 'export') {
46
+ if (req.method !== 'GET') return send(bad(405, 'GET only'));
47
+ const m = await modelOf(req, ctx, url.searchParams.get('ws'), url.searchParams.get('board'));
48
+ if (!m) return send(bad(500, 'The goals could not be read, so there is nothing to export.'));
49
+ res.writeHead(200, { 'Content-Type': 'text/csv; charset=utf-8', 'Content-Disposition': 'attachment; filename="insights-goals.csv"', 'Cache-Control': 'no-store' });
50
+ res.end(IG.exportCsv(m.goals || []));
51
+ return true;
52
+ }
53
+ if (!['goal', 'steps', 'dashboard', 'chart', 'describe', 'verdict', 'target'].includes(what)) return send(bad(404, 'no such insights-records route'));
54
+ if (req.method !== 'POST') return send(bad(405, 'POST only'));
55
+ const read = await ctx.readJson(req);
56
+ if (!read.ok) return send(bad(400, 'the body is not JSON'));
57
+ const body = read.body || {};
58
+ if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change Insights. Only a press on the page does'));
59
+ const g = guard.requirePagePress(req, body);
60
+ if (!g.ok) return send(bad(g.status, g.error));
61
+ const w = dashRoutes.wsOf(ctx, text(body.ws));
62
+ if (!w) return send(bad(404, 'no such workspace'));
63
+ const now = Date.now();
64
+
65
+ if (what === 'describe') {
66
+ let list;
67
+ try { list = krList(ctx, w.id).map((k) => ({ id: k.rid, title: k.metric, pillar: k.pillar || '' })); } catch { return send(bad(503, 'The goals could not be read, so nothing is filled in.')); }
68
+ const d = IG.describe(body.text, list);
69
+ return send(d.ok ? { status: 200, body: d } : bad(400, d.error));
70
+ }
71
+ if (what === 'goal') {
72
+ const f = IG.goalFields(body, { today: today() });
73
+ if (!f.ok) return send(bad(400, f.error));
74
+ const r = records().add(recordsDirFor(ctx, w.id), 'kr-metrics', f.fields, UI(), 'New goal from Insights');
75
+ return send(r.ok ? { status: 200, body: { ok: true, rid: r.rid, fields: f.fields } } : bad(400, r.reasons.join('; ')));
76
+ }
77
+ if (what === 'steps') {
78
+ let cur;
79
+ try { cur = krList(ctx, w.id).find((k) => k.rid === text(body.rid)); } catch { return send(bad(503, 'The goals could not be read.')); }
80
+ if (!cur || !Array.isArray(cur.steps) || !cur.steps.length) return send(bad(404, 'That goal has no steps.'));
81
+ if (!Array.isArray(body.done) || body.done.length !== cur.steps.length) return send(bad(400, 'Say which of its steps are done.'));
82
+ const steps = cur.steps.map((s, i) => ({ text: s.text, done: body.done[i] === true })), n = steps.filter((s) => s.done).length, root = recordsDirFor(ctx, w.id);
83
+ const e = records().edit(root, 'kr-metrics', cur.rid, { steps }, UI(), 'Steps ticked on Insights');
84
+ if (!e.ok) return send(bad(400, e.reasons.join('; ')));
85
+ const r = records().addReading(root, cur.rid, { at: today(), value: n }, UI(), 'Steps done, from Insights');
86
+ return send(r.ok ? { status: 200, body: { ok: true, done: n } } : bad(400, r.reasons.join('; ')));
87
+ }
88
+ if (what === 'target') {
89
+ const r = IR.append(w.root, 'target', body, g.actor, { now });
90
+ return send(r.ok ? { status: 200, body: { ok: true, targets: IR.read(w.root).targets } } : bad(r.status, r.error));
91
+ }
92
+ const ids = dashRoutes.boardIds(ctx, w);
93
+ if (!ids) return send(bad(503, 'The boards could not be read. Try again in a moment.'));
94
+ if (!ids.has(text(body.board))) return send(bad(404, 'no such board in this workspace'));
95
+ if (what === 'verdict') {
96
+ const r = IR.append(w.root, 'verdict', body, g.actor, { now });
97
+ return send(r.ok ? { status: 200, body: { ok: true, verdict: r.line } } : bad(r.status, r.error));
98
+ }
99
+ const ks = dashRoutes.krIds(ctx, w.id);
100
+ if (!ks) return send(bad(503, 'The KR metric records could not be read, so the charts cannot be checked.'));
101
+ if (what === 'chart') {
102
+ const c = IR.checkChart(body);
103
+ if (!c.ok) return send(bad(c.status, c.error));
104
+ if (!ks.has(c.value.goal)) return send(bad(400, 'No KR metric record is called “' + c.value.goal + '” in this workspace.'));
105
+ const D = PD.list(w.root, c.value.board).find((d) => d.id === c.value.dash);
106
+ if (!D) return send(bad(404, 'That dashboard is not on this board.'));
107
+ if (!D.charts.includes(c.value.goal)) {
108
+ if (body.add !== true) return send(bad(400, 'That goal is not on ' + D.name + '.'));
109
+ const s = PD.save(w.root, { id: D.id, board: D.board, name: D.name, purpose: D.purpose, charts: D.charts.concat(c.value.goal), main: D.main }, g.actor, { now, known: { charts: ks } });
110
+ if (!s.ok) return send(bad(s.status, s.error));
111
+ }
112
+ const r = IR.append(w.root, 'chart', c.value, g.actor, { now });
113
+ return send(r.ok ? { status: 200, body: { ok: true, chart: r.line } } : bad(r.status, r.error));
114
+ }
115
+ // dashboard: the dashboard itself, then each chart's form and the range, then the pin
116
+ const list = Array.isArray(body.charts) ? body.charts : [];
117
+ const goals = list.map((x) => (typeof x === 'string' ? x : x && x.goal));
118
+ const range = IR.RANGES.includes(body.range) ? body.range : 'Quarter';
119
+ for (const x of list) { const form = typeof x === 'string' ? 'Line' : x && x.form; if (!IR.FORMS.includes(form || 'Line')) return send(bad(400, 'Pick a form for each chart: ' + IR.FORMS.join(', ') + '.')); }
120
+ const s = PD.save(w.root, { id: body.id, board: body.board, name: body.name, purpose: body.purpose, charts: goals, main: false }, g.actor, { now, known: { charts: ks } });
121
+ if (!s.ok) return send(bad(s.status, s.error));
122
+ const D = s.dashboard;
123
+ list.forEach((x, i) => { IR.append(w.root, 'chart', { board: D.board, dash: D.id, goal: goals[i], form: (x && x.form) || 'Line', range, compare: '', target: true, forecast: false, note: '' }, g.actor, { now }); });
124
+ let pinned = null;
125
+ if (body.pin === true) { const p = PD.pin(w.root, { board: D.board, id: D.id }, g.actor, { now }); if (p.ok) pinned = p.pinned; }
126
+ return send({ status: 200, body: { ok: true, id: D.id, dashboard: D, pinned } });
127
+ }
128
+
129
+ module.exports = { prefixes: ['/api/insights-records'], handle };
@@ -933,6 +933,7 @@ async function handle(req, res, url, ctx) {
933
933
  if (note.note.private) return done({ ok: false, status: 409, error: 'this note is marked private, so nothing more is kept in it' });
934
934
  if (!note.note.recorded_from) return done({ ok: false, status: 409, error: 'press Listen first' });
935
935
  if (!notesScreen.getOn(dir)) return done({ ok: false, status: 409, error: 'Capture the shared screen is switched off in Settings' });
936
+ if (require('./viewer-meeting.js').shotsPaused(dir, id)) return done({ ok: false, status: 423, error: 'screen shots are paused for this note' }); // the Viewer's Pause shots: 423, not 409, so the page's capture keeps running and resumes with Resume shots
936
937
  const own = notesCapture.owns(dir, id, { token: body.cap });
937
938
  if (!own.ok) return done(own);
938
939
  if (typeof body.t !== 'number' || !Number.isFinite(body.t) || body.t < 0) return done({ ok: false, status: 400, error: 'a screenshot needs its meeting time' });