create-pmos 0.764.0 → 0.766.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 (49) hide show
  1. package/package.json +51 -39
  2. package/payload/AGENTS.md +1 -1
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/planning/evals/eval-calibration.md +1 -1
  5. package/payload/planning/okrs/health-budgets.md +1 -1
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/changelog.json +50 -0
  8. package/workspace/guide/breakdown.md +1 -1
  9. package/workspace/guide/cli.md +8 -0
  10. package/workspace/guide/home.md +1 -1
  11. package/workspace/guide/initiatives-and-next-steps.md +2 -2
  12. package/workspace/guide/layout.md +1 -1
  13. package/workspace/lib/briefing-premium-agent.js +4 -1
  14. package/workspace/lib/cos-chat.js +1 -1
  15. package/workspace/lib/engine/boards.js +9 -2
  16. package/workspace/lib/initiative-chat.js +1 -1
  17. package/workspace/lib/pmos-verbs.js +1 -1
  18. package/workspace/lib/program-chat.js +11 -6
  19. package/workspace/lib/program-cli.js +150 -2
  20. package/workspace/lib/programs.js +2 -1
  21. package/workspace/lib/routes-boards.js +62 -5
  22. package/workspace/lib/task-cli.js +45 -12
  23. package/workspace/lib/task-describe.js +228 -0
  24. package/workspace/lib/task-store.js +2 -2
  25. package/workspace/package-lock.json +2 -2
  26. package/workspace/package.json +1 -1
  27. package/workspace/premium-chat-viewer-test.js +3 -0
  28. package/workspace/premium-vw-item-test.js +1 -1
  29. package/workspace/premium-vw-jira-test.js +1 -1
  30. package/workspace/public/pm/bd-prog-panel.js +2 -0
  31. package/workspace/public/pm/cozy-home.css +1 -0
  32. package/workspace/public/pm/cozy-popup.js +47 -6
  33. package/workspace/public/pm/cozy-task-pop.css +10 -0
  34. package/workspace/public/pm/cozy-task-pop.js +63 -8
  35. package/workspace/public/pm/cozy-viewer.js +6 -3
  36. package/workspace/public/pm/home-app.js +1 -1
  37. package/workspace/public/pm/home-chat.js +16 -6
  38. package/workspace/public/pm/home-ini.js +2 -1
  39. package/workspace/public/pm/home-task.js +2 -1
  40. package/workspace/public/pm/library-open.js +1 -0
  41. package/workspace/public/pm/page-chat.js +21 -2
  42. package/workspace/public/pm/premium-board.js +2 -1
  43. package/workspace/public/pm/premium-viewer.js +1 -0
  44. package/workspace/public/pm/premium-vw-item.js +9 -2
  45. package/workspace/public/pm/task-card.js +10 -0
  46. package/workspace/public/pm/vw-ds.js +38 -0
  47. package/workspace/test-lists/chat-subtasks.json +9 -0
  48. package/workspace/test-lists/task-chat-scope.json +9 -0
  49. package/workspace/test-lists/task-descriptions.json +9 -0
