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,52 @@
1
+ 'use strict';
2
+ /* meeting-points.js — what the PM said about the key points of a meeting's Replay (initiative premium-uncovered-features, area meetings;
3
+ * MtReplay.dc.html: the bulk bar's Confirm and Not right). The Replay keeps the points that were agreed, owned or left open; the PM ticks
4
+ * some and confirms them, or marks them not right. A point marked not right leaves the kept list and goes to "Left out".
5
+ *
6
+ * pointsOf(dir, note) → { [pointId]: 'confirmed' | 'wrong' } a later line wins; verdict null forgets the point
7
+ * setPoints(dir, { note, ids, verdict }) → { ok, points } | { ok: false, status, error }
8
+ *
9
+ * A point's id is the id lib/meeting-replay.js gives it (d1, a2, q1). One line of <runtime>/meeting-points.jsonl per press, file mode,
10
+ * in the per-user runtime folder beside the notes. Nothing here sends anything. */
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const FILE = 'meeting-points.jsonl';
15
+ const NOTE_ID = /^[A-Za-z0-9_-]{1,80}$/;
16
+ const POINT_ID = /^[A-Za-z0-9_-]{1,40}$/;
17
+ const VERDICTS = ['confirmed', 'wrong'];
18
+
19
+ function readLines(file) {
20
+ let text = '';
21
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
22
+ const out = [];
23
+ for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object') out.push(o); } catch { /* a torn line is skipped */ } }
24
+ return out;
25
+ }
26
+
27
+ /** The verdict on each point of one note. */
28
+ function pointsOf(dir, note) {
29
+ const out = {};
30
+ if (!dir || !NOTE_ID.test(String(note || ''))) return out;
31
+ for (const l of readLines(path.join(dir, FILE))) {
32
+ if (l.note !== note || !Array.isArray(l.ids)) continue;
33
+ for (const id of l.ids) { if (VERDICTS.includes(l.verdict)) out[id] = l.verdict; else delete out[id]; }
34
+ }
35
+ return out;
36
+ }
37
+
38
+ /** One press: the verdict on the points ticked. verdict null takes the verdict back (Undo). */
39
+ function setPoints(dir, body = {}) {
40
+ if (!dir) return { ok: false, status: 500, error: 'no runtime folder' };
41
+ const note = String(body.note || '');
42
+ if (!NOTE_ID.test(note)) return { ok: false, status: 400, error: 'note is the id of a meeting note' };
43
+ const ids = Array.isArray(body.ids) ? [...new Set(body.ids.map(String))] : [];
44
+ if (!ids.length || ids.length > 200 || !ids.every((x) => POINT_ID.test(x))) return { ok: false, status: 400, error: 'ids are the key points to mark, 1 to 200 of them' };
45
+ const verdict = body.verdict == null ? null : String(body.verdict);
46
+ if (verdict !== null && !VERDICTS.includes(verdict)) return { ok: false, status: 400, error: 'verdict is confirmed, wrong or null' };
47
+ fs.mkdirSync(dir, { recursive: true });
48
+ fs.appendFileSync(path.join(dir, FILE), JSON.stringify({ v: 1, note, ids, verdict, at: new Date().toISOString() }) + '\n');
49
+ return { ok: true, points: pointsOf(dir, note) };
50
+ }
51
+
52
+ module.exports = { pointsOf, setPoints, FILE };
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+ /* news-for-you.js — New for you, which replaces the Inbox (initiative premium-uncovered-features, E2; canvas EvInbox, HmAround).
3
+ *
4
+ * build({ inbox, mentions, work, seen }) → { count, groups: [{ key, label, items }] } PURE
5
+ * readSeen(runtimeDir) → Set of ids · appendSeen(runtimeDir, ids, now) · badSeen(body) → null | the reason
6
+ *
7
+ * New for you holds items for the PM's information only, in three groups (EvInbox):
8
+ * mentions someone named the PM (today's brief, GET /api/brief-page mentions): unread, and not already a next step (in_needs)
9
+ * given a task given to the PM: an open Work item that came from a source (Jira, the work breakdown), not one the PM typed
10
+ * finished what the agents finished while the PM was away: the new items of the agent inbox (GET /api/inbox items)
11
+ * An item leaves once it is seen: its id is in <runtime>/news-seen.jsonl. A mention that asks something, a passed review or a proposal is
12
+ * its initiative's next step, so it is never only here: the inbox item is the news that it finished, and the next step stays on Home.
13
+ * Every word comes from the record. Nothing here decides, replies or sends anything. */
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+
17
+ const SEEN = 'news-seen.jsonl';
18
+ const ID_RE = /^(men|task|prop|goal|work):[^\s]{1,200}$/;
19
+ const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
20
+ const SRC = { slack: 'Slack', jira: 'Jira', confluence: 'Confluence', mail: 'Mail', wbs: 'Work breakdown', gmail: 'Gmail', figma: 'Figma' };
21
+ const srcName = (s) => SRC[s] || (s ? String(s)[0].toUpperCase() + String(s).slice(1) : '');
22
+ const FIN = { 'work-draft': 'Draft ready', 'work-stopped': 'Agent stopped', proposal: 'Proposal ready', draft: 'Draft ready', 'goal-waiting': 'Goal needs you', 'goal-done': 'Goal finished', 'goal-stopped': 'Goal stopped' };
23
+ const at = (x) => { const t = Date.parse(x || ''); return Number.isFinite(t) ? t : null; };
24
+
25
+ function mentionItems(list, seen) {
26
+ return (Array.isArray(list) ? list : []).filter((m) => m && m.id && !m.read && !m.in_needs && !seen.has('men:' + m.id)).map((m) => ({
27
+ id: 'men:' + m.id, kind: 'mention', mid: m.id, who: clip(m.who || srcName(m.source) || 'Someone', 80), source: m.source || '', where: clip(m.where || '', 80),
28
+ title: clip((m.who || srcName(m.source) || 'Someone') + ' mentioned you' + (m.where ? ' in ' + m.where : ''), 160), text: clip(m.text, 280),
29
+ at: at(m.at), link: m.link || null, initiative: m.initiative || null, asks: !!m.reply,
30
+ }));
31
+ }
32
+ /** The open Work items that came from a source, from GET /api/pm-items' answer (its five lists). */
33
+ function givenItems(v, seen) {
34
+ const w = (v && v.work) || {}, out = [], had = new Set();
35
+ for (const k of ['inbox', 'today', 'upcoming', 'waiting', 'someday']) for (const it of w[k] || []) {
36
+ if (!it || !it.id || it.done || had.has(it.id)) continue;
37
+ const src = it.origin || it.source || 'local';
38
+ if (!(it.assigned === true || (src !== 'local' && src !== 'brief' && src !== 'work'))) continue;
39
+ had.add(it.id);
40
+ if (seen.has('task:' + it.id)) continue;
41
+ out.push({ id: 'task:' + it.id, kind: 'task', tid: it.id, title: clip('New task: ' + (it.title || it.key || it.id), 160), from: srcName(src), key: it.key || '',
42
+ due: it.due || null, initiative: it.initiative || null, link: it.url || it.link || null, at: at(it.created_at) });
43
+ }
44
+ return out;
45
+ }
46
+ function finishedItems(inbox, seen) {
47
+ const items = inbox && inbox.ok !== false && Array.isArray(inbox.items) ? inbox.items : [];
48
+ return items.filter((x) => x && x.id && !seen.has(x.id)).map((x) => ({
49
+ id: x.id, kind: 'finished', what: FIN[x.kind] || 'Finished', title: clip(x.title, 160), product: x.product || '', target: x.target && x.target.title ? x.target.title : '',
50
+ at: Number.isFinite(x.at) ? x.at : null, open: x.open || '', pws: x.pws || '', session: x.session || '', agentKind: x.kind || '',
51
+ }));
52
+ }
53
+
54
+ /** The groups, newest first in each; an empty group is left out. inbox: GET /api/inbox; mentions: the brief page's list (null: no brief today). */
55
+ function build({ inbox = null, mentions = null, work = null, seen = new Set() } = {}) {
56
+ const by = (a, b) => (b.at || 0) - (a.at || 0);
57
+ const groups = [
58
+ { key: 'mentions', label: 'Mentions', items: mentionItems(mentions, seen).sort(by) },
59
+ { key: 'given', label: 'Given to you', items: givenItems(work, seen).sort(by) },
60
+ { key: 'finished', label: 'Finished while you were away', items: finishedItems(inbox, seen).sort(by) },
61
+ ].filter((g) => g.items.length);
62
+ return { count: groups.reduce((n, g) => n + g.items.length, 0), groups, read: { mentions: mentions !== null, inbox: !!(inbox && inbox.ok !== false), work: !!(work && work.ok !== false) } };
63
+ }
64
+
65
+ function readSeen(runtimeDir) {
66
+ const ids = new Set();
67
+ let t; try { t = fs.readFileSync(path.join(runtimeDir, SEEN), 'utf8'); } catch { return ids; }
68
+ for (const l of t.split('\n')) {
69
+ if (!l.trim()) continue;
70
+ let e; try { e = JSON.parse(l); } catch { continue; }
71
+ if (e && Array.isArray(e.ids)) for (const id of e.ids) if (typeof id === 'string') ids.add(id);
72
+ }
73
+ return ids;
74
+ }
75
+ /** The check of a seen body: 1 to 300 item ids. null when it is good, else the reason. Pure. */
76
+ function badSeen(b) {
77
+ if (!b || typeof b !== 'object') return 'a body is required';
78
+ if (!Array.isArray(b.ids) || !b.ids.length || b.ids.length > 300 || !b.ids.every((x) => typeof x === 'string' && ID_RE.test(x))) return 'ids must be 1 to 300 item ids';
79
+ return null;
80
+ }
81
+ function appendSeen(runtimeDir, ids, now = new Date()) {
82
+ fs.mkdirSync(runtimeDir, { recursive: true });
83
+ fs.appendFileSync(path.join(runtimeDir, SEEN), JSON.stringify({ ids, at: now.toISOString() }) + '\n');
84
+ }
85
+ /** The ids the agent inbox knows (its own seen file takes them too, so the inbox's count agrees with New for you). */
86
+ const inboxIds = (ids) => ids.filter((x) => /^(prop|goal|work):/.test(x));
87
+
88
+ module.exports = { SEEN, build, readSeen, badSeen, appendSeen, inboxIds, srcName };
@@ -331,14 +331,16 @@ function openCounts(dir, rows) {
331
331
  * notes, typed notes, summary and transcript. */
332
332
  function search(dir, q) {
333
333
  const ws = norm(q).split(' ').filter(Boolean);
334
- if (!ws.length || norm(q).length < 2) return { ok: true, ids: [] };
334
+ if (!ws.length || norm(q).length < 2) return { ok: true, ids: [], hits: [] };
335
335
  let names = [];
336
- try { names = fs.readdirSync(notes.notesDir(dir)).filter((f) => f.endsWith('.json')); } catch { return { ok: true, ids: [] }; }
337
- const ids = [];
336
+ try { names = fs.readdirSync(notes.notesDir(dir)).filter((f) => f.endsWith('.json')); } catch { return { ok: true, ids: [], hits: [] }; }
337
+ const ids = [], hits = [];
338
338
  for (const f of names) {
339
339
  const n = notes.loadCached(dir, f.slice(0, -5));
340
340
  if (!n || !n.id) continue;
341
341
  let hay = n.title || '';
342
+ /* where the words were said, for the snippet (premium-uncovered-features, MtNotes): an open next step or question first, then what was said */
343
+ const parts = [];
342
344
  if (!n.private) {
343
345
  const fin = n.final_notes || {};
344
346
  const items = (xs) => (Array.isArray(xs) ? xs.map((x) => (x && x.text) || '').join(' ') : '');
@@ -346,12 +348,33 @@ function search(dir, q) {
346
348
  hay += ' ' + [n.overview_pm, fin.overview, fin.purpose, fin.discussion, items(fin.decisions), items(fin.actions), items(fin.questions), n.body,
347
349
  items(sec.overview), items(sec.decisions), items(sec.actions), items(sec.questions), items(n.bullets), items(n.transcript),
348
350
  n.meeting && n.meeting.title].filter(Boolean).join(' ');
351
+ const each = (xs, open) => { for (const x of Array.isArray(xs) ? xs : []) if (x && x.text) parts.push({ text: String(x.text), open }); };
352
+ each(fin.actions, true); each(fin.questions, true); each(sec.actions, true); each(sec.questions, true);
353
+ each(n.transcript, false); each(fin.decisions, false); each(n.bullets, false);
354
+ for (const t of [fin.overview, n.overview_pm, n.body]) if (t) parts.push({ text: String(t), open: false });
349
355
  }
350
356
  const h = ' ' + norm(hay) + ' ';
351
- if (ws.every((w) => h.includes(w))) ids.push(n.id);
357
+ if (!ws.every((w) => h.includes(w))) continue;
358
+ ids.push(n.id);
359
+ hits.push({ id: n.id, ...snipOf(parts, ws) });
352
360
  }
353
- return { ok: true, ids };
361
+ return { ok: true, ids, hits };
362
+ }
363
+ /** The first passage that holds a searched word, about 80 characters around it: { snip, open } (open: it is an open next step or question). */
364
+ function snipOf(parts, ws) {
365
+ for (const p of parts) {
366
+ const low = p.text.toLowerCase();
367
+ let at = -1;
368
+ for (const w of ws) { const i = low.indexOf(w); if (i >= 0 && (at < 0 || i < at)) at = i; }
369
+ if (at < 0) continue;
370
+ let from = Math.max(0, at - 30), to = Math.min(p.text.length, at + 60);
371
+ if (from) { const sp = p.text.indexOf(' ', from); if (sp >= 0 && sp < at) from = sp + 1; } // whole words only
372
+ if (to < p.text.length) { const sp = p.text.lastIndexOf(' ', to); if (sp > at) to = sp; }
373
+ const snip = (from ? '…' : '') + p.text.slice(from, to).replace(/\s+/g, ' ').trim() + (to < p.text.length ? '…' : '');
374
+ return { snip, open: p.open };
375
+ }
376
+ return { snip: '', open: false };
354
377
  }
355
378
 
356
- module.exports = { assign, openCounts, thread, placeOf, search, markDone, bring, unbring, partsOf, topicsOf, carriedOf, nextOf, norm, storeFile,
379
+ module.exports = { assign, openCounts, thread, placeOf, search, snipOf, markDone, bring, unbring, partsOf, topicsOf, carriedOf, nextOf, norm, storeFile,
357
380
  OPEN_WINDOW, TOPIC_WINDOW, TOPIC_MIN, CARRY_WARN };
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+ /* report-confirm.js — what the PM confirmed on a report's Brief tab (initiative premium-uncovered-features, workstream reports; canvas RpBrief
3
+ * "Please confirm": Confirm, Use it). File mode, one line per press of <runtime>/report-confirms.jsonl, beside the Viewer's other runtime records
4
+ * (lib/viewer-meeting.js).
5
+ *
6
+ * confirmsOf(dir, path) → [key] the keys confirmed for one report file; a later 'undo' line takes one back
7
+ * confirm(dir, { path, key, act }) → { ok } | { ok: false, status, error } act: confirm | use | undo
8
+ *
9
+ * A key is the check and a hash of its words (public/pm/rp-parts.js confirmKey), so a check that says something new asks again. Nothing here
10
+ * changes the report file: a Confirm is the PM's word that the figure stands, kept for the Brief. */
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const FILE = 'report-confirms.jsonl';
15
+ const ACTS = ['confirm', 'use', 'undo'];
16
+ const str = (v, n) => String(v == null ? '' : v).trim().slice(0, n);
17
+ const REL = /^(?!\/)(?!.*\.\.)[^\0]{1,400}\.md$/;
18
+
19
+ function readLines(file) {
20
+ let text = '';
21
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
22
+ const out = [];
23
+ for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object') out.push(o); } catch { /* a torn line is skipped */ } }
24
+ return out;
25
+ }
26
+
27
+ function confirmsOf(dir, rel) {
28
+ if (!dir || !REL.test(String(rel || ''))) return [];
29
+ const on = new Set();
30
+ for (const l of readLines(path.join(dir, FILE))) {
31
+ if (l.path !== rel || typeof l.key !== 'string') continue;
32
+ if (l.act === 'undo') on.delete(l.key); else on.add(l.key);
33
+ }
34
+ return [...on];
35
+ }
36
+
37
+ function confirm(dir, { path: rel, key, act } = {}) {
38
+ if (!dir) return { ok: false, status: 409, error: 'this server has no runtime folder, so a confirm cannot be kept' };
39
+ if (!REL.test(String(rel || ''))) return { ok: false, status: 400, error: 'path is a report file (.md) inside the workspace' };
40
+ const k = str(key, 120);
41
+ if (!/^[a-z0-9-]+:[a-z0-9]+$/.test(k)) return { ok: false, status: 400, error: 'key is a check id and a hash, like check-figures:1x2y3z' };
42
+ const a = ACTS.includes(act) ? act : 'confirm';
43
+ fs.mkdirSync(dir, { recursive: true });
44
+ fs.appendFileSync(path.join(dir, FILE), JSON.stringify({ v: 1, path: String(rel), key: k, act: a, at: new Date().toISOString() }) + '\n');
45
+ return { ok: true };
46
+ }
47
+
48
+ module.exports = { confirmsOf, confirm, FILE };
@@ -52,11 +52,19 @@ 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)
56
+ 'routes-board-docs', // premium-uncovered-features (Board): when each document of the Documents tab changed and by whom, from git (read-only)
57
+ 'routes-board-grill', // premium-uncovered-features (Board): a new initiative's Why, material and first questions (page press; file mode)
55
58
  'routes-insights-premium', // briefing-premium-insights: the premium Insights page's model from the KR metric records and report files (read-only)
59
+ 'routes-home-desk', // premium-agreed-design (Home): seen marks, queued messages, the weekly update's recipients and sends, stakeholders (page press; file mode)
60
+ 'routes-home-review', // premium-uncovered-features (Home): the weekly review's four steps and the untouched work looked at (page press; file mode)
56
61
  'routes-initiative-premium', // briefing-premium-initiative: the premium initiative page's model from the Initiatives sheet's own routes (read-only)
62
+ 'routes-initiative-layout', // premium-uncovered-features (Initiative): Moves on by itself, held stages, task groups and saved group sets (page press; file mode)
57
63
  'routes-brief-page', // console3 Briefing as the brief: Today agenda, Needs you and Mentions (read-only; writes go through routes-pm-items)
58
64
  'routes-mentions', // console3 Briefing Mentions: the PM's read marks (page press only)
59
65
  'routes-inbox', // premium-agent-inbox: the bell's agent results and the PM's seen marks (page press only)
66
+ 'routes-search', // premium-uncovered-features (E1): Search across the repository and every worktree (read-only)
67
+ 'routes-news', // premium-uncovered-features (E2): New for you, the FYI items, and their seen marks (page press only)
60
68
  'routes-phone-day', // phone companion: the agent's finished drafts, the evening recap and tomorrow at a glance (read-only)
61
69
  'routes-report-facts', // console3 D: GET /api/report-families/facts (read-only, real data only)
62
70
  'routes-records', // console3 E1a: ideas, hypotheses, decisions, KR metrics, bets (GET list; page-press add/edit/reading)
@@ -77,6 +85,9 @@ const MODULES = Object.freeze([
77
85
  '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
86
  'routes-meeting-replay', // meeting-material-replay: the note, the Focus state and the shots joined for the Replay page (GET, read-only)
79
87
  '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)
88
+ 'routes-meeting-points', // premium-uncovered-features (meetings): the Replay's Confirm and Not right on a meeting's key points (meeting-points.jsonl)
89
+ 'routes-viewer', // premium-agreed-design (viewer): agenda minutes, what recording listens to, a next step made a drafted ticket, the report's Issue checks
90
+ 'routes-report-confirm', // premium-uncovered-features (reports): the Brief tab's Confirm and Use it (report-confirms.jsonl in the runtime folder)
80
91
  'routes-stage-tools', // stage-tools-records: the records the PM edits per stage, what PMOS holds per stage, the sprint burndown
81
92
  'routes-orchestrator', // agent-orchestrator: the status of the capacity governor and the PM's stop switch (orchestrator-stop.json)
82
93
  'routes-driver', // initiative-driver: the Agent strip's data, Keep, Send back, Drop, Pause and the board mode (driver.jsonl)
@@ -86,6 +97,7 @@ const MODULES = Object.freeze([
86
97
  'routes-custom-docs', // briefing-premium-adddoc: the documents the PM adds beyond the core set, Add a document (custom-docs.jsonl)
87
98
  'routes-premium-dashboards', // briefing-premium-reports: the dashboards the PM makes on premium Insights (premium-dashboards.jsonl; page-press POST save)
88
99
  '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)
100
+ '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
101
  'routes-premium-charts', // premium-studio-chart: the charts the PM makes in the Insight Studio (premium-charts.jsonl; page-press POST save)
90
102
  '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
103
  'routes-report-structure', // report-structure: the structure step (turns, versions, Use this structure, sources and their checks, dry run) and the chart store (GET /api/charts)
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+ /* routes-board-docs.js — GET /api/board-docs?ws=<id>&paths=<path,path,…> (initiative premium-uncovered-features, Board: BdDocs).
3
+ *
4
+ * 200 { ok, docs: { [path]: { changed, at, by, log: [{ at, by, subject }] } } } when each document last changed, by whom, and its last five commits
5
+ * 400 { ok: false, error } — no path, or a path outside the repository · 404 — the workspace is not registered
6
+ * Read-only: `git log` on the workspace's repository. A path git has no history for (a new file, no repository) is left out, so the
7
+ * Documents tab shows "—" for it rather than a guess. At most 40 paths per call. */
8
+ const path = require('path');
9
+ const { execFileSync } = require('child_process');
10
+
11
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
12
+ const day = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? Number(m[3]) + ' ' + MON[Number(m[2]) - 1] : ''; };
13
+ const PATH_RE = /^[\w@][\w@ .()/-]{0,300}$/;
14
+
15
+ /** The last commits of one file, newest first. → [{ at, by, subject }] (empty when git knows none). */
16
+ function logOf(root, rel) {
17
+ let out = '';
18
+ try { out = execFileSync('git', ['log', '-n', '5', '--format=%cI%x09%an%x09%s', '--', rel], { cwd: root, encoding: 'utf8', timeout: 4000, stdio: ['ignore', 'pipe', 'ignore'] }); } catch { return []; }
19
+ return out.split('\n').filter(Boolean).map((l) => { const [at, by, ...s] = l.split('\t'); return { at, by, subject: s.join('\t').slice(0, 160) }; });
20
+ }
21
+ /** The answer for a list of paths. Pure over `log` (a stand-in in the unit test). */
22
+ function docsOf(root, paths, log = logOf) {
23
+ const docs = {};
24
+ for (const p of paths) {
25
+ const L = log(root, p);
26
+ if (!L.length) continue;
27
+ docs[p] = { changed: day(L[0].at), at: L[0].at, by: L[0].by, log: L.map((x) => ({ at: day(x.at), by: x.by, subject: x.subject })) };
28
+ }
29
+ return docs;
30
+ }
31
+
32
+ module.exports = {
33
+ prefixes: ['/api/board-docs'],
34
+ docsOf,
35
+ handle: async (req, res, url, ctx) => {
36
+ if (url.pathname !== '/api/board-docs') return false;
37
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
38
+ const paths = String(url.searchParams.get('paths') || '').split(',').map((s) => s.trim()).filter(Boolean).slice(0, 40);
39
+ if (!paths.length) { ctx.json(res, { ok: false, error: 'name the documents: paths=<path,path,…>' }, 400); return true; }
40
+ if (!paths.every((p) => PATH_RE.test(p) && !p.split('/').includes('..') && !path.isAbsolute(p))) { ctx.json(res, { ok: false, error: 'a path must stay inside the repository' }, 400); return true; }
41
+ const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
42
+ if (!w || !w.root) { ctx.json(res, { ok: false, error: 'that workspace is not registered' }, 404); return true; }
43
+ ctx.json(res, { ok: true, docs: docsOf(w.root, paths) });
44
+ return true;
45
+ },
46
+ };
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+ /* routes-board-grill.js — the first questions of a new initiative on the Board (initiative premium-uncovered-features, Board: BdNew, BdGrill).
3
+ *
4
+ * GET /api/board-grill?ws=<id>&id=<initiative> → { ok, id, why, material, questions, summary }
5
+ * GET /api/board-grill?ws=<id>&ids=<id,id,…> → { ok, items: { [id]: summary } } only the initiatives with a line in the file
6
+ * POST /api/board-grill/start { ws, id, why?, links?: [{ url, label? }] } the New initiative panel's Why and links
7
+ * POST /api/board-grill/file { ws, id, name, type?, data } one file (base64, at most 4 MB) kept under <state>/material/<id>/
8
+ * POST /api/board-grill/answer { ws, id, q, answer } one answer; an empty answer clears it
9
+ * POST /api/board-grill/later { ws, id } keep the open questions as the next step
10
+ * lib/board-grill.js holds the rules. FILE MODE ONLY: <state>/triage-answers.jsonl, append-only. Every POST is a page press
11
+ * (pm-guard requirePagePress). Nothing is sent anywhere. */
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const guard = require('./pm-guard.js');
15
+ const pmItems = require('./pm-items.js');
16
+ const G = require('./board-grill.js');
17
+
18
+ const ID_RE = /^[a-z0-9][\w.-]{0,80}$/i;
19
+ const MAX_FILE = 4 * 1024 * 1024;
20
+ const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
21
+ function stateDir(ctx, w) {
22
+ let d = null;
23
+ try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create: true }) : null; } catch { d = null; }
24
+ return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
25
+ }
26
+ const fileOf = (sd) => path.join(sd, 'triage-answers.jsonl');
27
+ const read = (f) => { try { return pmItems.readLines(f).filter(Boolean); } catch { return []; } };
28
+ const linkOk = (u) => /^https?:\/\/[^\s]{3,}$/i.test(String(u || ''));
29
+ const one = (lines, id) => { const st = G.fold(lines, id); return { ok: true, id, why: st.why, material: st.material, questions: G.questionsOf(st), summary: G.summaryOf(st) }; };
30
+
31
+ module.exports = {
32
+ prefixes: ['/api/board-grill'],
33
+ handle: async (req, res, url, ctx) => {
34
+ const p = url.pathname;
35
+ if (!p.startsWith('/api/board-grill')) return false;
36
+ const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
37
+ if (p === '/api/board-grill') {
38
+ if (req.method !== 'GET') return bad('GET only', 405);
39
+ const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
40
+ if (!w || !w.root) return bad('that workspace is not registered', 404);
41
+ const sd = stateDir(ctx, w), lines = sd ? read(fileOf(sd)) : [];
42
+ const ids = String(url.searchParams.get('ids') || '').split(',').map((s) => s.trim()).filter(Boolean).slice(0, 150);
43
+ if (ids.length) {
44
+ if (!ids.every((x) => ID_RE.test(x))) return bad('a bad initiative id');
45
+ const items = {};
46
+ for (const id of ids) if (lines.some((l) => l && l.initiative === id)) items[id] = G.summaryOf(G.fold(lines, id));
47
+ ctx.json(res, { ok: true, items });
48
+ return true;
49
+ }
50
+ const id = url.searchParams.get('id') || '';
51
+ if (!ID_RE.test(id)) return bad('name the initiative: id=<id>');
52
+ ctx.json(res, one(lines, id));
53
+ return true;
54
+ }
55
+ if (req.method !== 'POST') return bad('POST only', 405);
56
+ const got = await ctx.readJson(req);
57
+ if (!got.ok) return bad('invalid JSON body');
58
+ const b = got.body || {};
59
+ const g = guard.requirePagePress(req, b);
60
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
61
+ const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
62
+ if (!w || !w.root) return bad('that workspace is not registered', 404);
63
+ if (!ID_RE.test(String(b.id || ''))) return bad('id must name the initiative');
64
+ const sd = stateDir(ctx, w);
65
+ if (!sd) return bad('this workspace has no state folder', 409);
66
+ const f = fileOf(sd), now = new Date();
67
+ if (p === '/api/board-grill/start') {
68
+ const links = (Array.isArray(b.links) ? b.links : []).slice(0, 20).map((k) => ({ url: str(k && k.url, 600), label: str(k && (k.label || k.url), 160) }));
69
+ if (links.some((k) => !linkOk(k.url))) return bad('a link must start with http:// or https://');
70
+ pmItems.appendEvent(f, { kind: 'start', initiative: b.id, why: str(b.why, 400), links }, now);
71
+ } else if (p === '/api/board-grill/file') {
72
+ const name = path.basename(str(b.name, 120)).replace(/[^\w .()-]+/g, '_');
73
+ if (!name || name.startsWith('.')) return bad('name the file');
74
+ const buf = Buffer.from(String(b.data || ''), 'base64');
75
+ if (!buf.length) return bad('the file is empty');
76
+ if (buf.length > MAX_FILE) return bad('a file can be at most 4 MB');
77
+ const dir = path.join(sd, 'material', b.id);
78
+ fs.mkdirSync(dir, { recursive: true });
79
+ fs.writeFileSync(path.join(dir, name), buf);
80
+ pmItems.appendEvent(f, { kind: 'file', initiative: b.id, name, type: str(b.type, 80), size: buf.length, path: path.relative(w.root, path.join(dir, name)).split(path.sep).join('/') }, now);
81
+ } else if (p === '/api/board-grill/answer') {
82
+ if (!G.QUESTIONS.some((x) => x.key === b.q)) return bad('q must name a question');
83
+ pmItems.appendEvent(f, { kind: 'answer', initiative: b.id, q: b.q, answer: str(b.answer, 500) }, now);
84
+ } else if (p === '/api/board-grill/later') {
85
+ pmItems.appendEvent(f, { kind: 'later', initiative: b.id }, now);
86
+ } else return bad('no such route', 404);
87
+ ctx.json(res, one(read(f), b.id));
88
+ return true;
89
+ },
90
+ };
@@ -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
+