create-pmos 0.763.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 (46) hide show
  1. package/package.json +51 -45
  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/chat-asks-test.js +1 -1
  9. package/workspace/guide/breakdown.md +1 -1
  10. package/workspace/guide/cli.md +8 -0
  11. package/workspace/guide/home.md +1 -1
  12. package/workspace/guide/initiatives-and-next-steps.md +2 -2
  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/question-batch.js +6 -2
  22. package/workspace/lib/routes-boards.js +62 -5
  23. package/workspace/lib/routes-proposals.js +15 -1
  24. package/workspace/lib/source-guard.js +10 -1
  25. package/workspace/lib/task-cli.js +45 -12
  26. package/workspace/lib/task-describe.js +228 -0
  27. package/workspace/lib/task-store.js +2 -2
  28. package/workspace/package-lock.json +2 -2
  29. package/workspace/package.json +1 -1
  30. package/workspace/premium-chat-viewer-test.js +3 -0
  31. package/workspace/premium-vw-jira-test.js +1 -1
  32. package/workspace/public/pm/bd-prog-panel.js +2 -0
  33. package/workspace/public/pm/cozy-home.css +1 -0
  34. package/workspace/public/pm/cozy-popup.js +2 -2
  35. package/workspace/public/pm/cozy-task-pop.css +10 -0
  36. package/workspace/public/pm/cozy-task-pop.js +46 -2
  37. package/workspace/public/pm/home-app.js +1 -1
  38. package/workspace/public/pm/home-chat.js +16 -6
  39. package/workspace/public/pm/home-ini.js +2 -1
  40. package/workspace/public/pm/library-open.js +1 -0
  41. package/workspace/public/pm/page-chat.js +7 -2
  42. package/workspace/public/pm/premium-board.js +2 -1
  43. package/workspace/public/pm/task-card.js +2 -0
  44. package/workspace/public/pm/vw-ds.js +38 -0
  45. package/workspace/test-lists/chat-subtasks.json +9 -0
  46. package/workspace/test-lists/task-descriptions.json +9 -0
@@ -15,7 +15,7 @@ const fs = require('fs');
15
15
  const pmItems = require('./pm-items.js');
16
16
  const MS = require('./milestone-suggest.js');
17
17
 
