create-pmos 0.419.0 → 0.420.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 (58) hide show
  1. package/package.json +13 -18
  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/scripts/lane-defs.js +14 -1
  6. package/payload/scripts/workflow-state.js +2 -2
  7. package/payload/state/discoveries.md +1 -1
  8. package/workspace/briefing-premium-board-test.js +9 -13
  9. package/workspace/changelog.json +12 -0
  10. package/workspace/fixtures/report-api/draft.json +2 -1
  11. package/workspace/guide/home.md +2 -0
  12. package/workspace/home-other-product-test.js +18 -0
  13. package/workspace/home-rows-test.js +14 -0
  14. package/workspace/lib/board-premium.js +13 -3
  15. package/workspace/lib/brief.js +5 -0
  16. package/workspace/lib/engine/lane-defs.js +14 -1
  17. package/workspace/lib/engine/workflow-state.js +2 -2
  18. package/workspace/lib/hold-spans.js +64 -0
  19. package/workspace/lib/mention-store.js +49 -13
  20. package/workspace/lib/plan-tree.js +1 -1
  21. package/workspace/lib/report-draft.js +6 -0
  22. package/workspace/lib/routes-boards.js +22 -6
  23. package/workspace/lib/source-reads.js +5 -0
  24. package/workspace/lib/vendor/scripts/lane-defs.js +14 -1
  25. package/workspace/lib/vendor/scripts/workflow-state.js +2 -2
  26. package/workspace/package-lock.json +2 -2
  27. package/workspace/package.json +1 -1
  28. package/workspace/public/pm/bd-acts.js +49 -1
  29. package/workspace/public/pm/bd-ini-panel.js +15 -8
  30. package/workspace/public/pm/bd-next.js +119 -0
  31. package/workspace/public/pm/bd-prog.js +1 -1
  32. package/workspace/public/pm/bd-span.js +117 -22
  33. package/workspace/public/pm/bd-views.js +7 -5
  34. package/workspace/public/pm/cozy-board.css +54 -9
  35. package/workspace/public/pm/cozy-today.css +9 -0
  36. package/workspace/public/pm/cozy-viewer.js +7 -3
  37. package/workspace/public/pm/cozy.css +10 -0
  38. package/workspace/public/pm/home-app.js +39 -13
  39. package/workspace/public/pm/home-ini.js +42 -11
  40. package/workspace/public/pm/home-list.js +22 -2
  41. package/workspace/public/pm/home-mentions.js +1 -1
  42. package/workspace/public/pm/home-today.js +13 -2
  43. package/workspace/public/pm/ini-tasks.js +363 -0
  44. package/workspace/public/pm/ini-view-model.js +19 -11
  45. package/workspace/public/pm/ini-view.css +160 -0
  46. package/workspace/public/pm/ini-view.js +39 -8
  47. package/workspace/public/pm/premium-board.js +54 -17
  48. package/workspace/public/pm/premium-vw-mtg.js +2 -0
  49. package/workspace/public/pm/task-card.js +6 -0
  50. package/workspace/skills/day-check.skill +2 -2
  51. package/workspace/skills/morning-brief.skill +1 -1
  52. package/workspace/skills/sources-read.skill +8 -4
  53. package/workspace/task-press-test.js +120 -0
  54. package/workspace/task-views-test.js +245 -0
  55. package/workspace/test-lists/task-press.json +6 -0
  56. package/workspace/test-lists/task-views.json +6 -0
  57. package/workspace/test-lists/timeline-holds.json +6 -0
  58. package/workspace/timeline-holds-test.js +191 -0
@@ -5,12 +5,18 @@
5
5
  * out, and Home showed only today's. A source read (source-reads.js) is replaced whole by the next read. So every mention a read or a brief
6
6
  * carries is copied here, and kept while it waits on the PM (whatever its age) or for 14 days after it stopped waiting.
7
7
  *
8
- * ingestRead(runtimeDir, record) a source read just saved (source-reads.js write calls it): its items that say `mention: true`
9
- * ingestBrief(runtimeDir, brief) a brief's mention items: they add what the brief judged (found, draft, initiative)
8
+ * ingestRead(runtimeDir, record, { me }?) a source read just saved (source-reads.js write calls it): its items that are mentions (isMention)
9
+ * ingestBrief(runtimeDir, brief, { me }?) a brief's mention items: they add what the brief judged (found, draft, initiative)
10
10
  * mark(runtimeDir, { id, act, until?, task?, text?, to? }, now, by) one appended line in <runtime>/mentions/marks.jsonl; by: 'pm' | 'agent'
11
11
  * view(runtimeDir, { now, me, missing }) → { ok, waiting, recent, count, gaps, as_of } what GET /api/mentions answers
12
12
  * build(entries, marks, { now, me }) → { waiting, recent } the pure part of view