@@ -553,7 +553,9 @@ function place(el) {
553
553
  function emit(x) {
554
554
  x = x || V;
555
555
  const d = { open: !!V.cur, id: V.cur ? V.cur.id : null, kind: V.cur ? V.cur.kind : null, title: V.cur ? V.cur.title : null, via: V.cur ? '' : x.via || '', // via 'history': the browser's Back closed it
556
- panel: 'v' + x.i, shut: !shown(x), pop: !!x.pop };
556
+ panel: 'v' + x.i, shut: !shown(x), pop: !!x.pop,
557
+ // what the popup's chat should be about for this item (open({ chatAbout }): a task, a milestone), and whether the chat itself opened it
558
+ chatAbout: V.cur && V.cur.args && V.cur.args.chatAbout ? V.cur.args.chatAbout : null, viaChat: !!(V.cur && V.cur.viaChat) };
557
559
  if (!x.pop) document.body.classList.toggle('cz-vw-on', side().some(shown)); // the popup covers the page: the page does not make room for it
558
560
  G.subs.forEach((f) => { try { f(d); } catch { /* a listener's fault stays its own */ } });
559
561
  document.dispatchEvent(new CustomEvent('cz-viewer', { detail: d }));
@@ -647,6 +649,7 @@ export function open(it) {
647
649
  use(x);
648
650
  // the chat opened it by itself (behind()): the item shown stays behind it, so ← comes back to it with its place (chat-open-keeps-back)
649
651
  const bn = !o._inst ? G.behindNext : null; if (bn) G.behindNext = null;
652
+ const pr = H.press && Date.now() - H.press.t < 10000 ? H.press : null, viaChat = !!bn || !!(pr && pr.chat); // the chat opened it (an answer, a link in it)
650
653
  if (keepsBehind(bn, V.cur, o)) o = { ...o, back: true };
651
654
  else if (bn && V.cur && o.id != null && V.cur.id !== String(o.id)) { try { console.warn(LOG_BEHIND, 'item not kept behind', { id: o.id }); } catch { /* no console */ } }
652
655
  // an item with unsaved changes asks first; the open goes on when it says so (and keeps a drill-in asked for before it)
@@ -674,7 +677,7 @@ export function open(it) {
674
677
  V.drill = false; H.adopt = false;
675
678
  const sameKind = V.cur && kindKey(V.cur.kind) === kindKey(o.kind);
676
679
  leave();
677
- 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, discussHome: !!o.discussHome, add: o.add || null, sub: o.sub || '', check: o.check || null, presses: o.presses || null, wrap: !!o.wrap, chip: o.chip && (o.chip.n > 0 || o.chip.looking) ? o.chip : null, onPress: o.onPress, guard: o.guard, rename: o.rename && typeof o.rename.save === 'function' ? o.rename : null, from: o.from || '', kindChip: o.kindChip || '', args: o };
680
+ 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, discussHome: !!o.discussHome, add: o.add || null, sub: o.sub || '', check: o.check || null, presses: o.presses || null, wrap: !!o.wrap, chip: o.chip && (o.chip.n > 0 || o.chip.looking) ? o.chip : null, onPress: o.onPress, guard: o.guard, rename: o.rename && typeof o.rename.save === 'function' ? o.rename : null, from: o.from || '', kindChip: o.kindChip || '', viaChat: o._nav ? false : viaChat, args: o };
678
681
  el.setAttribute('aria-label', 'Viewer: ' + (o.kind || o.title || 'item'));
679
682
  redraw();
680
683
  el.querySelectorAll('.cz-vw-menu,.cz-vw-trail').forEach((m) => m.remove());
@@ -822,7 +825,7 @@ function pressAt(e) {
822
825
  const t = e.target; let inst = t && t.nodeType === 1 && !t.closest('.cz-vw-trail') ? ALL.find((x) => x.el && x.el.contains(t)) || null : null;
823
826
  // a press in the popup's chat (a file or a link it names) opens on the popup's left, behind the work shown there (board 22)
824
827
  if (!inst && t && t.nodeType === 1 && t.closest('.cz-pop')) inst = ALL.find((x) => x.pop && shown(x)) || null;
825
- H.press = { t: Date.now(), inst };
828
+ H.press = { t: Date.now(), inst, chat: !!(t && t.nodeType === 1 && t.closest('.cz-pop-r')) };
826
829
  }
827
830
  /* the trail list: hover ← or → for a moment (a mouse), or hold it (a touch). It names every step, newest first, and the page it started on. */
828
831
  let HOLD = { t: 0, fired: 0 };
@@ -1057,7 +1057,7 @@ const chat = mountChat($('#hmChat'), {
1057
1057
  let turnT = null;
1058
1058
  function turnEnded() {
1059
1059
  clearTimeout(turnT);
1060
- turnT = setTimeout(async () => { await load(); iniFresh(); }, 400); // two chats that finish together read once
1060
+ turnT = setTimeout(async () => { await load(); iniFresh(); if (progPanel) progPanel.then((PP) => PP.refresh()); }, 400); // two chats that finish together read once
1061
1061
  // the popup's own reads (the case card, the Library's rows) are read again too, as on every other page (initiative chat-saves-to-cards)
1062
1062
  document.dispatchEvent(new CustomEvent('cz:chat-turn'));
1063
1063
  }
@@ -500,7 +500,7 @@ export function mountChat(el, host) {
500
500
  + `<div class="hm-tb">${add}`
501
501
  + to + wait + scope + `<span class="sp"></span>${host.viewerClosed() ? '<span class="hm-key">Enter sends · Shift+Enter for a new line</span>' : ''}`
502
502
  + `${NPU.undoHtml()}${mic}<button type="submit" class="hm-send" aria-label="Send" title="Send">${SVG(UP, 18)}</button></div>`
503
- + marksRow() + filesRow()
503
+ + marksRow() + filesRow() + errRow()
504
504
  + '</form>';
505
505
  if (foot.__h !== html) {
506
506
  const focused = document.activeElement && document.activeElement.id === 'hmIn';
@@ -509,6 +509,9 @@ export function mountChat(el, host) {
509
509
  if (focused) { ta.focus(); ta.setSelectionRange(ta.value.length, ta.value.length); }
510
510
  }
511
511
  }
512
+ /* a send that failed says why under the box, and stays until the PM writes again or sends (bug 2026-11-24: a toast behind the popup
513
+ * showed nothing, so the send looked dead) */
514
+ const errRow = () => (C.err ? `<p class="hm-senderr" role="alert">Not sent: ${esc(C.err)}</p>` : '');
512
515
  /* the files on the next message: a photo shows its picture, a saved file its size; × takes it off and deletes the copy nothing will name */
513
516
  const filesRow = () => (C.files.length ? `<div class="hm-files" id="hmFiles">${C.files.map((f, i) => `<span class="hm-att${f.state === 'saving' ? ' saving' : ''}">`
514
517
  + (f.url ? `<img class="hm-ath" src="${esc(f.url)}" alt="">` : '') + `<b>${esc(f.name)}</b><em>${f.state === 'saving' ? 'Saving…' : f.note ? 'Note' : esc(sizeText(f.size || 0))}</em>`
@@ -530,7 +533,7 @@ export function mountChat(el, host) {
530
533
  const mk = C.mark || {};
531
534
  if (text && (mk.point || mk.from)) text = (mk.from ? `[From version ${mk.from}] ` : '') + (mk.point ? `[On: ${String(mk.point.label || mk.point.el).replace(/[\]·]/g, ' ').trim()}${mk.point.el ? ' · ' + mk.point.el : ''}] ` : '') + text;
532
535
  if (text) C.mark = null;
533
- C.sending = true;
536
+ C.sending = true; C.err = '';
534
537
  let r;
535
538
  const was = running();
536
539
  // the bubble first, then the server (batch 24 item 2): the files leave the box with the words, and come back if the send fails
@@ -548,8 +551,9 @@ export function mountChat(el, host) {
548
551
  if (!r || r.ok !== true) {
549
552
  C.pend = C.pend.filter((x) => x !== p);
550
553
  if (C.t === t && !C.files.length) C.files = sentFiles;
551
- if (C.t === t) draw();
552
- host.toast((r && r.error) || 'The message was not sent.'); return false;
554
+ const why = notSentWhy(r);
555
+ if (C.t === t) { C.err = why; draw(); }
556
+ host.toast('Not sent: ' + why); return false;
553
557
  }
554
558
  const s = sid() || r.session;
555
559
  if (host.touch) host.touch(s);
@@ -561,6 +565,12 @@ export function mountChat(el, host) {
561
565
  read();
562
566
  return true;
563
567
  }
568
+ /** Why a send failed, in the PM's words: the server's own reason, else that the workspace did not answer. */
569
+ function notSentWhy(r) {
570
+ const e = String((r && r.error) || '').trim();
571
+ if (!r) return 'the workspace server did not answer. Your words and files are still here; send again.';
572
+ return (e ? e.charAt(0).toUpperCase() + e.slice(1) : 'PMOS did not take the message') + (/[.!?]$/.test(e) ? '' : '.');
573
+ }
564
574
  async function press(k) {
565
575
  const t = C.t; if (!t) return;
566
576
  const r = t.key && !t.sid ? await host.pmPost('/api/briefing-premium/press' + (t.ws ? '?ws=' + encodeURIComponent(t.ws) : ''), { key: t.key, press: k }).catch(() => null)
@@ -683,7 +693,7 @@ export function mountChat(el, host) {
683
693
  el.addEventListener('input', (e) => {
684
694
  const card = C.t && C.t.intro && C.t.intro.card;
685
695
  if (card && card.input && e.target.closest('.hm-icard')) { card.input(e.target, e.target.closest('.hm-icard')); return; }
686
- if (e.target.id === 'hmIn') { grow(e.target); C.slashAt = 0; drawSlash(); NPU.input(e.target.value); }
696
+ if (e.target.id === 'hmIn') { grow(e.target); C.slashAt = 0; drawSlash(); NPU.input(e.target.value); if (C.err) { C.err = ''; const er = foot.querySelector('.hm-senderr'); if (er) er.remove(); foot.__h = null; } }
687
697
  });
688
698
  /* ── the mic ── dictation into the box only (HmMic). A desk shows the blue dot in the box; a phone shows the Speak to Claude sheet. */
689
699
  const box = () => foot.querySelector('textarea');
@@ -790,7 +800,7 @@ export function mountChat(el, host) {
790
800
  if (notesM) notesM.then((M) => setTimeout(() => M.syncNotes(), 0)); // the Notes open in the Viewer belonged to the conversation before
791
801
  const same = C.t && t && C.t.key === t.key && C.t.sid === t.sid;
792
802
  C.t = t;
793
- if (!same) { C.mark = null; NPU.open(); C.addOpen = false; C.th = null; C.conv = null; C.show = 12; C.open = new Set(); C.files = []; C.marked = null; C.touched = null; C.picked = {}; C.pend = []; C.plOpen = false; C.plAll = false; C.seenAt = t.key ? host.seen(t.key) : null; put(log, introHtml(t.intro)); put(pl, ''); pl.hidden = true; C.jump = true; peek(null); }
803
+ if (!same) { C.mark = null; NPU.open(); C.addOpen = false; C.th = null; C.conv = null; C.show = 12; C.open = new Set(); C.files = []; C.err = ''; C.marked = null; C.touched = null; C.picked = {}; C.pend = []; C.plOpen = false; C.plAll = false; C.seenAt = t.key ? host.seen(t.key) : null; put(log, introHtml(t.intro)); put(pl, ''); pl.hidden = true; C.jump = true; peek(null); }
794
804
  draw(); read();
795
805
  },
796
806
  refresh() { if (C.t) draw(); },
@@ -500,7 +500,8 @@ export function iniPage(o = {}) {
500
500
  let rename = X.ctx.renameIni ? X.ctx.renameIni(id, '') : null;
501
501
  if (rename) rename = { ...rename, value: X.ctx.iniTitle(id) };
502
502
  const dh = dashFor(id);
503
- BODY = VW.open({ id: 'ov:' + id, kind: X.ctx.kindOf(id), title: X.ctx.iniTitle(id), icon: 'goal', wrap: true, more: () => (PW.on(BODY) ? PW.moreItems(null, popExtra(id), BODY) : []).concat(pageMore(id), PW.on(BODY) && !PW.inPop(BODY) ? moreOf(id, 'page').filter((x) => x.sep || /full record|Sprint/.test(x.label)) : []), rename, // a phone's page (Ph2_init) keeps the record and the sprint pop: o.pop || undefined,
503
+ BODY = VW.open({ id: 'ov:' + id, kind: X.ctx.kindOf(id), title: X.ctx.iniTitle(id), icon: 'goal', wrap: true, more: () => (PW.on(BODY) ? PW.moreItems(null, popExtra(id), BODY) : []).concat(pageMore(id), PW.on(BODY) && !PW.inPop(BODY) ? moreOf(id, 'page').filter((x) => x.sep || /full record|Sprint/.test(x.label)) : []), rename, // a phone's page (Ph2_init) keeps the record and the sprint
504
+ pop: o.pop || undefined, // on a desk: the one popup (goIni passes it); never inside the comment above, or work opens beside the page
504
505
  discuss: () => X.ctx.newIn(id), discussHome: true, // the one view (OvViewers): Discuss starts a new session about it, where + New session was
505
506
  // the kind of work (batch 29 item 11, KdV1-3): its glyph stands before Discuss; a tap opens the three kinds
506
507
  presses: [WK.pressOf(kindNow(id))].concat(dh ? dh.presses() : []), onPress: (a, btn) => {
@@ -6,7 +6,7 @@
6
6
  * status, the dates, the owner and the notes, and its move icon the section, the group or the initiative. Every write is the board's own route and is the PM's press; each says so
7
7
  * in a toast with Undo, and a refusal shows the route's reason and changes nothing. Talk it through in chat is under ⋯ (the chat is beside
8
8
  * the Viewer on Home). The PM's own items (a note, a mention made into a task) open in My work's item view (home-work.js). */
9
- import { taskOf, checkOf, mountCard, boardSaver, cardStyle, placeOf, historyFor, deleteEntry } from './task-card.js';
9
+ import { taskOf, checkOf, mountCard, boardSaver, cardStyle, placeOf, historyFor, deleteEntry, chatAbout } from './task-card.js';
10
10
 
11
11
  /** h: { VW, pmPost, toast, toastUndo?, now, ws, board, iniTitle(id), openIni(id), askInChat(task), onChange(), rename?(task),
12
12
  * owners?() → [names], inis?() → [{ id, title }] } */
@@ -28,6 +28,7 @@ export function openTask(task, h) {
28
28
  const del = deleteEntry({ ws, board, t, post: (p, b) => h.pmPost(p, b), toast, done: () => { if (h.VW.close) h.VW.close(); if (h.onChange) h.onChange(); } });
29
29
  const body = h.VW.open({
30
30
  id, kind: 'Task', title: t.title, icon: 'task', check: checkOf(t),
31
+ chatAbout: chatAbout(t, raw), // in the one popup, the chat beside it is about this task (cozy-popup.js, bug 2026-11-24)
31
32
  // a short link (bet A428): ⋯ Copy link gives /i/t/<uid> (or /i/m/ for a milestone), which opens this task on any device
32
33
  link: { kind: t.milestone ? 'milestone' : 'task', id: raw.uid, ws: ws || '' },
33
34
  rename: t.jira ? null : h.rename ? h.rename(raw) : null,
@@ -14,6 +14,7 @@ import * as POP from './cozy-popup.js';
14
14
  const KIND = { doc: 'document', link: 'link', meeting: 'meeting', proto: 'prototype' };
15
15
  const CHIP = { link: 'Link', meeting: 'Meeting notes', proto: 'Prototype' };
16
16
  export const aboutOf = (x, from) => ({ id: String(x.id || '').replace(/[^A-Za-z0-9._:-]+/g, '-').slice(0, 100), kind: KIND[x.kind] || 'document', title: x.name || '', ws: (x.about && x.about.ws) || undefined,
17
+ ...(x.open && x.open.doc && x.open.doc.path ? { path: String(x.open.doc.path) } : {}),
17
18
  ...(from ? { from } : {}), kindChip: CHIP[x.kind] || x.kindText || 'Document' });
18
19
 
19
20
  export function openItem(x, { from } = {}) {
@@ -46,12 +46,17 @@ export function targetOf(it, ws) {
46
46
  return { key: keyOf(it), ws: ws || undefined, title, about: title, scope: { text: title, icon: FLAG }, role: CLAUDE, rich: false, context: contextOf(it, ws),
47
47
  placeholder: 'Message PMOS about ' + title, empty: 'Ask about ' + title + '. PMOS reads its records and works on it in a real session.' };
48
48
  }
49
- /** What the chat is about, in the page's words, for a chat whose key the server's model has no row for (a program, a whole product):
49
+ /** What the chat is about, in the page's words, for a chat whose key the server's model has no row for (a program, a whole product, a document):
50
50
  * lib/briefing-premium-agent.js starts it from these words (bug 2026-11-23). An initiative's chat reads its own record and needs none. */
51
51
  export function contextOf(it, ws) {
52
52
  const kind = String((it && (it.scopeKind || it.kind)) || '').toLowerCase(), title = String((it && it.title) || '').replace(/\s+/g, ' ').trim().slice(0, 80);
53
- if (!title || !/^(program|product)$/.test(kind)) return undefined;
53
+ if (!title || !/^(program|product|document|doc)$/.test(kind)) return undefined;
54
54
  const where = ws ? ' (workspace ' + String(ws).slice(0, 60) + ')' : '';
55
+ // a document (Library, an initiative's artefacts; bug 2026-11-24): its title and file, so the chat reads the document the PM has open
56
+ if (kind !== 'program' && kind !== 'product') {
57
+ const file = String((it && it.path) || '').replace(/\s+/g, ' ').trim().slice(0, 300);
58
+ return 'The document ' + title + where + (file ? ', file ' + file : '') + '. Read it before you answer.';
59
+ }
55
60
  return kind === 'product'
56
61
  ? 'The product ' + title + where + ': its programs and initiatives on the Work page. Read them with pmos before you answer.'
57
62
  : 'The program ' + title + where + ': its initiatives and milestones. Read it with pmos before you answer.';
@@ -109,6 +114,20 @@ export function popTarget(it, ws) {
109
114
  return { ...T, popAbout: true, scope: { text: 'In: ' + T.title, icon: PIN, drop: true }, placeholder: 'Ask or tell PMOS', empty: COS_EMPTY };
110
115
  }
111
116
  const COS_EMPTY = 'Ask anything about your work. I read it with PMOS and say where each answer came from.';
117
+ /** The chat about one item that has no row of its own in a server model: a task, a milestone (bug 2026-11-24, Wawan: "When open chat from a
118
+ * task page, chat session should be about the task"). Its own conversation, pop:<kind>:<id>, so it never resumes the initiative's session;
119
+ * its first message carries what the item shows (lib/briefing-premium-agent.js popRow: title, subject, say, facts), so PMOS reads the task in.
120
+ * it: { id, kind, title, subject?, say?, facts?: [[label, value]] }. null without an id or a title. */
121
+ export function itemTarget(it, ws) {
122
+ const title = String((it && it.title) || '').replace(/\s+/g, ' ').trim().slice(0, 80);
123
+ const kind = String((it && it.kind) || 'item').trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') || 'item';
124
+ const id = String((it && it.id) || '').replace(/[^A-Za-z0-9._:-]+/g, '-').replace(/^[^A-Za-z0-9]+/, '');
125
+ if (!id || !title) return null;
126
+ const key = ('pop:' + kind + ':' + id).slice(0, 104);
127
+ const facts = (Array.isArray(it.facts) ? it.facts : []).filter((f) => Array.isArray(f) && f[1] != null && String(f[1]).trim()).slice(0, 12).map(([a, b]) => [String(a), String(b)]);
128
+ return { key, ws: ws || undefined, title, about: title, role: CLAUDE, rich: false, popAbout: true, scope: { text: 'In: ' + title, icon: PIN, drop: true },
129
+ context: { title, subject: String(it.subject || ''), say: String(it.say || ''), facts }, placeholder: 'Ask or tell PMOS', empty: COS_EMPTY };
130
+ }
112
131
  export function cosTarget(here, ws) {
113
132
  const h = String(here || '').replace(/\s+/g, ' ').trim().slice(0, 80);
114
133
  return { key: 'chat:main', ws: ws || undefined, title: 'Ask PMOS', about: 'Ask PMOS', role: CLAUDE, rich: false, cos: true, here: h,
@@ -117,7 +117,8 @@ mountPanels({ page: document.getElementById('stage'), key: 'board', sources: BP2
117
117
  /* Discuss in chat on an initiative's or a program's panel opens Home's chat about it in a panel of its own, beside the panel or sliding over
118
118
  * it (batch 26 item 4, page-chat.js); the Board stays. A finished turn reads the board again. A phone goes to Home as before. */
119
119
  VW.chatHere((it) => { const r = M && (M.rows || []).find((x) => x.id === it.id); import('./page-chat.js').then((C) => C.openChat(it, { ws: (r && r.ws) || (M && M.board.ws) || undefined })); return true; });
120
- document.addEventListener('cz:chat-turn', () => { clearTimeout(chatT); chatT = setTimeout(() => load(), 400); });
120
+ // the programs too, and an open program panel draws again: a chat that saved a program's goal shows it at once (initiative chat-saves-to-cards)
121
+ document.addEventListener('cz:chat-turn', () => { clearTimeout(chatT); chatT = setTimeout(async () => { await loadPrograms(); PP.refresh(); load(); }, 400); });
121
122
  let chatT = null;
122
123
  // the popup's sessions name the work they are about, and the chat icon opens a session's initiative here, in the popup
123
124
  POP.setTitles((id) => { const r = M && ((M.rows || []).find((x) => x.id === id) || goneRows().find((x) => x.id === id)); return r ? r.title : ''; });
@@ -89,6 +89,7 @@ function czVw(it) {
89
89
  let el = null; czLast = it;
90
90
  czOpen({ id: 'vw:' + it.id, kind: it.kind || it.title || 'Item', title: it.name || it.title || 'Item', icon: CZ_ICON[it.icon] || 'doc', url: it.url || '', rename: it.rename || null,
91
91
  check: it.check || null, onPress: it.onPress, more: it.more, // a task's check box and its ⋯ (canvas XetX1Rest)
92
+ chatAbout: it.chatAbout || undefined, // the popup's chat moves to the task (cozy-popup.js, bug 2026-11-24)
92
93
  render: (body) => {
93
94
  el = document.createElement('div'); el.className = 'obody vw'; el.dataset.vw = it.id; el.setAttribute('role', 'region'); body.append(el);
94
95
  if (it.render) it.render(el); else el.innerHTML = it.html || '';
@@ -9,7 +9,7 @@ import { vwOpen, vwStyle, vwClose } from './premium-viewer.js';
9
9
  import { esc, iniId, taskId, stateOf, readingHtml, errorHtml, iniHtml, taskHtml, findTask, cardTask } from './premium-vw-item-model.js';
10
10
  import { mountCard, boardSaver, checkOf, cardStyle, toastUndo, placeOf, deleteEntry, historyFor } from './task-card.js';
11
11
  import { pmPost } from './http.js';
12
- import { setCheck, retitle } from './cozy-viewer.js';
12
+ import { setCheck, retitle, popOpen as VW_POP } from './cozy-viewer.js';
13
13
 
14
14
  const TRIES = 20, WAIT = 1500, KEEP = 30000;
15
15
  const cache = new Map(); // query → { at, p }: two tabs of one initiative read once
@@ -55,7 +55,12 @@ async function openFull(o) {
55
55
  rename: o.rename && typeof o.rename.save === 'function' ? (raw, title) => o.rename.save(title, {}) : null,
56
56
  onChange: () => cache.clear(),
57
57
  openIni: (id) => openWorkItem({ kind: 'initiative', id, title: id === o.ini && m ? m.title : '', ws: o.ws, board: o.board }),
58
- chat: () => import('./page-chat.js').then((PC) => PC.openChat({ kind: 'task', id: uid, title: (row && row.title) || o.title || 'this task' }, { ws })),
58
+ // the chat about the task itself (bug 2026-11-24), read in from what the popup shows; with the one popup open, cozy-task-pop.js moved it already
59
+ chat: (about) => import('./page-chat.js').then((PC) => {
60
+ if (VW_POP()) { const k = document.querySelector('.cz-pop [data-pop="ask"]'); if (k) k.click(); return true; }
61
+ const t = PC.itemTarget(about || { kind: 'task', id: uid, title: (row && row.title) || o.title || 'this task' }, ws);
62
+ return t ? PC.openTarget(t, { title: t.title }) : false;
63
+ }),
59
64
  });
60
65
  return true;
61
66
  }
@@ -77,6 +82,8 @@ export function openWorkItem(o) {
77
82
  id: vid,
78
83
  title: o.title || (isTask ? 'Task' : 'Initiative'),
79
84
  icon: isTask ? 'tk' : 'list',
85
+ // a task in the one popup: the chat beside it is about the task, read in (cozy-popup.js, bug 2026-11-24)
86
+ chatAbout: isTask && o.title ? { id: String(o.key || '').replace(/^[a-z]+:/, ''), kind: 'task', title: o.title, ws: ctx.ws || undefined, facts: [['Initiative', ctx.id], ['Task key', o.key || '']] } : undefined,
80
87
  rename: o.rename || null, // the Viewer's rename option, from the page that knows how to write it (rename-press.js)
81
88
  check: editable ? { state: 'todo', label: 'Mark done' } : null, // the quick Done (canvas XetX1Rest); it follows the task once read
82
89
  onPress: (act) => { if (act === 'check' && card && cardT && !cardT.jira) card.setStatus(cardT.status === 'Done' ? 'To do' : 'Done'); },
@@ -64,9 +64,19 @@ export function taskOf(row, extra = {}) {
64
64
  iniTitle: extra.iniTitle || '', group: extra.group != null ? extra.group : '', board: r.board || extra.board || '',
65
65
  section: typeof r.section === 'string' ? r.section : '', milestone: !!r.milestone, wbs: r.wbs && (r.wbs.title || r.wbs.id) ? { id: r.wbs.id || '', title: r.wbs.title || r.wbs.id } : null,
66
66
  jira: jira ? { key: r.ref || r.key || r.uid || '', readAt: r.readAt || extra.readAt || '' } : null,
67
+ // the task's description (initiative task-descriptions): its words, who wrote the last one ('pmos' | 'you') and PMOS's sources
68
+ description: typeof r.description === 'string' ? r.description : '', descBy: r.descBy || '', descSources: Array.isArray(r.descSources) ? r.descSources : [],
67
69
  };
68
70
  }
69
71
 
72
+ /** What the chat about this task reads in (page-chat.js itemTarget, the server's popRow): the same facts the popup shows. */
73
+ export function chatAbout(t, raw = {}) {
74
+ const r = raw || {};
75
+ return { id: t.uid || String(t.key || '').replace(/^task:/, ''), kind: t.milestone ? 'milestone' : 'task', title: t.title, parent: t.iniTitle || '',
76
+ subject: (t.milestone ? 'Milestone' : 'Task') + (t.iniTitle ? ' in the initiative ' + t.iniTitle : '') + (t.ini ? ' (' + t.ini + ')' : '') + '. Read it with pmos before you answer.',
77
+ facts: [['Status', t.status], ['Start', t.start], ['Due', t.due], ['Owner', t.owner || r.owner || ''], ['Initiative', t.ini], ['Board', t.board], ['Task id', t.uid],
78
+ ['Notes', String(t.notes || '').slice(0, 240)]] };
79
+ }
70
80
  /** Where a task sits: { section, wbs }. The initiative view's model (ini-view-model.js, batch 6 item 1) owns the rules: sectionOf(task, stages)
71
81
  * resolves the PM's placement, then the stage that made the task, then its plan-tree stage; wbsOf(title) reads the breakdown code from the
72
82
  * title ("10.5 TC to review" sits under 10). Before that model is on the page, the same rules in their simplest form: the row's section by
@@ -6,6 +6,9 @@
6
6
  * pathOf(t, o) → [crumb] product › initiative › task (the Jira key, or the task's name)
7
7
  * standsOf(t, o) → [html] Where it stands, from the record only
8
8
  * linkedOf(t) → [{ kind, title, sub, href?, act? }] the initiative, the Jira ticket, each link in the notes
9
+ * descParts(text) → { what, why, done: [], rest } a description's What, Why and Done when (task-descriptions)
10
+ * descriptionHtml(t, o) → the Description block: PMOS writing it (o.busy), its parts, PMOS's sources with Undo, or the empty box to
11
+ * write in; o.edit draws the text box. Under Where it stands, so the task says what it is before anything else
9
12
  * standsHtml · linkedHtml · activityHtml(hist, o) the three main-column blocks
10
13
  *
11
14
  * NOTHING HERE MAKES A FACT UP. A task with no due date says so; a task nobody has says so; zero is silence (no link, no Linked block). */
@@ -60,6 +63,41 @@ export function standsHtml(t, o = {}) {
60
63
  + (S.length ? `<p class="ctp-say">${S.join(' ')}</p>` : '') + (o.sug || '') + '</section>';
61
64
  }
62
65
 
66
+ /* ── Description (initiative task-descriptions) ───────────────────────────────────────────────────────────────── */
67
+ /** "What: …\n\nWhy: …\n\nDone when:\n- …" → its parts; any other text is `rest`, shown as it is. */
68
+ export function descParts(text) {
69
+ const out = { what: '', why: '', done: [], rest: '' };
70
+ const s = String(text || '').replace(/\r\n?/g, '\n').trim();
71
+ if (!s) return out;
72
+ const m = /^What:\s*([\s\S]*?)(?:\n\s*\n|$)(?:Why:\s*([\s\S]*?)(?:\n\s*\n|$))?(?:Done when:\s*\n([\s\S]*))?$/.exec(s);
73
+ if (!m) { out.rest = s; return out; }
74
+ out.what = m[1].trim(); out.why = (m[2] || '').trim();
75
+ out.done = (m[3] || '').split('\n').map((l) => l.replace(/^\s*[-*•]\s*/, '').trim()).filter(Boolean);
76
+ return out;
77
+ }
78
+ const PEN = 'M4 20h4L19 9l-4-4L4 16v4zM13.5 6.5l4 4'; // brand/icons.json edit
79
+ export function descriptionHtml(t, o = {}) {
80
+ if (t.jira) return ''; // Jira keeps a ticket's description
81
+ const head = (extra = '') => `<div class="head"><h3 class="pm-h-sm">Description</h3>${extra}</div>`;
82
+ if (o.edit || (!t.description && !o.busy)) {
83
+ return `<section class="pm-block ctp-desc" aria-label="Description">${head()}<textarea class="ctp-dt" data-ctp-desc rows="${o.edit ? 8 : 3}" maxlength="4000" aria-label="Description" placeholder="What it is, why it matters, and when it is done">${esc(t.description)}</textarea></section>`;
84
+ }
85
+ if (o.busy && !t.description) return `<section class="pm-block ctp-desc" aria-label="Description" aria-busy="true">${head()}<p class="pm-meta">${SV(I.star, 14, 'pm-star')} PMOS is writing the description from your plan…</p></section>`;
86
+ const P = descParts(t.description);
87
+ const para = (x) => esc(x).replace(/\n/g, '<br>');
88
+ const body = P.rest ? `<p class="ctp-say">${para(P.rest)}</p>`
89
+ : `<p class="ctp-say">${para(P.what)}</p>` + (P.why ? `<p class="ctp-say"><b>Why.</b> ${para(P.why)}</p>` : '')
90
+ + (P.done.length ? `<p class="pm-h-sm ctp-dh">Done when</p><ul class="ctp-done">${P.done.map((x) => `<li>${esc(x)}</li>`).join('')}</ul>` : '');
91
+ const edit = `<button type="button" class="pm-btn" data-ctp-dedit aria-label="Edit the description" title="Edit">${SV(PEN)}</button>`;
92
+ const src = t.descSources || [];
93
+ const by = t.descBy === 'pmos'
94
+ ? `<p class="pm-meta ctp-dsrc">${SV(I.star, 14, 'pm-star')} PMOS wrote this from ${src.length} ${src.length === 1 ? 'source' : 'sources'}`
95
+ + (src.length ? `: ${src.map((x) => `<span title="${esc(x.path + (x.line ? ':' + x.line : ''))}">${esc(x.title || x.path)}</span>`).join(', ')}` : '')
96
+ + (o.undo ? ` <button type="button" class="pm-btn" data-ctp-dundo aria-label="Undo PMOS's description" title="Undo">${SV(I.undo)}</button>` : '') + '</p>'
97
+ : '';
98
+ return `<section class="pm-block ctp-desc" aria-label="Description">${head(edit)}${body}${by}</section>`;
99
+ }
100
+
63
101
  /* ── Linked ───────────────────────────────────────────────────────────────────────────────────────────────────── */
64
102
  const URL_RE = /\bhttps?:\/\/[^\s<>"')\]]+/g;
65
103
  const shortUrl = (u) => { try { const x = new URL(u); const p = x.pathname.replace(/\/$/, ''); return x.host.replace(/^www\./, '') + (p.length > 32 ? p.slice(0, 31) + '…' : p); } catch { return u.slice(0, 48); } };
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Chat creates subtasks: pmos task add and set take --parent, with an Undo, and the chat rule names it (initiative chat-subtasks, done test C1-C6). No browser, no network.",
3
+ "modules": [
4
+ "chat-subtasks.test.js"
5
+ ],
6
+ "seconds": {
7
+ "chat-subtasks.test.js": 3
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "The chat beside a task is about the task (task-chat-scope, done test C1-C5): page-chat.js itemTarget, task-card.js chatAbout and the server's popRow, plus a read of the popup's wiring. No browser.",
3
+ "modules": [
4
+ "task-chat-scope.test.js"
5
+ ],
6
+ "seconds": {
7
+ "task-chat-scope.test.js": 1
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Every task has a description PMOS writes (initiative task-descriptions, done test planning/done-tests/task-descriptions.md T1-T7): the task-description line and its fold, the edit route's description with Undo, the sources from the initiative's own files, the session's draft and its fallback, describe-draft once per task, pmos task describe, the Description block. A scratch repository; no server, network or browser.",
3
+ "modules": [
4
+ "task-descriptions.test.js"
5
+ ],
6
+ "seconds": {
7
+ "task-descriptions.test.js": 4
8
+ }
9
+ }