create-pmos 0.609.0 → 0.611.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 (145) hide show
  1. package/package.json +69 -27
  2. package/payload/KIT-VERSION +1 -1
  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/workspace/board-columns-test.js +2 -1
  7. package/workspace/board-deliveries-test.js +2 -1
  8. package/workspace/board-programs-test.js +9 -5
  9. package/workspace/board-publish-ui-test.js +2 -1
  10. package/workspace/board-shared-ui-test.js +2 -1
  11. package/workspace/board-workflows-test.js +2 -1
  12. package/workspace/briefing-premium-adddoc-test.js +2 -1
  13. package/workspace/briefing-premium-board-test.js +10 -9
  14. package/workspace/briefing-premium-doc-edit-test.js +2 -1
  15. package/workspace/briefing-premium-initiative-test.js +7 -6
  16. package/workspace/briefing-premium-insights-test.js +12 -11
  17. package/workspace/briefing-premium-products-test.js +4 -2
  18. package/workspace/briefing-premium-sources-test.js +1 -1
  19. package/workspace/briefing-premium-test.js +6 -5
  20. package/workspace/briefing-premium-work-test.js +1 -1
  21. package/workspace/calm-timeline-test.js +2 -1
  22. package/workspace/changelog.json +68 -0
  23. package/workspace/core-docs-workflow-test.js +2 -1
  24. package/workspace/ev-everywhere-test.js +11 -10
  25. package/workspace/guide/home.md +2 -2
  26. package/workspace/guide/index.md +4 -0
  27. package/workspace/guide/layout.md +92 -11
  28. package/workspace/guide/programs.md +16 -2
  29. package/workspace/guide/routine.md +50 -0
  30. package/workspace/guide/scheduled-tasks-and-cli.md +1 -1
  31. package/workspace/guide/settings-and-switches.md +1 -1
  32. package/workspace/home-other-product-test.js +2 -1
  33. package/workspace/home-railcard-test.js +2 -1
  34. package/workspace/impact-screens-test.js +3 -1
  35. package/workspace/ini-workflow-test.js +2 -1
  36. package/workspace/lib/beside-page.js +15 -0
  37. package/workspace/lib/classic-board.js +15 -0
  38. package/workspace/lib/events-place.js +216 -0
  39. package/workspace/lib/library-items.js +78 -0
  40. package/workspace/lib/notes.js +6 -1
  41. package/workspace/lib/route-modules.js +4 -0
  42. package/workspace/lib/routes-events-place.js +166 -0
  43. package/workspace/lib/routes-library.js +89 -0
  44. package/workspace/lib/routes-pop-work.js +39 -0
  45. package/workspace/lib/routes-report-setups.js +20 -0
  46. package/workspace/lib/routes-today-log.js +48 -0
  47. package/workspace/lib/routine-reports.js +52 -0
  48. package/workspace/lib/today-log.js +131 -0
  49. package/workspace/live-pill-round-test.js +11 -9
  50. package/workspace/metric-drafts-ui-test.js +3 -1
  51. package/workspace/milestone-pins-test.js +2 -1
  52. package/workspace/milestone-suggest-test.js +3 -1
  53. package/workspace/package-lock.json +2 -2
  54. package/workspace/package.json +1 -1
  55. package/workspace/panels-test.js +6 -4
  56. package/workspace/premium-board-actions-test.js +3 -1
  57. package/workspace/premium-chat-context-test.js +6 -6
  58. package/workspace/premium-chat-line-test.js +1 -1
  59. package/workspace/premium-chat-notes-test.js +1 -1
  60. package/workspace/premium-core-doc-issue-test.js +2 -1
  61. package/workspace/premium-rec-tab-test.js +2 -1
  62. package/workspace/premium-vw-backlog-test.js +3 -1
  63. package/workspace/premium-vw-cal-test.js +1 -1
  64. package/workspace/premium-vw-doc-test.js +2 -1
  65. package/workspace/premium-vw-item-test.js +3 -1
  66. package/workspace/premium-vw-jira-test.js +3 -1
  67. package/workspace/product-lane-test.js +2 -1
  68. package/workspace/program-charter-test.js +3 -1
  69. package/workspace/program-leave-test.js +3 -1
  70. package/workspace/program-order-test.js +2 -1
  71. package/workspace/program-panel-test.js +5 -3
  72. package/workspace/public/pm/bd-ini-panel.js +75 -8
  73. package/workspace/public/pm/bd-prog-panel.js +55 -8
  74. package/workspace/public/pm/bd-scroll.js +4 -2
  75. package/workspace/public/pm/bd-work.css +130 -0
  76. package/workspace/public/pm/bd-work.js +356 -0
  77. package/workspace/public/pm/cozy-board.css +3 -0
  78. package/workspace/public/pm/cozy-ev.css +52 -0
  79. package/workspace/public/pm/cozy-events-view.js +142 -0
  80. package/workspace/public/pm/cozy-events.css +107 -0
  81. package/workspace/public/pm/cozy-events.js +210 -0
  82. package/workspace/public/pm/cozy-evmodel.js +1 -1
  83. package/workspace/public/pm/cozy-library.css +36 -0
  84. package/workspace/public/pm/cozy-live-pill.js +3 -1
  85. package/workspace/public/pm/cozy-nav.js +70 -7
  86. package/workspace/public/pm/cozy-panels.js +1 -1
  87. package/workspace/public/pm/cozy-pick.css +3 -0
  88. package/workspace/public/pm/cozy-pick.js +6 -2
  89. package/workspace/public/pm/cozy-pop-work.css +165 -0
  90. package/workspace/public/pm/cozy-pop-work.js +427 -0
  91. package/workspace/public/pm/cozy-popup.css +113 -0
  92. package/workspace/public/pm/cozy-popup.js +408 -0
  93. package/workspace/public/pm/cozy-routine-model.js +111 -0
  94. package/workspace/public/pm/cozy-routine-pop.js +196 -0
  95. package/workspace/public/pm/cozy-routine.css +102 -0
  96. package/workspace/public/pm/cozy-routine.js +156 -0
  97. package/workspace/public/pm/cozy-schedwork.js +6 -5
  98. package/workspace/public/pm/cozy-settings.js +10 -1
  99. package/workspace/public/pm/cozy-today-app.js +236 -0
  100. package/workspace/public/pm/cozy-today-model.js +176 -0
  101. package/workspace/public/pm/cozy-today-page.css +100 -0
  102. package/workspace/public/pm/cozy-today-view.js +76 -0
  103. package/workspace/public/pm/cozy-viewer.js +66 -18
  104. package/workspace/public/pm/home-app.js +29 -6
  105. package/workspace/public/pm/home-ini.js +39 -7
  106. package/workspace/public/pm/library-model.js +69 -0
  107. package/workspace/public/pm/library-open.js +34 -0
  108. package/workspace/public/pm/page-chat.js +16 -4
  109. package/workspace/public/pm/pop-sessions.js +65 -0
  110. package/workspace/public/pm/pop-work-model.js +335 -0
  111. package/workspace/public/pm/premium-board.js +137 -11
  112. package/workspace/public/pm/premium-insights.js +14 -2
  113. package/workspace/public/pm/premium-library.js +122 -0
  114. package/workspace/public/pm/premium-shell.js +1 -1
  115. package/workspace/public/premium-board.html +1 -0
  116. package/workspace/public/premium-events.html +42 -0
  117. package/workspace/public/premium-library.html +31 -0
  118. package/workspace/public/premium-routine.html +31 -0
  119. package/workspace/public/today.html +50 -0
  120. package/workspace/ready-dash-ui-test.js +3 -1
  121. package/workspace/rename-test.js +2 -1
  122. package/workspace/run-tests.js +4 -1
  123. package/workspace/server.js +3 -2
  124. package/workspace/sort-order-test.js +2 -1
  125. package/workspace/split-merge-ui-test.js +3 -1
  126. package/workspace/stage-card-tasks-test.js +5 -3
  127. package/workspace/stage-card-test.js +2 -1
  128. package/workspace/task-card-test.js +2 -1
  129. package/workspace/task-delete-test.js +3 -1
  130. package/workspace/task-links-test.js +4 -2
  131. package/workspace/task-milestones-test.js +4 -2
  132. package/workspace/task-plans-test.js +3 -1
  133. package/workspace/task-press-test.js +3 -1
  134. package/workspace/task-views-test.js +10 -8
  135. package/workspace/test-lists/events-place.json +11 -0
  136. package/workspace/test-lists/library-place.json +9 -0
  137. package/workspace/test-lists/one-popup.json +9 -0
  138. package/workspace/test-lists/pop-work.json +9 -0
  139. package/workspace/test-lists/routine-place.json +9 -0
  140. package/workspace/test-lists/today-log.json +9 -0
  141. package/workspace/test-lists/work-view.json +9 -0
  142. package/workspace/timeline-holds-test.js +3 -1
  143. package/workspace/tk-tasks-test.js +3 -1
  144. package/workspace/viewer-trail-test.js +1 -1
  145. package/workspace/workflows-setup-test.js +1 -1
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+ /* classic-board: a browser-test helper. On a desk the Board page draws Work, one list with its timeline (public/pm/bd-work.js, initiative
3
+ * work-one-view), in place of the four views (List, By stage, Track, Timeline). A suite written for the four views wraps its browser with
4
+ * this: every context it makes starts with localStorage pmos.work.classic = 1, which keeps the four views on a desk, unless the suite set the
5
+ * key itself. It is a test seam, not a choice in the product: the phone and the narrow form keep the four views anyway. */
6
+ function classicBoard(browser) {
7
+ const make = browser.newContext.bind(browser);
8
+ browser.newContext = async (...a) => {
9
+ const ctx = await make(...a);
10
+ await ctx.addInitScript(() => { try { if (localStorage.getItem('pmos.work.classic') == null) localStorage.setItem('pmos.work.classic', '1'); } catch { /* no storage */ } });
11
+ return ctx;
12
+ };
13
+ return browser;
14
+ }
15
+ module.exports = { classicBoard };
@@ -0,0 +1,216 @@
1
+ 'use strict';
2
+ /* lib/events-place.js — Events, the place for everything with a date (slice 6 of the six-place navigation, initiative events-place; board 2,
3
+ * StEvPlan, on Exploring 2, page "Navigation: Today, Work, Goals, Events, Library, Routine").
4
+ *
5
+ * build(input) → { today, items, later } PURE. No I/O and no clock: `today` comes in as 'YYYY-MM-DD'.
6
+ * shortDay(day, today) · daysBetween(a, b) · KINDS · DROP_DAYS · WINDOW_DAYS · MEET_DAYS
7
+ *
8
+ * INPUT (plain data that lib/routes-events-place.js reads from the routes and files that already exist):
9
+ * boards [{ ws, id, name, rows }] every product's Board model (lib/board-premium.js): the open rows, each with `milestones` (◇ tasks with a
10
+ * due day, PMOS and Jira), `tasks` (the PMOS tasks), `end` (the plan end), `stage`, `status`, `forecast`
11
+ * meetings [{ id, at, end, title, initiative }] lib/calendar-events.js readAll
12
+ * schedules [{ id, name, cadence, next }] the enabled report schedules, with the day each fires next ('YYYY-MM-DD')
13
+ * drafts [{ ws, cadence, slot, title? }] report drafts that wait to be issued (lib/report-needs.js reportsOf: a draft, not issued)
14
+ * own [{ id, title, due, done }] the PM's own items (lib/pm-items.js)
15
+ * marks { fixed: Set<key>, declined: Set<sig> } the PM's fixed dates and the suggestions they said no to (lib/routes-events-place.js)
16
+ *
17
+ * AN ITEM: { key, kind, date, time, until, title, line, product, work, task, own, jira, fixed, canFix, editable, tone, days, group, suggest, act }
18
+ * kind milestone (a ◇ task, or the plan end of an initiative that has no open milestone) · task · report · meeting
19
+ * line the second line, which names the kind: "Delivery milestone: Deliver · Tender new CIAM", "Task due · …", "Report goes out", …
20
+ * group late (before today, not done) · today · coming (the next WINDOW_DAYS days; a meeting the next MEET_DAYS) · later
21
+ * tone late · risk (a milestone of an initiative at risk, or whose Jira forecast says it will miss) · ''
22
+ * suggest { op: done | move | drop, to?, with?, text, why, sig } or null. What PMOS suggests; the PM says yes (✓) or no (✕).
23
+ *
24
+ * THE RULES OF A SUGGESTION. A suggestion is made only from a record; PMOS does not invent a date.
25
+ * done a late PMOS item whose stage is behind the stage its initiative is in now: "It looks done. Mark it done".
26
+ * drop a late task, not a milestone, DROP_DAYS days late or more: "Drop it".
27
+ * move a late PMOS item: to the day the Jira forecast gives (a milestone), else to the plan end when that is later than today.
28
+ * A milestone whose stage has a task that moves later moves with it: "Moves with <task>, to <day>".
29
+ * Coming up: only a milestone at risk, to the day the Jira forecast gives.
30
+ * never a fixed date is never offered a new date (done and drop still are). A Jira item and a plan end get no suggestion: no route here writes
31
+ * them, and pressing the row opens the work. A suggestion the PM said no to (its sig is in marks.declined) does not come back. */
32
+ const BP = require('./board-premium.js');
33
+
34
+ const KINDS = Object.freeze(['milestone', 'task', 'report', 'meeting']);
35
+ const DROP_DAYS = 28;
36
+ const WINDOW_DAYS = 30;
37
+ const MEET_DAYS = 7;
38
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
39
+ const CLOSED = /^(done|won't do|archived|cancelled)$/i;
40
+ const MINE = /^(pm|me|you)$/i;
41
+
42
+ const isDay = (s) => typeof s === 'string' && /^\d{4}-\d{2}-\d{2}/.test(s) && !Number.isNaN(Date.parse(s.slice(0, 10) + 'T00:00:00Z'));
43
+ const day10 = (s) => String(s).slice(0, 10);
44
+ const ms = (d) => Date.parse(day10(d) + 'T00:00:00Z');
45
+ /** Days from a to b (b later: positive). */
46
+ const daysBetween = (a, b) => Math.round((ms(b) - ms(a)) / 86400000);
47
+ /** '25 Nov', or '3 Mar 2027' outside the year of today. */
48
+ function shortDay(d, today) {
49
+ if (!isDay(d)) return '';
50
+ const [y, m, dd] = day10(d).split('-').map(Number);
51
+ return dd + ' ' + MON[m - 1] + (today && String(y) !== String(today).slice(0, 4) ? ' ' + y : '');
52
+ }
53
+ const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
54
+ const cap = (s) => String(s || '').replace(/[-_]+/g, ' ').replace(/^./, (c) => c.toUpperCase());
55
+
56
+ /** The name of a stage key or name, from the row's own workflow when it has one. */
57
+ function stageName(r, sec) {
58
+ if (!sec) return '';
59
+ const own = (r.wfStages || []).find((s) => s && (s.key === sec || s.name === sec));
60
+ if (own && own.name) return own.name;
61
+ const k = BP.stepIndex(sec);
62
+ return k >= 0 ? BP.STEPS[k].label : cap(sec);
63
+ }
64
+ /** Is the stage `sec` behind the stage the initiative is in now? Only when both are known. */
65
+ function stagePast(r, sec) {
66
+ if (!sec || !r.stage) return false;
67
+ const own = (r.wfStages || []).map((s) => s && s.key);
68
+ const ownNames = (r.wfStages || []).map((s) => s && s.name);
69
+ const i = own.indexOf(sec) >= 0 ? own.indexOf(sec) : ownNames.indexOf(sec);
70
+ const j = own.indexOf(r.stage) >= 0 ? own.indexOf(r.stage) : ownNames.indexOf(r.stage);
71
+ if (i >= 0 && j >= 0) return i < j;
72
+ const a = BP.stepIndex(sec), b = BP.stepIndex(r.stage, r.cat);
73
+ return a >= 0 && b >= 0 && a < b;
74
+ }
75
+ const atRisk = (r) => r.status === 'at risk' || r.status === 'late' || !!(r.forecast && (r.forecast.state === 'at-risk' || r.forecast.state === 'will-miss'));
76
+
77
+ function groupOf(kind, date, today) {
78
+ const d = daysBetween(today, date);
79
+ if (d < 0) return 'late';
80
+ if (d === 0) return 'today';
81
+ return d <= (kind === 'meeting' ? MEET_DAYS : WINDOW_DAYS) ? 'coming' : 'later';
82
+ }
83
+
84
+ function build(input = {}) {
85
+ const today = isDay(input.today) ? day10(input.today) : null;
86
+ if (!today) return { today: null, items: [], later: { count: 0, next: null } };
87
+ const marks = input.marks || {};
88
+ const fixedSet = marks.fixed instanceof Set ? marks.fixed : new Set(marks.fixed || []);
89
+ const declined = marks.declined instanceof Set ? marks.declined : new Set(marks.declined || []);
90
+ const items = [];
91
+ const put = (x) => {
92
+ if (!isDay(x.date)) return;
93
+ x.date = day10(x.date);
94
+ x.days = daysBetween(today, x.date);
95
+ x.group = groupOf(x.kind, x.date, today);
96
+ if (x.kind === 'meeting' && x.group === 'late') return; // a meeting that has passed is not late
97
+ if (x.kind === 'report' && x.group === 'late' && !x.draft) return;
98
+ x.fixed = !!(x.canFix && fixedSet.has(x.key));
99
+ x.tone = x.group === 'late' ? 'late' : x.tone || '';
100
+ items.push(x);
101
+ };
102
+
103
+ for (const b of input.boards || []) {
104
+ const product = clip(b.name || b.ws || '', 80);
105
+ for (const r of b.rows || []) {
106
+ if (!r || !r.id || r.closed || r.status === 'done' || r.status === 'cancelled' || r.status === 'on hold') continue;
107
+ const work = { id: r.id, title: clip(r.title || r.id, 140), ws: b.ws || '', board: b.id || '' };
108
+ const risk = atRisk(r);
109
+ const open = (r.milestones || []).filter((m) => m && !m.done && isDay(m.date));
110
+ for (const m of open) {
111
+ const st = stageName(r, m.sec);
112
+ put({ key: 'ms:' + work.ws + '|' + work.board + '|' + m.id, kind: 'milestone', date: m.date, time: null, until: null, title: clip(m.name, 140),
113
+ line: 'Delivery milestone' + (st ? ': ' + st : '') + ' · ' + work.title, product, work, task: m.jira ? null : { uid: m.id, ws: work.ws, board: work.board },
114
+ own: null, jira: !!m.jira, canFix: true, editable: !m.jira, tone: risk ? 'risk' : '', sec: m.sec || '', row: r, act: null });
115
+ }
116
+ // the plan end stands for the delivery when the initiative names no open milestone (as Work's "Plan end")
117
+ if (!open.length && isDay(r.end)) {
118
+ put({ key: 'end:' + work.ws + '|' + work.board + '|' + r.id, kind: 'milestone', date: r.end, time: null, until: null, title: work.title,
119
+ line: 'Delivery milestone: Plan end · ' + product, product, work, task: null, own: null, jira: false, canFix: true, editable: false, planEnd: true,
120
+ tone: risk ? 'risk' : '', sec: '', row: r, act: null });
121
+ }
122
+ for (const t of r.tasks || []) {
123
+ if (!t || !t.uid || t.milestone || CLOSED.test(String(t.status || '')) || !isDay(t.end)) continue;
124
+ if (t.owner && !MINE.test(String(t.owner).trim())) continue; // the PM's tasks: no owner, or the PM
125
+ const sec = typeof t.section === 'string' && t.section ? t.section : t.from && t.from.stage ? t.from.stage : '';
126
+ put({ key: 'task:' + work.ws + '|' + work.board + '|' + t.uid, kind: 'task', date: t.end, time: null, until: null, title: clip(t.title, 140),
127
+ line: 'Task due · ' + work.title, product, work, task: { uid: t.uid, ws: work.ws, board: work.board, status: t.status || 'To do' }, own: null, jira: false,
128
+ canFix: true, editable: true, sec, row: r, act: null });
129
+ }
130
+ }
131
+ }
132
+
133
+ for (const o of input.own || []) {
134
+ if (!o || !o.id || o.done || !isDay(o.due)) continue;
135
+ put({ key: 'own:' + o.id, kind: 'task', date: o.due, time: null, until: null, title: clip(o.title, 140), line: 'Your task', product: '', work: null, task: null,
136
+ own: String(o.id), jira: false, canFix: true, editable: true, sec: '', row: null, act: null });
137
+ }
138
+
139
+ const draftOf = new Map();
140
+ for (const d of input.drafts || []) if (d && d.cadence && !draftOf.has(d.cadence)) draftOf.set(d.cadence, d);
141
+ // a draft whose report goes out today is said on that report's row, not on a row of its own
142
+ const outToday = new Set((input.schedules || []).filter((s) => s && isDay(s.next) && day10(s.next) === today).map((s) => s.cadence));
143
+ for (const d of draftOf.values()) {
144
+ if (outToday.has(d.cadence)) continue;
145
+ put({ key: 'draft:' + (d.ws || '') + '|' + d.cadence + '|' + (d.slot || ''), kind: 'report', date: today, time: null, until: null, title: clip(d.title || cap(d.cadence) + ' report', 120),
146
+ line: 'Report draft' + (isDay(d.slot) && day10(d.slot) !== today ? ' of ' + shortDay(d.slot, today) : '') + ' waits for you to issue it', product: '', work: null, task: null, own: null, jira: false, canFix: false, editable: false, draft: true,
147
+ act: { label: 'Read the draft', href: '/premium-intelligence.html?tab=library' } });
148
+ }
149
+ for (const s of input.schedules || []) {
150
+ if (!s || !isDay(s.next)) continue;
151
+ const name = clip(s.name || cap(s.cadence) + ' report', 120);
152
+ const d = draftOf.get(s.cadence);
153
+ put({ key: 'rep:' + (s.id || s.cadence) + ':' + day10(s.next), kind: 'report', date: s.next, time: null, until: null, title: name,
154
+ line: 'Report goes out' + (s.cadence ? ' · ' + cap(s.cadence) : '') + (d && daysBetween(today, s.next) === 0 ? ' · the draft waits for you' : ''), product: '', work: null, task: null, own: null, jira: false, canFix: false, editable: false,
155
+ act: d && daysBetween(today, s.next) === 0 ? { label: 'Read the draft', href: '/premium-intelligence.html?tab=library' } : null });
156
+ }
157
+
158
+ for (const e of input.meetings || []) {
159
+ if (!e || !e.title || typeof e.at !== 'string' || !isDay(e.at)) continue;
160
+ const time = /T(\d{2}:\d{2})/.exec(e.at);
161
+ const until = typeof e.end === 'string' && e.end.slice(0, 10) === e.at.slice(0, 10) ? /T(\d{2}:\d{2})/.exec(e.end) : null;
162
+ const work = e.initiative ? { id: String(e.initiative), title: '', ws: '', board: '' } : null;
163
+ put({ key: 'mtg:' + (e.id || e.at + '|' + e.title), kind: 'meeting', date: e.at, time: time ? time[1] : null, until: until ? until[1] : null, title: clip(e.title, 140),
164
+ line: time ? 'Meeting' : 'All day', product: '', work, task: null, own: null, jira: false, canFix: false, editable: false, act: null });
165
+ }
166
+
167
+ // the work a meeting is about, named from the Board rows
168
+ const names = new Map();
169
+ for (const x of items) if (x.work && x.work.title) names.set(x.work.id, x.work);
170
+ for (const x of items) if (x.kind === 'meeting' && x.work) { const w = names.get(x.work.id); if (w) { x.work = { ...w }; x.line = (x.time ? 'Meeting' : 'All day') + ' · ' + w.title; } }
171
+
172
+ // suggestions, first from the item's own record
173
+ const say = (x, s) => {
174
+ const sig = x.key + '|' + s.op + '|' + (s.to || '');
175
+ return declined.has(sig) ? null : { ...s, sig };
176
+ };
177
+ for (const x of items) {
178
+ x.suggest = null;
179
+ if (x.kind !== 'milestone' && x.kind !== 'task') continue;
180
+ if (x.jira || x.planEnd) continue;
181
+ const r = x.row;
182
+ if (x.group === 'late') {
183
+ if (r && x.sec && stagePast(r, x.sec)) { x.suggest = say(x, { op: 'done', text: 'It looks done. Mark it done', why: 'Its stage, ' + stageName(r, x.sec) + ', is behind the stage the work is in now, ' + (r.stage || '') + '.' }); continue; }
184
+ if (x.kind === 'task' && -x.days >= DROP_DAYS) { x.suggest = say(x, { op: 'drop', text: 'Drop it', why: 'It is ' + (-x.days) + ' days late.' }); continue; }
185
+ if (x.fixed || !r) continue;
186
+ const fc = x.kind === 'milestone' && r.forecast && isDay(r.forecast.likely) && daysBetween(today, r.forecast.likely) > 0 ? day10(r.forecast.likely) : null;
187
+ if (fc) { x.suggest = say(x, { op: 'move', to: fc, text: 'Move to ' + shortDay(fc, today), why: 'The Jira forecast says the work lands about ' + shortDay(fc, today) + '.' }); continue; }
188
+ if (isDay(r.end) && daysBetween(today, r.end) > 0) x.suggest = say(x, { op: 'move', to: day10(r.end), text: 'Move to ' + shortDay(r.end, today) + ', the plan end', why: 'The plan of ' + x.work.title + ' ends ' + shortDay(r.end, today) + '.' });
189
+ } else if (x.group === 'coming' && x.kind === 'milestone' && x.tone === 'risk' && !x.fixed && r && r.forecast && isDay(r.forecast.likely) && daysBetween(x.date, r.forecast.likely) > 0) {
190
+ const fc = day10(r.forecast.likely);
191
+ x.suggest = say(x, { op: 'move', to: fc, text: 'Move to ' + shortDay(fc, today), why: 'The Jira forecast says the work lands about ' + shortDay(fc, today) + ', after this date.' });
192
+ }
193
+ }
194
+ // then a milestone moves with a task of its stage that moves later
195
+ for (const x of items) {
196
+ if (x.kind !== 'milestone' || x.jira || x.planEnd || x.fixed || !x.sec || (x.group !== 'late' && x.tone !== 'risk')) continue;
197
+ if (x.suggest && x.suggest.op === 'done') continue;
198
+ let best = null;
199
+ for (const t of items) {
200
+ if (t.kind !== 'task' || !t.work || !x.work || t.work.id !== x.work.id || t.work.ws !== x.work.ws || t.sec !== x.sec) continue;
201
+ if (!t.suggest || t.suggest.op !== 'move' || daysBetween(x.date, t.suggest.to) <= 0) continue;
202
+ if (!best || t.suggest.to > best.suggest.to) best = t;
203
+ }
204
+ if (!best || (x.suggest && x.suggest.to && x.suggest.to > best.suggest.to)) continue;
205
+ const s = say(x, { op: 'move', to: best.suggest.to, with: best.title, text: 'Moves with ' + best.title + ', to ' + shortDay(best.suggest.to, today), why: best.title + ' is a task of the same stage, and it moves to ' + shortDay(best.suggest.to, today) + '.' });
206
+ if (s) x.suggest = s;
207
+ }
208
+
209
+ const ORDER = { late: 0, today: 1, coming: 2, later: 3 };
210
+ items.sort((a, b) => ORDER[a.group] - ORDER[b.group] || a.date.localeCompare(b.date) || String(a.time || '').localeCompare(String(b.time || '')) || a.title.localeCompare(b.title));
211
+ for (const x of items) { delete x.row; }
212
+ const ahead = items.filter((x) => x.group === 'later' && x.kind === 'milestone');
213
+ return { today, items, later: { count: ahead.length, next: ahead[0] ? { date: ahead[0].date, title: ahead[0].title, key: ahead[0].key } : null } };
214
+ }
215
+
216
+ module.exports = { build, shortDay, daysBetween, KINDS, DROP_DAYS, WINDOW_DAYS, MEET_DAYS };
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+ /* library-items.js — what was made, as one list (initiative library-place, slice 7 of the six-place navigation; boards StLibrary,
3
+ * StLibMeetings, StLibDocs on Exploring 2). PURE: no file, no clock, no network.
4
+ *
5
+ * build({ products, notes }) → [item] newest first
6
+ * products: [{ ws, name, titles: Map|{} initiative id → title, files, links, rounds }]
7
+ * files lib/doc-library.js library().files that an initiative owns: [{ path, title, category, date, initiative }]
8
+ * links lib/custom-docs.js rows with a link: [{ id, scope, title, link: { kind, url }, at }]
9
+ * rounds prototype rounds: [{ id, ini, name, at, made, board }] (lib/idle-lab.js roundsOf, named by the round's brief)
10
+ * notes: lib/notes.js list().notes, with `came` (rowOf)
11
+ * ITEM { id, kind, name, sub, kindText, type, came, about: { ws, product, ini, title }, updated, held, open }
12
+ * kind 'doc' | 'link' | 'meeting' | 'proto'
13
+ * kindText the Kind column: Document · Link · Confluence · Meeting notes · Prototype
14
+ * type the Type column when only documents show (Spec, Done test, Research …; a link says where it lives)
15
+ * came the "Came out of it" column of a meeting: '2 decisions · 3 tasks' ('' for a private note)
16
+ * updated ISO date or time of the last change; held: the meeting's start
17
+ * open what the page's opener needs: { doc: { ws, path } } | { url } | { note, ws } | { proto: { ws, board, id } }
18
+ * narrow(items, { ws, initiative }) → the items of one product or one initiative (slice 3's Artefacts table reads ?initiative=)
19
+ * Reports are not here (they repeat, so they live in Routine); Lab findings are not here (they go to Today as suggestions). */
20
+
21
+ /* the Type of a document, from the category doc-library gives it */
22
+ const TYPE = { spec: 'Spec', eval: 'Done test', res: 'Research', exp: 'Explainer', dec: 'Decision', know: 'Knowledge', guide: 'Guide', proto: 'Prototype brief' };
23
+ const { shortTitle: short } = require('./doc-library.js'); // a pure function of that module
24
+ const plural = (n, one, many) => (n === 1 ? '1 ' + one : n + ' ' + many);
25
+
26
+ /** "2 decisions · 3 tasks", "No decision · 2 tasks", '' when nothing came out of it (or the note is private). */
27
+ function cameText(c) {
28
+ if (!c) return '';
29
+ const d = Number(c.decisions) || 0, t = Number(c.tasks) || 0;
30
+ if (!d && !t) return '';
31
+ return (d ? plural(d, 'decision', 'decisions') : 'No decision') + ' · ' + (t ? plural(t, 'task', 'tasks') : 'no task');
32
+ }
33
+ const get = (m, k) => (!k ? '' : m instanceof Map ? m.get(k) || '' : (m && m[k]) || '');
34
+ const iniOfScope = (scope) => { const m = /^initiative:(.+)$/.exec(String(scope || '')); return m ? m[1] : null; };
35
+
36
+ function build({ products = [], notes = [] } = {}) {
37
+ const out = [];
38
+ const byWs = new Map(products.map((p) => [p.ws, p]));
39
+ // About names the initiative short, as the Board does ("Tender new CIAM", not the PRD's full title); no initiative: the product
40
+ const about = (p, ini, title) => ({ ws: p ? p.ws : null, product: p ? p.name : '', ini: ini || null, title: (ini && (short(title || get(p && p.titles, ini)) || ini)) || (p ? p.name : '') });
41
+ for (const p of products) {
42
+ for (const f of p.files || []) {
43
+ if (!f || !f.path || !f.initiative || f.category === 'ini') continue; // the initiative record is the work itself, not a thing made for it
44
+ const proto = f.category === 'proto';
45
+ out.push({ id: 'doc:' + p.ws + ':' + f.path, kind: proto ? 'proto' : 'doc', name: f.title || f.path.split('/').pop(), sub: '',
46
+ kindText: proto ? 'Prototype' : 'Document', type: /(^|\/)done-tests\//.test(f.path) ? 'Done test' : TYPE[f.category] || 'Document', came: '', about: about(p, f.initiative), updated: f.date || null,
47
+ held: null, open: { doc: { ws: p.ws, path: f.path } } });
48
+ }
49
+ for (const l of p.links || []) {
50
+ if (!l || !l.link || !l.link.url) continue;
51
+ const ini = iniOfScope(l.scope);
52
+ out.push({ id: 'link:' + p.ws + ':' + l.id, kind: 'link', name: l.title, sub: '', kindText: 'Link · ' + l.link.kind, type: 'Link · ' + l.link.kind, came: '',
53
+ about: about(p, ini), updated: l.at || null, held: null, open: { url: l.link.url } });
54
+ }
55
+ for (const r of p.rounds || []) {
56
+ if (!r || !r.id) continue;
57
+ out.push({ id: 'proto:' + p.ws + ':' + r.id, kind: 'proto', name: r.name || 'Prototype', sub: '', kindText: 'Prototype', type: 'Prototype',
58
+ came: r.made ? plural(r.made, 'version', 'versions') : '', about: about(p, r.ini), updated: r.at || null, held: null,
59
+ open: { proto: { ws: p.ws, board: r.board || '', id: r.id } } });
60
+ }
61
+ }
62
+ for (const n of notes) {
63
+ if (!n || !n.id) continue;
64
+ const ini = n.initiative && n.initiative.id ? n.initiative : null;
65
+ const p = byWs.get((ini && ini.ws) || n.ws) || null;
66
+ const held = (n.meeting && n.meeting.start) || n.created_at || null;
67
+ out.push({ id: 'meeting:' + n.id, kind: 'meeting', name: n.title || 'Untitled note', sub: '', kindText: 'Meeting notes', type: 'Meeting notes',
68
+ came: n.private ? '' : cameText(n.came), about: ini ? about(p, ini.id, ini.title) : about(p, null), updated: n.updated_at || held, held,
69
+ open: { note: n.id, ws: (p && p.ws) || n.ws || '' } });
70
+ }
71
+ return out.sort((a, b) => String(b.updated || '').localeCompare(String(a.updated || '')) || a.name.localeCompare(b.name));
72
+ }
73
+
74
+ function narrow(items, { ws, initiative } = {}) {
75
+ return items.filter((x) => (!ws || x.about.ws === ws) && (!initiative || x.about.ini === initiative));
76
+ }
77
+
78
+ module.exports = { build, narrow, cameText, TYPE };
@@ -203,7 +203,12 @@ function rowOf(n, now = Date.now(), resumeMs = RESUME_MS) {
203
203
  // the meeting time so far (a paused note's clock) and how many statements differ from a repository file (the Notes menu)
204
204
  meeting_ms: n.recorded_from ? heardMs(n, now) : 0, conflicts: n.private ? 0 : conflictsOf(n).length,
205
205
  // a private note shows its title on the calendar and the initiative, never its summary
206
- summary_lines: n.private ? [] : summaryLines(n), ...stateFields(n, now, resumeMs) };
206
+ summary_lines: n.private ? [] : summaryLines(n), came: n.private ? null : cameOf(n), ...stateFields(n, now, resumeMs) };
207
+ }
208
+ /** What came out of a meeting (Library's "Came out of it", initiative library-place): the decisions and tasks among the agent's bullets. */
209
+ function cameOf(n) {
210
+ const b = (n.bullets || []).filter((x) => x && !x.dropped);
211
+ return { decisions: b.filter((x) => x.cat === 'decision').length, tasks: b.filter((x) => x.cat === 'action').length };
207
212
  }