18
- const COMMANDS = { program: ['suggest', 'charter', 'line', 'draft', 'order', 'capacity', 'decide', 'outcome'] };
18
+ const COMMANDS = { program: ['suggest', 'charter', 'new', 'join', 'leave', 'task', 'task-done', 'check', 'milestone', 'archive', 'unarchive', 'line', 'draft', 'order', 'capacity', 'decide', 'outcome'] };
19
19
  const USAGE = [
20
20
  'usage: pmos program suggest — PMOS\'s milestone suggestions for a program',
21
21
  ' pmos program suggest --json <file|->',
@@ -25,6 +25,19 @@ const USAGE = [
25
25
  ' It answers filed, duplicate or declined for each. The PM keeps, changes or drops it on the page. Nothing is sent.',
26
26
  ' pmos program charter <id> [--goal "<text>"] [--why "<text>"] [--target YYYY-MM-DD] [--owner "<name>"]',
27
27
  ' The program card\'s Goal, For, target date and owner, after the user said yes in the chat. Run it in the repository where the program was made.',
28
+ ' pmos program new "<title>" [--from <initiative>] [--goal "<text>"] [--target YYYY-MM-DD]',
29
+ ' Make a program in this repository. --from turns an initiative into the program: it joins it. Prints the Undo.',
30
+ ' pmos program join <id> <initiative> | pmos program leave <id> <initiative>',
31
+ ' Put an initiative of this repository in a program (it leaves any other), or take it out. Prints the Undo.',
32
+ ' pmos program task <id> "<title>" [--owner "<name>"] [--due YYYY-MM-DD] [--key <key>] | pmos program task-done <id> <key> [--undo]',
33
+ ' Add or change a program task, or mark it done. Prints the Undo.',
34
+ ' pmos program milestone <id> add "<name>" --date YYYY-MM-DD [--waits <initiative>,…] | move <milestone> --date YYYY-MM-DD',
35
+ ' | rename <milestone> "<name>" | drop <milestone> Change the charter\'s milestones. Prints the Undo.',
36
+ ' pmos program check <id> <milestone> [--undo]',
37
+ ' Mark a milestone that waits on no initiative as done (--undo opens it again).',
38
+ ' pmos program archive <id> | pmos program unarchive <id>',
39
+ ' Take a program off the Board, or put it back.',
40
+ ' Every write above is one the user asked for in the chat. It shows on the Board when the chat turn ends.',
28
41
  ' pmos program line [<id>] [--json] [--root <dir>]',
29
42
  ' Where each program stands: Charter, Sequence, Track or Land, what is missing, the next move, the forecast against the target,',
30
43
  ' and one decision row for each team two products need in Build beyond its capacity. Reads every product on this computer, or only',
@@ -48,6 +61,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
48
61
  if (!verb || verb === 'help' || verb === '--help' || verb === '-h') { for (const l of USAGE) say(l); return verb ? 0 : 1; }
49
62
  if (!COMMANDS.program.includes(verb)) { say(`unknown program command "${verb}" — one of ${COMMANDS.program.join(', ')}`); return 2; }
50
63
  if (verb === 'charter') return charter(args.slice(1), { say, cwd: process.cwd() });
64
+ if (EDIT_VERBS.includes(verb)) return editVerb(verb, args.slice(1), { say, cwd: process.cwd() });
51
65
  if (LINE_VERBS.includes(verb)) return lineVerb(verb, args.slice(1), { say, cwd: process.cwd(), env });
52
66
  const i = args.indexOf('--json'), src = i >= 0 ? args[i + 1] : null;
53
67
  if (!src) { say('usage: pmos program suggest --json <file|->'); return 2; }
@@ -102,6 +116,140 @@ function charter(args, { say, cwd }) {
102
116
  return 0;
103
117
  }
104
118
 
119
+ const EDIT_VERBS = ['new', 'join', 'leave', 'task', 'task-done', 'check', 'milestone', 'archive', 'unarchive'];
120
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
121
+ const q = (t) => JSON.stringify(String(t == null ? '' : t));
122
+
123
+ /** The program writes a chat makes after the PM said yes (initiative chat-saves-to-cards): the same lines the Board's presses write
124
+ * (lib/routes-programs.js), in this repository's <state>/programs.jsonl. A line about the charter (milestones, checks, archive) goes where the
125
+ * charter is; join and leave go to this repository, where the initiative is. Each prints the command that undoes it. Exit 0, 1 refused, 2 usage. */
126
+ function editVerb(verb, args, { say, cwd, now = Date.now() } = {}) {
127
+ const path = require('path');
128
+ const P = require('./programs.js');
129
+ const driver = require('./driver.js');
130
+ const pos = [], flags = {};
131
+ for (let k = 0; k < args.length; k++) {
132
+ const a = args[k];
133
+ if (a === '--undo') flags.undo = true;
134
+ else if (/^--(root|from|goal|target|owner|due|key|date|waits)$/.test(a)) flags[a.slice(2)] = args[++k];
135
+ else if (a.startsWith('--')) { say(`✗ unknown flag ${a}`); return 2; }
136
+ else pos.push(a);
137
+ }
138
+ const use = () => { say(USAGE.find((l) => l.includes('pmos program ' + verb)) || USAGE[0]); return 2; };
139
+ const root = flags.root ? path.resolve(cwd, flags.root) : gitTop(cwd);
140
+ const dir = driver.stateDirOf(root);
141
+ if (!dir) { say('✗ this repository has no PMOS state folder'); return 1; }
142
+ const here = path.join(dir, 'programs.jsonl');
143
+ const at = new Date(now);
144
+ const add = (file, line) => pmItems.appendEvent(file, line, at);
145
+ const linesOf = (f) => (fs.existsSync(f) ? pmItems.readLines(f).filter(Boolean) : []);
146
+ // the charter's own file: this repository's state folders, as `pmos program charter` looks
147
+ const charterOf = (id) => {
148
+ const files = [['pmos', 'state'], ['state'], ['.pmos'], ['planning', 'runs']].map((r) => path.join(root, ...r, 'programs.jsonl')).filter((f) => fs.existsSync(f));
149
+ for (const f of files) { const p = P.fold(linesOf(f))[id]; if (p && p.charter) return { file: f, prog: p }; }
150
+ return null;
151
+ };
152
+ const done = (msg, undo) => { say(`✓ ${msg}. The Board shows it.${undo ? ' Undo: ' + undo : ''}`); return 0; };
153
+
154
+ if (verb === 'new') {
155
+ const title = String(pos[0] || '').trim();
156
+ if (!title) return use();
157
+ if (flags.from && !P.INI_RE.test(flags.from)) { say('✗ --from names an initiative id'); return 2; }
158
+ const v = P.validProgram({ title, goal: flags.goal, target: flags.target, owner: flags.owner });
159
+ if (v.error) { say('✗ ' + v.error); return 1; }
160
+ if (charterOf(v.id)) { say(`✗ a program ${v.id} exists already. Change it with pmos program charter ${v.id}`); return 1; }
161
+ add(here, flags.from ? { ...v, from: flags.from } : v);
162
+ if (flags.from) add(here, { kind: 'member', program: v.id, initiative: flags.from });
163
+ return done(`program ${v.id} made${flags.from ? ' with ' + flags.from + ' in it' : ''}`, `pmos program archive ${v.id}`);
164
+ }
165
+
166
+ const id = pos[0];
167
+ if (!id) return use();
168
+ if (!P.ID_RE.test(id)) { say('✗ the program id is lower-case letters, numbers and dashes'); return 2; }
169
+ const ch = charterOf(id);
170
+ if (!ch) { say(`✗ no charter of ${id} in this repository. Run it in the product where the program was made`); return 1; }
171
+ const { file, prog } = ch;
172
+
173
+ if (verb === 'archive' || verb === 'unarchive') {
174
+ if (verb === 'archive' && prog.archived) { say(`${id} is archived already.`); return 0; }
175
+ if (verb === 'unarchive' && !prog.archived) { say(`${id} is not archived.`); return 0; }
176
+ add(file, { kind: verb, program: id });
177
+ return done(`${id} ${verb === 'archive' ? 'archived' : 'is back on the Board'}`, `pmos program ${verb === 'archive' ? 'unarchive' : 'archive'} ${id}`);
178
+ }
179
+
180
+ if (verb === 'join' || verb === 'leave') {
181
+ const ini = pos[1];
182
+ if (!ini || !P.INI_RE.test(ini)) return use();
183
+ const mine = P.fold(linesOf(here));
184
+ if (verb === 'leave' && !(mine[id] && mine[id].members.includes(ini))) { say(`${ini} is not in ${id} in this repository.`); return 0; }
185
+ if (verb === 'join' && mine[id] && mine[id].members.includes(ini)) { say(`${ini} is in ${id} already.`); return 0; }
186
+ let undo = `pmos program ${verb === 'join' ? 'leave' : 'join'} ${id} ${ini}`;
187
+ // an initiative is in one program at most: joining one leaves the other (as the Board's press does)
188
+ if (verb === 'join') for (const o of Object.values(mine)) if (o.id !== id && o.members.includes(ini)) { add(here, { kind: 'leave', program: o.id, initiative: ini }); undo = `pmos program join ${o.id} ${ini}`; }
189
+ // a milestone that waits on an initiative that leaves could never be done: the leave takes it off the charter's milestones
190
+ if (verb === 'leave') {
191
+ const ms = prog.milestones.map((m) => ((m.waits || []).includes(ini) ? { ...m, waits: m.waits.filter((x) => x !== ini) } : m));
192
+ if (ms.some((m, i) => m !== prog.milestones[i])) { const v = P.validProgram({ ...prog, id, milestones: ms }); if (!v.error) add(file, { ...v, from: prog.from || undefined }); }
193
+ }
194
+ add(here, { kind: verb === 'join' ? 'member' : 'leave', program: id, initiative: ini });
195
+ return done(`${ini} ${verb === 'join' ? 'joined' : 'left'} ${id}`, undo);
196
+ }
197
+
198
+ if (verb === 'task') {
199
+ const title = String(pos[1] || '').replace(/\s+/g, ' ').trim().slice(0, 200);
200
+ if (!title) return use();
201
+ if (flags.due && !DAY.test(flags.due)) { say('✗ --due is YYYY-MM-DD'); return 2; }
202
+ const key = /^[A-Za-z0-9._-]{1,40}$/.test(String(flags.key || '')) ? String(flags.key) : 'pt' + now.toString(36);
203
+ const was = (P.fold(linesOf(file))[id] || { tasks: [] }).tasks.find((t) => t.key === key);
204
+ add(file, { kind: 'task', program: id, key, title, owner: String(flags.owner || '').slice(0, 80), due: flags.due || '' });
205
+ const undo = was ? `pmos program task ${id} ${q(was.title)} --key ${key}${was.owner ? ' --owner ' + q(was.owner) : ''}${was.due ? ' --due ' + was.due : ''}` : `pmos program task-done ${id} ${key}`;
206
+ return done(`task ${key} ${was ? 'changed' : 'added'} on ${id}`, undo);
207
+ }
208
+
209
+ if (verb === 'task-done') {
210
+ const key = pos[1];
211
+ if (!key) return use();
212
+ if (!prog.tasks.some((t) => t.key === key)) { say(`✗ ${id} has no task ${key}`); return 1; }
213
+ add(file, { kind: 'task-done', program: id, key, done: !flags.undo });
214
+ return done(`task ${key} ${flags.undo ? 'open again' : 'done'}`, `pmos program task-done ${id} ${key}${flags.undo ? '' : ' --undo'}`);
215
+ }
216
+
217
+ if (verb === 'check') {
218
+ const m = prog.milestones.find((x) => x.id === pos[1]);
219
+ if (!m) { say(`✗ ${id} has no milestone ${pos[1] || ''}`.trim()); return 1; }
220
+ if ((m.waits || []).length) { say('✗ this milestone waits on initiatives: it is done when they pass Deliver'); return 1; }
221
+ add(file, { kind: 'check', program: id, milestone: m.id, done: !flags.undo });
222
+ return done(`${m.name} ${flags.undo ? 'open again' : 'done'}`, `pmos program check ${id} ${m.id}${flags.undo ? '' : ' --undo'}`);
223
+ }
224
+
225
+ // milestone add|move|rename|drop: one charter line with the milestones changed, every other key kept (the last line wins)
226
+ const op = pos[1], ms = prog.milestones.map((m) => ({ ...m }));
227
+ let msg;
228
+ if (op === 'add') {
229
+ const name = String(pos[2] || '').trim();
230
+ if (!name || !DAY.test(String(flags.date || ''))) return use();
231
+ const waits = flags.waits ? String(flags.waits).split(',').map((x) => x.trim()).filter(Boolean) : [];
232
+ if (waits.some((x) => !P.INI_RE.test(x))) { say('✗ --waits names initiative ids, comma separated'); return 2; }
233
+ ms.push({ name, date: flags.date, waits });
234
+ msg = `milestone "${name}" added to ${id}`;
235
+ } else if (op === 'move' || op === 'rename' || op === 'drop') {
236
+ const i = ms.findIndex((m) => m.id === pos[2]);
237
+ if (i < 0) { say(`✗ ${id} has no milestone ${pos[2] || ''}`.trim()); return 1; }
238
+ if (op === 'move') { if (!DAY.test(String(flags.date || ''))) return use(); ms[i].date = flags.date; msg = `${ms[i].name} moved to ${flags.date}`; }
239
+ if (op === 'rename') { const name = String(pos[3] || '').trim(); if (!name) return use(); msg = `${ms[i].name} renamed to "${name}"`; ms[i].name = name; }
240
+ if (op === 'drop') { msg = `${ms[i].name} dropped from ${id}`; ms.splice(i, 1); }
241
+ } else return use();
242
+ const v = P.validProgram({ ...prog, id, milestones: ms });
243
+ if (v.error) { say('✗ ' + v.error); return 1; }
244
+ add(file, { ...v, from: prog.from || undefined });
245
+ const back = op === 'add' ? `pmos program milestone ${id} drop ${v.milestones[v.milestones.length - 1].id}`
246
+ : op === 'move' ? `pmos program milestone ${id} move ${pos[2]} --date ${prog.milestones.find((m) => m.id === pos[2]).date || ''}`
247
+ : op === 'rename' ? `pmos program milestone ${id} rename ${pos[2]} ${q(prog.milestones.find((m) => m.id === pos[2]).name)}`
248
+ : '';
249
+ const dropped = op === 'drop' ? prog.milestones.find((m) => m.id === pos[2]) : null;
250
+ return done(msg, back || (dropped ? `pmos program milestone ${id} add ${q(dropped.name)} --date ${dropped.date}${(dropped.waits || []).length ? ' --waits ' + dropped.waits.join(',') : ''}` : ''));
251
+ }
252
+
105
253
  const LINE_VERBS = ['line', 'draft', 'order', 'capacity', 'decide', 'outcome'];
106
254
  const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
107
255
  const short = (d) => (d ? MON[+d.slice(5, 7) - 1] + ' ' + (+d.slice(8, 10)) + ' ' + d.slice(0, 4) : '');
@@ -242,4 +390,4 @@ function gitTop(cwd) {
242
390
  try { return require('child_process').execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; }
243
391
  }
244
392
 
245
- module.exports = { run, COMMANDS, USAGE, charter, lineVerb };
393
+ module.exports = { run, COMMANDS, USAGE, charter, editVerb, lineVerb };
@@ -21,7 +21,7 @@
21
21
  * { kind: 'leave', program, initiative }
22
22
  * { kind: 'task', program, key, title, owner?, due? } a task on the program itself; the last line for a key wins
23
23
  * { kind: 'task-done', program, key, done: true|false }
24
- * { kind: 'archive', program }
24
+ * { kind: 'archive', program } · { kind: 'unarchive', program } the last one wins (`pmos program archive` / `unarchive`)
25
25
  * { kind: 'order', program, order: [initiative id] } the PM's sequence of the program's initiatives (canvas RoADrag, RoASuggest); the last
26
26
  * line wins. It is a line of its own, not a charter key, so a charter save never drops it
27
27
  * A PROGRAM'S SPAN is `start` to `target` (canvas PgProgram, "Sep 2026 to Jun 2028"): a program can run for years, longer than any one
@@ -134,6 +134,7 @@ function fold(lines) {
134
134
  } else if (l.kind === 'check' && ID_RE.test(String(l.milestone || ''))) p.checks[String(l.milestone)] = !!l.done;
135
135
  else if (l.kind === 'order' && Array.isArray(l.order)) { const v = validOrder(l.order); if (!v.error) { p.order = v; p.orderSet = true; } }
136
136
  else if (l.kind === 'archive') p.archived = true;
137
+ else if (l.kind === 'unarchive') p.archived = false; // `pmos program unarchive`, the Undo of an archive
137
138
  }
138
139
  for (const p of Object.values(out)) p.milestones = withChecks(p.milestones, p.checks);
139
140
  return out;
@@ -21,7 +21,7 @@ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
21
21
  const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
22
22
  const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
23
23
  const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
24
- const { KIND_NAMES } = require('./source-guard.js');
24
+ const { KIND_NAMES, namesOf } = require('./source-guard.js');
25
25
  const md = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
26
26
 
27
27
  /** The owner of a held proposal: the first owner its items name, or the dates proposal's ask. '' when the plan names none. */
@@ -36,7 +36,8 @@ function partOf(p, hold) {
36
36
  const first = items[0] || {};
37
37
  const name = one(first.title || p.title || '', 80);
38
38
  const kind = hold && hold.kinds && hold.kinds.length === 1 ? hold.kinds[0] : '';
39
- const only = kind ? ` Only ${KIND_NAMES[kind] || 'one source'} says so.` : '';
39
+ // shared-text-needs-a-record (A58): two kinds, all shared text; the owner sees which ones
40
+ const only = hold && hold.shared ? ` Only shared text says so (${namesOf(hold.kinds)}).` : kind ? ` Only ${KIND_NAMES[kind] || 'one source'} says so.` : '';
40
41
  if (p.group === 'dates' && (p.noReason || !kind)) {
41
42
  const n = items.length;
42
43
  return `${plural(n, 'task', 'tasks')} passed ${n === 1 ? 'its' : 'their'} date with no news${name ? ' (for example ' + name + ')' : ''}. Re-plan from today, or new dates?`;
@@ -101,6 +102,9 @@ function today(stateDir, held, { day, pm, now, extra = [] } = {}) {
101
102
  let fixed = stateDir ? readDays(stateDir).filter((l) => l.day === day).pop() : null;
102
103
  if (!fixed && stateDir && (list.length || asks.length)) {
103
104
  fixed = { day, at: new Date(now == null ? Date.now() : now).toISOString(), ids: [...new Set([...list.map((h) => h.prop.id), ...asks.map((x) => x.id)])].slice(0, MAX_IDS) };
105
+ // shared-text-needs-a-record: how many on the list rest on shared text only (the initiative's health number)
106
+ const shared = list.filter((h) => isObj(h.hold) && h.hold.shared).length;
107
+ if (shared) fixed.shared = shared;
104
108
  try { fs.mkdirSync(stateDir, { recursive: true }); fs.appendFileSync(path.join(stateDir, LEDGER), JSON.stringify(fixed) + '\n'); } catch { /* the list still shows; tomorrow tries again */ }
105
109
  }
106
110
  const on = new Set(fixed ? fixed.ids : []);
@@ -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 };
@@ -189,6 +189,7 @@ function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
189
189
  const cls = A.classOfProposal(x);
190
190
  const src = SGc.citedOf(x); // no source, no auto (A443), in every group
191
191
  if (SGc.trackerMoveOf(x)) logTrackerWait(w.id, ini, x);
192
+ else logSharedHold(w.id, ini, x);
192
193
  const d = A.decide({ stateDir: dir, job: `propose:${x.group}`, product: w.id, cls, mode: modeOf(board.id), undoable: true, now, settingsDir: ctx.runtimeDir || null, sources: src });
193
194
  if (!d.apply && !src.length) A.logHeld(`propose:${x.group}`, w.id, x.id);
194
195
  if (!d.apply) { out.held++; continue; }
@@ -206,6 +207,19 @@ function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
206
207
 
207
208
  /** tracker-date-moves-wait-for-owner: one [tracker-date-wait] line per held tracker move per process (its health log). */
208
209
  const trackerLogged = new Set();
210
+ /** shared-text-needs-a-record: one [shared-text-hold] line per change held because it rests on shared text only. → true when it logged. */
211
+ const sharedLogged = new Set();
212
+ function logSharedHold(product, ini, x, log = console.error) {
213
+ const h = require('./source-guard.js').holdOf(x);
214
+ if (!h || !h.shared) return false;
215
+ const k = product + '|' + x.id + '|' + x.sig;
216
+ if (sharedLogged.has(k)) return false;
217
+ if (sharedLogged.size > 5000) sharedLogged.clear();
218
+ sharedLogged.add(k);
219
+ try { log(`[shared-text-hold] held ${product} ${ini} ${x.id}: ${x.group} on shared text only (${h.kinds.join(', ')}); asks the owner`); } catch { /* a log never stops the apply step */ }
220
+ return true;
221
+ }
222
+
209
223
  function logTrackerWait(product, ini, x, log = console.error) {
210
224
  const k = product + '|' + x.id + '|' + x.sig;
211
225
  if (trackerLogged.has(k)) return;
@@ -618,7 +632,7 @@ const WRITES = {
618
632
 
619
633
  module.exports = {
620
634
  prefixes: ['/api/proposals'],
621
- viewFor, saidOf, prdRename, keepCore, undoCore, autoKeep, heldOf, keepDefault, keepText,
635
+ viewFor, saidOf, prdRename, keepCore, undoCore, autoKeep, heldOf, keepDefault, keepText, logSharedHold,
622
636
  handle: async (req, res, url, ctx) => {
623
637
  const p0 = url.pathname;
624
638
  if (req.method === 'GET') {
@@ -16,6 +16,9 @@
16
16
  * 2. A close (status done), a rename (names), or a date moved more than BIG_DAYS days needs two different kinds of source. Anyone who can
17
17
  * post in a channel PMOS reads can write one line of text (A58), so one kind is not enough for a change that is hard to see afterwards.
18
18
  * Two Slack lines are one kind. With one kind: held.
19
+ * 2b. Two kinds are not enough when every one is SHARED text: Slack, mail, a meeting note, a document or chat. The same person can write a Slack line and the meeting notes (A58, initiative shared-text-needs-a-record), so one of the
20
+ * kinds must be a record shared text cannot write: the tracker (Jira or another), the repository, or the plan itself. Else: held,
21
+ * with `shared: true`, and the owner answers on the day's question list.
19
22
  * 3. A date move of BIG_DAYS days or less whose only kind of source is the tracker (Jira, or another tracker by name) waits for the
20
23
  * owner the plan names on the work (initiative tracker-date-moves-wait-for-owner, idea A449: 23 of 35 such moves after an import
21
24
  * were applied with nobody told). It joins the day's question list with the old and the new date, and when nobody answers by the
@@ -74,6 +77,11 @@ function bigOf(p) {
74
77
  return '';
75
78
  }
76
79
  const TRACKER_KINDS = new Set(['jira', 'tracker']);
80
+ /** The kinds anyone who can post in a channel PMOS reads can write (rule 2b). A record kind (jira, tracker, repo, plan) is not one, and
81
+ * neither is a source no rule names ('other'): it is not known to be shared text, and the one-kind rule still covers it alone. */
82
+ const SHARED = new Set(['slack', 'mail', 'meeting', 'docs', 'chat']);
83
+ const sharedOnly = (kinds) => kinds.length > 0 && kinds.every((k) => SHARED.has(k));
84
+ const namesOf = (kinds) => { const n = kinds.map((k) => KIND_NAMES[k] || k); return n.length < 2 ? n.join('') : n.slice(0, -1).join(', ') + ' and ' + n[n.length - 1]; };
77
85
  /** A date move of BIG_DAYS days or less that only the tracker says: the owner confirms it, or PMOS takes it after the deadline. PURE. */
78
86
  function trackerMoveOf(p) {
79
87
  if (!isObj(p) || p.group !== 'dates' || p.noReason === true || bigOf(p)) return false;
@@ -90,6 +98,7 @@ function holdOf(p) {
90
98
  if (p.noReason === true || !kinds.length) return { why: 'It cites no source, so PMOS asks instead of changing the plan.', kinds };
91
99
  const big = bigOf(p);
92
100
  if (big && kinds.length < 2) return { why: `It ${BIG_WORDS[big]} on one kind of source (${KIND_NAMES[kinds[0]] || kinds[0]}). PMOS needs two kinds, or the owner's answer.`, kinds };
101
+ if (big && sharedOnly(kinds)) return { why: `It ${BIG_WORDS[big]} on shared text only (${namesOf(kinds)}). Anyone in those channels can write it, so PMOS needs the tracker, the repository or the owner's answer.`, kinds, shared: true };
93
102
  if (trackerMoveOf(p)) return { why: TRACKER_WHY(kinds[0]), kinds, tracker: true };
94
103
  return null;
95
104
  }
@@ -116,4 +125,4 @@ function citedOf(x) {
116
125
  return [...new Set(out)];
117
126
  }
118
127
 
119
- module.exports = { citedOf, noReason, LINK_SOURCES, holdOf, trackerMoveOf, TRACKER_KINDS, kindsOf, kindOf, bigOf, shiftOf, PLAN, BIG_DAYS, KIND_NAMES };
128
+ module.exports = { SHARED, sharedOnly, namesOf, citedOf, noReason, LINK_SOURCES, holdOf, trackerMoveOf, TRACKER_KINDS, kindsOf, kindOf, bigOf, shiftOf, PLAN, BIG_DAYS, KIND_NAMES };
@@ -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; }