create-pmos 0.396.0 → 0.398.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/scripts/nine-stages.js +49 -20
  6. package/payload/state/discoveries.md +1 -1
  7. package/payload/state/log.md +1 -1
  8. package/workspace/briefing-premium-adddoc-test.js +103 -74
  9. package/workspace/briefing-premium-board-test.js +316 -154
  10. package/workspace/briefing-premium-calendar-2-test.js +135 -195
  11. package/workspace/briefing-premium-calendar-3-test.js +143 -413
  12. package/workspace/briefing-premium-calendar-test.js +86 -185
  13. package/workspace/briefing-premium-doc-edit-test.js +95 -83
  14. package/workspace/briefing-premium-initiative-test.js +166 -294
  15. package/workspace/briefing-premium-insights-test.js +351 -214
  16. package/workspace/briefing-premium-metrics-test.js +53 -118
  17. package/workspace/briefing-premium-products-test.js +40 -27
  18. package/workspace/briefing-premium-sources-test.js +91 -52
  19. package/workspace/briefing-premium-test.js +150 -633
  20. package/workspace/briefing-premium-work-test.js +88 -269
  21. package/workspace/changelog.json +24 -0
  22. package/workspace/fixtures/board-premium-facts.js +2 -1
  23. package/workspace/fixtures/board-premium-jira.js +28 -0
  24. package/workspace/fixtures/board-premium-trail.js +32 -0
  25. package/workspace/fixtures/initiative-premium-facts.js +2 -1
  26. package/workspace/fixtures/initiatives-api/list.json +30 -42
  27. package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
  28. package/workspace/fixtures/initiatives-api/sheet.json +10 -14
  29. package/workspace/fixtures/insights-premium-facts.js +11 -2
  30. package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
  31. package/workspace/guide/briefing-premium.md +3 -1
  32. package/workspace/guide/home.md +47 -0
  33. package/workspace/guide/index.md +2 -0
  34. package/workspace/guide/lifecycle.md +51 -0
  35. package/workspace/home-shot.js +38 -0
  36. package/workspace/lib/agent-roles.js +71 -0
  37. package/workspace/lib/board-premium.js +160 -3
  38. package/workspace/lib/board-trail.js +223 -0
  39. package/workspace/lib/engine/boards.js +15 -14
  40. package/workspace/lib/engine/nine-stages.js +49 -20
  41. package/workspace/lib/engine/signals/detectors.js +13 -11
  42. package/workspace/lib/home-work-item.js +58 -0
  43. package/workspace/lib/insights-goals.js +196 -0
  44. package/workspace/lib/insights-premium.js +126 -1
  45. package/workspace/lib/insights-records.js +101 -0
  46. package/workspace/lib/jira-tickets.js +1 -1
  47. package/workspace/lib/route-modules.js +4 -0
  48. package/workspace/lib/routes-board-premium.js +3 -2
  49. package/workspace/lib/routes-board-trail.js +33 -0
  50. package/workspace/lib/routes-home-desk.js +176 -0
  51. package/workspace/lib/routes-initiatives.js +1 -1
  52. package/workspace/lib/routes-insights-premium.js +19 -3
  53. package/workspace/lib/routes-insights-records.js +129 -0
  54. package/workspace/lib/routes-notes.js +1 -0
  55. package/workspace/lib/routes-viewer.js +108 -0
  56. package/workspace/lib/transcript-steps.js +123 -0
  57. package/workspace/lib/vendor/scripts/nine-stages.js +49 -20
  58. package/workspace/lib/viewer-meeting.js +205 -0
  59. package/workspace/lib/viewer-report.js +89 -0
  60. package/workspace/package-lock.json +2 -2
  61. package/workspace/package.json +1 -1
  62. package/workspace/premium-agreed-viewer-shots.js +76 -0
  63. package/workspace/premium-board-actions-test.js +85 -73
  64. package/workspace/premium-briefing-depth-test.js +66 -53
  65. package/workspace/premium-chat-attach-test.js +54 -63
  66. package/workspace/premium-chat-chart-tab-test.js +35 -36
  67. package/workspace/premium-chat-context-test.js +22 -19
  68. package/workspace/premium-chat-goal-view-test.js +28 -26
  69. package/workspace/premium-chat-notes-test.js +29 -33
  70. package/workspace/premium-chat-report-tab-test.js +35 -25
  71. package/workspace/premium-chat-term-test.js +16 -14
  72. package/workspace/premium-chat-viewer-test.js +60 -53
  73. package/workspace/premium-core-doc-issue-test.js +50 -41
  74. package/workspace/premium-html-viewer-test.js +17 -18
  75. package/workspace/premium-phone-card-test.js +8 -2
  76. package/workspace/premium-phone-room-test.js +42 -31
  77. package/workspace/premium-report-read-test.js +115 -197
  78. package/workspace/premium-viewer-download-test.js +19 -22
  79. package/workspace/premium-viewer-flicker-test.js +11 -16
  80. package/workspace/premium-viewer-share-test.js +6 -9
  81. package/workspace/premium-viewer-test.js +41 -60
  82. package/workspace/premium-vw-backlog-test.js +53 -31
  83. package/workspace/premium-vw-cal-test.js +82 -123
  84. package/workspace/premium-vw-copy-test.js +17 -33
  85. package/workspace/premium-vw-doc-test.js +12 -11
  86. package/workspace/premium-vw-item-test.js +50 -48
  87. package/workspace/premium-vw-jira-test.js +55 -26
  88. package/workspace/premium-vw-meet-test.js +118 -187
  89. package/workspace/premium-vw-notes-test.js +85 -107
  90. package/workspace/premium-vw-rec-test.js +72 -193
  91. package/workspace/premium-vw-slides-test.js +46 -50
  92. package/workspace/premium-welcome-test.js +3 -2
  93. package/workspace/premium-work-depth-test.js +63 -51
  94. package/workspace/public/pm/bd-acts.js +305 -0
  95. package/workspace/public/pm/bd-span.js +224 -0
  96. package/workspace/public/pm/bd-stages.js +47 -0
  97. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  98. package/workspace/public/pm/c3-md.js +3 -395
  99. package/workspace/public/pm/c3-phone-detail.js +1 -1
  100. package/workspace/public/pm/c3-phone-model.js +3 -68
  101. package/workspace/public/pm/chat-term.js +3 -3
  102. package/workspace/public/pm/cozy-board.css +640 -0
  103. package/workspace/public/pm/cozy-home.css +580 -0
  104. package/workspace/public/pm/cozy-home.js +172 -0
  105. package/workspace/public/pm/cozy-initiative.css +138 -0
  106. package/workspace/public/pm/cozy-insights.css +421 -0
  107. package/workspace/public/pm/cozy-md.js +396 -0
  108. package/workspace/public/pm/cozy-nav.js +65 -0
  109. package/workspace/public/pm/cozy-placeholder.js +26 -0
  110. package/workspace/public/pm/cozy-viewer.css +143 -0
  111. package/workspace/public/pm/cozy-viewer.js +144 -0
  112. package/workspace/public/pm/cozy-vw.css +485 -0
  113. package/workspace/public/pm/cozy.css +254 -0
  114. package/workspace/public/pm/home-adddoc.js +48 -0
  115. package/workspace/public/pm/home-app.js +905 -0
  116. package/workspace/public/pm/home-around.js +515 -0
  117. package/workspace/public/pm/home-chat.js +459 -0
  118. package/workspace/public/pm/home-data.js +312 -0
  119. package/workspace/public/pm/home-draft.js +68 -0
  120. package/workspace/public/pm/home-more.js +249 -0
  121. package/workspace/public/pm/home-phone-card.js +109 -0
  122. package/workspace/public/pm/home-work.js +519 -0
  123. package/workspace/public/pm/lifecycle-lens-model.js +45 -27
  124. package/workspace/public/pm/lifecycle-lens.js +22 -11
  125. package/workspace/public/pm/phone-moment.js +69 -0
  126. package/workspace/public/pm/pm-work-view.js +1 -1
  127. package/workspace/public/pm/premium-attach.js +4 -0
  128. package/workspace/public/pm/premium-board.js +544 -253
  129. package/workspace/public/pm/premium-brief.js +1 -1
  130. package/workspace/public/pm/premium-chart-tab.js +110 -62
  131. package/workspace/public/pm/premium-chat.js +17 -10
  132. package/workspace/public/pm/premium-deck.js +3 -3
  133. package/workspace/public/pm/premium-first.js +25 -21
  134. package/workspace/public/pm/premium-initiative-head.js +138 -0
  135. package/workspace/public/pm/premium-initiative.js +28 -4
  136. package/workspace/public/pm/premium-insights.js +950 -440
  137. package/workspace/public/pm/premium-meeting.js +61 -549
  138. package/workspace/public/pm/premium-notes.js +1 -1
  139. package/workspace/public/pm/premium-report-frame.css +20 -0
  140. package/workspace/public/pm/premium-report-read.js +509 -480
  141. package/workspace/public/pm/premium-report-tab.js +87 -63
  142. package/workspace/public/pm/premium-shell.js +107 -124
  143. package/workspace/public/pm/premium-viewer.js +27 -1
  144. package/workspace/public/pm/premium-vw-cal.js +187 -48
  145. package/workspace/public/pm/premium-vw-doc.css +6 -0
  146. package/workspace/public/pm/premium-vw-doc.js +40 -2
  147. package/workspace/public/pm/premium-vw-file.js +2 -2
  148. package/workspace/public/pm/premium-vw-jira-model.js +22 -5
  149. package/workspace/public/pm/premium-vw-jira.css +11 -0
  150. package/workspace/public/pm/premium-vw-jira.js +11 -4
  151. package/workspace/public/pm/premium-vw-meet.js +6 -83
  152. package/workspace/public/pm/premium-vw-mtg.js +731 -0
  153. package/workspace/public/pm/premium-vw-notes.js +56 -69
  154. package/workspace/public/pm/premium-vw-open.js +35 -0
  155. package/workspace/public/pm/premium-vw-page.js +16 -0
  156. package/workspace/public/pm/premium-vw-rec.js +11 -215
  157. package/workspace/public/pm/premium-vw-slides.css +5 -0
  158. package/workspace/public/pm/premium-vw-slides.js +44 -8
  159. package/workspace/public/pm/term-view.js +22 -0
  160. package/workspace/public/premium-board.html +57 -64
  161. package/workspace/public/premium-chat.html +7 -33
  162. package/workspace/public/premium-initiative.html +8 -41
  163. package/workspace/public/premium-insights.html +63 -62
  164. package/workspace/public/premium-viewer.html +20 -0
  165. package/workspace/public/premium-work.html +6 -72
  166. package/workspace/public/premium.html +21 -66
  167. package/workspace/public/vendor/nunito-var.woff2 +0 -0
  168. package/workspace/server.js +25 -3
  169. package/workspace/test-files.json +1 -0
  170. package/workspace/test-lists/home-libs.json +9 -0
  171. package/workspace/test-lists/premium-agreed-viewer.json +9 -0
  172. package/workspace/test-lists/premium-report-read.json +1 -1
  173. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  174. package/workspace/test-lists/premium-vw-notes.json +1 -1
  175. package/workspace/third-party/README.md +1 -0
  176. package/workspace/public/pm/premium-work.js +0 -719
  177. package/workspace/public/pm/premium.js +0 -1133
