create-pmos 0.687.0 → 0.689.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 (42) hide show
  1. package/package.json +39 -33
  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/briefing-premium-insights-test.js +23 -1
  7. package/workspace/briefing-premium-test.js +3 -0
  8. package/workspace/changelog.json +38 -19
  9. package/workspace/guide/breakdown.md +24 -1
  10. package/workspace/guide/cli.md +3 -0
  11. package/workspace/guide/intelligence-okr-goals.md +1 -1
  12. package/workspace/lib/board-premium.js +13 -3
  13. package/workspace/lib/engine/boards.js +18 -3
  14. package/workspace/lib/jira-cli.js +21 -2
  15. package/workspace/lib/jira-epics.js +125 -0
  16. package/workspace/lib/jira-status.js +18 -3
  17. package/workspace/lib/pmos-verbs.js +1 -1
  18. package/workspace/lib/route-modules.js +1 -0
  19. package/workspace/lib/routes-boards.js +109 -6
  20. package/workspace/lib/routes-jira-epics.js +65 -0
  21. package/workspace/lib/task-cli.js +25 -7
  22. package/workspace/lib/task-jira.js +107 -23
  23. package/workspace/lib/task-store.js +2 -2
  24. package/workspace/lib/tracker-cli.js +21 -2
  25. package/workspace/package-lock.json +2 -2
  26. package/workspace/package.json +1 -1
  27. package/workspace/public/pm/bd-backlog.js +25 -4
  28. package/workspace/public/pm/bd-pop-ds.css +22 -0
  29. package/workspace/public/pm/bd-pop-ds.js +48 -11
  30. package/workspace/public/pm/bd-sprint-ds.js +5 -4
  31. package/workspace/public/pm/bd-sprint.js +10 -3
  32. package/workspace/public/pm/bd-work-ds.css +4 -0
  33. package/workspace/public/pm/cozy-pop-work.css +12 -0
  34. package/workspace/public/pm/cozy-pop-work.js +172 -9
  35. package/workspace/public/pm/ini-view-model.js +12 -1
  36. package/workspace/public/pm/pop-work-model.js +40 -7
  37. package/workspace/public/pm/premium-insights.js +1 -1
  38. package/workspace/public/pm/work-select.js +73 -0
  39. package/workspace/public/pm/work-tree.js +111 -0
  40. package/workspace/skills/jira-epic.skill +35 -0
  41. package/workspace/test-files.json +2 -1
  42. package/workspace/test-lists/work-subtasks.json +11 -0
@@ -27,6 +27,8 @@ import * as SW from './cozy-status-when.js'; // When did this happen? after a
27
27
  import * as DP from './cozy-day-pick.js'; // the app's own day field, "15 Oct 2026"
28
28
  const { localToday } = DP;
29
29
  import * as AK from './artefact-kind.js';
30
+ import * as WT from './work-tree.js'; // subtasks, the epic check and its fix (initiative work-subtasks)
31
+ import * as SEL from './work-select.js'; // select several rows and move them together (WorkBulkDS)
30
32
  import * as PD from './bd-pop-ds.js'; // the popup on a computer, built from the design system's blocks (initiative work-ds-popup) // the Kind of a file and one row per kind (round 3 point 16), shared with the Library // the rename and its Undo, the same write as the old List (batch 18 item 16)
31
33
 
32
34
  const CSS = new URL('./cozy-pop-work.css', import.meta.url).href, DSCSS = new URL('./bd-pop-ds.css', import.meta.url).href;