13
- * ACTS · MENTION_SOURCES · keyOf(source, link, title)
13
+ * isMention(item, source, me) → '' | 'at' | 'dm' | 'name' how an item reaches the PM, '' when it does not
14
+ * ACTS · MENTION_SOURCES · VIAS · keyOf(source, link, title)
15
+ *
16
+ * WHAT A MENTION IS (batch 9 item 7). Not only an @handle: a Slack direct message to the PM ("dm"), and a Slack message or a mail that names
17
+ * the PM by first name, full name or an alias, with no @ ("name"). The read says so with `via`; `mention: true` alone is an @handle ("at").
18
+ * The store also catches what a read missed: a Slack item whose place is a DM, and a Slack or mail item whose words name the PM (the names
19
+ * GET /api/mentions knows: the Settings name, git's user.name). A message the PM wrote is never a mention of the PM.
14
20
  *
15
21
  * A MENTION waits on the PM when it asks something (reply_needed, not @channel, @here, a team handle or a bot) and an ask in its thread is
16
22
  * newer than everything that covered it: the PM's own reply in the thread (a message by the PM's name, or the read's `replied: true`),
@@ -25,6 +31,8 @@ const path = require('path');
25
31
  const crypto = require('crypto');
26
32
 
27
33
  const MENTION_SOURCES = Object.freeze(['slack', 'jira', 'confluence', 'mail']);
34
+ const VIAS = Object.freeze(['at', 'dm', 'name']);
35
+ const NAME_SOURCES = new Set(['slack', 'mail']); // where a plain name, with no @, counts (Jira and Confluence mention by handle)
28
36
  const ACTS = Object.freeze(['answered', 'notask', 'snooze', 'task', 'keep', 'drafted', 'draft', 'read', 'closed', 'undo']);
29
37
  const NOT_UNDONE = new Set(['read', 'draft', 'closed']); // what Undo never takes back: opening, Claude's reply, a task closed by a reply
30
38
  const DAY = 86400000;
@@ -85,9 +93,31 @@ function entryOf(x, source, ref, o = {}) {
85
93
  if (/^https:\/\/\S+$/i.test(String(x.link || '')) && String(x.link).length <= 500) e.link = x.link;
86
94
  if (typeof x.initiative_id === 'string' && x.initiative_id) e.initiative = x.initiative_id;
87
95
  if (x.replied === true) { e.replied = true; e.replied_seen = e.seen; }
96
+ const via = o.via || (VIAS.includes(x.via) ? x.via : '');
97
+ if (via) e.via = via;
88
98
  return e;
89
99
  }
90
100
 
101
+ const escRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
102
+ /** True when the text names one of the PM's names as a whole word (case ignored). A name under 3 letters is too common to count. Pure. */
103
+ function namesMe(text, me) {
104
+ const t = String(text || ''); if (!t) return false;
105
+ return (me || []).some((n) => { const w = String(n || '').trim(); return w.length >= 3 && new RegExp('(^|[^\\p{L}\\p{N}])' + escRe(w) + '(?![\\p{L}\\p{N}])', 'iu').test(t); });
106
+ }
107
+ const DM_RE = /^(dm|direct message)\b|\bDM\b/i;
108
+ /** How an item reaches the PM: 'at' (an @handle, the read's `mention: true`), 'dm' (a Slack direct message), 'name' (a Slack message or a mail
109
+ * that names the PM with no @), '' when it does not. The read's `via` wins; else the place and the words decide. Pure. */
110
+ function isMention(x, source, me) {
111
+ if (!x || !MENTION_SOURCES.includes(source)) return '';
112
+ if (VIAS.includes(x.via) && (x.via === 'at' || NAME_SOURCES.has(source))) return x.via;
113
+ if (isMe(x.who, me)) return x.mention === true ? 'at' : '';
114
+ if (source === 'slack' && DM_RE.test(String(x.where || ''))) return 'dm';
115
+ if (x.mention === true) return 'at';
116
+ if (!NAME_SOURCES.has(source) || !(me || []).length) return '';
117
+ const said = [x.title, x.about, x.ask, x.quote, ...(Array.isArray(x.thread) ? x.thread.filter((m) => m && !isMe(m.who, me)).map((m) => m.text) : [])];
118
+ return said.some((t) => namesMe(t, me)) ? 'name' : '';
119
+ }
120
+
91
121
  /** What a brief item adds: What I found (refs and checks) and the proposed reply (send.suggest). */
92
122
  function briefExtras(x) {
93
123
  const found = [];
@@ -141,20 +171,26 @@ function upsert(rt, list) {
141
171
  return list.length;
142
172
  }
143
173
 
144
- function ingestRead(rt, rec) {
174
+ function ingestRead(rt, rec, o = {}) {
145
175
  if (!rt || !rec || rec.state !== 'read' || !MENTION_SOURCES.includes(rec.source)) return 0;
146
176
  const ref = Date.parse(rec.read_at) || Date.now();
147
- return upsert(rt, (rec.items || []).filter((x) => x && x.mention).map((x) => entryOf(x, rec.source, ref)));
177
+ const me = lower(o.me);
178
+ const list = [];
179
+ for (const x of rec.items || []) { const via = isMention(x, rec.source, me); if (via) list.push(entryOf(x, rec.source, ref, { via })); }
180
+ return upsert(rt, list);
148
181
  }
149
- function ingestBrief(rt, brief) {
182
+ const lower = (me) => (me || []).map((n) => String(n).toLowerCase());
183
+ function ingestBrief(rt, brief, o = {}) {
184
+ const me = lower(o.me);
150
185
  if (!rt || !brief) return 0;
151
186
  const ref = Date.parse(brief.generated_at || brief.created_at || '') || (brief.date ? Date.parse(brief.date + 'T12:00:00') : Date.now());
152
187
  const list = [];
153
188
  for (const k of ['priorities', 'worth_asking', 'items']) for (const x of Array.isArray(brief[k]) ? brief[k] : []) {
154
- if (!x || !x.mention || !MENTION_SOURCES.includes(x.source)) continue;
189
+ const via = x ? isMention(x, x.source, me) : '';
190
+ if (!via) continue;
155
191
  const ex = briefExtras(x);
156
192
  if (ex.draft) ex.draft_at = new Date(ref).toISOString();
157
- list.push({ ...entryOf(x, x.source, ref, { brief: true }), ...ex });
193
+ list.push({ ...entryOf(x, x.source, ref, { brief: true, via }), ...ex });
158
194
  }
159
195
  return upsert(rt, list);
160
196
  }
@@ -235,7 +271,7 @@ function judge(e, mk, now, me) {
235
271
  function rowOf(e, j, mk, reads, now) {
236
272
  const r = { id: e.id, source: e.source, who: e.who, where: e.where, text: e.text, ask: e.ask || undefined, about: e.about || undefined, link: e.link,
237
273
  initiative: e.initiative, waiting: j.waiting, since: j.since ? new Date(j.since).toISOString() : null, last: j.last ? new Date(j.last).toISOString() : null,
238
- count: j.count, fyi: !j.ask, broadcast: !!e.broadcast, thread: e.thread && e.thread.length ? e.thread : undefined };
274
+ count: j.count, fyi: !j.ask, broadcast: !!e.broadcast, via: e.via || undefined, thread: e.thread && e.thread.length ? e.thread : undefined };
239
275
  if (!j.waiting && j.how) r.status = j.how; // replied | answered | notask | task
240
276
  if (mk.task) r.task = mk.task.task;
241
277
  if (mk.closed) r.task_closed = true;
@@ -267,7 +303,7 @@ function build(entries, marks, o = {}) {
267
303
  else if (j.last >= start.getTime()) recent.push(r);
268
304
  }
269
305
  // oldest first; a tie: a direct message or a ticket first, then by time
270
- const direct = (r) => (/\bDM\b|direct/i.test(r.where || '') || r.source === 'jira' ? 0 : 1);
306
+ const direct = (r) => (r.via === 'dm' || /\bDM\b|direct/i.test(r.where || '') || r.source === 'jira' ? 0 : 1);
271
307
  waiting.sort((a, b) => T(a.since) - T(b.since) || direct(a) - direct(b) || T(a.last) - T(b.last));
272
308
  recent.sort((a, b) => T(b.last) - T(a.last));
273
309
  return { waiting, recent };
@@ -289,8 +325,8 @@ function prune(items, now, marks = []) {
289
325
  * brief (today's brief, ingested too) }. */
290
326
  function view(rt, o = {}) {
291
327
  const now = o.now || Date.now();
292
- for (const r of Object.values(o.reads || {})) { try { ingestRead(rt, r); } catch { /* a bad read is skipped */ } }
293
- if (o.brief) { try { ingestBrief(rt, o.brief); } catch { /* the same */ } }
328
+ for (const r of Object.values(o.reads || {})) { try { ingestRead(rt, r, { me: o.me }); } catch { /* a bad read is skipped */ } }
329
+ if (o.brief) { try { ingestBrief(rt, o.brief, { me: o.me }); } catch { /* the same */ } }
294
330
  const reads = new Map();
295
331
  for (const l of lines(readsFile(rt))) if (l && ID_RE.test(String(l.id || '')) && typeof l.read === 'boolean') reads.set(l.id, l.read);
296
332
  const { waiting, recent } = build(Object.values(load(rt)), lines(marksFile(rt)), { now, me: o.me, reads });
@@ -304,4 +340,4 @@ function view(rt, o = {}) {
304
340
  return { ok: true, waiting, recent, count: waiting.length, gaps, as_of, now: new Date(now).toISOString() };
305
341
  }
306
342
 
307
- module.exports = { MENTION_SOURCES, ACTS, keyOf, timeOf, entryOf, briefExtras, merge, ingestRead, ingestBrief, mark, foldMarks, judge, build, prune, view, nineTomorrow, _files: { storeFile, marksFile } };
343
+ module.exports = { MENTION_SOURCES, ACTS, VIAS, keyOf, isMention, namesMe, timeOf, entryOf, briefExtras, merge, ingestRead, ingestBrief, mark, foldMarks, judge, build, prune, view, nineTomorrow, _files: { storeFile, marksFile } };
@@ -106,7 +106,7 @@ function profileAndLane(root, initiative) {
106
106
  const file = recordPath(root, initiative);
107
107
  let fm = {};
108
108
  if (file) { try { fm = eng.parseLeadingFrontmatter(fs.readFileSync(file, 'utf8')) || {}; } catch { fm = {}; } }
109
- const declared = String(fm.lane || '').trim();
109
+ const declared = eng.declaredLane(profile, fm);
110
110
  // An unknown or missing lane is the profile's strictest, exactly as workflow-state.js computes `effLane`.
111
111
  const fallback = profile === 'pm-artifacts' ? 'prd' : 'feature';
112
112
  const lane = declared && defs[declared] ? declared : fallback;
@@ -60,6 +60,7 @@ const factoryJoin = require('./factory-join.js');
60
60
  const healthLib = require('./health.js');
61
61
  const display = require('./initiative-display.js');
62
62
  const itemSpans = require('./item-spans.js');
63
+ const holdSpans = require('./hold-spans.js');
63
64
  const actorLib = require('./actor.js');
64
65
  const reviewGate = require('./review-gate.js');
65
66
  const { readRules } = require('./plan-rules.js');
@@ -356,6 +357,8 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
356
357
 
357
358
  // The Timeline strip, frozen at fold time: one row per block with dated items, one span per stage.
358
359
  const timeline = { from: dayOf(fromMs), to: dayOf(nowMs + cycle * DAY), today: dayOf(nowMs), rows: [] };
360
+ // the holds break the strip as they break the Board's bar (feedback batch 9 item 8): every hold that touches the dated items, or still runs
361
+ const holdsBy = holdSpans.holdsOf(life.rows);
359
362
  for (const b of blocks) {
360
363
  const spans = itemSpans.spansOf(itemsOf(b.id).filter((it) => !it.proposed));
361
364
  if (!spans.length) continue;
@@ -367,6 +370,8 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
367
370
  id: b.id, title: b.title,
368
371
  spans: keys.map((k) => ({ stage: k || null, ...itemSpans.initiativeSpan(byStage.get(k)), milestone: false })),
369
372
  milestones: [...new Set(spans.filter((s) => s.milestone).map((s) => s.due))].sort(),
373
+ holds: (() => { const all = itemSpans.initiativeSpan(spans);
374
+ return (holdsBy.get(b.id) || []).filter((h) => !h.to || !all || (h.to > all.start && h.from < all.due)).map((h) => ({ from: h.from, to: h.to, back: h.back, reason: h.reason })); })(),
370
375
  });
371
376
  }
372
377
 
@@ -520,6 +525,7 @@ function render(draft, { notes } = {}) {
520
525
  push('| Initiative | Stage | Start | Due | Milestones |', '|---|---|---|---|---|');
521
526
  for (const r of draft.timeline.rows) {
522
527
  r.spans.forEach((s, i) => push(`| ${i ? '' : esc(r.title)} | ${esc(s.stage || '-')} | ${s.start || '-'} | ${s.due || '-'} | ${i ? '' : (r.milestones.map(short).join(', ') || '-')} |`));
528
+ for (const h of r.holds || []) push(`| | On hold${h.reason ? ': ' + esc(h.reason) : ''} | ${h.from} | ${h.to || (h.back ? h.back + ' (return date)' : 'no return date')} | |`);
523
529
  }
524
530
  } else push('No initiative in this report has dated items.');
525
531
  push('');
@@ -84,6 +84,8 @@ const B = require(repoScript('boards.js'));
84
84
  const WF = require(repoScript('workflows.js'));
85
85
  const WS = require('./workflows-store.js');
86
86
  const TI = require('./task-items.js');
87
+ const holdSpans = require('./hold-spans.js');
88
+ const ledgers = require('./plan-ledgers.js');
87
89
  const intake = require(repoScript('intake.js'));
88
90
 
89
91
  const LEDGER = 'boards.jsonl';
@@ -233,6 +235,9 @@ function baseRows(w) {
233
235
  const day = today();
234
236
  const sig = routesInit.sigOf(w.root);
235
237
  sig.records = rowsLib.answerSig(got);
238
+ // every lifecycle line, not only the latest: a hold is a gap on the timeline (feedback batch 9 item 8)
239
+ let lcFile = null;
240
+ try { lcFile = path.join(ledgers.runsDir(w.root), 'lifecycle.jsonl'); const st = fs.statSync(lcFile); sig.lifecycle = st.size + ':' + st.mtimeMs; } catch { sig.lifecycle = 'none'; }
236
241
  const cacheKey = JSON.stringify(sig) + day;
237
242
  const hit = rowCache.get(w.root);
238
243
  if (hit && hit.key === cacheKey) return { ok: true, rows: hit.rows };
@@ -243,6 +248,7 @@ function baseRows(w) {
243
248
  if (!itemsBy.has(it.initiative)) itemsBy.set(it.initiative, []);
244
249
  itemsBy.get(it.initiative).push(it);
245
250
  }
251
+ const holds = lcFile ? holdSpans.readHolds(lcFile) : new Map();
246
252
  const rows = [];
247
253
  const seen = new Set();
248
254
  for (const id of Object.values(F.placed.order).flat()) {
@@ -253,8 +259,8 @@ function baseRows(w) {
253
259
  let r;
254
260
  try { r = routesInit.rowOf(F, rec); } catch { continue; }
255
261
  const fm = frontmatter(w.root, rec.record);
256
- let span = null;
257
- try { span = itemSpans.initiativeSpan(itemSpans.spansOf(itemsBy.get(id) || [])); } catch { span = null; }
262
+ let span = null, work = [];
263
+ try { work = itemSpans.spansOf(itemsBy.get(id) || []).filter((x) => !x.proposed); span = itemSpans.initiativeSpan(work); } catch { span = null; work = []; }
258
264
  const end = span ? span.due || null : null;
259
265
  const prd = fm.prd_path || null;
260
266
  const hasSpec = !!(prd && fs.existsSync(path.join(w.root, prd)));
@@ -275,6 +281,7 @@ function baseRows(w) {
275
281
  stopped: rec.stopped ? { reason: rec.stopped.reason || '', at: rec.stopped.at || null, back: rec.stopped.back || null } : null,
276
282
  hasSpec, record: relRec || null, domainFolder: dm ? dm[1] : null,
277
283
  recordEpic: jiraTickets.anchorOf(fm),
284
+ holds: holds.get(id) || [], workSpans: work.map((x) => ({ start: x.start, due: x.due })),
278
285
  });
279
286
  }
280
287
  rowCache.set(w.root, { key: cacheKey, rows });
@@ -336,14 +343,21 @@ const wfRowFields = (x) => {
336
343
  * planned as dated tasks had no bar on the timeline. */
337
344
  function taskSpanOf(folded, id) {
338
345
  let start = null, end = null;
346
+ for (const t of taskSpansOf(folded, id)) {
347
+ if (!start || t.start < start) start = t.start;
348
+ if (!end || t.due > end) end = t.due;
349
+ }
350
+ return start ? { start, end } : null;
351
+ }
352
+ /** Each dated task of an initiative as { start, due } (Won't do and Archived left out). */
353
+ function taskSpansOf(folded, id) {
354
+ const out = [];
339
355
  for (const t of (folded && folded.tasks ? folded.tasks.values() : [])) {
340
356
  if (!t || t.initiative !== id || t.state === "Won't do" || t.state === 'Archived') continue;
341
357
  const a = t.start || t.due, z = t.due || t.start;
342
- if (!a) continue;
343
- if (!start || a < start) start = a;
344
- if (!end || z > end) end = z;
358
+ if (a) out.push({ start: String(a).slice(0, 10), due: String(z).slice(0, 10) });
345
359
  }
346
- return start ? { start: String(start).slice(0, 10), end: String(end).slice(0, 10) } : null;
360
+ return out;
347
361
  }
348
362
  const minDay = (a, b) => (!a ? b || null : !b ? a : a < b ? a : b);
349
363
  const maxDay = (a, b) => (!a ? b || null : !b ? a : a > b ? a : b);
@@ -358,6 +372,8 @@ function boardRow(board, base, folded, lib) {
358
372
  horizon: base.horizon, status: base.status, start: ts ? minDay(base.start, ts.start) : base.start, end: ts ? maxDay(base.end, ts.end) : base.end, progress: base.progress, warnings: [],
359
373
  rank: base.rank, health: B.isActive(base) ? base.health : null, updated: base.updated, reading: base.reading, stageSource: s.source, lifecycle: base.lifecycle,
360
374
  stopped: base.stopped || null, archived: archivedOf(folded, base.id),
375
+ // feedback batch 9 item 8: every hold of the initiative, and the stretches of 4 weeks or more that no dated work-item or task covers
376
+ holds: base.holds || [], gaps: holdSpans.planGaps((base.workSpans || []).concat(taskSpansOf(folded, base.id)), 28),
361
377
  template: B.templateOf(board, base.id, folded), workflow: wf.map((x) => ({ name: x.name, cat: x.cat })),
362
378
  ...epicsOf(base, folded),
363
379
  };
@@ -75,6 +75,11 @@ function item(x, source, i) {
75
75
  ['replied', B], ['broadcast', B]]);
76
76
  if (!r.ok) return { ok: false, error: `${at}: ${r.error}` };
77
77
  if (!r.v.title) return { ok: false, error: `${at} has no title` };
78
+ // how a mention reaches the PM: an @handle, a Slack direct message, or the PM's name with no @ (mention-store.js isMention)
79
+ if (x.via !== undefined) {
80
+ if (!['at', 'dm', 'name'].includes(x.via)) return { ok: false, error: `${at}: via must be at, dm or name` };
81
+ r.v.via = x.via;
82
+ }
78
83
  if (x.initiative_id !== undefined) {
79
84
  if (typeof x.initiative_id !== 'string' || !INI_RE.test(x.initiative_id) || x.initiative_id.length > 80) return { ok: false, error: `${at}: initiative_id must be an initiative id` };
80
85
  r.v.initiative_id = x.initiative_id;
@@ -219,8 +219,21 @@ function laneNames(profile) {
219
219
  function laneDef(profile, lane) {
220
220
  return defsFor(profile)[lane] || null;
221
221
  }
222
+ // A record that names its lane as `type:` (chore, feature, discovery …) and has no `lane:` still has a lane. `type:` is
223
+ // also the D63 document type ("Initiative"), so only a value that is a lane of the profile counts. In pm-artifacts,
224
+ // `feature` means `new-feature`. A `lane:` always wins.
225
+ const TYPE_ALIAS = { 'pm-artifacts': { feature: 'new-feature' } };
226
+ function declaredLane(profile, fm) {
227
+ const lane = String((fm && fm.lane) || '').trim();
228
+ if (lane) return lane;
229
+ const p = profile === 'pm-artifacts' ? 'pm-artifacts' : 'product-code';
230
+ const t = String((fm && fm.type) || '').trim().toLowerCase();
231
+ if (!t) return '';
232
+ const named = (TYPE_ALIAS[p] || {})[t] || t;
233
+ return defsFor(p)[named] ? named : '';
234
+ }
222
235
  function rungRule(profile, key) {
223
236
  return (RUNG_RULES[profile] || {})[key] || null;
224
237
  }
225
238
 
226
- module.exports = { PM_ARTIFACTS, PRODUCT_CODE, RUNG_RULES, defsFor, laneNames, laneDef, rungRule };
239
+ module.exports = { PM_ARTIFACTS, PRODUCT_CODE, RUNG_RULES, defsFor, laneNames, laneDef, rungRule, declaredLane };
@@ -645,7 +645,7 @@ function computeWorkflowDerived(id, opts) {
645
645
  const fm = readFrontmatter(recAbs) || {};
646
646
  const profile = profileOf(root);
647
647
  const pmProfile = profile === 'pm-artifacts';
648
- const lane = (fm.lane || (pmProfile ? 'prd' : 'feature')).trim() || (pmProfile ? 'prd' : 'feature');
648
+ const lane = laneDefs.declaredLane(profile, fm) || (pmProfile ? 'prd' : 'feature');
649
649
  const knownLane = pmProfile ? laneNames('pm-artifacts').includes(lane)
650
650
  : laneNames('product-code').includes(lane);
651
651
  // unknown lane = the profile's strictest (feature in product-code, a governed prd in pm-artifacts)
@@ -1877,7 +1877,7 @@ function main(argv) {
1877
1877
  }
1878
1878
 
1879
1879
  module.exports = {
1880
- computeWorkflow, readLifecycle, STOPPED_STATES, renderLadder, renderBoard, listInitiatives, layout, inFlight, BOARD_CAP,
1880
+ computeWorkflow, declaredLane: laneDefs.declaredLane, readLifecycle, STOPPED_STATES, renderLadder, renderBoard, listInitiatives, layout, inFlight, BOARD_CAP,
1881
1881
  parseLeadingFrontmatter, specimenRoute, surfaceRoute, priorsCitation, isBuildPath, commitRange,
1882
1882
  // the board's trunk range, exported so the suite can assert the split: the same record is legacy
1883
1883
  // under BOTH ranges, and `in this change` is false under the trunk one.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.419.0",
3
+ "version": "0.420.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.419.0",
9
+ "version": "0.420.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.419.0",
3
+ "version": "0.420.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -22,11 +22,13 @@ import * as Pop from './bd-pop.js';
22
22
  import * as V from './bd-views.js';
23
23
  import * as Asks from './bd-asks.js';
24
24
  import * as WF from './bd-wf.js';
25
+ import { holdSpans, holdWords, holdRange, md } from './bd-span.js';
25
26
 
26
27
  const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
27
28
  const I = {
28
29
  x: 'M6 6l12 12M18 6L6 18', go: 'M5 12h14M13 6l6 6-6 6', back: 'M19 12H5M11 6l-6 6 6 6', hold: 'M9 5v14M15 5v14', arch: 'M4 7h16v13H4zM4 7l2-3h12l2 3M10 11h4',
29
30
  find: 'M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14M20 20l-4-4', list: 'M4 6h16M4 12h16M4 18h10', ext: 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6', play: 'M8 5v14l11-7z',
31
+ pause: 'M9 6v12M15 6v12', cal: 'M4 6h16v14H4zM4 10h16M9 3v4M15 3v4',
30
32
  };
31
33
  const WHY_NOT = ['Out of scope', 'Already planned', 'Not now', 'Other'];
32
34
  const BACK_WHY = ['A part is missing', 'The scope changed', 'Not ready yet', 'Other'];
@@ -342,10 +344,54 @@ function openBell(from) {
342
344
  Pop.open(`<p class="bd-mlbl">On this Board</p>${list || asks ? list + asks : '<p class="bd-amut bd-mnote">Nothing on this board waits on you, and no new ask waits for triage.</p>'}`, from, { label: 'Notifications', width: 340, align: 'right', cls: 'bd-bell' });
343
345
  }
344
346
 
345
- export const open = { new: (from) => Asks.openNew(from), asks: (from) => Asks.openAsks(from), row: openRowMenu, sprint: openSprint, metrics: openMetrics, find: openFind, filter: openFilter, gone: (from) => openGone(from, 'all'), bell: openBell, trend: openTrend, release: openRelease, doc: openDocPanel };
347
+ /** The Next cell's arrow (pm/bd-next.js): Move to the next stage, as the ⋯ menu's Move to does, with its Undo. */
348
+ export function moveNext(r, btn) { const a = r.acts || {}, cur = (a.stages || []).indexOf(a.stage); if (cur >= 0 && a.stages[cur + 1]) runRow(r, 'mv:' + (cur + 1), btn); }
349
+ /* ── a hold on the timeline (feedback batch 9 item 8, XtiA2Hold): the ⏸ press ─────────────────────────────────────────────── */
350
+ /** How long a hold ran or runs: "12 days", "3 weeks", "4½ months". */
351
+ function lengthOf(a, b) {
352
+ const n = Math.max(1, Math.round((b - a) / 86400000));
353
+ if (n < 14) return n + ' ' + plural(n, 'day', 'days');
354
+ if (n < 61) { const w = Math.round(n / 7); return w + ' ' + plural(w, 'week', 'weeks'); }
355
+ const m = Math.round((n / 30.44) * 2) / 2, w = Math.floor(m) + (m % 1 ? '½' : '');
356
+ return w + ' ' + (m === 1 ? 'month' : 'months');
357
+ }
358
+ /** The ⏸ menu: how long, why, the dates; while the hold runs, icons to resume now and to change the return date (both write the lines the ⋯ menu
359
+ * writes: one menu, no second editor, XtiAGrill 9). With no return date, the date field is open at once (XtiAGrill 4). */
360
+ function holdHtml(r, x, now, edit) {
361
+ const h = x.h, open = x.kind !== 'past', a = day(h.from);
362
+ const len = lengthOf(a, x.kind === 'none' || x.kind === 'over' ? now : x.b);
363
+ const head = (open ? 'On hold' : 'Was on hold') + ' · ' + len;
364
+ const when = x.kind === 'none' ? 'Since ' + md(a) + '. No return date yet.' : holdRange(h) + '.';
365
+ const n = x.kind === 'over' ? Math.round((now - day(h.back)) / 86400000) : 0;
366
+ const late = n ? `<p class="late">The return date passed ${n} ${plural(n, 'day', 'days')} ago. It stays on hold until you resume it.</p>` : '';
367
+ const why = h.reason ? ' ' + esc(cap(h.reason.replace(/\.$/, ''))) + '.' : '';
368
+ const date = edit || x.kind === 'none' ? `<input type="date" data-holdback="${esc(r.key)}" value="${esc(h.back || '')}" min="${esc(dayIso(1))}" aria-label="Return date">` : '';
369
+ const acts = open ? `<div class="acts">${date}<button type="button" class="bd-ib" data-holdgo="resume" data-id="${esc(r.key)}" aria-label="Resume now" title="Resume now">${SV(I.play)}</button>${date ? '' : `<button type="button" class="bd-ib" data-holdgo="date" data-id="${esc(r.key)}" data-i="${x.i}" aria-label="Change the return date" title="Change the return date">${SV(I.cal)}</button>`}</div>` : '';
370
+ return `<h4>${SV(I.pause)}${esc(head)}</h4><p>${esc(when)}${why}</p>${late}${acts}${msg('holdM')}`;
371
+ }
372
+ function openHold(r, i, btn) {
373
+ const now = new Date(), x = holdSpans(r, now).find((y) => y.i === i); if (!x) return;
374
+ Pop.open(holdHtml(r, x, now, false), btn, { label: holdWords(x, now), width: 300, cls: 'bd-hold', focus: x.kind === 'none' ? 'input' : '.bd-ib' });
375
+ }
376
+ async function runHold(r, k, btn) {
377
+ const m = $('#holdM'), p = prevOf(r);
378
+ if (k === 'date') { const now = new Date(), x = holdSpans(r, now).find((y) => y.i === +btn.dataset.i); if (!x) return; Pop.redraw(holdHtml(r, x, now, true)); const f = Pop.el().querySelector('input'); if (f) f.focus(); return; }
379
+ if (k === 'resume') {
380
+ const res = await press(btn, m, () => life(r.id, 'active', 'resumed')); if (!res) return;
381
+ await done(res, 'Resumed · ' + r.title, async () => { const u = await lifeBack(r, p); A.say(u && u.ok ? 'Undone.' : errOf(u)); await A.load(); });
382
+ }
383
+ }
384
+ async function setBack(r, input) {
385
+ const v = input.value; if (!/^\d{4}-\d{2}-\d{2}$/.test(v)) return;
386
+ const p = prevOf(r), res = await press(input, $('#holdM'), () => life(r.id, 'on-hold', (r.acts && r.acts.reason) || 'Held from the Board', v)); if (!res) return;
387
+ await done(res, 'On hold · ' + r.title + ' · back ' + md(day(v)), async () => { const u = await lifeBack(r, p); A.say(u && u.ok ? r.title + ' is back as it was.' : errOf(u)); await A.load(); });
388
+ }
389
+
390
+ export const open = { hold: openHold, new: (from) => Asks.openNew(from), asks: (from) => Asks.openAsks(from), row: openRowMenu, sprint: openSprint, metrics: openMetrics, find: openFind, filter: openFilter, gone: (from) => openGone(from, 'all'), bell: openBell, trend: openTrend, release: openRelease, doc: openDocPanel };
346
391
  export const closeDoc = () => { docOpen = null; };
347
392
 
348
393
  /* ── the presses ─────────────────────────────────────────────────────────────────────────────────────────────── */
394
+ document.addEventListener('change', (e) => { const f = e.target.closest && e.target.closest('[data-holdback]'); if (!f || !A || !M()) return; const r = A.rowOf(f.dataset.holdback); if (r) setBack(r, f); });
349
395
  document.addEventListener('input', (e) => { if (e.target.id === 'bdQ') { findQ = e.target.value; findAt = 0; const r = $('#bdQr'); if (r) r.innerHTML = findList(); } });
350
396
  document.addEventListener('keydown', (e) => {
351
397
  if (e.target.id !== 'bdQ') return;
@@ -369,6 +415,8 @@ document.addEventListener('click', async (e) => {
369
415
  const tr = t.closest('[data-trshow]'); if (tr) { const k = tr.dataset.trshow; if (A.F.chips.has(k)) A.F.chips.delete(k); else A.F.chips.add(k); Pop.close(false); A.redraw(); return; }
370
416
  const g = t.closest('[data-gone]'); if (g) { openGone(null, g.dataset.gone); return; }
371
417
  const w = t.closest('[data-why]'); if (w && Pop.isOpen() && Pop.el().contains(w)) { $$('[data-why]', Pop.el()).forEach((b) => { const on = b === w; b.classList.toggle('on', on); b.setAttribute('aria-checked', String(on)); }); return; }
418
+ const hz = t.closest('[data-hold]'); if (hz) { const r = A.rowOf(hz.dataset.hold); if (r) openHold(r, +hz.dataset.i, hz); return; }
419
+ const hg = t.closest('[data-holdgo]'); if (hg) { const r = A.rowOf(hg.dataset.id); if (r) runHold(r, hg.dataset.holdgo, hg); return; }
372
420
  const ra = t.closest('[data-rowact]'); if (ra) { const r = A.rowOf(ra.dataset.id); if (r) runRow(r, ra.dataset.rowact, ra); return; }
373
421
  const od = t.closest('[data-opendoc]'); if (od) { openDocPanel(od.dataset.opendoc, od); return; }
374
422
  const b = t.closest('[data-act]'); if (!b) return;
@@ -5,8 +5,9 @@
5
5
  * questions, usual(track) the usual days in the step, rowOf(key), pageHref(r), askHref(r, q), refreshJira(), send(r) the
6
6
  * Send to Jira sheet, acts(r, btn) the row actions popover, grillOpen(r, btn), onShow(key, from) / onHide() so the page
7
7
  * marks the row the item came from, programOf(r) the program it is in or null, openProgram(id, btn), turnProgram(r)
8
- * "Turn into a program", setTask(r, uid, state) a task's state, addTask(r, title) a new task (POST /api/boards/tasks/add),
9
- * viewDoc(path) }
8
+ * "Turn into a program", setTask(r, uid, state) a task's state, setDates(r, uid, { start?, due? }) its days (the Tasks
9
+ * views' quick changes, batch 9 item 5b), addTask(r, title) a new task (POST /api/boards/tasks/add),
10
+ * openTask(r, task) the task's own editor, viewDoc(path) }
10
11
  * openIni(r, from) the initiative: the ONE view (pm/ini-view.js from pm/ini-view-model.js, feedback batch 6 item 1; canvas OvIniA), the
11
12
  * same as Home's initiative page: the summary card, the stage card with its dates line (it replaced the Plan card, item 3),
12
13
  * Tasks as the WBS, then Documents and Linked. What the Board adds under them: drafted tickets and the PRD drift.
@@ -25,6 +26,7 @@ import * as TV from './tk-view.js';
25
26
  let O = null;
26
27
  let cur = null; // { key, tk } the initiative shown, and its ticket while the drill-in is shown
27
28
  let adding = null; // the key of the initiative whose inline Add a task is open
29
+ let addTo = ''; // the stage a task added there finishes (the Board's Next cell: "Add what finishes <stage>")
28
30
  const TI = (r) => (r && r.trail) || null;
29
31
  const tkState = (k) => (k.blocked ? 'Blocked' + (k.reason ? ' by ' + k.reason.replace(/^Waiting on /i, '') : '') : k.status || 'To do');
30
32
  const jiraAt = () => { const J = (O.M() && O.M().jira) || {}; return J.readAt ? 'Jira · ' + O.ago(J.readAt) : ''; };
@@ -75,17 +77,22 @@ function iniText(r) {
75
77
  return lines.join('\n');
76
78
  }
77
79
  function iniBody(r) {
78
- return viewHtml(viewOf(r), { add: !!(r.id && O.addTask), adding: adding === r.key, openTask: false, tail: VW.czSections(boardSections(r), { key: 'board' }) });
80
+ return viewHtml(viewOf(r), { add: !!(r.id && O.addTask), adding: adding === r.key, openTask: !!O.openTask, quick: !!(O.setTask && O.setDates), tail: VW.czSections(boardSections(r), { key: 'board' }) });
79
81
  }
80
82
  /** Presses inside the shown item: the view's own (pm/ini-view.js), a ticket's drill-in, the PRD-change question. A [data-doc] goes to the page's handler. */
81
83
  function wire(body, key) {
82
84
  const redraw = () => { const r = O.rowOf(key); if (!r || (cur && cur.tk)) return; const top = body.scrollTop; body.innerHTML = iniBody(r); body.scrollTop = top; };
83
85
  wireView(body, {
84
86
  check: (uid, b) => { const r = O.rowOf(key), k = r && (r.tasks || []).find((x) => x.uid === uid); if (r && O.setTask) O.setTask(r, uid, k && k.status === 'Done' ? 'To do' : 'Done'); },
87
+ // the quick changes (batch 9 item 5b): the status caret, the date press and a Timeline or Kanban drag, each with Undo in the toast
88
+ status: (uid, state) => { const r = O.rowOf(key); if (r && O.setTask) O.setTask(r, uid, state); },
89
+ dates: (uid, patch) => { const r = O.rowOf(key); if (r && O.setDates) O.setDates(r, uid, patch); },
85
90
  openTicket: (tk) => { const r = O.rowOf(key), k = r && ((r.track && r.track.tickets) || []).find((x) => x.key === tk); if (k) openTicket(r, k); },
91
+ // a task's title opens the one task editor (task-card.js) as a drill-in: ← comes back to the initiative (batch 9 item 5a)
92
+ openTask: (uid) => { const r = O.rowOf(key), k = r && (r.tasks || []).find((x) => x.uid === uid); if (k && O.openTask) { VW.drill(); O.openTask(r, k); } },
86
93
  add: () => { adding = key; redraw(); const f = body.querySelector('#ivAddTask'); if (f) f.focus(); },
87
- addCancel: () => { adding = null; redraw(); },
88
- addTask: async (title, inp) => { const r = O.rowOf(key); if (!r || !O.addTask) return; inp.disabled = true; const ok = await O.addTask(r, title); inp.disabled = false; if (ok) { inp.value = ''; inp.focus(); } },
94
+ addCancel: () => { adding = null; addTo = ''; redraw(); },
95
+ addTask: async (title, inp) => { const r = O.rowOf(key); if (!r || !O.addTask) return; inp.disabled = true; const ok = await O.addTask(r, title, addTo); inp.disabled = false; if (ok) { inp.value = ''; inp.focus(); } },
89
96
  primary: (act, b) => {
90
97
  const r = O.rowOf(key); if (!r) return;
91
98
  if (act === 'grill') O.grillOpen(r, b);
@@ -108,13 +115,13 @@ function wire(body, key) {
108
115
  }
109
116
  /** The shell's id of an initiative: its record id, so Discuss in chat names it (?about=init:<id>&vid=<id>) and Home reopens it beside the chat. */
110
117
  export const vidOf = (r) => (r.id ? String(r.id) : 'bd:' + r.key);
111
- export function openIni(r, from) {
118
+ export function openIni(r, from, o = {}) {
112
119
  if (!O || !r || !r.track) return;
113
- adding = null;
120
+ adding = o.addTo != null ? r.key : null; addTo = o.addTo || '';
114
121
  // a row with no record id has no chat of its own: its question goes to the board's chat
115
122
  VW.open({ kind: 'Initiative', title: r.title, icon: 'flag', id: vidOf(r), url: r.id ? O.pageHref(r) : '', full: true,
116
123
  discuss: r.id ? true : () => location.assign(O.askHref(r, '')), more: iniMore(r), rename: O.rename ? O.rename(r) : null,
117
- render: (body) => { const x = O.rowOf(r.key) || r; cur = { key: x.key, tk: null }; O.onShow(x.key, from); body.innerHTML = iniBody(x); wire(body, x.key); },
124
+ render: (body) => { const x = O.rowOf(r.key) || r; cur = { key: x.key, tk: null }; O.onShow(x.key, from); body.innerHTML = iniBody(x); wire(body, x.key); if (adding === x.key) { const f = body.querySelector('#ivAddTask'); if (f && document.activeElement !== f) f.focus(); } },
118
125
  onClose: () => { if (cur && cur.key === r.key && !cur.tk) { cur = null; O.onHide(); } } });
119
126
  }
120
127
 
@@ -0,0 +1,119 @@
1
+ /* pm/bd-next.js — the Board's Next cell (batch 9 item 4; canvas XocA, XocAList, XocAPhone): one line that says what finishes the step next.
2
+ * The stage track, the List and the phone draw the same cell.
3
+ *
4
+ * nextOf(r, ctx) → { you, verb, obj, tail, tone, count, due, act } | null PURE. ctx: { self (a PMOS-self board: the stage moves with the files) }
5
+ * nextHtml(r, o) → the cell's markup. o: { self, icon (false on the phone), due (false in the List: Finish says the date) }
6
+ *
7
+ * The line is `[blue dot when it waits on the PM] <verb> <object in blue ink>`, the count muted on the right, and an icon action only where
8
+ * PMOS can do the step itself (draft with Claude, move the stage, add a stage task, link the epic, read Jira). The icon is a button with
9
+ * data-nx (draft | move | add | epic | jira) and data-nxrow (the row key); the page runs it. Nothing is invented: a step with no record
10
+ * behind it draws nothing (zero is silence), and the initiative's whole progress is never shown as the step's. */
11
+ import { esc } from './premium-shell.js';
12
+ import { sectionOf } from './ini-view-model.js';
13
+
14
+ const PF = 'product-feature';
15
+ const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
16
+ const IC = {
17
+ draft: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z', move: 'M5 12h14M13 6l6 6-6 6', add: 'M12 5v14M5 12h14',
18
+ epic: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1', jira: 'M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7',
19
+ };
20
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
21
+ const dm = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
22
+ // a part's name as the line says it, and the verb that writes it ("Write the problem statement")
23
+ const PART = {
24
+ problem: ['Write the', 'problem statement'], users: ['Describe the', 'users'], evidence: ['Add the', 'evidence'], scope: ['Write the', 'scope'],
25
+ 'success metric': ['Set the', 'success metric'], 'success measure': ['Set the', 'success measure'], risks: ['List the', 'risks'],
26
+ 'business case': ['Write the', 'business case'], 'who asked': ['Name', 'who asked'], timeline: ['Set the', 'timeline'], tickets: ['Draft the', 'tickets'],
27
+ 'KR or health budget': ['Pick the', 'KR or health budget'], rank: ['Rank it on the', 'roadmap'],
28
+ report: ['Draft the', 'outcome report'], evaluation: ['Write the', 'evaluation'], 'your verdict': ['Give', 'your verdict'],
29
+ };
30
+ // the parts PMOS can draft with Claude (a document's section); the others are the PM's or another tool's
31
+ const DRAFTS = new Set(['problem', 'users', 'evidence', 'scope', 'success metric', 'success measure', 'risks', 'business case', 'report', 'evaluation']);
32
+ const OUT = { triage: 'BRD', discover: 'PRD' };
33
+ const OPEN_TK = ['In review', 'In progress', 'To do'];
34
+ const CLOSED = new Set(['Done', "Won't do", 'Archived']);
35
+
36
+ /** The stage after the current one, by the row's own list of stage names (the ⋯ menu's Move to). */
37
+ function nextStage(r) {
38
+ const a = r.acts || {}, L = a.stages || [], i = L.indexOf(a.stage);
39
+ return i >= 0 && L[i + 1] ? L[i + 1] : null;
40
+ }
41
+ const canMove = (r, ctx) => !(ctx && ctx.self) && !(r.acts && r.acts.life);
42
+ function moveLine(r, ctx, count) {
43
+ const to = nextStage(r);
44
+ return to ? { you: true, verb: 'Move to', obj: to, count, act: canMove(r, ctx) ? { kind: 'move', label: 'Move to ' + to } : null } : null;
45
+ }
46
+ /** A part of the step's output, as the line: Write the <part>, or Review the <part> when the part waits on the PM. */
47
+ function partLine(p, count, draftable) {
48
+ const [verb, obj] = PART[p.name] || ['Finish the', p.name];
49
+ if (/verdict/.test(p.name)) return { you: true, verb: 'Give', obj: 'your verdict', count }; // the verdict is always the PM's
50
+ if (p.you && /^your /.test(p.name)) return { you: true, verb: 'Give', obj: p.name, count }; // "your review": Give your review
51
+ if (p.you) return { you: true, verb: 'Review the', obj, count };
52
+ return { verb, obj, count, act: draftable && DRAFTS.has(p.name) ? { kind: 'draft', label: 'Draft the ' + obj + ' with Claude', q: 'Draft the ' + obj } : null };
53
+ }
54
+ /** The open parts in the order the line reads them: one that waits on the PM first, then the first not done. */
55
+ const firstPart = (parts) => parts.find((p) => !p.done && p.you) || parts.find((p) => !p.done) || null;
56
+ /** A task title split into its verb and the rest: "Score vendor B's POC" → Score + vendor B's POC; a title that does not start with a word is finished. */
57
+ function taskLine(title) {
58
+ const m = /^([A-Z][a-z]+)\s+(\S.*)$/.exec(String(title || '').trim());
59
+ return m ? { verb: m[1], obj: m[2] } : { verb: 'Finish', obj: String(title || '').trim() };
60
+ }
61
+
62
+ export function nextOf(r, ctx = {}) {
63
+ if (!r || (r.acts && (r.acts.life === 'cancelled' || r.acts.archived))) return null;
64
+ const t = r.track || {}, it = r.trail || {};
65
+ // another workflow: the first open task of its stage, by order
66
+ if (r.wf && r.wf.id && r.wf.id !== PF && r.wfStage) {
67
+ const st = r.wfStage, list = r.wfStages || [st];
68
+ const mine = (r.tasks || []).filter((k) => sectionOf(k, list) === st.key && k.status !== 'Archived')
69
+ .map((k, i) => ({ k, i })).sort((a, b) => (Number.isFinite(a.k.order) ? a.k.order : 1e9 + a.i) - (Number.isFinite(b.k.order) ? b.k.order : 1e9 + b.i)).map((x) => x.k);
70
+ const counted = mine.filter((k) => k.status !== "Won't do"), done = counted.filter((k) => k.status === 'Done').length;
71
+ if (!mine.length) return { verb: 'Add what finishes', obj: st.name, act: { kind: 'add', label: 'Add a task to ' + st.name, stage: st.key } };
72
+ const open = mine.find((k) => !CLOSED.has(k.status));
73
+ const count = counted.length ? done + '/' + counted.length + ' tasks' : '';
74
+ return open ? { ...taskLine(open.title), count } : moveLine(r, ctx, count);
75
+ }
76
+ const key = t.key;
77
+ if (!key) return null;
78
+ if (key === 'build' || key === 'deliver') {
79
+ const tk = t.tickets || [];
80
+ if (tk.length) {
81
+ const p = t.prog || {}, count = p.total ? p.done + '/' + p.total + (p.unit === 'pts' ? ' pts' : ' tickets') : '';
82
+ const open = tk.filter((k) => k.status !== 'Done');
83
+ const pick = open.find((k) => k.blocked) || OPEN_TK.map((s) => open.find((k) => !k.blocked && k.status === s)).find(Boolean);
84
+ if (pick) return { verb: 'Finish', obj: pick.key, tail: open.length > 1 ? (open.length - 1) + ' more' : '', tone: pick.blocked ? 'red' : '', count, title: pick.key + ' · ' + pick.title + (pick.blocked ? ' · blocked' : '') };
85
+ if (key === 'deliver') return { you: true, verb: 'Give your', obj: 'sign-off', count };
86
+ return moveLine(r, ctx, count);
87
+ }
88
+ const epic = (it.links && it.links.epic) || (r.epics || [])[0] || null;
89
+ return epic ? { verb: 'Read', obj: 'Jira', act: { kind: 'jira', label: 'Read Jira again for ' + epic } } : { verb: 'Link the', obj: 'Jira epic', act: { kind: 'epic', label: 'Link the Jira epic' } };
90
+ }
91
+ const due = (key === 'monitor' || key === 'evaluate') && r.end ? 'due ' + dm(r.end) : '';
92
+ if (key === 'monitor') return { verb: 'Draft the', obj: 'outcome report', due, act: { kind: 'draft', label: 'Draft the outcome report with Claude', q: 'Draft the outcome report' } };
93
+ // the parts of the step: the trail's (the documents' headings, the tickets drafted), else what the model counts (Prioritize's anchor and rank)
94
+ let parts = Array.isArray(it.parts) && it.parts.length ? it.parts : null;
95
+ if (!parts && (key === 'plan' || key === 'prioritize')) parts = (t.segs || []).filter((s) => s.st === 'done' || s.st === 'to do').map((s) => ({ name: key === 'prioritize' && /^kr/i.test(s.name) ? 'KR or health budget' : s.name.toLowerCase(), done: s.st === 'done' }));
96
+ if (!parts || !parts.length) return key === 'evaluate' ? { verb: 'Draft the', obj: 'outcome report', due, act: { kind: 'draft', label: 'Draft the outcome report with Claude', q: 'Draft the outcome report' } } : null;
97
+ // Plan's ticket part says how many: "3 tickets drafted, waiting on you" is the PM's Commit
98
+ parts = parts.map((p) => (/tickets/.test(p.name) ? { ...p, name: 'tickets', pushed: /pushed/.test(p.name) } : p));
99
+ const d = parts.filter((p) => p.done).length, n = parts.length;
100
+ const count = OUT[key] ? OUT[key] + ' ' + d + '/' + n : key === 'evaluate' ? '' : d + '/' + n + ' parts';
101
+ const p = firstPart(parts);
102
+ if (!p) return moveLine(r, ctx, count);
103
+ const L = partLine(p, count, true);
104
+ if (p.name === 'tickets' && p.you) { L.verb = 'Commit the'; L.obj = 'drafted tickets'; } else if (p.pushed) L.verb = 'Push the';
105
+ return { ...L, due };
106
+ }
107
+
108
+ /** The cell. The icon is ghosted and lights with the row's hover or focus; the phone draws no icon (the row opens the panel). */
109
+ export function nextHtml(r, o = {}) {
110
+ const x = nextOf(r, o);
111
+ if (!x) return '';
112
+ const words = (x.verb ? x.verb + ' ' : '') + x.obj + (x.tail ? ' · ' + x.tail : '');
113
+ const count = [x.count, o.due === false ? '' : x.due].filter(Boolean)[0] || '';
114
+ const act = x.act && o.icon !== false
115
+ ? `<button type="button" class="bd-nxa" data-nx="${esc(x.act.kind)}" data-nxrow="${esc(r.key)}"${x.act.q ? ` data-q="${esc(x.act.q)}"` : ''}${x.act.stage ? ` data-stage="${esc(x.act.stage)}"` : ''} aria-label="${esc(x.act.label)}" title="${esc(x.act.label)}">${SV(IC[x.act.kind])}</button>` : '';
116
+ return `<div class="bd-nx">${x.you ? '<i class="cz-dot you" role="img" aria-label="Waits on you"></i>' : ''}`
117
+ + `<span class="tx" title="${esc(x.title || words)}">${x.verb ? esc(x.verb) + ' ' : ''}<em${x.tone ? ` class="${x.tone}"` : ''}>${esc(x.obj)}</em>${x.tail ? ' · ' + esc(x.tail) : ''}</span>`
118
+ + `${count ? `<span class="mu">${esc(count)}</span>` : ''}${act}</div>`;
119
+ }