create-pmos 0.476.0 → 0.477.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 (82) hide show
  1. package/package.json +20 -14
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/board-publish-ui-test.js +11 -16
  7. package/workspace/board-shared-ui-test.js +34 -33
  8. package/workspace/changelog.json +19 -0
  9. package/workspace/guide/briefing-premium.md +2 -2
  10. package/workspace/guide/claude-proposes.md +3 -1
  11. package/workspace/guide/forecast.md +16 -3
  12. package/workspace/guide/home.md +2 -2
  13. package/workspace/guide/workflows.md +13 -2
  14. package/workspace/home-railcard-test.js +4 -4
  15. package/workspace/home-rows-test.js +15 -4
  16. package/workspace/ini-workflow-test.js +1 -1
  17. package/workspace/lib/board-pack.js +20 -1
  18. package/workspace/lib/board-trail.js +17 -1
  19. package/workspace/lib/boards-host.js +22 -2
  20. package/workspace/lib/briefing-premium-agent.js +2 -2
  21. package/workspace/lib/engine/boards.js +15 -3
  22. package/workspace/lib/engine/workflows.js +79 -10
  23. package/workspace/lib/forecast-offer.js +57 -0
  24. package/workspace/lib/grill-runs.js +1 -0
  25. package/workspace/lib/grill.js +1 -1
  26. package/workspace/lib/insight-moves.js +8 -6
  27. package/workspace/lib/news-for-you.js +6 -4
  28. package/workspace/lib/report-chat.js +2 -0
  29. package/workspace/lib/routes-board-publish.js +7 -2
  30. package/workspace/lib/routes-boards.js +18 -5
  31. package/workspace/lib/routes-briefing-premium.js +16 -2
  32. package/workspace/lib/routes-forecast.js +8 -1
  33. package/workspace/lib/routes-insight-moves.js +7 -5
  34. package/workspace/lib/routes-news.js +3 -1
  35. package/workspace/lib/routes-workflows.js +13 -0
  36. package/workspace/lib/wf-bridge.js +165 -0
  37. package/workspace/package-lock.json +2 -2
  38. package/workspace/package.json +1 -1
  39. package/workspace/panels-test.js +1 -2
  40. package/workspace/public/pm/bd-fc-card.js +45 -0
  41. package/workspace/public/pm/bd-next.js +1 -1
  42. package/workspace/public/pm/bd-publish.css +22 -18
  43. package/workspace/public/pm/bd-publish.js +57 -48
  44. package/workspace/public/pm/bd-shared.css +92 -30
  45. package/workspace/public/pm/bd-shared.js +143 -55
  46. package/workspace/public/pm/bd-span.js +27 -7
  47. package/workspace/public/pm/cozy-board.css +15 -0
  48. package/workspace/public/pm/cozy-ev.css +46 -0
  49. package/workspace/public/pm/cozy-home.css +4 -4
  50. package/workspace/public/pm/cozy-insights.css +21 -0
  51. package/workspace/public/pm/cozy-jl.js +158 -0
  52. package/workspace/public/pm/cozy-news.js +56 -2
  53. package/workspace/public/pm/cozy-panels.js +3 -2
  54. package/workspace/public/pm/cozy-settings.js +11 -7
  55. package/workspace/public/pm/cozy-today.css +3 -0
  56. package/workspace/public/pm/cozy-viewer.js +19 -3
  57. package/workspace/public/pm/goal-forecast.js +101 -0
  58. package/workspace/public/pm/hi-pop.css +16 -0
  59. package/workspace/public/pm/home-app.js +11 -4
  60. package/workspace/public/pm/home-day.js +5 -3
  61. package/workspace/public/pm/home-list.js +14 -4
  62. package/workspace/public/pm/home-mentions.js +5 -0
  63. package/workspace/public/pm/home-task.js +1 -1
  64. package/workspace/public/pm/home-today.js +11 -4
  65. package/workspace/public/pm/ini-view-model.js +27 -14
  66. package/workspace/public/pm/ini-view.js +1 -1
  67. package/workspace/public/pm/ini-wf-model.js +76 -19
  68. package/workspace/public/pm/ini-wf.js +69 -18
  69. package/workspace/public/pm/metric-drafts.css +9 -0
  70. package/workspace/public/pm/metric-drafts.js +2 -2
  71. package/workspace/public/pm/premium-board.js +13 -3
  72. package/workspace/public/pm/premium-insights.js +43 -6
  73. package/workspace/public/pm/premium-report-tab.js +13 -3
  74. package/workspace/public/pm/premium-vw-item.js +1 -1
  75. package/workspace/public/pm/readonly.js +1 -0
  76. package/workspace/public/pm/report-chat.js +2 -1
  77. package/workspace/public/pm/task-card.js +4 -3
  78. package/workspace/public/pm/wf-page.css +9 -0
  79. package/workspace/public/pm/wf-page.js +30 -1
  80. package/workspace/run-tests.js +10 -2
  81. package/workspace/server.js +5 -2
  82. package/workspace/test-lists/forecast-board.json +5 -0
@@ -627,6 +627,11 @@ function drawList() {
627
627
  drawRailCard();
628
628
  drawRecTop();
629
629
  }
