create-pmos 0.764.0 → 0.765.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 +38 -20
  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 +37 -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/lib/briefing-premium-agent.js +4 -1
  13. package/workspace/lib/cos-chat.js +1 -1
  14. package/workspace/lib/engine/boards.js +9 -2
  15. package/workspace/lib/initiative-chat.js +1 -1
  16. package/workspace/lib/pmos-verbs.js +1 -1
  17. package/workspace/lib/program-chat.js +11 -6
  18. package/workspace/lib/program-cli.js +150 -2
  19. package/workspace/lib/programs.js +2 -1
  20. package/workspace/lib/routes-boards.js +62 -5
  21. package/workspace/lib/task-cli.js +45 -12
  22. package/workspace/lib/task-describe.js +228 -0
  23. package/workspace/lib/task-store.js +2 -2
  24. package/workspace/package-lock.json +2 -2
  25. package/workspace/package.json +1 -1
  26. package/workspace/premium-chat-viewer-test.js +3 -0
  27. package/workspace/premium-vw-jira-test.js +1 -1
  28. package/workspace/public/pm/bd-prog-panel.js +2 -0
  29. package/workspace/public/pm/cozy-home.css +1 -0
  30. package/workspace/public/pm/cozy-popup.js +2 -2
  31. package/workspace/public/pm/cozy-task-pop.css +10 -0
  32. package/workspace/public/pm/cozy-task-pop.js +46 -2
  33. package/workspace/public/pm/home-app.js +1 -1
  34. package/workspace/public/pm/home-chat.js +16 -6
  35. package/workspace/public/pm/home-ini.js +2 -1
  36. package/workspace/public/pm/library-open.js +1 -0
  37. package/workspace/public/pm/page-chat.js +7 -2
  38. package/workspace/public/pm/premium-board.js +2 -1
  39. package/workspace/public/pm/task-card.js +2 -0
  40. package/workspace/public/pm/vw-ds.js +38 -0
  41. package/workspace/test-lists/chat-subtasks.json +9 -0
  42. package/workspace/test-lists/task-descriptions.json +9 -0
@@ -172,7 +172,7 @@ function show(pop) {
172
172
  S.el.hidden = false; document.body.classList.add('cz-pop-on');
173
173
  S.all.hidden = true; closeMenu();
174
174
  const p = pop && typeof pop === 'object' ? pop : {};
175
- S.about = p.session ? (p.session.ini ? { id: p.session.ini, kind: 'initiative', title: p.session.work, ws: p.session.ws } : null) : p.id ? { id: p.id, kind: p.kind || 'initiative', title: p.title || '', ws: p.ws } : null;
175
+ S.about = p.session ? (p.session.ini ? { id: p.session.ini, kind: 'initiative', title: p.session.work, ws: p.session.ws } : null) : p.id ? { id: p.id, kind: p.kind || 'initiative', title: p.title || '', ws: p.ws, ...(p.path ? { path: p.path } : {}) } : null;
176
176
  width(parseInt(store.get('cz-pop-chat') || '', 10) || DEF_CHAT);
177
177
  // the chat shows when it was asked for (the rail's chat icon, a session row, search's Ask PMOS), else when it was recently open on this item
178
178
  S.userSet = false;
@@ -188,7 +188,7 @@ function show(pop) {
188
188
  function retarget(pop) {
189
189
  const p = pop && typeof pop === 'object' ? pop : null;
190
190
  if (!p || !p.id || p.keep || (S.about && S.about.id === p.id)) return;
191
- S.about = { id: p.id, kind: p.kind || 'initiative', title: p.title || '', ws: p.ws };
191
+ S.about = { id: p.id, kind: p.kind || 'initiative', title: p.title || '', ws: p.ws, ...(p.path ? { path: p.path } : {}) };
192
192
  S.userSet = false;
193
193
  chatOn(!!(p.target || p.chat || recentOn(S.about)));
194
194
  attach(p.target || aboutTarget(S.about), null);
@@ -64,6 +64,16 @@ button.ctp-cr:hover { text-decoration: underline; }
64
64
  .ctp-main .ctp-hx { margin: 0; }
65
65
  .ctp-say { margin: 0; }
66
66
  .ctp-side { position: sticky; top: 0; min-width: 0; }
67
+ /* the Description block (initiative task-descriptions): the text, Done when as a short list, PMOS's sources; edited in place like the notes */
68
+ .ctp-desc { display: flex; flex-direction: column; gap: var(--space-8); }
69
+ .ctp-desc .head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-8); }
70
+ .ctp-dh { margin: var(--space-4) 0 0; }
71
+ .ctp-done { margin: 0; padding-left: var(--space-16); display: flex; flex-direction: column; gap: var(--space-4); }
72
+ .ctp-dsrc { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }
73
+ .ctp-dt { border: 0; outline: 0; resize: none; field-sizing: content; min-height: 72px; border-radius: 12px; padding: 6px var(--space-8); margin: 0 calc(-1 * var(--space-8)); font: inherit; font-size: var(--fs-body); line-height: 1.55; color: var(--cz-ink); background: transparent; }
74
+ .ctp-dt::placeholder { color: var(--cz-ink3); }
75
+ .ctp-dt:hover { background: var(--cz-well); }
76
+ .ctp-dt:focus { background: var(--cz-card); box-shadow: 0 0 0 1.5px var(--cz-blue), 0 0 0 5px var(--cz-bluebg); }
67
77
  .ctp-ad { flex: none; width: 52px; }
68
78
  .ctp-main .pm-li { width: 100%; border: 0; background: none; font: inherit; color: inherit; text-align: left; text-decoration: none; cursor: pointer; }
69
79
  .ctp-main .pm-li:hover { background: var(--well); }
@@ -102,6 +102,7 @@ export async function openTask(uid, ctx = {}) {
102
102
  }
103
103
  document.addEventListener('keydown', onKey, true);
104
104
  el.addEventListener('click', press);
105
+ el.addEventListener('focusout', descOut); // the description saves when the PM leaves its box (task-descriptions)
105
106
  // the status pick waits for the day (point 18): the card's own press is held here, the line opens under the card
106
107
  el.addEventListener('click', holdStatus, true);
107
108
  }
