create-pmos 0.407.0 → 0.409.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 (79) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/board-programs-test.js +1 -1
  8. package/workspace/board-wf-shot.js +45 -0
  9. package/workspace/board-workflows-test.js +186 -0
  10. package/workspace/briefing-premium-board-test.js +2 -2
  11. package/workspace/briefing-premium-initiative-test.js +1 -1
  12. package/workspace/changelog.json +24 -0
  13. package/workspace/fixtures/board-workflows-facts.js +49 -0
  14. package/workspace/fixtures/workflows-facts.js +53 -0
  15. package/workspace/guide/home.md +2 -2
  16. package/workspace/guide/index.md +1 -0
  17. package/workspace/guide/workflows.md +58 -0
  18. package/workspace/home-other-product-test.js +94 -0
  19. package/workspace/ini-workflow-test.js +177 -0
  20. package/workspace/lib/board-premium.js +30 -5
  21. package/workspace/lib/board-trail.js +24 -7
  22. package/workspace/lib/briefing-premium-agent.js +3 -0
  23. package/workspace/lib/engine/boards.js +30 -2
  24. package/workspace/lib/engine/workflows.js +204 -0
  25. package/workspace/lib/pmos-verbs.js +3 -0
  26. package/workspace/lib/programs.js +22 -7
  27. package/workspace/lib/route-modules.js +1 -0
  28. package/workspace/lib/routes-boards.js +157 -7
  29. package/workspace/lib/routes-programs.js +5 -0
  30. package/workspace/lib/routes-workflows.js +105 -0
  31. package/workspace/lib/workflow-chat.js +26 -0
  32. package/workspace/lib/workflow-cli.js +141 -0
  33. package/workspace/lib/workflows-store.js +108 -0
  34. package/workspace/package-lock.json +2 -2
  35. package/workspace/package.json +1 -1
  36. package/workspace/program-charter-test.js +243 -0
  37. package/workspace/program-panel-test.js +1 -1
  38. package/workspace/public/pm/bd-acts.js +10 -5
  39. package/workspace/public/pm/bd-asks.js +2 -2
  40. package/workspace/public/pm/bd-prog-panel.js +33 -14
  41. package/workspace/public/pm/bd-prog.js +11 -3
  42. package/workspace/public/pm/bd-views.js +128 -45
  43. package/workspace/public/pm/bd-wf.js +99 -0
  44. package/workspace/public/pm/cozy-board.css +67 -6
  45. package/workspace/public/pm/cozy-evmodel.js +1 -1
  46. package/workspace/public/pm/cozy-panel.css +12 -6
  47. package/workspace/public/pm/cozy-settings.js +4 -2
  48. package/workspace/public/pm/cozy-viewer.js +36 -9
  49. package/workspace/public/pm/cozy-vw-shell.css +8 -0
  50. package/workspace/public/pm/goal-chat.js +1 -1
  51. package/workspace/public/pm/home-app.js +50 -13
  52. package/workspace/public/pm/home-ini-model.js +2 -2
  53. package/workspace/public/pm/home-ini.css +30 -0
  54. package/workspace/public/pm/home-ini.js +52 -9
  55. package/workspace/public/pm/home-list.js +5 -3
  56. package/workspace/public/pm/home-today.js +4 -4
  57. package/workspace/public/pm/ini-wf-model.js +91 -0
  58. package/workspace/public/pm/ini-wf.js +160 -0
  59. package/workspace/public/pm/premium-board.js +98 -30
  60. package/workspace/public/pm/premium-initiative-head.js +18 -8
  61. package/workspace/public/pm/program-charter.css +135 -0
  62. package/workspace/public/pm/program-charter.js +333 -0
  63. package/workspace/public/pm/program-model.js +44 -4
  64. package/workspace/public/pm/wf-edit.js +119 -0
  65. package/workspace/public/pm/wf-model.js +48 -0
  66. package/workspace/public/pm/wf-page.css +162 -0
  67. package/workspace/public/pm/wf-page.js +398 -0
  68. package/workspace/public/pm/wf-stage.js +187 -0
  69. package/workspace/public/premium-workflows.html +31 -0
  70. package/workspace/public/premium.html +1 -0
  71. package/workspace/server.js +1 -1
  72. package/workspace/skills/workflow-setup.skill +57 -0
  73. package/workspace/test-lists/briefing-premium.json +3 -1
  74. package/workspace/test-lists/ini-workflow.json +6 -0
  75. package/workspace/test-lists/program-charter.json +9 -0
  76. package/workspace/test-lists/workflows-board.json +13 -0
  77. package/workspace/test-lists/workflows-setup.json +13 -0
  78. package/workspace/test-lists/workflows.json +5 -0
  79. package/workspace/workflows-setup-test.js +346 -0
@@ -29,6 +29,12 @@
29
29
  * back true: keep the item shown now, so ← comes back to it. Without back, opening an item forgets what was behind it.
30
30
  * keep true: this item takes the place of the one shown now, and what was behind that one stays behind this one (a view switch)
31
31
  * add { label, on(button) }: a quiet + before ⋯ (Home's "New session" on an initiative, canvas HbC). Not drawn on a phone.
32
+ * sub one quiet line under the title: what the item is when the title is its parent's name (a program's "Charter", canvas MsBCharter)
33
+ * presses [{ act, label, icon, text?, solid? }]: the item's own presses before ⋯ (a program's charter icon, canvas MsB0Entry; the
34
+ * charter's Save, MsBCharter). text draws the word beside the icon (not on a phone); solid is the one dark primary.
35
+ * onPress(act, button) runs them. setPresses(id, list) changes them while the item is shown (Save shows only after a change).
36
+ * guard (go, anchor) → true when the item holds unsaved changes and asks first: Close, ←, Escape and another open() call it, and
37
+ * nothing leaves until the caller runs go() (canvas MsB5Leave: Save or Discard). false or none: it leaves at once.
32
38
  * render called with the body element to draw into; html is the same as a string. Neither: the body is left empty for the caller.
33
39
  * id optional; current() returns it, so a caller can tell whether its item is the one shown
34
40
  * onClose called once when this item leaves the card (Close, Escape, close(), or another open())
@@ -43,7 +49,7 @@
43
49
  * line and ONE primary press ({ label, act } → data-czs-act="<act>", or { label, href }). tone 'you' (blue dot), 'warn' (amber), 'live' (red).
44
50
  * also: [{ act, label, icon }] quiet icon-only presses after the primary (the Done check of a task). second: { label, act } one quiet
45
51
  * word press, only where a decision has two answers (Return it | Keep it as is).
46
- * czSections([{ id, title, count, open, render | html }], { key }) → the folding rows. A row folds and unfolds in place, and the fold
52
+ * czSections([{ id, title, count, open, render | html, tail? }], { key }) → the folding rows. A row folds and unfolds in place, and the fold
47
53
  * is remembered per key and id (localStorage, a private window forgets it). render(): a string of markup, called once when drawn.
48
54
  * widthOf(kind) · setWidth(px) · wide(on?) · railOn() for the page and the tests.
49
55
  * The look is in cozy-vw-shell.css (loaded here once) over cozy.css (.cz-vw…). The old #dlg path (premium-viewer.js) is separate. */