630
+ /** The list's own fold (batch 20 item 6): kept on this computer, the one thing that folds or unfolds the list. With a Viewer open it is the rail. */
631
+ function setFold(on) {
632
+ S.folded = !!on; store.set('pmos.home.fold', on ? '1' : null); drawList();
633
+ if (VW.isOpen() && VW.panels) VW.panels.relayout();
634
+ }
630
635
  /* ── the folded rail's card (batch 18 item 14, FlA1–FlA5) ──
631
636
  * With the Viewer wide, Home's list folds to a rail of group tiles (cozy-viewer.js). A tile's press opens a card beside it with that group's
632
637
  * rows, Home's own (iniHtml): a row opens as on Home and the card closes, the rail and the Viewer's width stay; the pill lists the sessions
@@ -1765,6 +1770,7 @@ $('#hmList').onclick = (e) => { // delegated: every press on the list is a <bu
1765
1770
  if (d.hmSes) { sesPill(d.hmSes === S.ses ? null : d.hmSes); return; } // an initiative's pill: what sits in it, under it (a sheet on a phone)
1766
1771
  if ('hmSesx' in d) { sesPill(null); return; }
1767
1772
  if (d.hmSesnew) { sesPill(null, false); newIn(d.hmSesnew); return; }
1773
+ if (d.hmProdnew) { sesPill(null, false); const g = ((S.M && S.M.groups) || []).find((x) => x.key === d.hmProdnew); if (g && !g.primary && g.product && g.product.ws) goOtherProduct(g); else goIni('product'); { const c = chat.current(); if (c && c.newChat) c.newChat(); } return; }
1768
1774
  if (d.hmCompact) { compact(d.hmCompact); return; } // ✓ on Claude's ✦ Compact (batch 13 item 8): the pill's list stays open
1769
1775
  if (S.ses && !b.closest('.hv-spp, .hv-sps, .hv-rcs')) sesPill(null, false); // a press anywhere else in the list closes it
1770
1776
  if (d.hmSel) { if (S.ses) sesPill(null, false); if (S.day) S.day = false; select(d.hmSel); return; }
@@ -1796,9 +1802,9 @@ $('#hmList').onclick = (e) => { // delegated: every press on the list is a <bu
1796
1802
  if (d.hmGroup) { if (S.shut.has(d.hmGroup)) S.shut.delete(d.hmGroup); else S.shut.add(d.hmGroup); store.set('pmos.home.shut', JSON.stringify([...S.shut])); drawList(); return; }
1797
1803
  if ('hmAllneeds' in d) { S.allNeeds = !S.allNeeds; drawList(); return; }
1798
1804
  if ('hmNew' in d) { menu(b, newItems(), 'New'); return; }
1799
- // the list header's fold (batch 18 item 15): with a Viewer open the list folds to the rail and the Viewer takes the room; with none, the
1800
- // list folds away and the button at the top left brings it back
1801
- if ('hmFold' in d) { if (VW.isOpen()) { VW.wide(true); return; } S.folded = true; store.set('pmos.home.fold', '1'); drawList(); return; }
1805
+ // the list header's fold (batch 18 item 15; batch 20 item 6): with a Viewer open the list folds to the rail; with none, it folds away and the
1806
+ // button at the top left brings it back. Only this fold and its unfold change the list: a Viewer's width, wide or close never do
1807
+ if ('hmFold' in d) { setFold(true); return; }
1802
1808
  if ('hmMeet' in d) { const m = H.meetLineOf(S.D.today); if (m) openMeeting(m.meeting); return; }
1803
1809
  if ('hmCal' in d) { openCalendar(); return; }
1804
1810
  if ('hmRec' in d) { MORE.openRecorder().then(() => drawList()); return; }
@@ -1887,7 +1893,8 @@ async function todayPress(k, b) {
1887
1893
  }
1888
1894
  }
1889
1895
  $('#hmDesk').insertAdjacentHTML('afterbegin', `<button type="button" class="hm-unfold" id="hmUnfold" aria-label="Show the list" title="Show the list">${SVG(I.fold, 16)}</button>`);
1890
- $('#hmUnfold').onclick = () => { S.folded = false; store.set('pmos.home.fold', null); drawList(); };
1896
+ $('#hmUnfold').onclick = () => setFold(false);
1897
+ VW.listFold({ folded: () => S.folded && !isPhone(), show: () => setFold(false) });
1891
1898
  function cta() {
1892
1899
  if (S.ini === 'product') { const C = H.productCard(S.D); if (C.sent) openUpdateViewer(); else { select('n:update'); } return; }
1893
1900
  const h = S.H || {};
@@ -227,11 +227,13 @@ function newsRow(it, now) {
227
227
  const who = it.kind === 'task' ? (it.from || 'Someone') : (it.product || 'Claude');
228
228
  const when = it.at ? ago(new Date(it.at).toISOString(), now) : '';
229
229
  const head = it.kind === 'task' ? String(it.title || '').replace(/^New task: /, '') : it.title;
230
- // an overlap note is Claude's proposal (batch 18 item 2b): the ✦ tile and both initiatives by name, never an id
231
- const sub = it.kind === 'overlap' ? [it.a && it.a.title, it.b && it.b.title].filter(Boolean).join(' and ') || 'Two open initiatives'
230
+ // an overlap note is Claude's proposal (batch 18 item 2b): the ✦ tile and both initiatives by name, never an id; so is moving a replaced
231
+ // workflow's initiatives (batch 20 item 3, WmB: "Shown under your day, in ✦")
232
+ const sub = it.kind === 'wf-bridge' ? ['From ' + ((it.from && it.from.name) || 'the old workflow'), (it.groups || []).length ? 'into ' + it.groups.map((g) => g.name).join(', ') : ''].filter(Boolean).join(' · ')
233
+ : it.kind === 'overlap' ? [it.a && it.a.title, it.b && it.b.title].filter(Boolean).join(' and ') || 'Two open initiatives'
232
234
  : it.kind === 'task' ? ['Given to you' + (it.from ? ' from ' + it.from : ''), it.due ? 'due ' + it.due : '', it.iniTitle ? 'filed under ' + it.iniTitle : ''].filter(Boolean).join(' · ')
233
235
  : ['Finished while you were away', it.target, when].filter(Boolean).join(' · ');
234
- const av = it.kind === 'overlap' ? `<span class="yd-av sp" aria-hidden="true">${svg(SPARK, 13, 2)}</span>` : `<span class="yd-av${it.kind === 'finished' ? ' b' : ''}" aria-hidden="true">${esc(initials(who))}</span>`;
236
+ const av = it.kind === 'overlap' || it.kind === 'wf-bridge' ? `<span class="yd-av sp" aria-hidden="true">${svg(SPARK, 13, 2)}</span>` : `<span class="yd-av${it.kind === 'finished' ? ' b' : ''}" aria-hidden="true">${esc(initials(who))}</span>`;
235
237
  return `<button type="button" class="yd-nw" data-yd="news" data-id="${esc(it.id)}"><i class="yd-nd" aria-hidden="true"></i>${av}<span class="yd-mt"><b>${esc(head)}</b><em>${esc(sub)}</em></span></button>`;
236
238
  }
237
239
  /** The New for you fold's parts: the 3 newest rows, "N more", the morning brief's digests as one row, and the ✓✓ that marks all seen.
@@ -148,6 +148,13 @@ function iniRowOf(D, r, needs, now) {
148
148
  stage: r.stage || '', at: rowAt(r), steps: ownSteps(r), yours: kids.filter(isMove).length, late: kids.some((k) => k.kind === 'task' && k.mine && k.late) };
149
149
  }
150
150
 
151
+ /** A product's own chat key: the board's product is `product` or `product:<n>`; another product is `product:<ws>` or `product:<ws>:<n>`
152
+ * (home-app.js productTarget, goOtherProduct, newProduct). */
153
+ export function isProductChat(key, p) {
154
+ const k = String(key || ''), ws = p && p.ws ? 'product:' + p.ws : null;
155
+ return !!((p && p.primary && (k === 'product' || /^product:\d+$/.test(k))) || (ws && (k === ws || /^:\d+$/.test(k.slice(ws.length)) && k.startsWith(ws + ':'))));
156
+ }
157
+
151
158
  /* ── programs (initiative program-hierarchy, H4; canvas PgHomePhone, PgHomeDesk) ── */
152
159
  const closedOf = (n, turnN) => [n ? plural(n, 'initiative', 'initiatives') : '', turnN ? turnN + ' your turn' : ''].filter(Boolean).join(' · ') || 'Nothing open';