@@ -138,7 +139,7 @@ async function show(uid) {
138
139
  S.el.innerHTML = `<div class="ctp-h ctp-fh">${ib('data-ctp-close', back, P.back)}<nav class="ctp-path" aria-label="Where this is">${crumbs}${t.jira ? '<span class="pm-chip">Jira</span>' : ''}</nav>`
139
140
  + `<span class="ctp-tools">${step}${ctx.chat ? ib('data-ctp-chat', 'Ask PMOS about this', P.chat) : ''}${more}${ib('data-ctp-x', 'Close', P.x)}</span></div>`
140
141
  + `<div class="ctp-th">${kind}${title}</div><p class="pm-meta ctp-meta">${esc(VD.metaOf(t))}</p>`
141
- + `<div class="ctp-g"><div class="ctp-main">${head ? `<div class="ctp-hx">${head}</div>` : ''}<div class="ctp-stands"></div><div class="ctp-linked"></div><div class="ctp-act"></div></div>`
142
+ + `<div class="ctp-g"><div class="ctp-main">${head ? `<div class="ctp-hx">${head}</div>` : ''}<div class="ctp-stands"></div><div class="ctp-descw"></div><div class="ctp-linked"></div><div class="ctp-act"></div></div>`
142
143
  + '<aside class="ctp-side"><section class="pm-block" aria-label="Fields and notes"><div class="ctp-b"></div><div class="ctp-when" hidden></div></section></aside></div>';
143
144
  } else {
144
145
  S.el.innerHTML = `<div class="ctp-h">${kind}${title}<span class="ctp-tools">${step}${more}${ib('data-ctp-close', 'Close', P.x)}</span></div>`
@@ -166,7 +167,7 @@ async function show(uid) {
166
167
  // the full popup says PMOS's changes once, in its Activity block; the small popup keeps the card's History fold
167
168
  history: ctx.full ? null : S.hist,
168
169
  });
169
- if (ctx.full) { drawMain(); loadActivity(); }
170
+ if (ctx.full) { drawMain(); loadActivity(); describe(); }
170
171
  const f = S.el.querySelector('.ctp-t') || S.el.querySelector('button'); if (f) f.focus();
171
172
  }
172
173
  /* the full popup's main column (viewer-ds-task, pm/vw-ds.js): Where it stands and Linked from the task, Activity from PMOS's kept changes */
@@ -174,9 +175,50 @@ function drawMain() {
174
175
  if (!S || !S.ctx.full || !S.t) return;
175
176
  const put = (sel, html) => { const x = S.el.querySelector(sel); if (x) x.innerHTML = html; };
176
177
  put('.ctp-stands', VD.standsHtml(S.t, { waits: S.ctx.waits ? S.ctx.waits(S.t) : '' }));
178
+ // the description (initiative task-descriptions): never redrawn under the PM's typing
179
+ const dw = S.el.querySelector('.ctp-descw');
180
+ if (dw && !(document.activeElement && dw.contains(document.activeElement) && document.activeElement.matches('[data-ctp-desc]'))) dw.innerHTML = VD.descriptionHtml(S.t, { busy: !!S.dbusy, edit: !!S.dedit, undo: !!S.dundo });
177
181
  put('.ctp-linked', VD.linkedHtml(S.t));
178
182
  put('.ctp-act', VD.activityHtml(S.histL || [], { open: !!S.aopen }));
179
183
  }
