create-pmos 0.828.0 → 0.829.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 (75) hide show
  1. package/package.json +140 -22
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/board-deliveries-test.js +2 -2
  7. package/workspace/changelog.json +139 -8
  8. package/workspace/guide/cli.md +34 -1
  9. package/workspace/guide/home.md +1 -0
  10. package/workspace/guide/settings-and-switches.md +1 -0
  11. package/workspace/lib/board-premium.js +1 -0
  12. package/workspace/lib/critical-needs.js +162 -0
  13. package/workspace/lib/deps-cli.js +102 -0
  14. package/workspace/lib/engine/boards.js +13 -2
  15. package/workspace/lib/features.json +3 -0
  16. package/workspace/lib/needs-providers.js +1 -0
  17. package/workspace/lib/page-one-answer.js +86 -0
  18. package/workspace/lib/pages-cli.js +6 -2
  19. package/workspace/lib/pmos-verbs.js +8 -0
  20. package/workspace/lib/prototype-cli.js +86 -0
  21. package/workspace/lib/report-cli.js +12 -2
  22. package/workspace/lib/report-readers.js +5 -3
  23. package/workspace/lib/review-pack.js +348 -0
  24. package/workspace/lib/route-modules.js +4 -0
  25. package/workspace/lib/routes-boards.js +25 -2
  26. package/workspace/lib/routes-review-pack.js +42 -0
  27. package/workspace/lib/routes-roadmap-ops.js +53 -1
  28. package/workspace/lib/routes-sim-users.js +66 -0
  29. package/workspace/lib/routes-team-waits.js +24 -0
  30. package/workspace/lib/sim-users.js +329 -0
  31. package/workspace/lib/task-store.js +1 -1
  32. package/workspace/lib/team-waits.js +167 -0
  33. package/workspace/lib/tradeoff-cards.js +258 -0
  34. package/workspace/lib/tradeoff-cli.js +83 -0
  35. package/workspace/package-lock.json +2 -2
  36. package/workspace/package.json +1 -1
  37. package/workspace/public/pm/bd-backlog.js +44 -6
  38. package/workspace/public/pm/cozy-library.css +5 -0
  39. package/workspace/public/pm/cozy-pop-work.js +2 -1
  40. package/workspace/public/pm/cozy-proto.css +5 -0
  41. package/workspace/public/pm/cozy-proto.js +11 -3
  42. package/workspace/public/pm/cozy-today-app.js +5 -2
  43. package/workspace/public/pm/day-time.js +8 -0
  44. package/workspace/public/pm/home-ini.js +3 -2
  45. package/workspace/public/pm/ini-links.js +2 -1
  46. package/workspace/public/pm/ini-tasks.js +5 -2
  47. package/workspace/public/pm/ini-view-model.js +14 -6
  48. package/workspace/public/pm/ini-view.js +12 -2
  49. package/workspace/public/pm/library-model.js +1 -1
  50. package/workspace/public/pm/page-one-answer.css +18 -0
  51. package/workspace/public/pm/page-one-answer.js +134 -0
  52. package/workspace/public/pm/pop-work-model.js +8 -6
  53. package/workspace/public/pm/portfolio.js +1 -1
  54. package/workspace/public/pm/premium-board.js +19 -6
  55. package/workspace/public/pm/premium-library.js +27 -3
  56. package/workspace/public/pm/range-pick.css +12 -0
  57. package/workspace/public/pm/range-pick.js +30 -6
  58. package/workspace/public/pm/review-pack.js +47 -0
  59. package/workspace/public/pm/sim-users.js +34 -0
  60. package/workspace/public/pm/sort-order.js +3 -0
  61. package/workspace/public/pm/task-card.js +10 -7
  62. package/workspace/public/pm/team-waits.js +56 -0
  63. package/workspace/public/pm/tradeoff-cards.css +27 -0
  64. package/workspace/public/pm/tradeoff-cards.js +183 -0
  65. package/workspace/public/premium-board.html +1 -0
  66. package/workspace/public/today.html +1 -0
  67. package/workspace/run-tests.js +9 -1
  68. package/workspace/test-lists/critical-needs.json +9 -0
  69. package/workspace/test-lists/page-one-answer.json +9 -0
  70. package/workspace/test-lists/review-pack.json +9 -0
  71. package/workspace/test-lists/sim-users.json +9 -0
  72. package/workspace/test-lists/task-time-optional.json +9 -0
  73. package/workspace/test-lists/team-waits.json +9 -0
  74. package/workspace/test-lists/tradeoff-cards.json +9 -0
  75. package/workspace/test-timings.json +25 -0
@@ -39,7 +39,7 @@ const actorLib = require('./actor.js');
39
39
  const RS = require('./report-setups.js');
40
40
  const { parseArgs } = require('./schedule-cli');
41
41
 
42
- const COMMANDS = { report: ['make', 'read', 'find', 'write', 'check', 'rule', 'draft', 'issue', 'list', 'propose', 'definitions', 'setups', 'finder', 'library', 'language', 'variants'] };
42
+ const COMMANDS = { report: ['make', 'read', 'find', 'write', 'check', 'rule', 'draft', 'issue', 'list', 'propose', 'definitions', 'setups', 'finder', 'library', 'language', 'variants', 'pack'] };
43
43
  const USAGE = [
44
44
  'usage: pmos report make|read|find|write|check|rule — the report engine: brief, read, find, answer, render (any report, any shape)',
45
45
  ' pmos report make <id> [--ask "<the question>"] [--readers "<who>"] [--source <kind:ref>,…] [--template <id>] [--slot <date>]',
@@ -82,12 +82,16 @@ const USAGE = [
82
82
  ' pmos report variants <cadence> [<slot>] [--only executives,engineers,customers]',
83
83
  ' The draft (default: the newest) in one version each for executives, engineers and customers, beside it',
84
84
  ' (<slot>.for-<audience>.md). A version holds only numbers and names the draft holds, and ends with its sources. Nothing is sent.',
85
+ ' pmos report pack [--redraft] [--now <time>]',
86
+ ' The monthly review pack of this product: goals with their state, bets that failed and the lesson, the next big decision and the asks.',
87
+ ' Every line names the record it came from; a line with no record is left out. A pack that exists is yours to edit: --redraft writes it again.',
88
+ ' Library drafts it by itself when it opens in the last 7 days of the month. Nothing is sent: share it with the Issue press.',
85
89
  ' every command: [--json] [--root <dir>]. The cadence is the report skill id without "report-", for example biweekly.',
86
90
  ];
87
91
  const BOOL = new Set(['json', 'redraft', 'help', 'off']);
88
92
  const VALUE = new Set(['now', 'root', 'ask', 'readers', 'source', 'slot', 'from', 'out', 'template', 'only']);
89
93
  const ALLOWED = { make: ['json', 'now', 'root', 'ask', 'readers', 'source', 'slot', 'template'], read: ['json', 'now', 'root', 'slot', 'from', 'source'], find: ['json', 'now', 'root', 'slot', 'from'],
90
- write: ['json', 'now', 'root', 'slot', 'from'], check: ['json', 'root', 'slot'], rule: ['json', 'root'], draft: ['json', 'redraft', 'now', 'root'], issue: ['root'], list: ['json', 'root'], propose: ['json', 'root'], definitions: ['json', 'root'], setups: ['json', 'root'], finder: ['json', 'root'], language: ['json', 'root', 'off'], variants: ['json', 'root', 'only'], library: ['json', 'out', 'template'] };
94
+ write: ['json', 'now', 'root', 'slot', 'from'], check: ['json', 'root', 'slot'], rule: ['json', 'root'], draft: ['json', 'redraft', 'now', 'root'], issue: ['root'], list: ['json', 'root'], propose: ['json', 'root'], definitions: ['json', 'root'], setups: ['json', 'root'], finder: ['json', 'root'], language: ['json', 'root', 'off'], variants: ['json', 'root', 'only'], library: ['json', 'out', 'template'], pack: ['json', 'redraft', 'now', 'root'] };
91
95
  const CADENCE_RE = /^[a-z][a-z0-9-]{0,39}$/;