153
160
  const isMe = (D, who) => { const me = String((D.today && D.today.me) || '').toLowerCase(), w = String(who || '').toLowerCase(); return !w || /^(pm|you)(:|$)/.test(w) || (!!me && (w === me || w.startsWith(me + ' '))); };
@@ -245,21 +252,24 @@ export function homeList(D, o = {}) {
245
252
  const flat = mineNeeds.filter((x) => !x.ini || !ids.has(x.ini)).filter((x) => !x.needSession).map((x) => ({ ...x, flat: true, hint: bareHint(x) }));
246
253
  const turnN = inis.filter((x) => x.turn).length + flat.length;
247
254
  const shown = inis.filter((x) => x.turn || x.busy);
248
- groups.push({ key: 'p:' + p.key, kind: 'product', product: p, name: p.name, initials: p.initials, tone: p.tone, primary: !!p.primary, goals: p.goals, flat, inis: shown, rest: inis.filter((x) => !shown.includes(x)),
249
- count: inis.length, turnN, yours: inis.reduce((n, x) => n + x.yours, 0) + flat.length, late: inis.some((x) => x.late), closedLine: [inis.length ? plural(inis.length, 'initiative', 'initiatives') : '', turnN ? turnN + ' your turn' : ''].filter(Boolean).join(' · ') || 'Nothing open' });
255
+ // the product's own chats (its heading's chat and its new sessions) sit in the header's pill, as an initiative's sit in its row's
256
+ const kids = (D.sessions || []).filter((s) => listed(s) && isProductChat(keyOfSession(s), p)).map((s) => sessionRow(s, D.desk && D.desk.roles)).sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0));
257
+ groups.push({ key: 'p:' + p.key, kind: 'product', product: p, name: p.name, kids, initials: p.initials, tone: p.tone, primary: !!p.primary, goals: p.goals, flat, inis: shown, rest: inis.filter((x) => !shown.includes(x)),
258
+ count: inis.length, turnN, yours: inis.reduce((n, x) => n + x.yours, 0) + flat.length + kids.filter((k) => k.state === 'needs' || k.state === 'blocked').length, late: inis.some((x) => x.late), closedLine: [inis.length ? plural(inis.length, 'initiative', 'initiatives') : '', turnN ? turnN + ' your turn' : ''].filter(Boolean).join(' · ') || 'Nothing open' });
250
259
  }
251
260
  // programs first (program-hierarchy P3): each program takes its initiatives out of their product groups, so an initiative shows once
252
261
  groups.unshift(...programGroups(D, groups, products, o, now));
253
262
  // the programs and products in the PM's sort or own order, the same as the Board's (batch 14 item 8, order-model.js)
254
263
  groups.splice(0, groups.length, ...sortTop(groups, D.order, TOP_ACC));
255
264
  // sessions that wait on the PM and belong to no initiative of a product: they are next steps too, under "Not in an initiative"
256
- const looseNeeds = needs.filter((x) => !used.has(x.id) && !(x.ini && groups.some((g) => g.inis.concat(g.rest).some((i) => i.ini === x.ini))));
265
+ const looseNeeds = needs.filter((x) => !used.has(x.id) && !(x.needSession && products.some((p) => isProductChat(x.key, p))) && !(x.ini && groups.some((g) => g.inis.concat(g.rest).some((i) => i.ini === x.ini))));
257
266
  const loose = [];
258
267
  for (const x of looseNeeds) loose.push({ ...x, flat: true });
259
268
  // an item the PM linked to an initiative (the clean-up, batch 13 item 3) sits under that initiative, not here
260
269
  for (const r of tabRows('today')) if (!r.ini || !groups.some((g) => g.inis.concat(g.rest).some((i) => i.ini === r.ini))) loose.push(itemRow(r));
261
270
  for (const m of todayOf(D).filter((x) => !meetIni(x) && x.state !== 'past')) loose.push(meetRow(m, null));
262
- for (const s of (D.sessions || []).filter((s) => listed(s) && !iniOfSession(s) && s.shown !== 'needs' && s.shown !== 'blocked')) loose.push({ ...sessionRow(s, D.desk && D.desk.roles), loose: true });
271
+ const inProduct = (s) => products.some((p) => isProductChat(keyOfSession(s), p));
272
+ for (const s of (D.sessions || []).filter((s) => listed(s) && !iniOfSession(s) && !inProduct(s) && s.shown !== 'needs' && s.shown !== 'blocked')) loose.push({ ...sessionRow(s, D.desk && D.desk.roles), loose: true });
263
273
  // the folded line's signals (HvAC .lh): a blue dot when a row waits on the PM, an amber square when one of the PM's own is late
264
274
  const lsig = { needs: loose.filter((r) => r.state === 'needs' || r.state === 'blocked').length, sessions: loose.filter((r) => r.kind === 'session' || r.needSession).length, tasks: loose.filter((r) => r.check).length, late: loose.filter((r) => r.check && r.late).length };
265
275
  groups.push({ key: 'loose', kind: 'loose', name: 'Not in an initiative', rows: loose, n: loose.length, sig: lsig });
@@ -336,6 +336,11 @@ export function openMentions(ctx, o = {}) {
336
336
  setTimeout(tick, 5000);
337
337
  // the desktop opens wide, so the list and the conversation sit side by side (MnA4); "Back to the side" keeps the one-column list
338
338
  if (!(typeof innerWidth === 'number' && innerWidth < 1280)) { VW.wide(true); if (LIST && LIST.body === body && canSplit(body) !== X.split) draw(body); }
339
+ // the Viewer's width changes without a new open (the PM folds or unfolds Home's list, drags the divider): side by side follows it (batch 20 item 6)
340
+ if (typeof ResizeObserver === 'function' && !body.__mnRo) {
341
+ body.__mnRo = new ResizeObserver(() => { if (body.isConnected && LIST && LIST.body === body && canSplit(body) !== X.split) draw(body); });
342
+ body.__mnRo.observe(body);
343
+ }
339
344
  // one column: the asked conversation opens over the list, as a press on its row does
340
345
  if (o.sel && !X.split) { const m = find(o.sel); if (m) openOne(m, ctx, { back: true }); }
341
346
  // read again on open, so the list is never older than the press that opened it
@@ -57,7 +57,7 @@ export function openTask(task, h) {
57
57
  const ini = (I.initiatives || []).find((x) => x.id === t.ini);
58
58
  sections = ini && Array.isArray(ini.stages) && ini.stages.length ? ini.stages : null;
59
59
  const row = (I.items || []).find((x) => x.uid === raw.uid) || raw;
60
- const P = await placeOf(row, sections || [], (I.items || []).filter((x) => x.ini === t.ini && x.src !== 'jira'));
60
+ const P = await placeOf(row, sections || [], (I.items || []).filter((x) => x.ini === t.ini && x.src !== 'jira'), (ini && ini.map) || null);
61
61
  t.section = P.section; t.wbs = P.wbs; card.draw();
62
62
  }).catch(() => {});
