create-pmos 0.827.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 (103) hide show
  1. package/package.json +217 -45
  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/bin/pmos.js +19 -9
  7. package/workspace/board-deliveries-test.js +2 -2
  8. package/workspace/changelog.json +216 -12
  9. package/workspace/guide/cli.md +62 -0
  10. package/workspace/guide/home.md +1 -0
  11. package/workspace/guide/settings-and-switches.md +1 -0
  12. package/workspace/lib/board-cli.js +5 -1
  13. package/workspace/lib/board-premium.js +1 -0
  14. package/workspace/lib/critical-needs.js +162 -0
  15. package/workspace/lib/deps-cli.js +102 -0
  16. package/workspace/lib/engine/boards.js +13 -2
  17. package/workspace/lib/features.json +5 -0
  18. package/workspace/lib/five-action-cap.js +84 -0
  19. package/workspace/lib/needs-providers.js +1 -0
  20. package/workspace/lib/page-one-answer.js +86 -0
  21. package/workspace/lib/pages-cli.js +6 -2
  22. package/workspace/lib/people-cli.js +43 -2
  23. package/workspace/lib/pmos-verbs.js +15 -1
  24. package/workspace/lib/portfolio-cli.js +64 -0
  25. package/workspace/lib/portfolio.js +168 -0
  26. package/workspace/lib/prototype-cli.js +86 -0
  27. package/workspace/lib/report-cli.js +12 -2
  28. package/workspace/lib/report-readers.js +5 -3
  29. package/workspace/lib/review-pack.js +348 -0
  30. package/workspace/lib/review-reasons.js +357 -0
  31. package/workspace/lib/route-modules.js +6 -0
  32. package/workspace/lib/routes-boards.js +25 -2
  33. package/workspace/lib/routes-portfolio.js +50 -0
  34. package/workspace/lib/routes-review-pack.js +42 -0
  35. package/workspace/lib/routes-roadmap-ops.js +53 -1
  36. package/workspace/lib/routes-sim-users.js +66 -0
  37. package/workspace/lib/routes-stakeholders.js +42 -0
  38. package/workspace/lib/routes-strategy-card.js +29 -1
  39. package/workspace/lib/routes-team-waits.js +24 -0
  40. package/workspace/lib/routes-use-log.js +6 -1
  41. package/workspace/lib/sim-users.js +329 -0
  42. package/workspace/lib/stakeholder-map.js +232 -0
  43. package/workspace/lib/task-store.js +1 -1
  44. package/workspace/lib/team-waits.js +167 -0
  45. package/workspace/lib/tradeoff-cards.js +258 -0
  46. package/workspace/lib/tradeoff-cli.js +83 -0
  47. package/workspace/lib/voice-cli.js +7 -0
  48. package/workspace/package-lock.json +2 -2
  49. package/workspace/package.json +1 -1
  50. package/workspace/premium-vw-jira-test.js +6 -2
  51. package/workspace/public/pm/bd-backlog.js +44 -6
  52. package/workspace/public/pm/bd-principles.js +12 -1
  53. package/workspace/public/pm/cozy-library.css +5 -0
  54. package/workspace/public/pm/cozy-pick.css +1 -0
  55. package/workspace/public/pm/cozy-pop-work.js +8 -2
  56. package/workspace/public/pm/cozy-proto.css +5 -0
  57. package/workspace/public/pm/cozy-proto.js +11 -3
  58. package/workspace/public/pm/cozy-today-app.js +53 -3
  59. package/workspace/public/pm/cozy-today-view.js +12 -4
  60. package/workspace/public/pm/day-time.js +8 -0
  61. package/workspace/public/pm/five-action-cap.js +104 -0
  62. package/workspace/public/pm/home-ini.js +3 -2
  63. package/workspace/public/pm/ini-links.js +2 -1
  64. package/workspace/public/pm/ini-tasks.js +5 -2
  65. package/workspace/public/pm/ini-view-model.js +14 -6
  66. package/workspace/public/pm/ini-view.js +12 -2
  67. package/workspace/public/pm/library-model.js +1 -1
  68. package/workspace/public/pm/page-one-answer.css +18 -0
  69. package/workspace/public/pm/page-one-answer.js +134 -0
  70. package/workspace/public/pm/pop-work-model.js +8 -6
  71. package/workspace/public/pm/portfolio.js +67 -0
  72. package/workspace/public/pm/premium-board.js +19 -6
  73. package/workspace/public/pm/premium-library.js +27 -3
  74. package/workspace/public/pm/product-switcher.js +7 -1
  75. package/workspace/public/pm/range-pick.css +12 -0
  76. package/workspace/public/pm/range-pick.js +30 -6
  77. package/workspace/public/pm/review-pack.js +47 -0
  78. package/workspace/public/pm/review-reasons.js +75 -0
  79. package/workspace/public/pm/sim-users.js +34 -0
  80. package/workspace/public/pm/sort-order.js +3 -0
  81. package/workspace/public/pm/stakeholder-map.js +125 -0
  82. package/workspace/public/pm/task-card.js +10 -7
  83. package/workspace/public/pm/team-waits.js +56 -0
  84. package/workspace/public/pm/tradeoff-cards.css +27 -0
  85. package/workspace/public/pm/tradeoff-cards.js +183 -0
  86. package/workspace/public/premium-board.html +1 -0
  87. package/workspace/public/premium-portfolio.html +48 -0
  88. package/workspace/public/today.html +1 -0
  89. package/workspace/run-tests.js +9 -1
  90. package/workspace/server.js +1 -1
  91. package/workspace/stage-card-tasks-test.js +11 -5
  92. package/workspace/test-lists/critical-needs.json +9 -0
  93. package/workspace/test-lists/five-action-cap.json +9 -0
  94. package/workspace/test-lists/page-one-answer.json +9 -0
  95. package/workspace/test-lists/portfolio.json +9 -0
  96. package/workspace/test-lists/review-pack.json +9 -0
  97. package/workspace/test-lists/review-reasons.json +9 -0
  98. package/workspace/test-lists/sim-users.json +9 -0
  99. package/workspace/test-lists/stakeholder-map.json +9 -0
  100. package/workspace/test-lists/task-time-optional.json +9 -0
  101. package/workspace/test-lists/team-waits.json +9 -0
  102. package/workspace/test-lists/tradeoff-cards.json +9 -0
  103. package/workspace/test-timings.json +25 -0
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+ /* portfolio-cli.js — `pmos portfolio`: every registered product side by side, and the answer to its one recommendation (initiative portfolio).
3
+ * The work is in lib/portfolio.js; the page (/premium-portfolio.html) reads the same rows and writes the same store.
4
+ *
5
+ * pmos portfolio [--json] one line per product (bets, odds, spend, outcome) and the ✦ recommendation, if any
6
+ * pmos portfolio keep|not-now <key> answer the recommendation: Keep hides it while its facts hold, Not now for 7 days
7
+ * pmos portfolio undo <key> take the last answer back
8
+ *
9
+ * The products are the workspace's registered ones (workspaces.json in the state folder), and this repository when it has a PMOS state
10
+ * folder. Reading changes no product's files. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const PF = require('./portfolio.js');
14
+
15
+ const COMMANDS = { portfolio: ['keep', 'not-now', 'undo'] };
16
+ const USAGE = [
17
+ 'usage: pmos portfolio [--json] | keep|not-now|undo <key> — every product side by side: bets, odds, spend, outcome so far',
18
+ ' pmos portfolio [--json] one line per product and PMOS\'s one recommendation',
19
+ ' pmos portfolio keep <key> keep the recommendation (it stays hidden while its facts hold)',
20
+ ' pmos portfolio not-now <key> not now: hidden for 7 days',
21
+ ' pmos portfolio undo <key> take the last answer back',
22
+ ].join('\n');
23
+
24
+ const stateOf = (env) => require('./state-root.js').defaultRoot({ env });
25
+
26
+ /** The registered products, and this repository when it has a PMOS state folder and is not registered. */
27
+ function productsOf(dir, cwd) {
28
+ const driver = require('./driver.js');
29
+ let reg = [];
30
+ try { reg = JSON.parse(fs.readFileSync(path.join(dir, 'workspaces.json'), 'utf8')); } catch { reg = []; }
31
+ const out = [], seen = new Set();
32
+ const add = (root, ws, name) => {
33
+ const r = path.resolve(root);
34
+ if (seen.has(r) || !driver.stateDirOf(r)) return;
35
+ seen.add(r);
36
+ out.push({ ws: ws || driver.wsIdOf(r), name: name || path.basename(r), root: r });
37
+ };
38
+ for (const x of Array.isArray(reg) ? reg : []) if (x && typeof x.root === 'string') { try { if (fs.statSync(x.root).isDirectory()) add(x.root, x.id, x.name); } catch { /* gone */ } }
39
+ if (cwd) add(cwd);
40
+ return out;
41
+ }
42
+
43
+ function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now() } = {}) {
44
+ const args = argv[0] === 'portfolio' ? argv.slice(1) : argv.slice();
45
+ const dir = stateOf(env);
46
+ const sub = args[0] && !args[0].startsWith('--') ? args[0] : null;
47
+ if (sub === 'help') { say(USAGE); return 0; }
48
+ if (sub) {
49
+ if (!PF.KINDS.includes(sub) || !args[1]) { say(USAGE); return 2; }
50
+ const r = PF.decide(dir, { key: args[1], kind: sub, by: 'cli' }, { now });
51
+ if (!r.ok) { say(r.error); return 1; }
52
+ console.info(`${PF.TAG} ${sub} key=${args[1]}`);
53
+ say(sub === 'undo' ? 'Taken back: the recommendation shows again.' : sub === 'keep' ? `Kept. To take it back: pmos portfolio undo ${args[1]}` : `Not now: hidden for ${PF.NOT_NOW_DAYS} days. To take it back: pmos portfolio undo ${args[1]}`);
54
+ return 0;
55
+ }
56
+ const v = PF.view(productsOf(dir, cwd), dir, { now });
57
+ try { require('./use-log.js').record(dir, [{ kind: 'use', page: 'premium-portfolio', control: 'portfolio', device: 'desk' }], now); } catch { /* a count, never a reason to fail */ }
58
+ console.info(`${PF.TAG} products=${v.rows.length} show=${v.show} rec=${v.rec ? 1 : 0}`);
59
+ if (args.includes('--json')) { say(JSON.stringify(v, null, 2)); return 0; }
60
+ for (const l of PF.lines(v)) say(l);
61
+ return 0;
62
+ }
63
+
64
+ module.exports = { COMMANDS, USAGE, run, productsOf };
@@ -0,0 +1,168 @@
1
+ 'use strict';
2
+ /* portfolio.js — the Portfolio: every product side by side for a head of product (bet A56, initiative portfolio, board BatchPlanDS panel 7).
3
+ *
4
+ * rowsOf(facts, { now }) PURE → [{ ws, name, bets, odds, judged, spend, outcome, due }] one row per product, in the given order
5
+ * recommend(rows) PURE → { key, to, from, n, text, why } | null at most one recommendation
6
+ * fold(lines, now) PURE → { [key]: { kind, until } } the decisions that stand (Undo takes the last back)
7
+ * hidden(rec, lines, now) PURE → bool Keep hides it while its facts hold; Not now for 7 days
8
+ * factsOf(root, { now }) → one product's facts, read from its own records (never written)
9
+ * read(products, { now }) → { show, rows, rec } products: [{ ws, name, root }]. rec is the recommendation before decisions
10
+ * view(products, dir, { now }) → { ok, show, rows, rec, as_of } read() with the decisions of <dir>/portfolio.jsonl applied
11
+ * decide(dir, { key, kind, by }, { now }) → { ok, line } | { ok: false, error } THE ONE WRITER of <dir>/portfolio.jsonl
12
+ *
13
+ * THE NUMBERS come from records every PMOS product keeps, so the page works on any user's products:
14
+ * bets the product's work initiatives that are not stopped and whose outcome is not judged yet (lib/outcomes.js scan: subjects less disposed)
15
+ * odds validated of validated plus refuted outcome checks, in percent. Under MIN_JUDGED judged it is null: not known, never a guess
16
+ * spend the cost of the product's agent runs in the last SPEND_DAYS days (factory-traces.jsonl in its state folder). No cost: null
17
+ * outcome the evidence of the product's latest check that held (validated). None: null
18
+ * due its bets whose outcome check is due: they wait on review
19
+ * THE RECOMMENDATION. The product with the most due checks, MIN_DUE or more, is the one to help. When another product has more open bets
20
+ * and none due, PMOS says to move one person from it; otherwise to look at the product first. The reason is the due count.
21
+ *
22
+ * THE STORE. <runtime>/portfolio.jsonl, append-only, one line { at, kind: 'keep'|'not-now'|'undo', key, by, until? }. The key holds the
23
+ * facts (to, from, due count), so a kept recommendation comes back only when they change. Nothing here writes a product's files.
24
+ * The Portfolio shows only with MIN_PRODUCTS products or more (`show`). */
25
+ const fs = require('fs');
26
+ const path = require('path');
27
+
28
+ const FILE = 'portfolio.jsonl';
29
+ const TAG = '[portfolio]';
30
+ const DAY = 86400000;
31
+ const SPEND_DAYS = 30;
32
+ const MIN_JUDGED = 3;
33
+ const MIN_DUE = 2;
34
+ const MIN_PRODUCTS = 2;
35
+ const NOT_NOW_DAYS = 7;
36
+ const KINDS = Object.freeze(['keep', 'not-now', 'undo']);
37
+ const KEY_RE = /^[A-Za-z0-9._:-]{1,200}$/;
38
+
39
+ const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); if (t.length <= n) return t; const c = t.slice(0, n - 1); return (c.slice(0, c.lastIndexOf(' ')) || c).replace(/[,;:\s]+$/, '') + '…'; };
40
+ const timeOf = (c) => { const t = Date.parse(c && (c.at || c.date) || ''); return Number.isFinite(t) ? t : 0; };
41
+
42
+ function rowsOf(facts, { now = Date.now() } = {}) {
43
+ const since = now - SPEND_DAYS * DAY;
44
+ return (facts || []).map((f) => {
45
+ const judgedIds = new Set((f.disposed || []).map((d) => d.id));
46
+ const bets = (f.subjects || []).filter((s) => !judgedIds.has(s.id)).length;
47
+ const held = (f.disposed || []).filter((d) => d.disposition === 'validated').length;
48
+ const refuted = (f.disposed || []).filter((d) => d.disposition === 'refuted').length;
49
+ const judged = held + refuted;
50
+ const odds = judged >= MIN_JUDGED ? Math.round((held / judged) * 100) : null;
51
+ let spend = null;
52
+ for (const r of f.runs || []) {
53
+ const t = Date.parse(r && r.at || '');
54
+ if (!Number.isFinite(t) || t < since || t > now || !Number.isFinite(r.costUsd) || r.costUsd <= 0) continue;
55
+ spend = (spend || 0) + r.costUsd;
56
+ }
57
+ if (spend != null) spend = Math.round(spend * 100) / 100;
58
+ const last = (f.checks || []).filter((c) => c && c.disposition === 'validated' && c.evidence).sort((a, b) => timeOf(b) - timeOf(a))[0];
59
+ return { ws: f.ws, name: f.name || f.ws, bets, odds, judged, spend, outcome: last ? clip(last.evidence, 60) : null, due: (f.due || []).length };
60
+ });
61
+ }
62
+
63
+ function recommend(rows) {
64
+ const R = (rows || []).filter(Boolean);
65
+ const to = R.filter((r) => r.due >= MIN_DUE).sort((a, b) => b.due - a.due || b.bets - a.bets || String(a.name).localeCompare(String(b.name)))[0];
66
+ if (!to) return null;
67
+ const from = R.filter((r) => r !== to && r.due === 0 && r.bets > to.bets).sort((a, b) => b.bets - a.bets || String(a.name).localeCompare(String(b.name)))[0] || null;
68
+ const n = to.due;
69
+ return {
70
+ key: `${to.ws}:${from ? from.ws : '-'}:${n}`,
71
+ to: to.ws, from: from ? from.ws : null, n,
72
+ text: from ? `Move one person from ${from.name} to ${to.name}` : `Look at ${to.name} first`,
73
+ why: `${n} bets there wait on their outcome check.`,
74
+ };
75
+ }
76
+
77
+ function fold(lines, now = Date.now()) {
78
+ const stack = {};
79
+ for (const l of lines || []) {
80
+ if (!l || !KEY_RE.test(String(l.key || '')) || !KINDS.includes(l.kind)) continue;
81
+ const s = (stack[l.key] = stack[l.key] || []);
82
+ if (l.kind === 'undo') s.pop(); else s.push(l);
83
+ }
84
+ const out = {};
85
+ for (const [k, s] of Object.entries(stack)) if (s.length) { const l = s[s.length - 1]; out[k] = { kind: l.kind, until: l.until || null, at: l.at || null }; }
86
+ return out;
87
+ }
88
+
89
+ function hidden(rec, lines, now = Date.now()) {
90
+ if (!rec) return false;
91
+ const d = fold(lines, now)[rec.key];
92
+ if (!d) return false;
93
+ if (d.kind === 'keep') return true;
94
+ return d.kind === 'not-now' && !!d.until && Date.parse(d.until) > now;
95
+ }
96
+
97
+ /** Every outcome check line the product holds, in the places lib/outcomes.js reads them, each file once. */
98
+ function checksOf(root, runsDir) {
99
+ const OC = require('./outcomes.js');
100
+ const files = [...new Set([runsDir, path.join(root, 'pmos', 'state'), path.join(root, 'planning', 'runs')].filter(Boolean).map((d) => path.join(d, 'outcome_checks.jsonl')))];
101
+ const rows = [];
102
+ for (const f of files) {
103
+ let text = ''; try { text = fs.readFileSync(f, 'utf8'); } catch { continue; }
104
+ for (const s of text.split('\n')) { if (!s.trim()) continue; try { const o = JSON.parse(s); if (o && typeof o === 'object') rows.push(o); } catch { /* a torn line */ } }
105
+ }
106
+ return OC.liveChecks(rows);
107
+ }
108
+
109
+ function factsOf(root, { now = Date.now() } = {}) {
110
+ const OC = require('./outcomes.js');
111
+ const S = OC.scan(root, { today: OC.todayOf(now) });
112
+ let runs = [];
113
+ try { const dir = require('./driver.js').stateDirOf(root); runs = require('./factory-traces.js').read(dir, { sinceMs: now - SPEND_DAYS * DAY }); } catch { runs = []; }
114
+ return {
115
+ subjects: S.subjects.map((s) => ({ id: s.id })),
116
+ disposed: S.disposed.map((d) => ({ id: d.id, disposition: d.disposition })),
117
+ due: S.due.map((d) => ({ id: d.id })),
118
+ checks: checksOf(path.resolve(root), S.layout && S.layout.runsDir),
119
+ runs: runs.map((r) => ({ at: r.at, costUsd: r.costUsd })),
120
+ };
121
+ }
122
+
123
+ function read(products, { now = Date.now(), factsOf: F = factsOf } = {}) {
124
+ const list = (products || []).filter((p) => p && p.root);
125
+ const facts = list.map((p) => { let f; try { f = F(p.root, { now }); } catch { f = {}; } return { ...f, ws: p.ws, name: p.name || path.basename(p.root) }; });
126
+ const rows = rowsOf(facts, { now });
127
+ return { show: rows.length >= MIN_PRODUCTS, rows, rec: recommend(rows) };
128
+ }
129
+
130
+ function linesOf(dir) {
131
+ let text = ''; try { text = fs.readFileSync(path.join(dir, FILE), 'utf8'); } catch { return []; }
132
+ const out = [];
133
+ for (const s of text.split('\n')) { if (!s.trim()) continue; try { out.push(JSON.parse(s)); } catch { /* a torn line */ } }
134
+ return out;
135
+ }
136
+
137
+ function view(products, dir, o = {}) {
138
+ const now = o.now || Date.now();
139
+ const r = read(products, o);
140
+ if (!r.show) return { ok: true, show: false, rows: [], rec: null, as_of: new Date(now).toISOString() };
141
+ const rec = r.rec && !hidden(r.rec, dir ? linesOf(dir) : [], now) ? r.rec : null;
142
+ return { ok: true, show: true, rows: r.rows, rec, as_of: new Date(now).toISOString() };
143
+ }
144
+
145
+ function decide(dir, { key, kind, by } = {}, { now = Date.now() } = {}) {
146
+ if (!dir) return { ok: false, error: 'no state folder to keep the decision in' };
147
+ if (!KINDS.includes(kind)) return { ok: false, error: `the answer is one of ${KINDS.join(', ')}` };
148
+ if (!KEY_RE.test(String(key || ''))) return { ok: false, error: 'name the recommendation by its key' };
149
+ if (kind === 'undo' && !fold(linesOf(dir), now)[key]) return { ok: false, error: 'there is no answer to this recommendation to undo' };
150
+ const line = { at: new Date(now).toISOString(), kind, key: String(key), by: String(by || 'pm').slice(0, 40) };
151
+ if (kind === 'not-now') line.until = new Date(now + NOT_NOW_DAYS * DAY).toISOString();
152
+ try {
153
+ fs.mkdirSync(dir, { recursive: true });
154
+ fs.appendFileSync(path.join(dir, FILE), JSON.stringify(line) + '\n', { mode: 0o600 });
155
+ } catch (e) { return { ok: false, error: 'the decision could not be saved: ' + String((e && e.message) || e).slice(0, 160) }; }
156
+ return { ok: true, line };
157
+ }
158
+
159
+ /** One printed line per product, then the recommendation. PURE. */
160
+ function lines(v) {
161
+ if (!v || !v.show) return ['Nothing to compare: the Portfolio needs two or more products.'];
162
+ const money = (n) => (n == null ? '' : '$' + (n >= 100 ? Math.round(n) : n.toFixed(2)));
163
+ const out = v.rows.map((r) => r.name + ': ' + [`${r.bets} bet${r.bets === 1 ? '' : 's'}`, r.odds == null ? '' : `odds ${r.odds}%`, r.spend == null ? '' : `spend ${money(r.spend)} (30 days)`, r.outcome ? `outcome: ${r.outcome}` : ''].filter(Boolean).join(' · '));
164
+ if (v.rec) out.push(`✦ ${v.rec.text}: ${v.rec.why} (pmos portfolio keep|not-now ${v.rec.key})`);
165
+ return out;
166
+ }
167
+
168
+ module.exports = { FILE, TAG, SPEND_DAYS, MIN_JUDGED, MIN_DUE, MIN_PRODUCTS, NOT_NOW_DAYS, KINDS, rowsOf, recommend, fold, hidden, factsOf, read, view, decide, linesOf, lines };
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+ /* prototype-cli.js — `pmos prototype`: what simulated users found on a prototype, and the personas that walk it (initiative sim-users,
3
+ * idea A20). The store is the one the Viewer reads (lib/sim-users.js, through the running server's /api/sim-users routes, lib/routes-sim-users.js),
4
+ * so what the chat writes here shows in the Viewer's Findings at once.
5
+ *
6
+ * pmos prototype findings <initiative> [--ws <id>] [--json] the findings of the initiative's prototype now
7
+ * pmos prototype personas [--ws <id>] the personas that walk each prototype (the base four when none is recorded)
8
+ * pmos prototype persona add --name "<who>" --needs <need,…> --from "<the record it comes from>" [--ws <id>]
9
+ * pmos prototype persona remove <id> [--ws <id>] it prints the Undo
10
+ * pmos prototype persona restore <id> [--ws <id>]
11
+ *
12
+ * A finding is a hint for the grilling, never a score. Nothing is sent and no model is called. Exit codes: 0 done, 1 refused, 2 usage. */
13
+ const SU = require('./sim-users.js');
14
+
15
+ const COMMANDS = { prototype: ['findings', 'personas', 'persona'] };
16
+ const USAGE = [
17
+ 'usage: pmos prototype findings|personas|persona — simulated users try the prototype before it reaches you; you see findings, never a score',
18
+ ' pmos prototype findings <initiative> [--ws <id>] [--json] where the simulated users got stuck on its prototype now, and how many',
19
+ ' pmos prototype personas [--ws <id>] the personas that walk each prototype',
20
+ ` pmos prototype persona add --name "<who>" --needs <${Object.keys(SU.NEEDS).join('|')},…> --from "<the record it comes from>" [--ws <id>]`,
21
+ ' pmos prototype persona remove <id> [--ws <id>] stop one walking (it prints the Undo)',
22
+ ' pmos prototype persona restore <id> [--ws <id>] bring it back',
23
+ 'With no persona recorded, four base personas walk: New user, Keyboard only, Screen reader, On a phone. Nothing is sent.',
24
+ ];
25
+ const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (args[i + 1] === undefined || args[i + 1].startsWith('--') ? true : args[i + 1]) : undefined; };
26
+ const NO_SERVER = '✗ no PMOS server answers: start PMOS, then ask again';
27
+ const needsOf = (p) => (p.needs || []).map((n) => SU.NEEDS[n] || n).join(', ');
28
+
29
+ async function run(argv, { say = (s) => console.log(s), env = process.env, call } = {}) {
30
+ const args = argv[0] === 'prototype' ? argv.slice(1) : argv.slice();
31
+ const verb = args[0];
32
+ if (!verb || ['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
33
+ if (!COMMANDS.prototype.includes(verb)) { say(`unknown prototype command "${verb}" — one of ${COMMANDS.prototype.join(', ')}`); return 2; }
34
+ if (typeof call !== 'function') { say(NO_SERVER); return 1; }
35
+ const ws = flag(args, 'ws'), wsQ = typeof ws === 'string' ? '&ws=' + encodeURIComponent(ws) : '';
36
+ const get = async (q) => { try { return await call('GET', q); } catch { return null; } };
37
+
38
+ if (verb === 'findings') {
39
+ const ini = args[1] && !args[1].startsWith('--') ? args[1] : '';
40
+ if (!ini) { say('usage: pmos prototype findings <initiative> [--ws <id>] [--json]'); return 2; }
41
+ const r = await get('/api/sim-users/findings?initiative=' + encodeURIComponent(ini) + wsQ);
42
+ if (!r) { say(NO_SERVER); return 1; }
43
+ if (!r.ok) { say('✗ ' + (r.error || 'no findings')); return 1; }
44
+ if (flag(args, 'json')) { say(JSON.stringify({ ok: true, file: r.file, version: r.version, findings: r.findings, personas: (r.personas || []).map((p) => p.id), base: r.base })); return 0; }
45
+ if (!r.file) { say(`${ini} has no prototype yet.`); return 0; }
46
+ if (!r.findings || !(r.findings.rows || []).length) { say(`Version ${r.version || 1} of ${ini} has no key tasks in its flow, so no simulated user walked it.`); return 0; }
47
+ say(`Version ${r.version || 1} of ${ini}, walked by ${r.findings.personas} simulated users${r.base ? ' (the base personas)' : ''}:`);
48
+ for (const x of r.findings.rows) say(`${x.state === 'risk' ? '◐' : '○'} ${x.text}${x.who ? ` (${x.who})` : ''}${x.screen ? ` · screen ${x.screen}` : ''}`);
49
+ say('A finding is a hint for your grilling, never a score.');
50
+ return 0;
51
+ }
52
+
53
+ if (verb === 'personas') {
54
+ const r = await get('/api/sim-users/personas?' + wsQ.slice(1));
55
+ if (!r) { say(NO_SERVER); return 1; }
56
+ if (!r.ok) { say('✗ ' + (r.error || 'no personas')); return 1; }
57
+ say(r.base ? 'No persona is recorded for this product, so the four base personas walk each prototype:' : 'The personas that walk each prototype:');
58
+ for (const p of r.personas || []) say(`- ${p.name} [${p.id}]: ${needsOf(p)}${p.from ? ` · from ${p.from}` : ''}`);
59
+ if (r.base) say('Add your own from your records: pmos prototype persona add --name "<who>" --needs <need,…> --from "<record>"');
60
+ return 0;
61
+ }
62
+
63
+ // persona add | remove | restore
64
+ const sub = args[1];
65
+ if (!['add', 'remove', 'restore'].includes(sub)) { say('usage: pmos prototype persona add|remove|restore … (pmos prototype help)'); return 2; }
66
+ let by = ''; try { by = require('./actor.js').fromCli({ env }).by || ''; } catch { by = ''; }
67
+ const body = { op: sub, ...(typeof ws === 'string' ? { ws } : {}), ...(by ? { by } : {}) };
68
+ if (sub === 'add') {
69
+ for (const k of ['name', 'needs', 'from']) { const v = flag(args, k); if (typeof v === 'string') body[k] = v; }
70
+ // refuse here first, so a persona with no record never reaches the store (the server refuses it too)
71
+ const v = SU.validPersona(body); if (v.error) { say('✗ ' + v.error); return 1; }
72
+ } else {
73
+ const id = args[2] && !args[2].startsWith('--') ? args[2] : '';
74
+ if (!id) { say(`usage: pmos prototype persona ${sub} <id> [--ws <id>]`); return 2; }
75
+ body.id = id;
76
+ }
77
+ let r = null; try { r = await call('POST', '/api/sim-users/personas', body); } catch { r = null; }
78
+ if (!r) { say(NO_SERVER); return 1; }
79
+ if (!r.ok) { say('✗ ' + (r.error || 'nothing changed')); return 1; }
80
+ if (sub === 'add') say(`✓ ${r.persona.name} walks each prototype from now on (${needsOf(r.persona)}).`);
81
+ else if (sub === 'remove') say(`✓ ${r.persona.name} no longer walks. Undo: ${r.undo}${typeof ws === 'string' ? ' --ws ' + ws : ''}`);
82
+ else say(`✓ ${r.persona.name} walks again.`);
83
+ return 0;
84
+ }
85
+
86
+ module.exports = { run, COMMANDS, USAGE };
@@ -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. */