@@ -39,6 +39,145 @@ const LANES = ['feature', 'discovery', 'chore', 'incident', 'content', 'prototyp
39
39
  let last = null;
40
40
  const peekModel = () => last;
41
41
 
42
+ /* ── The Agreed design's stage track (initiative premium-agreed-design, B1 B2) ───────────────────────────────────────────────────────────
43
+ * Six stages and two milestones (◆). A board's own workflow names map onto them; the old names count for the new ones (Ideate → Discover,
44
+ * Strategize → Prioritize), and a name the map does not know falls back on its category. Each row gets `track`: its step, the output that
45
+ * finishes the step, the progress toward it from a record (Jira tickets for Build and Deliver, the record's own progress otherwise) and the
46
+ * Jira tickets PMOS holds a reading for. Nothing here is invented: a step with nothing counted says so. */
47
+ const STEPS = [
48
+ ['triage', 'Triage', 'Triage', false, 'BRD complete'], ['discover', 'Discover', 'Disc', false, 'PRD complete'],
49
+ ['plan', 'Plan', 'Plan', false, 'Scope, timeline, work breakdown'], ['prioritize', 'Prioritize', 'Prio', false, 'Ranked on the roadmap'],
50
+ ['build', 'Build', 'Build', false, 'Features delivered'], ['deliver', 'Deliver', 'Deliv', true, 'Release shipped + your sign-off'],
51
+ ['monitor', 'Monitor', 'Mon', false, 'Outcome report'], ['evaluate', 'Evaluate', 'Eval', true, 'Keep, iterate or stop'],
52
+ ].map(([key, label, short, ms, output]) => ({ key, label, short, ms, output }));
53
+ const OLD_STEP = { ideate: 'discover', strategize: 'prioritize', intake: 'triage', ship: 'deliver', release: 'deliver', learn: 'monitor' };
54
+ const CAT_STEP = { discover: 'discover', plan: 'plan', do: 'build', learn: 'monitor' };
55
+ /** The index of a stage name among the eight steps, or -1. Reads old and new names alike. */
56
+ function stepIndex(name, cat) {
57
+ const n = String(name || '').trim().toLowerCase().replace(/^◆\s*/, '');
58
+ let k = STEPS.findIndex((s) => s.key === n);
59
+ if (k < 0 && OLD_STEP[n]) k = STEPS.findIndex((s) => s.key === OLD_STEP[n]);
60
+ if (k < 0 && n && cat && CAT_STEP[String(cat).toLowerCase()]) k = STEPS.findIndex((s) => s.key === CAT_STEP[String(cat).toLowerCase()]);
61
+ return k;
62
+ }
63
+ const TK_CLS = { Done: 'dn', 'In review': 'rv', 'In progress': 'ip', 'To do': '' };
64
+ const tkStatus = (status, category) => {
65
+ const s = String(status || '');
66
+ if (category === 'done' || /\b(done|closed|resolved|released)\b/i.test(s)) return 'Done';
67
+ if (/review|\bqa\b|test/i.test(s)) return 'In review';
68
+ if (category === 'doing' || /progress|doing|block|started/i.test(s)) return 'In progress';
69
+ return 'To do';
70
+ };
71
+ /** The Jira tickets of each initiative, from the sprint readings (with sprint, points and flag) and the board's work items (pushed tickets). */
72
+ function ticketsBy(sprints, items) {
73
+ const by = new Map(), seen = new Map();
74
+ const add = (ini, t) => {
75
+ if (!ini || !t.key) return;
76
+ const had = seen.get(t.key);
77
+ if (had) { for (const k of Object.keys(t)) if (had[k] == null || had[k] === '') had[k] = t[k]; return; }
78
+ if (!by.has(ini)) by.set(ini, []);
79
+ seen.set(t.key, t); by.get(ini).push(t);
80
+ };
81
+ for (const sp of sprints || []) for (const i of sp.issues || []) {
82
+ const status = tkStatus(i.status, i.category);
83
+ add(i.initiative, { key: i.key, title: clip(i.summary || i.key, 120), status, raw: i.status || '', cls: i.flagged ? 'bl' : TK_CLS[status], blocked: !!i.flagged, reason: i.flagged && i.reason ? clip(i.reason, 160) : '',
84
+ points: Number.isFinite(i.points) ? i.points : null, url: i.url || '', sprint: sp.name || '', sprintState: sp.state || '', sprintEnd: sp.end ? String(sp.end).slice(0, 10) : '', assignee: i.assignee || '' });
85
+ }
86
+ for (const w of items || []) {
87
+ if (!w || w.src !== 'jira' || w.kind === 'Epic' || !w.key) continue;
88
+ add(w.ini, { key: w.key, title: clip(w.title || w.key, 120), status: w.status || 'To do', raw: w.status || '', cls: w.blocked ? 'bl' : TK_CLS[w.status] || '', blocked: !!w.blocked, reason: '', points: null, url: '', sprint: '', sprintState: '', sprintEnd: '', assignee: w.owner || '' });
89
+ }
90
+ return by;
91
+ }
92
+ /** The parts that finish each step, as the Agreed design's "What finishes each step" frame names them. Only Build and Deliver (Jira tickets),
93
+ * Plan (dates and pushed tickets) and Prioritize (anchor and rank) have a record PMOS reads; the other parts are named but not counted. */
94
+ const PARTS = {
95
+ triage: ['business case', 'who asked', 'problem', 'success measure'],
96
+ discover: ['problem', 'users', 'evidence', 'scope', 'success metric', 'risks'],
97
+ plan: ['scope', 'timeline', 'tickets in Jira'],
98
+ prioritize: ['KR or health budget', 'rank'],
99
+ monitor: ['days of data', 'outcome report'],
100
+ evaluate: ['report', 'evaluation', 'your verdict'],
101
+ };
102
+ /** A progress the record holds: the route gives a fraction (0..1), older readings a percent. → a whole percent, or null. */
103
+ const pctOf = (v) => { const n = Number(v); if (v == null || v === '' || !Number.isFinite(n)) return null; return Math.max(0, Math.min(100, Math.round(n <= 1 ? n * 100 : n))); };
104
+ /** The stage track of one row: its step, the output that finishes it, the parts or tickets counted toward it, the steps it skipped
105
+ * (a move past a stage leaves a "Skipped <stage>" warning on the row) and what waits on the PM. Nothing is invented: a part PMOS
106
+ * has no record for is named and left uncounted. */
107
+ function trackOf(r, tickets, today, release) {
108
+ const k = stepIndex(r.stage, r.cat), step = STEPS[k] || null, key = step ? step.key : null;
109
+ const tk = (tickets || []).slice(0, 40);
110
+ const done = tk.filter((t) => t.status === 'Done').length, blocked = tk.filter((t) => t.blocked);
111
+ const pts = tk.filter((t) => t.points != null), ptsAll = pts.reduce((n, t) => n + t.points, 0), ptsDone = pts.filter((t) => t.status === 'Done').reduce((n, t) => n + t.points, 0);
112
+ const byPts = pts.length === tk.length && ptsAll > 0;
113
+ const jira = !!((key === 'build' || key === 'deliver') && tk.length);
114
+ let out = step ? step.output : 'No step on record';
115
+ if (key === 'deliver' && release) out = release + ' shipped + your sign-off';
116
+ const pct = r.progress != null ? r.progress : null;
117
+ const prog = jira
118
+ ? { done: byPts ? ptsDone : done, total: byPts ? ptsAll : tk.length, unit: byPts ? 'pts' : 'tickets', parts: tk.map((t) => t.cls || '') }
119
+ : pct != null ? { done: pct, total: 100, unit: '%', parts: null } : null;
120
+ // the segments of the Output bar and the words under it
121
+ let segs = [], count = '', line = [];
122
+ if (jira) {
123
+ segs = tk.map((t) => ({ cls: t.cls || '', tk: t.key }));
124
+ count = prog.done + ' of ' + prog.total + (byPts ? ' pts' : '');
125
+ if (blocked.length) line.push({ text: blocked[0].key + ' blocked' + (blocked[0].reason ? ' · ' + blocked[0].reason : ''), tone: 'red' });
126
+ const review = tk.filter((t) => t.status === 'In review');
127
+ if (review.length) line.push({ text: review.map((t) => t.key + (review.length === 1 ? ' ' + t.title : '')).slice(0, 2).join(', ') + ' in review' });
128
+ if (!line.length) { const doing = tk.filter((t) => t.status === 'In progress'); line.push({ text: doing.length ? doing.length + ' in progress · ' + (tk.length - done - doing.length) + ' to do' : done === tk.length ? 'Every ticket is done' : (tk.length - done) + ' to do' }); }
129
+ } else if (key === 'plan' || key === 'prioritize') {
130
+ const have = key === 'plan' ? [null, !!(r.start && r.end), tk.length > 0] : [!!r.anchor, Number.isInteger(r.rank)];
131
+ segs = have.map((h, i) => ({ cls: h ? 'dn' : '', name: cap1(PARTS[key][i], 0), st: h === true ? 'done' : h === null ? 'not on record' : 'to do' }));
132
+ const n = have.filter(Boolean).length, known = have.filter((h) => h !== null).length;
133
+ count = n + ' of ' + have.length;
134
+ const words = PARTS[key].map((w, i) => (have[i] === true ? cap1(w, i) + ' ✓' : have[i] === null ? cap1(w, i) + ' not on record' : cap1(w, i)));
135
+ if (key === 'prioritize' && !r.anchor) line.push({ text: 'Needs a KR or health budget' });
136
+ else line.push({ text: words.join(' · ') });
137
+ if (known === 0) count = '— of ' + have.length;
138
+ } else if (step && PARTS[key]) {
139
+ segs = PARTS[key].map((w) => ({ cls: '', name: cap1(w, 0), st: 'not counted' }));
140
+ count = '— of ' + PARTS[key].length + ' parts';
141
+ line.push({ text: PARTS[key].map(cap1).join(' · '), muted: true });
142
+ } else if (key === 'build' || key === 'deliver') {
143
+ segs = [{ cls: 'na' }];
144
+ count = 'No tickets yet';
145
+ line.push({ text: 'No Jira ticket has been read for it yet', muted: true });
146
+ } else if (step) {
147
+ count = 'Not counted yet';
148
+ line.push({ text: 'Nothing is counted toward it yet' });
149
+ } else line.push({ text: 'Its stage is not one of the eight steps' });
150
+ if (!jira && pct != null) { count = pct + '%'; }
151
+ // a step the row was moved past (lib/routes-boards.js keeps the move's "Skipped <stage>" warning)
152
+ const skipped = [...new Set((r.warnings || []).map((w) => (typeof w === 'string' ? /^Skipped (.+)$/.exec(w) : null)).filter(Boolean).map((m) => stepIndex(m[1], null)).filter((i) => i >= 0 && (k < 0 || i < k)))].sort((a, b) => a - b);
153
+ // what waits on the PM: the sign-off of a release whose tickets are all done (the last part of Deliver is the PM's)
154
+ const you = key === 'deliver' && tk.length && done === tk.length ? 'Your sign-off' + (release ? ' · ' + release : '') : null;
155
+ const upd = r.updated ? days(String(r.updated).slice(0, 10), today) : null;
156
+ const fc = tk.filter((t) => t.status !== 'Done' && t.sprintEnd).map((t) => t.sprintEnd).sort().pop() || null;
157
+ const next = line.find((x) => x.tone === 'red') || null;
158
+ return { k, key, label: step ? step.label : (r.stage || 'No stage'), ms: !!(step && step.ms), output: out, prog, pct: jira ? null : pct, segs, count, line, next, tickets: tk, blocked: blocked.length, skipped, you,
159
+ days: null, idle: upd != null && upd >= 30 && r.status !== 'done' ? upd : null, forecast: fc, forecastLabel: fc ? shortDate(fc) : '' };
160
+ }
161
+ const cap1 = (w, i) => (i === 0 ? w.charAt(0).toUpperCase() + w.slice(1) : w);
162
+ /** The short label of an anchor: q3-2026:o2:kr1 → KR 2.1; health:<id> → Health budget. */
163
+ function krShort(anchor) {
164
+ const a = String(anchor || '');
165
+ if (!a) return '';
166
+ if (/^health:/.test(a)) return 'Health budget';
167
+ const m = /:o(\d+):kr(\d+)/i.exec(a);
168
+ return m ? 'KR ' + m[1] + '.' + m[2] : clip(a, 24);
169
+ }
170
+ /** The anchor's theme, for the long timeline spans: the objective a KR belongs to, or the health budgets. */
171
+ function themeOf(anchor) {
172
+ const a = String(anchor || '');
173
+ if (!a) return { key: 'none', label: 'No anchor', kind: 'none', period: '' };
174
+ if (/^health:/.test(a)) return { key: 'health', label: 'Health budgets', kind: 'health', period: '' };
175
+ const m = /^(.*?):o(\d+)/i.exec(a);
176
+ if (!m) return { key: a, label: clip(a, 40), kind: 'other', period: '' };
177
+ const q = /^q(\d)-(\d{4})$/i.exec(m[1]);
178
+ return { key: m[1] + ':o' + m[2], label: 'Objective ' + m[2], kind: 'kr', period: q ? 'Q' + q[1] + ' ' + q[2] : m[1] };
179
+ }
180
+
42
181
  /** What the row's ⋯ menu and the initiative page's bar can do, from the row's own fields (initiative premium-board-actions): its workflow's stage names,
43
182
  * its stage, its lifecycle (on hold or cancelled, with the reason and check-back day the lifecycle line holds) and its archive entry. */
44
183
  function actsOf(r, boardNames) {
@@ -62,7 +201,7 @@ function rowOf(r, wf, today) {
62
201
  const facts = [
63
202
  ['Lane', r.lane], ['Stage', r.stage ? r.stage + (r.stageSource ? ' (' + r.stageSource + ')' : '') : ''], ['Anchor', r.anchor], ['Horizon', r.horizon],
64
203
  ['Status', STATUS_LABEL[r.status] || (r.status ? r.status.charAt(0).toUpperCase() + r.status.slice(1) : '')], ['Owner', r.owner],
65
- ['Progress', r.progress != null ? Math.round(r.progress) + '%' : ''], ['Starts', r.start ? shortDate(r.start) : ''], ['Ends', r.end ? shortDate(r.end) : ''],
204
+ ['Progress', pctOf(r.progress) != null ? pctOf(r.progress) + '%' : ''], ['Starts', r.start ? shortDate(r.start) : ''], ['Ends', r.end ? shortDate(r.end) : ''],
66
205
  ['Last changed', r.updated ? shortDate(String(r.updated).slice(0, 10)) : ''], ['Possible duplicate of', r.dupOf], ['Warnings', (r.warnings || []).map((w) => (typeof w === 'string' ? w : w && (w.text || w.message || w.id)) || '').filter(Boolean).join('; ')],
67
206
  ].filter((x) => x[1]);
68
207
  const over = r.end && today && days(r.end, today) > 0 && r.status !== 'done';
@@ -70,8 +209,9 @@ function rowOf(r, wf, today) {
70
209
  key: 'board:' + r.id, id: r.id, title: clip(r.title, 140), sub: [r.owner || 'No owner', r.lane].filter(Boolean).join(' · '),
71
210
  status: r.status || null, statusLabel: r.status && r.status !== 'on track' ? (STATUS_LABEL[r.status] || r.status) : null, bad, late: r.status === 'late',
72
211
  stage: r.stage || null, cat: r.cat || null, stageNote: r.stageSource === 'derived' ? 'derived' : null,
73
- seg: names.map((n, j) => (j < cur ? 'p' : j === cur ? 'n' : '')), progress: r.progress != null ? Math.max(0, Math.min(100, Math.round(r.progress))) : null,
212
+ seg: names.map((n, j) => (j < cur ? 'p' : j === cur ? 'n' : '')), progress: pctOf(r.progress),
74
213
  finish: r.end ? shortDate(r.end) : 'Not planned', over: !!over, start: r.start || null, end: r.end || null,
214
+ owner: r.owner || null, lane: r.lane || null, anchor: r.anchor || null, kr: krShort(r.anchor), rank: Number.isInteger(r.rank) ? r.rank : null, warnings: (r.warnings || []).filter((w) => typeof w === 'string').slice(0, 12), epics: Array.isArray(r.epics) ? r.epics.filter((e) => typeof e === 'string').slice(0, 6) : [], updated: r.updated || null, reading: r.reading || null, overDays: over ? days(r.end, today) : 0,
75
215
  acts: actsOf(r, names),
76
216
  dialog: {
77
217
  eye: 'Initiative', logTitle: 'Read from the board',
@@ -98,6 +238,18 @@ function build(f) {
98
238
  if (rows[0] && rows[0].late) rows[0].first = true;
99
239
  const stages = (f.columns || []).map((c) => ({ stage: c.stage, cat: c.cat, count: Number(c.count) || 0, rows: (c.rows || []).slice(0, STAGE_ROWS).map((r) => rowOf(r, wf, todayIso)), more: Math.max(0, (Number(c.count) || 0) - STAGE_ROWS) }));
100
240
  const stageRows = [].concat(...stages.map((s) => s.rows));
241
+ // the Agreed design's stage track (premium-agreed-design): tickets, output and progress per row
242
+ const tkBy = ticketsBy((f.sprints && Array.isArray(f.sprints.sprints)) ? f.sprints.sprints : [], f.items || []);
243
+ const relOfIni = new Map(); if (f.nextRelease && f.nextRelease.at) for (const id of f.nextRelease.ini || []) relOfIni.set(id, f.nextRelease.name || f.nextRelease.id);
244
+ const relAt = f.nextRelease && f.nextRelease.at ? String(f.nextRelease.at).slice(0, 10) : null;
245
+ // the Jira epic of each initiative, from the board's work items (Linked: Epic <key>)
246
+ const epicBy = new Map(); for (const w of f.items || []) if (w && w.kind === 'Epic' && w.key && w.ini && !epicBy.has(w.ini)) epicBy.set(w.ini, w.key);
247
+ for (const r of rows.concat(stageRows, gone.cancelled, gone.archived)) if (!r.track) {
248
+ r.track = trackOf(r, tkBy.get(r.id), todayIso, relOfIni.get(r.id)); r.theme = themeOf(r.anchor);
249
+ if (epicBy.has(r.id) && !r.epics.includes(epicBy.get(r.id))) r.epics.unshift(epicBy.get(r.id));
250
+ // the release it rides on, with the days to it (the status line says when it ships)
251
+ r.release = relOfIni.has(r.id) && relAt ? { name: relOfIni.get(r.id), at: shortDate(relAt), iso: relAt, days: days(todayIso, relAt) } : null;
252
+ }
101
253
  // the timeline: only an initiative with both a start and an end date has a bar
102
254
  const dated = rows.filter((r) => r.start && r.end && isoDay(r.start) && isoDay(r.end));
103
255
  let timeline;
@@ -186,6 +338,11 @@ function build(f) {
186
338
  stages, timeline,
187
339
  },
188
340
  sprint, release, docs,
341
+ // the Agreed design (premium-agreed-design): the eight steps with the board's own count in each, the Jira read time and the chip counts
342
+ steps: STEPS.map((st, i) => ({ ...st, count: stages.filter((c) => stepIndex(c.stage, c.cat) === i).reduce((n, c) => n + c.count, 0) })),
343
+ jira: { source: sp.source || 'none', readAt: sp.readAt || null, release: nr && nr.at ? { name: nr.name || nr.id, at: shortDate(String(nr.at).slice(0, 10)), iso: String(nr.at).slice(0, 10) } : null,
344
+ sprint: active ? { name: active.name, start: active.start ? String(active.start).slice(0, 10) : null, end: active.end ? String(active.end).slice(0, 10) : null } : null },
345
+ chips: { late, risk, blocked: rows.filter((r) => r.track && r.track.blocked).length, idle: rows.filter((r) => r.track && r.track.idle != null).length, asks: f.asks == null ? null : f.asks.filter((a) => a && a.state !== 'accepted' && a.state !== 'declined').length },
189
346
  asks: f.asks == null ? { missing: true, rows: [] } : { rows: f.asks.filter((a) => a && a.state !== 'accepted' && a.state !== 'declined').slice(0, 50).map(askOf) },
190
347
  dock: { needs: risk + late, label: 'need a look', release: nr && nr.at ? { at: shortDate(String(nr.at).slice(0, 10)), name: nr.name || nr.id } : null, next: (rows.find((r) => r.late) || rows.find((r) => r.bad) || {}).title || null },
191
348
  rows: rows.concat(stageRows.filter((r) => !rows.some((x) => x.key === r.key)), gone.cancelled, gone.archived, [sprintRow, relRow].filter(Boolean)).concat([{ key: 'board:this-board', id: null, title: board.name || 'This board', sub: 'Board', dialog: { eye: 'Board', logTitle: 'Read from the board', log: ['Read the board and its initiatives', 'Counted them by status', 'Changed nothing'], say: (board.name || 'This board') + ' has ' + open + ' open ' + plural(open, 'initiative', 'initiatives') + ': ' + on + ' on track, ' + risk + ' at risk, ' + late + ' late' + (hold ? ', ' + hold + ' on hold' : '') + '.', head: 'Where it stands', facts: [['Open initiatives', String(open)], ['On track', String(on)], ['At risk', String(risk)], ['Late', String(late)], ['On hold', hold ? String(hold) : '']].filter((x) => x[1] !== ''), hold: 'Nothing here changes a board.', pane: { label: 'Board record', file: '', note: 'The board as its records hold it.', rows: [['Open initiatives', String(open)], ['On track', String(on)], ['At risk', String(risk)], ['Late', String(late)], ['On hold', hold ? String(hold) : '']].filter((x) => x[1] !== '') } } }]),
@@ -194,4 +351,4 @@ function build(f) {
194
351
  return model;
195
352
  }
196
353
 
197
- module.exports = { build, peekModel };
354
+ module.exports = { build, peekModel, STEPS, stepIndex, themeOf };
@@ -0,0 +1,223 @@
1
+ 'use strict';
2
+ /* board-trail.js — what the Agreed Board draws beside each initiative that the board's own model does not carry
3
+ * (initiative premium-agreed-design, PM scope change of 2026-10-22: "build the missing data instead of empty states").
4
+ *
5
+ * trail({ root, ids, rows, moves, now, io }) → { ok, at, usual, themes, items: { [id]: item } }
6
+ *
7
+ * Everything is DERIVED from what the repository already holds. Nothing here writes:
8
+ * · days in the current stage the last board move into the stage (the board ledger), else the first appearance in git of
9
+ * the newest artifact on the initiative's ladder (record, PRD, rubric, evaluation)
10
+ * · "usually N days" per stage the median days past initiatives spent in that stage, from the same dates (record → PRD is
11
+ * Triage, PRD → rubric is Plan, rubric → evaluation is Build) and from consecutive board moves;
12
+ * null until 3 samples exist. A record reconstructed after the fact (reconstructed_from) is no sample,
13
+ * and neither are two artifacts first seen in the same commit (they were written together).
14
+ * · skipped stages and why the lane's own ladder (scripts/nine-stages.js LANE_STAGES: "the chore lane has no Triage step"),
15
+ * and a board move past a stage, with the move's own reason
16
+ * · the parts of a step's output Triage: the record and brief headings · Discover: the PRD headings · Plan: scope, timeline,
17
+ * tickets drafted and pushed · Evaluate: the evaluation file and the verdict
18
+ * · what waits on the PM the Commit of drafted tickets, a PRD change after the push, the verdict
19
+ * · tickets drafted in PMOS lib/jira-tickets.js view(): drafted, pushed (key), the PRD-changed flag, the Commit gate,
20
+ * the epic, and the Jira reading's subtasks and blocker reason
21
+ * · links prd_path and rubric_path of the record (with the PRD's `version:`), the evaluation file, the epic
22
+ * · dependencies the record's `predecessor:` and `depends_on:` keys, with where each one stands
23
+ * · themes one per objective: the PRD's `theme:` (and optional `theme_note:`, `theme_color:`), else the
24
+ * objective's own title; the health budgets are one theme
25
+ *
26
+ * io (tests pass their own): { text(rel) → string | null, list(relDir) → [names], firstSeen() → Map<rel, epoch ms>,
27
+ * jira(id) → jira-tickets view | null, anchor(raw) → { objective: { id, title } } | null, records() → [rel] }. */
28
+ const fs = require('fs');
29
+ const path = require('path');
30
+ const { execFileSync } = require('child_process');
31
+ const { repoScript } = require('./repo-script.js');
32
+
33
+ const STAGES = ['triage', 'discover', 'plan', 'prioritize', 'build', 'deliver', 'monitor', 'evaluate'];
34
+ const LABEL = { triage: 'Triage', discover: 'Discover', plan: 'Plan', prioritize: 'Prioritize', build: 'Build', deliver: 'Deliver', monitor: 'Monitor', evaluate: 'Evaluate' };
35
+ const FALLBACK_LANES = { feature: STAGES, discovery: ['triage', 'discover', 'prioritize', 'evaluate'], chore: ['plan', 'build', 'deliver', 'evaluate'],
36
+ incident: ['build', 'deliver', 'monitor', 'evaluate'], content: ['discover', 'plan', 'build', 'deliver'], prototype: ['triage', 'discover', 'evaluate'] };
37
+ let LANE_STAGES = FALLBACK_LANES;
38
+ try { LANE_STAGES = require(repoScript('nine-stages.js')).LANE_STAGES || FALLBACK_LANES; } catch { LANE_STAGES = FALLBACK_LANES; }
39
+ const TONES = ['grey', 'blue', 'green', 'amber', 'violet', 'teal'];
40
+ const DAY = 86400000;
41
+ const MIN_SAMPLES = 3;
42
+
43
+ // The parts of an output that a heading of a document stands for (AgBoardStages: "How progress is counted").
44
+ const TRIAGE_PARTS = [['business case', /business case|why (now|this)|\bvalue\b|the bet/i], ['who asked', /who asked|asked by|requested|stakeholder|where (it|this) came from|origin/i],
45
+ ['problem', /problem/i], ['success measure', /success (measure|metric|criteria)|done[ -]criteria|outcome|how we know/i]];
46
+ const DISCOVER_PARTS = [['problem', /problem/i], ['users', /\busers?\b|persona|audience|who (it|this) is for|customers?/i], ['evidence', /evidence|research|signal|\bdata\b|findings/i],
47
+ ['scope', /scope|non-goals|out of scope|requirements/i], ['success metric', /success|metric|done[ -]criteria|acceptance/i], ['risks', /risk/i]];
48
+
49
+ const stageKey = (s) => { const k = String(s || '').toLowerCase().trim(); return { ideate: 'discover', strategize: 'prioritize' }[k] || k; };
50
+ const median = (a) => { if (!a.length) return null; const s = a.slice().sort((x, y) => x - y), m = s.length >> 1; return s.length % 2 ? s[m] : Math.round((s[m - 1] + s[m]) / 2); };
51
+ const dayIso = (ms) => new Date(ms).toISOString().slice(0, 10);
52
+
53
+ /** The leading YAML frontmatter as flat keys (strings, or lists of strings). Enough for the record and PRD keys read here. */
54
+ function frontmatter(text) {
55
+ const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(String(text || ''));
56
+ const out = {};
57
+ if (!m) return out;
58
+ let last = null;
59
+ for (const line of m[1].split(/\r?\n/)) {
60
+ const kv = /^([A-Za-z_][\w-]*):\s*(.*)$/.exec(line);
61
+ if (kv) { last = kv[1]; const v = kv[2].trim().replace(/^["']|["']$/g, ''); out[last] = v === '' ? [] : v; continue; }
62
+ const li = /^\s*-\s+(.*)$/.exec(line);
63
+ if (li && last && Array.isArray(out[last])) out[last].push(li[1].trim().replace(/^["']|["']$/g, ''));
64
+ }
65
+ return out;
66
+ }
67
+ const headings = (text) => String(text || '').replace(/^---[\s\S]*?\n---/, '').split(/\r?\n/).filter((l) => /^#{1,4}\s|^\*\*[^*]+\*\*|^[A-Z][\w ]{2,40}:\s/.test(l)).join('\n');
68
+ const listOf = (v) => (Array.isArray(v) ? v : v ? String(v).split(/[,\s]+/) : []).map((x) => x.trim()).filter((x) => /^[a-z0-9][\w.-]*$/i.test(x));
69
+ const pathOf = (v) => (typeof v === 'string' && /^[\w./-]+\.md$/.test(v.trim()) ? v.trim() : null);
70
+
71
+ /** The default io: the files of `root`, its git history (one `git log` per HEAD), the Jira draft and reading, the OKR anchors. */
72
+ const gitCache = new Map();
73
+ function defaultIo(root) {
74
+ const read = (rel) => { try { return fs.readFileSync(path.join(root, rel), 'utf8'); } catch { return null; } };
75
+ return {
76
+ text: read,
77
+ list: (dir) => { try { return fs.readdirSync(path.join(root, dir)); } catch { return []; } },
78
+ records: () => { try { return fs.readdirSync(path.join(root, 'planning', 'initiatives')).filter((f) => f.endsWith('.md') && f !== 'README.md' && f !== 'index.md').map((f) => 'planning/initiatives/' + f); } catch { return []; } },
79
+ firstSeen: () => {
80
+ let head = '';
81
+ try { head = execFileSync('git', ['-C', root, 'rev-parse', 'HEAD'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim(); } catch { return new Map(); }
82
+ const hit = gitCache.get(root); if (hit && hit.head === head) return hit.map;
83
+ const map = new Map();
84
+ try {
85
+ const out = execFileSync('git', ['-C', root, 'log', '--diff-filter=A', '--name-only', '--format=@@%at', '--', 'planning'], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] });
86
+ let at = 0;
87
+ for (const line of out.split('\n')) { if (line.startsWith('@@')) at = Number(line.slice(2)) * 1000; else if (line.trim()) map.set(line.trim(), at); } // newest first: the last write is the first appearance
88
+ } catch { /* not a git checkout: no dates */ }
89
+ gitCache.set(root, { head, map });
90
+ return map;
91
+ },
92
+ jira: (id) => {
93
+ try {
94
+ const T = require('./jira-tickets.js'), S = require('./jira-status.js');
95
+ return T.view(root, id, { snapshot: S.readSnapshot(root, id) });
96
+ } catch { return null; }
97
+ },
98
+ anchor: (() => { let A = null; return (raw) => { try { if (!A) A = require('./initiative-rows.js').anchorsOf(root); return A.resolve(raw); } catch { return null; } }; })(),
99
+ };
100
+ }
101
+
102
+ /** One initiative's dates on its ladder, in order: [stage entered, epoch ms]. */
103
+ function ladderDates(id, fm, seen, evals) {
104
+ const out = [];
105
+ const at = (rel) => (rel && seen.has(rel) ? seen.get(rel) : null);
106
+ const rec = at('planning/initiatives/' + id + '.md'), prd = at(pathOf(fm.prd_path)), rub = at(pathOf(fm.rubric_path)), ev = evals.map(at).filter(Boolean).sort()[0] || null;
107
+ if (rec) out.push(['triage', rec]);
108
+ if (prd && (!rec || prd >= rec)) out.push(['plan', prd]);
109
+ if (rub && (!prd || rub >= prd)) out.push(['build', rub]);
110
+ if (ev && (!rub || ev >= rub)) out.push(['evaluate', ev]);
111
+ return out;
112
+ }
113
+ const evalFiles = (id, names) => names.filter((n) => n.startsWith(id + '-') && n.endsWith('.md') && !/rubric/.test(n)).map((n) => 'planning/evals/' + n);
114
+
115
+ /** The parts of a stage's output with what is done, and the first one that is not. */
116
+ function partsOf(stage, ctx) {
117
+ const P = (name, done, extra) => ({ name, done: !!done, ...(extra || {}) });
118
+ if (stage === 'triage') { const h = headings(ctx.recordText) + '\n' + headings(ctx.briefText); return TRIAGE_PARTS.map(([n, re]) => P(n, re.test(h))); }
119
+ if (stage === 'discover') { const h = headings(ctx.prdText); return DISCOVER_PARTS.map(([n, re]) => P(n, ctx.prdText && re.test(h))); }
120
+ if (stage === 'plan') {
121
+ const d = ctx.drafted, pushed = d.filter((t) => t.key).length;
122
+ return [P('scope', ctx.prdText && /scope|non-goals|requirements/i.test(headings(ctx.prdText))), P('timeline', ctx.row && ctx.row.start && ctx.row.end),
123
+ P(d.length ? (pushed ? pushed + ' of ' + d.length + ' tickets pushed' : d.length + ' tickets drafted, waiting on you') : 'tickets', d.length && pushed === d.length, d.length && pushed < d.length ? { you: true } : null)];
124
+ }
125
+ if (stage === 'evaluate') return [P('report', ctx.evals.length), P('evaluation', ctx.evals.length), P('your verdict', ctx.row && /accepted/i.test(String(ctx.row.reading || '')), { you: !!ctx.evals.length })];
126
+ return null;
127
+ }
128
+
129
+ function trail({ root, ids, rows = [], moves = [], now = Date.now(), io } = {}) {
130
+ const X = io || defaultIo(root);
131
+ const seen = X.firstSeen ? X.firstSeen() : new Map();
132
+ const evalNames = X.list ? X.list('planning/evals') : [];
133
+ const rowBy = new Map(rows.map((r) => [r.id, r]));
134
+ const fmCache = new Map();
135
+ const fmOf = (id) => { if (!fmCache.has(id)) { const t = X.text('planning/initiatives/' + id + '.md'); fmCache.set(id, t == null ? null : { fm: frontmatter(t), text: t }); } return fmCache.get(id); };
136
+
137
+ // "usually N days": every record's ladder, and every run of board moves
138
+ const samples = Object.fromEntries(STAGES.map((s) => [s, []]));
139
+ for (const rel of (X.records ? X.records() : [])) {
140
+ const id = path.basename(rel, '.md'), r = fmOf(id); if (!r || r.fm.reconstructed_from) continue;
141
+ const L = ladderDates(id, r.fm, seen, evalFiles(id, evalNames));
142
+ // two artifacts first seen in the same commit were written together: that says nothing about time in a stage, so it is no sample
143
+ for (let i = 0; i + 1 < L.length; i++) if (L[i + 1][1] !== L[i][1]) samples[L[i][0]].push(Math.max(0, Math.round((L[i + 1][1] - L[i][1]) / DAY)));
144
+ }
145
+ const byIni = new Map();
146
+ for (const m of moves) { if (!m || !m.id || !m.at) continue; if (!byIni.has(m.id)) byIni.set(m.id, []); byIni.get(m.id).push(m); }
147
+ for (const L of byIni.values()) {
148
+ L.sort((a, b) => String(a.at).localeCompare(String(b.at)));
149
+ for (let i = 0; i + 1 < L.length; i++) { const k = stageKey(L[i].to); if (samples[k]) samples[k].push(Math.max(0, Math.round((Date.parse(L[i + 1].at) - Date.parse(L[i].at)) / DAY))); }
150
+ }
151
+ const usual = Object.fromEntries(STAGES.map((s) => [s, samples[s].length >= MIN_SAMPLES ? { days: median(samples[s]), n: samples[s].length } : { days: null, n: samples[s].length }]));
152
+
153
+ const items = {};
154
+ const themes = new Map();
155
+ for (const id of ids || []) {
156
+ const r = fmOf(id);
157
+ if (!r && !rowBy.has(id)) continue; // neither a record nor a row of the board: nothing to say about it
158
+ const row = rowBy.get(id) || {}, fm = r ? r.fm : {};
159
+ const stage = stageKey(row.stage);
160
+ const lane = String(row.lane || fm.lane || 'feature').toLowerCase();
161
+ const evals = evalFiles(id, evalNames);
162
+ const prdRel = pathOf(fm.prd_path), rubRel = pathOf(fm.rubric_path);
163
+ const prdText = prdRel ? X.text(prdRel) : null, prdFm = frontmatter(prdText);
164
+ const briefName = (X.list ? X.list('planning/briefs') : []).find((n) => n.startsWith(id) && n.endsWith('.md'));
165
+ const jv = X.jira ? X.jira(id) : null;
166
+ const tks = jv && jv.ok && Array.isArray(jv.tickets) ? jv.tickets : [];
167
+ const drafted = tks.map((t) => ({ id: t.id, summary: t.summary, key: t.key || null, prdChanged: !!t.prdChanged, waiting: !!t.waiting }));
168
+
169
+ // days in the current stage: the last move into it, else the newest artifact on the ladder
170
+ let since = null, sinceFrom = null;
171
+ const mv = (byIni.get(id) || []).filter((m) => stageKey(m.to) === stage).pop();
172
+ if (mv) { since = Date.parse(mv.at); sinceFrom = 'move'; }
173
+ else { const L = ladderDates(id, fm, seen, evals); if (L.length) { since = L[L.length - 1][1]; sinceFrom = 'git'; } }
174
+
175
+ // skipped: the lane's own ladder, then a move past a stage (with the move's reason)
176
+ const k = STAGES.indexOf(stage), laneSet = new Set(LANE_STAGES[lane] || STAGES);
177
+ const skipped = [];
178
+ for (let j = 0; j < (k < 0 ? 0 : k); j++) if (!laneSet.has(STAGES[j])) skipped.push({ stage: STAGES[j], why: 'The ' + lane + ' lane has no ' + LABEL[STAGES[j]] + ' step.', from: 'lane' });
179
+ for (const m of byIni.get(id) || []) for (const w of m.warnings || []) {
180
+ const s = /^Skipped (.+)$/.exec(String(w)); if (!s) continue;
181
+ const sk = stageKey(s[1]); if (STAGES.includes(sk) && !skipped.some((x) => x.stage === sk)) skipped.push({ stage: sk, why: m.why ? String(m.why) : null, from: 'move', at: m.at });
182
+ }
183
+
184
+ const parts = partsOf(stage, { recordText: r ? r.text : '', briefText: briefName ? X.text('planning/briefs/' + briefName) : '', prdText, drafted, row, evals });
185
+ const unpushed = drafted.filter((t) => !t.key), drift = drafted.filter((t) => t.key && t.prdChanged);
186
+ const you = drift.length ? { text: 'Review the PRD change', why: drift.length + ' pushed ' + (drift.length === 1 ? 'ticket differs' : 'tickets differ') + ' from the PRD now', kind: 'drift' }
187
+ : stage === 'plan' && unpushed.length ? { text: 'Your Commit · push ' + unpushed.length + ' ' + (unpushed.length === 1 ? 'ticket' : 'tickets'), why: 'Drafted in PMOS. Nothing reaches Jira until you commit.', kind: 'commit' }
188
+ : stage === 'evaluate' && evals.length && !/accepted/i.test(String(row.reading || '')) ? { text: 'Your verdict', why: 'The evaluation is written. Keep, iterate or stop is yours.', kind: 'verdict' } : null;
189
+
190
+ const deps = [...new Set(listOf(fm.predecessor).concat(listOf(fm.depends_on)))].filter((d) => d !== id).slice(0, 8).map((d) => {
191
+ const dr = rowBy.get(d), df = fmOf(d);
192
+ return { id: d, title: dr ? dr.title : df ? String(df.fm.title || d) : d, stage: dr ? dr.stage : null, known: !!(dr || df), done: !!(dr && /evaluate|accepted|done/i.test(String(dr.stage || '') + ' ' + String(dr.reading || ''))) };
193
+ });
194
+
195
+ // the theme: the objective of the anchor; the PRD may name it
196
+ const raw = String(row.anchor || fm.parent_kr || '').split(/\s/)[0];
197
+ const res = raw && !/^health:/.test(raw) && X.anchor ? X.anchor(raw) : null;
198
+ const obj = res && res.objective ? res.objective : null;
199
+ const tkey = /^health:/.test(raw) ? 'health' : obj ? obj.id : raw ? 'other' : 'none';
200
+ if (!themes.has(tkey)) themes.set(tkey, { key: tkey, name: null, note: null, tone: null, objective: obj ? obj.title : null, period: obj ? obj.period || null : null, from: null });
201
+ const th = themes.get(tkey);
202
+ if (!th.name && typeof prdFm.theme === 'string' && prdFm.theme.trim()) { th.name = prdFm.theme.trim().slice(0, 60); th.from = prdRel; }
203
+ if (!th.note && typeof prdFm.theme_note === 'string' && prdFm.theme_note.trim()) th.note = prdFm.theme_note.trim().slice(0, 120);
204
+ if (!th.tone && typeof prdFm.theme_color === 'string' && TONES.includes(prdFm.theme_color.trim().toLowerCase())) th.tone = prdFm.theme_color.trim().toLowerCase();
205
+
206
+ const tickets = {};
207
+ for (const t of tks) if (t.key && t.jira) tickets[t.key] = { subtasks: t.jira.subtasks || null, reason: t.jira.reason || null, flagged: !!t.jira.flagged };
208
+
209
+ items[id] = {
210
+ since: since ? dayIso(since) : null, sinceFrom, days: since ? Math.max(0, Math.floor((now - since) / DAY)) : null,
211
+ skipped, parts, next: parts ? (parts.find((p) => !p.done) || {}).name || null : null, you,
212
+ links: { prd: prdRel, prdVersion: prdRel && (typeof prdFm.version === 'string' || typeof prdFm.version === 'number') && String(prdFm.version).trim() ? String(prdFm.version).trim().slice(0, 12) : null,
213
+ rubric: rubRel, evaluation: evals[0] || null, epic: jv && jv.ok && jv.epic && jv.epic.key ? jv.epic.key : null },
214
+ drafted, gate: jv && jv.ok ? jv.gate || null : null, drift: drift.map((t) => t.key), deps, theme: tkey, tickets,
215
+ };
216
+ }
217
+ // a theme with no name on any PRD takes its objective's title; tones in order where none is set
218
+ let ti = 0;
219
+ const out = [...themes.values()].map((t) => ({ ...t, name: t.name || (t.key === 'health' ? 'Health budgets' : t.objective || (t.key === 'none' ? 'No anchor' : 'Other anchors')), tone: t.tone || TONES[ti++ % TONES.length] }));
220
+ return { ok: true, at: new Date(now).toISOString(), usual, themes: out, items };
221
+ }
222
+
223
+ module.exports = { trail, frontmatter, partsOf, ladderDates, median, STAGES, MIN_SAMPLES, TONES };
@@ -6,7 +6,7 @@
6
6
  * templateWorkflow(name) → a fresh copy of a template's stages [{ name, cat, hint }]
7
7
  * isTemplateEdited(template, workflow) → true when the stages differ from the template's (names or categories)
8
8
  * fold(events) → { boards, moves, assigns, asks, stages, events }
9
- * readingOf(nineStages, { accepted }) → the nine-stage key the reading names (scripts/nine-stages.js output)
9
+ * readingOf(nineStages, { accepted }) → the lifecycle key the reading names (scripts/nine-stages.js output: eight steps)
10
10
  * deriveStage(board, reading) → the stage name a reading maps to on this board's workflow
11
11
  * stageOf(board, id, reading, folded) → { stage, source: 'move'|'derived' }
12
12
  * moveWarnings(board, row, from, to, facts) → ['Skipped Plan', 'No spec yet', 'No anchor']
@@ -40,8 +40,8 @@
40
40
  * Nothing is deleted. A line that is not an object with a known kind is skipped.
41
41
  *
42
42
  * STAGE OF AN INITIATIVE on a team board: the last move recorded for it on that board (a workflow edit's `moved` and an
43
- * ask-accept count as moves; a rename carries the move along). With none, it is derived from the nine-stage reading:
44
- * discover|ideate → first Discover stage; strategize|prioritize|plan → first Plan; build|deliver → first Do;
43
+ * ask-accept count as moves; a rename carries the move along). With none, it is derived from the lifecycle reading:
44
+ * triage|discover → first Discover stage; plan|prioritize → first Plan; build|deliver → first Do;
45
45
  * monitor|evaluate → first Learn. A workflow with no stage in that category uses the nearest earlier category, else
46
46
  * its first stage.
47
47
  */
@@ -104,16 +104,16 @@ function boardSettings(board) {
104
104
  return { build, jira: projects[0] || null, jiraProjects: projects, offer, defTpl };
105
105
  }
106
106
 
107
- /* The PMOS-self board: the nine stage names of scripts/nine-stages.js, read-only, each in its category. */
107
+ /* The PMOS-self board: the six stages and two milestones of scripts/nine-stages.js (premium-agreed-design L1), read-only, each in its
108
+ * category. The removed keys ideate and strategize keep a category so an old reading still maps (read-time only). */
109
+ const { STAGES: LIFE, LABELS: LIFE_LABEL, MILESTONES: LIFE_MILESTONES, stageKey } = require('./nine-stages');
108
110
  const READING_CAT = Object.freeze({
109
- discover: 'Discover', ideate: 'Discover',
110
- strategize: 'Plan', prioritize: 'Plan', plan: 'Plan',
111
+ triage: 'Discover', discover: 'Discover', ideate: 'Discover',
112
+ plan: 'Plan', prioritize: 'Plan', strategize: 'Plan',
111
113
  build: 'Do', deliver: 'Do',
112
114
  monitor: 'Learn', evaluate: 'Learn',
113
115
  });
114
- const NINE = ['discover', 'ideate', 'strategize', 'prioritize', 'plan', 'build', 'deliver', 'monitor', 'evaluate'];
115
- const NINE_LABEL = { discover: 'Discover', ideate: 'Ideate', strategize: 'Strategize', prioritize: 'Prioritize', plan: 'Plan', build: 'Build', deliver: 'Deliver', monitor: 'Monitor', evaluate: 'Evaluate' };
116
- const SELF_LADDER = Object.freeze(NINE.map((k) => st(NINE_LABEL[k], READING_CAT[k], 'Derived by scripts/workflow-state.js; not moved by hand.')));
116
+ const SELF_LADDER = Object.freeze(LIFE.map((k) => Object.freeze({ ...st(LIFE_LABEL[k], READING_CAT[k], 'Derived by scripts/workflow-state.js; not moved by hand.'), ...(LIFE_MILESTONES.has(k) ? { milestone: true } : {}) })));
117
117
 
118
118
  /* The stage tools of each category, per template: the initiative page shows these first and the rest behind
119
119
  * "More tools". `id` names the page section or tool the UI opens. */
@@ -324,16 +324,17 @@ function shiftDay(iso, days) {
324
324
  return d.toISOString().slice(0, 10);
325
325
  }
326
326
 
327
- /** The nine-stage key a reading names: the current stage, else (accepted) evaluate, else the last done, else the first used. */
327
+ /** The lifecycle key a reading names: the current stage, else (accepted) evaluate, else the last done, else the first used.
328
+ * A removed key (ideate, strategize) in an old reading maps to its new key. */
328
329
  function readingOf(nine, { accepted = false } = {}) {
329
330
  const list = Array.isArray(nine) ? nine : [];
330
331
  const cur = list.find((s) => s && s.status === 'current');
331
- if (cur) return cur.key;
332
+ if (cur) return stageKey(cur.key);
332
333
  if (accepted) return 'evaluate';
333
334
  const done = list.filter((s) => s && s.status === 'done');
334
- if (done.length) return done[done.length - 1].key;
335
+ if (done.length) return stageKey(done[done.length - 1].key);
335
336
  const used = list.find((s) => s && s.status !== 'skipped');
336
- return used ? used.key : 'discover';
337
+ return used ? stageKey(used.key) : 'triage';
337
338
  }
338
339
 
339
340
  function deriveStage(board, reading) {
@@ -348,7 +349,7 @@ function deriveStage(board, reading) {
348
349
  }
349
350
 
350
351
  function stageOf(board, id, reading, folded) {
351
- if (board && board.self) return { stage: NINE_LABEL[reading] || NINE_LABEL.discover, source: 'derived' };
352
+ if (board && board.self) return { stage: LIFE_LABEL[stageKey(reading)] || LIFE_LABEL.triage, source: 'derived' };
352
353
  const wf = workflowOf(board, id, folded);
353
354
  const moved = folded && folded.stages ? folded.stages.get(key(board.id, id)) : null;
354
355
  if (moved && wf.some((s) => s.name === moved)) return { stage: moved, source: 'move' };