create-pmos 0.397.0 → 0.399.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) 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/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/briefing-premium-adddoc-test.js +105 -52
  8. package/workspace/briefing-premium-board-test.js +284 -128
  9. package/workspace/briefing-premium-calendar-2-test.js +135 -198
  10. package/workspace/briefing-premium-calendar-3-test.js +143 -418
  11. package/workspace/briefing-premium-calendar-test.js +85 -196
  12. package/workspace/briefing-premium-doc-edit-test.js +99 -83
  13. package/workspace/briefing-premium-initiative-test.js +175 -290
  14. package/workspace/briefing-premium-insights-test.js +414 -219
  15. package/workspace/briefing-premium-metrics-test.js +55 -97
  16. package/workspace/briefing-premium-products-test.js +44 -28
  17. package/workspace/briefing-premium-sources-test.js +70 -49
  18. package/workspace/briefing-premium-test.js +155 -648
  19. package/workspace/briefing-premium-work-test.js +88 -283
  20. package/workspace/changelog.json +24 -0
  21. package/workspace/ev-everywhere-test.js +210 -0
  22. package/workspace/fixtures/board-premium-trail.js +32 -0
  23. package/workspace/fixtures/premium-viewer-fixtures.js +187 -0
  24. package/workspace/guide/briefing-premium.md +3 -1
  25. package/workspace/guide/home.md +68 -0
  26. package/workspace/guide/index.md +1 -0
  27. package/workspace/lib/agent-roles.js +71 -0
  28. package/workspace/lib/board-grill.js +63 -0
  29. package/workspace/lib/board-premium.js +121 -24
  30. package/workspace/lib/board-trail.js +223 -0
  31. package/workspace/lib/home-work-item.js +58 -0
  32. package/workspace/lib/initiative-layout.js +77 -0
  33. package/workspace/lib/insights-goals.js +196 -0
  34. package/workspace/lib/insights-premium.js +64 -15
  35. package/workspace/lib/insights-records.js +115 -0
  36. package/workspace/lib/jira-tickets.js +1 -1
  37. package/workspace/lib/meeting-points.js +52 -0
  38. package/workspace/lib/news-for-you.js +88 -0
  39. package/workspace/lib/notes-series.js +29 -6
  40. package/workspace/lib/report-confirm.js +48 -0
  41. package/workspace/lib/route-modules.js +12 -0
  42. package/workspace/lib/routes-board-docs.js +46 -0
  43. package/workspace/lib/routes-board-grill.js +90 -0
  44. package/workspace/lib/routes-board-trail.js +33 -0
  45. package/workspace/lib/routes-home-desk.js +176 -0
  46. package/workspace/lib/routes-home-review.js +108 -0
  47. package/workspace/lib/routes-initiative-layout.js +57 -0
  48. package/workspace/lib/routes-insights-premium.js +16 -4
  49. package/workspace/lib/routes-insights-records.js +133 -0
  50. package/workspace/lib/routes-meeting-points.js +37 -0
  51. package/workspace/lib/routes-news.js +57 -0
  52. package/workspace/lib/routes-notes.js +3 -1
  53. package/workspace/lib/routes-report-confirm.js +31 -0
  54. package/workspace/lib/routes-search.js +38 -0
  55. package/workspace/lib/routes-viewer.js +108 -0
  56. package/workspace/lib/search-index.js +176 -0
  57. package/workspace/lib/transcript-steps.js +123 -0
  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-board-actions-test.js +128 -82
  63. package/workspace/premium-briefing-depth-test.js +104 -90
  64. package/workspace/premium-chat-attach-test.js +54 -63
  65. package/workspace/premium-chat-chart-tab-test.js +37 -37
  66. package/workspace/premium-chat-context-test.js +19 -18
  67. package/workspace/premium-chat-goal-view-test.js +23 -23
  68. package/workspace/premium-chat-notes-test.js +26 -31
  69. package/workspace/premium-chat-report-tab-test.js +46 -28
  70. package/workspace/premium-chat-term-test.js +16 -16
  71. package/workspace/premium-chat-viewer-test.js +60 -59
  72. package/workspace/premium-core-doc-issue-test.js +52 -43
  73. package/workspace/premium-html-viewer-test.js +14 -17
  74. package/workspace/premium-phone-card-test.js +10 -3
  75. package/workspace/premium-phone-room-test.js +41 -35
  76. package/workspace/premium-report-read-test.js +152 -197
  77. package/workspace/premium-viewer-download-test.js +19 -22
  78. package/workspace/premium-viewer-flicker-test.js +11 -16
  79. package/workspace/premium-viewer-share-test.js +6 -9
  80. package/workspace/premium-viewer-test.js +41 -60
  81. package/workspace/premium-vw-backlog-test.js +53 -33
  82. package/workspace/premium-vw-cal-test.js +97 -128
  83. package/workspace/premium-vw-copy-test.js +17 -33
  84. package/workspace/premium-vw-doc-test.js +17 -10
  85. package/workspace/premium-vw-item-test.js +50 -49
  86. package/workspace/premium-vw-jira-test.js +53 -27
  87. package/workspace/premium-vw-meet-test.js +115 -187
  88. package/workspace/premium-vw-notes-test.js +88 -109
  89. package/workspace/premium-vw-rec-test.js +71 -194
  90. package/workspace/premium-vw-slides-test.js +46 -50
  91. package/workspace/premium-welcome-test.js +3 -2
  92. package/workspace/premium-work-depth-test.js +61 -53
  93. package/workspace/public/pm/bd-acts.js +383 -0
  94. package/workspace/public/pm/bd-asks.js +261 -0
  95. package/workspace/public/pm/bd-pop.js +59 -0
  96. package/workspace/public/pm/bd-span.js +222 -82
  97. package/workspace/public/pm/bd-stages.js +25 -11
  98. package/workspace/public/pm/bd-views.js +169 -0
  99. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  100. package/workspace/public/pm/c3-md.js +3 -395
  101. package/workspace/public/pm/c3-phone-detail.js +1 -1
  102. package/workspace/public/pm/c3-phone-model.js +3 -68
  103. package/workspace/public/pm/chat-term.js +3 -3
  104. package/workspace/public/pm/cozy-board.css +798 -230
  105. package/workspace/public/pm/cozy-ev.css +228 -0
  106. package/workspace/public/pm/cozy-evmodel.js +106 -0
  107. package/workspace/public/pm/cozy-evui.js +47 -0
  108. package/workspace/public/pm/cozy-home.css +570 -142
  109. package/workspace/public/pm/cozy-home.js +5 -3
  110. package/workspace/public/pm/cozy-insights.css +437 -170
  111. package/workspace/public/pm/cozy-md.js +396 -0
  112. package/workspace/public/pm/cozy-nav.js +104 -29
  113. package/workspace/public/pm/cozy-news.js +140 -0
  114. package/workspace/public/pm/cozy-placeholder.js +26 -0
  115. package/workspace/public/pm/cozy-search.js +203 -0
  116. package/workspace/public/pm/cozy-settings.js +198 -0
  117. package/workspace/public/pm/cozy-sources.js +89 -0
  118. package/workspace/public/pm/cozy-today.css +217 -0
  119. package/workspace/public/pm/cozy-viewer.css +3 -3
  120. package/workspace/public/pm/cozy-viewer.js +145 -0
  121. package/workspace/public/pm/cozy-vw-mtg.css +350 -0
  122. package/workspace/public/pm/cozy-vw-rp.css +152 -0
  123. package/workspace/public/pm/cozy-vw.css +485 -0
  124. package/workspace/public/pm/cozy.css +83 -1
  125. package/workspace/public/pm/home-adddoc.js +48 -0
  126. package/workspace/public/pm/home-app.js +1179 -0
  127. package/workspace/public/pm/home-around.js +413 -0
  128. package/workspace/public/pm/home-chat.js +512 -0
  129. package/workspace/public/pm/home-data.js +312 -0
  130. package/workspace/public/pm/home-dictate.js +54 -0
  131. package/workspace/public/pm/home-draft.js +68 -0
  132. package/workspace/public/pm/home-ini-model.js +190 -0
  133. package/workspace/public/pm/home-ini.css +171 -0
  134. package/workspace/public/pm/home-ini.js +456 -0
  135. package/workspace/public/pm/home-list.js +276 -0
  136. package/workspace/public/pm/home-more.js +132 -0
  137. package/workspace/public/pm/home-phone-card.js +109 -0
  138. package/workspace/public/pm/home-review.js +104 -0
  139. package/workspace/public/pm/home-task.js +67 -0
  140. package/workspace/public/pm/home-today.js +144 -0
  141. package/workspace/public/pm/home-work.js +547 -0
  142. package/workspace/public/pm/phone-moment.js +69 -0
  143. package/workspace/public/pm/pm-work-view.js +1 -1
  144. package/workspace/public/pm/premium-attach.js +4 -0
  145. package/workspace/public/pm/premium-board.js +548 -395
  146. package/workspace/public/pm/premium-chart-tab.js +109 -62
  147. package/workspace/public/pm/premium-deck.js +3 -3
  148. package/workspace/public/pm/premium-first.js +23 -21
  149. package/workspace/public/pm/premium-insights.js +1102 -581
  150. package/workspace/public/pm/premium-meeting.js +61 -549
  151. package/workspace/public/pm/premium-mtg-present.js +138 -0
  152. package/workspace/public/pm/premium-mtg-replay.js +142 -0
  153. package/workspace/public/pm/premium-notes.js +1 -1
  154. package/workspace/public/pm/premium-report-frame.css +20 -0
  155. package/workspace/public/pm/premium-report-read.js +669 -476
  156. package/workspace/public/pm/premium-report-tab.js +116 -67
  157. package/workspace/public/pm/premium-shell.js +76 -123
  158. package/workspace/public/pm/premium-viewer.js +22 -1
  159. package/workspace/public/pm/premium-vw-cal.js +277 -48
  160. package/workspace/public/pm/premium-vw-doc.css +6 -0
  161. package/workspace/public/pm/premium-vw-doc.js +40 -2
  162. package/workspace/public/pm/premium-vw-file.js +2 -2
  163. package/workspace/public/pm/premium-vw-meet.js +6 -83
  164. package/workspace/public/pm/premium-vw-mtg.js +958 -0
  165. package/workspace/public/pm/premium-vw-notes.js +116 -68
  166. package/workspace/public/pm/premium-vw-open.js +35 -0
  167. package/workspace/public/pm/premium-vw-page.js +16 -0
  168. package/workspace/public/pm/premium-vw-rec.js +11 -218
  169. package/workspace/public/pm/premium-vw-slides.css +5 -0
  170. package/workspace/public/pm/premium-vw-slides.js +44 -8
  171. package/workspace/public/pm/rp-parts.js +269 -0
  172. package/workspace/public/pm/term-view.js +22 -0
  173. package/workspace/public/premium-board.html +29 -70
  174. package/workspace/public/premium-initiative.html +8 -48
  175. package/workspace/public/premium-insights.html +26 -64
  176. package/workspace/public/premium-viewer.html +20 -0
  177. package/workspace/public/premium.html +18 -107
  178. package/workspace/r/m1.png +0 -0
  179. package/workspace/r/m2.png +0 -0
  180. package/workspace/r/m3.png +0 -0
  181. package/workspace/r/nl.png +0 -0
  182. package/workspace/server.js +18 -3
  183. package/workspace/test-files.json +1 -0
  184. package/workspace/test-lists/home-libs.json +9 -0
  185. package/workspace/test-lists/initiative-layout.json +9 -0
  186. package/workspace/test-lists/premium-report-read.json +1 -1
  187. package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
  188. package/workspace/test-lists/premium-uncovered-reports.json +9 -0
  189. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  190. package/workspace/test-lists/premium-vw-notes.json +1 -1
  191. package/workspace/test-lists/uf-everywhere.json +15 -0
  192. package/workspace/test-lists/uf-home.json +9 -0
  193. package/workspace/test-lists/uncovered-board.json +9 -0
  194. package/workspace/public/pm/premium-work.js +0 -729
  195. package/workspace/public/pm/premium.js +0 -1146
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+ /* routes-home-review.js — the PM's weekly review on Home (initiative premium-uncovered-features, H1; canvas HmReview).
3
+ *
4
+ * GET /api/home-review?ws=<id>
5
+ * → { ok, week, steps: { [step]: { note, at } }, kept: { [initiative]: { how, at } }, last: { week, at, minutes } | null }
6
+ * POST /api/home-review/step { ws, week, step, note? } one of the four steps is done this week ("4 sorted · 1 kept")
7
+ * POST /api/home-review/keep { ws, week, initiative, how } an untouched initiative was looked at: kept going, or asked in chat
8
+ *
9
+ * The review has four steps: sort (what came in), wait (what the PM waits on), untouched (work with no change for 14 days or more) and
10
+ * pick (next week's three). A week is named by its Monday (YYYY-MM-DD). "last" is the newest earlier week with all four steps done, and how
11
+ * long it took from its first step to its last.
12
+ *
13
+ * FILE MODE ONLY, append-only JSONL (D64/D66): <state>/weekly-review.jsonl in the workspace's state folder (stateDirFor). Nothing is
14
+ * rewritten; the last line for a step or an initiative in a week wins when read back. Every POST is a page press (pm-guard
15
+ * requirePagePress): an agent session cannot write the review. Nothing here sends anything to anyone. */
16
+ const path = require('path');
17
+ const guard = require('./pm-guard.js');
18
+ const pmItems = require('./pm-items.js');
19
+
20
+ const STEPS = ['sort', 'wait', 'untouched', 'pick'];
21
+ const HOWS = ['kept', 'asked', 'held'];
22
+ const WEEK_RE = /^\d{4}-\d{2}-\d{2}$/;
23
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
24
+ const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
25
+ const pad = (n) => String(n).padStart(2, '0');
26
+
27
+ /** The Monday of the week that holds `now`, as YYYY-MM-DD in local time. */
28
+ function weekOf(now) {
29
+ const d = new Date(now); d.setHours(0, 0, 0, 0);
30
+ d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
31
+ return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
32
+ }
33
+ const fileOf = (sd) => path.join(sd, 'weekly-review.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
+ /** This week's review and the last full one before it. Pure over the lines. */
42
+ function foldReview(lines, week) {
43
+ const weeks = new Map();
44
+ const of = (w) => weeks.get(w) || weeks.set(w, { steps: {}, kept: {} }).get(w);
45
+ for (const l of lines) {
46
+ if (!l || !WEEK_RE.test(String(l.week || ''))) continue;
47
+ const W = of(l.week);
48
+ if (l.kind === 'step' && STEPS.includes(l.step)) W.steps[l.step] = { note: l.note || '', at: l.at };
49
+ if (l.kind === 'keep' && ID_RE.test(String(l.initiative || '')) && HOWS.includes(l.how)) W.kept[l.initiative] = { how: l.how, at: l.at };
50
+ }
51
+ const cur = weeks.get(week) || { steps: {}, kept: {} };
52
+ let last = null;
53
+ for (const [w, W] of weeks) {
54
+ if (w >= week || !STEPS.every((s) => W.steps[s])) continue;
55
+ const at = STEPS.map((s) => Date.parse(W.steps[s].at)).filter((x) => !Number.isNaN(x));
56
+ if (!last || w > last.week) last = { week: w, at: at.length ? new Date(Math.max(...at)).toISOString() : null, minutes: at.length ? Math.max(1, Math.round((Math.max(...at) - Math.min(...at)) / 60000)) : null };
57
+ }
58
+ return { week, steps: cur.steps, kept: cur.kept, last };
59
+ }
60
+
61
+ async function body(req, ctx, res) {
62
+ const got = await ctx.readJson(req);
63
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return null; }
64
+ const b = got.body || {};
65
+ const g = guard.requirePagePress(req, b);
66
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return null; }
67
+ return b;
68
+ }
69
+
70
+ module.exports = {
71
+ prefixes: ['/api/home-review'],
72
+ STEPS, HOWS, weekOf, foldReview,
73
+ handle: async (req, res, url, ctx) => {
74
+ const p = url.pathname;
75
+ if (p !== '/api/home-review' && !p.startsWith('/api/home-review/')) return false;
76
+ const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
77
+ const now = ctx.now ? ctx.now() : Date.now();
78
+ if (p === '/api/home-review') {
79
+ if (req.method !== 'GET') return bad('GET only', 405);
80
+ const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
81
+ const sd = w ? stateDir(ctx, w) : null;
82
+ const week = weekOf(now);
83
+ ctx.json(res, { ok: true, ws: w ? w.id : null, ...foldReview(sd ? read(fileOf(sd)) : [], week) });
84
+ return true;
85
+ }
86
+ if (p !== '/api/home-review/step' && p !== '/api/home-review/keep') return bad('no such route', 404);
87
+ if (req.method !== 'POST') return bad('POST only', 405);
88
+ const b = await body(req, ctx, res);
89
+ if (!b) return true;
90
+ const week = b.week == null || b.week === '' ? weekOf(now) : String(b.week);
91
+ if (!WEEK_RE.test(week)) return bad('week must be a date (YYYY-MM-DD)');
92
+ const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
93
+ if (!w) return bad('that workspace is not registered', 404);
94
+ const sd = stateDir(ctx, w);
95
+ if (!sd) return bad('this workspace has no state folder', 409);
96
+ const at = new Date(now);
97
+ if (p === '/api/home-review/step') {
98
+ if (!STEPS.includes(b.step)) return bad('step must be one of: ' + STEPS.join(', '));
99
+ pmItems.appendEvent(fileOf(sd), { kind: 'step', week, step: b.step, note: str(b.note, 200) }, at);
100
+ } else {
101
+ if (!ID_RE.test(String(b.initiative || ''))) return bad('initiative must name an initiative');
102
+ if (!HOWS.includes(b.how)) return bad('how must be one of: ' + HOWS.join(', '));
103
+ pmItems.appendEvent(fileOf(sd), { kind: 'keep', week, initiative: b.initiative, how: b.how }, at);
104
+ }
105
+ ctx.json(res, { ok: true, ...foldReview(read(fileOf(sd)), week) });
106
+ return true;
107
+ },
108
+ };
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+ /* routes-initiative-layout.js — the PM's layout choices for one initiative inside Home (initiative premium-uncovered-features, Initiative).
3
+ *
4
+ * GET /api/initiative-layout?ws=<id>&initiative=<id>
5
+ * → { ok, initiative, auto, held, by, names, of, stage, sets: [{ name, names }] }
6
+ * POST /api/initiative-layout { ws, kind, initiative?, ... } one press (lib/initiative-layout.js eventOf):
7
+ * auto { on } · hold { stage } · by { by } · groups { names } · rename { from, to } · place { task, group } · stage { task, stage }
8
+ * set { name, names } · unset { name }
9
+ * → the same answer as GET, after the line is written
10
+ *
11
+ * FILE MODE ONLY, append-only JSONL (D64/D66): <state>/initiative-layout.jsonl in the workspace's state folder (stateDirFor).
12
+ * Every POST is a page press (pm-guard requirePagePress): an agent session cannot write it. */
13
+ const path = require('path');
14
+ const guard = require('./pm-guard.js');
15
+ const pmItems = require('./pm-items.js');
16
+ const L = require('./initiative-layout.js');
17
+
18
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
19
+ function stateDir(ctx, w) {
20
+ let d = null;
21
+ try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create: true }) : null; } catch { d = null; }
22
+ return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
23
+ }
24
+ const fileOf = (sd) => path.join(sd, 'initiative-layout.jsonl');
25
+ const read = (f) => { try { return pmItems.readLines(f).filter(Boolean); } catch { return []; } };
26
+ const answer = (lines, ini) => ({ ok: true, initiative: ini || null, ...(ini ? L.fold(lines, ini) : {}), sets: L.foldSets(lines) });
27
+
28
+ module.exports = {
29
+ prefixes: ['/api/initiative-layout'],
30
+ handle: async (req, res, url, ctx) => {
31
+ if (url.pathname !== '/api/initiative-layout') { if (url.pathname.startsWith('/api/initiative-layout')) { ctx.json(res, { ok: false, error: 'no such route' }, 404); return true; } return false; }
32
+ const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
33
+ if (req.method === 'GET') {
34
+ const ini = url.searchParams.get('initiative') || '';
35
+ if (ini && !ID_RE.test(ini)) return bad('initiative must name an initiative');
36
+ const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
37
+ const sd = w ? stateDir(ctx, w) : null;
38
+ ctx.json(res, answer(sd ? read(fileOf(sd)) : [], ini));
39
+ return true;
40
+ }
41
+ if (req.method !== 'POST') return bad('GET or POST only', 405);
42
+ const got = await ctx.readJson(req);
43
+ if (!got.ok) return bad('invalid JSON body');
44
+ const b = got.body || {};
45
+ const g = guard.requirePagePress(req, b);
46
+ if (!g.ok) return bad(g.error, g.status);
47
+ const ev = L.eventOf(b);
48
+ if (!ev.ok) return bad(ev.error);
49
+ const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
50
+ if (!w) return bad('that workspace is not registered', 404);
51
+ const sd = stateDir(ctx, w);
52
+ if (!sd) return bad('this workspace has no state folder', 409);
53
+ pmItems.appendEvent(fileOf(sd), ev.event, new Date());
54
+ ctx.json(res, answer(read(fileOf(sd)), ev.event.initiative || (ID_RE.test(String(b.initiative || '')) ? b.initiative : '')));
55
+ return true;
56
+ },
57
+ };
@@ -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'];
@@ -79,10 +81,20 @@ 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
+ }
91
+ // premium-uncovered-features (IsMenus): the product picker says how many goals each product's workspace records; a workspace that cannot be read says none
92
+ const counts = new Map();
93
+ const goalsIn = (w) => { if (!counts.has(w)) { let n = null; try { n = w === ws ? outcomes.length : require(repoScript('records/index.js')).list(recordsDirFor(ctx, w), 'kr-metrics').length; } catch { n = null; } counts.set(w, n); } return counts.get(w) === null ? {} : { goals: counts.get(w) }; };
82
94
  const model = Insights.build({
83
- 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 })),
95
+ now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Insights' }, boards: all.map((x) => Object.assign({ ws: x.ws, id: x.id, name: x.name }, goalsIn(x.ws))),
84
96
  outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