208
213
  /** The statements of a note that a repository file says otherwise: transcript lines, the agent's bullets and the PM's
209
214
  * highlights whose check verdict is 'differs'. → [{ text, doc, line, t, from }] */
@@ -45,11 +45,13 @@ const MODULES = Object.freeze([
45
45
  'routes-my-work', // initiative my-work: the ranked list of work assigned to the PM, the brief, Read again
46
46
  'routes-intake', // planning-flows run 4: one-line intake draft (drafts only)
47
47
  'routes-pm-items', // planning-flows runs 1-2: the PM's own items and jobs to be done (add, edit, remove, undo)
48
+ 'routes-today-log', // six-place navigation slice 5: Today's log, the PM's own entries and marks (today-log/log.jsonl; page-press POST)
48
49
  'routes-runs', // console3 agent surfaces: runs grouped for the sessions panel, PM answers, corrections
49
50
  'routes-doc-health', // console3 B2: the six document health checks, recomputed from text
50
51
  'routes-outbox', // console3 B3: the outbox queue, hash-bound confirm (no channel connected)
51
52
  'routes-waiting', // home-your-move-waiting: Waiting on others, derived from records, with its exit rule
52
53
  'routes-calendar-views', // console3 C2: Day/Week/Month/Quarter/Year cells, Gantt and the strategy lens (read-only)
54
+ 'routes-events-place', // events-place (nav slice 6): every date PMOS holds, grouped Late / Today / Coming up, and the PM's fixed marks and noes (events/marks.jsonl; page-press POST)
53
55
  'routes-briefing', // console3 C1: the day-part Briefing cards from the signal engine (read-only)
54
56
  'routes-briefing-premium', // briefing-premium: the premium Briefing's page model from repository state (read-only)
55
57
  'routes-my-work-premium', // briefing-premium-work: the premium My work page's model from the Work page's own list (read-only)
@@ -110,7 +112,9 @@ const MODULES = Object.freeze([
110
112
  'routes-report-setups', // report-workspace: recurring reports, the Ask box, the finder, the report documents and their export (report-setups.jsonl)
111
113
  'routes-artefacts', // R18 (D107): the seven artefacts, read-only, and the lossless carry of the older records (artefacts.jsonl)
112
114
  'routes-core-docs', // core-documents: the core documents of each level, Draft it (a core-doc run), Issue it and Drop (core-docs.jsonl)
115
+ 'routes-pop-work', // popup-work-contents (slice 3): the summary of an initiative changed or confirmed in place (initiative-writer setDescription; page-press POST)
113
116
  'routes-custom-docs', // briefing-premium-adddoc: the documents the PM adds beyond the core set, Add a document (custom-docs.jsonl)
117
+ 'routes-library', // library-place (slice 7 of the six-place navigation): GET /api/library-items, what was made, every product (read only)
114
118
  'routes-premium-dashboards', // briefing-premium-reports: the dashboards the PM makes on premium Insights (premium-dashboards.jsonl; page-press POST save)
115
119
  '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)
116
120
  '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)
@@ -0,0 +1,166 @@
1
+ 'use strict';
2
+ /* routes-events-place.js — the Events place (slice 6 of the six-place navigation, initiative events-place).
3
+ *
4
+ * GET /api/events-place → 200 { ok, state: 'ready', today, items, later, missing } | 202 { ok, state: 'reading' }
5
+ * every date PMOS holds, as lib/events-place.js build() makes it: each product's Board model (GET /api/board-premium, the route the
6
+ * Board reads: milestones, plan ends, tasks, forecasts), the calendar (lib/calendar-events.js), the report schedules and the drafts
7
+ * that wait (lib/report-needs.js), and the PM's own items (lib/pm-items.js). While a Board is still being read the answer is 202 and
8
+ * the page asks again. A source that cannot be read is named in `missing`, never read as nothing.
9
+ * POST /api/events-place/mark { key, fixed } → { ok } a date is fixed (true) or not (false): Events never offers it a new date
10
+ * POST /api/events-place/mark { sig, no } → { ok } the PM said no to a suggestion (no: true), or took the no back (no: false)
11
+ *
12
+ * STATE. <runtime>/events/marks.jsonl, append-only, one line per press: { at, by, kind: fixed | unfixed | no | unno, key | sig }. The fold
13
+ * keeps the last line of each key or sig. Writes pass pm-guard requirePagePress: the page only. Every other write of Events (✓ on a
14
+ * suggestion, a new day, +) goes through the routes that already make it: /api/boards/tasks/state, /api/boards/tasks/edit, /api/pm-items/*. */
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+ const EP = require('./events-place.js');
18
+
19
+ const MAX_LEN = 400;
20
+ const pad = (n) => String(n).padStart(2, '0');
21
+ const localDay = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
22
+ const reason = (e) => String((e && e.message) || e).slice(0, 160);
23
+
24
+ /* ── the marks ── */
25
+ const marksFile = (runtimeDir) => path.join(runtimeDir, 'events', 'marks.jsonl');
26
+ /** The marks folded: { fixed: Set<key>, declined: Set<sig> }. PURE over the lines. */
27
+ function foldMarks(lines) {
28
+ const fixed = new Map(), no = new Map();
29
+ for (const l of lines || []) {
30
+ if (!l || typeof l !== 'object') continue;
31
+ if ((l.kind === 'fixed' || l.kind === 'unfixed') && typeof l.key === 'string') fixed.set(l.key, l.kind === 'fixed');
32
+ if ((l.kind === 'no' || l.kind === 'unno') && typeof l.sig === 'string') no.set(l.sig, l.kind === 'no');
33
+ }
34
+ return { fixed: new Set([...fixed].filter(([, v]) => v).map(([k]) => k)), declined: new Set([...no].filter(([, v]) => v).map(([k]) => k)) };
35
+ }
36
+ function readMarks(runtimeDir) {
37
+ let text = '';
38
+ try { text = fs.readFileSync(marksFile(runtimeDir), 'utf8'); } catch { return foldMarks([]); }
39
+ return foldMarks(text.split('\n').filter(Boolean).map((s) => { try { return JSON.parse(s); } catch { return null; } }));
40
+ }
41
+ /** One mark line from a page press body, or { error }. PURE. */
42
+ function markLine(body, by, at) {
43
+ const b = body && typeof body === 'object' && !Array.isArray(body) ? body : {};
44
+ const okStr = (s) => typeof s === 'string' && s.length > 0 && s.length <= MAX_LEN;
45
+ if (okStr(b.key) && typeof b.fixed === 'boolean') return { at, by, kind: b.fixed ? 'fixed' : 'unfixed', key: b.key };
46
+ if (okStr(b.sig) && typeof b.no === 'boolean') return { at, by, kind: b.no ? 'no' : 'unno', sig: b.sig };
47
+ return { error: 'send { key, fixed: true | false } or { sig, no: true | false }' };
48
+ }
49
+
50
+ /* ── the readers ── */
51
+ async function via(mod, pathAndQuery, req, ctx) {
52
+ let out = { status: 500, body: null };
53
+ const c = Object.assign({}, ctx, { json: (res, obj, code) => { out = { status: code || 200, body: obj }; } });
54
+ const handled = await mod.handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, new URL('http://local' + pathAndQuery), c);
55
+ return handled === false ? { status: 404, body: null } : out;
56
+ }
57
+ /** Every product's Board model, the way the Board's All products reads them: { state: 'reading' } | { boards, missing }. */
58
+ async function readBoards(req, ctx) {
59
+ const BPR = require('./routes-board-premium.js');
60
+ const first = await via(BPR, '/api/board-premium', req, ctx);
61
+ if (first.status === 202 || (first.body && first.body.state === 'reading')) return { state: 'reading' };
62
+ if (!first.body || !first.body.ok || !first.body.model) return { boards: [], missing: ['the boards'] };
63
+ const home = first.body.model;
64
+ const nameOf = (m) => (m.board && (m.board.product || m.board.name)) || '';
65
+ const rowsOf = (m) => (m.initiatives && m.initiatives.list && m.initiatives.list.rows) || [];
66
+ const boards = [{ ws: home.board.ws || '', id: home.board.id || '', name: nameOf(home), rows: rowsOf(home) }];
67
+ const missing = [];
68
+ const others = (home.board.switcher || []).filter((b) => !(b.ws === home.board.ws && b.id === home.board.id));
69
+ const q = (b) => '?ws=' + encodeURIComponent(b.ws) + '&board=' + encodeURIComponent(b.id);
70
+ const got = await Promise.all(others.map((b) => via(BPR, '/api/board-premium' + q(b), req, ctx)));
71
+ if (got.some((g) => g.status === 202 || (g.body && g.body.state === 'reading'))) return { state: 'reading' };
72
+ got.forEach((g, i) => {
73
+ if (g.body && g.body.ok && g.body.model) boards.push({ ws: others[i].ws, id: others[i].id, name: nameOf(g.body.model) || others[i].name, rows: rowsOf(g.body.model) });
74
+ else missing.push((others[i].name || others[i].ws) + ' board');
75
+ });
76
+ return { boards, missing };
77
+ }
78
+ /** The enabled report schedules, each with the local day it fires next. */
79
+ function readSchedules(now) {
80
+ const RN = require('./report-needs.js');
81
+ const logic = require('./schedule-logic.js');
82
+ const out = [];
83
+ for (const s of RN.readSchedules()) {
84
+ if (!s || !s.enabled) continue;
85
+ const cadence = RN.cadenceOfSchedule(s);
86
+ if (!cadence) continue;
87
+ const next = logic.nextRun(s, now);
88
+ if (!next) continue;
89
+ out.push({ id: String(s.id || s.name || cadence), name: s.name || '', cadence, next: localDay(new Date(next)) });
90
+ }
91
+ return out;
92
+ }
93
+ /** The newest report of each cadence when it is a draft not issued: a draft that waits for the PM. */
94
+ function readDrafts(roots) {
95
+ const RN = require('./report-needs.js');
96
+ const out = [];
97
+ for (const { ws, root } of roots) {
98
+ const seen = new Set();
99
+ for (const r of RN.reportsOf(root).reports) { // newest slot first
100
+ if (/^scan-/.test(r.cadence) || seen.has(r.cadence)) continue;
101
+ seen.add(r.cadence);
102
+ if (r.status === 'draft' && !r.issued) { const fm = RN.frontmatter(path.join(root, r.path)); out.push({ ws, cadence: r.cadence, slot: r.slot, ...(fm.title ? { title: fm.title } : {}) }); }
103
+ }
104
+ }
105
+ return out;
106
+ }
107
+ function readOwn(runtimeDir) {
108
+ const P = require('./pm-items.js');
109
+ return P.fold(P.readLines(path.join(runtimeDir, 'pm-items', 'items.jsonl'))).map((o) => ({ id: o.id, title: o.title, due: o.due || null, done: !!o.done }));
110
+ }
111
+
112
+ /** The pure handler. deps: { today, readBoards() → { state } | { boards, missing }, readMeetings(), readSchedules(), readDrafts(boards), readOwn(),
113
+ * readMarks() }. A reader that throws names its source in `missing`. */
114
+ async function handle(deps) {
115
+ const b = await deps.readBoards();
116
+ if (b && b.state === 'reading') return { status: 202, body: { ok: true, state: 'reading' } };
117
+ const missing = [...((b && b.missing) || [])];
118
+ const boards = (b && b.boards) || [];
119
+ const tryRead = (name, fn, fallback) => { try { const v = fn(); return v == null ? fallback : v; } catch (e) { missing.push(name + ' (' + reason(e) + ')'); return fallback; } };
120
+ const meetings = tryRead('the calendar', () => deps.readMeetings(), []);
121
+ const schedules = tryRead('the report schedules', () => deps.readSchedules(), []);
122
+ const drafts = tryRead('the report drafts', () => deps.readDrafts(boards), []);
123
+ const own = tryRead('your items', () => deps.readOwn(), []);
124
+ const marks = tryRead('your marks', () => deps.readMarks(), { fixed: new Set(), declined: new Set() });
125
+ const model = EP.build({ today: deps.today, boards, meetings, schedules, drafts, own, marks });
126
+ return { status: 200, body: { ok: true, state: 'ready', today: model.today, items: model.items, later: model.later, missing } };
127
+ }
128
+
129
+ module.exports = {
130
+ foldMarks, markLine, handlePure: handle, readers: { readSchedules, readDrafts, readOwn, readMarks },
131
+ prefixes: ['/api/events-place'],
132
+ handle: async (req, res, url, ctx) => {
133
+ if (url.pathname === '/api/events-place/mark') {
134
+ if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
135
+ const got = await ctx.readJson(req);
136
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'the body must be JSON' }, 400); return true; }
137
+ const g = require('./pm-guard.js').requirePagePress(req, got.body);
138
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
139
+ if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'this server has no runtime folder, so the mark cannot be kept' }, 409); return true; }
140
+ const line = markLine(got.body, g.actor && g.actor.by ? g.actor.by : 'pm', new Date().toISOString());
141
+ if (line.error) { ctx.json(res, { ok: false, error: line.error }, 400); return true; }
142
+ try {
143
+ fs.mkdirSync(path.dirname(marksFile(ctx.runtimeDir)), { recursive: true });
144
+ fs.appendFileSync(marksFile(ctx.runtimeDir), JSON.stringify(line) + '\n');
145
+ } catch (e) { ctx.json(res, { ok: false, error: 'the mark could not be kept: ' + reason(e) }, 500); return true; }
146
+ ctx.json(res, { ok: true });
147
+ return true;
148
+ }
149
+ if (url.pathname !== '/api/events-place') return false;
150
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
151
+ const now = new Date();
152
+ try {
153
+ const out = await handle({
154
+ today: localDay(now),
155
+ readBoards: () => readBoards(req, ctx),
156
+ readMeetings: () => (ctx.runtimeDir ? require('./calendar-events.js').readAll(ctx.runtimeDir, { now: now.getTime() }) : []),
157
+ readSchedules: () => readSchedules(now),
158
+ readDrafts: (boards) => readDrafts([...new Set(boards.map((x) => x.ws))].map((ws) => ({ ws, w: ctx.getWs ? ctx.getWs(ws || null) : null })).filter((x) => x.w && x.w.root).map((x) => ({ ws: x.ws, root: x.w.root }))),
159
+ readOwn: () => (ctx.runtimeDir ? readOwn(ctx.runtimeDir) : []),
160
+ readMarks: () => (ctx.runtimeDir ? readMarks(ctx.runtimeDir) : foldMarks([])),
161
+ });
162
+ ctx.json(res, out.body, out.status);
163
+ } catch (e) { ctx.json(res, { ok: false, state: 'error', error: reason(e) }, 500); }
164
+ return true;
165
+ },
166
+ };
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+ /* routes-library.js — GET /api/library-items[?ws=<id>&initiative=<id>] (initiative library-place, slice 7 of the six-place navigation).
3
+ *
4
+ * The Library place reads every product; slice 3's Artefacts table reads one initiative. → { ok, items } (lib/library-items.js ITEM),
5
+ * newest first. READ ONLY: it folds what is already recorded and writes nothing.
6
+ * files lib/doc-library.js library() — the tracked markdown files, attributed to the initiative that owns them (server.js initiativeIndex)
7
+ * links lib/custom-docs.js — the links the PM added to an initiative (Confluence, Google Docs, Google Slides)
8
+ * rounds lib/idle-lab.js roundsOf over lib/proposals.js — the prototype rounds of each initiative
9
+ * notes lib/notes.js list() — the meeting notes of the runtime directory
10
+ * A source that cannot be read is left out, and the answer says which in `unread` (the page says nothing about it unless every source failed).
11
+ * (/api/library is the old file tree of one workspace, server.js; this route is a different one.) */
12
+ const Items = require('./library-items.js');
13
+
14
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/;
15
+
16
+ function titlesOf(w, ctx) {
17
+ const m = new Map();
18
+ try { const b = require('./routes-boards.js').baseRows(w, ctx); if (b && b.ok) for (const r of b.rows || []) if (r && r.id) m.set(r.id, r.title || r.id); } catch { /* none yet */ }
19
+ return m;
20
+ }
21
+ function ownersOf(ctx, root) {
22
+ const own = new Map();
23
+ if (typeof ctx.initiativeIndex !== 'function') return own;
24
+ for (const g of ctx.initiativeIndex(root).initiatives || []) {
25
+ for (const a of g.artifacts || []) { const rel = String(a.path).split(require('path').sep).join('/'); if (!a.shared && !own.has(rel)) own.set(rel, { id: g.id, title: g.title || g.id }); }
26
+ }
27
+ return own;
28
+ }
29
+ function roundsOf(dir) {
30
+ const PR = require('./proposals.js'), LAB = require('./idle-lab.js');
31
+ const P = PR.read(dir), all = [...P.props.values()];
32
+ const inis = [...new Set(all.filter((x) => x.group === 'prototyped' && x.ini).map((x) => x.ini))];
33
+ const out = [];
34
+ for (const ini of inis) {
35
+ const roots = new Map(all.filter((x) => x.group === 'prototyped' && x.ini === ini).map((x) => [x.id, x]));
36
+ for (const r of LAB.roundsOf(P, ini)) {
37
+ const root = roots.get(r.id) || all.find((x) => x.id === r.id) || {};
38
+ const of = (root.data && root.data.of) || r.id;
39
+ const top = roots.get(of) || root;
40
+ const brief = (top.data && top.data.live && top.data.live.brief) || String(top.title || '').replace(/^Round \d+ · [^:]*:\s*/, '');
41
+ const newest = all.filter((x) => x.group === 'improved' && x.ini === ini && x.data && x.data.of === of).reduce((a, x) => (String(x.at) > a ? String(x.at) : a), String(r.at || ''));
42
+ out.push({ id: r.id, ini, board: top.board || '', name: brief || 'Prototype', at: newest || r.at, made: r.rounds || r.made || 0 });
43
+ }
44
+ }
45
+ return out;
46
+ }
47
+
48
+ function gather(ctx, list) {
49
+ const unread = [];
50
+ const products = [];
51
+ for (const w of list) {
52
+ const p = { ws: w.id, name: w.label || w.name || w.id, titles: titlesOf(w, ctx), files: [], links: [], rounds: [] };
53
+ try {
54
+ const lib = require('./doc-library.js').library(w.root, { stateDir: ctx.runtimeDir, owners: () => ownersOf(ctx, w.root) });
55
+ if (lib.ok) {
56
+ p.files = lib.files.filter((f) => f.initiative);
57
+ for (const [id, t] of Object.entries(lib.initiatives || {})) if (!p.titles.has(id)) p.titles.set(id, t.title);
58
+ }
59
+ } catch { unread.push({ ws: w.id, source: 'documents' }); }
60
+ try {
61
+ const C = require('./custom-docs.js');
62
+ p.links = C.readLines(C.ledgerFile(w.root)).filter((l) => l.link && C.KINDS.includes(l.link.kind) && typeof l.link.url === 'string' && /^https?:\/\//i.test(l.link.url));
63
+ } catch { unread.push({ ws: w.id, source: 'links' }); }
64
+ try { const dir = ctx.stateDirFor ? ctx.stateDirFor(w) : null; if (dir) p.rounds = roundsOf(dir); } catch { unread.push({ ws: w.id, source: 'prototypes' }); }
65
+ products.push(p);
66
+ }
67
+ let notes = [];
68
+ try { const l = require('./notes.js').list(ctx.runtimeDir); notes = l.ok ? l.notes : []; } catch { unread.push({ ws: null, source: 'meeting notes' }); }
69
+ return { items: Items.build({ products, notes }), unread };
70
+ }
71
+
72
+ async function handle(req, res, url, ctx) {
73
+ if (url.pathname !== '/api/library-items') return false;
74
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
75
+ const ws = url.searchParams.get('ws') || '', ini = url.searchParams.get('initiative') || '';
76
+ if (ini && !ID_RE.test(ini)) { ctx.json(res, { ok: false, error: 'initiative names an initiative' }, 400); return true; }
77
+ let list = [];
78
+ try { list = typeof ctx.workspaceList === 'function' ? ctx.workspaceList() : []; } catch { list = []; }
79
+ if (ws) {
80
+ const w = list.find((x) => x.id === ws);
81
+ if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
82
+ list = [w];
83
+ }
84
+ const { items, unread } = gather(ctx, list);
85
+ ctx.json(res, { ok: true, items: Items.narrow(items, { ws: ws || null, initiative: ini || null }), unread });
86
+ return true;
87
+ }
88
+
89
+ module.exports = { prefixes: ['/api/library-items'], handle, gather, roundsOf };