@@ -111,10 +117,14 @@ export function headHtml(it) {
111
117
  const disc = o.discuss && !o.home ? ib('discuss', 'Discuss in chat', P.chat) : '';
112
118
  const more = typeof o.more === 'function' || (Array.isArray(o.more) && o.more.some((m) => m && !m.sep)) || o.url ? ib('more', 'More', P.more, ' aria-haspopup="menu" aria-expanded="false"') : '';
113
119
  const add = o.add && o.add.label && !phone ? ib('add', o.add.label, P.add) : '';
120
+ const own = (o.presses || []).filter((x) => x && x.act && x.label).map((x) => x.solid
121
+ ? `<button type="button" class="cz-vw-pri${x.text && !phone ? '' : ' i'}" data-cz-vw="press" data-cz-vw-p="${esc(x.act)}" aria-label="${esc(x.label)}" title="${esc(x.label)}">${svg(path(x.icon), 15, 2.2)}${x.text && !phone ? `<span>${esc(x.text)}</span>` : ''}</button>`
122
+ : `<button type="button" class="cz-vw-ib" data-cz-vw="press" data-cz-vw-p="${esc(x.act)}" aria-label="${esc(x.label)}" title="${esc(x.label)}">${svg(path(x.icon), 18)}</button>`).join('');
123
+ const sub = o.sub ? `<p class="cz-vw-sub">${esc(o.sub)}</p>` : '';
114
124
  return (o.canBack || phone ? ib('back', o.canBack ? 'Back' : 'Close the viewer', P.back) : '')
115
125
  + `<span class="cz-vw-tile" aria-hidden="true">${svg(path(o.icon), 17)}</span>`
116
- + (o.renaming ? renHtml(o) : `<div class="cz-vw-t">${kind}<h3 class="cz-vw-title" id="czVwTitle">${o.rename ? `<button type="button" class="cz-vw-rn" data-cz-vw-rn aria-label="${esc('Rename ' + (o.title || ''))}" title="Rename">${esc(o.title || '')}</button>` : esc(o.title || '')}</h3></div>`)
117
- + disc + add + more
126
+ + (o.renaming ? renHtml(o) : `<div class="cz-vw-t">${kind}<h3 class="cz-vw-title" id="czVwTitle">${o.rename ? `<button type="button" class="cz-vw-rn" data-cz-vw-rn aria-label="${esc('Rename ' + (o.title || ''))}" title="Rename">${esc(o.title || '')}</button>` : esc(o.title || '')}</h3>${sub}</div>`)
127
+ + disc + own + add + more
118
128
  + (phone ? '' : ib('wide', o.isWide ? 'Back to the side' : 'Open wide', o.isWide ? P.side : P.wide, ` aria-pressed="${o.isWide ? 'true' : 'false'}"`))
119
129
  + (phone ? '' : `<button type="button" class="cz-vw-ib" data-cz-vw="close" aria-label="Close the viewer" title="Close">${svg(P.close, 18)}</button>`);
120
130
  }
@@ -150,9 +160,10 @@ export function czSections(list, opt = {}) {
150
160
  const body = typeof s.render === 'function' ? s.render() : s.html || '';
151
161
  const n = s.count === 0 || s.count == null || s.count === '' ? '' : `<span class="czs-n">${esc(s.count)}</span>`;
152
162
  const can = !!body || typeof s.on === 'string';
153
- return `<div class="czs-sec${open && body ? ' on' : ''}" data-czs-id="${esc(id)}">`
163
+ return `<div class="czs-sec${open && body ? ' on' : ''}${s.tail ? ' t' : ''}" data-czs-id="${esc(id)}">`
154
164
  + `<button type="button" class="czs-row" ${body ? `data-czs-fold="${esc(id)}" aria-expanded="${open ? 'true' : 'false'}"` : can ? `data-czs-act="${esc(s.on)}"` : 'disabled'}>`
155
165
  + `<b>${esc(s.title)}</b>${n}${can ? `<span class="czs-cv">${svg(open && body ? P.down : P.chev, 15, 2)}</span>` : ''}</button>`
166
+ + (s.tail ? `<span class="czs-tail">${s.tail}</span>` : '')
156
167
  + (body ? `<div class="czs-body"${open ? '' : ' hidden'}>${body}</div>` : '')
157
168
  + '</div>';
158
169
  }).join('') + '</div>';