92
96
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
93
97
 
@@ -156,6 +160,12 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
156
160
  return 0;
157
161
  }
158
162
 
163
+ if (verb === 'pack') {
164
+ // the monthly review pack (lib/review-pack.js): drafted from the product's records, never sent
165
+ const a = [...(json ? ['--json'] : []), ...(flags.redraft ? ['--redraft'] : []), ...(flags.now ? ['--now', String(flags.now)] : [])];
166
+ return require('./review-pack.js').cli(a, { root, say, now: now ? Number(now) || Date.parse(now) : Date.now() });
167
+ }
168
+
159
169
  if (verb === 'library') {
160
170
  // the slide library as one page: sanitized as a report render is, with the workspace face inlined so the file shows it anywhere
161
171
  const out = path.resolve(cwd || process.cwd(), typeof flags.out === 'string' && flags.out ? flags.out : 'report-library.html');
@@ -48,7 +48,7 @@ function blockOf(text) {
48
48
  const titles = new Map();
49
49
  let inInis = false, cur = null;
50
50
  L.forEach((l, i) => {
51
- if (/^##\s/.test(l)) { inInis = /^##\s+Initiatives\s*$/i.test(l); cur = null; return; }
51
+ if (/^##\s/.test(l)) { inInis = /^##\s+(Initiatives|Bets that failed)\s*$/i.test(l); cur = null; return; } // the review pack's failed bets are blocks too
52
52
  const m = inInis && /^###\s+(.+?)\s+\(([A-Za-z0-9._-]{1,80})\)\s*$/.exec(l);
53
53
  if (m) { cur = m[2]; titles.set(m[2], m[1].trim()); }
54
54
  if (inInis) out[i] = cur;
@@ -185,7 +185,7 @@ let attached = false;
185
185
  function attach(ctxFactory) {
186
186
  if (attached || typeof ctxFactory !== 'function') return;
187
187
  attached = true;
188
- require('./report-draft.js').onDraftWritten(({ root, cadence, path: rel }) => {
188
+ const heard = ({ root, cadence, path: rel }) => {
189
189
  setImmediate(() => {
190
190
  let ctx = null; try { ctx = ctxFactory(); } catch { ctx = null; }
191
191
  if (!ctx) return;
@@ -199,7 +199,9 @@ function attach(ctxFactory) {
199
199
  file({ root: abs, rel, cadence, dir, runtime: ctx.runtimeDir || null, ask: SC.askVia(spawn), ws: w.id || '', board })
200
200
  .catch((e) => console.log(`[report-readers] ${rel}: not run (${one(e && e.message, 160)})`));
201
201
  });
202
- });
202
+ };
203
+ require('./report-draft.js').onDraftWritten(heard);
204
+ try { require('./review-pack.js').onWritten(heard); } catch { /* a checkout without the review pack still reads its reports */ } // the monthly review pack (job #1910)
203
205
  }
204
206
 
205
207
  /** Reader proposals filed in one state folder: the health number. */
@@ -0,0 +1,348 @@
1
+ 'use strict';
2
+ /* review-pack.js — the monthly product review pack (initiative review-pack, job #1910, idea A343; board BatchMoreADS panel 25, agreed 2026-11-25).
3
+ *
4
+ * Before a monthly review with leadership the PM writes the same page from zero. PMOS already keeps each part of it as a record, so it drafts
5
+ * the page and the PM edits it. One pack per product per month. No model call: every line is read from a record, and every line names that
6
+ * record. A part with nothing to cite is left out (no source, no line; zero is silence).
7
+ *
8
+ * gather(root, { today, stateDir }) → { goals, failed, decision, asks } the product's records, each item with `source` { label, ref } or none
9
+ * goals the key results of the OKR files and the loose KR metric records (lib/goal-source.js), with the state of their newest reading
10
+ * (lib/goal-status.js readingOf). Source: the reading's own source, else the key result's line in the OKR file, else the record.
11
+ * failed each refuted outcome check of the last WINDOW_DAYS days (outcome_checks.jsonl, the live checks only), with the newest Lessons
12
+ * line of that experiment (artefacts.jsonl). Source: the check's path:line.
13
+ * decision a key result of the OKR files that is a decision (okr-goals `decision`: go/no-go, decided by) with a date today or later, the
14
+ * nearest first; else the decision journal's next look-again (state open or due), the nearest first. Source: its line.
15
+ * asks the Narrative artefact's `asks` lines of the product (scope portfolio or board:<id>), newest first. Source: the set's own sources.
16
+ * packOf({ product, today, goals, failed, decision, asks }) PURE → { title, month, slot, sections: [{ key, head, lines | bets }], dropped } | null
17
+ * null when no part has a line. `dropped` counts the items left out for having no source.
18
+ * markdown(pack) PURE → the file. readPack(text) PURE → { title, sections } read back from a file (the PM's edits show in Library)
19
+ * write(root, pack, { redraft }) → { ok, path, sha, written } | { ok: false, status, error }
20
+ * <state>/reports/review-pack/<YYYY-MM>-01.md (lib/report-draft.js draftPath, so the Issue press and the report readers know it).
21
+ * A pack that exists is left byte for byte as it is (the PM may have edited it) unless `redraft`; an issued pack is frozen (409).
22
+ * After a write, the report readers are told (onWritten: lib/report-readers.js attach listens here as it does to report drafts).
23
+ * onWritten(fn) → unsubscribe
24
+ * itemsOf({ ws, name, packs }) PURE → Library rows (the lib/library-items.js ITEM shape) in the Reports family, kind 'Review pack', with
25
+ * `pack` { sections, cadence, slot, sha, issued } for the preview and the share (Issue) press. lib/routes-review-pack.js serves them.
26
+ * due(today) PURE → true in the last DUE_DAYS days of the month: the pack is drafted before the review.
27
+ * tick(ctx, now) → [{ ws, ok, path? , why? }] drafts the month's pack of each product that has none, when due. Never shares.
28
+ * autoOn(env) → whether Library's open drafts due packs here (PMOS_REVIEW_PACK; off by default on a scratch server)
29
+ * list(root) → [{ path, slot, title, sections, sha, cadence }] the packs of one product, newest first (Library › Reports)
30
+ * cli(args, { root, now, say }) → exit code `pmos report pack [--redraft] [--json] [--now <time>]`
31
+ * The copy names PMOS only. Sharing is the PM's Issue press (POST /api/report/issue); nothing here issues or sends. */
32
+ const fs = require('fs');
33
+ const path = require('path');
34
+
35
+ const CADENCE = 'review-pack';
36
+ const WINDOW_DAYS = 30;
37
+ const DUE_DAYS = 7;
38
+ const MAX = { goals: 6, failed: 4, asks: 4 };
39
+ const DAY = 86400000;
40
+ const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
41
+ const MON = MONTHS.map((m) => m.slice(0, 3));
42
+ const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
43
+ const one = (v, n = 240) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
44
+ const short = (d) => (DAY_RE.test(String(d || '')) ? (+d.slice(8, 10)) + ' ' + MON[+d.slice(5, 7) - 1] : String(d || ''));
45
+ const firstSentence = (s) => { const t = one(s, 600); const m = /^(.+?[.;])(\s|$)/.exec(t); return one(m ? m[1].replace(/[.;]$/, '') : t, 160); };
46
+ const relOf = (root, f) => path.relative(root, f).split(path.sep).join('/');
47
+ const SEVERITY = { broken: 0, behind: 1, close: 2, none: 3, on: 4 };
48
+ const STATE_WORD = { on: 'on track', behind: 'behind', close: 'near its limit', broken: 'over its limit', none: 'no reading yet' };
49
+ const HEAD = { goals: 'Goals', failed: 'Bets that failed', decision: 'Next big decision', asks: 'Asks' };
50
+ const SAID = 'Drafted by PMOS from goals, experiments and decisions. Edit, then share.';
51
+
52
+ /* ── reading the records ─────────────────────────────────────────────────────────────────────────────────────────────── */
53
+ function linesOf(file) { try { return fs.readFileSync(file, 'utf8').split('\n'); } catch { return null; } }
54
+ function stateDirOf(root) {
55
+ for (const rel of [['pmos', 'state'], ['state'], ['.pmos']]) { const d = path.join(root, ...rel); try { if (fs.statSync(d).isDirectory()) return d; } catch { /* next */ } }
56
+ try { return require('./driver.js').stateDirOf(root); } catch { return null; }
57
+ }
58
+ function okrDirOf(root) {
59
+ for (const d of [path.join(root, 'pmos', 'planning', 'okrs'), path.join(root, 'planning', 'okrs')]) { try { if (fs.statSync(d).isDirectory()) return d; } catch { /* next */ } }
60
+ return null;
61
+ }
62
+ /** The path:line of the first line of the OKR files that names a key result's token as a heading or a list item. */
63
+ const tokRe = (t) => new RegExp('(^|[^A-Za-z0-9.-])' + String(t).replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '([^A-Za-z0-9-]|$)');
64
+ const listy = (l) => /^\s*(#{1,6}\s|[-*]\s|\|)/.test(l);
65
+ /** The path:line of a key result in the OKR files: the first heading or list line naming its token after its objective's line (KR1 repeats per objective). */
66
+ function okrRef(root, files, token, objective) {
67
+ const dir = okrDirOf(root);
68
+ if (!dir || !token) return null;
69
+ const re = tokRe(token), ro = objective ? tokRe(objective) : null;
70
+ for (const f of files || []) {
71
+ const L = linesOf(path.join(dir, f));
72
+ if (!L) continue;
73
+ const o = ro ? L.findIndex((l) => listy(l) && ro.test(l)) : 0;
74
+ if (o < 0) continue;
75
+ const i = L.findIndex((l, n) => n >= o && listy(l) && re.test(l));
76
+ if (i >= 0) return relOf(root, path.join(dir, f)) + ':' + (i + 1);
77
+ }
78
+ return null;
79
+ }
80
+ function titleOf(root, id) {
81
+ for (const d of [path.join(root, 'pmos', 'state', 'initiatives'), path.join(root, 'planning', 'initiatives')]) {
82
+ const L = linesOf(path.join(d, id + '.md'));
83
+ if (!L) continue;
84
+ const t = L.slice(0, 40).find((l) => /^title:\s*/.test(l));
85
+ if (t) return one(t.replace(/^title:\s*/, '').replace(/^["']|["']$/g, ''), 120);
86
+ }
87
+ return id;
88
+ }
89
+ function goalsOf(root, today) {
90
+ const GS = require('./goal-status.js');
91
+ let src; try { src = require('./goal-source.js').source({ root }); } catch { return []; }
92
+ const files = (src.okr && src.okr.files) || [];
93
+ let recRel = ''; try { recRel = relOf(root, require('./goal-source.js').recordsDirOf(root)) + '/kr-metrics.jsonl'; } catch { recRel = ''; }
94
+ const out = [];
95
+ const add = (title, rec, token, objective) => {
96
+ const r = rec ? GS.readingOf(rec, today) : { dot: 'none', txt: '', source: '' };
97
+ let ref = r.source ? one(r.source, 200) : '';
98
+ let label = ref ? 'reading' : '';
99
+ if (!ref && token) { ref = okrRef(root, files, token, objective) || ''; label = ref ? 'OKR file' : ''; }
100
+ if (!ref && rec && rec.rid && recRel) { ref = recRel + '#' + rec.rid; label = 'goal record'; }
101
+ const state = STATE_WORD[r.dot] || 'no reading yet';
102
+ const text = r.dot === 'none' ? `${title}: no reading yet` : `${title}: ${r.txt}${r.txt ? ' · ' : ''}${state}${r.stale && r.ageDays != null ? `, reading ${r.ageDays} days old` : ''}`;
103
+ out.push({ title, dot: r.dot, text: one(text, 200), source: ref ? { label, ref } : null });
104
+ };
105
+ for (const g of src.goals || []) if (!(g.k && g.k.decision && !g.record)) add(one(g.title, 110), g.record, g.token, g.o && g.o.token); // a decision key result is the Next big decision, not a goal
106
+ for (const rec of src.loose || []) add(one(rec.title || rec.rid, 110), rec, null);
107
+ return out.sort((a, b) => SEVERITY[a.dot] - SEVERITY[b.dot]);
108
+ }
109
+ function failedOf(root, today, stateDir) {
110
+ const O = require('./outcomes.js');
111
+ const files = [...new Set([stateDir && path.join(stateDir, 'outcome_checks.jsonl'), path.join(root, 'pmos', 'state', 'outcome_checks.jsonl'), path.join(root, 'planning', 'runs', 'outcome_checks.jsonl')].filter(Boolean))];
112
+ const rows = [], at = new Map();
113
+ for (const f of files) (linesOf(f) || []).forEach((l, i) => { let o = null; try { o = JSON.parse(l); } catch { return; } if (o && o.initiative_id) { rows.push(o); at.set(o, relOf(root, f) + ':' + (i + 1)); } });
114
+ const live = new Set(O.liveChecks(rows));
115
+ const from = Date.parse(today + 'T00:00:00Z') - WINDOW_DAYS * DAY, to = Date.parse(today + 'T23:59:59Z');
116
+ let lessons = new Map();
117
+ try {
118
+ const A = require('./artefacts.js');
119
+ const F = A.fold(A.readLines(A.file(stateDir)));
120
+ lessons = new Map([...F].map(([scope, m]) => [scope, ((m.get('lessons') || {}).sets || []).filter((s) => s.text)]));
121
+ } catch { lessons = new Map(); }
122
+ const out = [];
123
+ for (const r of rows) {
124
+ if (!live.has(r) || r.disposition !== 'refuted') continue;
125
+ const t = Date.parse(r.checked_at || r.at || r.date || '');
126
+ if (!(t >= from && t <= to)) continue;
127
+ const id = String(r.initiative_id);
128
+ const ls = lessons.get('experiment:' + id) || lessons.get('initiative:' + id) || [];
129
+ const lesson = ls.length ? one(ls[ls.length - 1].text, 160) : '';
130
+ const found = firstSentence(r.evidence);
131
+ const text = (found || 'The outcome check refuted it') + (lesson ? `; learned ${lesson.replace(/^learned\s+/i, '')}` : '');
132
+ out.push({ id, title: titleOf(root, id), at: t, text: one(text, 280), source: { label: 'outcome check', ref: at.get(r) } });
133
+ }
134
+ return out.sort((a, b) => b.at - a.at);
135
+ }
136
+ function decisionOf(root, today) {
137
+ try {
138
+ const OG = require('./okr-goals.js');
139
+ const okr = OG.read(root);
140
+ const ks = [];
141
+ for (const o of (okr.ok && okr.objectives) || []) for (const k of o.krs || []) if (k.decision && DAY_RE.test(String(k.due || '')) && k.due >= today) ks.push(Object.assign({ otoken: o.token }, k));
142
+ ks.sort((a, b) => a.due.localeCompare(b.due));
143
+ for (const k of ks) {
144
+ const ref = okrRef(root, okr.files, k.token, k.otoken);
145
+ if (ref) return { text: one(`${k.title}, by ${short(k.due)}`, 200), source: { label: 'OKR file', ref } };
146
+ }
147
+ } catch { /* no OKR file */ }
148
+ try {
149
+ const DJ = require('./decision-journal.js');
150
+ const J = DJ.read(root);
151
+ const es = DJ.fold(J.rows, { today }).filter((e) => (e.state === 'open' || e.state === 'due') && e.decided && DAY_RE.test(String(e.check || ''))).sort((a, b) => a.check.localeCompare(b.check));
152
+ for (const e of es) {
153
+ for (const f of (DJ.filesOf(root).all || [])) {
154
+ const L = linesOf(f) || [];
155
+ const i = L.findIndex((l) => l.includes(`"id":"${e.id}"`) && l.includes('"decision"'));
156
+ if (i >= 0) return { text: one(`Look again at "${one(e.decided, 120)}", by ${short(e.check)}`, 200), source: { label: 'decision journal', ref: relOf(root, f) + ':' + (i + 1) } };
157
+ }
158
+ }
159
+ } catch { /* no journal */ }
160
+ return null;
161
+ }
162
+ function asksOf(stateDir) {
163
+ try {
164
+ const A = require('./artefacts.js');
165
+ const F = A.fold(A.readLines(A.file(stateDir)));
166
+ const out = [];
167
+ for (const [scope, m] of F) {
168
+ if (scope !== 'portfolio' && !/^board:/.test(scope)) continue;
169
+ for (const s of ((m.get('narrative') || {}).sets || [])) {
170
+ if (s.field !== 'asks' || !one(s.text)) continue;
171
+ const src = (Array.isArray(s.sources) ? s.sources : []).find((x) => x && x.ref);
172
+ out.push({ at: String(s.at || ''), text: one(s.text, 200), source: src ? { label: one(src.label || 'source', 40), ref: one(src.ref, 200) } : null });
173
+ }
174
+ }
175
+ return out.sort((a, b) => b.at.localeCompare(a.at));
176
+ } catch { return []; }
177
+ }
178
+ function gather(root, { today, stateDir } = {}) {
179
+ const abs = path.resolve(String(root));
180
+ const dir = stateDir || stateDirOf(abs);
181
+ const t = DAY_RE.test(String(today || '')) ? today : new Date().toISOString().slice(0, 10);
182
+ return { goals: goalsOf(abs, t), failed: dir || abs ? failedOf(abs, t, dir) : [], decision: decisionOf(abs, t), asks: dir ? asksOf(dir) : [] };
183
+ }
184
+
185
+ /* ── the pack ─────────────────────────────────────────────────────────────────────────────────────────────────────────── */
186
+ const cited = (x) => !!(x && one(x.text) && x.source && one(x.source.ref));
187
+ function packOf({ product, today, goals = [], failed = [], decision = null, asks = [] } = {}) {
188
+ if (!DAY_RE.test(String(today || ''))) return null;
189
+ let dropped = 0;
190
+ const keep = (xs, n) => { const all = (xs || []).filter((x) => x && one(x.text)); const ok = all.filter(cited); dropped += all.length - ok.length; return ok.slice(0, n); };
191
+ const sections = [];
192
+ const g = keep(goals, MAX.goals);
193
+ if (g.length) sections.push({ key: 'goals', head: HEAD.goals, lines: g.map((x) => ({ text: one(x.text, 200), source: x.source })) });
194
+ const f = keep(failed, MAX.failed);
195
+ if (f.length) sections.push({ key: 'failed', head: HEAD.failed, bets: f.map((x) => ({ id: x.id, title: one(x.title || x.id, 120), lines: [{ text: one(x.text, 280), source: x.source }] })) });
196
+ const d = keep(decision ? [decision] : [], 1);
197
+ if (d.length) sections.push({ key: 'decision', head: HEAD.decision, lines: [{ text: one(d[0].text, 200), source: d[0].source }] });
198
+ const a = keep(asks, MAX.asks);
199
+ if (a.length) sections.push({ key: 'asks', head: HEAD.asks, lines: a.map((x) => ({ text: one(x.text, 200), source: x.source })) });
200
+ if (!sections.length) return null;
201
+ const month = MONTHS[+today.slice(5, 7) - 1];
202
+ const name = one(product || 'Product', 80);
203
+ return { title: `${name} · ${month} review`, product: name, month, slot: today.slice(0, 7) + '-01', today, sections, dropped };
204
+ }
205
+ const srcText = (s) => (s && s.ref ? ` — source: \`${String(s.ref).replace(/`/g, "'")}\`` : '');
206
+ function markdown(pack) {
207
+ const out = ['---', 'type: Reference', `title: ${JSON.stringify(pack.title)}`, `timestamp: ${pack.today}`, 'kind: review-pack', 'status: draft', '---', '',
208
+ `# ${pack.title}`, '', `✦ ${SAID}`, ''];
209
+ for (const s of pack.sections) {
210
+ out.push(`## ${s.head}`, '');
211
+ if (s.bets) for (const b of s.bets) { out.push(`### ${b.title} (${b.id})`, ''); for (const l of b.lines) out.push(`- ${l.text}${srcText(l.source)}`); out.push(''); }
212
+ else { for (const l of s.lines) out.push(`- ${l.text}${srcText(l.source)}`); out.push(''); }
213
+ }
214
+ return out.join('\n');
215
+ }
216
+ const KEY_OF = Object.fromEntries(Object.entries(HEAD).map(([k, v]) => [v.toLowerCase(), k]));
217
+ function readPack(text) {
218
+ const body = String(text || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
219
+ const L = body.split(/\r?\n/);
220
+ const t = L.find((l) => /^#\s/.test(l));
221
+ const sections = [];
222
+ let cur = null, bet = null;
223
+ for (const l of L) {
224
+ const h = /^##\s+(.+?)\s*$/.exec(l);
225
+ if (h) { cur = { key: KEY_OF[h[1].toLowerCase()] || 'other', head: one(h[1], 80), lines: [] }; sections.push(cur); bet = null; continue; }
226
+ const b = cur && /^###\s+(.+?)(?:\s+\(([A-Za-z0-9._-]{1,80})\))?\s*$/.exec(l);
227
+ if (b) { bet = b[2] || ''; cur.lines.push({ text: one(b[1], 160), head: true, id: bet }); continue; }
228
+ const li = cur && /^\s*[-*]\s+(.+)$/.exec(l);
229
+ if (li) {
230
+ const m = /^(.*?)\s+—\s+source:\s+`([^`]+)`\s*$/.exec(li[1]);
231
+ cur.lines.push(m ? { text: one(m[1], 300), source: one(m[2], 200) } : { text: one(li[1], 300), source: '' });
232
+ }
233
+ }
234
+ return { title: t ? one(t.replace(/^#\s+/, ''), 160) : '', sections: sections.filter((s) => s.lines.length) };
235
+ }
236
+
237
+ /* ── writing ── */
238
+ const heard = new Set(); // the report readers (lib/report-readers.js attach) hear each pack this process writes, as they hear a cadence draft
239
+ /** Call fn({ root, cadence, slot, path }) after each pack this process writes. → an unsubscribe function */
240
+ function onWritten(fn) { if (typeof fn === 'function') heard.add(fn); return () => heard.delete(fn); }
241
+ /* ──────────────────────────────────────────────────────────────────────────────────────────────────────────── */
242
+ function write(root, pack, { redraft = false } = {}) {
243
+ if (!pack || !pack.slot) return { ok: false, status: 400, error: 'there is no pack to write: no part has a line with a source' };
244
+ const RD = require('./report-draft.js'), IS = require('./issues.js');
245
+ const abs = path.resolve(String(root));
246
+ const rel = RD.draftPath(abs, CADENCE, pack.slot);
247
+ const file = path.join(abs, rel);
248
+ if (IS.isIssued(IS.readIssues(abs), CADENCE, pack.slot)) return { ok: false, status: 409, error: `the ${pack.month} pack is shared (issued) and frozen; nothing was written` };
249
+ let st = null; try { st = fs.lstatSync(file); } catch { st = null; }
250
+ if (st && !st.isFile()) return { ok: false, status: 403, error: `${rel} is not a regular file; nothing was written` };
251
+ if (st && !redraft) return { ok: true, path: rel, written: false, why: 'the pack exists; it is yours to edit (add --redraft to write it again)' };
252
+ const md = markdown(pack);
253
+ const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
254
+ try { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(tmp, md, { flag: 'wx' }); fs.renameSync(tmp, file); } catch (e) {
255
+ try { fs.unlinkSync(tmp); } catch { /* not made */ }
256
+ return { ok: false, status: 500, error: 'could not write the pack: ' + one(e && e.message, 160) };
257
+ }
258
+ console.info(`[review-pack] wrote ${rel} sections=${pack.sections.length} dropped=${pack.dropped}`);
259
+ for (const fn of heard) { try { fn({ root: abs, cadence: CADENCE, slot: pack.slot, path: rel }); } catch { /* a listener never fails the write */ } }
260
+ return { ok: true, path: rel, written: true, sha: IS.blobSha(Buffer.from(md, 'utf8')) };
261
+ }
262
+ function due(today) {
263
+ if (!DAY_RE.test(String(today || ''))) return false;
264
+ const y = +today.slice(0, 4), m = +today.slice(5, 7), d = +today.slice(8, 10);
265
+ const last = new Date(Date.UTC(y, m, 0)).getUTCDate();
266
+ return d > last - DUE_DAYS;
267
+ }
268
+ /** Does Library draft due packs by itself here? PMOS_REVIEW_PACK=0 turns it off, =1 on; by default a scratch server (its own PMOS_STATE_DIR,
269
+ * which every suite sets) writes no pack into the repositories it hosts (the lib/profile-default.js rule). */
270
+ function autoOn(env = process.env) {
271
+ const v = String((env && env.PMOS_REVIEW_PACK) || '').trim();
272
+ if (v === '0') return false;
273
+ if (v === '1') return true;
274
+ return !String((env && env.PMOS_STATE_DIR) || '').trim();
275
+ }
276
+ function itemsOf({ ws, name, packs } = {}) {
277
+ const about = { ws: ws || null, product: one(name, 80), ini: null, title: '', program: null, programTitle: '' };
278
+ return (packs || []).filter((k) => k && k.path).map((k) => ({
279
+ id: 'pack:' + ws + ':' + k.path, kind: 'doc', name: k.title || 'Review pack', sub: '', kindText: 'Review pack', type: 'Review pack', family: 'reports',
280
+ state: k.issued ? 'Issued' : 'Draft', v: null, gate: false, came: '', by: 'PMOS', ed: null, about: { ...about }, product: about.product,
281
+ scope: ws ? ['p:' + ws] : [], updated: k.updated || k.slot || null, held: null, path: k.path, open: { doc: { ws, path: k.path } },
282
+ pack: { sections: k.sections || [], cadence: k.cadence, slot: k.slot, sha: k.sha, issued: !!k.issued },
283
+ }));
284
+ }
285
+ function nameOf(w) { return one((w && (w.label || w.name || w.id)) || 'Product', 80); }
286
+ function draftFor(root, { product, today, stateDir, redraft = false } = {}) {
287
+ if (!redraft) {
288
+ // a pack that exists is the PM's to edit: say so before reading any record
289
+ try { const rel = require('./report-draft.js').draftPath(path.resolve(String(root)), CADENCE, String(today).slice(0, 7) + '-01'); if (fs.existsSync(path.join(path.resolve(String(root)), rel))) return { ok: true, path: rel, written: false, why: 'the pack exists; it is yours to edit (add --redraft to write it again)' }; } catch { /* write() says */ }
290
+ }
291
+ const pack = packOf({ product, today, ...gather(root, { today, stateDir }) });
292
+ if (!pack) return { ok: true, written: false, why: 'nothing to cite: no goal, failed bet, decision or ask has a record' };
293
+ return Object.assign(write(root, pack, { redraft }), { pack });
294
+ }
295
+ const tried = new Map(); // ws → the day it was last tried: one read a day per product, not one a minute
296
+ async function tick(ctx, now = new Date()) {
297
+ const today = new Date(now).toISOString().slice(0, 10);
298
+ if (!ctx || !due(today)) return [];
299
+ const out = [];
300
+ const list = typeof ctx.workspaceList === 'function' ? ctx.workspaceList() : [];
301
+ for (const w of list) {
302
+ if (!w || !w.root || tried.get(w.id || w.root) === today) continue;
303
+ tried.set(w.id || w.root, today);
304
+ try {
305
+ let dir = null; try { dir = ctx.stateDirFor ? ctx.stateDirFor(w) : null; } catch { dir = null; }
306
+ const r = draftFor(w.root, { product: nameOf(w), today, stateDir: dir || undefined });
307
+ out.push({ ws: w.id, ok: r.ok, path: r.path, written: !!r.written, why: r.why || r.error });
308
+ } catch (e) { out.push({ ws: w.id, ok: false, why: one(e && e.message, 160) }); }
309
+ }
310
+ return out;
311
+ }
312
+ function list(root) {
313
+ const RD = require('./report-draft.js'), IS = require('./issues.js');
314
+ const abs = path.resolve(String(root));
315
+ let dirRel; try { dirRel = path.posix.dirname(RD.draftPath(abs, CADENCE, '2000-01-01')); } catch { return []; }
316
+ let names = []; try { names = fs.readdirSync(path.join(abs, dirRel)).filter((n) => /^\d{4}-\d{2}-01\.md$/.test(n)); } catch { return []; }
317
+ let iss = null; try { iss = IS.readIssues(abs); } catch { iss = null; }
318
+ const out = [];
319
+ for (const n of names.sort().reverse()) {
320
+ let text = ''; try { text = fs.readFileSync(path.join(abs, dirRel, n), 'utf8'); } catch { continue; }
321
+ const slot = n.slice(0, 10), P = readPack(text);
322
+ let at = ''; try { at = fs.statSync(path.join(abs, dirRel, n)).mtime.toISOString(); } catch { at = ''; }
323
+ out.push({ path: dirRel + '/' + n, cadence: CADENCE, slot, title: P.title || slot, sections: P.sections, sha: IS.blobSha(Buffer.from(text, 'utf8')), issued: !!(iss && IS.isIssued(iss, CADENCE, slot)), updated: at });
324
+ }
325
+ return out;
326
+ }
327
+
328
+ /* ── pmos report pack ─────────────────────────────────────────────────────────────────────────────────────────────────── */
329
+ function cli(args, { root, now = Date.now(), say = (s) => process.stdout.write(s + '\n'), product } = {}) {
330
+ const has = (f) => args.includes('--' + f);
331
+ const val = (f) => { const i = args.indexOf('--' + f); return i >= 0 ? args[i + 1] : undefined; };
332
+ const t = val('now') ? Date.parse(val('now')) : now;
333
+ if (!Number.isFinite(t)) { say('--now needs a time, for example 2026-11-25T09:00:00Z'); return 2; }
334
+ const today = new Date(t).toISOString().slice(0, 10);
335
+ const abs = path.resolve(String(root || process.cwd()));
336
+ const r = draftFor(abs, { product: product || val('product') || path.basename(abs), today, redraft: has('redraft') });
337
+ if (has('json')) { say(JSON.stringify({ ok: r.ok, path: r.path || null, written: !!r.written, why: r.why || r.error || null, pack: r.pack || null })); return r.ok ? 0 : 1; }
338
+ if (!r.ok) { say(r.error); return 1; }
339
+ if (!r.pack) { say(r.why); return 0; }
340
+ say(r.written ? `Wrote ${r.path}. Edit it in Library › Reports, then share it.` : `${r.path}: ${r.why}.`);
341
+ if (r.pack.dropped) say(`${r.pack.dropped} ${r.pack.dropped === 1 ? 'line was' : 'lines were'} left out: no record to cite.`);
342
+ return 0;
343
+ }
344
+
345
+ const resetTick = () => tried.clear();
346
+ module.exports = { resetTick, onWritten, itemsOf, autoOn, CADENCE, WINDOW_DAYS, DUE_DAYS, MAX, HEAD, SAID, gather, packOf, markdown, readPack, write, due, draftFor, tick, list, cli, stateDirOf };
347
+
348
+ if (require.main === module && process.argv[2] === 'count') console.log(list(process.argv[3] || process.cwd()).length);
@@ -104,6 +104,7 @@ const MODULES = Object.freeze([
104
104
  'routes-tracker-sync', // tracker-sync-on-today: the sync with Jira of a product, the PM's ✓ that takes Jira's value, and its Undo (task ledger; page-press POST)
105
105
  'routes-standing-rules', // standing-rules-list (A470): the standing rules PMOS keeps, with edit, retire and bring back (memory + standing-rules.jsonl)
106
106
  'routes-lab', // idle lab (build U): Intelligence › Lab, the compare view, the specimen files and the Lab's own ✦ (idle-lab.jsonl; page-press POST)
107
+ 'routes-sim-users', // simulated users try the prototype (sim-users, A20): Findings of a version, the personas that walk (sim-users.jsonl)
107
108
  'routes-loose', // batch 13 item 3: Claude's clean-up of Home's "Not in an initiative" under the group's ✦ (loose-props/; page-press POST)
108
109
  'routes-workflows', // workflows-per-initiative (D99): the workflow library, save, copy, archive and the chat's draft (workflows.jsonl; page-press POST)
109
110
  'routes-settings', // console3 Settings: the settings store for settings with no home of their own (GET; page-press POST)
@@ -135,6 +136,7 @@ const MODULES = Object.freeze([
135
136
  'routes-report-design', // report-design-studio: the design studio (describe, samples, turns, versions, This is it), cycle renders and decisions, speaker notes and pins
136
137
  'routes-report-structure', // report-structure: the structure step (turns, versions, Use this structure, sources and their checks, dry run) and the chart store (GET /api/charts)
137
138
  'routes-insight-moves', // batch 16 item 1: the ✓ and Undo of a drafted move on the Intelligence ✦ strip (insight-moves.jsonl; date, anchor, chase to the outbox)
139
+ 'page-one-answer', // page-one-answer (A308): POST /api/page-calls, each page's first-view calls to act, local only (runtime page-calls.jsonl); pmos pages calls
138
140
  'routes-page-opens', // batch 16 item 1: the pages the PM opens, by day, local only (runtime page-opens.jsonl); drives the weekly report proposal
139
141
  'routes-ready-reports', // batch 17 item 1: the ready-made dashboard and reports of every program, product and initiative (ready-reports.jsonl; page-press POST)
140
142
  'routes-metric-drafts', // batch 15 item 1: the metrics Claude drafts unasked for a product, a program or an initiative; ✓ keep writes kr-metrics (metric-drafts.jsonl; page-press POST)
@@ -155,7 +157,9 @@ const MODULES = Object.freeze([
155
157
  'routes-code-map', // idea A176: the product's code map on Work, redrawn when the default branch moves (records code-map.json; read-only)
156
158
  'routes-arch-warns', // idea A54: one warning when an initiative names a risky part of the code (reads code-map.json; read-only)
157
159
  'routes-live-rows', // bet A458: chat-made task changes streamed to open pages (runtime live-events.jsonl; read-only event stream)
160
+ 'routes-team-waits', // team-waits (A364): Work › Dependencies' waits on other teams (GET, read-only; team-waits.jsonl written by pmos deps)
158
161
  'routes-connector-data', // connector-data (A150): what each connector reads and writes, from lib/connector-data.js (read only)
162
+ 'routes-review-pack', // job #1910 (A343): the monthly review packs for Library › Reports, drafted when due (<state>/reports/review-pack/; page-press POST)
159
163
  'routes-portfolio', // bet A56: the Portfolio, every product side by side, and the answer to its one recommendation (runtime portfolio.jsonl; page-press POST)
160
164
  ]);
161
165
  const PM_DIR = path.join(__dirname, '..', 'public', 'pm');
@@ -962,6 +962,9 @@ function itemsOf(w, fr, board, rows) {
962
962
  // the PM's priority (inline-sprint-priority): carried only when set
963
963
  const PR = fr.folded.priorities || new Map();
964
964
  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);
965
+ // the PM's optional times (task-time-optional): carried only when set, so a task with no time reads exactly as before
966
+ const TMS = fr.folded.times || new Map();
967
+ if (TMS.size) for (const x of out) if (x.kind !== 'Epic' && x.src !== 'jira' && TMS.has(x.uid)) Object.assign(x, timeFields(TMS, x.uid));
965
968
  // the task's description (task-descriptions): carried only when set; descBy 'pmos' when PMOS wrote the last one, with its sources
966
969
  const DS = fr.folded.descriptions || new Map();
967
970
  if (DS.size) for (const x of out) if (x.src !== 'jira' && DS.has(x.uid)) Object.assign(x, descFields(DS.get(x.uid)));
@@ -971,6 +974,9 @@ function itemsOf(w, fr, board, rows) {
971
974
  return B.rollupItems(out);
972
975
  }
973
976
 
977
+ /** A task's times as item fields (task-time-optional): start_time and due_time, each only when set. */
978
+ function timeFields(TM, id) { const v = TM && TM.get(id); const o = {}; if (v && v.start_time) o.start_time = v.start_time; if (v && v.due_time) o.due_time = v.due_time; return o; }
979
+
974
980
  /** tracker-daily: a PMOS task that names a Jira key carries `tracker` { key, status, readAt, stale }: Jira's status at the last read, and
975
981
  * stale when that read is older than a day or did not return the ticket (lib/task-jira.js staleOf). Its state is already the read's
976
982
  * (readLedger). A page or a forecast says "not read since" instead of trusting a stale state. */
@@ -1758,6 +1764,8 @@ const WRITES = {
1758
1764
  if (body.milestone != null && typeof body.milestone !== 'boolean') return fail(ctx, res, 400, 'milestone is true or false');
1759
1765
  // the priority and the sprint, set in the row (initiative inline-sprint-priority): sprint is the sprint's name, only to word the line's why
1760
1766
  if (body.priority != null && (typeof body.priority !== 'string' || !/^(P[1-3])?$/.test(body.priority))) return fail(ctx, res, 400, "priority is P1, P2, P3, or '' for none");
1767
+ // an optional time of day on the start and due (task-time-optional): "HH:MM", or '' to take it out; the day stays in start and due
1768
+ for (const k of ['start_time', 'due_time']) if (body[k] != null && body[k] !== '' && !(typeof body[k] === 'string' && B.TIME_RE.test(body[k]))) return fail(ctx, res, 400, `${k} is a time of day, HH:MM (00:00 to 23:59), or '' for none`);
1761
1769
  if (body.sprint != null && body.sprint !== '' && !ONE_LINE(body.sprint, 80)) return fail(ctx, res, 400, 'sprint is the sprint\'s name, one line of at most 80 characters');
1762
1770
  if (body.pinned !== undefined && body.pinned !== null && typeof body.pinned !== 'boolean') return fail(ctx, res, 400, 'pinned is true, false, or null for the rule (the last milestone only)');
1763
1771
  const pinWas = (id) => { const PN = p.fr.folded.pins || new Map(); return PN.has(id) ? PN.get(id) : null; };
@@ -1765,7 +1773,7 @@ const WRITES = {
1765
1773
  // 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):
1766
1774
  // Jira keeps its title, status and assignee, and nothing is written to Jira
1767
1775
  if (typeof body.task === 'string' && B.JIRA_KEY_RE.test(body.task) && !B.taskOf(p.fr.folded, body.task)) {
1768
- 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');
1776
+ if (['owner', 'notes', 'initiative', 'section', 'priority', 'description', 'start_time', 'due_time'].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');
1769
1777
  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');
1770
1778
  if (body.parent != null) { const pe = parentError(p, body.task, body.parent, null); if (pe) return fail(ctx, res, 400, pe); }
1771
1779
  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`);
@@ -1857,12 +1865,26 @@ const WRITES = {
1857
1865
  const d0 = (p.fr.folded.descriptions || new Map()).get(t.id);
1858
1866
  desc = body.description.replace(/\s+$/, ''); from.description = d0 ? d0.text : '';
1859
1867
  }
1860
- 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');
1868
+ // the times (task-time-optional): a board-ledger line for every kind of PMOS task, like the priority. A day cleared to '' takes its time
1869
+ // with it, so a task never keeps a time on a day it no longer has
1870
+ let tm = null;
1871
+ {
1872
+ const T0 = (p.fr.folded.times || new Map()).get(t.id) || { start_time: '', due_time: '' }, next = {};
1873
+ for (const k of ['start_time', 'due_time']) if (body[k] != null) next[k] = String(body[k]);
1874
+ if (ev.start === '' && T0.start_time && next.start_time == null) next.start_time = '';
1875
+ if (ev.due === '' && T0.due_time && next.due_time == null) next.due_time = '';
1876
+ if (Object.keys(next).length) {
1877
+ if (!p.file) return fail(ctx, res, 409, NO_STATE);
1878
+ tm = next; for (const k of Object.keys(next)) if (body[k] != null) from[k] = T0[k] || '';
1879
+ }
1880
+ }
1881
+ if (!Object.keys(ev).length && sec == null && ms == null && !pin && !prio && par == null && desc == null && tm == null) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, start_time, due_time, initiative, section, milestone, pinned, priority, parent or description');
1861
1882
  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' });
1862
1883
  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' });
1863
1884
  if (pin) append(p.file, g.actor, pinLine(t.id));
1864
1885
  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'); }
1865
1886
  if (par != null) append(p.file, g.actor, parentLine(p, t.id, par));
1887
+ if (tm) append(p.file, g.actor, { kind: 'task-time', board: p.board.id, task: t.id, ...tm, why: Object.values(tm).some(Boolean) ? 'time set' : 'time taken out' });
1866
1888
  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' });
1867
1889
  if (!Object.keys(ev).length) {
1868
1890
  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));
@@ -1876,6 +1898,7 @@ const WRITES = {
1876
1898
  if (intoSprint) console.info('[inline-field] sprint');
1877
1899
  const F2 = B.fold(readLedger(ctx, p.w)), t2 = B.taskOf(F2, t.id), it2 = B.rollupItems([B.taskItem(t2)])[0];
1878
1900
  if (F2.priorities && F2.priorities.has(t.id)) it2.priority = F2.priorities.get(t.id);
1901
+ Object.assign(it2, timeFields(F2.times, t.id));
1879
1902
  ctx.json(res, { ok: true, from, item: it2 });
1880
1903
  },
1881
1904
  '/api/boards/tasks/describe-draft': async (ctx, res, body, g) => {
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+ /* routes-review-pack.js — the monthly review packs of every product, for Library › Reports (initiative review-pack, job #1910; lib/review-pack.js).
3
+ *
4
+ * GET /api/review-packs → { ok, items } each product's packs as Library rows (lib/review-pack.js itemsOf), newest first. Read only.
5
+ * POST /api/review-packs/due {} → { ok, written, items } Library calls it when it opens: in the last 7 days of the month, PMOS drafts the month's
6
+ * pack of each product that has none (lib/review-pack.js tick). A pack that exists is
7
+ * never written over, and nothing is shared: Share is the PM's Issue press.
8
+ * PMOS_REVIEW_PACK=0 turns the drafting off (=1 on); a scratch server (its own PMOS_STATE_DIR) drafts none by default (lib/review-pack.js autoOn).
9
+ * The POST comes from the page only (pm-guard requirePagePress); an agent session is refused (403). */
10
+ const guard = require('./pm-guard.js');
11
+ const RP = require('./review-pack.js');
12
+
13
+ function itemsAll(ctx) {
14
+ const list = typeof ctx.workspaceList === 'function' ? ctx.workspaceList() : [];
15
+ const out = [];
16
+ for (const w of list) {
17
+ if (!w || !w.root) continue;
18
+ try { out.push(...RP.itemsOf({ ws: w.id, name: w.label || w.name || w.id, packs: RP.list(w.root) })); } catch { /* an unreadable product shows no pack */ }
19
+ }
20
+ return out.sort((a, b) => String(b.updated || '').localeCompare(String(a.updated || '')));
21
+ }
22
+
23
+ async function handle(req, res, url, ctx) {
24
+ const send = (status, body) => { ctx.json(res, body, status); return true; };
25
+ const what = url.pathname.replace(/^\/api\/review-packs\/?/, '');
26
+ if (what === '') {
27
+ if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
28
+ return send(200, { ok: true, items: itemsAll(ctx) });
29
+ }
30
+ if (what !== 'due') return send(404, { ok: false, error: 'no such review-pack route' });
31
+ if (req.method !== 'POST') return send(405, { ok: false, error: 'POST only' });
32
+ if (req.headers && req.headers['x-pmos-session']) return send(403, { ok: false, error: 'An agent session does not open Library. Draft a pack with pmos report pack.' });
33
+ const rd = await ctx.readJson(req);
34
+ if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
35
+ const g = guard.requirePagePress(req, rd.body || {});
36
+ if (!g.ok) return send(g.status, { ok: false, error: g.error });
37
+ let written = [];
38
+ if (RP.autoOn(process.env)) try { written = (await RP.tick({ workspaceList: ctx.workspaceList, stateDirFor: ctx.stateDirFor })).filter((r) => r.written).map((r) => ({ ws: r.ws, path: r.path })); } catch { written = []; }
39
+ return send(200, { ok: true, written, items: itemsAll(ctx) });
40
+ }
41
+
42
+ module.exports = { prefixes: ['/api/review-packs'], handle, itemsAll };