85
- setups: setupsOk ? su.body : null, pinned, leads, archived, initiatives,
97
+ setups: setupsOk ? su.body : null, pinned, leads, archived, initiatives, goalMeta, ins, budgets,
86
98
  });
87
99
  ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
88
100
  return true;
@@ -0,0 +1,133 @@
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
+ * POST /api/insights-records/tile { ws, key, dir: at least | at most | none, from, chip } → { ok, tiles } how a Delivery trends target is
15
+ * read (premium-uncovered-features, IsTarget): its direction, the day it counts from and whether the Board chip shows it
16
+ * GET /api/insights-records/export?ws=&board= → text/csv of the goals the page shows
17
+ *
18
+ * WHO WRITES. As routes-premium-dashboards.js: an agent session header is refused (403), and pm-guard requirePagePress checks the launch nonce and the
19
+ * page's origin. Describe and Export write nothing. */
20
+ const guard = require('./pm-guard.js');
21
+ const IG = require('./insights-goals.js');
22
+ const IR = require('./insights-records.js');
23
+ const PD = require('./premium-dashboards.js');
24
+ const dashRoutes = require('./routes-premium-dashboards.js');
25
+ const { repoScript } = require('./repo-script.js');
26
+ const { recordsDirFor } = require('./records-dir.js');
27
+
28
+ const text = (v) => (typeof v === 'string' ? v : '');
29
+ const bad = (status, error) => ({ status, body: { ok: false, error } });
30
+ const today = () => new Date().toISOString().slice(0, 10);
31
+ const records = () => require(repoScript('records/index.js'));
32
+ const UI = () => require(repoScript('trust/ledger.js')).actorFrom({ ui: true });
33
+ const krList = (ctx, ws) => records().list(recordsDirFor(ctx, ws), 'kr-metrics');
34
+
35
+ /** The Insights model, through the page's own read, so Export says what the page shows. */
36
+ async function modelOf(req, ctx, ws, board) {
37
+ let out = null;
38
+ const c = Object.assign({}, ctx, { json: (res, obj) => { out = obj; } });
39
+ const u = new URL('http://local/api/insights-premium?' + new URLSearchParams(Object.entries({ ws, board }).filter(([, v]) => v)).toString());
40
+ await require('./routes-insights-premium.js').handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, u, c);
41
+ return out && out.ok ? out.model : null;
42
+ }
43
+
44
+ async function handle(req, res, url, ctx) {
45
+ const send = (r) => { ctx.json(res, r.body, r.status); return true; };
46
+ const what = url.pathname.replace(/^\/api\/insights-records\/?/, '');
47
+ if (what === 'export') {
48
+ if (req.method !== 'GET') return send(bad(405, 'GET only'));
49
+ const m = await modelOf(req, ctx, url.searchParams.get('ws'), url.searchParams.get('board'));
50
+ if (!m) return send(bad(500, 'The goals could not be read, so there is nothing to export.'));
51
+ res.writeHead(200, { 'Content-Type': 'text/csv; charset=utf-8', 'Content-Disposition': 'attachment; filename="insights-goals.csv"', 'Cache-Control': 'no-store' });
52
+ res.end(IG.exportCsv(m.goals || []));
53
+ return true;
54
+ }
55
+ if (!['goal', 'steps', 'dashboard', 'chart', 'describe', 'verdict', 'target', 'tile'].includes(what)) return send(bad(404, 'no such insights-records route'));
56
+ if (req.method !== 'POST') return send(bad(405, 'POST only'));
57
+ const read = await ctx.readJson(req);
58
+ if (!read.ok) return send(bad(400, 'the body is not JSON'));
59
+ const body = read.body || {};
60
+ 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'));
61
+ const g = guard.requirePagePress(req, body);
62
+ if (!g.ok) return send(bad(g.status, g.error));
63
+ const w = dashRoutes.wsOf(ctx, text(body.ws));
64
+ if (!w) return send(bad(404, 'no such workspace'));
65
+ const now = Date.now();
66
+
67
+ if (what === 'describe') {
68
+ let list;
69
+ 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.')); }
70
+ const d = IG.describe(body.text, list);
71
+ return send(d.ok ? { status: 200, body: d } : bad(400, d.error));
72
+ }
73
+ if (what === 'goal') {
74
+ const f = IG.goalFields(body, { today: today() });
75
+ if (!f.ok) return send(bad(400, f.error));
76
+ const r = records().add(recordsDirFor(ctx, w.id), 'kr-metrics', f.fields, UI(), 'New goal from Insights');
77
+ return send(r.ok ? { status: 200, body: { ok: true, rid: r.rid, fields: f.fields } } : bad(400, r.reasons.join('; ')));
78
+ }
79
+ if (what === 'steps') {
80
+ let cur;
81
+ try { cur = krList(ctx, w.id).find((k) => k.rid === text(body.rid)); } catch { return send(bad(503, 'The goals could not be read.')); }
82
+ if (!cur || !Array.isArray(cur.steps) || !cur.steps.length) return send(bad(404, 'That goal has no steps.'));
83
+ if (!Array.isArray(body.done) || body.done.length !== cur.steps.length) return send(bad(400, 'Say which of its steps are done.'));
84
+ 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);
85
+ const e = records().edit(root, 'kr-metrics', cur.rid, { steps }, UI(), 'Steps ticked on Insights');
86
+ if (!e.ok) return send(bad(400, e.reasons.join('; ')));
87
+ const r = records().addReading(root, cur.rid, { at: today(), value: n }, UI(), 'Steps done, from Insights');
88
+ return send(r.ok ? { status: 200, body: { ok: true, done: n } } : bad(400, r.reasons.join('; ')));
89
+ }
90
+ if (what === 'target' || what === 'tile') {
91
+ const r = IR.append(w.root, what, body, g.actor, { now });
92
+ if (!r.ok) return send(bad(r.status, r.error));
93
+ const R = IR.read(w.root);
94
+ return send({ status: 200, body: what === 'target' ? { ok: true, targets: R.targets } : { ok: true, tiles: R.tiles } });
95
+ }
96
+ const ids = dashRoutes.boardIds(ctx, w);
97
+ if (!ids) return send(bad(503, 'The boards could not be read. Try again in a moment.'));
98
+ if (!ids.has(text(body.board))) return send(bad(404, 'no such board in this workspace'));
99
+ if (what === 'verdict') {
100
+ const r = IR.append(w.root, 'verdict', body, g.actor, { now });
101
+ return send(r.ok ? { status: 200, body: { ok: true, verdict: r.line } } : bad(r.status, r.error));
102
+ }
103
+ const ks = dashRoutes.krIds(ctx, w.id);
104
+ if (!ks) return send(bad(503, 'The KR metric records could not be read, so the charts cannot be checked.'));
105
+ if (what === 'chart') {
106
+ const c = IR.checkChart(body);
107
+ if (!c.ok) return send(bad(c.status, c.error));
108
+ if (!ks.has(c.value.goal)) return send(bad(400, 'No KR metric record is called “' + c.value.goal + '” in this workspace.'));
109
+ const D = PD.list(w.root, c.value.board).find((d) => d.id === c.value.dash);
110
+ if (!D) return send(bad(404, 'That dashboard is not on this board.'));
111
+ if (!D.charts.includes(c.value.goal)) {
112
+ if (body.add !== true) return send(bad(400, 'That goal is not on ' + D.name + '.'));
113
+ 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 } });
114
+ if (!s.ok) return send(bad(s.status, s.error));
115
+ }
116
+ const r = IR.append(w.root, 'chart', c.value, g.actor, { now });
117
+ return send(r.ok ? { status: 200, body: { ok: true, chart: r.line } } : bad(r.status, r.error));
118
+ }
119
+ // dashboard: the dashboard itself, then each chart's form and the range, then the pin
120
+ const list = Array.isArray(body.charts) ? body.charts : [];
121
+ const goals = list.map((x) => (typeof x === 'string' ? x : x && x.goal));
122
+ const range = IR.RANGES.includes(body.range) ? body.range : 'Quarter';
123
+ 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(', ') + '.')); }
124
+ 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 } });
125
+ if (!s.ok) return send(bad(s.status, s.error));
126
+ const D = s.dashboard;
127
+ 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 }); });
128
+ let pinned = null;
129
+ 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; }
130
+ return send({ status: 200, body: { ok: true, id: D.id, dashboard: D, pinned } });
131
+ }
132
+
133
+ module.exports = { prefixes: ['/api/insights-records'], handle };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+ /* routes-meeting-points.js — the Replay's Confirm and Not right (initiative premium-uncovered-features, area meetings; lib/route-modules.js).
3
+ * The data is kept by lib/meeting-points.js.
4
+ *
5
+ * GET /api/meeting-points?note=<id> → { ok, points: { [pointId]: 'confirmed' | 'wrong' } }
6
+ * POST /api/meeting-points { note, ids: [pointId], verdict } → { ok, points } verdict confirmed | wrong | null (Undo)
7
+ * The POST is a page press (lib/pm-guard.js requirePagePress). Handlers are pure over (q | body, ctx) so a test needs no server. */
8
+ const MP = require('./meeting-points.js');
9
+ const guard = require('./pm-guard.js');
10
+
11
+ const fail = (status, error) => ({ status, body: { ok: false, error } });
12
+
13
+ function read(q, ctx) {
14
+ if (!/^[A-Za-z0-9_-]{1,80}$/.test(String(q.note || ''))) return fail(400, 'note is the id of a meeting note');
15
+ return { status: 200, body: { ok: true, points: MP.pointsOf(ctx.runtimeDir, String(q.note)) } };
16
+ }
17
+ function write(req, body, ctx) {
18
+ const g = guard.requirePagePress(req, body);
19
+ if (!g.ok) return fail(g.status, g.error);
20
+ const r = MP.setPoints(ctx.runtimeDir, body);
21
+ return r.ok ? { status: 200, body: { ok: true, points: r.points } } : fail(r.status || 400, r.error);
22
+ }
23
+
24
+ const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
25
+
26
+ module.exports = {
27
+ prefixes: ['/api/meeting-points'],
28
+ read, write,
29
+ handle: async (req, res, url, ctx) => {
30
+ if (url.pathname !== '/api/meeting-points') return false;
31
+ if (req.method === 'GET') return respond(ctx, res, read(Object.fromEntries(url.searchParams), ctx));
32
+ if (req.method !== 'POST') return respond(ctx, res, fail(405, 'GET or POST'));
33
+ const got = await ctx.readJson(req);
34
+ if (!got.ok || !got.body || typeof got.body !== 'object' || Array.isArray(got.body)) return respond(ctx, res, fail(400, 'the body must be a JSON object'));
35
+ return respond(ctx, res, write(req, got.body, ctx));
36
+ },
37
+ };
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+ /* routes-news.js — New for you (initiative premium-uncovered-features, E2; lib/news-for-you.js).
3
+ *
4
+ * GET /api/news-for-you → { ok, count, groups, read } the FYI items not seen yet: mentions, tasks given to you, finished work
5
+ * POST /api/news-for-you/seen { ids } → { ok } one line in <runtime>/news-seen.jsonl; the agent inbox's own ids also go to its seen file,
6
+ * so its count agrees. A page press only (pm-guard requirePagePress).
7
+ *
8
+ * The read asks the routes the pages already read, answered by their own handlers: GET /api/inbox, GET /api/brief-page (its mentions) and
9
+ * GET /api/pm-items (the Work lists). A route that cannot be read gives no items and says so in `read`. Nothing here sends anything. */
10
+ const guard = require('./pm-guard.js');
11
+ const News = require('./news-for-you.js');
12
+
13
+ /** One GET answered by a route module's own handler, as routes-my-work-premium.js listView does. null when it did not answer. */
14
+ async function ask(mod, req, ctx, p) {
15
+ let body = null;
16
+ const c = Object.assign({}, ctx, { json: (res, obj) => { body = obj; } });
17
+ try { await require(mod).handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, new URL('http://local' + p), c); } catch { body = null; }
18
+ return body;
19
+ }
20
+
21
+ module.exports = {
22
+ prefixes: ['/api/news-for-you'],
23
+ handle: async (req, res, url, ctx) => {
24
+ const p = url.pathname;
25
+ if (p === '/api/news-for-you/seen') {
26
+ if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
27
+ const got = await ctx.readJson(req);
28
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
29
+ const b = got.body || {};
30
+ const g = guard.requirePagePress(req, b);
31
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
32
+ const err = News.badSeen(b);
33
+ if (err) { ctx.json(res, { ok: false, error: err }, 400); return true; }
34
+ if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'no runtime folder' }, 500); return true; }
35
+ News.appendSeen(ctx.runtimeDir, b.ids);
36
+ const ib = News.inboxIds(b.ids);
37
+ for (let i = 0; i < ib.length; i += 100) require('./agent-inbox.js').appendSeen(ctx.runtimeDir, { ids: ib.slice(i, i + 100) });
38
+ ctx.json(res, { ok: true });
39
+ return true;
40
+ }
41
+ if (p !== '/api/news-for-you') return false;
42
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
43
+ const ws = url.searchParams.get('ws');
44
+ const [inbox, brief, work] = await Promise.all([
45
+ ask('./routes-inbox.js', req, ctx, '/api/inbox'),
46
+ ask('./routes-brief-page.js', req, ctx, '/api/brief-page' + (ws ? '?ws=' + encodeURIComponent(ws) : '')),
47
+ ask('./routes-pm-items.js', req, ctx, '/api/pm-items'),
48
+ ]);
49
+ const out = News.build({
50
+ inbox, mentions: brief && brief.ok !== false ? brief.mentions : null, work: work && work.ok !== false ? work : null,
51
+ seen: ctx.runtimeDir ? News.readSeen(ctx.runtimeDir) : new Set(),
52
+ });
53
+ out.read.mentions = !!(brief && brief.ok !== false); // no brief for today is read too: it has no mentions
54
+ ctx.json(res, { ok: true, ...out });
55
+ return true;
56
+ },
57
+ };
@@ -70,7 +70,8 @@
70
70
  * POST /api/notes/final-edit { id, sec: 'overview'|'decision'|'action'|'question', i?, text, field?: 'owner'|'due'|'why' } → { ok, final_notes } the PM's correction
