create-pmos 0.780.0 → 0.782.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 (66) hide show
  1. package/package.json +47 -73
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/design-system/ui/README.md +2 -2
  4. package/payload/design-system/ui/components/MainItem/README.md +4 -2
  5. package/payload/design-system/ui/components/MainItem/preview.html +2 -2
  6. package/payload/design-system/ui/components/MainSide/README.md +4 -2
  7. package/payload/design-system/ui/components/MainSide/preview.html +2 -2
  8. package/payload/design-system/ui/components/Popup/README.md +15 -0
  9. package/payload/design-system/ui/components/Popup/preview.html +8 -0
  10. package/payload/design-system/ui/components/Reading/README.md +19 -0
  11. package/payload/design-system/ui/components/Reading/preview.html +8 -0
  12. package/payload/design-system/ui/components/SingleColumn/README.md +4 -2
  13. package/payload/design-system/ui/components/SingleColumn/preview.html +2 -2
  14. package/payload/design-system/ui/components/bundle.css +29 -0
  15. package/payload/design-system/ui/pages.md +6 -6
  16. package/payload/design-system/ui/tokens.css +1 -1
  17. package/payload/design-system/ui/tokens.json +30 -0
  18. package/payload/planning/evals/eval-calibration.md +1 -1
  19. package/payload/planning/okrs/health-budgets.md +1 -1
  20. package/payload/state/discoveries.md +1 -1
  21. package/workspace/changelog.json +46 -0
  22. package/workspace/design-system/ui/README.md +2 -2
  23. package/workspace/design-system/ui/components/MainItem/README.md +4 -2
  24. package/workspace/design-system/ui/components/MainItem/preview.html +2 -2
  25. package/workspace/design-system/ui/components/MainSide/README.md +4 -2
  26. package/workspace/design-system/ui/components/MainSide/preview.html +2 -2
  27. package/workspace/design-system/ui/components/Popup/README.md +15 -0
  28. package/workspace/design-system/ui/components/Popup/preview.html +8 -0
  29. package/workspace/design-system/ui/components/Reading/README.md +19 -0
  30. package/workspace/design-system/ui/components/Reading/preview.html +8 -0
  31. package/workspace/design-system/ui/components/SingleColumn/README.md +4 -2
  32. package/workspace/design-system/ui/components/SingleColumn/preview.html +2 -2
  33. package/workspace/design-system/ui/components/bundle.css +29 -0
  34. package/workspace/design-system/ui/pages.md +6 -6
  35. package/workspace/design-system/ui/tokens.css +1 -1
  36. package/workspace/design-system/ui/tokens.json +30 -0
  37. package/workspace/guide/agent-capabilities.md +2 -1
  38. package/workspace/guide/claude-proposes.md +11 -1
  39. package/workspace/guide/cli.md +9 -1
  40. package/workspace/guide/layout.md +14 -0
  41. package/workspace/lib/card-catalog.js +67 -0
  42. package/workspace/lib/card-catalog.json +2032 -0
  43. package/workspace/lib/pmos-verbs.js +3 -0
  44. package/workspace/lib/routes-card-catalog.js +19 -0
  45. package/workspace/lib/routes-slash.js +7 -1
  46. package/workspace/lib/routes-star-drafts.js +36 -0
  47. package/workspace/lib/sprint-cli.js +79 -0
  48. package/workspace/lib/sprint-retro.js +176 -0
  49. package/workspace/lib/star-draft.js +99 -0
  50. package/workspace/lib/task-cli.js +26 -12
  51. package/workspace/package-lock.json +2 -2
  52. package/workspace/package.json +1 -1
  53. package/workspace/public/pm/action-run.js +120 -0
  54. package/workspace/public/pm/bd-pop-ds.js +2 -2
  55. package/workspace/public/pm/card-run.js +25 -0
  56. package/workspace/public/pm/cozy-pop-work.js +91 -10
  57. package/workspace/public/pm/goals-open.js +14 -2
  58. package/workspace/public/pm/komorebi.css +29 -1
  59. package/workspace/public/pm/premium-vw-doc.css +31 -0
  60. package/workspace/public/pm/premium-vw-doc.js +49 -3
  61. package/workspace/public/pm/reading-model.js +76 -0
  62. package/workspace/public/pm/star-draft.js +63 -0
  63. package/workspace/public/pm/state-blocks.js +18 -1
  64. package/workspace/test-lists/reading-layouts.json +9 -0
  65. package/workspace/test-lists/sprint-retro-one-change.json +9 -0
  66. package/workspace/test-lists/star-buttons-act-directly.json +13 -0