184
+ /* PMOS writes a task's description by itself when it has none (POST /api/boards/tasks/describe-draft): once per task, from the initiative's
185
+ * own files, with its sources and Undo. The server never writes it twice, so opening the task again costs nothing. */
186
+ async function describe() {
187
+ const s = S; if (!s || s.t.jira || s.t.description || !s.ctx.pmPost) return;
188
+ s.dbusy = true; drawMain();
189
+ const r = await s.ctx.pmPost('/api/boards/tasks/describe-draft', { ws: s.ctx.ws, board: s.raw.board || s.ctx.board, task: s.t.uid }).catch(() => null);
190
+ s.dbusy = false;
191
+ if (S !== s) return;
192
+ if (r && r.ok && r.wrote && !s.t.description) {
193
+ Object.assign(s.t, { description: r.description, descBy: 'pmos', descSources: r.sources || [] });
194
+ s.raw.description = r.description; s.raw.descBy = 'pmos'; s.raw.descSources = r.sources || [];
195
+ s.dundo = true;
196
+ if (s.ctx.onChange) s.ctx.onChange();
197
+ }
198
+ drawMain();
199
+ }
200
+ /** Save the description (the PM's words, or '' for PMOS's Undo) through tasks/edit, with Undo in the toast. */
201
+ async function saveDesc(text, { word = 'Description saved' } = {}) {
202
+ const s = S; if (!s) return;
203
+ const before = { description: s.t.description, descBy: s.t.descBy, descSources: s.t.descSources };
204
+ const post = (v) => s.ctx.pmPost('/api/boards/tasks/edit', { ws: s.ctx.ws, board: s.raw.board || s.ctx.board, task: s.t.uid, description: v });
205
+ const set = (o) => { Object.assign(s.t, o); s.raw.description = o.description; s.raw.descBy = o.descBy; s.raw.descSources = o.descSources; };
206
+ set({ description: text, descBy: text ? 'you' : '', descSources: [] }); s.dedit = false; s.dundo = false; drawMain();
207
+ const r = await post(text).catch(() => null);
208
+ if (!r || r.ok === false) { set(before); if (S === s) drawMain(); if (s.ctx.toast) s.ctx.toast((r && r.error) || 'Nothing was changed.'); return; }
209
+ if (s.ctx.onChange) s.ctx.onChange();
210
+ if (s.ctx.toast) s.ctx.toast(word, async () => {
211
+ const u = await post(before.description || '').catch(() => null);
212
+ if (u && u.ok !== false) { set(before); if (S === s) drawMain(); if (s.ctx.onChange) s.ctx.onChange(); }
213
+ return u || { ok: false };
214
+ });
215
+ }
216
+ function descOut(e) {
217
+ const a = e.target; if (!S || !a.matches || !a.matches('[data-ctp-desc]')) return;
218
+ const v = a.value.replace(/\s+$/, '');
219
+ if (v === (S.t.description || '')) { if (S.dedit) { S.dedit = false; setTimeout(drawMain, 0); } return; }
220
+ saveDesc(v, { word: v ? 'Description saved' : 'Description cleared' });
221
+ }
180
222
  function loadActivity() {
181
223
  const s = S; if (!s || !s.hist) return;
182
224
  Promise.resolve(s.hist.load()).catch(() => []).then((L) => { if (S !== s) return; s.histL = Array.isArray(L) ? L : []; drawMain(); });
@@ -219,6 +261,8 @@ async function press(e) {
219
261
  return;
220
262
  }
221
263
  if ('ctpAfold' in d) { S.aopen = true; drawMain(); return; }
264
+ if ('ctpDedit' in d) { S.dedit = true; drawMain(); const a = S.el.querySelector('[data-ctp-desc]'); if (a) { a.focus(); a.setSelectionRange(a.value.length, a.value.length); } return; }
265
+ if ('ctpDundo' in d) { saveDesc('', { word: 'PMOS\'s description taken back' }); return; }
222
266
  if (b.closest('.ctp-hx')) { if (ctx.headPress) { const s0 = S; await ctx.headPress(b, { refresh: () => { if (S === s0) show(s0.uid); }, close: closeTask }); } return; }
223
267
  if ('ctpClose' in d) { closeTask(); return; }
224
268
  if ('ctpChat' in d) { if (ctx.chat) ctx.chat(); return; }
@@ -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) => {
@@ -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.';
@@ -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 : ''; });
@@ -64,6 +64,8 @@ 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
 
@@ -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": "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
+ }