71
71
  * GET /api/notes also answers `series_open`: { <series key>: { open, carried } }, the actions each meeting series carries open.
72
72
  * GET /api/notes/series?key= → { ok, series } one regular meeting's notes together (lib/notes-series.js thread)
73
- * GET /api/notes/search?q= → { ok, ids } the notes whose title, notes or transcript hold every word (a private note: its title)
73
+ * GET /api/notes/search?q= → { ok, ids, hits: [{ id, snip, open }] } the notes whose title, notes or transcript hold every word (a private
74
+ * note: its title); each hit with the passage that holds a word, and whether it is an open step or question
74
75
  * POST /api/notes/series-done { key, text, kind: 'action'|'question', done? } → { ok } the PM marks a carried action done, a question answered
75
76
  * POST /api/notes/series-bring { key, text } → { ok, line } · POST /api/notes/series-unbring { key, id } → { ok } lines to bring up next time
76
77
  * POST /api/notes/series-member { id, key: '<series key>'|'off'|null } → { ok, series } put a note in a series, take it out, or back to automatic
@@ -933,6 +934,7 @@ async function handle(req, res, url, ctx) {
933
934
  if (note.note.private) return done({ ok: false, status: 409, error: 'this note is marked private, so nothing more is kept in it' });
934
935
  if (!note.note.recorded_from) return done({ ok: false, status: 409, error: 'press Listen first' });
935
936
  if (!notesScreen.getOn(dir)) return done({ ok: false, status: 409, error: 'Capture the shared screen is switched off in Settings' });
937
+ 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
938
  const own = notesCapture.owns(dir, id, { token: body.cap });
937
939
  if (!own.ok) return done(own);
938
940
  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' });
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+ /* routes-report-confirm.js — the Brief tab's Confirm and Use it (initiative premium-uncovered-features, workstream reports; lib/route-modules.js).
3
+ *
4
+ * GET /api/report-confirm?path=<report file> → { ok, keys: [key] }
5
+ * POST /api/report-confirm { path, key, act } → { ok } act: confirm | use | undo; a page press (lib/pm-guard.js requirePagePress)
6
+ * The records are lib/report-confirm.js, in the runtime folder. Handlers are pure over (q | body, ctx) so a test needs no server. */
7
+ const RC = require('./report-confirm.js');
8
+ const guard = require('./pm-guard.js');
9
+
10
+ const fail = (status, error) => ({ status, body: { ok: false, error } });
11
+ function read(q, ctx) { return { status: 200, body: { ok: true, keys: RC.confirmsOf(ctx.runtimeDir, String(q.path || '')) } }; }
12
+ function post(req, body, ctx) {
13
+ const g = guard.requirePagePress(req, body);
14
+ if (!g.ok) return fail(g.status, g.error);
15
+ const r = RC.confirm(ctx.runtimeDir, body);
16
+ return r.ok ? { status: 200, body: { ok: true } } : fail(r.status || 400, r.error);
17
+ }
18
+ const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
19
+
20
+ module.exports = {
21
+ prefixes: ['/api/report-confirm'],
22
+ read, post,
23
+ handle: async (req, res, url, ctx) => {
24
+ if (url.pathname !== '/api/report-confirm') return false;
25
+ if (req.method === 'GET') return respond(ctx, res, read(Object.fromEntries(url.searchParams), ctx));
26
+ if (req.method !== 'POST') return respond(ctx, res, fail(405, 'GET or POST only'));
27
+ const got = await ctx.readJson(req);
28
+ if (!got.ok || !got.body || typeof got.body !== 'object' || Array.isArray(got.body)) return respond(ctx, res, fail(400, 'the body must be a JSON object'));
29
+ return respond(ctx, res, post(req, got.body, ctx));
30
+ },
31
+ };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+ /* routes-search.js — Search across the repository and every worktree (initiative premium-uncovered-features, E1; lib/search-index.js).
3
+ *
4
+ * GET /api/find?q=<words>&ws=<id>&wt=<id,id> → { ok, q, worktrees, counts, results, more } wt: the worktrees to search (none: all)
5
+ * GET /api/find/file?ws=<id>&wt=<id>&path=<p> → { ok, wt, branch, main, path, text, mtime } one file of a listed worktree, for the Viewer
6
+ *
7
+ * Read-only: nothing here writes or calls anything outside this machine. The repository is the workspace's own (ws, else the home one). */
8
+ const Search = require('./search-index.js');
9
+
10
+ function wsOf(ctx, id) {
11
+ const w = typeof ctx.getWs === 'function' ? ctx.getWs(id || '') : null;
12
+ return w && (!id || w.id === id) ? w : null;
13
+ }
14
+
15
+ module.exports = {
16
+ prefixes: ['/api/find'],
17
+ handle: async (req, res, url, ctx) => {
18
+ const p = url.pathname;
19
+ if (p !== '/api/find' && p !== '/api/find/file') return false;
20
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
21
+ const w = wsOf(ctx, url.searchParams.get('ws'));
22
+ if (!w || !w.root) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
23
+ if (p === '/api/find/file') {
24
+ const r = Search.readFile({ root: w.root, wt: url.searchParams.get('wt') || 'main', path: url.searchParams.get('path') || '' });
25
+ ctx.json(res, r.ok ? r : { ok: false, error: r.error }, r.ok ? 200 : r.status || 400);
26
+ return true;
27
+ }
28
+ let notes = [];
29
+ try { const l = ctx.runtimeDir ? require('./notes.js').list(ctx.runtimeDir) : null; notes = l && l.ok ? l.notes : []; } catch { notes = []; }
30
+ const only = (url.searchParams.get('wt') || '').split(',').map((x) => x.trim()).filter(Boolean);
31
+ try {
32
+ ctx.json(res, { ws: w.id, ...Search.search({ root: w.root, q: url.searchParams.get('q') || '', only, notes }) });
33
+ } catch (e) {
34
+ ctx.json(res, { ok: false, error: 'the search could not run: ' + String((e && e.message) || e).slice(0, 160) }, 500);
35
+ }
36
+ return true;
37
+ },
38
+ };
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+ /* routes-viewer.js — the routes of the Viewer's meeting and report panel that no other module answered (initiative premium-agreed-design,
3
+ * area viewer; lib/route-modules.js). The data is kept by lib/viewer-meeting.js and read by lib/viewer-report.js.
4
+ *
5
+ * GET /api/viewer-meeting?note=&event=&series=&title=&length=&topic=…(repeated)
6
+ * → { ok, agenda: { key, topics: [{ n, text, min, set }], total }, capture: { app, shots }, steps: { links: { [stepKey]: ticketId }, tasks: [stepKey] } }
7
+ * agenda: the topics the page sends (the meeting's agenda), each with its minutes. capture and steps need a note.
8
+ * steps.links are the next steps that became a ticket Drafted in PMOS; steps.tasks the ones Make task made a task of (plan-items).
9
+ * POST /api/viewer-meeting/agenda { key, topic, min } → { ok } the minutes of one topic (0 forgets them)
10
+ * POST /api/viewer-meeting/capture { id, app?, shots? } → { ok, capture } what recording listens to; shots on | paused
11
+ * POST /api/viewer-meeting/work-item { note, step: { text, owner?, due? } } → { ok, ticket, created }
12
+ * A next step becomes a ticket Drafted in PMOS on the note's initiative (lib/jira-tickets.js's draft file). It is not approved and not pushed:
13
+ * only the Commit gate pushes a ticket to Jira.
14
+ * GET /api/viewer-report/checks?ws=&path=&slot= → { ok, checks: [{ id, ok, text }] } the three checks before Issue (lib/viewer-report.js)
15
+ * Every POST is a page press (lib/pm-guard.js requirePagePress). Handlers are pure over (q | body, ctx) so a test needs no server. */
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+ const VM = require('./viewer-meeting.js');
19
+ const VR = require('./viewer-report.js');
20
+ const guard = require('./pm-guard.js');
21
+
22
+ const fail = (status, error) => ({ status, body: { ok: false, error } });
23
+ const okBody = (body) => ({ status: 200, body: { ok: true, ...body } });
24
+ const str = (v, n) => String(v == null ? '' : v).trim().slice(0, n || 300);
25
+
26
+ function noteOf(ctx, id) {
27
+ if (!ctx.runtimeDir || !/^[A-Za-z0-9_-]{1,80}$/.test(String(id || ''))) return null;
28
+ try { const r = require('./notes.js').read(ctx.runtimeDir, String(id)); return r && r.ok ? r.note : null; } catch { return null; }
29
+ }
30
+ function rootOf(ctx, ws) {
31
+ try { const w = ctx.getWs ? ctx.getWs(ws || null) : null; return w && w.root ? w : null; } catch { return null; }
32
+ }
33
+ /** The step keys Make task made a task of: plan items of the initiative whose note names this meeting note's title (premium-meeting.js taskEvent). */
34
+ function tasksOf(root, initiative, title) {
35
+ try {
36
+ const fold = require('./plan-items.js').readFold(root);
37
+ const want = 'From the meeting note "' + (title || 'Untitled note') + '"';
38
+ return (fold.order || []).map((id) => fold.items[id]).filter((it) => it && it.initiative === initiative && it.note === want && it.state !== 'withdrawn').map((it) => VM.stepKey(it.title));
39
+ } catch { return []; }
40
+ }
41
+
42
+ function meeting(q, ctx) {
43
+ const n = q.note ? noteOf(ctx, q.note) : null;
44
+ const ev = n && n.meeting ? n.meeting : {};
45
+ const key = VM.keyOf({ series: q.series || (n && n.series_pm !== 'off' && n.series && n.series.key) || '', event: q.event || ev.event_id || '', title: q.title || ev.title || (n && n.title) || '' });
46
+ const topics = [].concat(q.topic || []).map((t) => str(t, 300)).filter(Boolean);
47
+ const agenda = { key, ...VM.agendaOf(ctx.runtimeDir, { key, topics, length_min: Number(q.length) || 0 }) };
48
+ const out = { agenda, capture: n ? VM.captureOf(ctx.runtimeDir, n.id) : { app: null, shots: 'on' }, steps: { links: {}, tasks: [] } };
49
+ const ini = n && n.initiative && n.initiative.id ? n.initiative : null;
50
+ const w = ini ? rootOf(ctx, ini.ws || n.ws) : null;
51
+ if (ini && w) out.steps = { links: VM.stepLinks(w.root, ini.id, n.id), tasks: tasksOf(w.root, ini.id, n.title) };
52
+ return okBody(out);
53
+ }
54
+
55
+ function post(p, req, body, ctx) {
56
+ const g = guard.requirePagePress(req, body);
57
+ if (!g.ok) return fail(g.status, g.error);
58
+ if (p === '/api/viewer-meeting/agenda') { const r = VM.setAgenda(ctx.runtimeDir, body); return r.ok ? okBody({}) : fail(r.status || 400, r.error); }
59
+ if (p === '/api/viewer-meeting/capture') { const r = VM.setCapture(ctx.runtimeDir, body); return r.ok ? okBody({ capture: r.capture }) : fail(r.status || 400, r.error); }
60
+ if (p === '/api/viewer-meeting/work-item') {
61
+ const n = noteOf(ctx, body.note);
62
+ if (!n) return fail(404, 'that note could not be found');
63
+ if (n.private) return fail(409, 'the note is private, so its steps are not kept');
64
+ const ini = n.initiative && n.initiative.id ? n.initiative : null;
65
+ if (!ini) return fail(409, 'link the note to an initiative first: the step becomes a ticket of that initiative');
66
+ const w = rootOf(ctx, ini.ws || n.ws);
67
+ if (!w) return fail(409, 'the initiative\'s repository is not registered in this workspace');
68
+ const start = (n.meeting && n.meeting.start) || n.created_at || '';
69
+ const day = /^\d{4}-\d{2}-\d{2}/.test(start) ? start.slice(0, 10) : '';
70
+ const r = VM.makeWorkItem(w.root, ini.id, { note: { id: n.id, title: n.title, day }, step: body.step || {} });
71
+ if (r.ok && r.created && typeof ctx.invalidateNeedsAgg === 'function') { try { ctx.invalidateNeedsAgg(w.id); } catch { /* a cache that cannot be cleared refreshes on its own */ } }
72
+ return r.ok ? okBody({ ticket: r.ticket, created: r.created }) : fail(r.status || 400, r.error);
73
+ }
74
+ return fail(404, 'no such route');
75
+ }
76
+
77
+ function checks(q, ctx) {
78
+ const w = rootOf(ctx, q.ws);
79
+ if (!w) return fail(404, 'no such workspace');
80
+ const rel = str(q.path, 400);
81
+ if (!/\.md$/.test(rel) || path.isAbsolute(rel) || !/(^|\/)reports\//.test(rel)) return fail(400, 'path is a report file under reports/');
82
+ const full = path.resolve(w.root, rel), back = path.relative(w.root, full);
83
+ if (!back || back.startsWith('..') || path.isAbsolute(back)) return fail(400, 'path is outside the workspace');
84
+ let text = '';
85
+ try { text = fs.readFileSync(full, 'utf8'); } catch { return fail(404, 'the report file could not be read'); }
86
+ const slot = str(q.slot, 10) || ((/(\d{4}-\d{2}-\d{2})\.md$/.exec(rel) || [])[1] || '');
87
+ return okBody({ checks: VR.issueChecks(text, { slot }) });
88
+ }
89
+
90
+ const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
91
+
92
+ module.exports = {
93
+ prefixes: ['/api/viewer-meeting', '/api/viewer-report'],
94
+ meeting, post, checks,
95
+ handle: async (req, res, url, ctx) => {
96
+ const p = url.pathname;
97
+ if (p === '/api/viewer-meeting' || p === '/api/viewer-report/checks') {
98
+ if (req.method !== 'GET') return respond(ctx, res, fail(405, 'GET only'));
99
+ const q = Object.fromEntries(url.searchParams); q.topic = url.searchParams.getAll('topic');
100
+ return respond(ctx, res, p === '/api/viewer-meeting' ? meeting(q, ctx) : checks(q, ctx));
101
+ }
102
+ if (!['/api/viewer-meeting/agenda', '/api/viewer-meeting/capture', '/api/viewer-meeting/work-item'].includes(p)) return false;
103
+ if (req.method !== 'POST') return respond(ctx, res, fail(405, 'POST only'));
104
+ const got = await ctx.readJson(req);
105
+ if (!got.ok || !got.body || typeof got.body !== 'object' || Array.isArray(got.body)) return respond(ctx, res, fail(400, 'the body must be a JSON object'));
106
+ return respond(ctx, res, post(p, req, got.body, ctx));
107
+ },
108
+ };