create-pmos 0.712.0 → 0.714.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 (123) hide show
  1. package/package.json +99 -51
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/design-system/ui/README.md +1 -1
  4. package/payload/design-system/ui/components/State/README.md +21 -0
  5. package/payload/design-system/ui/components/State/preview.html +8 -0
  6. package/payload/design-system/ui/components/bundle.css +12 -0
  7. package/payload/design-system/ui/interactions.md +10 -0
  8. package/payload/planning/evals/eval-calibration.md +1 -1
  9. package/payload/planning/okrs/health-budgets.md +1 -1
  10. package/payload/state/discoveries.md +1 -1
  11. package/workspace/bin/back-place-health.js +70 -0
  12. package/workspace/changelog.json +98 -0
  13. package/workspace/design-system/ui/README.md +1 -1
  14. package/workspace/design-system/ui/components/State/README.md +21 -0
  15. package/workspace/design-system/ui/components/State/preview.html +8 -0
  16. package/workspace/design-system/ui/components/bundle.css +12 -0
  17. package/workspace/design-system/ui/interactions.md +10 -0
  18. package/workspace/guide/breakdown.md +20 -1
  19. package/workspace/guide/claude-proposes.md +5 -1
  20. package/workspace/guide/cli.md +10 -1
  21. package/workspace/guide/home.md +1 -0
  22. package/workspace/guide/initiatives-and-next-steps.md +13 -0
  23. package/workspace/guide/layout.md +27 -1
  24. package/workspace/guide/routine.md +10 -2
  25. package/workspace/guide/settings-and-switches.md +4 -0
  26. package/workspace/lib/briefing-premium-products.js +16 -2
  27. package/workspace/lib/changed-mark.js +34 -0
  28. package/workspace/lib/launch-cli.js +43 -5
  29. package/workspace/lib/launch-tiers.js +143 -0
  30. package/workspace/lib/moments.js +41 -3
  31. package/workspace/lib/needs-providers.js +1 -0
  32. package/workspace/lib/parked-cli.js +105 -0
  33. package/workspace/lib/parked-reasons.js +245 -0
  34. package/workspace/lib/pmos-verbs.js +4 -1
  35. package/workspace/lib/prefs-sync.js +138 -0
  36. package/workspace/lib/product-dots.js +60 -0
  37. package/workspace/lib/route-modules.js +2 -0
  38. package/workspace/lib/routes-briefing-premium.js +11 -1
  39. package/workspace/lib/routes-moments.js +1 -1
  40. package/workspace/lib/routes-prefs.js +56 -0
  41. package/workspace/lib/routes-strategy-card.js +53 -0
  42. package/workspace/lib/routes-use-log.js +24 -3
  43. package/workspace/lib/routine-sentence.js +250 -0
  44. package/workspace/lib/strategy-card.js +133 -0
  45. package/workspace/lib/unused-controls.js +178 -0
  46. package/workspace/lib/use-log.js +27 -3
  47. package/workspace/package-lock.json +2 -2
  48. package/workspace/package.json +1 -1
  49. package/workspace/premium-vw-doc-test.js +2 -0
  50. package/workspace/public/pm/action-keys.js +187 -0
  51. package/workspace/public/pm/back-place.js +87 -0
  52. package/workspace/public/pm/bd-pop-ds.css +10 -0
  53. package/workspace/public/pm/bd-pop-ds.js +27 -3
  54. package/workspace/public/pm/bd-strategy.js +85 -0
  55. package/workspace/public/pm/bd-views.js +2 -1
  56. package/workspace/public/pm/changed-mark.css +7 -0
  57. package/workspace/public/pm/changed-mark.js +117 -0
  58. package/workspace/public/pm/cozy-ev.css +7 -0
  59. package/workspace/public/pm/cozy-nav.js +2 -0
  60. package/workspace/public/pm/cozy-pick.css +12 -0
  61. package/workspace/public/pm/cozy-pop-work.css +10 -1
  62. package/workspace/public/pm/cozy-pop-work.js +201 -17
  63. package/workspace/public/pm/cozy-routine-job.js +50 -7
  64. package/workspace/public/pm/cozy-routine.css +2 -0
  65. package/workspace/public/pm/cozy-settings.js +21 -3
  66. package/workspace/public/pm/cozy-today-page.css +1 -0
  67. package/workspace/public/pm/cozy-viewer.css +1 -1
  68. package/workspace/public/pm/cozy-viewer.js +14 -2
  69. package/workspace/public/pm/cozy-vw-mtg.css +0 -2
  70. package/workspace/public/pm/cozy-vw.css +0 -1
  71. package/workspace/public/pm/home-app.js +21 -1
  72. package/workspace/public/pm/home-today.js +2 -0
  73. package/workspace/public/pm/ini-tasks.js +4 -1
  74. package/workspace/public/pm/komorebi.css +11 -0
  75. package/workspace/public/pm/page-chat.js +16 -0
  76. package/workspace/public/pm/prefs-sync.js +111 -0
  77. package/workspace/public/pm/premium-board.js +20 -2
  78. package/workspace/public/pm/premium-chart-tab.js +2 -1
  79. package/workspace/public/pm/premium-insights.js +2 -2
  80. package/workspace/public/pm/premium-mtg-replay.js +4 -3
  81. package/workspace/public/pm/premium-report-read.js +5 -4
  82. package/workspace/public/pm/premium-report-tab.js +4 -3
  83. package/workspace/public/pm/premium-vw-backlog.css +2 -1
  84. package/workspace/public/pm/premium-vw-backlog.js +4 -3
  85. package/workspace/public/pm/premium-vw-cal.css +1 -2
  86. package/workspace/public/pm/premium-vw-cal.js +14 -13
  87. package/workspace/public/pm/premium-vw-copies.js +3 -2
  88. package/workspace/public/pm/premium-vw-copy.css +0 -3
  89. package/workspace/public/pm/premium-vw-mtg.js +12 -11
  90. package/workspace/public/pm/product-switcher.js +41 -0
  91. package/workspace/public/pm/quiet-place.js +15 -2
  92. package/workspace/public/pm/report-orders-ui.js +2 -1
  93. package/workspace/public/pm/rp-parts.js +3 -2
  94. package/workspace/public/pm/state-blocks.js +67 -0
  95. package/workspace/public/pm/use-log.js +127 -1
  96. package/workspace/public/pm/work-select.js +92 -2
  97. package/workspace/public/pm/work-tree.js +70 -0
  98. package/workspace/public/premium-aud.html +1 -0
  99. package/workspace/public/premium-board.html +5 -0
  100. package/workspace/public/premium-buddy.html +1 -0
  101. package/workspace/public/premium-events.html +1 -0
  102. package/workspace/public/premium-goals.html +1 -0
  103. package/workspace/public/premium-intelligence.html +1 -0
  104. package/workspace/public/premium-library.html +1 -0
  105. package/workspace/public/premium-present.html +1 -0
  106. package/workspace/public/premium-rec.html +1 -0
  107. package/workspace/public/premium-routine.html +1 -0
  108. package/workspace/public/premium-viewer.html +1 -0
  109. package/workspace/public/premium-workflows.html +1 -0
  110. package/workspace/public/today.html +1 -0
  111. package/workspace/server.js +20 -0
  112. package/workspace/test-lists/action-keys.json +9 -0
  113. package/workspace/test-lists/back-place.json +9 -0
  114. package/workspace/test-lists/changed-mark.json +9 -0
  115. package/workspace/test-lists/launch-tiers.json +9 -0
  116. package/workspace/test-lists/parked-reasons.json +9 -0
  117. package/workspace/test-lists/prefs-follow-person.json +9 -0
  118. package/workspace/test-lists/product-switcher-dots.json +9 -0
  119. package/workspace/test-lists/routine-sentence.json +9 -0
  120. package/workspace/test-lists/shared-empty-states.json +9 -0
  121. package/workspace/test-lists/strategy-card.json +9 -0
  122. package/workspace/test-lists/unused-controls.json +9 -0
  123. package/workspace/test-lists/work-subtasks-followups.json +9 -0
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+ /* parked-cli.js — `pmos parked`: parked initiatives, why each is parked and what brings it back (initiative parked-reason-way-back,
3
+ * bet A446; lib/parked-reasons.js).
4
+ *
5
+ * pmos parked list [--json] every on-hold initiative: why, and its way back; met ones first
6
+ * pmos parked hold <id> --why "<reason>" [--back <YYYY-MM-DD>] [--after <initiative id>]
7
+ * park it with its reason and its way back (one lifecycle line)
8
+ * pmos parked back <id> bring it back (one `active` lifecycle line); Undo is a new hold
9
+ * pmos parked coverage [--json] how many parked initiatives say why and what brings them back
10
+ * every command: [--root <dir>] (default: this repository)
11
+ *
12
+ * The agent runs hold and back only after the PM said yes in the chat; the line names who wrote it (lib/actor.js).
13
+ * Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
14
+ const path = require('path');
15
+ const { execFileSync } = require('child_process');
16
+ const P = require('./parked-reasons.js');
17
+
18
+ const COMMANDS = { parked: ['list', 'hold', 'back', 'coverage'] };
19
+ const USAGE = [
20
+ 'usage: pmos parked list|hold|back|coverage — parked initiatives, why each is parked and what brings it back',
21
+ ' pmos parked list [--json] every on-hold initiative: why, and its way back; the ones whose way back is met come first',
22
+ ' pmos parked hold <id> --why "<reason>" [--back <YYYY-MM-DD>] [--after <initiative id>]',
23
+ ' park it: the reason, and a return day or the initiative that must finish first',
24
+ ' pmos parked back <id> bring it back to the Roadmap',
25
+ ' pmos parked coverage [--json] how many parked initiatives say why and what brings them back',
26
+ 'When a way back is met, Today shows "Bring back …?". Run it in the product\'s repository, or pass --root <dir>.',
27
+ ];
28
+ const ALLOWED = { list: ['json', 'root'], hold: ['json', 'root', 'why', 'back', 'after'], back: ['json', 'root'], coverage: ['json', 'root'] };
29
+ const BOOL = new Set(['json']);
30
+
31
+ function parse(args) {
32
+ const pos = [], flags = {};
33
+ for (let i = 0; i < args.length; i++) {
34
+ const a = args[i];
35
+ if (!a.startsWith('--')) { pos.push(a); continue; }
36
+ const k = a.slice(2);
37
+ if (BOOL.has(k)) flags[k] = true;
38
+ else flags[k] = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
39
+ }
40
+ return { pos, flags };
41
+ }
42
+ function repoRoot(cwd) {
43
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; }
44
+ }
45
+
46
+ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now(), isTTY } = {}) {
47
+ const args = argv[0] === 'parked' ? argv.slice(1) : argv.slice();
48
+ const sub = args[0];
49
+ if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
50
+ if (!COMMANDS.parked.includes(sub)) { say(`unknown parked command "${sub}". Use one of: ${COMMANDS.parked.join(', ')}`); return 2; }
51
+ const { pos, flags } = parse(args.slice(1));
52
+ for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos parked ${sub}`); return 2; }
53
+ const root = path.resolve(flags.root || repoRoot(cwd));
54
+ const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
55
+ const actor = () => require('./actor.js').fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env });
56
+
57
+ if (sub === 'list') {
58
+ if (pos.length) return fail('pmos parked list takes no argument', 2);
59
+ const { file, parked } = P.parkedOf(root, { today: P.todayOf(now) });
60
+ if (flags.json) { say(JSON.stringify({ ok: true, file, parked: parked.map((p) => ({ ...p, kind_words: P.KIND_WORDS[p.kind], way_back: P.wayBackWords(p) || null })) })); return 0; }
61
+ if (!parked.length) { say('Nothing is parked.'); return 0; }
62
+ const met = parked.filter((p) => p.met).length;
63
+ say(`${parked.length} parked${met ? ` · ${met} ready to bring back` : ''}`);
64
+ for (const p of parked) {
65
+ say(` ${p.met ? '✦' : '─'} ${p.id} — ${p.title}`);
66
+ say(` why: ${p.reason || 'no reason given'}${p.reason ? ` (${P.KIND_WORDS[p.kind]})` : ''}`);
67
+ const wb = P.wayBackWords(p);
68
+ say(` way back: ${wb || 'none named'}${p.met ? ` · met: ${p.met.why}` : ''}`);
69
+ }
70
+ if (met) say('\nBring one back: pmos parked back <id>');
71
+ if (parked.some((p) => !p.reason || !(p.back || p.after))) say('Name a way back: pmos parked hold <id> --why "<reason>" --after <id> | --back <YYYY-MM-DD>');
72
+ return 0;
73
+ }
74
+
75
+ if (sub === 'hold') {
76
+ if (pos.length !== 1) return fail('usage: pmos parked hold <id> --why "<reason>" [--back <YYYY-MM-DD>] [--after <initiative id>]', 2);
77
+ const a = actor();
78
+ const r = P.hold(root, { id: pos[0], why: flags.why, back: flags.back || null, after: flags.after || null }, { now, by: a.by, via: a.via });
79
+ if (!r.ok) return fail(r.error);
80
+ if (flags.json) { say(JSON.stringify({ ok: true, file: r.file, line: r.line })); return 0; }
81
+ const wb = P.wayBackWords({ back: r.line.back || null, after: r.line.after || null });
82
+ say(`${P.TAG} ✓ ${pos[0]} parked: ${r.line.reason}${wb ? ` · back ${wb}` : ' · no way back named'} (${r.file}). Commit it to keep it.`);
83
+ return 0;
84
+ }
85
+
86
+ if (sub === 'back') {
87
+ if (pos.length !== 1) return fail('usage: pmos parked back <id>', 2);
88
+ const a = actor();
89
+ const r = P.bringBack(root, { id: pos[0] }, { now, by: a.by, via: a.via });
90
+ if (!r.ok) return fail(r.error);
91
+ if (flags.json) { say(JSON.stringify({ ok: true, file: r.file, line: r.line })); return 0; }
92
+ say(`${P.TAG} ✓ ${pos[0]} is back on the Roadmap. ${r.line.reason} (${r.file}). Commit it to keep it.`);
93
+ return 0;
94
+ }
95
+
96
+ // coverage
97
+ if (pos.length) return fail('pmos parked coverage takes no argument', 2);
98
+ const c = P.coverage(root);
99
+ if (flags.json) { say(JSON.stringify({ ok: true, ...c })); return 0; }
100
+ say(`${P.TAG} ${c.explained} of ${c.parked} parked initiatives say why and what brings them back`);
101
+ say(String(c.pct));
102
+ return 0;
103
+ }
104
+
105
+ module.exports = { run, COMMANDS, USAGE };
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* parked-reasons.js — parked work keeps a reason and a way back (bet A446, initiative parked-reason-way-back).
4
+ *
5
+ * A parked initiative is one whose LATEST lifecycle line (D70, lifecycle.jsonl) is `on-hold`. This module reads why it is parked, what
6
+ * brings it back, and whether that has happened; it writes the hold and the return; and it is the needs provider that puts one Today card
7
+ * per parked initiative whose way back is met (lib/needs-providers.js). Works on any product built with PMOS, in either layout.
8
+ *
9
+ * reasonKind(text) → 'waiting' | 'evidence' | 'crowded' | 'other' | 'none'
10
+ * parkedOf(root, { today }) → { file, parked: [{ id, title, reason, kind, at, back, after, afterTitle, met }] }
11
+ * met = { why } | null
12
+ * hold(root, { id, why, back, after }, { now, by, via }) → { ok, file, line } | { ok: false, error }
13
+ * bringBack(root, { id }, { now, by, via }) → { ok, file, line } | { ok: false, error }
14
+ * coverage(root) → { parked, explained, pct }
15
+ * broughtBack(root, { days, now }) → number of `active` lines with way_back: true in the last `days` days
16
+ * needs provider: kinds ['parked-back'] · rowsFor(w, { lead }) · sig(w)
17
+ * CLI: node lib/parked-reasons.js coverage <root> the health number, on its last line
18
+ * node lib/parked-reasons.js brought <root> [--days N] the outcome number, on its last line
19
+ *
20
+ * THE WAY BACK. A hold names it in one of three ways, read in this order:
21
+ * back a day (YYYY-MM-DD): met when today is that day or later (the field the Board's hold already writes)
22
+ * after an initiative id: met when that initiative's latest lifecycle line is closed or cancelled, or it has an acceptance line
23
+ * the reason itself: an initiative id of this repository named after "waiting on", "after", "until", "blocked by" or "depends on"
24
+ * reads as `after`, so an older hold that says "waiting on checkout-v2" gets its way back with no new field.
25
+ * A hold with none of these has no way back; `pmos parked list` says so, and it never makes a card.
26
+ *
27
+ * Every line this module writes carries `[parked]` in what the CLI prints (the health log text). Nothing is sent. */
28
+ const fs = require('fs');
29
+ const path = require('path');
30
+
31
+ const NAME = 'parked-reasons';
32
+ const FILE = 'lifecycle.jsonl';
33
+ const DAY = 864e5;
34
+ const DATE = /^\d{4}-\d{2}-\d{2}$/;
35
+ const ID_RE = /^[a-z0-9][a-z0-9._-]*$/i;
36
+ const STOPPED = new Set(['closed', 'on-hold', 'cancelled']);
37
+ const DONE = new Set(['closed', 'cancelled']);
38
+ const TAG = '[parked]';
39
+
40
+ const todayOf = (now = Date.now()) => new Date(now).toISOString().slice(0, 10);
41
+ const clip = (s, n) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
42
+ const rel = (root, f) => path.relative(root, f).split(path.sep).join('/');
43
+ const isDir = (p) => { try { return fs.statSync(p).isDirectory(); } catch { return false; } };
44
+
45
+ /** Where this repository keeps its initiatives and ledgers (the layout scripts/workflow-state.js and POST /api/lifecycle use). */
46
+ function layoutOf(root) {
47
+ root = path.resolve(root);
48
+ if (isDir(path.join(root, 'planning', 'initiatives'))) return { initiatives: path.join(root, 'planning', 'initiatives'), runs: path.join(root, 'planning', 'runs') };
49
+ if (isDir(path.join(root, 'pmos', 'state', 'initiatives'))) return { initiatives: path.join(root, 'pmos', 'state', 'initiatives'), runs: path.join(root, 'pmos', 'state') };
50
+ return null;
51
+ }
52
+
53
+ function jsonl(file) {
54
+ let text = '';
55
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
56
+ const out = [];
57
+ for (const l of text.split('\n')) { if (!l.trim()) continue; try { const r = JSON.parse(l); if (r && typeof r === 'object') out.push(r); } catch { /* a torn line */ } }
58
+ return out;
59
+ }
60
+
61
+ /** The initiatives of this repository: Map id → title (the file name is the id; `id:` in the frontmatter wins). */
62
+ function initiativesOf(L) {
63
+ const out = new Map();
64
+ let files = [];
65
+ try { files = fs.readdirSync(L.initiatives).filter((f) => f.endsWith('.md')); } catch { return out; }
66
+ for (const f of files) {
67
+ let head = '';
68
+ try { head = fs.readFileSync(path.join(L.initiatives, f), 'utf8').slice(0, 4000); } catch { continue; }
69
+ const fm = /^---\n([\s\S]*?)\n---/.exec(head);
70
+ const get = (k) => { const m = fm && new RegExp('^' + k + ':\\s*(.*)$', 'm').exec(fm[1]); return m ? m[1].trim().replace(/^["']|["']$/g, '') : ''; };
71
+ const id = get('id') || f.slice(0, -3);
72
+ out.set(id, get('title') || id);
73
+ }
74
+ return out;
75
+ }
76
+
77
+ /** Why it is parked, as one of five kinds. Order matters: "waiting on more data" is waiting, not evidence. */
78
+ function reasonKind(text) {
79
+ const t = String(text || '').toLowerCase().trim();
80
+ if (!t) return 'none';
81
+ if (/\b(waiting (on|for)|blocked (by|on)|depends on|dependent on|after|until|once)\b/.test(t)) return 'waiting';
82
+ if (/\b(low evidence|no evidence|not enough evidence|no data|not enough data|unproven|not proven|no signal|weak signal|needs? proof)\b/.test(t)) return 'evidence';
83
+ if (/\b(no capacity|capacity|bandwidth|other priorities|priorit\w*|crowded|not now|too many|focus|no time|no one|nobody)\b/.test(t)) return 'crowded';
84
+ return 'other';
85
+ }
86
+ const KIND_WORDS = { waiting: 'waiting on something', evidence: 'low evidence', crowded: 'crowded out', other: 'other', none: 'no reason given' };
87
+
88
+ /** An initiative id of this repository named in the reason after a waiting word. */
89
+ function afterFromReason(reason, ids, self) {
90
+ const t = String(reason || '');
91
+ const re = /\b(?:waiting (?:on|for)|blocked (?:by|on)|depends on|dependent on|after|until|once)\s+(?:the\s+)?([a-z0-9][a-z0-9._-]*)/gi;
92
+ let m;
93
+ while ((m = re.exec(t))) { const id = m[1].replace(/[.]+$/, ''); if (id !== self && ids.has(id)) return id; }
94
+ return null;
95
+ }
96
+
97
+ /** Latest lifecycle line per id, and the ids with an acceptance line. */
98
+ function foldOf(L) {
99
+ const latest = new Map();
100
+ for (const r of jsonl(path.join(L.runs, FILE))) {
101
+ if (typeof r.initiative_id !== 'string') continue;
102
+ if (r.state !== 'active' && !STOPPED.has(r.state)) continue;
103
+ latest.set(r.initiative_id, r);
104
+ }
105
+ const accepted = new Set();
106
+ for (const a of jsonl(path.join(L.runs, 'acceptances.jsonl'))) if (typeof a.initiative_id === 'string' && a.accepted !== false) accepted.add(a.initiative_id);
107
+ return { latest, accepted };
108
+ }
109
+
110
+ function parkedOf(root, { today = todayOf() } = {}) {
111
+ root = path.resolve(root);
112
+ const L = layoutOf(root);
113
+ if (!L) return { file: null, parked: [] };
114
+ const titles = initiativesOf(L);
115
+ const { latest, accepted } = foldOf(L);
116
+ const parked = [];
117
+ for (const [id, r] of latest) {
118
+ if (r.state !== 'on-hold') continue;
119
+ const reason = String(r.reason || '').trim();
120
+ const back = DATE.test(r.back || '') ? r.back : null;
121
+ const after = (typeof r.after === 'string' && r.after && r.after !== id ? r.after : null) || afterFromReason(reason, titles, id);
122
+ let met = null;
123
+ if (back && back <= today) met = { why: `its return day ${back} came` };
124
+ else if (after) {
125
+ const a = latest.get(after);
126
+ const afterTitle = titles.get(after) || after;
127
+ if (accepted.has(after)) met = { why: `${afterTitle} is done` };
128
+ else if (a && DONE.has(a.state)) met = { why: `${afterTitle} was ${a.state}` };
129
+ }
130
+ parked.push({ id, title: titles.get(id) || id, reason, kind: reasonKind(reason), at: r.at || null, back, after,
131
+ afterTitle: after ? titles.get(after) || after : null, met });
132
+ }
133
+ parked.sort((x, y) => (!!y.met - !!x.met) || String(x.at || '').localeCompare(String(y.at || '')) || x.id.localeCompare(y.id));
134
+ return { file: rel(root, path.join(L.runs, FILE)), parked };
135
+ }
136
+
137
+ /** The way back in words, or '' when the hold names none. */
138
+ function wayBackWords(p) {
139
+ const parts = [];
140
+ if (p.back) parts.push(`on ${p.back}`);
141
+ if (p.after) parts.push(`when ${p.afterTitle && p.afterTitle !== p.after ? `${p.afterTitle} (${p.after})` : p.after} is done`);
142
+ return parts.join(', or ');
143
+ }
144
+
145
+ function append(root, L, line) {
146
+ const file = path.join(L.runs, FILE);
147
+ try {
148
+ fs.mkdirSync(L.runs, { recursive: true });
149
+ const st = (() => { try { return fs.lstatSync(file); } catch { return null; } })();
150
+ if (st && !st.isFile()) return { ok: false, error: 'the lifecycle ledger is not a plain file — nothing was saved' };
151
+ fs.appendFileSync(file, JSON.stringify(line) + '\n');
152
+ return { ok: true, file: rel(root, file), line };
153
+ } catch (e) { return { ok: false, error: 'the lifecycle ledger could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
154
+ }
155
+ function pmSlug() { try { return require('./actor.js').PM_SLUG || 'pm'; } catch { return 'pm'; } }
156
+
157
+ /** Park an initiative with its reason and its way back. One `on-hold` line. */
158
+ function hold(root, { id, why, back, after } = {}, { now = Date.now(), by, via } = {}) {
159
+ root = path.resolve(root);
160
+ const L = layoutOf(root);
161
+ if (!L) return { ok: false, error: 'this folder has no initiatives (planning/initiatives or pmos/state/initiatives)' };
162
+ if (!ID_RE.test(String(id || ''))) return { ok: false, error: 'name the initiative by its id' };
163
+ const ids = initiativesOf(L);
164
+ if (!ids.has(id)) return { ok: false, error: `no initiative ${id} here` };
165
+ const reason = String(why || '').replace(/\s+/g, ' ').trim();
166
+ if (!reason) return { ok: false, error: 'say why it is parked (--why "<reason>")' };
167
+ if (reason.length > 500) return { ok: false, error: 'keep the reason under 500 characters' };
168
+ if (back != null && back !== '' && !DATE.test(String(back))) return { ok: false, error: 'the return day is YYYY-MM-DD' };
169
+ if (after != null && after !== '') {
170
+ if (after === id) return { ok: false, error: 'an initiative cannot wait on itself' };
171
+ if (!ids.has(after)) return { ok: false, error: `no initiative ${after} here to wait on` };
172
+ }
173
+ return append(root, L, { initiative_id: id, state: 'on-hold', reason, ...(back ? { back: String(back) } : {}), ...(after ? { after } : {}),
174
+ pm: pmSlug(), by: by || 'agent:unknown', via: via || 'cli', at: new Date(now).toISOString() });
175
+ }
176
+
177
+ /** Bring a parked initiative back. One `active` line marked as brought back through its way back. */
178
+ function bringBack(root, { id } = {}, { now = Date.now(), by, via } = {}) {
179
+ root = path.resolve(root);
180
+ const L = layoutOf(root);
181
+ if (!L) return { ok: false, error: 'this folder has no initiatives (planning/initiatives or pmos/state/initiatives)' };
182
+ const p = parkedOf(root, { today: todayOf(now) }).parked.find((x) => x.id === id);
183
+ if (!p) return { ok: false, error: `${id} is not on hold (pmos parked list shows what is)` };
184
+ const reason = p.met ? `Brought back: ${p.met.why}` : 'Brought back before its way back was met';
185
+ return append(root, L, { initiative_id: id, state: 'active', reason, way_back: !!p.met, pm: pmSlug(), by: by || 'agent:unknown', via: via || 'cli',
186
+ at: new Date(now).toISOString() });
187
+ }
188
+
189
+ /** The health number: how many parked initiatives say why AND name a way back. */
190
+ function coverage(root) {
191
+ const { parked } = parkedOf(root);
192
+ const explained = parked.filter((p) => p.reason && (p.back || p.after)).length;
193
+ return { parked: parked.length, explained, pct: parked.length ? Math.round((explained / parked.length) * 100) : 100 };
194
+ }
195
+
196
+ /** The outcome number: initiatives brought back through their way back in the last `days` days. */
197
+ function broughtBack(root, { days = 7, now = Date.now() } = {}) {
198
+ const L = layoutOf(root);
199
+ if (!L) return 0;
200
+ const since = now - days * DAY;
201
+ return jsonl(path.join(L.runs, FILE)).filter((r) => r.state === 'active' && r.way_back === true && Date.parse(r.at) >= since).length;
202
+ }
203
+
204
+ /* ── the needs provider (lib/needs-providers.js): one Today card per parked initiative whose way back is met ─────────────── */
205
+ function rowsFor(w, { lead } = {}) {
206
+ if (!lead || !w || !w.root) return [];
207
+ const { file, parked } = parkedOf(w.root);
208
+ return parked.filter((p) => p.met).map((p) => {
209
+ const cause = `Bring back ${clip(p.title, 80)}? ${p.met.why[0].toUpperCase() + p.met.why.slice(1)}. Parked because: ${p.reason ? clip(p.reason, 160) : 'no reason given'}.`;
210
+ return {
211
+ run_id: `${NAME}:${w.id}:${p.id}`, kind: 'parked-back', initiative_id: p.id, question: cause, doc: file, ws: w.id,
212
+ today: { kind: 7, source: NAME, cause, evidence: `${file} · on hold since ${String(p.at || '').slice(0, 10) || 'an unknown day'}`,
213
+ act: { label: 'Bring back', cli: `pmos parked back ${p.id}` } },
214
+ };
215
+ });
216
+ }
217
+ // the date is in the signature: a return day comes at midnight with no change to the ledger
218
+ function sig(w) {
219
+ if (!w || !w.root) return '';
220
+ const L = layoutOf(w.root);
221
+ if (!L) return 'none';
222
+ const parts = [FILE, 'acceptances.jsonl'].map((f) => { try { const st = fs.statSync(path.join(L.runs, f)); return st.size + ':' + st.mtimeMs; } catch { return '-'; } });
223
+ return parts.join('|') + '@' + todayOf();
224
+ }
225
+
226
+ module.exports = { kinds: ['parked-back'], rowsFor, sig, NAME, TAG, KIND_WORDS, reasonKind, parkedOf, wayBackWords, hold, bringBack, coverage, broughtBack, layoutOf, todayOf };
227
+
228
+ if (require.main === module) {
229
+ const [cmd, rootArg, ...rest] = process.argv.slice(2);
230
+ const root = path.resolve(rootArg || '.');
231
+ if (cmd === 'coverage') {
232
+ const c = coverage(root);
233
+ console.log(`${TAG} ${c.explained} of ${c.parked} parked initiatives say why and what brings them back`);
234
+ console.log(String(c.pct));
235
+ } else if (cmd === 'brought') {
236
+ const i = rest.indexOf('--days');
237
+ const days = i >= 0 ? Math.max(1, parseInt(rest[i + 1], 10) || 7) : 7;
238
+ const n = broughtBack(root, { days });
239
+ console.log(`${TAG} ${n} parked initiatives brought back through their way back in the last ${days} days`);
240
+ console.log(String(n));
241
+ } else {
242
+ console.log('usage: node lib/parked-reasons.js coverage <root> | brought <root> [--days N]');
243
+ process.exitCode = 2;
244
+ }
245
+ }
@@ -59,7 +59,7 @@ const VERBS = Object.freeze({
59
59
  help: 'pmos calendar import|status — the calendar events an agent session read, saved for Briefing and Calendar (pmos calendar help)' }),
60
60
  // Not a pm-os-absorb verb (run: null): launch-readiness-check added it through the same table.
61
61
  launch: Object.freeze({ module: 'launch-cli.js', run: null, guide: 'cli.md',
62
- help: 'pmos launch check|list — what is not ready before a launch date: tasks, tracker tickets, sign-offs, open questions (pmos launch help)' }),
62
+ help: 'pmos launch check|list|tier — what is not ready before a launch date, and the launch tier with its steps (pmos launch help)' }),
63
63
  // Not a pm-os-absorb verb (run: null): ready-for-engineering-check added it through the same table.
64
64
  ready: Object.freeze({ module: 'ready-cli.js', run: null, guide: 'cli.md',
65
65
  help: 'pmos ready check|list — is an initiative ready for engineering: problem, done test, design for every state, open questions, sign-offs (pmos ready help)' }),
@@ -139,6 +139,9 @@ const VERBS = Object.freeze({
139
139
  // Not a pm-os-absorb verb (run: null): initiative decision-journal-outcome-checks added it through the same table.
140
140
  decisions: Object.freeze({ module: 'decisions-cli.js', run: null, guide: 'cli.md',
141
141
  help: 'pmos decisions add|list|show|check|record — a decision journal: what you decided, what you expect, a date to check, and how your calls turned out (pmos decisions help)' }),
142
+ // Not a pm-os-absorb verb (run: null): initiative parked-reason-way-back (bet A446) added it through the same table.
143
+ parked: Object.freeze({ module: 'parked-cli.js', run: null, guide: 'cli.md',
144
+ help: 'pmos parked list|hold|back|coverage — parked initiatives: why each is parked, what brings it back, and bringing it back (pmos parked help)' }),
142
145
  // Not a pm-os-absorb verb (run: null): chief-unit-owners (Wawan 2026-11-18) added both through the same table.
143
146
  units: Object.freeze({ module: 'units-cli.js', run: null, guide: 'cli.md',
144
147
  help: 'pmos units [list|show <unit>] — the programs, products and projects, who owns each initiative, and each owner\'s brief (pmos units help)' }),
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* prefs-sync.js — view preferences that follow the person, not the browser (bet A461, initiative prefs-follow-person).
4
+ * THE ONE WRITER of <runtime>/view-prefs.json. lib/routes-prefs.js does the HTTP; public/pm/prefs-sync.js is the page side.
5
+ *
6
+ * WHY. About 40 view choices (theme, the Work and Board views, columns, folds, filters, scopes) were kept in one browser's localStorage
7
+ * only, so the phone and a second browser started from scratch. The workspace server runs on the user's own computer and the phone
8
+ * reaches that same server, so the person's copy lives in the server's runtime folder. NOTHING LEAVES THE COMPUTER.
9
+ *
10
+ * WHAT FOLLOWS. Only the keys in KEYS: view choices. Drafts, caches, "seen" markers and panel sizes stay in each browser (a panel
11
+ * width that fits a desk does not fit a phone). A key is allowed when it is in KEYS.exact or starts with one of KEYS.prefix.
12
+ *
13
+ * THE FILE. { v: 1, prefs: { <key>: { v: <string> | null, at: <ms> } }, followed: [{ at, device, n }] }, mode 0600, written through a
14
+ * temporary file and a rename. The later `at` wins, so two devices never fight; `v: null` means the person removed the value.
15
+ * `followed` notes each page open that took at least one value from here (the health number); it keeps KEEP_DAYS days.
16
+ *
17
+ * allowed(key) → boolean PURE
18
+ * off(env) → boolean PMOS_PREFS_SYNC=off (or 0, false, no) turns the whole thing off
19
+ * read(dir) → { prefs, followed } a file that cannot be read counts as empty
20
+ * values(dir) → { <key>: { v, at } }
21
+ * apply(dir, body, now) → { ok, wrote, refused } | { ok: false, error }
22
+ * body = { set: { <key>: { v, at } }, followed?: <n>, device?: phone|tablet|desk }
23
+ * count(dir, now) → the page opens in the last KEEP_DAYS days that took a value from the store
24
+ * CLI: node lib/prefs-sync.js count [--root <runtime>] → the count on its last line (the health number) */
25
+ const fs = require('fs');
26
+ const path = require('path');
27
+
28
+ const FILE = 'view-prefs.json';
29
+ const MAX_VALUE = 8192;
30
+ const MAX_KEYS = 300;
31
+ const MAX_FOLLOWED = 500;
32
+ const KEEP_DAYS = 30;
33
+ const DAY = 864e5;
34
+ const SKEW = 60e3; // a device clock a minute ahead is still believed; further ahead is cut to now
35
+ const DEVICES = ['phone', 'tablet', 'desk'];
36
+
37
+ /* View choices only. A new view choice that should follow the person is added here; nothing else needs to change. */
38
+ const KEYS = Object.freeze({
39
+ exact: Object.freeze([
40
+ 'pmos.c3.theme', 'pmos.adler',
41
+ 'pmos.work.view.3', 'pmos.work.sprint', 'pmos.work.classic', 'pmos.work.backlog',
42
+ 'pmos.backlog.view', 'pmos.backlog.prefs',
43
+ 'pmos.tasks.view', 'pmos.tasks.zoom', 'pmos.tasks.cols.timeline',
44
+ 'pmos.goals.filt', 'pmos.goals.cols',
45
+ 'pmos.lib.view', 'pmos.srl.view',
46
+ 'pmos.events.scope.v1', 'pmos.events.hide.v2', 'pmos.events.show',
47
+ 'pmos.routine.kind', 'pmos.routine.scope.v1',
48
+ 'pmos.intel.tiles.off', 'pmos.guide.folded', 'pmos.order.notnow', 'pmos.listen.where',
49
+ 'pmos.home.cardfold', 'pmos-report-orders-hidden', 'cz-live-side',
50
+ ]),
51
+ prefix: Object.freeze(['pmos.board.', 'pmos.pv.tab:', 'pmos.dash.view:', 'cz-vw-fold:']),
52
+ });
53
+ const EXACT = new Set(KEYS.exact);
54
+
55
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
56
+ const say = (s) => { try { console.log('[prefs-follow-person] ' + s); } catch { /* no console */ } };
57
+
58
+ function allowed(key) {
59
+ if (typeof key !== 'string' || !key || key.length > 120) return false;
60
+ if (EXACT.has(key)) return true;
61
+ return KEYS.prefix.some((p) => key.length > p.length && key.startsWith(p));
62
+ }
63
+
64
+ function off(env = process.env) { return ['off', '0', 'false', 'no'].includes(String((env && env.PMOS_PREFS_SYNC) || '').trim().toLowerCase()); }
65
+
66
+ function file(dir) { return dir ? path.join(dir, FILE) : null; }
67
+
68
+ function read(dir) {
69
+ const f = file(dir);
70
+ let j = null;
71
+ try { j = f ? JSON.parse(fs.readFileSync(f, 'utf8')) : null; } catch { j = null; }
72
+ const prefs = {};
73
+ if (isObj(j) && isObj(j.prefs)) {
74
+ for (const [k, e] of Object.entries(j.prefs)) {
75
+ if (allowed(k) && isObj(e) && Number.isFinite(e.at) && (e.v === null || typeof e.v === 'string')) prefs[k] = { v: e.v, at: e.at };
76
+ }
77
+ }
78
+ const followed = isObj(j) && Array.isArray(j.followed) ? j.followed.filter((x) => isObj(x) && typeof x.at === 'string' && Number.isFinite(x.n)) : [];
79
+ return { prefs, followed };
80
+ }
81
+
82
+ function values(dir) { return read(dir).prefs; }
83
+
84
+ function write(dir, data) {
85
+ const f = file(dir);
86
+ fs.mkdirSync(dir, { recursive: true });
87
+ const tmp = f + '.' + process.pid + '.' + Date.now() + '.tmp';
88
+ fs.writeFileSync(tmp, JSON.stringify({ v: 1, prefs: data.prefs, followed: data.followed }), { mode: 0o600 });
89
+ fs.renameSync(tmp, f);
90
+ try { fs.chmodSync(f, 0o600); } catch { /* a file system without modes */ }
91
+ }
92
+
93
+ function apply(dir, body, now = Date.now()) {
94
+ if (!dir) return { ok: false, error: 'This workspace has no runtime folder, so preferences are not kept.' };
95
+ if (!isObj(body)) return { ok: false, error: 'the body must be an object' };
96
+ const set = body.set == null ? {} : body.set;
97
+ if (!isObj(set)) return { ok: false, error: 'set must be an object of key → { v, at }' };
98
+ const n = body.followed == null ? 0 : Number(body.followed);
99
+ if (!Number.isInteger(n) || n < 0 || n > MAX_KEYS) return { ok: false, error: 'followed must be a whole number' };
100
+ const cur = read(dir);
101
+ const refused = [];
102
+ let wrote = 0;
103
+ for (const [k, e] of Object.entries(set)) {
104
+ if (!allowed(k)) { refused.push({ key: String(k).slice(0, 120), why: 'not a view preference' }); continue; }
105
+ if (!isObj(e) || !(e.v === null || typeof e.v === 'string') || !Number.isFinite(e.at)) { refused.push({ key: k, why: 'needs { v: text or null, at: time }' }); continue; }
106
+ if (typeof e.v === 'string' && e.v.length > MAX_VALUE) { refused.push({ key: k, why: `longer than ${MAX_VALUE} characters` }); continue; }
107
+ const at = Math.min(e.at, now + SKEW);
108
+ const had = cur.prefs[k];
109
+ if (had && had.at >= at) continue; // an older or equal write: the person's later choice stands
110
+ if (!had && Object.keys(cur.prefs).length >= MAX_KEYS) { refused.push({ key: k, why: `the store already keeps ${MAX_KEYS} preferences` }); continue; }
111
+ cur.prefs[k] = { v: e.v, at };
112
+ wrote++;
113
+ }
114
+ let followed = cur.followed.filter((x) => Date.parse(x.at) > now - KEEP_DAYS * DAY);
115
+ const pruned = followed.length !== cur.followed.length;
116
+ if (n > 0) followed.push({ at: new Date(now).toISOString(), device: DEVICES.includes(body.device) ? body.device : 'desk', n });
117
+ if (followed.length > MAX_FOLLOWED) followed = followed.slice(-MAX_FOLLOWED);
118
+ if (wrote || n > 0 || pruned) {
119
+ try { write(dir, { prefs: cur.prefs, followed }); } catch (e) { return { ok: false, error: 'could not save: ' + (e && e.message) }; }
120
+ say(`wrote ${wrote}, followed ${n}${n ? ' on ' + (DEVICES.includes(body.device) ? body.device : 'desk') : ''}, keeps ${Object.keys(cur.prefs).length}`);
121
+ }
122
+ return { ok: true, wrote, refused };
123
+ }
124
+
125
+ function count(dir, now = Date.now()) {
126
+ return read(dir).followed.filter((x) => Date.parse(x.at) > now - KEEP_DAYS * DAY && x.n > 0).length;
127
+ }
128
+
129
+ module.exports = { FILE, KEYS, MAX_VALUE, MAX_KEYS, KEEP_DAYS, allowed, off, file, read, values, apply, count };
130
+
131
+ if (require.main === module) {
132
+ const argv = process.argv.slice(2);
133
+ const i = argv.indexOf('--root');
134
+ const dir = i >= 0 ? argv[i + 1] : require('./state-root.js').defaultRoot({ env: process.env });
135
+ if (argv[0] === 'count') { console.log(count(dir)); process.exit(0); }
136
+ console.error('usage: node lib/prefs-sync.js count [--root <runtime folder>]');
137
+ process.exit(2);
138
+ }
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* product-dots.js — the product switcher's dots (bet A381, initiative product-switcher-dots). For each registered product: how many rows
4
+ * need the PM now, from the same rows that make Today's "needs you" count (lib/briefing-premium.js allRowsOf). The row that shows them is
5
+ * public/pm/product-switcher.js; the route is GET /api/briefing-premium/products?needs=1.
6
+ *
7
+ * needsIn(f, now, defers, product?) → n | null PURE. One product's read: its rows that need the PM, less those put off. null while pending.
8
+ * dotsOf({ available, now, factsOf, defers, log? }) → { [ws]: n | null } every registered product, ticked or not. null: not read yet.
9
+ * presses(lines, now) → n PURE. Presses of the switcher (control data-psw) in the use log, last 7 days.
10
+ * CLI: node lib/product-dots.js count → presses of the last 7 days on its last line (the health number)
11
+ *
12
+ * WHAT IS READ. A product that is on Home is asked with the Briefing's own age (5 minutes), so it costs nothing new. A product that is not
13
+ * on Home is read only for its dot, at most every 30 minutes, through the same one-read-at-a-time state (lib/briefing-premium-products.js
14
+ * factsOf). Nothing here writes a record or sends anything. A change in the dots writes one `[product-dots]` server log line. */
15
+ const BP = require('./briefing-premium.js');
16
+ const Prod = require('./briefing-premium-products.js');
17
+
18
+ const ON_MAX_AGE = Prod.STALE_MS;
19
+ const OFF_MAX_AGE = 30 * 60 * 1000;
20
+ const PRESS_DAYS = 7;
21
+ const CONTROL = 'data-psw';
22
+ const say = (line) => { try { console.log(line); } catch { /* no console */ } };
23
+
24
+ function needsIn(f, now, defers, product) {
25
+ if (!f || f.pending) return null;
26
+ const g = Object.assign({ initiatives: [], runs: [], merges: [], evals: [], tripwires: null, missing: [], protoDecided: [] }, f, { now, asOf: now, meetings: null, defers: defers || {} });
27
+ if (product) g.product = product;
28
+ return BP.allRowsOf(g).all.length;
29
+ }
30
+
31
+ let lastSig = null;
32
+ async function dotsOf({ available, now = Date.now(), factsOf, defers = {}, log = say }) {
33
+ const out = {};
34
+ for (const p of available || []) {
35
+ let f = null;
36
+ try { f = await factsOf(p, { maxAge: p.on ? ON_MAX_AGE : OFF_MAX_AGE }); } catch { f = null; }
37
+ out[p.ws] = needsIn(f, now, defers, { ws: p.ws, name: p.name });
38
+ }
39
+ const v = Object.values(out), sig = JSON.stringify(out);
40
+ if (sig !== lastSig) {
41
+ lastSig = sig;
42
+ log('[product-dots] ' + v.length + ' products, ' + v.filter((x) => x > 0).length + ' with a dot, ' + v.filter((x) => x === null).length + ' not read yet');
43
+ }
44
+ return out;
45
+ }
46
+ const forget = () => { lastSig = null; };
47
+
48
+ function presses(lines, now = Date.now()) {
49
+ const cut = now - PRESS_DAYS * 864e5;
50
+ return (lines || []).filter((l) => l && l.kind === 'use' && l.control === CONTROL && Date.parse(l.at) >= cut && Date.parse(l.at) <= now + 864e5).length;
51
+ }
52
+
53
+ module.exports = { ON_MAX_AGE, OFF_MAX_AGE, CONTROL, needsIn, dotsOf, presses, forget };
54
+
55
+ if (require.main === module) {
56
+ if (process.argv[2] !== 'count') { console.error('usage: node lib/product-dots.js count (presses of the product switcher in the last ' + PRESS_DAYS + ' days)'); process.exit(2); }
57
+ const UL = require('./use-log.js');
58
+ const dir = require('./state-root.js').defaultRoot({ env: process.env });
59
+ console.log(String(presses(UL.readLines(dir))));
60
+ }
@@ -138,6 +138,8 @@ const MODULES = Object.freeze([
138
138
  'routes-spec-critic', // spec-critic: the sceptical reviewer's hardest questions on a document before it is shared (runtime spec-critic.jsonl)
139
139
  'routes-jira-epics', // work-subtasks: the epic check's fix, direct on tickets assigned to the PM, the day's draft for the rest (tracker/jira/epics.jsonl; page-press POST)
140
140
  'routes-use-log', // bet A466: the local use log, page opens and controls pressed, on this computer only (runtime use-log.jsonl; page-press POST)
141
+ 'routes-strategy-card', // bet A458: a product's five-line strategy above its Board, and the gentle "doesn't fit" note on new work (records strategy-card.jsonl; page-press POST)
142
+ 'routes-prefs', // bet A461: view preferences that follow the person to the phone and other browsers (runtime view-prefs.json; page-press POST)
141
143
  ]);
142
144
  const PM_DIR = path.join(__dirname, '..', 'public', 'pm');
143
145
  const MODULE_NAME = /^[a-z0-9][a-z0-9-]*\.js$/;
@@ -27,6 +27,7 @@ const { correctionEvent } = require(repoScript('card-state.js'));
27
27
  const { appendOutbox } = require(repoScript('outbox.js'));
28
28
 
29
29
  const Prod = require('./briefing-premium-products.js');
30
+ const Dots = require('./product-dots.js');
30
31
  const Src = require('./briefing-premium-sources.js');
31
32
  const Drafts = require('./briefing-premium-drafts.js');
32
33
  const settings = require('./settings-store.js');
@@ -327,7 +328,16 @@ module.exports = { grillAsk, liveAsk,
327
328
  let def = null; try { def = ctx.getWs ? ctx.getWs(null) : null; } catch { def = null; }
328
329
  // with no pick saved (the default), the workspace a page opens with stays ticked, as every page showed it before the pick
329
330
  const pub = (sel) => { const chosen = Array.isArray(settings.get(ctx.runtimeDir, 'ws.briefing.include', null)); return { ok: true, all: !!sel.all, chosen, products: sel.available.map((a) => { const primary = !!def && def.id === a.ws; return { ws: a.ws, name: a.name, home: a.home, primary, initials: a.initials || null, on: a.on || (!chosen && primary) }; }) }; };
330
- if (req.method === 'GET') { ctx.json(res, pub(products(ctx))); return true; }
331
+ if (req.method === 'GET') {
332
+ const sel = products(ctx), body = pub(sel);
333
+ // ?needs=1 (bet A381): each product's count of rows that need the PM, for the product switcher's dot (lib/product-dots.js); null: not read yet
334
+ if (url.searchParams.get('needs') === '1') {
335
+ const now = Date.now();
336
+ const d = await Dots.dotsOf({ available: sel.available.map((a, i) => ({ ...a, on: body.products[i].on })), now, defers: Object.fromEntries(Wr.readDefers(ctx.runtimeDir, now)), factsOf: (p, o) => Prod.factsOf(p, { engine: enginePath(), runtimeDir: ctx.runtimeDir, maxAge: o.maxAge }) });
337
+ body.products.forEach((p) => { p.needs = p.ws in d ? d[p.ws] : null; });
338
+ }
339
+ ctx.json(res, body); return true;
340
+ }
331
341
  if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'GET or POST only' }, 405); return true; }
332
342
  const got = await ctx.readJson(req);
333
343
  if (!got.ok || !got.body || typeof got.body !== 'object' || !Array.isArray(got.body.on)) { ctx.json(res, { ok: false, error: 'body must be JSON with on, the ticked workspace ids' }, 400); return true; }
@@ -2,7 +2,7 @@
2
2
  /* routes-moments.js — a feature appears when its moment comes, over HTTP (onboarding build B3; lib/moments.js holds the rules).
3
3
  *
4
4
  * GET /api/moments → { ok, moment: { id, ws, product, text, sub, href, guide, guideLabel, go, shown } | null,
5
- * places: { board|insights|reports: { quiet, dot, line } } }
5
+ * places: { board|insights|reports: { quiet, dot, line, next? } } } next: { id, say, ask }, the one step a quiet place offers
6
6
  * the day's ✦ for Home's chat, the menu dots, and the quiet line of a place not open yet
7
7
  * POST /api/moments/shown { ws, id } → { ok } the ✦ was drawn: it is that day's moment
8
8
  * POST /api/moments/keep { ws, id } → { ok } ✓: the page opens the place; its dot clears