@@ -52,10 +54,13 @@ const store = {
52
54
  // 'pw-cols2': a column choice saved before round 3 (Status and Date hidden by an older tune menu) no longer hides them (round 3 point 5)
53
55
  const COLS = 'pw-cols2', SPAN = 'pw-span', BIG = 'pw-big', TLW = 'pw-tlw';
54
56
  const cols = () => ({ status: true, date: true, tl: true, kind: true, when: true, ...store.get(COLS, {}) });
55
- const ST = new Map(); // initiative id → { open, shut, moreOpen, farOpen, details, top }
57
+ const ST = new Map(); // initiative id → { open, shut, moreOpen, farOpen, details, top, subOpen, subShut, sel, anchor, tickAsk }
58
+ let RSEL = new Set(); // the rows picked in the initiative drawn last (WorkBulkDS)
56
59
  const LOOSE = 'pw-loose'; // the initiatives whose Not in a stage row the PM opened (round 3 point 21), remembered on this computer
57
60
  const stOf = (id) => {
58
- if (!ST.has(id)) ST.set(id, { open: new Set((store.get(LOOSE, []) || []).includes(id) ? [''] : []), shut: new Set(), moreOpen: new Set(), farOpen: false, details: null, top: 0, msAdd: false, focus: '' });
61
+ if (!ST.has(id)) ST.set(id, { open: new Set((store.get(LOOSE, []) || []).includes(id) ? [''] : []), shut: new Set(), moreOpen: new Set(), farOpen: false, details: null, top: 0, msAdd: false, focus: '',
62
+ // subtasks and the bulk move (initiative work-subtasks): the parents the PM opened or folded, the picked rows, the parent ticked
63
+ subOpen: new Set(), subShut: new Set(), sel: new Set(), anchor: '', tickAsk: '' });
59
64
  return ST.get(id);
60
65
  };
61
66
  const looseKeep = (id, on) => { const L = (store.get(LOOSE, []) || []).filter((x) => x !== id); if (on) L.push(id); store.set(LOOSE, L.slice(-200)); };
@@ -207,6 +212,12 @@ const xOf = (W) => { const a = Date.parse(W.span.a), b = Date.parse(W.span.b); r
207
212
  function barHtml(x, W) {
208
213
  const X = xOf(W);
209
214
  if (x.kind === 'stage') return x.start || x.end ? CB.stageBar({ start: x.start, end: x.end, tone: x.tone, late: x.late, ms: x.ms, name: x.name, gaps: x.gaps, marks: x.open ? [] : x.marks }, X, { today: W.today }) : '';
215
+ // a parent (WorkSubtasksDS): one outlined bar from its earliest subtask start to its latest end, filled as its subtasks finish
216
+ if (x.kids) {
217
+ if (!x.start && !x.end) return '';
218
+ const l = Math.max(0, X(x.start || x.end)), r = Math.min(100, X(x.end || x.start) + 0.6), f = x.nLeaf ? Math.round((x.nDone / x.nLeaf) * 100) : 0;
219
+ return `<i class="pw-pbar${x.done ? ' dn' : ''}" style="left:${l.toFixed(2)}%;width:${Math.max(0.8, r - l).toFixed(2)}%" title="${esc(x.title + ': ' + x.count)}"><b style="width:${f}%"></b></i>`;
220
+ }
210
221
  return CB.taskBar(x, X, W.today);
211
222
  }
212
223
  function rowHtml(x, W, C, sugRows) {
@@ -224,7 +235,10 @@ function rowHtml(x, W, C, sugRows) {
224
235
  if (x.kind === 'more') return `<div class="pw-tr pw-dr" role="row"><span class="pw-it"><button type="button" class="pw-dn" data-pw-more="${esc(x.key)}" aria-expanded="false">${esc(x.label)}${SVG(P.right, 14)}</button></span>${C.status ? '<span></span>' : ''}${C.date ? '<span></span>' : ''}${C.tl ? '<div class="pw-tl"></div>' : ''}</div>`;
225
236
  const s = sugRows.get(x.uid);
226
237
  const title = x.jira ? `<span class="pw-tt">${esc(x.title)}</span>` : `<button type="button" class="pw-tt" data-pw-name="${esc(x.uid)}" aria-label="${esc('Rename ' + x.title)}">${esc(x.title)}</button>`;
227
- return `<div class="pw-tr pw-kr${x.done ? ' done' : ''}${x.lit ? ' lit' : ''}" role="row" data-pw-row="${esc(x.uid)}" data-pw-sec="${esc(x.sec)}"><span class="pw-it"><i class="pw-bul${x.ms ? ' ms' : ''}" aria-hidden="true"></i>${title}${RO ? '' : ib(`data-pw-open="${esc(x.uid)}"`, 'Open the task', P.open, 'xs hov') + ib(`data-pw-row-more="${esc(x.uid)}" aria-haspopup="menu"`, 'More for ' + x.title, P.more, 'xs hov')}</span>${stc}${dtc}${tl}</div>`
238
+ // subtasks (WorkSubtasksDS): indent one step per level, a parent's fold and count; a Jira row's key chip and the epic check's dot (WorkJiraDS)
239
+ const chev = x.kids ? `<button type="button" class="pw-chev" data-pw-sub="${esc(x.uid)}" aria-expanded="${!!x.open}" aria-label="${esc((x.open ? 'Fold ' : 'Open ') + x.title)}">${SVG(x.open ? P.down : P.right, 13)}</button>` : '';
240
+ const more2 = (x.kids ? `<small class="pw-cnt">${esc(x.count)}</small>` : '') + PD.keyChip(x) + PD.epicDot(x, W.epics || []);
241
+ return `<div class="pw-tr pw-kr${x.done ? ' done' : ''}${x.lit ? ' lit' : ''}${x.kids ? ' par' : ''}${RSEL.has(String(x.uid)) ? ' sel' : ''}" role="row" data-pw-row="${esc(x.uid)}" data-pw-sec="${esc(x.sec)}"${x.depth ? ` style="--pw-d:${x.depth}"` : ''}><span class="pw-it">${chev}<i class="pw-bul${x.ms ? ' ms' : ''}" aria-hidden="true"></i>${title}${more2}${RO ? '' : ib(`data-pw-open="${esc(x.uid)}"`, 'Open the task', P.open, 'xs hov') + ib(`data-pw-row-more="${esc(x.uid)}" aria-haspopup="menu"`, 'More for ' + x.title, P.more, 'xs hov')}</span>${stc}${dtc}${tl}</div>`
228
242
  + (s ? `<div class="pw-tr pw-sugrow" role="row"><span class="pw-it">${sugLine(s, true)}</span></div>` : '');
229
243
  }
230
244
  function breakdownHtml(W, C, mode, full, S) {
@@ -287,8 +301,9 @@ const keyOf = (v, o) => String((o && o.id) || (v && (v.id || v.key)) || '');
287
301
  function model(r, v, o) {
288
302
  const id = keyOf(v, o), S = stOf(id), it = ITEMS.get(id);
289
303
  const g = o.goal || goalOf(o.ws, o.board, r.anchor || v.anchor);
290
- const W = M.workOf(r, v, { ...o, goal: M.idShaped(g) ? '' : g, product: productName(o.product, o.ws), art: artOf(id, o.ws), open: S.open, shut: S.shut, moreOpen: S.moreOpen, farOpen: S.farOpen, focus: S.focus, mode: store.get(SPAN, 'full'), items: it || [], dropped: dropped() });
304
+ const W = M.workOf(r, v, { ...o, goal: M.idShaped(g) ? '' : g, product: productName(o.product, o.ws), art: artOf(id, o.ws), open: S.open, shut: S.shut, moreOpen: S.moreOpen, farOpen: S.farOpen, focus: S.focus, subOpen: S.subOpen, subShut: S.subShut, mode: store.get(SPAN, 'full'), items: it || [], dropped: dropped() });
291
305
  const mk = M.marksOf(W.span, W.today); W.tx = mk.today;
306
+ W.epics = (r.epics || []).filter(Boolean); RSEL = S.sel; // the epic check and the picked rows, for the Gantt rows (initiative work-subtasks)
292
307
  return { W, S, id };
293
308
  }
294
309
  export function html(r, v, o = {}) {
@@ -312,15 +327,39 @@ function stagesOf(r, v, o, S) {
312
327
  }
313
328
  function dsHtml(r, v, o, W, S, C, mode) {
314
329
  const id = keyOf(v, o), view = store.get(VIEW, 'list') === 'gantt' ? 'gantt' : 'list';
315
- const st = stagesOf(r, v, { ...o, today: W.today, focus: S.focus }, S);
330
+ const st = stagesOf(r, v, { ...o, today: W.today, focus: S.focus, subOpen: S.subOpen, subShut: S.subShut }, S);
331
+ // the epic check (WorkJiraDS): the initiative's epics, the ✦ fix unless the PM said no to it; ticking a parent asks once
332
+ const epics = (r.epics || []).filter(Boolean), fix = dropped().has('epic:' + id) ? null : WT.epicFix(st, epics);
333
+ const askRow = S.tickAsk ? st.find((x) => x.uid === S.tickAsk) : null, ask = askRow ? { x: askRow, n: openUnder(stagesOf(r, v, { ...o, today: W.today, subAll: true }), askRow.uid).length } : null;
334
+ const head = (vw) => PD.wbsHead(vw, epics[0] || '', epics[0] ? jiraUrlOf(st, epics[0]) : '');
316
335
  const wbs = view === 'gantt'
317
- ? breakdownHtml(W, C, mode, false, S).replace('<h3>Work breakdown</h3>', PD.wbsHead('gantt')).replace('class="pw-sec"', 'class="pw-sec pm-block pwd-blk pwd-wbs"')
318
- : `<section class="pm-block pwd-blk pwd-wbs" aria-label="Work breakdown">${PD.wbsHead('list')}${PD.listHtml(st, W, { looseN: W.looseN })}</section>`;
336
+ ? breakdownHtml(W, C, mode, false, S).replace('<h3>Work breakdown</h3>', head('gantt') + (S.sel.size ? SEL.barHtml(S.sel.size) : '')).replace('class="pw-sec"', 'class="pw-sec pm-block pwd-blk pwd-wbs"')
337
+ : `<section class="pm-block pwd-blk pwd-wbs" aria-label="Work breakdown">${S.sel.size ? '' : head('list')}${PD.listHtml(st, W, { looseN: W.looseN, epics, fix, ask, sel: S.sel, nested: st.some((x) => x.kids) })}</section>`;
319
338
  const mg = mergeOf(W.artefacts), merge = mg ? `<div class="pw-sugs pw-amg" role="list" aria-label="PMOS suggests">${sugLine({ id: mg.id, say: mg.say, merge: mg })}</div>` : '';
320
339
  return `<div class="pw pwd">${'<div class="pwd-main">'}${PD.standsHtml(W, r)}${PD.stagesHtml(st, W)}${wbs}</div>`
321
340
  + `<aside class="pwd-side">${PD.caseHtml(W, { oid: id, dropped: dropped() })}${PD.artsHtml(W.artefacts, { merge })}</aside></div>`;
322
341
  }
323
342
 
343
+ /** The open rows under a parent, at any depth (a parent ticked asks to tick them too). */
344
+ /** A tick on a parent with open subtasks: ask once (true), else write the tick (false). */
345
+ function askKids(c, x, W, S, uid) {
346
+ if (S.tickAsk === uid) return false;
347
+ const kids = openUnder(stagesOf(c.r, c.v, { ...(x.o() || {}), today: W.today, subAll: true }), uid);
348
+ if (!kids.length) return false;
349
+ S.tickAsk = uid; return true;
350
+ }
351
+ function openUnder(rows, uid) {
352
+ const out = [], kids = new Map();
353
+ for (const x of rows || []) if (x.kind === 'task' && x.up) { if (!kids.has(x.up)) kids.set(x.up, []); kids.get(x.up).push(x); }
354
+ const walk = (u) => { for (const k of kids.get(u) || []) { if (!k.done && !k.jira) out.push(k); walk(k.uid); } };
355
+ walk(uid);
356
+ return out;
357
+ }
358
+ /** A Jira link for a key, from any row that carries a link to the same site. */
359
+ function jiraUrlOf(rows, key) {
360
+ const r = (rows || []).find((x) => x && x.jurl && /\/browse\//.test(x.jurl));
361
+ return r ? r.jurl.replace(/\/browse\/[^/?#]+/, '/browse/' + key) : '';
362
+ }
324
363
  /* ── a phone (board Ph2_init; build brief nav-structure/phone/build-brief-v2.md item 8): the popup's content in a phone layout. No cards and
325
364
  * no table: the stage and its days over, the gate line, ✦ Overview with the lines that are written and one proposal for the ones that are not,
326
365
  * the status line and PMOS's proposals, the Work breakdown as rows with a status dot (grey done, blue in progress, an empty ring to do), the
@@ -496,6 +535,13 @@ export function wire(body, h0, x0) {
496
535
  body.addEventListener('scroll', () => { if (!body.querySelector(':scope > .pw, .pw:not(.pw-sp)')) return; const c = cur(); if (c) c.S.top = body.scrollTop; }, { passive: true });
497
536
  body.addEventListener('click', async (e) => {
498
537
  if (!live(e)) return;
538
+ // select several rows (WorkBulkDS): Cmd or Ctrl-click adds one, Shift-click a range; with rows picked, a click adds or takes out one
539
+ { const rw = e.target.closest('[data-pw-row]'), c0 = rw && !e.target.closest('a, input, textarea, [data-pw-tick], [data-pw-sub], [data-pw-row-more], .acts') ? cur() : null;
540
+ if (rw && c0 && !RO && (e.shiftKey || e.metaKey || e.ctrlKey || c0.S.sel.size)) {
541
+ const order = [...body.querySelectorAll('[data-pw-row]')].map((el) => el.dataset.pwRow);
542
+ const pk = SEL.pick(c0.S.sel, order, rw.dataset.pwRow, { shift: e.shiftKey, meta: e.metaKey || e.ctrlKey, anchor: c0.S.anchor });
543
+ if (pk) { e.preventDefault(); c0.S.sel = pk.sel; c0.S.anchor = pk.anchor; redraw(); return; }
544
+ } }
499
545
  const b = e.target.closest('button, [data-pw-line]');
500
546
  // a List row (work-ds-popup): a press on the rest of the row opens the task
501
547
  if (!b) { const li = e.target.closest('[data-pwli]'); if (li && !e.target.closest('input, textarea')) { const c0 = cur(); if (c0) openSmall(li.dataset.pwli, c0, body.__pwh, body.__pwx, body); } return; }
@@ -529,7 +575,19 @@ export function wire(body, h0, x0) {
529
575
  if (d.pwVer) { if (ARTOPEN.has(d.pwVer)) ARTOPEN.delete(d.pwVer); else ARTOPEN.add(d.pwVer); redraw(); return; }
530
576
  if (d.pwRowMore) { rowMenu(b, d.pwRowMore, c, h, body); return; }
531
577
  // quick edit in the row (work-ds-quick-edit, WorkStatesDS 1 and 3): the tick, Who and Stage
532
- if (d.pwTick) { b.disabled = true; if (h.status) await h.status(d.pwTick, 'Done'); return; }
578
+ // a parent ticked asks once whether to tick its open subtasks too (WorkSubtasksDS)
579
+ // ticking a parent with open subtasks asks once (WorkSubtasksDS); otherwise the tick writes as before
580
+ if (d.pwTick) { if (askKids(c, x, W, S, d.pwTick)) return redraw(); b.disabled = true; S.tickAsk = ''; if (h.status) await h.status(d.pwTick, 'Done'); return; }
581
+ if (d.pwTickAll) {
582
+ const all = stagesOf(c.r, c.v, { ...(x.o() || {}), today: W.today, subAll: true }), row = all.find((q) => q.uid === d.pwTickAll);
583
+ const ids = openUnder(all, d.pwTickAll).map((q) => q.uid).concat(row && !row.jira && !row.done ? [row.uid] : []);
584
+ S.tickAsk = ''; await runBulk(ids, 'done', null, c, h, x); return;
585
+ }
586
+ if ('pwTickNo' in d) { const u = S.tickAsk; S.tickAsk = ''; redraw(); if (u && h.status) await h.status(u, 'Done'); return; }
587
+ if (d.pwSub) { const u = d.pwSub, open = b.getAttribute('aria-expanded') === 'true'; S.subOpen.delete(u); S.subShut.delete(u); (open ? S.subShut : S.subOpen).add(u); redraw(); return; }
588
+ if ('pwEpicFix' in d) { b.disabled = true; await epicFix(c, h, x); return; }
589
+ if ('pwEpicDrop' in d) { const dd = dropped(); dd.add('epic:' + c.id); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
590
+ if (d.wsOp) { await bulkPress(b, d.wsOp, c, h, x); return; }
533
591
  if (d.pwWho) { whoMenu(b, d.pwWho, c, h, x); return; }
534
592
  if (d.pwStage) { stageMenu(b, d.pwStage, c, h, x); return; }
535
593
  if ('pwAddty' in d) { S.msAdd = !S.msAdd; const f = b.closest('.pw-add'), k = f && f.querySelector('[data-pw-add]') && f.querySelector('[data-pw-add]').dataset.pwAdd; redraw(); if (k != null) setTimeout(() => { const i = body.querySelector(`[data-pw-add="${window.CSS.escape(k)}"]`); if (i) i.focus(); }, 0); return; }
@@ -547,10 +605,14 @@ export function wire(body, h0, x0) {
547
605
  body.addEventListener('keydown', async (e) => {
548
606
  if (!live(e)) return;
549
607
  const t = e.target, h = body.__pwh;
608
+ if (e.key === 'Escape') { const c0 = cur(); if (c0 && (c0.S.sel.size || c0.S.tickAsk)) { e.preventDefault(); c0.S.sel.clear(); c0.S.tickAsk = ''; redraw(); return; } }
550
609
  if (t.matches && t.matches('[data-pw-line]') && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); t.click(); return; }
551
610
  // the List's one capture Input (work-ds-popup): the task goes to the stage it names ("… in Plan"), else the stage in progress
552
611
  if (t.matches && t.matches('[data-pw-cap]') && e.key === 'Enter') {
553
612
  e.preventDefault(); const v0 = t.value.trim(), c = cur(); if (!v0 || !h.addTask || !c) return;
613
+ // "under Batch 2: TM web" adds a subtask (WorkSubtasksDS): it takes its parent's stage
614
+ const all = stagesOf(c.r, c.v, { ...(body.__pwx.o() || {}), today: c.W.today, subAll: true }), un = WT.parseUnder(v0, all);
615
+ if (un) { await addUnder(un, all, c, h, body.__pwx); setTimeout(() => { const f = body.querySelector('[data-pw-cap]'); if (f) { f.value = ''; f.focus(); } }, 0); return; }
554
616
  const ms = /^◇\s*/.test(v0), k = PD.stageKeyOf(v0.replace(/^◇\s*/, ''), stagesOf(c.r, c.v, { ...(body.__pwx.o() || {}), today: c.W.today }));
555
617
  if (!k || !k.title) return;
556
618
  await h.addTask(k.title, t, { section: k.key, name: k.name, ...(ms ? { milestone: true } : {}) });
@@ -726,8 +788,13 @@ function rowMenu(btn, uid, c, h, body) {
726
788
  const row = c.W.rows.find((x) => x.uid === uid) || {};
727
789
  openPop(btn, 'pw-rowm', `<button type="button" class="hi-mi" role="menuitem" data-k="status">${SVG(P.box, 14, 2)} Status: ${esc(row.status || 'To do')}</button>`
728
790
  + `<button type="button" class="hi-mi" role="menuitem" data-k="kind">${SVG(row.ms ? P.box : P.dia, 14, 2)} ${row.ms ? 'Make it a task' : 'Make it a milestone'}</button>`
729
- + `<button type="button" class="hi-mi" role="menuitem" data-k="open">${SVG(P.open, 14)} Open the task</button>` + jiraNote(row), (b) => {
791
+ + `<button type="button" class="hi-mi" role="menuitem" data-k="open">${SVG(P.open, 14)} Open the task</button>`
792
+ // subtasks (WorkSubtasksDS): make it a subtask of another task, or move it out of its parent
793
+ + (row.jsub ? '' : `<button type="button" class="hi-mi" role="menuitem" data-k="under" aria-haspopup="menu">${SVG(P.right, 14)} Make subtask of…</button>`)
794
+ + (row.up && !row.jsub ? `<button type="button" class="hi-mi" role="menuitem" data-k="out">${SVG(P.show, 14)} Move out of ${esc(((c.W.rows.find((q) => q.uid === row.up) || {}).title) || 'its parent')}</button>` : '') + jiraNote(row), (b) => {
730
795
  const k = b.dataset.k;
796
+ if (k === 'under') { parentMenu(btn, [uid], c, h, body.__pwx); return; }
797
+ if (k === 'out') { closePop(); runBulk([uid], 'parent', '', c, h, body.__pwx); return; }
731
798
  // Status opens its own list (and its "when did this happen" line) in place of this menu
732
799
  if (k === 'status') { statusMenu(btn, uid, h, c); return; }
733
800
  closePop();
@@ -735,6 +802,102 @@ function rowMenu(btn, uid, c, h, body) {
735
802
  else if (k === 'open') openSmall(uid, c, h, body.__pwx, body);
736
803
  }, { menu: true, label: 'Task' });
737
804
  }
805
+ /* ── subtasks and the bulk move (initiative work-subtasks; WorkSubtasksDS, WorkBulkDS) ── */
806
+ const atOf = (h, x) => { const o = (x && x.o && x.o()) || {}, w = h.where ? h.where() : {}; return { ws: w.ws || o.ws, board: w.board || o.board, ini: o.id }; };
807
+ /** One bulk write (POST /api/boards/tasks/bulk) with one Undo; the picked rows clear. */
808
+ async function runBulk(ids, op, value, c, h, x, label) {
809
+ const at = atOf(h, x);
810
+ if (c && c.S) { c.S.sel.clear(); c.S.anchor = ''; }
811
+ await SEL.bulk(pmPost, { ws: at.ws, board: at.board }, ids, op, value, { say: (m, u) => (u ? undoToast(m, u) : h.toast ? h.toast(m) : undoToast(m)), reload: async () => { if (h.reload) await h.reload(); else if (h.redraw) h.redraw(); } }, label);
812
+ }
813
+ /** The parents a task can go under: the other tasks of this work, not the picked ones and not under them. "A new parent…" and the top level. */
814
+ function parentMenu(btn, ids, c, h, x) {
815
+ const all = stagesOf(c.r, c.v, { ...((x && x.o && x.o()) || {}), today: c.W.today, subAll: true }).filter((r) => r.kind === 'task' && !r.jsub);
816
+ const pick = new Set(ids), under = new Set();
817
+ const kids = new Map(); for (const r of all) if (r.up) { if (!kids.has(r.up)) kids.set(r.up, []); kids.get(r.up).push(r.uid); }
818
+ const walk = (u) => { for (const k of kids.get(u) || []) { under.add(k); walk(k); } };
819
+ for (const u of ids) walk(u);
820
+ const L = all.filter((r) => !pick.has(r.uid) && !under.has(r.uid)).slice(0, 60);
821
+ const n = ids.length;
822
+ openPop(btn, 'pw-under', `<p class="hi-small">${esc('Move ' + (n === 1 ? 'it' : n + ' tasks') + ' under')}</p>`
823
+ + `<button type="button" class="hi-mi" role="menuitem" data-new>${SVG(P.plus, 14)} A new parent…</button>`
824
+ + L.map((r, i) => `<button type="button" class="hi-mi" role="menuitem" data-i="${i}" style="padding-left:${10 + Math.min(r.depth || 0, 3) * 14}px">${esc(r.title)}${r.kids ? ` <span class="hi-small">${esc(String(r.kids))}</span>` : ''}</button>`).join('')
825
+ + `<button type="button" class="hi-mi" role="menuitem" data-top>Top level (no parent)</button>`, async (b) => {
826
+ if ('new' in b.dataset) { newParent(btn, ids, all, c, h, x); return; }
827
+ closePop();
828
+ if ('top' in b.dataset) { await runBulk(ids, 'parent', '', c, h, x, 'the top level'); return; }
829
+ const r = L[+b.dataset.i]; if (r) await runBulk(ids, 'parent', r.uid, c, h, x, r.title);
830
+ }, { menu: true, label: 'Under a parent' });
831
+ }
832
+ /** A new parent: its name, then it is made in the stage of the first picked task and the picked tasks move under it. */
833
+ function newParent(btn, ids, all, c, h, x) {
834
+ openPop(btn, 'pw-newp', `<label class="hi-small" for="pw-newp-in">The new parent's name</label><input id="pw-newp-in" class="pm-input" data-newp maxlength="200" autocomplete="off" placeholder="Batch 2 · go-live 1 Dec"><div class="pm-row"><button type="button" class="pm-btn primary" data-go aria-label="Make it and move the tasks under it" title="Make it">${SVG(P.plus, 14)}</button></div>`, async (b) => {
835
+ if (!('go' in b.dataset)) return;
836
+ const inp = document.querySelector('[data-newp]'), name = inp ? inp.value.trim() : '';
837
+ if (!name) return;
838
+ closePop();
839
+ const at = atOf(h, x), first = all.find((r) => r.uid === ids[0]);
840
+ const r = await pmPost('/api/boards/tasks/add', { ws: at.ws, board: at.board, initiative: at.ini, title: name, ...(first && first.sec ? { section: first.sec } : {}) }).catch(() => null);
841
+ if (!r || r.ok === false || !r.item) { (h.toast || undoToast)((r && r.error) || 'The parent was not made.'); return; }
842
+ await runBulk(ids, 'parent', r.item.uid, c, h, x, name);
843
+ }, { label: 'A new parent', focus: '[data-newp]' });
844
+ }
845
+ /** "under Batch 2: TM web": a new task under that parent, in its stage. Undo takes it back. */
846
+ async function addUnder(un, all, c, h, x) {
847
+ const at = atOf(h, x), p = all.find((r) => r.uid === un.parent);
848
+ const r = await pmPost('/api/boards/tasks/add', { ws: at.ws, board: at.board, initiative: at.ini, title: un.title, parent: un.parent, ...(p && p.sec ? { section: p.sec } : {}) }).catch(() => null);
849
+ if (!r || r.ok === false || !r.item) { (h.toast || undoToast)((r && r.error) || 'The subtask was not added.'); return; }
850
+ c.S.subOpen.add(un.parent); c.S.subShut.delete(un.parent);
851
+ undoToast(`Added under ${un.parentTitle}: ${un.title}.`, async () => { await pmPost('/api/boards/tasks/undo-add', { ws: at.ws, board: at.board, task: r.item.uid }).catch(() => null); if (h.reload) await h.reload(); });
852
+ if (h.reload) await h.reload();
853
+ }
854
+ /** The bar's presses (WorkBulkDS): under a parent, stage, who, move dates, done, clear. */
855
+ async function bulkPress(btn, op, c, h, x) {
856
+ const S = c.S, ids = [...S.sel];
857
+ if (op === 'clear') { S.sel.clear(); S.anchor = ''; if (h.redraw) h.redraw(); return; }
858
+ if (!ids.length) return;
859
+ if (op === 'done') { await runBulk(ids, 'done', null, c, h, x); return; }
860
+ if (op === 'parent') { parentMenu(btn, ids, c, h, x); return; }
861
+ if (op === 'section') {
862
+ const L = PD.stageList(stagesOf(c.r, c.v, { ...((x && x.o && x.o()) || {}), today: c.W.today }), '');
863
+ openPop(btn, 'pw-bstage', L.map((s2, i) => `<button type="button" class="hi-mi" role="menuitem" data-i="${i}">${esc(s2.name)}</button>`).join('') || '<p class="hi-small">This work has no stages.</p>', async (b) => {
864
+ const s2 = L[+b.dataset.i]; closePop(); if (s2) await runBulk(ids, 'section', s2.key, c, h, x, s2.name);
865
+ }, { menu: true, label: 'Stage' });
866
+ return;
867
+ }
868
+ if (op === 'owner') {
869
+ const L = PD.whoOf(c.W.rows, '').filter((p) => !p.pmos);
870
+ openPop(btn, 'pw-bwho', L.map((p, i) => `<button type="button" class="hi-mi" role="menuitem" data-i="${i}">${SVG(PD.I.who, 14, 2)} ${esc(p.label)}</button>`).join(''), async (b) => {
871
+ const p = L[+b.dataset.i]; closePop(); if (p) await runBulk(ids, 'owner', p.k === 'You' ? '' : p.k, c, h, x, p.label);
872
+ }, { menu: true, label: 'Who' });
873
+ return;
874
+ }
875
+ if (op === 'shift') {
876
+ const Q = [[-7, '1 week earlier'], [-1, '1 day earlier'], [1, '1 day later'], [7, '1 week later']];
877
+ openPop(btn, 'pw-bshift', Q.map(([n, l]) => `<button type="button" class="hi-mi" role="menuitem" data-n="${n}">${esc(l)}</button>`).join('')
878
+ + `<label class="hi-small" for="pw-bshift-in">Or a number of days (+3, -2, 1w)</label><input id="pw-bshift-in" class="pm-input" data-bshift maxlength="12" autocomplete="off"><div class="pm-row"><button type="button" class="pm-btn primary" data-go aria-label="Move the dates" title="Move the dates">${SVG(P.check, 14)}</button></div>`, async (b) => {
879
+ let n = b.dataset.n != null ? +b.dataset.n : null;
880
+ if ('go' in b.dataset) { const i = document.querySelector('[data-bshift]'); n = SEL.shiftOf(i ? i.value : ''); if (n == null) return; }
881
+ if (n == null) return;
882
+ closePop(); await runBulk(ids, 'shift', n, c, h, x);
883
+ }, { label: 'Move dates' });
884
+ }
885
+ }
886
+ /** The epic check's ✦ fix (WorkJiraDS): every flagged ticket goes under the initiative's epic; Undo withdraws what Jira has not done yet. */
887
+ async function epicFix(c, h, x) {
888
+ const o = (x && x.o && x.o()) || {}, at = atOf(h, x), epics = (c.r.epics || []).filter(Boolean);
889
+ const st = stagesOf(c.r, c.v, { ...o, today: c.W.today, subAll: true }), fx = WT.epicFix(st, epics);
890
+ if (!fx) return;
891
+ const tickets = fx.keys.map((k) => { const r = st.find((q) => WT.keyOf(q) === k) || {}; return { key: k, from: r.jepic || '', who: r.jassignee || '' }; });
892
+ const r = await pmPost('/api/jira-epics/fix', { ws: at.ws, ini: at.ini, epic: fx.epic, tickets }).catch(() => null);
893
+ const say = (m, u) => (u ? undoToast(m, u) : h.toast ? h.toast(m) : undoToast(m));
894
+ if (!r || r.ok === false) { say((r && r.error) || 'The fix was not asked.'); if (h.redraw) h.redraw(); return; }
895
+ const dd = dropped(); dd.add('epic:' + c.id); store.set(DROP, [...dd].slice(-200));
896
+ const words = [r.direct.length ? (r.direct.length === 1 ? r.direct[0] + ' moves' : r.direct.length + ' tickets move') + ' under ' + fx.epic + ' in Jira now.' : '',
897
+ r.draft.length ? (r.draft.length === 1 ? r.draft[0].key + ' is' : r.draft.length + ' tickets are') + ' in today\'s Jira draft for ' + [...new Set(r.draft.map((q) => q.who || 'their owner'))].join(', ') + '.' : ''].filter(Boolean).join(' ');
898
+ say(words, async () => { const u = await pmPost('/api/jira-epics/undo', { ws: at.ws, ids: r.ids }).catch(() => null); dd.delete('epic:' + c.id); store.set(DROP, [...dd].slice(-200)); say(u && u.kept && u.kept.length ? 'Put back, except ' + u.kept.join(', ') + ': Jira already has it.' : 'Put back.'); if (h.redraw) h.redraw(); });
899
+ if (h.redraw) h.redraw();
900
+ }
738
901
  /* Who (WorkStatesDS 1): You, the people who own this initiative's tasks, and "PMOS does it". A name writes the owner (Undo puts the old one
739
902
  * back, POST /api/boards/tasks/edit with `from`); PMOS does it gives the task to PMOS (POST /api/backlog/give; Undo is /api/backlog/stop). */
740
903
  function whoMenu(btn, uid, c, h, x) {
@@ -143,7 +143,18 @@ function rowOf(k0, today, J = null) {
143
143
  // planned versus actual (batch 11 item 8, pm/ini-versions.js): the compared version's days where they differ, ⊕ added after it, a draft's task
144
144
  cmp: k.cmp || null, added: !!k.added, dr: !!k.draft,
145
145
  // jkey: the key of the Jira ticket the task is linked to, only when PMOS read that ticket; jst: its own Jira status (it owns the status)
146
- jkey: J ? J.key : '', jst: J ? String(J.raw || J.status || '') : '', jmove: J && J.move ? J.move : null, _k: k0, _t: today }; // jmove: a move asked in PMOS (lib/jira-moves.js)
146
+ jkey: J ? J.key : '', jst: J ? String(J.raw || J.status || '') : '', jmove: J && J.move ? J.move : null, _k: k0, _t: today, // jmove: a move asked in PMOS (lib/jira-moves.js)
147
+ // subtasks and the Jira chip and epic check (initiative work-subtasks): the parent task; the ticket's link, epic (undefined: not read),
148
+ // assignee, type and sub-tasks, from the sprint read (J) or the read of the ticket the task names (k0.jira, lib/board-premium.js jiraOf)
149
+ parent: k0.parent || '', ...jiraFields(J, k0.jira) };
150
+ }
151
+ function jiraFields(J, R) {
152
+ if (!J && !R) return {};
153
+ const pick = (k) => (J && J[k] != null && J[k] !== '' ? J[k] : R && R[k] != null ? R[k] : '');
154
+ const read = (J && 'epic' in J) || (R && 'epic' in R);
155
+ // ckey: the key the row's chip shows: the linked ticket's, else the one the task names that PMOS read (the task keeps its own status then)
156
+ return { ckey: (J && J.key) || (R && R.key) || '', jurl: pick('url'), jassignee: pick('assignee'), jtype: pick('type'), ...(read ? { jepic: pick('epic') || '', jepicName: pick('epicName') } : {}),
157
+ ...(J && J.sub || (R && R.parentTicket) ? { jsubOf: (J && J.parentTicket) || R.parentTicket || '' } : {}), jsubs: (R && R.subs) || (J && J.subs) || [] };
147
158
  }
148
159
  /** The Jira keys a task's title holds ("MSD-4376 Navigation tabs" → ['MSD-4376']). A task whose title names a ticket PMOS read IS that ticket
149
160
  * (linkOf): it shows the Jira mark and the key once, its status is Jira's, and the ticket's own row does not show again (batch 11 item 4,
@@ -29,6 +29,7 @@
29
29
 
30
30
  import { gapsOf } from './cozy-bar.js';
31
31
  import { provenStatus, NO_SIGNAL } from './status-proof.js';
32
+ import * as WT from './work-tree.js'; // subtasks: nesting and the roll-up (initiative work-subtasks)
32
33
  const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
33
34
  const DAY = 864e5;
34
35
  const day = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
@@ -295,7 +296,24 @@ function taskRow(x, t) {
295
296
  const dl = x.end ? dateLate(x.end, t, !x.closed) : { text: x.start ? 'from ' + dayText(x.start, t) : '', late: false };
296
297
  const st = taskStatus(x);
297
298
  return { kind: 'task', uid: x.uid, title: x.title, who: x.owner || '', status: st, date: dl.text, late: dl.late, start: x.start || '', end: x.end || '', since: x.since || '', done: !!x.closed, ms: !!x.ms, jira: !!x.jkey, canCheck: !!x.canCheck,
298
- prog: /progress|review/i.test(st), wont: !!x.wont || st === "Won't do" };
299
+ prog: /progress|review/i.test(st), wont: !!x.wont || st === "Won't do",
300
+ // subtasks and Jira (initiative work-subtasks): the parent, the chip's key and link, the epic as read, the assignee, a Jira sub-task
301
+ parent: x.parent || '', ckey: x.ckey || x.jkey || '', jurl: x.jurl || '', ...(x.jepic !== undefined ? { jepic: x.jepic, jepicName: x.jepicName || '' } : {}), jassignee: x.jassignee || '', jtype: x.jtype || '',
302
+ ...(x.jsub ? { jsub: true } : {}), ...(x.jsubOf ? { jsubOf: x.jsubOf } : {}) };
303
+ }
304
+ /** The tasks of every stage, nested (initiative work-subtasks): the read Jira sub-tasks join as rows under their ticket, and a task that names
305
+ * a sub-task's key with no parent of its own sits under its ticket's row. → { T: Map uid → node, isChild(x), rx(x) (a parent with its roll-up) } */
306
+ function treeOf(secs) {
307
+ const all0 = [];
308
+ for (const s of secs) all0.push(...tasksOf(s), ...(s.done || []));
309
+ const keyed = new Map(); for (const x of all0) { const k = x.ckey || x.jkey; if (k && !keyed.has(k)) keyed.set(k, x); }
310
+ const extra = [];
311
+ for (const x of all0) for (const sr of WT.subRows(x)) if (!keyed.has(sr.uid)) { keyed.set(sr.uid, sr); extra.push(sr); }
312
+ const T = WT.nest(all0.map((x) => (!x.parent && x.jsubOf && keyed.has(x.jsubOf) && keyed.get(x.jsubOf) !== x ? { ...x, parent: keyed.get(x.jsubOf).uid } : x)).concat(extra));
313
+ const node = (x) => T.get(String(x.uid));
314
+ const isChild = (x) => { const n = node(x); return !!(n && n.up); };
315
+ const rx = (x) => { const n = node(x); if (!n || !n.kids.length) return x; const r = WT.rollup(n); return { ...x, start: r.start, end: r.end, closed: r.done, status: r.done ? 'Done' : x.status === 'Done' ? 'In progress' : x.status }; };
316
+ return { T, node, isChild, rx };
299
317
  }
300
318
  /** o.focus: the task a Today row opened (round 3 item 11b): its stage, its done fold and the far stages open, and its row lit. */
301
319
  const holds = (list, f) => !!f && (list || []).some((x) => x && String(x.uid) === f);
@@ -316,11 +334,26 @@ export function breakdownOf(r, v, o = {}) {
316
334
  // offers to put them in the stage in progress, the one stage PMOS can name for each
317
335
  const looseUnder = null;
318
336
  const loose = [];
337
+ const TR = treeOf(secs), subOpen = o.subOpen || new Set(), subShut = o.subShut || new Set();
338
+ // one row and, when it is open, its subtasks under it by date (initiative work-subtasks); depth caps the indent at INDENT_MAX
339
+ const emit = (x, d, sec) => {
340
+ const n = TR.node(x), r = n && n.kids.length ? WT.rollup(n) : null;
341
+ const hasF = !!(f && n && WT.under(n).some((y) => String(y.uid) === f));
342
+ const open = r ? (hasF || o.subAll ? true : subShut.has(String(x.uid)) ? false : subOpen.has(String(x.uid)) ? true : r.kids <= WT.FOLD_KIDS) : false;
343
+ rows.push(lit({ ...x, sec, depth: Math.min(d, WT.INDENT_MAX), ...(n && n.up ? { up: String(n.up.x.uid) } : {}), ...(r ? { kids: r.kids, nLeaf: r.n, nDone: r.nDone, count: r.nDone + ' of ' + r.n + ' done', open } : {}) }));
344
+ if (!r || !open) return;
345
+ const kids = n.kids.map((k) => taskRow(TR.rx(k.x), t)).sort((a, b) => (a.start || a.end || '9999').localeCompare(b.start || b.end || '9999') || (a.end || '9999').localeCompare(b.end || '9999'));
346
+ for (const k of kids) emit(k, d + 1, sec);
347
+ };
319
348
  const stageRow = (s, i) => {
320
- const ts = (s.top || []).concat(...(s.groups || []).map((g) => g.rows || []));
349
+ // a child sits in its parent's stage: the stage holds its top-level tasks, and each counts as done when everything under it is done
350
+ const roots = (s.top || []).concat(...(s.groups || []).map((g) => g.rows || []), s.done || []).filter((x) => !TR.isChild(x)).map(TR.rx);
351
+ const ts = roots.filter((x) => !x.closed), sDone = roots.filter((x) => x.closed);
321
352
  const lz = looseUnder === s ? looseTs : [];
322
- const all = ts.concat(s.done || []);
323
- const nDone = (s.done || []).length, n = all.length;
353
+ const all = ts.concat(sDone);
354
+ const leaves = (x) => { const nd = TR.node(x); return nd && nd.kids.length ? WT.rollup(nd) : { n: 1, nDone: x.closed ? 1 : 0 }; };
355
+ const nDone = all.reduce((k, x) => k + leaves(x).nDone, 0), n = all.reduce((k, x) => k + leaves(x).n, 0);
356
+ const deep = all.concat(...all.map((x) => WT.under(TR.node(x))));
324
357
  const [ta, tb] = taskSpan(all);
325
358
  const rn = ran[i] || {};
326
359
  let a = '', b = '';
@@ -335,14 +368,14 @@ export function breakdownOf(r, v, o = {}) {
335
368
  const dl = b && (s.status === 'now' || s.status === 'next') ? dateLate(b, t, live || ts.some((x) => !x.closed)) : { text: b && s.status === 'done' ? '' : '', late: false };
336
369
  // a finished stage (every task done) folds until the PM opens it; the List opens every other stage with tasks
337
370
  const finished = n > 0 && nDone === n;
338
- const isOpen = holds(all, f) ? true : shut.has(s.key) ? false : open.has(s.key) ? true : !finished && (o.openAll || s.status === 'now');
371
+ const isOpen = holds(deep, f) ? true : shut.has(s.key) ? false : open.has(s.key) ? true : !finished && (o.openAll || s.status === 'now');
339
372
  // the count holds every task drawn under the stage: its own and the ones in no stage that sit under it (design check, 2026-11-19)
340
373
  const nAll = n + lz.length;
341
374
  const count = nAll ? (s.status === 'next' && !nDone ? plural(nAll, 'task', 'tasks') : nDone + ' of ' + nAll + ' done') : '';
342
375
  const has = n + lz.length > 0;
343
376
  // the bar's gap line and its ◇s (pm/cozy-bar.js stageBar): the stage's dated tasks, and its milestone tasks
344
377
  const gaps = a && b ? gapsOf(all.filter((x) => !x.wont).map((x) => [x.start || x.end, x.end || x.start]).filter(([p]) => p), a, b) : [];
345
- const marks = all.filter((x) => x.ms && !x.wont && x.end).map((x) => ({ uid: x.uid, title: x.title, end: x.end, done: !!x.closed, late: !!x.late && !x.closed }));
378
+ const marks = deep.filter((x) => x.ms && !x.wont && x.end).map((x) => ({ uid: x.uid, title: x.title, end: x.end, done: !!x.closed, late: !!x.late && !x.closed }));
346
379
  rows.push({ kind: 'stage', key: s.key, n: s.n, name: s.name, ms: !!s.ms, status: STATUS[s.status] || '', count, date: dl.text, late: dl.late, start: a, end: b, gaps, marks, tone: s.status === 'done' ? 'dn' : s.status === 'now' ? 'now' : '',
347
380
  done: s.status === 'done', open: (isOpen || lz.length > 0) && has, can: has, now: s.status === 'now', skip: s.status === 'skip' });
348
381
  if (!((isOpen || lz.length > 0) && has)) return;
@@ -356,7 +389,7 @@ export function breakdownOf(r, v, o = {}) {
356
389
  const keep = new Set(hot.concat(rest.slice(0, NEXT)));
357
390
  shown = all2.filter((x) => keep.has(x));
358
391
  }
359
- for (const x of shown) rows.push(lit({ ...x, sec: s.key }));
392
+ for (const x of shown) emit(x, 0, s.key);
360
393
  if (shown.length < all2.length) rows.push({ kind: 'more', key: s.key, n: all2.length - shown.length, label: plural(all2.length - shown.length, 'more task', 'more tasks') });
361
394
  for (const x of lz.slice().sort(urgent)) { rows.push(lit({ ...taskRow(x, t), sec: '', loose: s.key })); loose.push({ uid: x.uid, title: x.title, to: s.key, name: s.name }); }
362
395
  };
@@ -3,7 +3,7 @@
3
3
  * north-star, input or guardrail), what Claude drafted for this product (GET /api/metric-drafts, one ✓ to keep each), the key results grouped by
4
4
  * objective with the health budgets, then "Did it work?" (to judge and in their window; a drafted verdict with ✓ Keep and Undo, POST
5
5
  * /api/insights-records/verdict and /verdict-undo; decided ones fold). A key result with no reading is not a table row: it waits in "Waiting on a
6
- * source", one row per source (U3). ⋯ holds Reports and dashboards (the old Library, in a side panel) and Export CSV. The old ?tab=goals|outcomes|library links land on the matching section or panel; ?goal= and ?dash= still work.
6
+ * source", one row per source (U3). ⋯ holds Reports and dashboards (the old Library, in a side panel) and Export CSV. The old ?tab=goals|outcomes|library links land on the matching section or panel; ?goal= opens that goal. (No code reads ?dash=: a dashboard opens from the View chip.)
7
7
  * Before it, the premium Insights in the Agreed design's frames (initiative premium-agreed-design): AgInsGoals, AgInsPeriod,
8
8
  * AgInsNewGoal, AgInsNewDash, AgInsChart, AgInsOutcomes, AgInsVerdict, AgInsLibrary and AgInsPhone.
9
9
  *
@@ -0,0 +1,73 @@
1
+ /* pm/work-select.js — select several tasks and move them together (initiative work-subtasks, board WorkBulkDS on Exploring 3, page Work).
2
+ * One selection model and one bar for the four views that list tasks: the initiative popup's List and Gantt, Work › Backlog, This sprint.
3
+ *
4
+ * pick(sel, order, uid, m) → { sel: Set, anchor } PURE. m: { shift, meta, anchor, touch }
5
+ * Cmd or Ctrl-click (meta) adds or takes out one row; Shift-click adds the range from the last picked row;
6
+ * with rows already picked, a plain click (or a tap after a long press) adds or takes out one row.
7
+ * A plain click with nothing picked is not a selection: answers null, and the row opens as before.
8
+ * barHtml(n, o) → the bar that replaces the block's head while rows are picked: "N selected", then Under a parent, Stage,
9
+ * Who, Move dates, Done, and × (Esc does the same). o: { stage: false } leaves out what a view cannot do.
10
+ * shiftOf(text) → a whole number of days from "+3", "-7", "1w", "2 weeks", or null
11
+ * bulk(post, at, ids, op, value, h) → runs POST /api/boards/tasks/bulk for each board and offers one Undo (POST …/bulk-undo) for all of it.
12
+ * at: { ws, board } or a function uid → { ws, board, id }. h: { say(text, undo), reload() }
13
+ *
14
+ * The UI says PMOS, never Claude. Buttons are icons with aria-label where the design shows an icon. */
15
+ export const OPS = Object.freeze([['parent', 'Under a parent'], ['section', 'Stage'], ['owner', 'Who'], ['shift', 'Move dates'], ['done', 'Done']]);
16
+
17
+ export function pick(sel, order, uid, m = {}) {
18
+ const S = new Set(sel || []), u = String(uid);
19
+ if (m.shift && (m.anchor || S.size)) {
20
+ const L = (order || []).map(String), a = L.indexOf(String(m.anchor || [...S][S.size - 1])), b = L.indexOf(u);
21
+ if (a >= 0 && b >= 0) { for (let i = Math.min(a, b); i <= Math.max(a, b); i++) S.add(L[i]); return { sel: S, anchor: m.anchor || u }; }
22
+ }
23
+ if (m.meta || m.shift || m.touch || S.size) { if (S.has(u)) S.delete(u); else S.add(u); return { sel: S, anchor: u }; }
24
+ return null;
25
+ }
26
+
27
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
28
+ const X = '<svg class="pm-ic" aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>';
29
+ export function barHtml(n, o = {}) {
30
+ if (!n) return '';
31
+ const ops = OPS.filter(([k]) => o[k] !== false);
32
+ return `<div class="pm-row ws-bar" role="toolbar" aria-label="${esc(n + ' selected')}"><b class="ws-n">${esc(n)} selected</b>`
33
+ + ops.map(([k, l]) => `<button type="button" class="pm-btn${k === 'done' ? '' : ' outline'}" data-ws-op="${k}"${k === 'done' ? '' : ' aria-haspopup="menu"'}>${esc(l)}</button>`).join('')
34
+ + `<button type="button" class="pm-btn ws-x" data-ws-op="clear" aria-label="Clear the selection" title="Clear (Esc)">${X}</button></div>`;
35
+ }
36
+
37
+ export function shiftOf(text) {
38
+ const m = /^\s*([+-]?)\s*(\d{1,3})\s*(d|day|days|w|wk|week|weeks)?\s*$/i.exec(String(text || ''));
39
+ if (!m) return null;
40
+ const n = +m[2] * (/^w/i.test(m[3] || '') ? 7 : 1) * (m[1] === '-' ? -1 : 1);
41
+ return n && Math.abs(n) <= 730 ? n : null;
42
+ }
43
+
44
+ const WORDS = { parent: 'moved under', section: 'moved to', owner: 'given to', shift: 'moved by', done: 'marked done' };
45
+ /** One write per board, one Undo for all. → { moved, skipped } */
46
+ export async function bulk(post, at, ids, op, value, h = {}, label = '') {
47
+ const groups = new Map();
48
+ for (const u of ids) {
49
+ const p = typeof at === 'function' ? at(u) : { ...at, id: u };
50
+ if (!p) continue;
51
+ const k = p.ws + '\u0000' + p.board;
52
+ if (!groups.has(k)) groups.set(k, { ws: p.ws, board: p.board, ids: [] });
53
+ groups.get(k).ids.push(p.id);
54
+ }
55
+ const done = [], skipped = [];
56
+ for (const g of groups.values()) {
57
+ const r = await post('/api/boards/tasks/bulk', { ws: g.ws, board: g.board, tasks: g.ids, op, value }).catch(() => null);
58
+ if (r && r.ok !== false) { done.push({ ws: g.ws, board: g.board, undo: r.undo || [] }); skipped.push(...(r.skipped || [])); }
59
+ else skipped.push(...((r && r.skipped) || g.ids.map((id) => ({ task: id, why: (r && r.error) || 'not moved' }))));
60
+ }
61
+ const n = done.reduce((k, d) => k + d.undo.length, 0);
62
+ const what = op === 'shift' ? (value > 0 ? '+' : '') + value + (Math.abs(value) === 1 ? ' day' : ' days') : label || '';
63
+ const text = n ? `${n === 1 ? '1 task' : n + ' tasks'} ${WORDS[op]}${what ? ' ' + what : ''}.${skipped.length ? ' ' + skipped.length + ' not moved: ' + skipped[0].why + '.' : ''}`
64
+ : (skipped[0] && skipped[0].why ? 'Nothing moved: ' + skipped[0].why + '.' : 'Nothing moved.');
65
+ const undo = n ? async () => {
66
+ for (const d of done) await post('/api/boards/tasks/bulk-undo', { ws: d.ws, board: d.board, undo: d.undo }).catch(() => null);
67
+ if (h.say) h.say('Put back.');
68
+ if (h.reload) await h.reload();
69
+ } : null;
70
+ if (h.say) h.say(text, undo);
71
+ if (h.reload) await h.reload();
72
+ return { moved: n, skipped };
73
+ }
@@ -0,0 +1,111 @@
1
+ /* pm/work-tree.js — subtasks in a work breakdown (initiative work-subtasks; boards WorkSubtasksDS and WorkJiraDS on Exploring 3, page Work).
2
+ * Pure: no DOM, no reads. pm/pop-work-model.js nests the rows with it, pm/bd-pop-ds.js and pm/cozy-pop-work.js draw them.
3
+ *
4
+ * nest(rows) → Map uid → node { x, kids: [node], up: node | null } a row with a parent in the list sits under it; any depth.
5
+ * A parent that is not in the list, the row itself, or a loop leaves the row at the top level.
6
+ * rollup(node) → { start, end, n, nDone, done, kids } a parent has no date of its own: its start is the earliest start under
7
+ * it, its end the latest end, n and nDone count the tasks with no subtasks under it (the leaves), done when
8
+ * every leaf is done. A row with no subtasks answers its own.
9
+ * subRows(row) → the Jira sub-tasks of a ticket row as child rows (the read's sub-task list), each { uid: key, parent: row.uid }
10
+ * epicFlag(row, epics) → '' | 'none' | 'other' the epic check: a Jira ticket with no epic, or with one that is not one of the
11
+ * initiative's epics. A ticket whose epic PMOS has not read, a sub-task, and a PMOS-only task: ''.
12
+ * epicWhy(row, flag, epics) → the hover line of the red dot
13
+ * epicFix(rows, epics, me) → { say, why, direct: [key], draft: [{ key, who }], epic } | null the ✦ fix of every flagged ticket of an
14
+ * initiative: put it under the initiative's first epic. Tickets assigned to the PM (`me`) are direct; the
15
+ * rest go to the day's Jira draft for their owner.
16
+ * parseUnder(text, rows) → { parent, title } | null "under Batch 2: TM web" in the add box
17
+ * INDENT_MAX (3) · FOLD_KIDS (5): past three levels the indent stops growing; a parent with more than five subtasks folds by default. */
18
+ export const INDENT_MAX = 3;
19
+ export const FOLD_KIDS = 5;
20
+
21
+ export function nest(rows) {
22
+ const by = new Map();
23
+ for (const x of rows || []) if (x && x.uid != null && !by.has(String(x.uid))) by.set(String(x.uid), { x, kids: [], up: null });
24
+ for (const [uid, n] of by) {
25
+ const p = n.x.parent ? String(n.x.parent) : '';
26
+ if (!p || p === uid || !by.has(p)) continue;
27
+ // a loop (a sits under b, b under a) leaves the row at the top level
28
+ let q = by.get(p), loop = false;
29
+ for (let i = 0; q && i < 10000; i++) { if (q === n) { loop = true; break; } q = q.up; }
30
+ if (loop) continue;
31
+ n.up = by.get(p); n.up.kids.push(n);
32
+ }
33
+ return by;
34
+ }
35
+
36
+ const cache = new WeakMap();
37
+ export function rollup(node) {
38
+ if (!node) return null;
39
+ if (cache.has(node)) return cache.get(node);
40
+ let out;
41
+ if (!node.kids.length) {
42
+ const x = node.x, done = !!(x.closed || x.done);
43
+ out = { start: x.start || x.end || '', end: x.end || x.start || '', n: 1, nDone: done ? 1 : 0, done, kids: 0 };
44
+ } else {
45
+ let a = '', b = '', n = 0, nDone = 0;
46
+ for (const k of node.kids) {
47
+ const r = rollup(k);
48
+ if (r.start && (!a || r.start < a)) a = r.start;
49
+ if (r.end && (!b || r.end > b)) b = r.end;
50
+ n += r.n; nDone += r.nDone;
51
+ }
52
+ out = { start: a, end: b, n, nDone, done: n > 0 && nDone === n, kids: node.kids.length };
53
+ }
54
+ cache.set(node, out);
55
+ return out;
56
+ }
57
+ /** Every row under a node, depth first. */
58
+ export function under(node) { const out = []; for (const k of (node && node.kids) || []) { out.push(k.x); out.push(...under(k)); } return out; }
59
+
60
+ const isSubType = (t) => /sub-?task/i.test(String(t || ''));
61
+ const doneCat = (s) => s && (s.category === 'done' || /^(done|closed|resolved|released)$/i.test(String(s.status || '')));
62
+ export function subRows(row) {
63
+ return ((row && row.jsubs) || []).filter((s) => s && s.key).map((s) => ({ kind: 'task', uid: s.key, title: s.summary || s.key, parent: row.uid, jira: true, jkey: s.key, ckey: s.key, jsub: true,
64
+ jurl: row.jurl ? String(row.jurl).replace(/\/browse\/[^/?#]+/, '/browse/' + s.key) : '', closed: !!doneCat(s), done: !!doneCat(s), status: doneCat(s) ? 'Done' : /progress|review|doing/i.test(String(s.status || '')) ? 'In progress' : 'To do',
65
+ start: '', end: '', owner: '' }));
66
+ }
67
+
68
+ /** The Jira key a row's chip shows: the linked ticket's, else the one the task names that PMOS read. */
69
+ export const keyOf = (row) => (row && (row.ckey || row.jkey)) || '';
70
+ export function epicFlag(row, epics) {
71
+ if (!row || !keyOf(row) || row.jsub || row.jsubOf || isSubType(row.jtype)) return '';
72
+ if (row.jepic == null) return ''; // not read: PMOS says nothing it has not read
73
+ const E = (epics || []).map((k) => String(k).toUpperCase());
74
+ if (!row.jepic) return 'none';
75
+ return E.length && !E.includes(String(row.jepic).toUpperCase()) ? 'other' : '';
76
+ }
77
+ export function epicWhy(row, flag, epics) {
78
+ const mine = (epics || [])[0] || '';
79
+ if (flag === 'none') return keyOf(row) + ' has no epic in Jira' + (mine ? ', so it is not counted under this initiative\'s epic ' + mine + '.' : '.');
80
+ if (flag === 'other') return keyOf(row) + ' is under ' + row.jepic + (row.jepicName ? ' (' + row.jepicName + ')' : '') + ', not this initiative\'s epic ' + (mine || '') + '.';
81
+ return '';
82
+ }
83
+ const sameWho = (a, b) => !!a && !!b && String(a).trim().toLowerCase() === String(b).trim().toLowerCase();
84
+ export function epicFix(rows, epics, me) {
85
+ const epic = (epics || [])[0];
86
+ if (!epic) return null;
87
+ const hit = (rows || []).filter((x) => x && x.kind === 'task' && epicFlag(x, epics));
88
+ if (!hit.length) return null;
89
+ const keys = [...new Set(hit.map(keyOf))];
90
+ const direct = [], draft = [];
91
+ for (const k of keys) { const x = hit.find((y) => keyOf(y) === k); if (me && sameWho(x.jassignee, me)) direct.push(k); else draft.push({ key: k, who: x.jassignee || '' }); }
92
+ const none = hit.filter((x) => epicFlag(x, epics) === 'none').map(keyOf), other = hit.filter((x) => epicFlag(x, epics) === 'other');
93
+ const why = [epic + ' is this initiative\'s epic.', none.length ? (none.length === 1 ? none[0] + ' has no epic' : none.slice(0, -1).join(', ') + ' and ' + none[none.length - 1] + ' have no epic') + '.' : '',
94
+ other.length ? other.map((x) => keyOf(x) + ' sits under ' + x.jepic).join(', ') + '.' : '', 'Jira reports and boards miss them today.'].filter(Boolean).join(' ');
95
+ const will = [];
96
+ if (direct.length) will.push('Set the epic on ' + direct.join(', ') + ' now: ' + (direct.length === 1 ? 'it is' : 'they are') + ' assigned to you');
97
+ for (const [who, ks] of groupBy(draft)) will.push((ks.length === 1 ? ks[0] + ' is ' : ks.join(', ') + ' are ') + (who ? who + '\'s' : 'not yours') + ': add ' + (ks.length === 1 ? 'it' : 'them') + ' to today\'s Jira draft for ' + (who || 'its owner') + ' to apply; you see the draft first');
98
+ return { say: 'Put ' + (keys.length === 1 ? 'this ticket' : 'these ' + keys.length + ' tickets') + ' under the epic ' + epic + '?', why, will, direct, draft, epic, keys };
99
+ }
100
+ function groupBy(draft) { const m = new Map(); for (const d of draft) { const k = d.who || ''; if (!m.has(k)) m.set(k, []); m.get(k).push(d.key); } return m; }
101
+
102
+ /** "under Batch 2: TM web" (or "under Batch 2 – TM web"): the parent the add box names, by its title (case and spaces aside). */
103
+ export function parseUnder(text, rows) {
104
+ const m = /^\s*under\s+(.+?)\s*[:–—-]\s*(.+)$/i.exec(String(text || ''));
105
+ if (!m) return null;
106
+ const norm = (s) => String(s || '').trim().toLowerCase().replace(/\s+/g, ' ');
107
+ const want = norm(m[1]);
108
+ const T = (rows || []).filter((x) => x && x.kind === 'task' && x.uid);
109
+ const hit = T.find((x) => norm(x.title) === want) || T.find((x) => norm(x.title).startsWith(want));
110
+ return hit ? { parent: hit.uid, parentTitle: hit.title, title: m[2].trim() } : null;
111
+ }