@@ -169,6 +169,9 @@ const VERBS = Object.freeze({
169
169
  // Not a pm-os-absorb verb (run: null): initiative strategy-draft (Wawan 2026-11-24) added it through the same table.
170
170
  strategy: Object.freeze({ module: 'strategy-cli.js', run: null, guide: 'cli.md',
171
171
  help: 'pmos strategy show|sources|draft|set|undo — the product\'s five-line strategy; PMOS drafts blank lines from the product\'s files, each citing them (pmos strategy help)' }),
172
+ // Not a pm-os-absorb verb (run: null): initiative sprint-retro-one-change (bet A76) added it through the same table.
173
+ sprint: Object.freeze({ module: 'sprint-cli.js', run: null, guide: 'cli.md',
174
+ help: 'pmos sprint retro|change — a closed sprint\'s retro from PMOS\'s own close numbers, and its one tracked change (pmos sprint help)' }),
172
175
  // Not a pm-os-absorb verb (run: null): initiative parked-reason-way-back (bet A446) added it through the same table.
173
176
  parked: Object.freeze({ module: 'parked-cli.js', run: null, guide: 'cli.md',
174
177
  help: 'pmos parked list|hold|back|coverage — parked initiatives: why each is parked, what brings it back, and bringing it back (pmos parked help)' }),
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+ /* routes-card-catalog.js — the card catalog for the page (star-buttons-act-directly).
3
+ *
4
+ * GET /api/card-catalog → { ok, catalog } the committed v2 catalog (lib/card-catalog.json), read only
5
+ *
6
+ * The page runs a button with public/pm/action-run.js; the catalog only says which command a button runs and who acts. */
7
+ const CC = require('./card-catalog.js');
8
+
9
+ module.exports = {
10
+ prefixes: ['/api/card-catalog'],
11
+ handle: async (req, res, url, ctx) => {
12
+ if (url.pathname !== '/api/card-catalog') return false;
13
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
14
+ let catalog = null;
15
+ try { catalog = CC.load(); } catch (e) { ctx.json(res, { ok: false, error: 'The card catalog could not be read: ' + e.message }, 500); return true; }
16
+ ctx.json(res, { ok: true, catalog });
17
+ return true;
18
+ },
19
+ };
@@ -80,10 +80,16 @@ function list(deps = {}) {
80
80
  return { status: 200, body: { ok: true, commands: out } };
81
81
  }
82
82
 
83
+ // The commands a card's buttons run live beside the chat's commands (star-buttons-act-directly): GET /api/card-catalog
84
+ // (lib/routes-card-catalog.js) and the ✦ drafts' background job, POST/GET /api/star-drafts (lib/routes-star-drafts.js). They ride on this
85
+ // module's entry, so route-modules.js keeps its list.
86
+ const BESIDE = [require('./routes-card-catalog.js'), require('./routes-star-drafts.js')];
87
+
83
88
  module.exports = {
84
- prefixes: ['/api/slash-commands'],
89
+ prefixes: ['/api/slash-commands', '/api/card-catalog', '/api/star-drafts'],
85
90
  list, sayOf, CLAUDE,
86
91
  handle: async (req, res, url, ctx) => {
92
+ for (const m of BESIDE) if (m.prefixes.includes(url.pathname)) return m.handle(req, res, url, ctx);
87
93
  if (url.pathname !== '/api/slash-commands') return false;
88
94
  if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
89
95
  const ws = url.searchParams.get('ws');
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+ /* routes-star-drafts.js — a ✦ "Draft …" answer as a PMOS background job (star-buttons-act-directly, done test A7; lib/star-draft.js).
3
+ *
4
+ * POST /api/star-drafts { ws, ask, again? } → { ok, state: 'pending' | 'ready' | 'failed', key, text?, why? } starts the job, or
5
+ * answers the kept draft at once
6
+ * GET /api/star-drafts?key= → { ok, state: 'pending' | 'ready' | 'failed' | 'none', key, text?, why? } the page reads it until it lands
7
+ *
8
+ * The POST is a page press (pm-guard requirePagePress). The job reads and drafts only: nothing is written until the PM's ✓ on the row,
9
+ * which saves through the row's own route with Undo. */
10
+ const guard = require('./pm-guard.js');
11
+ const SD = require('./star-draft.js');
12
+
13
+ module.exports = {
14
+ prefixes: ['/api/star-drafts'],
15
+ handle: async (req, res, url, ctx) => {
16
+ if (url.pathname !== '/api/star-drafts') return false;
17
+ const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
18
+ if (req.method === 'GET') {
19
+ const key = String(url.searchParams.get('key') || '');
20
+ if (!/^[0-9a-f]{16}$/.test(key)) return bad('key must name a draft');
21
+ ctx.json(res, { ok: true, ...SD.peek(ctx, key) });
22
+ return true;
23
+ }
24
+ if (req.method !== 'POST') return bad('GET or POST only', 405);
25
+ const got = await ctx.readJson(req);
26
+ if (!got.ok) return bad('invalid JSON body');
27
+ const b = got.body || {};
28
+ const g = guard.requirePagePress(req, b);
29
+ if (!g.ok) return bad(g.error, g.status);
30
+ const ask = String(b.ask || '').trim();
31
+ if (!ask) return bad('ask must hold the words of the draft');
32
+ const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
33
+ ctx.json(res, { ok: true, ...SD.start(ctx, { ws: w ? w.id : (b.ws || null), ask, again: !!b.again }) });
34
+ return true;
35
+ },
36
+ };
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+ /* sprint-cli.js — `pmos sprint`: the retro of a closed sprint and its one tracked change, the same block the past sprint view on Work ›
3
+ * Backlog shows (initiative sprint-retro-one-change). The store is lib/sprint-retro.js (_sprint-retro.jsonl beside the kept sprint history).
4
+ *
5
+ * pmos sprint retro [--sprint "<name>"] [--json] the retro (default: the newest closed sprint PMOS kept)
6
+ * pmos sprint change --sprint "<name>" --pick <reason> | --drop | --undo the PM's override of the tracked change (the chat writes it)
7
+ * every command: [--root <dir>] (default: this repository)
8
+ *
9
+ * Reasons: twice, never, review, started, added. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent and Jira is not written. */
10
+ const path = require('path');
11
+ const { execFileSync } = require('child_process');
12
+ const SR = require('./sprint-retro.js');
13
+ const SH = require('./sprint-history.js');
14
+
15
+ const COMMANDS = { sprint: ['retro', 'change'] };
16
+ const REASONS = SR.REASONS.map((x) => x.reason);
17
+ const USAGE = [
18
+ 'usage: pmos sprint retro|change — a closed sprint\'s retro, from PMOS\'s own close numbers, and its one tracked change',
19
+ ' pmos sprint retro [--sprint "<name>"] [--json] the retro (default: the newest closed sprint PMOS kept)',
20
+ ' pmos sprint change --sprint "<name>" --pick <reason> track another change (reasons: ' + REASONS.join(', ') + ')',
21
+ ' pmos sprint change --sprint "<name>" --drop | --undo track no change, or go back to PMOS\'s pick',
22
+ 'Run it in the product\'s repository, or pass --root <dir>.',
23
+ ];
24
+ const ALLOWED = { retro: ['json', 'root', 'sprint'], change: ['json', 'root', 'sprint', 'pick', 'drop', 'undo'] };
25
+ const BOOL = new Set(['json', 'drop', 'undo']);
26
+
27
+ function parse(args) {
28
+ const pos = [], flags = {};
29
+ for (let i = 0; i < args.length; i++) {
30
+ const a = args[i];
31
+ if (!a.startsWith('--')) { pos.push(a); continue; }
32
+ const k = a.slice(2);
33
+ if (BOOL.has(k)) { flags[k] = true; continue; }
34
+ flags[k] = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
35
+ }
36
+ return { pos, flags };
37
+ }
38
+ function repoRoot(cwd) {
39
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; }
40
+ }
41
+
42
+ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd() } = {}) {
43
+ const args = argv[0] === 'sprint' ? argv.slice(1) : argv.slice();
44
+ const sub = args[0];
45
+ if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
46
+ if (!COMMANDS.sprint.includes(sub)) { say(`unknown sprint command "${sub}". Use one of: ${COMMANDS.sprint.join(', ')}`); return 2; }
47
+ const { pos, flags } = parse(args.slice(1));
48
+ for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos sprint ${sub}`); return 2; }
49
+ if (pos.length) { say(`✗ pmos sprint ${sub} takes options, not an argument (pmos sprint help)`); return 2; }
50
+ const root = path.resolve(flags.root || repoRoot(cwd));
51
+ const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
52
+ const lines = SH.read(root);
53
+ const kept = SR.keptOrder(lines);
54
+
55
+ if (sub === 'retro') {
56
+ const name = flags.sprint || kept[0];
57
+ if (!name) return fail('PMOS has kept no sprint it saw open and then closed. Read Jira while a sprint is open (pmos jira sync --sprints).');
58
+ const x = SR.retroOf(lines, name, { overrides: SR.readOverrides(root) });
59
+ if (!x) return fail(`PMOS did not see ${name} open and then closed, so it has no close numbers for it`);
60
+ if (flags.json) { say(JSON.stringify({ ok: true, retro: x })); return 0; }
61
+ for (const l of SR.linesOf(x)) say(l);
62
+ if (x.options.length > 1) say('Other changes: ' + x.options.filter((o) => !x.change || o.reason !== x.change.reason).map((o) => `${o.reason} (${o.count})`).join(', ') + ' · pmos sprint change --sprint "' + name + '" --pick <reason>');
63
+ return 0;
64
+ }
65
+ // change
66
+ if (!flags.sprint) return fail('name the sprint: --sprint "<name>"', 2);
67
+ const n = [flags.pick != null && flags.pick !== '', !!flags.drop, !!flags.undo].filter(Boolean).length;
68
+ if (n !== 1) return fail('give one of --pick <reason>, --drop, --undo', 2);
69
+ if (!kept.includes(flags.sprint)) return fail(`PMOS did not see ${flags.sprint} open and then closed, so it tracks no change for it`);
70
+ const ev = flags.drop ? 'drop' : flags.undo ? 'undo' : 'pick';
71
+ const r = SR.appendOverride(root, { sprint: flags.sprint, ev, reason: flags.pick || null, by: 'pm' });
72
+ if (!r.ok) return fail(r.error, 2);
73
+ const x = SR.retroOf(SH.read(root), flags.sprint, { overrides: SR.readOverrides(root) });
74
+ if (flags.json) { say(JSON.stringify({ ok: true, row: r.row, retro: x })); return 0; }
75
+ say(x && x.change ? `✓ ${flags.sprint}: tracking "${x.change.text}" (${x.change.number}, now ${x.change.count})` : `✓ ${flags.sprint}: no change tracked`);
76
+ return 0;
77
+ }
78
+
79
+ module.exports = { run, COMMANDS, USAGE };
@@ -0,0 +1,176 @@
1
+ 'use strict';
2
+ /* sprint-retro.js — the retro of a closed sprint, written from PMOS's own close numbers, with one change tracked into the next sprint
3
+ * (initiative sprint-retro-one-change, bet A76; done test planning/done-tests/sprint-retro-one-change.md).
4
+ *
5
+ * WHY. lib/sprint-history.js keeps every closed sprint with each ticket's state at close, but nothing turns those numbers into a retro, and
6
+ * nothing tracks whether what a team tried helped. This file reads only the kept snapshot (never the agent's count, never Jira):
7
+ * · the reasons work was carried: never started (to do at close), started (moving, not in review), in review (a review or test status),
8
+ * carried twice (carried in and carried on again), added after the start (not in the sprint's first read);
9
+ * · ONE change for the next sprint: the reason with the biggest count (at least MIN), ties in the order of REASONS, each with its number;
10
+ * · the check: at the next kept sprint's close, the previous sprint's change on its own number, helped (lower) / same / worse.
11
+ *
12
+ * THE FILE. <state>/tracker/jira/_sprint-retro.jsonl, append-only, the PM's overrides only (PMOS's own pick is worked out, never written):
13
+ * { at, sprint, ev: pick|drop|undo, reason?, by } pick: another listed reason · drop: no change tracked · undo: back to PMOS's pick
14
+ *
15
+ * reasonsOf(snapshot) → { done, total, carried, never, started, review, twice, added }
16
+ * optionsOf(reasons, sprintName) → [{ reason, count, text, number }] biggest first, only counts ≥ MIN
17
+ * retroOf(lines, name, { order, overrides }) → retro | null order: the closed sprints' names, newest first (the board's own picker)
18
+ * readOverrides(root) · appendOverride(root, { sprint, ev, reason, by }) · foldOverrides(rows) · countOf(root)
19
+ * CLI: node lib/sprint-retro.js count [--root <dir>] the health number on its last line
20
+ *
21
+ * BOUNDARY. No network, no child process, no Jira write. Writes only the overrides file. */
22
+ const fs = require('fs');
23
+ const path = require('path');
24
+ const SH = require('./sprint-history.js');
25
+ const jiraTickets = require('./jira-tickets.js');
26
+
27
+ const FILE = '_sprint-retro.jsonl';
28
+ const MIN = 2;
29
+ const LOG = '[sprint-retro]';
30
+ const REVIEW = /review|test|qa|verif|approv/i;
31
+ const t = (n) => n + (n === 1 ? ' ticket' : ' tickets');
32
+ const label = (name) => String(name || 'the sprint');
33
+
34
+ /** The reasons, in tie order, with the number each change moves and the words of the change. r: reasonsOf, s: the sprint's name. */
35
+ const REASONS = Object.freeze([
36
+ { reason: 'twice', number: 'tickets carried two sprints in a row',
37
+ text: (r) => `Start with the ${t(r.twice)} carried two sprints in a row, or take them out of the next sprint` },
38
+ { reason: 'never', number: 'tickets carried without being started',
39
+ text: (r, s) => `Plan about ${t(r.done)}, what ${label(s)} finished, not ${r.total}` },
40
+ { reason: 'review', number: 'tickets carried while in review',
41
+ text: (r) => `Review before starting new work: ${t(r.review)} waited in review at the close` },
42
+ { reason: 'started', number: 'started tickets carried unfinished',
43
+ text: (r) => `Finish started work before starting new: ${t(r.started)} were started and not finished` },
44
+ { reason: 'added', number: 'tickets added after the sprint started',
45
+ text: (r) => `Keep new tickets for the next sprint unless they are urgent: ${t(r.added)} were added after the start` },
46
+ ]);
47
+ const BY = new Map(REASONS.map((x, i) => [x.reason, { ...x, i }]));
48
+
49
+ /** Why the work was carried, from one kept snapshot (sprint-history.js snapshotOf). */
50
+ function reasonsOf(snap) {
51
+ const held = (snap && snap.rows ? snap.rows : []).filter((r) => !r.removed);
52
+ const carried = held.filter((r) => r.carried);
53
+ const review = carried.filter((r) => r.category === 'doing' && REVIEW.test(r.status || '')).length;
54
+ const started = carried.filter((r) => r.category === 'doing').length - review;
55
+ return { done: held.filter((r) => r.category === 'done').length, total: held.length, carried: carried.length,
56
+ never: carried.length - review - started, started, review, twice: carried.filter((r) => r.carriedIn).length, added: held.filter((r) => r.added).length };
57
+ }
58
+
59
+ /** The changes PMOS could track, biggest first (ties in REASONS order); only a reason with MIN or more tickets. */
60
+ function optionsOf(r, name) {
61
+ return REASONS.map((x, i) => ({ x, i, count: r[x.reason] || 0 })).filter((o) => o.count >= MIN)
62
+ .sort((a, b) => b.count - a.count || a.i - b.i)
63
+ .map((o) => ({ reason: o.x.reason, count: o.count, number: o.x.number, text: o.x.text(r, name) }));
64
+ }
65
+
66
+ /* ── the PM's overrides ──────────────────────────────────────────────────────────────────────────────────────── */
67
+ const fileOf = (root) => path.join(jiraTickets.jiraDir(root), FILE);
68
+ function readOverrides(root) {
69
+ let raw = ''; try { raw = fs.readFileSync(fileOf(root), 'utf8'); } catch { return []; }
70
+ const out = [];
71
+ for (const l of raw.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && o.sprint && o.ev) out.push(o); } catch { /* a torn line has no effect */ } }
72
+ return out;
73
+ }
74
+ /** { [sprint]: { ev: pick|drop, reason?, at, by } }; undo removes the sprint's entry. */
75
+ function foldOverrides(rows) {
76
+ const out = {};
77
+ for (const o of rows || []) {
78
+ if (o.ev === 'undo') delete out[o.sprint];
79
+ else if (o.ev === 'drop') out[o.sprint] = { ev: 'drop', at: o.at, by: o.by || null };
80
+ else if (o.ev === 'pick' && BY.has(o.reason)) out[o.sprint] = { ev: 'pick', reason: o.reason, at: o.at, by: o.by || null };
81
+ }
82
+ return out;
83
+ }
84
+ /** One override, appended. → { ok, row } | { ok: false, error } */
85
+ function appendOverride(root, { sprint, ev, reason = null, by = 'pm', at = new Date().toISOString() } = {}) {
86
+ const name = String(sprint || '').trim().slice(0, 120);
87
+ if (!name) return { ok: false, error: 'name the sprint' };
88
+ if (!['pick', 'drop', 'undo'].includes(ev)) return { ok: false, error: 'ev is one of pick, drop, undo' };
89
+ if (ev === 'pick' && !BY.has(reason)) return { ok: false, error: 'pick one of: ' + REASONS.map((x) => x.reason).join(', ') };
90
+ const row = { at, sprint: name, ev, ...(ev === 'pick' ? { reason } : {}), by };
91
+ const file = fileOf(root);
92
+ fs.mkdirSync(path.dirname(file), { recursive: true });
93
+ fs.appendFileSync(file, JSON.stringify(row) + '\n');
94
+ console.log(`${LOG} ${ev}${ev === 'pick' ? ' ' + reason : ''} · ${name}`);
95
+ return { ok: true, row };
96
+ }
97
+
98
+ /* ── the retro ───────────────────────────────────────────────────────────────────────────────────────────────── */
99
+ /** The closed sprints PMOS saw open, newest first (the order the picker uses, when none is given). */
100
+ function keptOrder(lines) {
101
+ const L = [];
102
+ for (const name of new Set((lines || []).map((l) => l.sprint.name))) {
103
+ const s = SH.snapshotOf(lines, name);
104
+ if (s && s.seenOpen && s.sprint.state === 'closed') L.push({ name, start: s.sprint.start || null });
105
+ }
106
+ const num = (n) => { const m = /(\d+)\s*$/.exec(n); return m ? Number(m[1]) : null; };
107
+ return L.sort((a, b) => ((a.start && b.start && a.start !== b.start) ? b.start.localeCompare(a.start)
108
+ : (num(a.name) != null && num(b.name) != null) ? num(b.name) - num(a.name) : b.name.localeCompare(a.name))).map((x) => x.name);
109
+ }
110
+ /** The change tracked for one sprint: PMOS's pick unless the PM picked another or dropped it. */
111
+ function changeOf(r, name, ov) {
112
+ const options = optionsOf(r, name);
113
+ const o = ov && ov[name];
114
+ if (o && o.ev === 'drop') return { change: null, options, by: 'dropped' };
115
+ if (o && o.ev === 'pick') {
116
+ const x = BY.get(o.reason);
117
+ const opt = options.find((y) => y.reason === o.reason) || { reason: o.reason, count: r[o.reason] || 0, number: x.number, text: x.text(r, name) };
118
+ return { change: opt, options, by: 'pm' };
119
+ }
120
+ return { change: options[0] || null, options, by: options.length ? 'pmos' : 'none' };
121
+ }
122
+ /** One sprint's retro. → null when PMOS did not see the sprint open and then closed. */
123
+ function retroOf(lines, name, { order = null, overrides = null } = {}) {
124
+ const snap = SH.snapshotOf(lines, name);
125
+ if (!snap || !snap.seenOpen || snap.sprint.state !== 'closed') return null;
126
+ const ov = overrides && !Array.isArray(overrides) ? overrides : foldOverrides(overrides || []);
127
+ const r = reasonsOf(snap);
128
+ const { change, options, by } = changeOf(r, name, ov);
129
+ const kept = keptOrder(lines);
130
+ const names = (order && order.length ? order : kept).filter((n) => kept.includes(n));
131
+ const i = names.indexOf(name);
132
+ const prev = i >= 0 ? names[i + 1] || null : null;
133
+ const next = i > 0 ? names[i - 1] : (snap.counts.carriedTo || null);
134
+ let check = null;
135
+ if (prev) {
136
+ const ps = SH.snapshotOf(lines, prev), pr = reasonsOf(ps), pc = changeOf(pr, prev, ov).change;
137
+ if (pc) {
138
+ const before = pc.count, after = r[pc.reason] || 0;
139
+ check = { sprint: prev, reason: pc.reason, text: pc.text, number: pc.number, before, after, result: after < before ? 'helped' : after === before ? 'same' : 'worse' };
140
+ }
141
+ }
142
+ return { sprint: name, next, reasons: r, change, by, options, check };
143
+ }
144
+
145
+ /** The health number: closed kept sprints with a tracked change (PMOS's or the PM's pick, not dropped). */
146
+ function countOf(root) {
147
+ const lines = SH.read(root), ov = foldOverrides(readOverrides(root));
148
+ let n = 0;
149
+ for (const name of keptOrder(lines)) { const x = retroOf(lines, name, { overrides: ov }); if (x && x.change) n++; }
150
+ return n;
151
+ }
152
+
153
+ /** The sentences a retro says, for the CLI and the chat (the page draws its own block from the same fields). */
154
+ function linesOf(x) {
155
+ if (!x) return [];
156
+ const r = x.reasons, out = [`${label(x.sprint)}: ${r.done} of ${r.total} done.`];
157
+ if (r.carried) {
158
+ const parts = [r.never && `${r.never} never started`, r.started && `${r.started} started`, r.review && `${r.review} in review`].filter(Boolean);
159
+ out.push(`${t(r.carried)} carried: ${parts.join(', ')}.` + (r.twice ? ` ${r.twice} of them carried two sprints in a row.` : ''));
160
+ }
161
+ if (r.added) out.push(`${t(r.added)} added after the start.`);
162
+ if (x.change) out.push(`One change for ${x.next ? label(x.next) : 'the next sprint'}: ${x.change.text}. Its number: ${x.change.number}, now ${x.change.count}.`);
163
+ else if (x.by === 'dropped') out.push('No change tracked: you dropped it.');
164
+ if (x.check) out.push(`Last sprint's change (${label(x.check.sprint)}): ${x.check.number} went from ${x.check.before} to ${x.check.after}. ${x.check.result === 'helped' ? 'It helped.' : x.check.result === 'same' ? 'No change.' : 'It got worse.'}`);
165
+ return out;
166
+ }
167
+
168
+ module.exports = { FILE, MIN, LOG, REASONS, fileOf, reasonsOf, optionsOf, retroOf, keptOrder, readOverrides, foldOverrides, appendOverride, countOf, linesOf };
169
+
170
+ if (require.main === module) {
171
+ const a = process.argv.slice(2);
172
+ const ri = a.indexOf('--root');
173
+ const root = path.resolve(ri >= 0 && a[ri + 1] ? a[ri + 1] : process.cwd());
174
+ if (a[0] === 'count') { const n = countOf(root); console.log(`${LOG} count · ${n} closed ${n === 1 ? 'sprint carries' : 'sprints carry'} a tracked change`); console.log(String(n)); process.exit(0); }
175
+ console.log('usage: node lib/sprint-retro.js count [--root <dir>]'); process.exit(2);
176
+ }
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+ /* star-draft.js — a ✦ "Draft …" answer runs as a PMOS background job, and its result lands on the row it came from (initiative
3
+ * star-buttons-act-directly, done test A7; Wawan chose "Yes, run drafts in background" on 2026-11-24).
4
+ *
5
+ * Before, a ✦ that offered a draft (the Overview's Problem, Goal and Done when, a program's For and Goal, the missing gate documents, a
6
+ * goal or initiatives from the strategy, an outcome verdict, a name) wrote its words into the chat and the PM had to send them. Now the
7
+ * press starts one short read-only PMOS session and the row shows "PMOS is drafting…", then the draft. Nothing is kept until the PM's ✓.
8
+ *
9
+ * keyOf(ws, ask) → the job's key: one job per workspace and words PURE
10
+ * askOf(ask) → the words the session gets: the ✦ words without their save step ("When I say yes, save it with …"),
11
+ * and the answer rules: the draft only, plain text, no preamble PURE
12
+ * clean(text) → the draft as the row shows it, or '' when there is none PURE
13
+ * start(ctx, { ws, ask, again }) → { state: 'pending' | 'ready' | 'failed', key, text?, why? }
14
+ * peek(ctx, key) → the same, or { state: 'none', key }
15
+ *
16
+ * THE RUN. One session of the existing read-only `ask` kind (lib/headless.js, origin briefing-ask:star-draft:<key>), in the workspace's
17
+ * folder, with Read, Glob and Grep only: it reads the records and writes nothing and sends nothing. The answer is kept in
18
+ * <runtime>/star-drafts.json by key (the newest 60), so a second press reads it at once. No session or an empty answer: state failed with
19
+ * the reason, and the row offers Try again (honest state). 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
+
24
+ const MODEL = 'claude-sonnet-5-5';
25
+ const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read,Glob,Grep' }]);
26
+ const TIMEOUT_MS = 180000, KEEP = 60, MAX_ASK = 4000, MAX_TEXT = 6000;
27
+
28
+ const keyOf = (ws, ask) => crypto.createHash('sha1').update(String(ws || '') + '\n' + String(ask || '')).digest('hex').slice(0, 16);
29
+
30
+ /** The ✦ words without the step that saves (the row saves on ✓), and the rules of the answer. */
31
+ function askOf(ask) {
32
+ const words = String(ask || '').replace(/\s*When I say yes,[\s\S]*$/, '').replace(/\s*Show it to me before you keep it\.?/g, '').trim().slice(0, MAX_ASK);
33
+ return words + '\n\nRead the records in this folder that you need. Change nothing, write nothing, send nothing.'
34
+ + '\nAnswer with the draft only, as plain text: no preamble, no heading, no closing line. If the records hold nothing to draft it from, answer exactly: NOTHING';
35
+ }
36
+
37
+ function clean(text) {
38
+ const t = String(text == null ? '' : text).replace(/\r\n?/g, '\n').replace(/^\s*```[a-z]*\n?|\n?```\s*$/g, '').trim();
39
+ if (!t || /^NOTHING\.?$/i.test(t)) return '';
40
+ return t.length > MAX_TEXT ? t.slice(0, MAX_TEXT - 1).replace(/\s+\S*$/, '') + '…' : t;
41
+ }
42
+
43
+ /* ── the kept answers, in the runtime folder ── */
44
+ const fileOf = (ctx) => path.join((ctx && ctx.runtimeDir) || require('os').tmpdir(), 'star-drafts.json');
45
+ function readAll(ctx) { try { const o = JSON.parse(fs.readFileSync(fileOf(ctx), 'utf8')); return o && typeof o === 'object' ? o : {}; } catch { return {}; } }
46
+ function keepOne(ctx, key, value) {
47
+ const all = readAll(ctx); all[key] = { at: new Date().toISOString(), ...value };
48
+ const keys = Object.keys(all).sort((a, b) => String(all[b].at).localeCompare(String(all[a].at)));
49
+ for (const k of keys.slice(KEEP)) delete all[k];
50
+ fs.mkdirSync(path.dirname(fileOf(ctx)), { recursive: true });
51
+ fs.writeFileSync(fileOf(ctx), JSON.stringify(all));
52
+ }
53
+ const running = new Map(); // key → started at (ms)
54
+ const say = (s) => { try { console.log('[star-draft] ' + s); } catch { /* no console */ } }; // the health log: landed / failed
55
+
56
+ function viaSession(ctx, ws, prompt, key) {
57
+ if (ctx && typeof ctx.askClaude === 'function') return Promise.resolve(ctx.askClaude(prompt, { job: 'star-draft', key, ws })).catch(() => null);
58
+ const headless = require('./headless.js');
59
+ const origin = 'briefing-ask:star-draft:' + key;
60
+ if (!ctx || typeof ctx.spawnSession !== 'function' || headless.kindFor({ agent: 'claude', origin }) !== 'ask') return Promise.resolve(null);
61
+ return new Promise((resolve) => {
62
+ let settled = false; const done = (v) => { if (settled) return; settled = true; clearTimeout(tm); resolve(v); };
63
+ const tm = setTimeout(() => done(null), TIMEOUT_MS);
64
+ let s = null;
65
+ try {
66
+ s = ctx.spawnSession({ name: 'Draft: ' + prompt.split('\n')[0].slice(0, 60), agent: 'claude', ws: ws || null, origin, initialInput: prompt,
67
+ modelAsk: { explicit: { model: MODEL, effort: 'low' } }, launchFlags: LEAN.map((f) => ({ ...f })),
68
+ onDone: (d) => { const r = d && d.result; done(r && r.ok && !r.isError ? String(r.text || '') : null); } });
69
+ } catch { s = null; }
70
+ if (!s || s.state === 'exited') done(null);
71
+ });
72
+ }
73
+
74
+ function peek(ctx, key) {
75
+ const have = readAll(ctx)[key];
76
+ if (running.has(key)) return { state: 'pending', key };
77
+ if (!have) return { state: 'none', key };
78
+ return have.text ? { state: 'ready', key, text: have.text, at: have.at } : { state: 'failed', key, why: have.why || 'PMOS could not draft it.' };
79
+ }
80
+
81
+ function start(ctx, { ws, ask, again = false, wait = false } = {}) {
82
+ const words = String(ask || '').trim();
83
+ if (!words) return { state: 'failed', key: '', why: 'There is nothing to draft.' };
84
+ const key = keyOf(ws, words);
85
+ if (running.has(key)) return { state: 'pending', key };
86
+ const have = readAll(ctx)[key];
87
+ if (have && have.text && !again) return { state: 'ready', key, text: have.text, at: have.at };
88
+ running.set(key, Date.now());
89
+ const p = Promise.resolve(viaSession(ctx, ws, askOf(words), key)).then((text) => {
90
+ const t = clean(text);
91
+ const value = t ? { text: t } : { text: '', why: text == null ? 'PMOS could not start a session.' : 'The records hold nothing to draft it from.' };
92
+ try { keepOne(ctx, key, value); } catch { /* the next press tries again */ }
93
+ say(t ? 'landed ' + t.length + ' characters' : 'failed: ' + value.why);
94
+ }).catch(() => {}).finally(() => running.delete(key));
95
+ if (wait) return p.then(() => peek(ctx, key));
96
+ return { state: 'pending', key };
97
+ }
98
+
99
+ module.exports = { keyOf, askOf, clean, start, peek, MODEL };
@@ -41,7 +41,8 @@ const USAGE = [
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
+ ' --parents <task>=<parent>|none,… gives each task its own parent (the Undo uses it when the tasks came from different parents).',
45
+ ' The answer prints the Undo: one command that puts every task back under the parent it had.',
45
46
  ' Group tasks under a stage of the initiative\'s workflow (key or name; none takes it out), or change dates, owner or notes.',
46
47
  ' --milestone makes a task a milestone: its due date shows as ◇ on Work and the timeline. Set it only when the PM asks.',
47
48
  ' --pin shows a milestone on the Work timeline, --no-pin hides it, --pin-default goes back to the rule (the last milestone',
@@ -70,8 +71,8 @@ const USAGE = [
70
71
  ];
71
72
  const BOOL = new Set(['json', 'help', 'all', 'milestone', 'no-milestone', 'pin', 'no-pin', 'pin-default', 'propose']);
72
73
  const PIN_FLAGS = ['pin', 'no-pin', 'pin-default'];
73
- const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes', 'stage', 'type', 'lag', 'parent']);
74
- 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: [], comment: [] };
74
+ const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes', 'stage', 'type', 'lag', 'parent', 'parents']);
75
+ const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage', 'parent'], list: ['all'], state: ['to', 'why'], remove: ['why'], set: ['due', 'start', 'owner', 'notes', 'stage', 'parent', 'parents'], link: ['type', 'lag', 'why'], unlink: [], describe: [], comment: [] };
75
76
  const OPEN = new Set(['To do', 'In progress']);
76
77
  /** The PM's words for a state: any case, with or without the apostrophe or the space. */
77
78
  function stateOf(s) {
@@ -215,7 +216,17 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
215
216
  };
216
217
 
217
218
  if (verb === 'set') {
218
- 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'] : []);
219
+ // --parents a=P,b=none (checker finding on chat-subtasks): each task its own parent, so one command can put several back
220
+ let PM = null;
221
+ if (flags.parents !== undefined) {
222
+ if (flags.parent !== undefined) return fail('give --parent or --parents, not both', 2);
223
+ PM = new Map(String(flags.parents).split(',').map((x) => x.trim()).filter(Boolean).map((x) => { const i = x.indexOf('='); return i > 0 ? [x.slice(0, i).trim(), x.slice(i + 1).trim()] : [x, null]; }));
224
+ const bad = [...PM].find(([, v]) => v == null || v === '');
225
+ if (bad) return fail(`--parents takes <task>=<parent> or <task>=none, comma-separated: "${bad[0]}" has no parent`, 2);
226
+ const miss = pos.filter((u) => !PM.has(u));
227
+ if (miss.length) return fail(`--parents names no parent for ${miss.join(', ')}`, 2);
228
+ }
229
+ const keys = ['stage', 'due', 'start', 'owner', 'notes', 'parent'].filter((k) => (k === 'parent' ? flags.parent !== undefined || PM : flags[k] !== undefined)).concat(flags.milestone || flags['no-milestone'] ? ['milestone'] : []).concat(PIN_FLAGS.some((k) => flags[k]) ? ['pinned'] : []);
219
230
  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; }
220
231
  const folded = boards.foldOf(ctx, w);
221
232
  const done = [], refused = [];
@@ -232,7 +243,8 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
232
243
  }