63
63
  return body;
@@ -128,16 +128,23 @@ function pillHtml(r, o) {
128
128
  const on = o.ses === sesKey(r, o);
129
129
  return `<button type="button" class="hv-sp ${m.top}${on ? ' on' : ''}" data-hm-ses="${esc(sesKey(r, o))}" aria-haspopup="dialog" aria-expanded="${on}" aria-label="${esc(m.say)}. ${on ? 'Hide' : 'Show'}" title="${esc(m.say)}">${pillMark(m.top)}<span class="n">${m.n}</span></button>`;
130
130
  }
131
+ /** A product's own chats as a row for the pill (the same pill and list an initiative row has; Wawan, batch 20 item 10). */
132
+ const prodRow = (g) => ({ id: 'product', at: -1, name: g.name, kids: g.kids || [], prodNew: g.key });
133
+ const prodPillHtml = (g, o) => (o.card ? '' : pillHtml(prodRow(g), { ...o, gk: g.key }));
134
+ function prodPopHtml(g, o) {
135
+ const r = prodRow(g);
136
+ return !o.card && !o.phone && r.kids.length && o.ses === sesKey(r, { gk: g.key }) ? `<div class="hv-spp hv-spp-p" data-esc-layer role="dialog" aria-label="In ${esc(g.name)}">${sesListHtml(r, o)}</div>` : '';
137
+ }
131
138
  /** The list behind the pill: the rows that used to nest, waiting first, then + for a new session here. */
132
139
  function sesListHtml(r, o) {
133
140
  const kids = r.kids.slice().sort((a, b) => RANKED.indexOf(kidState(a)) - RANKED.indexOf(kidState(b)));
134
141
  return kids.map((k) => rowHtml(k, { ...o, kid: false, sub: kidSub(k), act: kidActHtml(k), safe: !!(k.close && k.close.safe) })).join('')
135
- + `<div class="hv-spf"><button type="button" class="ut-ib hv-ib" data-hm-sesnew="${esc(r.ini || '')}" aria-label="New session in ${esc(r.name)}" title="New session here">${svg(P.plus, 18)}</button></div>`;
142
+ + `<div class="hv-spf"><button type="button" class="ut-ib hv-ib" ${r.prodNew ? `data-hm-prodnew="${esc(r.prodNew)}"` : `data-hm-sesnew="${esc(r.ini || '')}"`}" aria-label="New session in ${esc(r.name)}" title="New session here">${svg(P.plus, 18)}</button></div>`;
136
143
  }
137
144
  /** On a phone the list is a sheet over Home (as Your day was): the initiative's name and stage track on top. M is homeList(). */