@@ -337,8 +348,9 @@ function mount() {
337
348
  if (e.target.closest('[data-cz-vw-rn]')) { startRename(); return; } // the title is the rename press (RnATask)
338
349
  const b = e.target.closest('[data-cz-vw]'); if (!b || b.disabled || !el.querySelector('.cz-vw-hd').contains(b)) return;
339
350
  const a = b.dataset.czVw;
340
- if (a === 'close') close();
341
- else if (a === 'back') { if (V.stack.length) back(); else close(); }
351
+ if (a === 'close') guarded(close, b);
352
+ else if (a === 'back') guarded(() => { if (V.stack.length) back(); else close(); }, b);
353
+ else if (a === 'press') { if (V.cur && typeof V.cur.onPress === 'function') V.cur.onPress(b.dataset.czVwP, b); }
342
354
  else if (a === 'more') moreMenu(b);
343
355
  else if (a === 'add') { if (V.cur && V.cur.add && typeof V.cur.add.on === 'function') V.cur.add.on(b); }
344
356
  else if (a === 'wide') wide();
@@ -368,6 +380,12 @@ function emit() {
368
380
  V.subs.forEach((f) => { try { f(d); } catch { /* a listener's fault stays its own */ } });
369
381
  document.dispatchEvent(new CustomEvent('cz-viewer', { detail: d }));
370
382
  }
383
+ /** Runs go now, or after the item's guard says so (it holds unsaved changes and asks Save or Discard first). */
384
+ function guarded(go, anchor) {
385
+ const g = V.cur && V.cur.guard;
386
+ if (typeof g === 'function') { let held = false; try { held = g(go, anchor || (V.el && V.el.querySelector('[data-cz-vw="back"],[data-cz-vw="close"]'))) === true; } catch { held = false; } if (held) return; }
387
+ go();
388
+ }
371
389
  function leave() {
372
390
  const was = V.cur; V.cur = null;
373
391
  if (was && typeof was.onClose === 'function') { try { was.onClose(); } catch { /* the caller's own fault */ } }
@@ -406,19 +424,28 @@ async function saveRename() {
406
424
  cur.title = r.title || v; if (cur.rename.value != null && r.title == null) cur.rename.value = v; if (cur.args) cur.args = { ...cur.args, title: cur.title };
407
425
  endRename(); emit();
408
426
  }
427
+ /** The item's own presses change while it is shown (the charter's Save shows only after a change). */
428
+ export function setPresses(id, list) { if (V.cur && V.cur.id === String(id)) { V.cur.presses = list || null; if (V.cur.args) V.cur.args = { ...V.cur.args, presses: list || null }; if (!V.cur.renaming) redraw(); } }
409
429
  /** The caller's own rename landed elsewhere (Undo, or a reload): the header shows the name. */
410
430
  export function retitle(id, title) { if (V.cur && V.cur.id === String(id) && title) { V.cur.title = title; if (V.cur.args) V.cur.args = { ...V.cur.args, title }; if (!V.cur.renaming) redraw(); emit(); } }
411
431
 
412
432
  /** Show one item in the Viewer, in place of the one shown. Returns the body element the content is in. */
413
433
  export function open(it) {
414
434
  const o = it || {};
435
+ // an item with unsaved changes asks first; the open goes on when it says so (and keeps a drill-in asked for before it)
436
+ if (!o._asked && V.cur && typeof V.cur.guard === 'function') {
437
+ const dr = V.drill; let now = true, ran = false;
438
+ guarded(() => { ran = true; if (!now) { V.drill = dr; open({ ...o, _asked: true }); } });
439
+ now = false;
440
+ if (!ran) return null;
441
+ }
415
442
  const el = mount(); place(el);
416
443
  if (!V.cur) { const ae = document.activeElement; V.back = ae && ae !== document.body && !el.contains(ae) ? ae : null; }
417
444
  if ((o.back || V.drill) && V.cur && V.cur.args) V.stack.push(V.cur.args); else if (!o._back && !o.keep) V.stack = [];
418
445
  V.drill = false;
419
446
  const sameKind = V.cur && kindKey(V.cur.kind) === kindKey(o.kind);
420
447
  leave();
421
- V.cur = { id: o.id == null ? null : String(o.id), kind: o.kind || '', title: o.title || '', icon: o.icon, url: o.url || '', full: !!o.full, onClose: o.onClose, more: o.more, discuss: o.discuss, add: o.add || null, rename: o.rename && typeof o.rename.save === 'function' ? o.rename : null, args: o };
448
+ V.cur = { id: o.id == null ? null : String(o.id), kind: o.kind || '', title: o.title || '', icon: o.icon, url: o.url || '', full: !!o.full, onClose: o.onClose, more: o.more, discuss: o.discuss, add: o.add || null, sub: o.sub || '', presses: o.presses || null, onPress: o.onPress, guard: o.guard, rename: o.rename && typeof o.rename.save === 'function' ? o.rename : null, args: o };
422
449
  el.setAttribute('aria-label', 'Viewer: ' + (o.kind || o.title || 'item'));
423
450
  redraw();
424
451
  const m = el.querySelector('.cz-vw-menu'); if (m) m.remove();
@@ -470,7 +497,7 @@ if (typeof window !== 'undefined' && typeof window.addEventListener === 'functio
470
497
  window.addEventListener('keydown', (e) => {
471
498
  if (e.key !== 'Escape' || !isOpen() || e.defaultPrevented) return;
472
499
  if (document.querySelector('[data-esc-layer]')) return;
473
- e.preventDefault(); e.stopImmediatePropagation(); close();
500
+ e.preventDefault(); e.stopImmediatePropagation(); guarded(close);
474
501
  }, true);
475
502
  }
476
- if (typeof window !== 'undefined') window.czViewer = { open, close, back, drill, isOpen, current, body, onChange, placeholder, retitle, czSummary, czSections, widthOf, setWidth, wide, railOn, ICONS };
503
+ if (typeof window !== 'undefined') window.czViewer = { open, close, back, drill, setPresses, isOpen, current, body, onChange, placeholder, retitle, czSummary, czSections, widthOf, setWidth, wide, railOn, ICONS };
@@ -12,6 +12,11 @@
12
12
  .cz-vw-t { display: block; }
13
13
  .cz-vw-kind { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } /* say it once: the kind is for a screen reader */
14
14
  .cz-vw-title { font-size: 16px; font-weight: 800; }
15
+ .cz-vw-sub { margin: 1px 0 0; font-size: 12.5px; color: var(--cz-ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* what the item is under its parent's name (MsBCharter "Charter") */
16
+ /* the item's one dark primary in the header (the charter's Save, canvas MsBCharter): a word on a desk, a round check on a phone (MsBPhone) */
17
+ .cz-vw-pri { height: 36px; padding: 0 14px; margin: 0 4px; border-radius: 999px; border: 0; background: var(--cz-ink); color: var(--cz-card); font: inherit; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; flex: none; cursor: pointer; }
18
+ .cz-vw-pri.i { width: 40px; height: 40px; padding: 0; justify-content: center; }
19
+ .cz-vw-pri:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
15
20
  .cz-vw-ib { border-radius: 999px; }
16
21
 
17
22
  /* rename (canvas RnATask, RnAIni, RnAProg, RnAPhone): the title is the press; a tap makes it one field with a blue check */
@@ -80,6 +85,9 @@ body.cz-vw-drag, body.cz-vw-drag * { cursor: col-resize !important; user-select:
80
85
  .czs-sec + .czs-sec::before { content: ""; position: absolute; left: 14px; right: 12px; top: 0; height: 1px; background: var(--cz-hair); }
81
86
  .czs-row { position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 12px 0 14px; background: none; border: 0; font: inherit; color: var(--cz-ink); text-align: left; cursor: pointer; }
82
87
  .czs-row:disabled { cursor: default; }
88
+ /* a row's own quiet press at its right end, after the chevron (the pencil on a program's Milestones row, canvas MsB0Entry) */
89
+ .czs-sec.t > .czs-row { padding-right: 52px; }
90
+ .czs-tail { position: absolute; right: 6px; top: 6px; display: inline-flex; }
83
91
  .czs-row:hover:not(:disabled) { background: color-mix(in srgb, var(--cz-well) 40%, var(--cz-card)); }
84
92
  .czs-row:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: -2px; border-radius: 12px; }
85
93
  .czs-row b { flex: 1; min-width: 0; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@@ -39,7 +39,7 @@ export function shownUser(text) {
39
39
  const g = t.indexOf(MARK.grill + ' The PM set a goal: ');
40
40
  if (g >= 0) return '/goal ' + t.slice(g + (MARK.grill + ' The PM set a goal: ').length).split('\n')[0];
41
41
  if (t.startsWith(OPENING)) { const i = t.lastIndexOf('\nThe PM says: '); if (i >= 0) return t.slice(i + '\nThe PM says: '.length); }
42
- if (t.startsWith('[PMOS report]') || t.startsWith('[PMOS program]')) { const i = t.lastIndexOf('\nThe PM says: '); if (i >= 0) return t.slice(i + '\nThe PM says: '.length); } // premium-reports-from-chat: lib/report-chat.js wrap; lib/program-chat.js wrap
42
+ if (t.startsWith('[PMOS report]') || t.startsWith('[PMOS program]') || t.startsWith('[PMOS workflow]')) { const i = t.lastIndexOf('\nThe PM says: '); if (i >= 0) return t.slice(i + '\nThe PM says: '.length); } // premium-reports-from-chat: lib/report-chat.js wrap; lib/program-chat.js wrap; lib/workflow-chat.js wrap
43
43
  return t;
44
44
  }
45
45
 
@@ -21,6 +21,8 @@ import * as H from './home-data.js';
21
21
  import { mountChat, avHtml } from './home-chat.js';
22
22
  import * as MORE from './home-more.js';
23
23
  import { headModel, STEPS } from './premium-initiative-head.js';
24
+ import * as WFM from './ini-wf-model.js'; // D99: the workflow an initiative runs (kind line, usual days)
25
+ import { wfIcon, wfOf } from './wf-model.js';
24
26
  import { startAgent } from './page-agent.js';
25
27
  import { mdHtml } from './chat-md.js';
26
28
  import { mountPhoneCard } from './home-phone-card.js';
@@ -166,6 +168,8 @@ async function load() {
166
168
  const others = await Promise.all(otherProducts(D).map((a) => getRetry('/api/board-premium?ws=' + encodeURIComponent(a.ws), 4).then((r) => (r && r.ok && r.model ? { ws: a.ws, name: a.name, model: r.model } : null))));
167
169
  const got = others.filter(Boolean);
168
170
  if (got.length || D.others.length) { D.others = got; drawList(); }
171
+ // an initiative of another product opened before its board was read (a link, a quick press): read it again from its own board
172
+ if (S.ini && !S.IM && otherIni(S.ini)) goIni(S.ini, { page: VW.isOpen() });
169
173
  }
170
174
  /** The products Home reads (Products, on) other than the board's own: each is a group of the list, read from its own board. At most four. */
171
175
  function otherProducts(D) {
@@ -176,7 +180,8 @@ function otherProducts(D) {
176
180
  async function loadIni() {
177
181
  const id = S.ini;
178
182
  if (!id || id === 'product') { S.IM = null; S.IMid = id; S.D.files = []; return; }
179
- const b = (S.D.board && S.D.board.board) || {};
183
+ // an initiative of another product is read from its own board, not this one (it is not on this board, so the read said it could not be read)
184
+ const oi = otherIni(id), b = oi ? { ws: oi.ws, id: oi.board } : (S.D.board && S.D.board.board) || {};
180
185
  const r = await getRetry('/api/initiative-premium?id=' + encodeURIComponent(id) + (b.ws ? '&ws=' + encodeURIComponent(b.ws) : wsQ('&')) + (b.id ? '&board=' + encodeURIComponent(b.id) : boardQ('&')), 16);
181
186
  S.IM = r && r.ok && r.model ? r.model : null; S.IMid = id;
182
187
  if (S.IM) { import('./premium-vw-jira.js').catch(() => {}); import('./premium-vw-item.js').catch(() => {}); } // the Overview's ticket, sprint and record views, ready before a press
@@ -277,14 +282,25 @@ function filterMenu(b) {
277
282
  }
278
283
 
279
284
  /* ── the initiative card ── */
280
- function iniRowOf(id) { return H.boardRows(S.D).find((r) => r.id === id) || null; }
285
+ function iniRowOf(id) { return H.boardRows(S.D).find((r) => r.id === id) || (otherIni(id) || {}).row || null; }
286
+ /** An initiative of another product Home reads (D.others): its row, and the workspace and board it is read from. Null for the board's own. */
287
+ function otherIni(id) {
288
+ if (!id || id === 'product' || H.boardRows(S.D).some((r) => r.id === id)) return null;
289
+ for (const o of S.D.others || []) {
290
+ const rows = (o && o.model && o.model.initiatives && o.model.initiatives.list && o.model.initiatives.list.rows) || [];
291
+ const row = rows.find((r) => r.id === id);
292
+ if (row) return { ws: o.ws, board: (o.model.board || {}).id || null, row };
293
+ }
294
+ return null;
295
+ }
281
296
  function headOf(id) {
282
- const M = S.IM && S.IMid === id ? { ...S.IM } : { head: { stage: (iniRowOf(id) || {}).stage }, acts: (iniRowOf(id) || {}).acts || {} };
297
+ const row = iniRowOf(id) || {};
298
+ const M = S.IM && S.IMid === id ? { ...S.IM } : { head: { stage: row.stage }, acts: row.acts || {} };
299
+ Object.assign(M, { wf: row.wf || null, wfStage: row.wfStage || null, wfStages: row.wfStages || null }); // D99: the initiative's own workflow
283
300
  const t = S.D.trail && S.D.trail.items && S.D.trail.items[id];
284
- const k = String((M.head && M.head.stage) || (iniRowOf(id) || {}).stage || '').toLowerCase();
285
- const u = S.D.trail && S.D.trail.usual && S.D.trail.usual[k];
301
+ const u = WFM.usualOf(S.D.trail, { ...row, stage: (M.head && M.head.stage) || row.stage }); // "usually N days" within its own workflow
286
302
  if (t && t.since) M.stageSince = t.since;
287
- if (u && u.n >= 3 && u.days != null) M.usualDays = u.days;
303
+ if (u) M.usualDays = u.days;
288
304
  const h = headModel(M, S.D.now);
289
305
  // the Needs-you rows of this initiative make it the PM's turn too
290
306
  const need = H.needsOf(S.D).find((r) => r.ini === id);
@@ -307,8 +323,10 @@ const MS = '<i class="cz-ms" aria-hidden="true"></i>'; // the milestone mark (
307
323
  const msStep = (label) => !!(STEPS.find((s) => s.label === label) || {}).ms;
308
324
  /** "To reach ◆ Deliver": the milestone mark before a milestone's name in the checklist's title. */
309
325
  const ckTitle = (t, ms) => { const m = ms && /^(To reach |To finish )(.+)$/.exec(String(t || '')); return m ? esc(m[1]) + MS + esc(m[2]) : esc(t); };
310
- /** "Feature · KR 2.1": an initiative's lane and anchor, the kind line over its name. */
311
- function kindOf(id) { const r = iniRowOf(id) || {}; return [r.lane ? r.lane.charAt(0).toUpperCase() + r.lane.slice(1) : 'Feature', r.kr || r.anchor || ''].filter(Boolean).join(' · '); }
326
+ /** The workflow's icon on the stage card (WfTriage): a press opens the Change picker (ini-wf.js). */
327
+ const wfPill = (id) => { const w = wfOf(iniRowOf(id) || {}); return `<button type="button" class="hm-wf" data-hm-wf aria-haspopup="listbox" aria-expanded="false" aria-label="Workflow: ${esc(w.name)}. Change" title="${esc(w.name)} · Change">${wfIcon(w, 18)}</button>`; };
328
+ /** "Tender · KR 2.1": the workflow an initiative runs and its anchor, the kind line over its name (D99: Kind becomes Workflow). */
329
+ function kindOf(id) { return WFM.kindLine(iniRowOf(id) || {}); }
312
330
  function cardHtml(id) {
313
331
  const prod = id === 'product';
314
332
  let kind, title, turn, turnLabel, stage, lad = '', bars = '', ckh, items, then, time, cta, primary, over = false, foldSum = '', msNext = false;
@@ -338,7 +356,7 @@ function cardHtml(id) {
338
356
  }
339
357
  // on the initiative's page the Viewer's header names it (kind, title, New session): the card is its stage box alone (HbCDesk)
340
358
  return `<section class="hm-card hm-pcard" aria-label="${esc(title)}">`
341
- + `<div class="hm-box ${esc(turn)}"><div class="hm-br"><span class="hm-turn ${esc(turn)}"><i aria-hidden="true"></i>${esc(turnLabel)}</span><span class="st">${esc(stage)}</span></div>`
359
+ + `<div class="hm-box ${esc(turn)}"><div class="hm-br"><span class="hm-turn ${esc(turn)}"><i aria-hidden="true"></i>${esc(turnLabel)}</span>${prod ? '' : wfPill(id)}<span class="st">${esc(stage)}</span></div>`
342
360
  + lad + bars
343
361
  // the checklist folds to one line (AgInitSpec): its title, the summary and a chevron; Then and the time line show only unfolded
344
362
  + (S.cardFold
@@ -435,7 +453,7 @@ function chatHead(t) {
435
453
  const ini = t.ini || (r && r.ini) || null;
436
454
  const ir = ini ? rowById('i:' + ini) : null, b = ini ? iniRowOf(ini) : null;
437
455
  const stage = (ir && ir.stage) || (b && b.stage) || '';
438
- return { row: r || ir, title, scope: ini ? iniTitle(ini) : '', at: L.stageAt(stage), stage };
456
+ return { row: r || ir, title, scope: ini ? iniTitle(ini) : '', at: b ? L.rowAt({ ...b, stage }) : L.stageAt(stage), steps: L.ownSteps(b), stage };
439
457
  }
440
458
  function scopeItems() {
441
459
  return [{ label: 'All work', sub: 'Home', go: () => select(null) }, { label: H.productName(S.D) + ' · product', go: () => goIni('product') }]
@@ -484,7 +502,7 @@ const scopeOf = (ini) => (ini ? { text: iniTitle(ini), icon: I.flag } : { text:
484
502
  const rich = () => !!S.ini;
485
503
  function iniTarget(id) {
486
504
  const h = S.H || {};
487
- return { key: 'init:' + id, ini: id, ws: WS || undefined, title: iniTitle(id), sub: (S.IMid === id && h.stage) || '', scope: scopeOf(id), rich: true, placeholder: 'Message Claude about ' + iniTitle(id),
505
+ return { key: 'init:' + id, ini: id, ws: (otherIni(id) || {}).ws || WS || undefined, title: iniTitle(id), sub: (S.IMid === id && h.stage) || '', scope: scopeOf(id), rich: true, placeholder: 'Message Claude about ' + iniTitle(id),
488
506
  empty: 'Ask about ' + iniTitle(id) + '. Claude reads its records and works in a real Claude Code session.', also: alsoOf(id),
489
507
  // the initiative's conversation opens on where it stands (AgInitYou), until it has messages of its own
490
508
  intro: S.IMid === id && h.cur ? { role: CLAUDE, onlyEmpty: true, text: h.cur + '. ' + h.doneOf + '.' + (h.rest.length ? ' Waiting: ' + h.rest.map((x) => x.label).join(', ') + '.' : ''), pills: [{ label: h.cta, primary: true, go: () => cta() }, { label: 'Discuss', go: () => chat.focus() }] } : undefined, context: h.payoff ? 'Initiative ' + id + ': ' + (h.stage || '') + '. ' + (h.time || '') : undefined };
@@ -668,6 +686,25 @@ async function goIni(id, o = {}) {
668
686
  if (S.ini !== id) return;
669
687
  drawList(); openTarget(iniTarget(id));
670
688
  }
689
+ /** Another product's heading name: its page in the Viewer and its own chat, as the board's own product opens. Home stays on this workspace,
690
+ * so the chat and the list do not change to that product's workspace. Its weekly update and metrics review open its own Home in a new tab. */
691
+ function goOtherProduct(g) {
692
+ const ws = g.product.ws, name = g.name, C = H.productCard({ board: g.product.model }, S.D.now);
693
+ S.ini = null; S.sel = null; S.IM = null; S.head = g.key;
694
+ if (isPhone()) sheet(false);
695
+ syncUrl(); drawList();
696
+ openTarget({ key: 'chat:product:' + ws, ws, title: name, sub: 'Product', scope: { text: name + ' · product', icon: I.flag }, rich: false, role: CLAUDE, to: null,
697
+ placeholder: 'Message Claude about ' + name, empty: 'Ask about ' + name + '. Claude reads its goals, its initiatives and this week\'s update.',
698
+ context: 'Product ' + name + '. ' + C.of + (C.items.length ? ': ' + C.items.map((x) => x.label).join('; ') : '') + '.', also: null });
699
+ pushPage();
700
+ const own = '/premium.html?ws=' + encodeURIComponent(ws) + '&ini=product';
701
+ VW.open({ id: 'product:' + ws, kind: 'Product', title: name, icon: 'chart',
702
+ render: (b) => {
703
+ const goals = C.items.map((x) => itemHtml({ kind: x.kind === 'ok' ? 'done' : 'risk', label: x.label })).join('') || '<p class="hm-none">No KR or budget is anchored on this board.</p>';
704
+ b.innerHTML = `<div class="hi-v hi-page"><section class="hi-pg" aria-label="Goals"><div class="hi-pgh"><b>Goals</b><span class="hi-n">${esc(C.of)}</span></div>${goals}</section>`
705
+ + `<section class="hi-pg" aria-label="This week"><div class="hi-pgh"><b>This week</b></div><div class="hm-r hi-r"><a class="hm-rm" href="${esc(own)}" target="_blank" rel="noopener"><span class="hm-tile">${SVG(I.doc, 14)}</span><span class="hm-rt"><b>Weekly update and metrics review</b><em class="q">In ${esc(name)}'s own Home, in a new tab</em></span></a></div></section></div>`;
706
+ } });
707
+ }
671
708
  /** A program heading's name: the program panel in the Viewer, the program's own chat (HbCProg). */
672
709
  function goProgram(id) {
673
710
  if (!(S.D.programs || []).some((p) => p && p.id === id)) { toast('That program is not on this machine.'); return; }
@@ -1252,7 +1289,7 @@ $('#hmList').onclick = (e) => { // delegated: every press on the list is a <bu
1252
1289
  if ('hmDayx' in d) { day(false); return; }
1253
1290
  if ('hmFlt' in d) { filterMenu(b); return; }
1254
1291
  if (d.hmProg) { goProgram(d.hmProg); return; } // the program panel, in Home's Viewer (HbCProg)
1255
- if (d.hmProdopen) { const g = ((S.M && S.M.groups) || []).find((x) => x.key === d.hmProdopen); if (g && !g.primary && g.product && g.product.ws) { location.href = '/premium.html?ws=' + encodeURIComponent(g.product.ws) + '&ini=product'; return; } goIni('product'); return; }
1292
+ if (d.hmProdopen) { const g = ((S.M && S.M.groups) || []).find((x) => x.key === d.hmProdopen); if (g && !g.primary && g.product && g.product.ws) { goOtherProduct(g); return; } goIni('product'); return; }
1256
1293
  if (d.hmKids) { // the chevron of an initiative: what sits under it shows or hides
1257
1294
  if (b.getAttribute('aria-expanded') === 'true') { S.kids.delete(d.hmKids); S.kidsOff.add(d.hmKids); } else { S.kids.add(d.hmKids); S.kidsOff.delete(d.hmKids); }
1258
1295
  keepKids(); drawList(); const f = $(`#hmList [data-hm-kids="${CSS.escape(d.hmKids)}"]`); if (f) f.focus(); return;
@@ -1339,7 +1376,7 @@ function cta() {
1339
1376
  }
1340
1377
 
1341
1378
  /* ── start ── */
1342
- mountIni({ S, VW, pmGet, pmPost, toast, renameIni: (id, pre) => iniRenameOf(id, pre), renameTask: (t) => taskRenameOf(t), load: () => load(), loadIni: () => loadIni(), openFile: (f) => openFile(f), iniTitle: (id) => iniTitle(id), drawList: () => drawList(), wait: MORE.WAIT,
1379
+ mountIni({ S, VW, pmGet, pmPost, toast, rowOf: (id) => iniRowOf(id), renameIni: (id, pre) => iniRenameOf(id, pre), renameTask: (t) => taskRenameOf(t), load: () => load(), loadIni: () => loadIni(), openFile: (f) => openFile(f), iniTitle: (id) => iniTitle(id), drawList: () => drawList(), wait: MORE.WAIT,
1343
1380
  // the initiative's page (HbCDesk): its card, its header and its ⋯
1344
1381
  cardHtml: (id) => cardHtml(id), kindOf: (id) => kindOf(id), cta: () => cta(), overviewAsk: (id) => overviewAsk(id), newIn: (id) => newIn(id), addPerson: () => addPerson(), turnProgram: (id) => turnProgram(id), talk: () => talk(),
1345
1382
  foldCard: () => { S.cardFold = !S.cardFold; store.set('pmos.home.cardfold', S.cardFold ? '1' : null); } });
@@ -36,7 +36,7 @@ export function moveModel(h, M, L, now = Date.now()) {
36
36
  const open = items.filter((x) => !x.done);
37
37
  const self = !!acts.self, life = acts.life || null;
38
38
  const lay = L || { auto: true, held: [] };
39
- const ms = !!next && isMilestone(next);
39
+ const ms = !!next && (Array.isArray(acts.msNames) ? acts.msNames.includes(next) : isMilestone(next)); // D99: the workflow's own ◆ stages
40
40
  const finished = String((m.head && m.head.statusLabel) || '') === 'Done';
41
41
  const canMove = !self && !life && !!next, canBack = !self && !life && !!prev;
42
42
  const allDone = items.length > 0 && open.length === 0;
@@ -44,7 +44,7 @@ export function moveModel(h, M, L, now = Date.now()) {
44
44
  const auto = lay.auto !== false;
45
45
  const n = items.length;
46
46
  const swText = !n ? 'Moves on by itself when its exit items are done' : n === 1 ? 'Moves on by itself when it is done' : n === 2 ? 'Moves on by itself when both are done' : 'Moves on by itself when all ' + n + ' are done';
47
- const why = self ? 'The stage of this board comes from the workflow engine.' : life === 'hold' ? 'On hold: resume it to move the stage.' : life === 'cancelled' ? 'Cancelled: resume it to move the stage.' : !next && cur ? cur + ' is the last stage.' : !cur ? 'No stage on record.' : '';
47
+ const why = self ? 'The stage of this board comes from the workflow engine.' : life === 'hold' ? 'On hold: resume it to move the stage.' : life === 'cancelled' ? 'Cancelled: resume it to move the stage.' : life === 'ended' ? 'Won’t do: bring it back to Triage to move it.' : !next && cur ? cur + ' is the last stage.' : !cur ? 'No stage on record.' : '';
48
48
  return {
49
49
  cur, next, prev, items, open, allDone, ms, self, life, canMove, canBack, auto, held, swText, why,
50
50
  title: next ? 'To finish ' + cur : cur ? 'To finish ' + cur : 'What is next',
@@ -183,3 +183,33 @@ button.hi-pill { cursor: pointer; }
183
183
  .hi-pge p { margin: 0; font-size: 13px; color: var(--cz-ink3); }
184
184
  .hi-talk { min-height: 44px; border: 0; border-radius: 22px; background: var(--cz-well); color: var(--cz-ink3); font: inherit; font-size: 14px; text-align: left; padding: 0 16px; cursor: pointer; }
185
185
  @media (hover: hover) { .hi-pgm:hover { background: var(--cz-well2); } }
186
+
187
+ /* ── D99: the initiative's own workflow (WfTriage, WfAChange, WfAWontDo) ── */
188
+ .cz .wfi { display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: 6px; background: var(--cz-well); color: var(--cz-ink2); }
189
+ .cz .wfi svg { width: 70%; height: 70%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
190
+ .hm-br .hm-wf { margin-left: auto; display: inline-flex; align-items: center; padding: 3px; border: 0; border-radius: 9px; background: none; cursor: pointer; color: inherit; }
191
+ .hm-br .hm-wf:hover, .hm-br .hm-wf[aria-expanded="true"] { background: var(--cz-well); }
192
+ .hm-br .hm-wf + .st { margin-left: 0; }
193
+ .hi-pop.wide:not(.sheet) { width: 560px; }
194
+ .hi-pop.menu .hi-mi .wfi { margin-left: -2px; }
195
+ .hi-wfpad { padding: 4px 12px 6px; }
196
+ .hi-wfchain { line-height: 1.5; }
197
+ .hi-mut { color: var(--cz-ink3); }
198
+ .hi-wfh { display: flex; align-items: center; gap: 8px; }
199
+ .hi-wfh .hi-h3 { flex: 1; min-width: 0; }
200
+ .hi-wfrows { display: flex; flex-direction: column; }
201
+ .hi-wfrow { display: grid; grid-template-columns: minmax(0, 130px) 14px minmax(0, 130px) minmax(0, 1fr); align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--cz-hair); font-size: 13.5px; }
202
+ .hi-wfrow:first-child { border-top: 0; }
203
+ .hi-wfrow span { min-width: 0; }
204
+ .hi-wfrow em { display: block; font-style: normal; font-size: 12px; color: var(--cz-ink3); }
205
+ .hi-wfland { display: flex; align-items: center; gap: 8px; }
206
+ .hi-wfland span { flex: 1; }
207
+ .hi-wfland select { font: inherit; font-size: 13px; font-weight: 700; color: var(--cz-ink); background: var(--cz-well); border: 0; border-radius: 10px; padding: 6px 10px; max-width: 60%; }
208
+ .hi-end { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; background: var(--cz-well); font-size: 13px; }
209
+ .hi-end p { margin: 0; flex: 1; min-width: 0; color: var(--cz-ink2); }
210
+ .hi-endi { display: inline-flex; color: var(--cz-ink3); }
211
+ @media (max-width: 760px) {
212
+ .hi-wfrow { grid-template-columns: minmax(0, 1fr) 14px minmax(0, 1fr); }
213
+ .hi-wfrow > .hi-small { grid-column: 1 / -1; }
214
+ .hi-end { flex-wrap: wrap; }
215
+ }
@@ -23,6 +23,7 @@
23
23
  * under ⋯; the phone keeps the Tasks | Documents | Stage switch. The pure half of the tickets is tk-model.js. */
24
24
  import * as MD from './home-ini-model.js';
25
25
  import * as TKM from './tk-model.js';
26
+ import * as WF from './ini-wf.js'; // D99: the initiative's own workflow (Change picker, switch, Won't do, Archive)
26
27
 
27
28
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
28
29
  const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
@@ -76,10 +77,37 @@ function moveHtml(id, M, mv) {
76
77
  + `<div class="hi-mvb"><button type="button" class="hi-btn sm dark" data-hi-move aria-haspopup="dialog" aria-expanded="${!!(X.pop && X.pop.kind === 'move')}">Move to ${mv.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(mv.next)}${SVG(I.next, 14)}</button>`
77
78
  + (mv.canBack ? `<button type="button" class="hi-ib" data-hi-back aria-haspopup="dialog" aria-label="Move back a stage, to ${esc(mv.prev)}" title="Move back to ${esc(mv.prev)}">${SVG(I.back, 16)}</button>` : '') + '</div></div>';
78
79
  }
79
- function mvOf(id, M) { return MD.moveModel(X.ctx.S.H || null, M, Lof(id), Date.now()); }
80
+ /** D99: an initiative on a workflow of the library moves between ITS stages (the row's wfStages; a skipped stage is left out), and that
81
+ * stage's Moves on by itself is the default (the PM's own choice for this one initiative wins, POST /api/boards/ini-auto). */
82
+ const rowOf = (id) => (X.ctx.rowOf ? X.ctx.rowOf(id) : null) || {};
83
+ const ownWf = (row) => !!(row.wf && row.wf.id && row.wf.id !== 'product-feature' && Array.isArray(row.wfStages) && row.wfStage);
84
+ function wfM(id, M) {
85
+ const row = rowOf(id);
86
+ if (!ownWf(row) && !row.ended) return M;
87
+ const acts = { ...M.acts };
88
+ if (ownWf(row)) {
89
+ const st = row.wfStages.filter((s) => s.status !== 'skipped' || s.key === row.wfStage.key);
90
+ Object.assign(acts, { stages: st.map((s) => s.name), stage: row.wfStage.name, msNames: st.filter((s) => s.milestone).map((s) => s.name), self: false });
91
+ }
92
+ if (row.ended) acts.life = 'ended';
93
+ return { ...M, acts };
94
+ }
95
+ function wfL(id, L) {
96
+ const row = rowOf(id);
97
+ if (!ownWf(row)) return L;
98
+ const cur = row.wfStages.find((s) => s.key === row.wfStage.key) || {};
99
+ return { ...L, auto: !!cur.auto, held: L.held || [] };
100
+ }
101
+ function mvOf(id, M) { return MD.moveModel(X.ctx.S.H || null, wfM(id, M), wfL(id, Lof(id)), Date.now()); }
102
+ /** What ini-wf.js needs from the page. */
103
+ function wfUi() {
104
+ const C = X.ctx;
105
+ return { openPop, closePop, undoToast, toast: C.toast, pmGet: C.pmGet, pmPost: C.pmPost, load: async () => { await C.load(); redrawView(); }, row: rowOf, title: C.iniTitle,
106
+ bw: (id) => { const M = curM(); const r = rowOf(id); return M ? bw(M) : { ws: r.ws, board: r.board }; } };
107
+ }
80
108
 
81
109
  async function doMove(id, M, to, why, o = {}) {
82
- const from = M.acts.stage;
110
+ const from = wfM(id, M).acts.stage;
83
111
  const r = await X.ctx.pmPost('/api/boards/move', { ...bw(M), id, to, why });
84
112
  if (!r || r.ok === false) { X.ctx.toast((r && r.error) || 'The stage did not move.'); return false; }
85
113
  const title = X.ctx.iniTitle(id);
@@ -119,8 +147,8 @@ function openPop(anchor, kind, html, onClick, o = {}) {
119
147
  closePop();
120
148
  const el = document.createElement('div');
121
149
  const sheet = isPhone() && !o.menu;
122
- el.className = 'cz hi-pop' + (sheet ? ' sheet' : '') + (o.menu ? ' menu' : '');
123
- el.setAttribute('role', o.menu ? 'menu' : 'dialog'); el.setAttribute('aria-label', o.label || ''); el.setAttribute('data-esc-layer', '');
150
+ el.className = 'cz hi-pop' + (sheet ? ' sheet' : '') + (o.menu ? ' menu' : '') + (o.wide ? ' wide' : '');
151
+ el.setAttribute('role', o.role || (o.menu ? 'menu' : 'dialog')); el.setAttribute('aria-label', o.label || ''); el.setAttribute('data-esc-layer', '');
124
152
  el.innerHTML = (sheet ? '<div class="hi-grab" aria-hidden="true"></div>' : '') + html;
125
153
  let scrim = null;
126
154
  if (sheet) { scrim = document.createElement('div'); scrim.className = 'hi-scrim'; scrim.onclick = closePop; document.body.appendChild(scrim); }
@@ -214,22 +242,34 @@ function pageHtml(id, M) {
214
242
  + look.map(drow).join('') + `<button type="button" class="hi-pgm" data-hi-open="docs">Show all ${docs.length}${SVG(I.right, 14, 2)}</button></section>` : '';
215
243
  // a phone: the page is a sheet over the list, and the chat is one press away (HbCPhone)
216
244
  const talk = isPhone() ? `<button type="button" class="hi-talk" data-hi-talk>Message Claude about ${esc(X.ctx.iniTitle(id))}</button>` : '';
217
- return `<div class="hi-v hi-page" data-hi-v="page">${card}${tasks}${dsec}${talk}<p class="hi-small" role="status" id="ovMsg"></p></div>`;
245
+ return `<div class="hi-v hi-page" data-hi-v="page">${WF.endedHtml(rowOf(id))}${card}${tasks}${dsec}${talk}<p class="hi-small" role="status" id="ovMsg"></p></div>`;
218
246
  }
219
247
  /** ⋯ of the page (HbCMore): change it, look at it elsewhere, then stop it, red and last. */
220
248
  function pageMore(id) {
221
249
  const M = curM(); if (!M) return [];
222
- const mv = mvOf(id, M), out = [];
223
- if (!mv.why) out.push({ label: 'Moves on by itself', note: mv.auto ? 'On' : 'Off', on: () => press(id, M, { kind: 'auto', on: !mv.auto }) });
250
+ const mv = mvOf(id, M), out = [], row = rowOf(id), self = !!(M.acts && M.acts.self);
251
+ // D99 (WfAWontDo): Change workflow and Rename first; the PMOS-self board keeps its derived ladder, so it has no workflow to change
252
+ if (!self && !row.ended) out.push({ label: 'Change workflow', note: (row.wf || {}).name || 'Product feature', on: (b) => WF.openPicker(b || moreBtn(), wfUi(), id) });
253
+ if (X.ctx.renameIni) out.push({ label: 'Rename', on: () => { const t = document.querySelector('#czViewer [data-cz-vw-rn]'); if (t) t.click(); } });
254
+ if (!mv.why) out.push({ label: 'Moves on by itself', note: mv.auto ? 'On' : 'Off', on: () => (ownWf(row) ? autoPress(id, M, !mv.auto) : press(id, M, { kind: 'auto', on: !mv.auto })) });
224
255
  if (mv.canBack) out.push({ label: 'Move back a stage', note: mv.prev, on: (b) => popBack(b || document.querySelector('#czViewer [data-cz-vw="more"]'), id, M, mv) });
225
256
  if ((M.acts.stages || []).length && !M.acts.self) out.push({ label: 'Move to a stage', on: () => iniOverview('stage', { back: true }) });
226
257
  out.push({ label: 'Add a stakeholder', on: () => X.ctx.addPerson() });
227
258
  if (X.ctx.turnProgram) out.push({ label: 'Turn into a program', on: () => X.ctx.turnProgram(id) });
228
259
  out.push({ sep: true }, { label: 'Open on the Board', on: () => { location.href = '/premium-board.html?focus=' + encodeURIComponent(id) + (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) : '') + (M.board.id ? '&board=' + encodeURIComponent(M.board.id) : ''); } },
229
260
  { label: 'The record', on: async () => (X.ctx.VW.drill(), await import('./premium-vw-item.js')).openWorkItem({ kind: 'initiative', id, title: M.title, ...bw(M) }) });
230
- if (!M.acts.life) out.push({ sep: true }, { label: 'Put on hold', on: () => { iniOverview('stage', { back: true, ask: 'on-hold' }); } }, { label: 'Cancel the initiative', danger: true, on: () => { iniOverview('stage', { back: true, ask: 'cancelled' }); } });
261
+ // Won't do and Archive hold from any stage (wfRules); Won't do comes back to Triage. Cancel stays red and last (HbCMore)
262
+ if (!self) out.push({ sep: true }, row.ended ? { label: 'Back to Triage', on: () => WF.backToTriage(wfUi(), id) } : { label: 'Won’t do', on: (b) => WF.openWontDo(b || moreBtn(), wfUi(), id) }, { label: 'Archive', on: () => WF.archive(wfUi(), id) });
263
+ if (!M.acts.life && !row.ended) out.push({ sep: true }, { label: 'Put on hold', on: () => { iniOverview('stage', { back: true, ask: 'on-hold' }); } }, { label: 'Cancel the initiative', danger: true, on: () => { iniOverview('stage', { back: true, ask: 'cancelled' }); } });
231
264
  return out;
232
265
  }
266
+ const moreBtn = () => document.querySelector('#czViewer [data-cz-vw="more"]') || document.body;
267
+ /** Moves on by itself for this one initiative, on a workflow of the library (POST /api/boards/ini-auto): the stage sets the default. */
268
+ async function autoPress(id, M, on) {
269
+ const r = await X.ctx.pmPost('/api/boards/ini-auto', { ...bw(M), id, stage: rowOf(id).wfStage.key, auto: on });
270
+ if (!r || r.ok === false) { X.ctx.toast((r && r.error) || 'Nothing was changed.'); return; }
271
+ await X.ctx.load(); redrawView();
272
+ }
233
273
  export function iniPage() {
234
274
  if (!X.ctx) return false;
235
275
  const S = X.ctx.S, id = S.ini;
@@ -241,6 +281,7 @@ export function iniPage() {
241
281
  BODY = VW.open({ id: 'ov:' + id, kind: X.ctx.kindOf(id), title: X.ctx.iniTitle(id), icon: 'goal', more: () => pageMore(id), rename,
242
282
  add: { label: 'New session', on: () => X.ctx.newIn(id) },
243
283
  render: (b) => { X.view = 'page'; BODY = b; draw(b); wire(b, id); } });
284
+ WF.pmosNotice(wfUi(), id); // WfTriage: "Set to Tender from the BRD · Undo", once
244
285
  if (!curM()) { X.failed = null; X.ctx.loadIni().then(() => { if (S.ini !== id) return; if (!curM()) X.failed = id; redrawView(); }); }
245
286
  return true;
246
287
  }
@@ -491,7 +532,7 @@ function wire(body, id) {
491
532
  const d = t.dataset;
492
533
  if (X.view === 'page' && pagePress(t, id, M)) return;
493
534
  if (d.hiView) { iniOverview(d.hiView); return; }
494
- if ('hiAuto' in d) { press(id, M, { kind: 'auto', on: t.getAttribute('aria-checked') !== 'true' }); return; }
535
+ if ('hiAuto' in d) { const on = t.getAttribute('aria-checked') !== 'true'; if (ownWf(rowOf(id))) autoPress(id, M, on); else press(id, M, { kind: 'auto', on }); return; }
495
536
  if ('hiBy' in d) { groupMenu(t, id, M); return; }
496
537
  // PRD to Jira (T1 to T3)
497
538
  if (d.czsAct === 'tk-sendall') { sendSheet(id, M); return; }
@@ -598,6 +639,8 @@ function pagePress(t, id, M) {
598
639
  if ('hmCta' in d) { C.cta(); return true; }
599
640
  if ('hmOv' in d) { C.overviewAsk(id); return true; }
600
641
  if ('hmCfold' in d) { C.foldCard(); redrawView(); return true; }
642
+ if ('hmWf' in d) { if (!(M.acts && M.acts.self)) WF.openPicker(t, wfUi(), id); else C.toast('This board takes its stages from the workflow engine.'); return true; }
643
+ if ('wfBack' in d) { WF.backToTriage(wfUi(), id); return true; }
601
644
  if ('hmDone' in d) { C.S.doneOpen = !C.S.doneOpen; redrawView(); return true; }
602
645
  if ('hiTalk' in d) { C.talk(id); return true; }
603
646
  if ('hiMove' in d) { const mv = mvOf(id, M); if (!mv.canMove) return true; if (mv.open.length) popMove(t, id, M, mv); else doMove(id, M, mv.next, mv.allDone ? 'Moved by hand: every exit item is done.' : 'Moved by hand'); return true; }
@@ -23,7 +23,6 @@ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct
23
23
  const DOW = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
24
24
  const RANK = { needs: 4, blocked: 3, working: 2, quiet: 1 };
25
25
  const pad = (n) => String(n).padStart(2, '0');
26
- const cap1 = (s) => (s ? String(s).charAt(0).toUpperCase() + String(s).slice(1) : '');
27
26
  const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
28
27
  const isoDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); };
29
28
  const dayDiff = (iso, now) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); if (!m) return null; const a = new Date(+m[1], +m[2] - 1, +m[3]); const t = new Date(now); t.setHours(0, 0, 0, 0); return Math.round((a - t) / 86400000); };
@@ -102,6 +101,9 @@ const meetIni = (m) => (m && (m.initiative || (m.level && m.level.kind === 'init
102
101
  const bareHint = (x) => { const h = String(x.hint || ''), p = prodOf(x); return p && h.startsWith(p + ' · ') ? h.slice(p.length + 3) : p && h === p ? '' : h; }; // the group names the product; "Across products" stays
103
102
  /** Where an initiative is on the eight stages (the row's stage track, HvAC .mt): 0 Triage … 7 Evaluate, or -1 when its stage is not one of them. */
104
103
  export const stageAt = (stage) => { const k = stageKey(stage); return k ? STEPS.findIndex((s) => s.key === k) : -1; };
104
+ /** D99: an initiative on another workflow draws ITS stages ({ ms } each) and its place among them; Product feature draws the eight. */
105
+ export const ownSteps = (r) => (r && r.wf && r.wf.id && r.wf.id !== 'product-feature' && Array.isArray(r.wfStages) && r.wfStage ? r.wfStages.map((s) => ({ ms: !!s.milestone })) : null);
106
+ export const rowAt = (r) => (ownSteps(r) ? r.wfStage.n - 1 : stageAt(r && r.stage));
105
107
  /** A row under an initiative that is the PM's move now (Your move, and the initiative's count badge): a next step, a session
106
108
  * that waits on the PM, or a task of the PM's own that is late. */
107
109
  const isMove = (k) => k.step || (k.kind === 'session' && (k.state === 'needs' || k.state === 'blocked')) || (k.kind === 'task' && k.mine && k.late);
@@ -117,9 +119,9 @@ function iniRowOf(D, r, needs, now) {
117
119
  const right = turn ? 'your turn' + (mine ? ' · ' + plural(mine, 'task', 'tasks') : '') : mine ? plural(mine, 'task', 'tasks') : run ? run + ' running' : 'Nothing today';
118
120
  // next steps, sessions and today's meetings always show; tasks show the TASKS_SHOWN most urgent, the rest behind "Show N more tasks"
119
121
  const kids = [...steps, ...ses.sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0)), ...tasks.map((t, i) => (i < TASKS_SHOWN ? t : { ...t, extra: true })), ...meet];
120
- const hint = r.made ? [cap1(r.lane), r.stage].filter(Boolean).join(' · ') : [cap1(r.lane || 'feature'), r.stage].filter(Boolean).join(' · ');
122
+ const hint = [(r.wf && r.wf.name) || 'Product feature', r.stage].filter(Boolean).join(' · '); // D99: Kind becomes Workflow
121
123
  return { id: 'i:' + r.id, kind: 'ini', ini: r.id, name: r.title, hint, right, turn, busy: kids.length > 0, state: turn ? 'needs' : run ? 'working' : 'quiet', kids, board: r, updated: r.updated || '',
122
- stage: r.stage || '', at: stageAt(r.stage), yours: kids.filter(isMove).length, late: kids.some((k) => k.kind === 'task' && k.mine && k.late) };
124
+ 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) };
123
125
  }
124
126
 
125
127
  /* ── programs (initiative program-hierarchy, H4; canvas PgHomePhone, PgHomeDesk) ── */
@@ -45,7 +45,7 @@ function checkHtml(r) {
45
45
  return `<button type="button" class="hv-mk hm-ck" data-hm-check="${esc(r.id)}" aria-label="${esc(what)}. Mark ${esc(r.name)} done" title="Mark done"><span class="hv-ck${r.late ? ' late' : ''}"></span></button>`;
46
46
  }
47
47
  const isCheck = (r) => r.check || r.kind === 'task' || r.done;
48
- const track = (at, label) => (at < 0 ? '' : `<span class="hv-mt" role="img" aria-label="${esc(label)}">${STEPS.map((x, i) => `<i class="${[i < at ? 'on' : i === at ? 'now' : '', x.ms ? 'ms' : ''].filter(Boolean).join(' ')}"></i>`).join('')}</span>`);
48
+ const track = (at, label, steps) => (at < 0 ? '' : `<span class="hv-mt" role="img" aria-label="${esc(label)}">${(steps || STEPS).map((x, i) => `<i class="${[i < at ? 'on' : i === at ? 'now' : '', x.ms ? 'ms' : ''].filter(Boolean).join(' ')}"></i>`).join('')}</span>`);
49
49
  const clock = (when) => (when ? `<span class="hv-st">${svg(P.clock, 13)}${esc(String(when).split(' ')[0])}</span>` : '');
50
50
  /** A row of the list: a next step, a task, a note, a mention, a session or a meeting. o: { sel, kid } */
51
51
  export function rowHtml(r, o) {
@@ -68,8 +68,8 @@ export function chatHeadHtml(h) {
68
68
  const mk = !r ? '' : isCheck(r) ? `<span class="hv-mk"><span class="hv-ck${r.late ? ' late' : ''}" role="img" aria-label="${r.late ? 'Task, late' : 'Task'}"></span></span>` : markHtml(r.kind === 'ini' && r.yours && r.state !== 'blocked' ? { state: 'needs' } : r);
69
69
  const lead = h.prog ? `<span class="hv-tl tp sm" aria-hidden="true">${svg(P.layers, 13)}</span>` : '';
70
70
  const same = !h.scope || h.scope === h.title;
71
- const chip = same ? '' : `<span class="hm-chs" title="In ${esc(h.scope)}">${h.prog ? svg(P.layers, 13) : track(h.at == null ? -1 : h.at, h.stage || '')}<span>${esc(h.scope)}</span></span>`;
72
- return `${mk}${same ? lead : ''}<b class="hm-chb">${esc(h.title)}</b>${same && !h.prog ? track(h.at == null ? -1 : h.at, h.stage || '') : ''}${chip}`;
71
+ const chip = same ? '' : `<span class="hm-chs" title="In ${esc(h.scope)}">${h.prog ? svg(P.layers, 13) : track(h.at == null ? -1 : h.at, h.stage || '', h.steps)}<span>${esc(h.scope)}</span></span>`;
72
+ return `${mk}${same ? lead : ''}<b class="hm-chb">${esc(h.title)}</b>${same && !h.prog ? track(h.at == null ? -1 : h.at, h.stage || '', h.steps) : ''}${chip}`;
73
73
  }
74
74
  /** An initiative row: its mark, its title, the count of what is yours while it is folded, the stage track, and a chevron when something
75
75
  * sits under it. The title opens the initiative; the chevron shows or hides its sessions, next steps, tasks and meetings. */
@@ -82,7 +82,7 @@ function iniHtml(r, o) {
82
82
  const badge = !open && r.yours ? `<span class="hv-c" role="img" aria-label="${r.yours === 1 ? '1 is yours' : r.yours + ' are yours'}">${r.yours}</span>` : '';
83
83
  const chev = r.kids.length ? `<button type="button" class="hv-xc" data-hm-kids="${esc(r.id)}" aria-expanded="${open}" aria-label="${open ? 'Hide' : 'Show'} what is in ${esc(r.name)}">${svg(open ? P.chevD : P.chevR, 15)}</button>` : '<span class="hv-xc" aria-hidden="true"></span>';
84
84
  return `<div class="hm-r hv-r ini st-${esc(r.state)}${o.sel === r.id ? ' sel' : ''}" data-id="${esc(r.id)}"><button type="button" class="hm-rm" data-hm-sel="${esc(r.id)}"${o.sel === r.id ? ' aria-current="true"' : ''} title="${esc(r.hint)}">${markHtml(r.yours && r.state !== 'blocked' ? { state: 'needs' } : r)}`
85
- + `<span class="hm-rt"><b>${esc(r.name)}</b></span>${badge}${track(r.at, r.stage)}</button>${chev}</div>${nest}`;
85
+ + `<span class="hm-rt"><b>${esc(r.name)}</b></span>${badge}${track(r.at, r.stage, r.steps)}</button>${chev}</div>${nest}`;
86
86
  }
87
87
 
88
88
  /* ── a group (HvAC .pg, .card; PgHomePhone .psub) ── */