233
244
  for (const k of ['due', 'start']) if (flags[k] !== undefined) body[k] = String(flags[k]).toLowerCase() === 'none' ? '' : flags[k];
234
245
  for (const k of ['owner', 'notes']) if (flags[k] !== undefined) body[k] = flags[k];
235
- if (flags.parent !== undefined) body.parent = String(flags.parent).toLowerCase() === 'none' ? '' : String(flags.parent); // a subtask (initiative work-subtasks)
246
+ const pv = PM ? PM.get(id) : flags.parent;
247
+ if (pv !== undefined) body.parent = String(pv).toLowerCase() === 'none' ? '' : String(pv); // a subtask (initiative work-subtasks)
236
248
  if (flags.milestone || flags['no-milestone']) body.milestone = !!flags.milestone;
237
249
  if (PIN_FLAGS.some((k) => flags[k])) body.pinned = flags.pin ? true : flags['no-pin'] ? false : null;
238
250
  const e = boards.taskEdit(ctx, body, g);
@@ -246,17 +258,19 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
246
258
  const TLR = require('./routes-task-links.js'), F2 = boards.foldOf(ctx, w), seen = new Set();
247
259
  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; }
248
260
  }
249
- // the Undo of a parent move (initiative chat-subtasks): one command per old parent puts every task back where it was
250
- const back = new Map();
251
- 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); }
252
- const undo = [...back].map(([was, ids]) => `pmos task set ${ids.join(' ')} --parent ${was || 'none'}`);
253
- if (flags.parent !== undefined && done.length) console.error('[task-parent]', 'set', done.length);
254
- if (json) say(JSON.stringify({ ok: !refused.length, done, refused, ...(kept ? { moved: kept } : {}), ...(flags.parent !== undefined ? { undo } : {}) }));
261
+ // the Undo of a parent move (initiative chat-subtasks): ONE command puts every task back where it was; --parent when they shared one, else --parents
262
+ const back = done.filter((d) => d.was !== undefined && d.was !== d.set.parent);
263
+ const olds = [...new Set(back.map((d) => d.was))];
264
+ const undo = !back.length ? '' : olds.length === 1 ? `pmos task set ${back.map((d) => d.task).join(' ')} --parent ${olds[0] || 'none'}`
265
+ : `pmos task set ${back.map((d) => d.task).join(' ')} --parents ${back.map((d) => d.task + '=' + (d.was || 'none')).join(',')}`;
266
+ const moving = flags.parent !== undefined || !!PM;
267
+ if (moving && done.length) console.error('[task-parent]', 'set', done.length);
268
+ if (json) say(JSON.stringify({ ok: !refused.length, done, refused, ...(kept ? { moved: kept } : {}), ...(moving ? { undo } : {}) }));
255
269
  else {
256
270
  for (const d of done) say(`✓ ${d.task} ${what(d.set)}: ${d.title}`);
257
271
  for (const x of refused) say(`✗ ${x.task}: ${x.error}`);
258
272
  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 ✦.`);
259
- for (const u of undo) say(' Undo: ' + u);
273
+ if (undo) say(' Undo: ' + undo);
260
274
  if (done.length) say(' The page shows it. Nothing was sent.');
261
275
  }
262
276
  return refused.length ? 1 : 0;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.780.0",
3
+ "version": "0.782.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.780.0",
9
+ "version": "0.782.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.780.0",
3
+ "version": "0.782.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",