138
145
  export function sesSheetHtml(M, o) {
139
146
  const g = o.ses && M.groups.find((x) => o.ses.startsWith(x.key + '|'));
140
- const r = g && (g.inis || []).concat(g.rest || []).find((x) => o.ses === g.key + '|' + x.id);
147
+ const r = g && (o.ses === g.key + '|product' ? prodRow(g) : (g.inis || []).concat(g.rest || []).find((x) => o.ses === g.key + '|' + x.id));
141
148
  if (!r || !r.kids.length) return '';
142
149
  return `<button type="button" class="hv-scrim" data-hm-sesx tabindex="-1" aria-label="Close"></button><section class="hv-sheet hv-sps" data-esc-layer role="dialog" aria-label="In ${esc(r.name)}" tabindex="-1"><div class="hv-grab" aria-hidden="true"></div>`
143
150
  + `<div class="hv-sbar"><b>${esc(r.name)}</b>${track(r.at, r.stage, r.steps)}<button type="button" class="ut-ib hv-ib" data-hm-sesx aria-label="Close" title="Close">${svg(P.x, 20)}</button></div>`
@@ -164,8 +171,8 @@ function productHtml(g, o) {
164
171
  const say = [g.name, open ? (g.goals && g.goals.n ? g.goals.text : '') : [plural(g.count, 'initiative', 'initiatives'), yoursWords(g)].filter(Boolean).join(', ')].filter(Boolean).join(', ');
165
172
  // the name opens the product in the Viewer, with its own chat; the rest of the header folds the group (canvas HbCProduct)
166
173
  const head = `<div class="hv-gh hv-prg${open ? '' : ' closed'}${o.selHead === g.key ? ' sel' : ''}"><button type="button" class="hv-pt" data-hm-prodopen="${esc(g.key)}" aria-label="Open ${esc(g.name)}, a product"${o.selHead === g.key ? ' aria-current="true"' : ''}>`
167
- + `<span class="hv-tl t${g.tone}" aria-hidden="true" data-cz-rail-tile="${esc(g.key)}" data-cz-rail-name="${esc(g.name)}"${o.here === g.key ? ' data-cz-rail-here' : ''}>${esc(g.initials)}${open ? '' : nd(g)}</span><b>${esc(g.name)}</b></button>`
168
- + `<button type="button" class="hv-pf" data-hm-pg="${esc(g.key)}" aria-expanded="${open}" aria-label="${esc(say)}. ${open ? 'Close' : 'Open'} the group">${open ? dots(g) : ''}<span class="hv-cv">${svg(open ? P.chevD : P.chevR, 16)}</span></button></div>`;
174
+ + `<span class="hv-tl t${g.tone}" aria-hidden="true" data-cz-rail-tile="${esc(g.key)}" data-cz-rail-name="${esc(g.name)}"${o.here === g.key ? ' data-cz-rail-here' : ''}>${esc(g.initials)}${open ? '' : nd(g)}</span><b>${esc(g.name)}</b></button>${prodPillHtml(g, o)}`
175
+ + `<button type="button" class="hv-pf" data-hm-pg="${esc(g.key)}" aria-expanded="${open}" aria-label="${esc(say)}. ${open ? 'Close' : 'Open'} the group">${open ? dots(g) : ''}<span class="hv-cv">${svg(open ? P.chevD : P.chevR, 16)}</span></button>${prodPopHtml(g, o)}</div>`;
169
176
  const sec = `<section class="hm-pg hv-g" aria-label="${esc(g.name)}" data-po-id="${esc(prodKey(g.name))}">${SO.gripHtml(g.name)}`;
170
177
  if (!open) return `${sec}${head}</section>`;
171
178
  return `${sec}${head}<div class="hv-card">${productBody(g, o, true)}</div></section>`;
@@ -10,7 +10,8 @@
10
10
  * session that waits on the PM, Home's; n: how many wait on this initiative), docs (count | null), linked (count | null), claude (Claude's
11
11
  * line while a session works on it, Home's), people ([{ name }]: the stakeholders) }
12
12
  * stagesOf(r, steps) → { list: [{ key, name, ms, status: done | now | next | skip, why }], cur } the initiative's OWN workflow (D99)
13
- * sectionOf(task, list) → the stage key the task sits under in the breakdown, or '' (a WBS section is a task's place, never its state)
13
+ * sectionOf(task, list, map?) → the stage key the task sits under in the breakdown, or '' (a WBS section is a task's place, never its state;
14
+ * map: the row's wfMap, so a task of an earlier workflow's stage sits in the stage it went into, batch 20 item 3)
14
15
  * wbsOf(title) → { code, top } | null "10.5 TC to review" → { code: '10.5', top: '10' }; "WP-03 Token exchange" → { code: 'WP-03', top: 'WP' }
15
16
  * statusOf(r, grill, fmt) → { tone, text } the status the row and the view both say
16
17
  * linkedOf(r) → [{ kind: doc | dep | epic, label, path?, title? }] the Linked fold, from the trail
@@ -28,7 +29,8 @@
28
29
  * late task.
29
30
  * 9 what waits on you leads, with the one primary; the status then moves to the meta line.
30
31
  * 10 a new initiative with no breakdown draws its workflow's sections dashed, with Draft it.
31
- * 11 Build with Jira tickets: the open tickets are Build's section, by epic, with "N of M done in Jira" and how fresh.
32
+ * 11 the stage whose output is Jira tickets (Build; a workflow's own Jira stage): the open tickets are its section, by epic, with "N of M done
33
+ * in Jira" and how fresh (batch 20 item 3: by the output, never by the name build or deliver).
32
34
  * 12 over the plan: the dates line turns amber with the days over; a skipped stage keeps its place, with its reason.
33
35
  * 18 each section carries its dates: done stages when they ran, now from when to the plan end, later ones "Plan <date>", amber when missed.
34
36
  * 19 a big section shows the 3 most urgent first, then folds the rest by the next WBS level, each with its count; done folds last. */
@@ -73,12 +75,14 @@ export function stagesOf(r, steps) {
73
75
  /* ── where a task sits ── */
74
76
  /** The stage key a task sits under: the PM's own placement (section, '' = none), the stage whose To finish entry made it, a breakdown item's
75
77
  * own stage when a stage of this workflow has that key or name; else '' (Not in a stage). */
76
- export function sectionOf(task, list) {
78
+ export function sectionOf(task, list, map) {
77
79
  const L = list || [];
78
80
  const has = (k) => L.some((s) => s.key === k);
79
- if (typeof task.section === 'string') return has(task.section) ? task.section : '';
80
- if (task.from && task.from.stage && has(task.from.stage)) return task.from.stage;
81
- if (task.itemStage) { const n = norm(task.itemStage), hit = L.find((s) => s.key === task.itemStage || norm(s.name) === n || norm(s.key) === n); if (hit) return hit.key; }
81
+ // a stage of the workflow it ran before a switch: the stage that switch put it in (row.wfMap: old key → stage key)
82
+ const via = (k) => { if (!k) return ''; if (has(k)) return k; const m = map && (map[k] || map[norm(k)]); return typeof m === 'string' && has(m) ? m : ''; };
83
+ if (typeof task.section === 'string') return via(task.section);
84
+ if (task.from && task.from.stage) { const v = via(task.from.stage); if (v) return v; }
85
+ if (task.itemStage) { const n = norm(task.itemStage), hit = L.find((s) => s.key === task.itemStage || norm(s.name) === n || norm(s.key) === n); if (hit) return hit.key; const v = via(task.itemStage); if (v) return v; }
82
86
  return '';
83
87
  }
84
88
  /** The WBS code a title starts with, and its top level: "10.5 TC to review" → 10.5 under 10; "WP-03 Token exchange" → WP-03 under WP. */
@@ -180,12 +184,18 @@ export function iniView(r, ctx = {}) {
180
184
  const T = (r.tasks || []).filter((k) => k.status !== 'Archived');
181
185
  // the Jira tickets PMOS read for this initiative: a task whose title names one is linked to it
182
186
  const byKey = new Map((t.tickets || []).filter((k) => k && k.key).map((k) => [k.key, k]));
183
- const rows = T.map((k) => ({ ...rowOf(k, today, linkOf(k.title, byKey)), sec: sectionOf(k, list) }));
187
+ const rows = T.map((k) => ({ ...rowOf(k, today, linkOf(k.title, byKey)), sec: sectionOf(k, list, r.wfMap) }));
184
188
  // archived tasks count nowhere and show in no view but the List's Archived fold (batch 9 item 5b)
185
- const arch = (r.tasks || []).filter((k) => k.status === 'Archived').map((k) => ({ ...rowOf(k, today, linkOf(k.title, byKey)), sec: sectionOf(k, list) }));
189
+ const arch = (r.tasks || []).filter((k) => k.status === 'Archived').map((k) => ({ ...rowOf(k, today, linkOf(k.title, byKey)), sec: sectionOf(k, list, r.wfMap) }));
186
190
  const archOf = (keys) => arch.filter((x) => keys.includes(x.sec));
187
191
  const open = rows.filter((x) => !x.closed), late = open.filter((x) => x.late);
188
- const jira = !ownWf(r) && (t.key === 'build' || t.key === 'deliver') && (t.tickets || []).length > 0;
192
+ // Jira tickets attach to the stage whose output is Jira tickets (batch 20 item 3), whatever it is called: Product feature's Build, a 3-stage
193
+ // workflow's Implementation. They stay in that stage's section once it is passed; the stage card counts them only while it is the stage.
194
+ const jk = ((r.wfStages || []).find((x) => x.output && x.output.kind === 'jira') || {}).key || (!ownWf(r) ? 'build' : '');
195
+ const jIdx = jk ? list.findIndex((x) => x.key === jk) : -1;
196
+ const hasTk = (t.tickets || []).length > 0;
197
+ const jira = jIdx >= 0 && cur === jIdx && hasTk; // the stage card reads Jira
198
+ const jiraIn = jIdx >= 0 && cur >= jIdx && hasTk; // the section holds the tickets
189
199
  // a ticket a task is named for shows once, as the task: it is not drawn or counted again as a Jira row
190
200
  const named = new Set(rows.concat(arch).map((x) => x.jkey).filter(Boolean));
191
201
  const tkOwn = (t.tickets || []).filter((k) => !named.has(k.key));
@@ -238,6 +248,8 @@ export function iniView(r, ctx = {}) {
238
248
  doneOf, nDone: sDone, nTotal: sTotal, nLate: curRows.filter((x) => !x.closed && x.late).length, gates, day: days != null ? 'day ' + days + (usual != null ? ' of ~' + usual : '') : '', dayOver: days != null && usual != null && days > usual,
239
249
  clock: days != null && !line.chip ? (usual != null ? days + ' of ~' + usual + ' days' : plural(days, 'day', 'days')) : '', line, ready,
240
250
  ladder: list.map((s) => ({ name: s.name, ms: s.ms, cls: s.status })), dates, next: nx,
251
+ // the old stages' own days, kept after a switch merged them (batch 20 item 3, canvas WmD): "Before the switch: Triage 4 days · Discover 12 days"
252
+ before: Array.isArray(tr.before) && tr.before.length ? 'Before the switch: ' + tr.before.map((b) => b.name + ' ' + plural(b.days, 'day', 'days')).join(' · ') : '',
241
253
  aria: cur >= 0 ? 'Stage ' + (cur + 1) + ' of ' + list.length + ' of ' + ((r.wf && r.wf.name) || 'Product feature') + ': ' + st.name + '.' + (nx ? ' Next stage: ' + nx.name + '.' : '') : 'No stage on record.',
242
254
  };
243
255
 
@@ -256,18 +268,19 @@ export function iniView(r, ctx = {}) {
256
268
  return { kind: 'stage', key: s.key, n: i + 1, name: s.name, ms: s.ms, status: s.status, sub, subWarn, count: countOf(op.length, lt.length, dn), warn: lt.length > 0,
257
269
  open: s.status === 'now' || lt.length > 0, ...bodyOf(rs, archOf([s.key])), jira: null, why, ...(s.status === 'skip' ? { skipWhy: s.why || '' } : {}) };
258
270
  };
259
- const anyTasks = rows.length > 0 || jira;
271
+ const anyTasks = rows.length > 0 || jiraIn;
260
272
  // one row per stage, in workflow order (batch 11 item 5, Wawan: "one row/group per stage. Do not combine"): past and later stages are no
261
273
  // longer merged into "Stages 1–4" or "Later: …". A stage that is not live starts folded; the current one and any with a late task start open.
262
274
  list.forEach((s, i) => {
263
275
  const x = one(s, i);
264
- if (i === cur && jira && tkOwn.length) {
276
+ if (i === jIdx && jiraIn && tkOwn.length) {
265
277
  // a ticket just moved to Done in PMOS stays in view until Jira's next read, so the card the PM dropped does not vanish
266
278
  const opn = tkOwn.filter((k) => k.status !== 'Done' || (k.move && (k.move.state === 'moving' || k.move.state === 'moved'))).sort((a, b) => (b.blocked ? 1 : 0) - (a.blocked ? 1 : 0));
267
279
  x.jira = { open: opn.map((k) => ({ key: k.key, title: k.title, epic: k.epic || '', status: k.status || 'To do', raw: k.raw || '', move: k.move || null, start: k.start || '', due: k.due || k.sprintEnd || '', here: !!k.datesHere, days: jDays(k, today), av: initials(k.assignee), sub: [k.blocked ? 'Blocked' + (k.reason ? ' by ' + String(k.reason).replace(/^Waiting on /i, '') : '') : k.status || 'To do', k.assignee || ''].filter(Boolean).join(' · '), warn: !!k.blocked })),
268
280
  done: tkOwn.length - opn.length, total: tkOwn.length, at: ctx.jiraAt || '' };
269
281
  x.count = countOf(opn.length + x.top.length + x.groups.reduce((n, g) => n + g.n, 0), x.top.filter((y) => y.late).length, 0);
270
282
  x.sub = x.sub + (x.sub ? ' · ' : '') + 'Jira tickets, by epic';
283
+ if (opn.length) x.open = true; // passed but still open in Jira (Deliver): the tickets stay in view, not folded under a done stage
271
284
  }
272
285
  sections.push(x);
273
286
  });
@@ -276,7 +289,7 @@ export function iniView(r, ctx = {}) {
276
289
  const op = loose.filter((x) => !x.closed), lt = op.filter((x) => x.late);
277
290
  sections.push({ kind: 'none', key: '', label: 'Not in a stage', sub: '', count: countOf(op.length, lt.length, loose.length - op.length), warn: lt.length > 0, open: op.length > 0, ...bodyOf(loose, archOf([''])) });
278
291
  }
279
- const nOpen = open.length + (jira ? tkOwn.filter((k) => k.status !== 'Done').length : 0), nDone = rows.length - open.length + (jira ? tkOwn.filter((k) => k.status === 'Done').length : 0);
292
+ const nOpen = open.length + (jiraIn ? tkOwn.filter((k) => k.status !== 'Done').length : 0), nDone = rows.length - open.length + (jiraIn ? tkOwn.filter((k) => k.status === 'Done').length : 0);
280
293
  const tasks = { open: nOpen, done: nDone, late: late.length, count: [nOpen ? nOpen + ' open' : '', nDone ? nDone + ' done' : ''].filter(Boolean).join(' · '), sections,
281
294
  empty: !anyTasks ? { stages: list.map((s, i) => ({ n: i + 1, name: s.name, ms: s.ms, now: i === cur })) } : null };
282
295
 
@@ -285,7 +298,7 @@ export function iniView(r, ctx = {}) {
285
298
  const lateSay = late.length ? plural(late.length, 'task is', 'tasks are') + ' late' + (late.length > 1 ? ', the oldest since ' + dateY(late.map((x) => x.end).sort()[0], today) : ', since ' + dateY(late[0].end, today)) + '.' : '';
286
299
  const why = whyText(r, list, cur, today, finished);
287
300
  const it = tr || {};
288
- const progress = jira ? (ctx.jiraAt || '') : r.progress != null && Number.isFinite(Number(r.progress)) ? Math.round(Number(r.progress)) + '% · by hand' : '';
301
+ const progress = jiraIn ? (ctx.jiraAt || '') : r.progress != null && Number.isFinite(Number(r.progress)) ? Math.round(Number(r.progress)) + '% · by hand' : '';
289
302
  // what waits on the PM: the track's, else the trail's (the Board merges the trail into the track; Home reads the row as sent)
290
303
  const you = t.you || (it.you && it.you.text) || null, youKind = t.youKind || (it.you && it.you.kind) || null, youWhy = t.youWhy || (it.you && it.you.why) || '';
291
304
  let wait = null;
@@ -307,7 +320,7 @@ export function iniView(r, ctx = {}) {
307
320
  summary.wf = r.wf || { id: PF_ID, name: 'Product feature', icon: 'feature' };
308
321
  summary.program = ctx.program || null;
309
322
  const today2 = (n) => String(n).padStart(2, '0');
310
- return { anchor: r.kr || '', vs: r.__vs || null, links: r.__vs && r.__vs.draft ? null : r.links || null, id: r.id || null, key: r.key, title: r.title, today: today.getFullYear() + '-' + today2(today.getMonth() + 1) + '-' + today2(today.getDate()), summary, stage, tasks, docs: ctx.docs != null ? ctx.docs : null, linked: linkedOf(r), jiraAt: jira ? ctx.jiraAt || '' : '', jiraRead: ctx.jiraReadAt || '',
323
+ return { anchor: r.kr || '', vs: r.__vs || null, links: r.__vs && r.__vs.draft ? null : r.links || null, id: r.id || null, key: r.key, title: r.title, today: today.getFullYear() + '-' + today2(today.getMonth() + 1) + '-' + today2(today.getDate()), summary, stage, tasks, docs: ctx.docs != null ? ctx.docs : null, linked: linkedOf(r), jiraAt: jiraIn ? ctx.jiraAt || '' : '', jiraRead: ctx.jiraReadAt || '',
311
324
  // split or merge (batch 11 item 14): Claude's suggestion for it, and where its work went when it was merged
312
325
  suggest: r.suggest || null, merged: mergedOf(r),
313
326
  // what Claude proposes under the one blue ✦, and what a ✓ kept from elsewhere (batch 12 items 2, 3 and 4; pm/ini-props.js)
@@ -145,7 +145,7 @@ function telHtml(v, o, pri, mc) {
145
145
  // the banner (hidden): the stage, the dates, the days left, the count, the measure, the next move
146
146
  const left = D && D.left ? `<span class="iv-chp2${D.over ? ' late' : ''}">${esc(D.left)}</span>` : L && L.chip ? `<span class="iv-chp2">${esc(L.chip.text)}</span>` : '';
147
147
  const count = st.nTotal ? `<span class="iv-chp2${st.nLate ? ' late' : ''}">${pipsOf(st, 'sm')}${esc(st.doneOf || st.nDone + ' of ' + st.nTotal + ' done')}</span>` : '';
148
- const bn = mc ? '' : `<div class="iv-bn"><div class="iv-bt"><span class="iv-shn">${tileOf(st)}<b>${esc(st.name)}</b></span>${dt ? `<span class="s">${esc(dt)}</span>` : ''}</div><div class="iv-chips">${left}${count}${AB.chipHtml(v, o)}</div>${nextHtml(st, o, pri)}</div>`;
148
+ const bn = mc ? '' : `<div class="iv-bn"><div class="iv-bt"><span class="iv-shn">${tileOf(st)}<b>${esc(st.name)}</b></span>${dt ? `<span class="s">${esc(dt)}</span>` : ''}</div><div class="iv-chips">${left}${count}${AB.chipHtml(v, o)}</div>${st.before ? `<p class="iv-bf s">${esc(st.before)}</p>` : ''}${nextHtml(st, o, pri)}</div>`;
149
149
  const tg = `<button type="button" class="iv-mctg" data-iv-mc="mc" aria-expanded="${!!mc}" aria-label="${mc ? 'Hide the mission' : 'Show the mission'}" title="${mc ? 'Hide' : 'Show'}">${SVG(CHEV, 16, 2)}</button>`;
150
150
  return `<div class="iv-tel" data-iv-tel aria-label="${esc(st.aria || 'Stage · ' + st.name)}">`
151
151
  + (mc ? `<div class="iv-tj" data-iv-tj="${esc(id)}">${svg}</div>`
@@ -4,14 +4,17 @@
4
4
  * kindLine(row) "Tender · KR 2.1": the workflow and the anchor over the initiative's name (HbC*; was the lane)
5
5
  * chainText(wf) "Triage → Requirements → ◆ RFP out → …": a workflow's stages in order
6
6
  * pickerItems(lib, row) the Change picker's rows: every workflow not archived, with its stage count, the current one picked
7
- * switchTarget(from, to, key) the stage an initiative lands on (scripts/workflows.js switchTarget, the same rule)
8
- * switchPlan(row, to, landing?) the switch dialog: each done or current stage → where it lands, the landing stage, the stages to pick from
7
+ * proposeBridge(from, to) Claude's proposal of where each old stage lands (scripts/workflows.js proposeBridge, the same rule)
8
+ * mapOf(from, to, override?) every old stage → its new stage: the PM's pick, the bridge saved with `to`, else the proposal
9
+ * switchTarget(stage, to, from) the stage an initiative lands on (scripts/workflows.js switchTarget, the same rule)
10
+ * switchPlan(row, to, landing?, override?) the switch dialog (A's bridge, canvas WmB): each new stage with the old stages that go into it,
11
+ * the landing stage, the stages to pick from
9
12
  * wontdoReady(reason, note) Won't do can go: a reason, and words when the reason is Other
10
13
  * endedLine(row) "Won't do · No budget: Moved to next year's budget." or ''
11
14
  * usualOf(trail, row) the usual days in the row's stage, compared within its own workflow only
12
15
  * setByPmos(row) { name, why } when PMOS set the workflow from the BRD, else null
13
16
  * Every figure comes from a row field or the workflow library (GET /api/workflows). */
14
- import { PRODUCT_FEATURE_ID, WONTDO_REASONS, catLabel, wfOf } from './wf-model.js';
17
+ import { PRODUCT_FEATURE_ID, WONTDO_REASONS, wfOf } from './wf-model.js';
15
18
 
16
19
  /** The workflow and the anchor: the kind line over an initiative's name. */
17
20
  export function kindLine(row) {
@@ -38,38 +41,92 @@ export function pickerItems(lib, row) {
38
41
  }
39
42
 
40
43
  const same = (a, b) => String(a || '').toLowerCase() === String(b || '').toLowerCase();
41
- /** Switching workflow (WfAChange): a stage of the same name carries over, else the first stage of the same category, else the first stage. */
42
- export function switchTarget(fromStage, to) {
44
+ /** Claude's proposal (batch 20 item 3, canvas WmB): order kept; anchors are the same key or name, the same stem in the same category, the
45
+ * stage whose output is Jira tickets, first to first and last to last; between two anchors an old stage stays with the earlier one until a
46
+ * ◆ milestone closes it, and a wider gap spreads in order. The server's proposeBridge is the same function: a test holds them equal. */
47
+ export function proposeBridge(from, to) {
48
+ const F = (from && from.stages) || [], T = (to && to.stages) || [];
49
+ const out = {};
50
+ if (!T.length) return out;
51
+ const low = (x) => String(x || '').toLowerCase().trim();
52
+ const stem = (x) => { const v = low(x).replace(/[^a-z0-9]/g, ''); return v.length >= 6 ? v.slice(0, 6) : null; };
53
+ const anchor = F.map((s) => {
54
+ let j = T.findIndex((t) => t.key === s.key || low(t.name) === low(s.name));
55
+ if (j < 0 && stem(s.name)) j = T.findIndex((t) => t.cat === s.cat && stem(t.name) === stem(s.name));
56
+ return j;
57
+ });
58
+ const tj = T.findIndex((t) => t.output && t.output.kind === 'jira');
59
+ if (tj >= 0 && !anchor.includes(tj)) { const i = F.findIndex((s, n) => anchor[n] < 0 && s.output && s.output.kind === 'jira'); if (i >= 0) anchor[i] = tj; }
60
+ if (F.length && anchor[0] < 0) anchor[0] = 0;
61
+ if (F.length > 1 && anchor[F.length - 1] < 0) anchor[F.length - 1] = T.length - 1;
62
+ let hi = -1;
63
+ for (let i = 0; i < F.length; i++) { if (anchor[i] < 0) continue; if (anchor[i] < hi) anchor[i] = -1; else hi = anchor[i]; }
64
+ for (let i = 0; i < F.length;) {
65
+ if (anchor[i] >= 0) { out[F[i].key] = T[anchor[i]].key; i++; continue; }
66
+ let j = i; while (j < F.length && anchor[j] < 0) j++;
67
+ const a = i > 0 ? anchor[i - 1] : 0, b = j < F.length ? anchor[j] : a, n = j - i;
68
+ let closed = false;
69
+ for (let k = 0; k < n; k++) {
70
+ let t = a;
71
+ if (b - a === 1) { t = closed ? b : a; if (F[i + k].milestone) closed = true; }
72
+ else if (b - a > 1) t = Math.min(b, a + Math.round(((k + 1) * (b - a)) / (n + 1)));
73
+ out[F[i + k].key] = T[t].key;
74
+ }
75
+ i = j;
76
+ }
77
+ return out;
78
+ }
79
+ /** Every old stage and its new stage: the PM's own pick, the bridge saved with `to` (when it replaces `from`), else Claude's proposal. */
80
+ export function mapOf(from, to, override) {
81
+ const p = proposeBridge(from, to);
82
+ const br = to && to.bridge && from && to.bridge.from === from.id ? to.bridge.map || {} : {};
83
+ const ok = (k) => !!k && ((to && to.stages) || []).some((s) => s.key === k);
84
+ const out = {};
85
+ for (const s of (from && from.stages) || []) { const o = override && override[s.key]; out[s.key] = ok(o) ? o : ok(br[s.key]) ? br[s.key] : p[s.key]; }
86
+ return out;
87
+ }
88
+ /** The workflow a row runs now, as mapOf reads it: { id, stages } from the row's own stages (Product feature when it has none). */
89
+ export function fromOf(row, pf) {
90
+ const r = row || {};
91
+ if (Array.isArray(r.wfStages) && r.wfStages.length) return { id: (r.wf && r.wf.id) || PRODUCT_FEATURE_ID, stages: r.wfStages };
92
+ return pf || { id: PRODUCT_FEATURE_ID, stages: [] };
93
+ }
94
+ /** Switching workflow (WfAChange): the stage the bridge or the proposal sends the current stage to; no current stage, the first stage. */
95
+ export function switchTarget(fromStage, to, from) {
43
96
  const st = (to && to.stages) || [];
44
97
  if (!st.length) return null;
45
98
  if (!fromStage) return st[0].key;
46
- const s = st.find((x) => same(x.name, fromStage.name));
47
- if (s) return s.key;
48
- return (st.find((x) => x.cat === fromStage.cat) || st[0]).key;
99
+ const f = from && (from.stages || []).length ? from : { id: '', stages: [fromStage] };
100
+ const k = f.stages.find((x) => x.key === fromStage.key) ? fromStage.key : null;
101
+ return (k && mapOf(f, to)[k]) || st[0].key;
49
102
  }
50
103
  /** Why a stage lands where it does, in a few words. */
51
- function landNote(fromStage, toStage) {
104
+ function landNote(fromStage, toStage, to, from) {
52
105
  if (!toStage) return '';
53
106
  if (same(fromStage.name, toStage.name)) return 'same stage, carries over';
54
- if (fromStage.cat === toStage.cat) return 'first ' + catLabel(toStage.cat) + ' stage';
55
- return 'first stage';
107
+ if (to && to.bridge && from && to.bridge.from === from.id && to.bridge.map && to.bridge.map[fromStage.key] === toStage.key) return 'saved with ' + (to.name || 'the workflow');
108
+ return 'goes into ' + toStage.name;
56
109
  }
57
110
 
58
- /** The switch dialog. row: a board row (wfStages with status); to: the workflow picked (with stages); landing: the PM's own pick, a key.
59
- * Answers { rows: [{ from, state, to, note }], land, lands: [{ key, name, milestone }], name } — nothing is deleted, so a done stage of the
60
- * old workflow shows where its work sits now. */
61
- export function switchPlan(row, to, landing) {
111
+ /** The switch dialog (A's bridge, canvas WmB). row: a board row (wfStages with status); to: the workflow picked (with stages and its bridge);
112
+ * landing: the PM's own pick, a key; override: the PM's own picks per old stage ({ oldKey: newKey }).
113
+ * Answers { rows: [{ from, state, to, note }], groups: [{ key, name, from: [{ key, name }] }], map, land, lands, name } — nothing is deleted,
114
+ * so a done stage of the old workflow shows where its work sits now, and its tasks move with it. */
115
+ export function switchPlan(row, to, landing, override) {
116
+ const from = fromOf(row);
117
+ const map = mapOf(from, to, override);
62
118
  const mine = ((row && row.wfStages) || []).filter((s) => s.status === 'done' || s.status === 'current');
63
119
  const tst = (to && to.stages) || [];
64
120
  const byKey = (k) => tst.find((s) => s.key === k) || null;
65
121
  const rows = mine.map((s) => {
66
- const t = byKey(switchTarget(s, to));
67
- return { from: s.name, state: s.status === 'current' ? 'now' : 'done', to: t ? t.name : '', note: t ? landNote(s, t) : '' };
122
+ const t = byKey(map[s.key]);
123
+ return { from: s.name, state: s.status === 'current' ? 'now' : 'done', to: t ? t.name : '', note: t ? landNote(s, t, to, from) : '' };
68
124
  });
125
+ const groups = tst.map((t) => ({ key: t.key, name: t.name, milestone: !!t.milestone, from: from.stages.filter((s) => map[s.key] === t.key).map((s) => ({ key: s.key, name: s.name })) }));
69
126
  const cur = mine.find((s) => s.status === 'current') || (row && row.wfStage) || null;
70
- const auto = switchTarget(cur, to);
127
+ const auto = cur && map[cur.key] ? map[cur.key] : switchTarget(cur, to, from);
71
128
  const land = landing && byKey(landing) ? landing : auto;
72
- return { rows, land, auto, lands: tst.map((s) => ({ key: s.key, name: s.name, milestone: !!s.milestone })), name: (to && to.name) || '' };
129
+ return { rows, groups, map, land, auto, lands: tst.map((s) => ({ key: s.key, name: s.name, milestone: !!s.milestone })), name: (to && to.name) || '' };
73
130
  }
74
131
 
75
132
  /** Won't do can go: a reason; Other needs at least a few words. */