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
@@ -40,7 +40,8 @@
40
40
  * at once (initiative work-subtasks, WorkBulkDS), each through the single route; a Jira ticket keeps its stage, assignee and status
41
41
  * POST /api/boards/tasks/bulk-undo { ws, board, undo } → { ok, back, failed } the one Undo of a bulk move
42
42
  * POST /api/boards/tasks/rename { ws, board, task, title } → { ok, from, item } only the title changes
43
- * POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative?, section?, milestone?, pinned?, parent? } → { ok, from, item } the Viewer's edits in place
43
+ * POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative?, section?, milestone?, pinned?, parent?, description? } → { ok, from, item } the Viewer's edits in place
44
+ * POST /api/boards/tasks/describe-draft { ws, board, task } → { ok, wrote, description?, sources?, from? } PMOS writes a task's description once (task-descriptions)
44
45
  * (parent: the task it sits under, '' for the top level; a task-parent line, any kind of task, a loop refused)
45
46
  * (milestone: true | false, the ◇ flag of batch 11 item 3; a Jira key takes the flag only)
46
47
  * (pinned: true | false | null, a milestone's pin on the Board timeline, batch 13 item 4; null = the rule, the last one only)
@@ -119,6 +120,8 @@ const OS = require('./one-stage.js');
119
120
  const LEDGER = 'boards.jsonl';
120
121
  const SELF_REFUSAL = 'PMOS keeps its derived ladder: its stages come from scripts/workflow-state.js, so a move or a workflow edit is refused here';
121
122
  const NO_STATE = 'This repository has no PMOS state folder (pmos/state, state or .pmos). Boards read with the defaults, and nothing is saved until the folder exists.';
123
+ const DESC_MAX = 4000;
124
+ const describing = new Map(); // task id → the describe-draft running for it (two opens make one draft) // a task's description (task-descriptions)
122
125
  const PENDING = 'The initiatives are being read. Ask again in a few seconds.';
123
126
  const ONE_LINE = (v, max) => typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= max && !/[\r\n\x00-\x08\x0b-\x1f]/.test(v);
124
127
  const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
@@ -188,6 +191,10 @@ function withTracker(w, f, key, lines) {
188
191
  trackerMemo.set(f, { key: k, lines: all });
189
192
  return all.slice();
190
193
  }
194
+ /** A folded description as item fields: { description, descBy: 'pmos' | 'you', descSources } (task-descriptions). Never the session token. */
195
+ function descFields(d) {
196
+ return { description: d.text, descBy: /^agent:/.test(String(d.by || '')) ? 'pmos' : 'you', descSources: (d.sources || []).map((x) => ({ path: x.path, line: x.line || null, title: x.title || '' })) };
197
+ }
191
198
  function append(file, actor, ev) {
192
199
  const line = { at: new Date().toISOString(), by: actor.by, ...ev };
193
200
  // a task line is the initiative's (D104): it goes to the initiative ledger; only when that ledger cannot be placed does it stay here
@@ -878,6 +885,9 @@ function itemsOf(w, fr, board, rows) {
878
885
  // the PM's priority (inline-sprint-priority): carried only when set
879
886
  const PR = fr.folded.priorities || new Map();
880
887
  if (PR.size) for (const x of out) if (x.kind !== 'Epic' && x.src !== 'jira' && PR.has(x.uid)) x.priority = PR.get(x.uid);
888
+ // the task's description (task-descriptions): carried only when set; descBy 'pmos' when PMOS wrote the last one, with its sources
889
+ const DS = fr.folded.descriptions || new Map();
890
+ if (DS.size) for (const x of out) if (x.src !== 'jira' && DS.has(x.uid)) Object.assign(x, descFields(DS.get(x.uid)));
881
891
  return B.rollupItems(out);
882
892
  }
883
893
 
@@ -1669,7 +1679,7 @@ const WRITES = {
1669
1679
  // a Jira ticket takes the milestone flag (feedback batch 11 item 3) and the PM's own start and due days, kept in PMOS only (item 23):
1670
1680
  // Jira keeps its title, status and assignee, and nothing is written to Jira
1671
1681
  if (typeof body.task === 'string' && B.JIRA_KEY_RE.test(body.task) && !B.taskOf(p.fr.folded, body.task)) {
1672
- if (['owner', 'notes', 'initiative', 'section', 'priority'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates, its milestone flag and its pin change here');
1682
+ if (['owner', 'notes', 'initiative', 'section', 'priority', 'description'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates, its milestone flag and its pin change here');
1673
1683
  if (body.milestone == null && body.start == null && body.due == null && body.pinned === undefined && body.parent == null) return fail(ctx, res, 400, 'nothing to change: send start, due, milestone, pinned or parent');
1674
1684
  if (body.parent != null) { const pe = parentError(p, body.task, body.parent, null); if (pe) return fail(ctx, res, 400, pe); }
1675
1685
  for (const k of ['start', 'due']) if (body[k] != null && body[k] !== '' && !/^\d{4}-\d{2}-\d{2}$/.test(String(body[k]))) return fail(ctx, res, 400, `${k} is a day, YYYY-MM-DD, or '' for none`);
@@ -1753,12 +1763,21 @@ const WRITES = {
1753
1763
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
1754
1764
  par = body.parent; from.parent = (p.fr.folded.parents || new Map()).get(t.id) || '';
1755
1765
  }
1756
- if (!Object.keys(ev).length && sec == null && ms == null && !pin && !prio && par == null) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, initiative, section, milestone, pinned, priority or parent');
1766
+ // the description (task-descriptions): a board-ledger line for every kind of task, like the priority. PMOS's own draft carries its sources
1767
+ let desc = null;
1768
+ if (body.description != null) {
1769
+ if (typeof body.description !== 'string' || body.description.length > DESC_MAX) return fail(ctx, res, 400, `description is text of at most ${DESC_MAX} characters`);
1770
+ if (!p.file) return fail(ctx, res, 409, NO_STATE);
1771
+ const d0 = (p.fr.folded.descriptions || new Map()).get(t.id);
1772
+ desc = body.description.replace(/\s+$/, ''); from.description = d0 ? d0.text : '';
1773
+ }
1774
+ if (!Object.keys(ev).length && sec == null && ms == null && !pin && !prio && par == null && desc == null) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, initiative, section, milestone, pinned, priority, parent or description');
1757
1775
  if (sec != null) append(p.file, g.actor, { kind: 'task-section', board: p.board.id, task: t.id, section: sec, why: sec ? 'placed under ' + sec : 'placed under no stage' });
1758
1776
  if (ms != null) append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: t.id, milestone: ms, why: ms ? 'made a milestone' : 'no longer a milestone' });
1759
1777
  if (pin) append(p.file, g.actor, pinLine(t.id));
1760
1778
  if (prio) { append(p.file, g.actor, { kind: 'task-priority', board: p.board.id, task: t.id, priority: body.priority, why: body.priority ? 'priority ' + body.priority : 'no priority' }); console.info('[inline-field] priority'); }
1761
1779
  if (par != null) append(p.file, g.actor, parentLine(p, t.id, par));
1780
+ if (desc != null) append(p.file, g.actor, { kind: 'task-description', board: p.board.id, task: t.id, description: desc, ...(Array.isArray(g.sources) && desc ? { sources: g.sources } : {}), why: desc ? (g.sources ? 'written from ' + g.sources.length + (g.sources.length === 1 ? ' source' : ' sources') : 'description edited') : 'description cleared' });
1762
1781
  if (!Object.keys(ev).length) {
1763
1782
  const items = itemsOf(p.w, { ...p.fr, folded: B.fold(readLedger(ctx, p.w)) }, p.board, (needRows(ctx, res, p.w) || []).filter((r) => r.id === t.initiative));
1764
1783
  return ctx.json(res, { ok: true, from, item: items.find((x) => x.uid === t.id) || null });
@@ -1773,6 +1792,38 @@ const WRITES = {
1773
1792
  if (F2.priorities && F2.priorities.has(t.id)) it2.priority = F2.priorities.get(t.id);
1774
1793
  ctx.json(res, { ok: true, from, item: it2 });
1775
1794
  },
1795
+ '/api/boards/tasks/describe-draft': async (ctx, res, body, g) => {
1796
+ // PMOS writes a task's description by itself (initiative task-descriptions): once per task, from the initiative's own files, with its
1797
+ // sources, as agent:auto, through tasks/edit so the page's Undo is the same save. A task whose description was ever set (or undone)
1798
+ // is never drafted again: the PM's word stands. Nothing about the task in the files: nothing is written.
1799
+ const p = postFrame(ctx, res, body);
1800
+ if (!p) return;
1801
+ if (typeof body.task !== 'string' || !body.task || body.task.length > 80) return fail(ctx, res, 400, 'task is a task id');
1802
+ if (B.JIRA_KEY_RE.test(body.task) && !B.taskOf(p.fr.folded, body.task)) return ctx.json(res, { ok: true, wrote: false, why: 'Jira keeps this ticket\'s description' });
1803
+ let t = B.taskOf(p.fr.folded, body.task);
1804
+ if (!t && TI.isItemId(body.task)) { const it = TI.itemOf(p.w.root, body.task); if (it) t = { id: it.id, title: it.title, initiative: it.initiative, notes: it.note || '' }; }
1805
+ if (!t) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1806
+ const ever = (p.fr.folded.events || []).some((e) => e.kind === 'task-description' && e.task === t.id);
1807
+ if (ever) return ctx.json(res, { ok: true, wrote: false, why: 'it has a description, or had one' });
1808
+ const busy = describing.get(t.id);
1809
+ if (busy) return ctx.json(res, await busy);
1810
+ const run = (async () => {
1811
+ let iniTitle = '';
1812
+ try { const b0 = (baseRows(p.w).rows || []).find((r) => r.id === t.initiative); iniTitle = (b0 && b0.title) || ''; } catch { iniTitle = ''; }
1813
+ let d;
1814
+ try { d = await require('./task-describe.js').draft(ctx, { root: p.w.root, ini: t.initiative, task: { title: t.title, iniTitle } }); } catch (e) { d = { ok: true, text: null, why: 'the description could not be written' }; }
1815
+ if (!d.text) { console.log('[task-describe] none'); return { ok: true, wrote: false, why: d.why }; }
1816
+ // written while the session ran: the PM's word stands
1817
+ const F = B.fold(readLedger(ctx, p.w));
1818
+ if ((F.events || []).some((e) => e.kind === 'task-description' && e.task === t.id)) return { ok: true, wrote: false, why: 'it has a description now' };
1819
+ const r = writeAs(ctx, '/api/boards/tasks/edit', { ws: body.ws, board: body.board, task: t.id, description: d.text }, { ok: true, actor: { by: 'agent:auto', via: 'ui' }, sources: d.sources });
1820
+ if (!r.body || r.body.ok === false) { console.log('[task-describe] none'); return { ok: true, wrote: false, why: (r.body && r.body.error) || 'it was not saved' }; }
1821
+ console.log('[task-describe] wrote');
1822
+ return { ok: true, wrote: true, description: d.text, sources: d.sources, from: { description: '' }, item: r.body.item || null };
1823
+ })();
1824
+ describing.set(t.id, run);
1825
+ try { ctx.json(res, await run); } finally { describing.delete(t.id); }
1826
+ },
1776
1827
  '/api/boards/tasks/bulk': (ctx, res, body, g) => {
1777
1828
  // bulk move (initiative work-subtasks, board WorkBulkDS): several tasks under a parent, to a stage, to a person, by N days, or to Done.
1778
1829
  // Each task goes through the same route a single press uses; the answer's `undo` puts every one back in one press (tasks/bulk-undo)
@@ -1828,7 +1879,7 @@ const WRITES = {
1828
1879
  else if (x.op === 'shift') r = writeAs(ctx, '/api/boards/tasks/reschedule', { ...base, task: x.task, days: -Number(x.from.days) }, g);
1829
1880
  else {
1830
1881
  const from = {};
1831
- for (const k of ['owner', 'notes', 'start', 'due', 'initiative', 'section', 'parent']) if (typeof x.from[k] === 'string') from[k] = x.from[k];
1882
+ for (const k of ['owner', 'notes', 'start', 'due', 'initiative', 'section', 'parent', 'description']) if (typeof x.from[k] === 'string') from[k] = x.from[k];
1832
1883
  if (typeof x.from.milestone === 'boolean') from.milestone = x.from.milestone;
1833
1884
  if (!Object.keys(from).length) continue;
1834
1885
  r = writeAs(ctx, '/api/boards/tasks/edit', { ...base, task: x.task, ...from }, g);
@@ -2168,6 +2219,12 @@ function taskState(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/state'
2168
2219
  function taskAdd(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/add', body, g); }
2169
2220
  /** A task's edit, by the same function as the Viewer's (POST /api/boards/tasks/edit; `pmos task set`). body: { ws, board, task, section?, start?, due?, owner?, notes? }. */
2170
2221
  function taskEdit(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/edit', body, g); }
2222
+ /** PMOS's own description of a task (POST /api/boards/tasks/describe-draft; task-descriptions). → Promise<{ status, body }> after the draft. */
2223
+ async function describeDraft(ctx, body, g) {
2224
+ let out = { status: 500, body: { ok: false, error: 'the draft was not answered' } };
2225
+ await WRITES['/api/boards/tasks/describe-draft']({ ...ctx, json: (_r, obj, code) => { out = { status: code || 200, body: obj }; } }, null, body, g);
2226
+ return out;
2227
+ }
2171
2228
  /** Delete a task added by mistake, and its Undo (POST /api/boards/tasks/delete|restore; `pmos task remove`; batch 7 item 5). */
2172
2229
  function taskDelete(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/delete', body, g); }
2173
2230
  function taskRestore(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/restore', body, g); }
@@ -2258,4 +2315,4 @@ function meetingBoards(ctx) {
2258
2315
  return { list, detail };
2259
2316
  }
2260
2317
 
2261
- module.exports = { prefixes: ['/api/boards'], handle, tasksOfIni, postFrame, needRows, itemsOf, readLedger, foldOf, epicsOf, rowsOfBoard, invalidateRows: (w) => { rowsLib.invalidate(w.root); rowCache.delete(w.root); }, move, switchWorkflow, taskState, taskAdd, taskEdit, writeAs, taskDelete, taskRestore, initiativeWorkflow, seedInitiative, stageTasks, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, startOnDefault, kindSwitch, recordKind, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, taskSpanOf, workflowRowOf, closedOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
2318
+ module.exports = { prefixes: ['/api/boards'], handle, tasksOfIni, postFrame, needRows, itemsOf, readLedger, foldOf, epicsOf, rowsOfBoard, invalidateRows: (w) => { rowsLib.invalidate(w.root); rowCache.delete(w.root); }, move, switchWorkflow, taskState, taskAdd, taskEdit, describeDraft, writeAs, taskDelete, taskRestore, initiativeWorkflow, seedInitiative, stageTasks, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, startOnDefault, kindSwitch, recordKind, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, taskSpanOf, workflowRowOf, closedOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
@@ -33,14 +33,15 @@ const B = require(repoScript('boards.js'));
33
33
  const TI = require('./task-items.js');
34
34
  const rowsLib = require('./initiative-rows.js');
35
35
 
36
- const COMMANDS = { task: ['add', 'list', 'state', 'set', 'remove', 'link', 'unlink'] };
36
+ const COMMANDS = { task: ['add', 'list', 'state', 'set', 'remove', 'link', 'unlink', 'describe'] };
37
37
  const USAGE = [
38
38
  'usage: pmos task add|list|state|set|remove — an initiative\'s tasks, the ones the PM sees in its Tasks section',
39
- ' pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]',
40
- ' Add a task. Every new task goes here; pmos item add is the older breakdown record.',
39
+ ' pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>] [--parent <task>]',
40
+ ' Add a task. Every new task goes here; pmos item add is the older breakdown record. --parent adds it as a subtask of that task.',
41
41
  ' pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>]',
42
42
  ' [--milestone|--no-milestone] [--pin|--no-pin|--pin-default] [--parent <task>|none]',
43
43
  ' --parent puts the task under another task of the same initiative as a subtask; none takes it back to the top level. Set it only when the PM asks.',
44
+ ' The answer prints the Undo: one command per old parent that puts the tasks back where they were.',
44
45
  ' Group tasks under a stage of the initiative\'s workflow (key or name; none takes it out), or change dates, owner or notes.',
45
46
  ' --milestone makes a task a milestone: its due date shows as ◇ on the Board and the timeline. Set it only when the PM asks.',
46
47
  ' --pin shows a milestone on the Board timeline, --no-pin hides it, --pin-default goes back to the rule (the last milestone',
@@ -56,6 +57,9 @@ const USAGE = [
56
57
  ' There is one kind of task: Board tasks, breakdown items and the current stage\'s To finish tasks all list and close here.',
57
58
  ' The Tasks section groups tasks by the workflow\'s stages: --stage places a task there. It never changes the task\'s state or',
58
59
  ' moves the initiative. Move the initiative with pmos workflow move.',
60
+ ' pmos task describe <task> ["<text>"]',
61
+ ' Print the task\'s description, or write it when the PM asks (what it is, why, and when it is done). "none" clears it.',
62
+ ' The page shows it at once, with Undo. A Jira ticket keeps its description in Jira: it is refused here.',
59
63
  ' pmos task link <from> <to> [--type fs|ss|ff|sf] [--lag <days>] [--propose --why <text>]',
60
64
  ' <to> waits on <from>: fs finish → start (the default), ss start → start, ff finish → finish, sf start → finish; --lag adds days.',
61
65
  ' Link only when the PM asks. Else --propose: the PM approves it with ✓ on the page. A loop is refused. Moving a task later',
@@ -66,7 +70,7 @@ const USAGE = [
66
70
  const BOOL = new Set(['json', 'help', 'all', 'milestone', 'no-milestone', 'pin', 'no-pin', 'pin-default', 'propose']);
67
71
  const PIN_FLAGS = ['pin', 'no-pin', 'pin-default'];
68
72
  const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes', 'stage', 'type', 'lag', 'parent']);
69
- const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage'], list: ['all'], state: ['to', 'why'], remove: ['why'], set: ['due', 'start', 'owner', 'notes', 'stage'], link: ['type', 'lag', 'why'], unlink: [] };
73
+ const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage', 'parent'], list: ['all'], state: ['to', 'why'], remove: ['why'], set: ['due', 'start', 'owner', 'notes', 'stage', 'parent'], link: ['type', 'lag', 'why'], unlink: [], describe: [] };
70
74
  const OPEN = new Set(['To do', 'In progress']);
71
75
  /** The PM's words for a state: any case, with or without the apostrophe or the space. */
72
76
  function stateOf(s) {
@@ -133,7 +137,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
133
137
  const json = !!flags.json;
134
138
  if (!verb || verb === 'help' || verb === '--help' || verb === '-h' || flags.help) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
135
139
  if (!COMMANDS.task.includes(verb)) { say(`unknown task command "${verb}" — one of ${COMMANDS.task.join(', ')}`); return 2; }
136
- if (verb === 'add' && pos.length > 2) { say('usage: pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]'); return 2; }
140
+ if (verb === 'add' && pos.length > 2) { say('usage: pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>] [--parent <task>]'); return 2; }
137
141
  if ('by' in flags || 'via' in flags) { say(`attribution is set from the call path; --${'by' in flags ? 'by' : 'via'} is not accepted`); return 2; }
138
142
  for (const k of Object.keys(flags)) {
139
143
  if (!BOOL.has(k) && !VALUE.has(k)) { say(`unknown option --${k}`); return 2; }
@@ -164,7 +168,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
164
168
 
165
169
  if (verb === 'add') {
166
170
  const [id, title] = pos;
167
- if (!id || title === undefined) { say('usage: pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]'); return 2; }
171
+ if (!id || title === undefined) { say('usage: pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>] [--parent <task>]'); return 2; }
168
172
  const r = rowOf(boards, ctx, w, id);
169
173
  if (!r.ok) return fail(r.error);
170
174
  const stages = r.row.wfStages || [];
@@ -172,6 +176,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
172
176
  if (flags.stage !== undefined && sec == null) return fail(`"${flags.stage}" is not a stage of ${id}'s workflow: one of ${stages.map((x) => x.key).join(', ')}, or none`, 2);
173
177
  const body = { ws: w.id, board: r.board.id, initiative: id, title };
174
178
  for (const k of ['due', 'start', 'owner', 'notes']) if (flags[k] !== undefined) body[k] = flags[k];
179
+ if (flags.parent !== undefined && String(flags.parent).toLowerCase() !== 'none') body.parent = String(flags.parent); // a subtask (initiative chat-subtasks)
175
180
  const a = boards.taskAdd(ctx, body, g);
176
181
  if (!a.body || a.body.ok !== true) return fail((a.body && a.body.error) || 'the write was refused');
177
182
  const t = a.body.item;
@@ -179,8 +184,9 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
179
184
  const e = boards.taskEdit(ctx, { ws: w.id, board: r.board.id, task: t.uid, section: sec }, g);
180
185
  if (!e.body || e.body.ok !== true) return fail(`added ${t.uid}, but it was not placed under ${sec}: ${(e.body && e.body.error) || 'the write was refused'}`);
181
186
  }
182
- if (json) say(JSON.stringify({ ok: true, task: { id: t.uid, board: t.board, title: t.title, state: t.status, owner: t.owner, start: t.start, due: t.end, ...(sec ? { stage: sec } : {}) } }));
183
- else say(`✓ added ${t.uid} · ${t.status} · ${t.title}${sec ? ' · under ' + sec : ''}${t.end ? ' · due ' + t.end : ''}. The initiative's Tasks section shows it. Nothing was sent.`);
187
+ if (body.parent) console.error('[task-parent]', 'add', 1);
188
+ if (json) say(JSON.stringify({ ok: true, task: { id: t.uid, board: t.board, title: t.title, state: t.status, owner: t.owner, start: t.start, due: t.end, ...(sec ? { stage: sec } : {}), ...(body.parent ? { parent: body.parent } : {}) } }));
189
+ else say(`✓ added ${t.uid} · ${t.status} · ${t.title}${body.parent ? ' · a subtask of ' + body.parent : ''}${sec ? ' · under ' + sec : ''}${t.end ? ' · due ' + t.end : ''}. The initiative's Tasks section shows it. Nothing was sent.`);
184
190
  return 0;
185
191
  }
186
192
 
@@ -209,7 +215,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
209
215
 
210
216
  if (verb === 'set') {
211
217
  const keys = ['stage', 'due', 'start', 'owner', 'notes', 'parent'].filter((k) => flags[k] !== undefined).concat(flags.milestone || flags['no-milestone'] ? ['milestone'] : []).concat(PIN_FLAGS.some((k) => flags[k]) ? ['pinned'] : []);
212
- if (!pos.length || !keys.length) { say('usage: pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>] [--milestone|--no-milestone] [--pin|--no-pin|--pin-default]'); return 2; }
218
+ if (!pos.length || !keys.length) { say('usage: pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>] [--milestone|--no-milestone] [--pin|--no-pin|--pin-default] [--parent <task>|none]'); return 2; }
213
219
  const folded = boards.foldOf(ctx, w);
214
220
  const done = [], refused = [];
215
221
  for (const id of pos) {
@@ -230,25 +236,52 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
230
236
  if (PIN_FLAGS.some((k) => flags[k])) body.pinned = flags.pin ? true : flags['no-pin'] ? false : null;
231
237
  const e = boards.taskEdit(ctx, body, g);
232
238
  if (!e.body || e.body.ok !== true) refused.push({ task: id, error: (e.body && e.body.error) || 'the write was refused' });
233
- else done.push({ task: id, title: t.title, set: Object.fromEntries(keys.map((k) => [k, k === 'stage' ? body.section : body[k]])) });
239
+ else done.push({ task: id, title: t.title, set: Object.fromEntries(keys.map((k) => [k, k === 'stage' ? body.section : body[k]])), ...(body.parent !== undefined ? { was: (e.body.from && e.body.from.parent) || '' } : {}) });
234
240
  }
235
- const what = (x) => Object.entries(x).map(([k, v]) => (k === 'stage' ? (v ? 'under ' + v : 'under no stage') : k === 'milestone' ? (v ? 'a milestone' : 'not a milestone') : k === 'pinned' ? (v === true ? 'pinned to the timeline' : v === false ? 'off the timeline' : 'pinned by the rule') : v === '' ? 'no ' + k : k + ' ' + v)).join(', ');
241
+ const what = (x) => Object.entries(x).map(([k, v]) => (k === 'stage' ? (v ? 'under ' + v : 'under no stage') : k === 'parent' ? (v ? 'under ' + v : 'at the top level') : k === 'milestone' ? (v ? 'a milestone' : 'not a milestone') : k === 'pinned' ? (v === true ? 'pinned to the timeline' : v === false ? 'off the timeline' : 'pinned by the rule') : v === '' ? 'no ' + k : k + ' ' + v)).join(', ');
236
242
  // a date changed outside a drag: inside the approved links, what waits on it moves quietly (batch 11 item 15, the grey ✦ on the page)
237
243
  let kept = 0;
238
244
  if (done.length && (flags.due !== undefined || flags.start !== undefined)) {
239
245
  const TLR = require('./routes-task-links.js'), F2 = boards.foldOf(ctx, w), seen = new Set();
240
246
  for (const d of done) { const t = findTask(F2, d.task); const k = t ? t.board + '|' + t.initiative : ''; if (!t || seen.has(k)) continue; seen.add(k); kept += TLR.sweepFor(ctx, w, t.board, t.initiative, g).moved || 0; }
241
247
  }
242
- if (json) say(JSON.stringify({ ok: !refused.length, done, refused, ...(kept ? { moved: kept } : {}) }));
248
+ // the Undo of a parent move (initiative chat-subtasks): one command per old parent puts every task back where it was
249
+ const back = new Map();
250
+ for (const d of done) if (d.was !== undefined && d.was !== d.set.parent) { if (!back.has(d.was)) back.set(d.was, []); back.get(d.was).push(d.task); }
251
+ const undo = [...back].map(([was, ids]) => `pmos task set ${ids.join(' ')} --parent ${was || 'none'}`);
252
+ if (flags.parent !== undefined && done.length) console.error('[task-parent]', 'set', done.length);
253
+ if (json) say(JSON.stringify({ ok: !refused.length, done, refused, ...(kept ? { moved: kept } : {}), ...(flags.parent !== undefined ? { undo } : {}) }));
243
254
  else {
244
255
  for (const d of done) say(`✓ ${d.task} ${what(d.set)}: ${d.title}`);
245
256
  for (const x of refused) say(`✗ ${x.task}: ${x.error}`);
246
257
  if (kept) say(` Kept the links: ${kept === 1 ? '1 task that waits on it moved' : kept + ' tasks that wait on it moved'}. The page lists them under the grey ✦.`);
258
+ for (const u of undo) say(' Undo: ' + u);
247
259
  if (done.length) say(' The page shows it. Nothing was sent.');
248
260
  }
249
261
  return refused.length ? 1 : 0;
250
262
  }
251
263
 
264
+ if (verb === 'describe') {
265
+ // initiative task-descriptions: chat writes every card. Read with one argument, write with two; the same route as the page's edit
266
+ const [id, text] = pos;
267
+ if (!id || pos.length > 2) { say('usage: pmos task describe <task> ["<text>"]'); return 2; }
268
+ const folded = boards.foldOf(ctx, w);
269
+ const t = findTask(folded, id);
270
+ if (!t) return fail(`no task ${id}; pmos task list <initiative> names them`);
271
+ const d0 = (folded.descriptions || new Map()).get(id);
272
+ if (text === undefined) {
273
+ if (json) say(JSON.stringify({ ok: true, task: id, description: d0 ? d0.text : '', by: d0 ? (/^agent:/.test(String(d0.by || '')) ? 'pmos' : 'you') : null, sources: d0 ? d0.sources : [] }));
274
+ else say(d0 ? d0.text + (d0.sources && d0.sources.length ? '\n\nSources: ' + d0.sources.map((x) => x.path + (x.line ? ':' + x.line : '')).join(', ') : '') : `${id} has no description yet.`);
275
+ return 0;
276
+ }
277
+ const body = String(text).trim().toLowerCase() === 'none' ? '' : String(text);
278
+ const e = boards.taskEdit(ctx, { ws: w.id, board: t.board, task: id, description: body }, g);
279
+ if (!e.body || e.body.ok !== true) return fail((e.body && e.body.error) || 'the write was refused');
280
+ if (json) say(JSON.stringify({ ok: true, task: id, description: body, from: e.body.from || {} }));
281
+ else say(`✓ ${id} ${body ? 'has its description' : 'has no description now'}: ${t.title}. The page shows it, with Undo. Nothing was sent.`);
282
+ return 0;
283
+ }
284
+
252
285
  if (verb === 'remove') {
253
286
  // batch 7 item 5: a task added by mistake goes from every list (POST /api/boards/tasks/delete, the page's ⋯ Delete)
254
287
  if (!pos.length) { say('usage: pmos task remove <task> [<task> …] [--why <text>]'); return 2; }
@@ -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.765.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.765.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.765.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));
@@ -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; }