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
@@ -0,0 +1,228 @@
1
+ 'use strict';
2
+ /* task-describe.js — every task has a description PMOS writes (initiative task-descriptions; done test planning/done-tests/task-descriptions.md).
3
+ *
4
+ * Wawan (2026-11-24): a task page showed Where it stands, Linked and empty Notes, and nothing said what the task is, why it matters or when it
5
+ * is done. "Tasks miss a description. PMOS should work on the detailed description."
6
+ *
7
+ * docsOf(root, ini) → [{ path, title, lines }] READ-ONLY. The initiative's own files: its record, its PRD, its done test
8
+ * and the newest version of each of its core documents (<state>/core-docs/initiative-<id>/<key>/)
9
+ * sourcesOf({ root, ini, task }) → [{ n, path, line, title, text }] the lines of those files about the task: the most key words of its
10
+ * title, best 3 per file, at most 12; the record's first paragraph (the why) is always one
11
+ * promptOf(task, list) · parse(text, list) the session's prompt, and its answer read back ({ what, why, done: [], used: [passage] } | null) PURE
12
+ * textOf(d) → the description as the page and the ledger keep it: What, Why and Done when, plain text PURE
13
+ * fallbackOf(task, list) → { what, why, done, used } | null from the passages' own words, when no session answers PURE
14
+ * draft(ctx, { root, ini, task }) → { ok: true, text, sources } | { ok: true, text: null, why }
15
+ *
16
+ * The session is one normal PMOS session (`claude -p`, the existing read-only `briefing-ask:` ask kind, no tools: the same path as Search's
17
+ * answers, lib/search-ask.js). It writes from the passages only and names the ones it used: a description with no source is not kept. No
18
+ * passage about the task: no description (zero is silence). Nothing here writes: lib/routes-boards.js describe-draft writes the line.
19
+ * Tests inject ctx.askClaude(prompt, { job, key }) → Promise<string|null>. */
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+ const crypto = require('crypto');
23
+ const { wordsOf } = require('./library-find.js');
24
+
25
+ const MAX = 12, PER_FILE = 3, MIN_LEN = 20;
26
+ const clip = (s, n) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
27
+ const plain = (l) => String(l || '').replace(/^\s*\|\s*|\s*\|\s*$/g, '').replace(/\s*\|\s*/g, ' · ').replace(/^\s*(?:#+|[-*+>]|\d+[.)])\s*/, '').replace(/^\[[ xX]\]\s*/, '').replace(/\*\*|__|`|\[([^\]]*)\]\([^)]*\)/g, (m, a) => a || '').trim();
28
+ const reOf = (w) => new RegExp('(^|[^a-z0-9])' + w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
29
+ const rel = (root, f) => path.relative(root, f).split(path.sep).join('/');
30
+ const linesOf = (f) => { try { return fs.readFileSync(f, 'utf8').replace(/\r\n?/g, '\n').split('\n'); } catch { return null; } };
31
+ const inside = (root, f) => { const a = path.resolve(f); return a === root || a.startsWith(root + path.sep); };
32
+
33
+ function layoutOf(root) {
34
+ try { const l = require('./console-state').loadEngine(); if (l.ok) return l.engine.layout(root); } catch { /* fall through */ }
35
+ const kit = fs.existsSync(path.join(root, 'pmos', 'state'));
36
+ return { root, kit, initiatives: kit ? path.join(root, 'pmos', 'state', 'initiatives') : path.join(root, 'planning', 'initiatives') };
37
+ }
38
+ /** The frontmatter's end (0-based index of the first body line) and its keys. */
39
+ function front(L) {
40
+ const fm = {};
41
+ if (!/^---\s*$/.test(L[0] || '')) return { end: 0, fm };
42
+ let i = 1;
43
+ for (; i < L.length && !/^---\s*$/.test(L[i]); i++) { const m = /^([A-Za-z_][\w]*):\s*(.*)$/.exec(L[i]); if (m && !(m[1] in fm)) fm[m[1]] = m[2].replace(/^["']|["']$/g, '').trim(); }
44
+ return { end: i + 1, fm };
45
+ }
46
+ function titleOf(L, f) { const t = front(L).fm.title; if (t) return t; const h = L.find((l) => /^#\s/.test(l)); return h ? h.replace(/^#\s+/, '').trim() : path.basename(f, '.md'); }
47
+
48
+ /** The newest file of each core document of the initiative (the slots sort by day). */
49
+ function coreDocs(root, L, ini) {
50
+ let base;
51
+ try { base = path.join(root, require('./report-draft.js').stateRel(root)); } catch { base = L.kit ? path.join(root, 'pmos', 'state') : path.join(root, 'planning'); }
52
+ const dir = path.join(base, 'core-docs', 'initiative-' + ini);
53
+ const out = [];
54
+ let keys = [];
55
+ try { keys = fs.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort(); } catch { return out; }
56
+ for (const k of keys) {
57
+ let slots = [];
58
+ try { slots = fs.readdirSync(path.join(dir, k)).filter((f) => f.endsWith('.md')).sort(); } catch { continue; }
59
+ if (slots.length) out.push(path.join(dir, k, slots[slots.length - 1]));
60
+ }
61
+ return out;
62
+ }
63
+
64
+ /** The initiative's own files, read once: [{ path, title, lines, end, record? }]. READ-ONLY. */
65
+ function docsOf(root, ini) {
66
+ root = path.resolve(String(root || ''));
67
+ if (!ini || !/^[a-z0-9][a-z0-9._-]{0,80}$/i.test(ini)) return [];
68
+ const L = layoutOf(root), files = [];
69
+ const rec = path.join(L.initiatives, ini + '.md');
70
+ const RL = linesOf(rec);
71
+ const fm = RL ? front(RL).fm : {};
72
+ if (RL) files.push(rec);
73
+ const cands = [];
74
+ for (const k of ['prd_path', 'prd', 'done_test_path']) if (fm[k]) cands.push(path.join(root, fm[k]), path.join(root, 'pmos', fm[k]));
75
+ cands.push(path.join(root, 'planning', 'prd', ini + '-prd.md'), path.join(root, 'pmos', 'planning', 'prd', ini + '-prd.md'));
76
+ for (const f of cands) { try { if (inside(root, f) && fs.statSync(f).isFile() && !files.includes(path.resolve(f))) files.push(path.resolve(f)); } catch { /* not there */ } }
77
+ for (const f of coreDocs(root, L, ini)) if (!files.includes(f)) files.push(f);
78
+ const out = [];
79
+ for (const f of files.slice(0, 20)) {
80
+ const lines = linesOf(f); if (!lines) continue;
81
+ out.push({ path: rel(root, f), title: titleOf(lines, f), lines, end: front(lines).end, record: f === rec, fm: f === rec ? fm : null });
82
+ }
83
+ return out;
84
+ }
85
+
86
+ /** The record's own first paragraph about the work (its why), or its `description:` line: { line, text } | null. */
87
+ function whyOf(doc) {
88
+ if (doc.fm && doc.fm.description && doc.fm.description.length >= MIN_LEN) {
89
+ const n = doc.lines.findIndex((l) => /^description:/.test(l));
90
+ return { line: n + 1, text: clip(doc.fm.description, 400) };
91
+ }
92
+ let head = '';
93
+ for (let i = doc.end; i < doc.lines.length; i++) {
94
+ const l = doc.lines[i];
95
+ if (/^#{1,6}\s/.test(l)) { head = l; continue; }
96
+ if (!l.trim() || /^\s*([-*+|>]|```|<!--)/.test(l)) continue;
97
+ if (head && !/^#{1,3}\s*(intent|goal|problem|why|background|context|summary|overview)\b/i.test(head) && !/^#\s/.test(head)) continue;
98
+ const t = plain(l);
99
+ if (t.length >= MIN_LEN) return { line: i + 1, text: clip(t, 400) };
100
+ }
101
+ return null;
102
+ }
103
+
104
+ /** The passages about the task, best first. READ-ONLY. task: { title, notes? } */
105
+ function sourcesOf({ root, ini, task } = {}) {
106
+ const docs = docsOf(root, ini);
107
+ const words = wordsOf(String((task && task.title) || ''));
108
+ const out = [], seen = new Set();
109
+ const add = (d, line, text, why = false) => { const k = d.path + ':' + line; if (seen.has(k) || out.length >= MAX) return; seen.add(k); out.push({ n: out.length + 1, path: d.path, line, title: d.title, text: clip(text, 320), ...(why ? { why: true } : {}) }); };
110
+ const rec = docs.find((d) => d.record);
111
+ const why = rec ? whyOf(rec) : null;
112
+ if (why) add(rec, why.line, why.text, true);
113
+ if (!words.length) return [];
114
+ const need = Math.min(2, words.length);
115
+ const df = new Map(), hits = [];
116
+ for (const d of docs) {
117
+ for (let i = d.end; i < d.lines.length; i++) {
118
+ const t = plain(d.lines[i]);
119
+ if (t.length < MIN_LEN || /^---/.test(t)) continue;
120
+ const have = words.filter((w) => reOf(w).test(t));
121
+ if (have.length < need) continue;
122
+ // a line that only repeats the task's title adds nothing; the lines around it are the detail
123
+ hits.push({ d, line: i + 1, t, have });
124
+ for (const w of have) { let s = df.get(w); if (!s) { s = new Set(); df.set(w, s); } s.add(d.path); }
125
+ }
126
+ }
127
+ const nDocs = docs.length || 1;
128
+ const weight = (w) => 1 + Math.log((nDocs + 1) / ((df.get(w) || new Set()).size + 0.5));
129
+ for (const h of hits) h.score = h.have.reduce((a, w) => a + weight(w), 0) * 100 - Math.min(h.t.length, 400) / 10;
130
+ const per = new Map();
131
+ for (const h of hits.sort((a, b) => b.score - a.score || a.d.path.localeCompare(b.d.path) || a.line - b.line)) {
132
+ const c = per.get(h.d.path) || 0; if (c >= PER_FILE) continue;
133
+ per.set(h.d.path, c + 1);
134
+ add(h.d, h.line, h.t);
135
+ // the line under a matching heading or list item often holds the detail: take the next prose line of the same block
136
+ const nx = h.d.lines[h.line];
137
+ if (nx && plain(nx).length >= MIN_LEN && out.length < MAX && per.get(h.d.path) < PER_FILE) { per.set(h.d.path, per.get(h.d.path) + 1); add(h.d, h.line + 1, plain(nx)); }
138
+ }
139
+ // the task itself: no match beyond the why is no source about the task
140
+ return out.length > (why ? 1 : 0) ? out : [];
141
+ }
142
+
143
+ function promptOf(task, list) {
144
+ return [
145
+ 'You write the description of one task in a product manager\'s plan, from passages of their own files. Do not use any tool. Answer with JSON only.',
146
+ `The task: "${clip(task.title, 200)}"` + (task.iniTitle ? ` (part of the initiative "${clip(task.iniTitle, 120)}")` : ''),
147
+ 'The passages, each with the file it comes from:',
148
+ list.map((p) => `${p.n}. [${clip(p.title, 100)}] ${p.text}`).join('\n'),
149
+ 'Write, using ONLY what the passages say. Do not guess and do not add facts, names, numbers or dates the passages do not hold:',
150
+ '- what: one or two plain sentences on what this task does.',
151
+ '- why: one sentence on why it matters for the initiative.',
152
+ '- done: two to four short checks that show the task is done, each one testable.',
153
+ 'Name the numbers of the passages you used. If the passages say nothing about this task, answer {"what":null}.',
154
+ 'Answer: {"what":"…","why":"…","done":["…","…"],"used":[<passage numbers>]}',
155
+ ].join('\n\n');
156
+ }
157
+ /** The session's answer read back, with only passages of the list, or null. Pure. */
158
+ function parse(text, list) {
159
+ const t = String(text || '');
160
+ const at = t.indexOf('{'), end = t.lastIndexOf('}');
161
+ if (at < 0 || end < at) return null;
162
+ let o; try { o = JSON.parse(t.slice(at, end + 1)); } catch { return null; }
163
+ const s = (v, n) => (typeof v === 'string' ? clip(v, n) : '');
164
+ const what = s(o && o.what, 400);
165
+ if (!what) return null;
166
+ const used = [];
167
+ for (const k of Array.isArray(o.used) ? o.used : []) { const p = list.find((x) => x.n === Number(k)); if (p && !used.includes(p)) used.push(p); }
168
+ if (!used.length) return null; // a description that names no passage has no source: it is not kept
169
+ const done = (Array.isArray(o.done) ? o.done : []).map((x) => s(x, 200)).filter(Boolean).slice(0, 5);
170
+ return { what, why: s(o.why, 300), done, used };
171
+ }
172
+ /** The description as plain text: What, Why, Done when. Pure. */
173
+ function textOf(d) {
174
+ const out = ['What: ' + d.what];
175
+ if (d.why) out.push('Why: ' + d.why);
176
+ if (d.done && d.done.length) out.push('Done when:\n' + d.done.map((x) => '- ' + x).join('\n'));
177
+ return out.join('\n\n');
178
+ }
179
+ const CHECK = /\b(done when|acceptance|must|should|passes|verified|criteria|test|check)\b|^\s*-\s*\[[ xX]\]/i;
180
+ /** From the passages' own words, when no session answers. Pure. */
181
+ function fallbackOf(task, list) {
182
+ const whyP = list.find((p) => p.why) || null;
183
+ const about = list.filter((p) => !p.why);
184
+ if (!about.length) return null;
185
+ const whatP = about.find((p) => !CHECK.test(p.text)) || about[0];
186
+ const done = about.filter((p) => p !== whatP && CHECK.test(p.text)).slice(0, 3);
187
+ const used = [whatP, whyP, ...done].filter(Boolean);
188
+ return { what: whatP.text, why: whyP ? whyP.text : '', done: done.map((p) => p.text), used };
189
+ }
190
+
191
+ /* ── the session ── */
192
+ const MODEL = 'claude-sonnet-5-5';
193
+ const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read' }]);
194
+ const TIMEOUT_MS = 90000;
195
+
196
+ function viaSession(ctx, prompt, key) {
197
+ if (typeof ctx.askClaude === 'function') return Promise.resolve(ctx.askClaude(prompt, { job: 'task-describe', key })).catch(() => null);
198
+ const headless = require('./headless.js');
199
+ const origin = 'briefing-ask:task-describe:' + key;
200
+ if (typeof ctx.spawnSession !== 'function' || headless.kindFor({ agent: 'claude', origin }) !== 'ask') return Promise.resolve(null);
201
+ return new Promise((resolve) => {
202
+ let settled = false; const done = (v) => { if (settled) return; settled = true; clearTimeout(t); resolve(v); };
203
+ const t = setTimeout(() => done(null), TIMEOUT_MS);
204
+ let s = null;
205
+ try {
206
+ s = ctx.spawnSession({ name: 'task: write its description', agent: 'claude', origin, initialInput: prompt,
207
+ modelAsk: { explicit: { model: MODEL, effort: 'low' } }, launchFlags: LEAN.map((f) => ({ ...f })),
208
+ onDone: (d) => { const r = d && d.result; done(r && r.ok && !r.isError ? String(r.text || '') : null); } });
209
+ } catch { s = null; }
210
+ if (!s || s.state === 'exited') done(null);
211
+ });
212
+ }
213
+ const srcOf = (p) => ({ path: p.path, line: p.line, title: p.title });
214
+ const dedupe = (used) => { const seen = new Set(); return used.filter((p) => { const k = p.path + ':' + p.line; return !seen.has(k) && seen.add(k); }).slice(0, 6).map(srcOf); };
215
+
216
+ /** The description of one task, written from its sources, or none with why. */
217
+ async function draft(ctx, { root, ini, task } = {}) {
218
+ const t = { title: String((task && task.title) || '').slice(0, 200), iniTitle: (task && task.iniTitle) || '' };
219
+ const list = sourcesOf({ root, ini, task: t });
220
+ if (!list.length) return { ok: true, text: null, why: 'nothing in the initiative\'s files is about this task' };
221
+ const key = crypto.createHash('sha1').update(String(root) + '\n' + ini + '\n' + t.title + '\n' + list.map((p) => p.path + p.text).join('\n')).digest('hex').slice(0, 12);
222
+ const said = await viaSession(ctx || {}, promptOf(t, list), key);
223
+ const d = (said != null && parse(said, list)) || fallbackOf(t, list);
224
+ if (!d) return { ok: true, text: null, why: 'the sources say nothing about this task' };
225
+ return { ok: true, text: textOf(d).slice(0, 4000), sources: dedupe(d.used), made: said != null && !!parse(said, list) };
226
+ }
227
+
228
+ module.exports = { docsOf, sourcesOf, promptOf, parse, textOf, fallbackOf, draft };
@@ -28,7 +28,7 @@ const path = require('path');
28
28
  const ledgers = require('./plan-ledgers.js');
29
29
 
30
30
  const LEDGER = 'initiative-tasks.jsonl';
31
- const TASK_KINDS = Object.freeze(['task', 'task-update', 'task-remove', 'task-restore', 'task-section', 'task-milestone', 'task-pin', 'task-order', 'task-parent', 'task-priority']);
31
+ const TASK_KINDS = Object.freeze(['task', 'task-update', 'task-remove', 'task-restore', 'task-section', 'task-milestone', 'task-pin', 'task-order', 'task-parent', 'task-priority', 'task-description']);
32
32
  const KINDS = new Set(TASK_KINDS);
33
33
  const isTaskKind = (k) => KINDS.has(k);
34
34
  const isTaskLine = (r) => !!r && typeof r === 'object' && !Array.isArray(r) && isTaskKind(r.kind);
@@ -118,7 +118,7 @@ function view(boardLines, storeLines) {
118
118
  /** The task part of a boards fold, as JSON text: equal text = the Board shows the same tasks, dates, places, milestones, pins and orders. */
119
119
  function snapshot(f) {
120
120
  const m = (x) => (x instanceof Map ? [...x.entries()].sort((a, b) => (String(a[0]) < String(b[0]) ? -1 : String(a[0]) > String(b[0]) ? 1 : 0)) : []);
121
- return JSON.stringify({ tasks: m(f.tasks), removed: m(f.removed), sections: m(f.sections), parents: m(f.parents), milestones: m(f.milestones), pins: m(f.pins), orders: m(f.orders),
121
+ return JSON.stringify({ tasks: m(f.tasks), removed: m(f.removed), sections: m(f.sections), parents: m(f.parents), milestones: m(f.milestones), pins: m(f.pins), orders: m(f.orders), descriptions: m(f.descriptions),
122
122
  // the last task-remove of a task is what its Undo reads (routes-boards tasks/restore)
123
123
  removes: (f.events || []).filter((e) => e.kind === 'task-remove').map((e) => [e.task, e.at || null, e.why || null]) });
124
124
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.764.0",
3
+ "version": "0.766.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.764.0",
9
+ "version": "0.766.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.764.0",
3
+ "version": "0.766.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -71,6 +71,9 @@ const look = () => {
71
71
  // at 1280 the chat is the popup's (home-page-retire): its work side shows what opens; ✕ closes the popup, so V1's close and V3's
72
72
  // "Open the Viewer" button are phone checks now (Home's desk page with its list is gone)
73
73
  { const { p, ctx, errs } = await open(1280);
74
+ // the popup with the chat comes after Today's log on a slow machine (CI under load): wait for it rather than read too early
75
+ await until(() => p.evaluate(() => !!document.querySelector('.cz-pop:not([hidden]) #hmChat')), 12000);
76
+ await sleep(300);
74
77
  const s0 = await p.evaluate(look);
75
78
  const popChat = await p.evaluate(() => !!document.querySelector('.cz-pop:not([hidden]) #hmChat'));
76
79
  ok('V1 at 1280 /premium-chat.html opens Today with the conversation in the popup, no file open yet', popChat && s0.conv >= 360 && !/\.md$/.test(s0.title || ''), JSON.stringify(s0));
@@ -51,7 +51,7 @@ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
51
51
  await page.route('**/api/initiative-premium*', (r) => { const u = r.request().url(); S.gets.push(u); if (!r.request().headers()['x-pmos-nonce']) S.vgets.push(u); const a = answer ? answer(u, S.gets.filter((x) => x === u).length) : { status: 200, body: { ok: true, state: 'ready', model: MODEL, as_of: Date.now() } }; r.fulfill({ status: a.status, contentType: 'application/json', body: JSON.stringify(a.body) }); });
52
52
  await page.route('**/api/briefing-premium/**', (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, turns: [], working: false }) }));
53
53
  await page.goto(BASE + '/today.html?ini=self-serve-v2&ws=w1&board=w1&theme=' + theme);
54
- S.up = await until(() => page.evaluate(() => !!document.querySelector('#czViewer .iv-mc') && !!window.__premiumWorkItem), 20000);
54
+ S.up = await until(() => page.evaluate(() => !!document.querySelector('#czViewer .iv-mc') && !!window.__premiumWorkItem), 45000); // the server's first reads take ~17s on main here and more on a busy CI runner
55
55
  // When Home does not come up, say what the page holds instead, so a CI-only failure can be read from the log.
56
56
  if (!S.up) console.log(' (R9 not up: ' + JSON.stringify(await page.evaluate(() => { const v = document.querySelector('#czViewer'); return { url: location.pathname + location.search, viewer: v ? { hidden: v.hidden, w: v.getBoundingClientRect().width, cls: v.className, html: v.innerHTML.replace(/\s+/g, ' ').slice(0, 300) } : null, item: !!window.__premiumWorkItem, body: document.body.className, fs: getComputedStyle(document.documentElement).getPropertyValue('--fs-body') }; }).catch((e) => String(e))) + ' errors ' + JSON.stringify(S.errors.slice(0, 3)) + ' gets ' + S.gets.length + ')');
57
57
  return { page, ctx, S };
@@ -191,7 +191,7 @@ const TICKETS = {
191
191
  await I.page.click('#czViewer [data-iv-ticket="PMOS-142"]');
192
192
  ok('I2 a Jira ticket in the page\'s Tasks opens its ticket in the Viewer', !!(await until(async () => /^jira:PMOS-142$/.test(String(await curId(I.page))))), JSON.stringify(await curId(I.page)));
193
193
  await I.page.goto(BASE + '/premium-initiative.html?id=self-serve-v2&ws=w1&board=w1');
194
- ok('I1 the initiative loads the Jira view module without a page error', !!(await until(() => I.page.evaluate(() => !!window.__premiumVwJira))) && I.errors.length === 0, I.errors.join(' | '));
194
+ ok('I1 the initiative loads the Jira view module without a page error', !!(await until(() => I.page.evaluate(() => !!window.__premiumVwJira), 20000)) && I.errors.length === 0, I.errors.join(' | '));
195
195
  await I.ctx.close();
196
196
  }
197
197
 
@@ -620,6 +620,8 @@ async function popPress(e) {
620
620
  }
621
621
  }
622
622
 
623
+ /** Draw the open program panel again from the programs the page has now (after a chat turn re-read them). Nothing open: nothing. */
624
+ export function refresh() { if (O && cur && shownHere()) draw(); }
623
625
  export function mount(o) {
624
626
  if (O) return;
625
627
  O = o;
@@ -196,6 +196,7 @@ body.cz-home { min-height: 100vh; overflow: hidden; }
196
196
  .hm-ren .sv { width: 32px; height: 32px; border-radius: var(--radius-pill, 999px); border: 0; background: var(--cz-solid); color: var(--cz-onsolid); display: inline-flex; align-items: center; justify-content: center; flex: none; cursor: pointer; }
197
197
  .hm-ren .sv:disabled { opacity: .6; cursor: default; }
198
198
  .hm-renerr { margin: var(--space-4) 0 0 10px; font-size: var(--fs-meta); color: var(--cz-red); line-height: var(--lh-meta); }
199
+ .hm-senderr { flex-basis: 100%; order: 10; margin: var(--space-4) 0 0; padding: 0 var(--space-8); font-size: var(--fs-meta); color: var(--cz-red); line-height: var(--lh-meta); } /* a send that failed says why (home-chat.js errRow) */
199
200
  .hm-chs { flex: 0 1 auto; min-width: 0; height: 28px; padding: 0 10px; border-radius: var(--radius-pill, 999px); background: var(--cz-well); color: var(--cz-ink2); font-size: var(--fs-label); font-weight: var(--fw-strong); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: var(--lh-label); }
200
201
  .hm-chs > span { overflow: hidden; text-overflow: ellipsis; }
201
202
  .hm-chs .hv-mt { margin-left: 0; }
@@ -53,6 +53,7 @@ const S = {
53
53
  el: null, card: null, left: null, right: null, box: null, all: null, menu: null, toast: null, tools: null, title: null, st: null,
54
54
  open: false, about: null, home: null, chat: null, back: null, raw: [], rows: { now: [], earlier: [], all: [] }, view: 'chat', q: '', prev: null,
55
55
  ending: new Map(), timer: 0, toastT: 0, titles: null, opener: null, w: 0, seq: 0,
56
+ base: null, views: new Map(), bind: undefined, // base: what the popup was opened about; views: Viewer item id → what its chat is about
56
57
  };
57
58
 
58
59
  /* ── the page's hooks ── */
@@ -156,7 +157,17 @@ function drawDot() { const d = S.tools && S.tools.querySelector('.cz-pop-dot');
156
157
 
157
158
  /* ── open and close ── */
158
159
  VW.popHook({ host: () => { frame(); return S.left; }, show });
159
- VW.onChange((d) => { if (d && d.pop && d.shut && S.open) hide(); });
160
+ VW.onChange((d) => {
161
+ if (!d || !d.pop) return;
162
+ if (d.shut) { if (S.open) hide(); return; }
163
+ if (!S.open || RO || !d.open || d.id == null) return;
164
+ // the item an open with pop put on the left: its chat is the popup's base (show, retarget)
165
+ if (S.bind !== undefined) { S.views.set(d.id, S.bind); S.bind = undefined; return; }
166
+ // ← or → back to an item shown before: the chat goes back to that item's chat (the initiative's, after a task)
167
+ if (S.views.has(d.id)) { aboutItem(S.views.get(d.id)); return; }
168
+ // a drill-in that says what it is (chatAbout: a task, a milestone): the chat moves to it, unless the chat opened it itself
169
+ if (d.chatAbout && !d.viaChat) { const a = itemAbout(d.chatAbout); if (a) { S.views.set(d.id, a); aboutItem(a); } }
170
+ });
160
171
  /** cozy-viewer.js calls this as an item goes into the popup. A popup already open keeps its chat: the work on the left changes, the chat stays. */
161
172
  function show(pop) {
162
173
  if (S.open) { retarget(pop); return; }
@@ -172,7 +183,8 @@ function show(pop) {
172
183
  S.el.hidden = false; document.body.classList.add('cz-pop-on');
173
184
  S.all.hidden = true; closeMenu();
174
185
  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;
186
+ 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;
187
+ S.base = S.about; S.views = new Map(); S.bind = S.base;
176
188
  width(parseInt(store.get('cz-pop-chat') || '', 10) || DEF_CHAT);
177
189
  // 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
190
  S.userSet = false;
@@ -187,8 +199,12 @@ function show(pop) {
187
199
  * item's scope ("In: <title>"), so it never keeps the previous item's conversation beside it. The same item, or none, changes nothing. */
188
200
  function retarget(pop) {
189
201
  const p = pop && typeof pop === 'object' ? pop : null;
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 };
202
+ if (!p || !p.id || p.keep || (S.base && S.base.id === p.id)) {
203
+ if (p && p.id && S.base && S.base.id === p.id) { S.bind = S.base; aboutItem(null); } // the popup's own item again: its own chat
204
+ return;
205
+ }
206
+ S.about = { id: p.id, kind: p.kind || 'initiative', title: p.title || '', ws: p.ws, ...(p.path ? { path: p.path } : {}) };
207
+ S.base = S.about; S.bind = S.base;
192
208
  S.userSet = false;
193
209
  chatOn(!!(p.target || p.chat || recentOn(S.about)));
194
210
  attach(p.target || aboutTarget(S.about), null);
@@ -225,8 +241,31 @@ function aboutTarget(a) {
225
241
  async function resolve(t) {
226
242
  if (!t || !t.__about) return t;
227
243
  const M = await pageChat(), a = t.__about;
244
+ if (a.item) { const x = M.itemTarget(a, a.ws); if (x) return x; } // a task, a milestone: its own conversation, with the item read in
228
245
  return M.keyOf(a) ? M.popTarget(a, a.ws) : M.cosTarget(a.title || '', a.ws);
229
246
  }
247
+ /** An item inside the popup's work (a task or a milestone over the initiative, bug 2026-11-24): { id, kind, title, ws?, parent?, subject?,
248
+ * say?, facts? }. null without an id and a title. */
249
+ function itemAbout(a) {
250
+ if (!a || !a.id || !a.title) return null;
251
+ return { id: String(a.id), kind: String(a.kind || 'item').toLowerCase(), title: String(a.title), ws: a.ws || (S.base && S.base.ws) || undefined, item: true,
252
+ parent: a.parent || '', subject: a.subject || '', say: a.say || '', facts: Array.isArray(a.facts) ? a.facts : [] };
253
+ }
254
+ const sameAbout = (a, b) => (!a && !b) || (!!a && !!b && a.id === b.id && (a.kind || '') === (b.kind || '') && !!a.item === !!b.item);
255
+ /** The chat moves to an item inside the popup's work (a task, a milestone; Wawan 2026-11-24: "When open chat from a task page, chat session
256
+ * should be about the task"), or back to the popup's own item with null (or the base itself). The work on the left stays; whether the chat
257
+ * shows does not change. The item's sessions and the initiative's stay in the session chooser. Returns false when the popup is not open. */
258
+ export function aboutItem(a) {
259
+ if (!S.open || RO) return false;
260
+ const next = !a || a === S.base ? S.base : a.item ? a : itemAbout(a);
261
+ if (!next && a) return false;
262
+ if (sameAbout(next, S.about)) return true;
263
+ S.about = next;
264
+ if (next) attach(aboutTarget(next), null);
265
+ else pageChat().then((M) => { if (S.open && !S.about) attach(M.cosTarget(''), null); }); // opened on the list of sessions: the chat over everything
266
+ drawDot(); read();
267
+ return true;
268
+ }
230
269
  async function attach(want, row) {
231
270
  const my = ++S.seq;
232
271
  const P = await provider();
@@ -299,6 +338,7 @@ function rowHtml(r, sel) {
299
338
  + `<em class="${r.state}">${esc(r.word)}</em>`
300
339
  + (r.live ? `<button type="button" class="cz-pop-x" data-end="${esc(r.id)}" aria-label="${esc('End ' + r.name)}" title="End this session"><i></i></button>` : '<span></span>') + '</div>';
301
340
  }
341
+ const kindWord = (k) => { const s = String(k || '').replace(/[-_]+/g, ' ').trim(); return s ? s[0].toUpperCase() + s.slice(1) : 'About'; };
302
342
  function drawTitle() {
303
343
  if (!S.title || !S.open) return;
304
344
  if (S.view === 'all') {
@@ -316,7 +356,8 @@ function drawTitle() {
316
356
  }
317
357
  delete S.title.dataset.ren;
318
358
  // one quiet context line under the session (round 3 point 19a, the phone chat's line): what the chat is about, said once
319
- const a = S.about, cx = a && a.title ? (a.kind === 'initiative' ? 'Initiative' : a.kind === 'program' ? 'Program' : 'About') + ' · ' + a.title : '';
359
+ const a = S.about, cx = a && a.item ? kindWord(a.kind) + (a.parent ? ' in ' + a.parent : ' · ' + a.title)
360
+ : a && a.title ? (a.kind === 'initiative' ? 'Initiative' : a.kind === 'program' ? 'Program' : 'About') + ' · ' + a.title : '';
320
361
  S.title.innerHTML = `<button type="button" class="cz-pop-t" data-pop="pick" aria-haspopup="menu" aria-expanded="${on}" title="Change session" aria-label="${esc(name + '. Change session')}"><span>${esc(name)}</span>${svg(I.down, 16)}</button>`
321
362
  + (cx ? `<small class="cz-pop-cx" title="${esc(cx)}">${esc(cx)}</small>` : '');
322
363
  }
@@ -501,4 +542,4 @@ export async function openCos(t) {
501
542
  VW.open(sessionsItem({ target: t }));
502
543
  return true;
503
544
  }
504
- if (typeof window !== 'undefined') { window.czOpenChat = openChat; window.czPopup = { openChat, openCos, openWork, chatTo, close, isOpen, useChat, setTitles, setOpener }; }
545
+ if (typeof window !== 'undefined') { window.czOpenChat = openChat; window.czPopup = { openChat, openCos, openWork, chatTo, close, isOpen, useChat, setTitles, setOpener, aboutItem }; }
@@ -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); }
@@ -7,7 +7,8 @@
7
7
  * pressed, becomes a field; Enter or leaving it saves), onClose?(uid) (the host
8
8
  * lights the row), openIni?(id),
9
9
  * full?: true → the full popup over the work side of the popup (work-ds-quick-edit, WorkStatesDS 4 and 6): ← and the
10
- * path (path?: [crumb]) go back to the initiative, chat?() shows the popup's chat, × closes the task and the popup
10
+ * path (path?: [crumb]) go back to the initiative, chat?(about) shows the chat about the task (with the one popup
11
+ * open, its chat already moved to the task as the task opened: window.czPopup.aboutItem), × closes the task and the popup
11
12
  * (closeAll?()); head?(t) → html under the title (a milestone's date, done test and suggestion), its presses go to
12
13
  * headPress?(button, { refresh, close }) }
13
14
  * closeTask() closes it, as ✕, Esc or a press outside do. Esc closes only the small popup.
@@ -16,7 +17,7 @@
16
17
  * where it sits, what PMOS changed) whose status pick asks when it really happened (pm/cozy-status-when.js, point 18); ⋯ with Make it a
17
18
  * milestone, Archive and Delete (Undo). No chat inside: one level only, a second task replaces the content. On a phone it is a sheet from the bottom.
18
19
  * Every write is the PM's press, on the board's own routes. The UI says PMOS, never Claude; icon-only buttons carry aria-label. */
19
- import { taskOf, mountCard, boardSaver, cardStyle, historyFor } from './task-card.js';
20
+ import { taskOf, mountCard, boardSaver, cardStyle, historyFor, chatAbout } from './task-card.js';
20
21
  import * as SWN from './cozy-status-when.js';
21
22
  import { linkPath, copyLink } from './short-link.js'; // Copy link in ⋯ (bet A428)
22
23
  import * as VD from './vw-ds.js'; // viewer-ds-task (board ViewerDS): the full popup's Where it stands, Linked and Activity blocks
@@ -45,10 +46,11 @@ async function rowOf(uid, ctx) {
45
46
  return it ? { ...(own || {}), ...it } : own || null;
46
47
  }
47
48
 
48
- export function closeTask() {
49
+ export function closeTask(o = {}) {
49
50
  if (!S) return;
50
51
  const S0 = S, { el, scrim, uid, ctx, prevFocus } = S;
51
52
  S = null;
53
+ if (S0.chatOn && !o.all) popChat(null); // the popup stays: its chat goes back to the initiative's
52
54
  document.removeEventListener('keydown', onKey, true);
53
55
  if (S0.ro) S0.ro.disconnect(); if (S0.offPop) document.removeEventListener('click', S0.offPop, true); window.removeEventListener('resize', place);
54
56
  el.remove(); scrim.remove();
@@ -66,6 +68,13 @@ function place() {
66
68
  Object.assign(S.el.style, { left: r.left + 'px', top: r.top + 'px', width: r.width + 'px', height: r.height + 'px' });
67
69
  }
68
70
 
71
+ /** The one popup's chat moves to the task (or back, with null). false when no popup is open (the task is on its own: its chat press opens one). */
72
+ function popChat(a) {
73
+ const P = typeof window !== 'undefined' ? window.czPopup : null;
74
+ if (!P || typeof P.aboutItem !== 'function' || !P.isOpen || !P.isOpen()) return false;
75
+ return P.aboutItem(a);
76
+ }
77
+
69
78
  function onKey(e) {
70
79
  if (!S) return;
71
80
  if (e.key === 'Escape') {
@@ -97,11 +106,12 @@ export async function openTask(uid, ctx = {}) {
97
106
  if (L && typeof ResizeObserver !== 'undefined') { S.ro = new ResizeObserver(place); S.ro.observe(L); }
98
107
  window.addEventListener('resize', place); place();
99
108
  // the popup behind closing (its scrim or its own ×) takes the full popup with it
100
- S.offPop = (e) => { if (e.target.closest && e.target.closest('.cz-pop [data-pop="close"]')) closeTask(); };
109
+ S.offPop = (e) => { if (e.target.closest && e.target.closest('.cz-pop [data-pop="close"]')) closeTask({ all: true }); };
101
110
  document.addEventListener('click', S.offPop, true);
102
111
  }
103
112
  document.addEventListener('keydown', onKey, true);
104
113
  el.addEventListener('click', press);
114
+ el.addEventListener('focusout', descOut); // the description saves when the PM leaves its box (task-descriptions)
105
115
  // the status pick waits for the day (point 18): the card's own press is held here, the line opens under the card
106
116
  el.addEventListener('click', holdStatus, true);
107
117
  }
@@ -120,6 +130,8 @@ async function show(uid) {
120
130
  if (!raw) { S.el.innerHTML = `<div class="ctp-h">${ib('data-ctp-close', 'Close', P.x)}</div><p class="ctp-none">This task could not be read. It may have been removed.</p>`; return; }
121
131
  const t = taskOf(raw, { iniTitle: ctx.iniTitle ? ctx.iniTitle(raw.ini || ctx.ini) : '', board: ctx.board, ini: ctx.ini });
122
132
  S.raw = raw; S.t = t; S.nextDay = null;
133
+ // the full popup over the one popup: the chat beside it is about this task now, not its initiative (bug 2026-11-24); ← gives it back
134
+ if (ctx.full) S.chatOn = popChat(chatAbout(t, raw)) || S.chatOn;
123
135
  const L = ctx.list ? ctx.list() : [], i = L.indexOf(uid);
124
136
  const kind = `<button type="button" class="ctp-kind" data-ctp-kind aria-label="${esc(t.milestone ? 'Milestone. Make it a task' : 'Task. Make it a milestone')}"${t.jira ? ' disabled' : ''}>${SVG(t.milestone ? P.dia : P.box)}<span>${t.milestone ? 'Milestone' : 'Task'}</span></button>`;
125
137
  const title = !t.jira && ctx.rename ? `<button type="button" class="ctp-t" data-ctp-rename aria-label="${esc('Rename ' + t.title)}">${esc(t.title)}</button>` : `<span class="ctp-t">${esc(t.title)}</span>`;
@@ -138,7 +150,7 @@ async function show(uid) {
138
150
  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
151
  + `<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
152
  + `<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>`
153
+ + `<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
154
  + '<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
155
  } else {
144
156
  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 +178,7 @@ async function show(uid) {
166
178
  // the full popup says PMOS's changes once, in its Activity block; the small popup keeps the card's History fold
167
179
  history: ctx.full ? null : S.hist,
168
180
  });
169
- if (ctx.full) { drawMain(); loadActivity(); }
181
+ if (ctx.full) { drawMain(); loadActivity(); describe(); }
170
182
  const f = S.el.querySelector('.ctp-t') || S.el.querySelector('button'); if (f) f.focus();
171
183
  }
172
184
  /* 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 +186,50 @@ function drawMain() {
174
186
  if (!S || !S.ctx.full || !S.t) return;
175
187
  const put = (sel, html) => { const x = S.el.querySelector(sel); if (x) x.innerHTML = html; };
176
188
  put('.ctp-stands', VD.standsHtml(S.t, { waits: S.ctx.waits ? S.ctx.waits(S.t) : '' }));
189
+ // the description (initiative task-descriptions): never redrawn under the PM's typing
190
+ const dw = S.el.querySelector('.ctp-descw');
191
+ 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
192
  put('.ctp-linked', VD.linkedHtml(S.t));
178
193
  put('.ctp-act', VD.activityHtml(S.histL || [], { open: !!S.aopen }));
179
194
  }
195
+ /* 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
196
+ * own files, with its sources and Undo. The server never writes it twice, so opening the task again costs nothing. */
197
+ async function describe() {
198
+ const s = S; if (!s || s.t.jira || s.t.description || !s.ctx.pmPost) return;
199
+ s.dbusy = true; drawMain();
200
+ 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);
201
+ s.dbusy = false;
202
+ if (S !== s) return;
203
+ if (r && r.ok && r.wrote && !s.t.description) {
204
+ Object.assign(s.t, { description: r.description, descBy: 'pmos', descSources: r.sources || [] });
205
+ s.raw.description = r.description; s.raw.descBy = 'pmos'; s.raw.descSources = r.sources || [];
206
+ s.dundo = true;
207
+ if (s.ctx.onChange) s.ctx.onChange();
208
+ }
209
+ drawMain();
210
+ }
211
+ /** Save the description (the PM's words, or '' for PMOS's Undo) through tasks/edit, with Undo in the toast. */
212
+ async function saveDesc(text, { word = 'Description saved' } = {}) {
213
+ const s = S; if (!s) return;
214
+ const before = { description: s.t.description, descBy: s.t.descBy, descSources: s.t.descSources };
215
+ 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 });
216
+ const set = (o) => { Object.assign(s.t, o); s.raw.description = o.description; s.raw.descBy = o.descBy; s.raw.descSources = o.descSources; };
217
+ set({ description: text, descBy: text ? 'you' : '', descSources: [] }); s.dedit = false; s.dundo = false; drawMain();
218
+ const r = await post(text).catch(() => null);
219
+ 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; }
220
+ if (s.ctx.onChange) s.ctx.onChange();
221
+ if (s.ctx.toast) s.ctx.toast(word, async () => {
222
+ const u = await post(before.description || '').catch(() => null);
223
+ if (u && u.ok !== false) { set(before); if (S === s) drawMain(); if (s.ctx.onChange) s.ctx.onChange(); }
224
+ return u || { ok: false };
225
+ });
226
+ }
227
+ function descOut(e) {
228
+ const a = e.target; if (!S || !a.matches || !a.matches('[data-ctp-desc]')) return;
229
+ const v = a.value.replace(/\s+$/, '');
230
+ if (v === (S.t.description || '')) { if (S.dedit) { S.dedit = false; setTimeout(drawMain, 0); } return; }
231
+ saveDesc(v, { word: v ? 'Description saved' : 'Description cleared' });
232
+ }
180
233
  function loadActivity() {
181
234
  const s = S; if (!s || !s.hist) return;
182
235
  Promise.resolve(s.hist.load()).catch(() => []).then((L) => { if (S !== s) return; s.histL = Array.isArray(L) ? L : []; drawMain(); });
@@ -219,10 +272,12 @@ async function press(e) {
219
272
  return;
220
273
  }
221
274
  if ('ctpAfold' in d) { S.aopen = true; drawMain(); return; }
275
+ 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; }
276
+ if ('ctpDundo' in d) { saveDesc('', { word: 'PMOS\'s description taken back' }); return; }
222
277
  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
278
  if ('ctpClose' in d) { closeTask(); return; }
224
- if ('ctpChat' in d) { if (ctx.chat) ctx.chat(); return; }
225
- if ('ctpX' in d) { const all = ctx.closeAll; closeTask(); if (all) all(); return; }
279
+ if ('ctpChat' in d) { if (t) S.chatOn = popChat(chatAbout(t, S.raw)) || S.chatOn; if (ctx.chat) ctx.chat(t ? chatAbout(t, S.raw) : null); return; }
280
+ if ('ctpX' in d) { const all = ctx.closeAll; closeTask({ all: !!all }); if (all) all(); return; }
226
281
  if (d.ctpStep) { const L = ctx.list ? ctx.list() : [], j = L.indexOf(S.uid) + Number(d.ctpStep); if (j >= 0 && j < L.length) show(L[j]); return; }
227
282
  if ('ctpRename' in d && t && ctx.rename) { renameField(b); return; }
228
283
  if ('ctpKind' in d && t) { kindOf(!t.milestone); return; }