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
@@ -0,0 +1,162 @@
1
+ 'use strict';
2
+ /* critical-needs.js — a Today row when a task on an initiative's critical path moves (initiative critical-moved, bet A103;
3
+ * done test planning/done-tests/critical-moved.md).
4
+ *
5
+ * movesOf(lines, { today, days }) → Map uid → { field, from, to, at } each task's latest start or due move in the window
6
+ * rowsOf(ws, { today, snapshot, lines, days }) → rows the needs rows, pure (the tests call it)
7
+ * needs provider: kinds ['critical-move'] · rowsFor(w, { lead }) · sig(w)
8
+ * count(root, { days, today }) → number the health number: rows raised in the window
9
+ *
10
+ * THE RULE. kind-control.js works out each initiative's critical path: the tasks that hold go-live tight through their links. When one of
11
+ * those tasks moved its start or its due date in the last `days` days (7), the PM gets ONE row for it, naming the task, the old and the new
12
+ * date, the initiative and what go-live now forecasts. A move off the critical path says nothing. A task's first dates are not a move.
13
+ * An initiative with no links into go-live has no critical path, so it says nothing either.
14
+ *
15
+ * WHERE THE DATES COME FROM. The tasks and links come from lib/rehearse-read.js snapshotOf (the readers the pmos verbs use). The moves come
16
+ * from the three task ledgers lib/routes-kind-control.js reads for the baseline: the task store, the plan-items ledger and the Board's task
17
+ * lines. A line names a task (`task` or `item`) and a `start` or `due`, at the top or under `fields`. Never a typed status.
18
+ */
19
+ const fs = require('fs');
20
+ const path = require('path');
21
+ const KC = require('./kind-control.js');
22
+ const TL = require('./task-links.js');
23
+
24
+ const NAME = 'critical-needs';
25
+ const KIND = 'critical-move';
26
+ const TAG = '[critical-moved]';
27
+ const DAYS = 7;
28
+ const clip = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
29
+ const todayOf = (now = Date.now()) => new Date(now).toISOString().slice(0, 10);
30
+ const WORD = { start: 'start', due: 'due' };
31
+
32
+ function readJsonl(file) {
33
+ let text = '';
34
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
35
+ const out = [];
36
+ for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { out.push(JSON.parse(raw)); } catch { /* a torn line */ } }
37
+ return out;
38
+ }
39
+
40
+ /** Each task's latest start or due move whose line is dated in the last `days` days. A line that sets a field for the first time is not a
41
+ * move; a line that repeats the same value is not a move. Lines are read oldest first. */
42
+ function movesOf(lines, { today = todayOf(), days = DAYS } = {}) {
43
+ const since = TL.dn(today) - days;
44
+ const last = new Map(), moves = new Map();
45
+ const sorted = (lines || []).filter((e) => e && typeof e === 'object').slice().sort((a, b) => String(a.at || '').localeCompare(String(b.at || '')));
46
+ for (const e of sorted) {
47
+ const id = typeof e.task === 'string' ? e.task : typeof e.item === 'string' ? e.item : null;
48
+ if (!id) continue;
49
+ const f = e.fields && typeof e.fields === 'object' ? e.fields : e;
50
+ const was = last.get(id) || {};
51
+ const now = { ...was };
52
+ for (const k of ['start', 'due']) {
53
+ const v = typeof f[k] === 'string' && TL.dn(f[k]) != null ? f[k].slice(0, 10) : undefined;
54
+ if (v === undefined) continue;
55
+ if (was[k] && was[k] !== v) {
56
+ const at = String(e.at || '');
57
+ const d = TL.dn(at.slice(0, 10));
58
+ if (d != null && d >= since && d <= TL.dn(today)) moves.set(id, { field: k, from: was[k], to: v, at });
59
+ }
60
+ now[k] = v;
61
+ }
62
+ last.set(id, now);
63
+ }
64
+ return moves;
65
+ }
66
+
67
+ /** The needs rows for one workspace, from a snapshot (rehearse-read.js shape) and the task ledger lines. Pure. */
68
+ function rowsOf(ws, { today = todayOf(), snapshot, lines, days = DAYS } = {}) {
69
+ const snap = snapshot || {};
70
+ const moves = movesOf(lines, { today, days });
71
+ if (!moves.size) return [];
72
+ const out = [];
73
+ for (const row of snap.rows || []) {
74
+ if (!row || !row.id) continue;
75
+ const tasks = (snap.tasks || []).filter((x) => x && x.ini === row.id);
76
+ if (!tasks.some((x) => moves.has(x.uid || x.key))) continue;
77
+ const goal = (snap.goals || []).find((g) => (g.moves || []).includes(row.id)) || null;
78
+ const m = KC.project({ today, title: row.title || row.id, goal: goal ? { id: goal.id, title: goal.title, byAt: goal.byAt } : null, end: row.end || null,
79
+ record: {}, tasks, links: snap.links || [] });
80
+ for (const r of m.rows) {
81
+ if (!r.critical) continue;
82
+ const mv = moves.get(r.uid);
83
+ if (!mv) continue;
84
+ const title = clip(row.title || row.id, 80);
85
+ const goLive = m.goLive && m.goLive.due ? TL.md(TL.dn(m.goLive.due)) : '';
86
+ const effect = goLive ? `, so go-live forecasts ${goLive}` : '';
87
+ const track = m.ontrack && (m.ontrack.answer === 'yes' || m.ontrack.answer === 'no') ? ' ' + m.ontrack.words : '';
88
+ const cause = `"${clip(r.title, 80)}" moved its ${WORD[mv.field]} from ${TL.md(TL.dn(mv.from))} to ${TL.md(TL.dn(mv.to))}. It is on the critical path of ${title}${effect}.${track}`;
89
+ out.push({
90
+ run_id: `${NAME}:${ws}:${row.id}:${r.uid}:${mv.at}`, kind: KIND, initiative_id: row.id, question: cause, doc: null, ws,
91
+ today: { kind: 7, source: NAME, cause, evidence: `Task dates and links · moved ${mv.at.slice(0, 10)} · critical path ${m.critical.length} tasks`, act: { label: 'Open' } },
92
+ });
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+
98
+ /** The task ledger lines of a repository (the three routes-kind-control.js reads for the baseline). */
99
+ function linesOf(root, stateDir) {
100
+ const lines = [];
101
+ try { const s = require('./task-store.js').storeFor(root); if (s) lines.push(...readJsonl(s.file)); } catch { /* none */ }
102
+ try { lines.push(...readJsonl(require('./plan-ledgers.js').ledgerPath(root, 'plan-items'))); } catch { /* none */ }
103
+ if (stateDir) {
104
+ try { const f = require('./routes-boards.js').ledgerFile({ stateDirFor: () => stateDir }, { root }); if (f) lines.push(...readJsonl(f).filter((e) => e && (e.kind === 'task' || e.kind === 'task-update'))); } catch { /* none */ }
105
+ }
106
+ return lines;
107
+ }
108
+ function stateDirOf(root) { try { return require('./driver.js').stateDirOf(root) || null; } catch { return null; } }
109
+
110
+ function read(root, { today = todayOf(), days = DAYS } = {}) {
111
+ const stateDir = stateDirOf(root);
112
+ const lines = linesOf(root, stateDir);
113
+ if (!movesOf(lines, { today, days }).size) return { lines, snapshot: null }; // no move in the window: the snapshot is not read
114
+ let snapshot;
115
+ try { snapshot = require('./rehearse-read.js').snapshotOf(root, { today, stateDir: stateDir || undefined }); } catch { snapshot = null; }
116
+ return { lines, snapshot };
117
+ }
118
+
119
+ /* ── the needs provider (lib/needs-providers.js) ─────────────────────────────────────────────────────────────────── */
120
+ const said = new Set(); // a row's id, logged once per process
121
+ function rowsFor(w, { lead } = {}) {
122
+ if (!lead || !w || !w.root) return [];
123
+ const today = todayOf();
124
+ const { lines, snapshot } = read(w.root, { today });
125
+ if (!snapshot) return [];
126
+ const rows = rowsOf(w.id, { today, snapshot, lines });
127
+ for (const r of rows) { if (said.has(r.run_id)) continue; said.add(r.run_id); console.info(`${TAG} ${r.initiative_id}: ${r.question}`); }
128
+ return rows;
129
+ }
130
+ // the date is in the signature: a move leaves the 7-day window at midnight with no change to a ledger
131
+ function sig(w) {
132
+ if (!w || !w.root) return '';
133
+ const files = [];
134
+ try { const s = require('./task-store.js').storeFor(w.root); if (s) files.push(s.file); } catch { /* none */ }
135
+ try { files.push(require('./plan-ledgers.js').ledgerPath(w.root, 'plan-items')); } catch { /* none */ }
136
+ const d = stateDirOf(w.root);
137
+ if (d) { files.push(path.join(d, 'boards.jsonl')); files.push(TL.ledgerFile(d)); }
138
+ return files.map((f) => { try { const st = fs.statSync(f); return st.size + ':' + st.mtimeMs; } catch { return '-'; } }).join('|') + '@' + todayOf();
139
+ }
140
+
141
+ /** The health number: the rows the provider raises for `root` in the window. */
142
+ function count(root, { days = DAYS, today = todayOf() } = {}) {
143
+ const { lines, snapshot } = read(root, { today, days });
144
+ return snapshot ? rowsOf('count', { today, snapshot, lines, days }).length : 0;
145
+ }
146
+
147
+ /** `node lib/critical-needs.js count <root> [--days N]`: the health number on the last line. → exit code */
148
+ function cli(argv, log = console.log) {
149
+ const [cmd, rootArg, ...rest] = argv;
150
+ if (cmd !== 'count') { log('usage: node lib/critical-needs.js count <root> [--days N]'); return 2; }
151
+ const root = path.resolve(rootArg || '.');
152
+ const i = rest.indexOf('--days');
153
+ const days = i >= 0 ? Math.max(1, parseInt(rest[i + 1], 10) || DAYS) : DAYS;
154
+ const n = count(root, { days });
155
+ log(`${TAG} ${n} critical-path date moves raised a Today row in the last ${days} days`);
156
+ log(String(n));
157
+ return 0;
158
+ }
159
+
160
+ module.exports = { kinds: [KIND], rowsFor, sig, NAME, KIND, TAG, DAYS, movesOf, rowsOf, linesOf, count, cli };
161
+
162
+ if (require.main === module) process.exitCode = cli(process.argv.slice(2));
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+ /* deps-cli.js — `pmos deps`: what the product's work waits on outside the team (Work › Dependencies). Initiative team-waits (bet A364);
3
+ * lib/team-waits.js is the store the page reads (GET /api/team-waits), so what the chat writes here shows on Work › Dependencies.
4
+ *
5
+ * pmos deps waits [--json] every open wait on another team, oldest first, with the day it started
6
+ * pmos deps wait --team "<team>" [--what "<what>"] [--ini <id>] [--since YYYY-MM-DD] [--who "<name>"] [--email <address>]
7
+ * [--key <JIRA-1>] [--sprint "<name>" --sprint-end YYYY-MM-DD]
8
+ * add one wait (from a Jira link: pass --key; one open wait per key)
9
+ * pmos deps done <wait id> the wait is over
10
+ * pmos deps undo <wait id> Undo of done: the wait is open again
11
+ * every command: [--root <dir>] (default: this repository)
12
+ *
13
+ * Waits that come from the initiative itself (a parked hold "waiting on <team>", or `waiting_on:` in its record) are listed too; change them
14
+ * with `pmos parked` or in the record. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
15
+ const path = require('path');
16
+ const fs = require('fs');
17
+ const TW = require('./team-waits.js');
18
+ const { todayOf } = require('./parked-reasons.js');
19
+
20
+ const COMMANDS = { deps: ['waits', 'wait', 'done', 'undo'] };
21
+ const USAGE = [
22
+ 'usage: pmos deps waits|wait|done|undo — what your work waits on outside the team (Work › Dependencies)',
23
+ ' pmos deps waits [--json] every open wait on another team, oldest first, with the day it started',
24
+ ' pmos deps wait --team "<team>" [--what "<what>"] [--ini <id>] [--since YYYY-MM-DD] [--who "<name>"] [--email <address>]',
25
+ ' [--key <JIRA-1>] [--sprint "<name>" --sprint-end YYYY-MM-DD]',
26
+ ' add a wait; from a Jira link pass --key (one open wait per key)',
27
+ ' pmos deps done <wait id> the wait is over',
28
+ ' pmos deps undo <wait id> the wait is open again',
29
+ 'Run it in the product\'s repository, or pass --root <dir>.',
30
+ ];
31
+ const ALLOWED = {
32
+ waits: ['json', 'root'],
33
+ wait: ['json', 'root', 'team', 'what', 'ini', 'since', 'who', 'email', 'key', 'sprint', 'sprint-end'],
34
+ done: ['json', 'root'], undo: ['json', 'root'],
35
+ };
36
+ const BOOL = new Set(['json']);
37
+
38
+ function parse(args) {
39
+ const pos = [], flags = {};
40
+ for (let i = 0; i < args.length; i++) {
41
+ const a = args[i];
42
+ if (!a.startsWith('--')) { pos.push(a); continue; }
43
+ const k = a.slice(2);
44
+ if (BOOL.has(k)) flags[k] = true;
45
+ else flags[k] = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
46
+ }
47
+ return { pos, flags };
48
+ }
49
+ function repoRoot(cwd) {
50
+ for (let d = path.resolve(cwd); ; d = path.dirname(d)) {
51
+ if (fs.existsSync(path.join(d, '.git'))) return d;
52
+ if (path.dirname(d) === d) return path.resolve(cwd);
53
+ }
54
+ }
55
+
56
+ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now(), isTTY } = {}) {
57
+ const args = argv[0] === 'deps' ? argv.slice(1) : argv.slice();
58
+ const sub = args[0];
59
+ if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
60
+ if (!COMMANDS.deps.includes(sub)) { say(`unknown deps command "${sub}". Use one of: ${COMMANDS.deps.join(', ')}`); return 2; }
61
+ const { pos, flags } = parse(args.slice(1));
62
+ for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos deps ${sub}`); return 2; }
63
+ const root = path.resolve(flags.root || repoRoot(cwd));
64
+ const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
65
+ const actor = () => require('./actor.js').fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env });
66
+
67
+ if (sub === 'waits') {
68
+ if (pos.length) return fail('pmos deps waits takes no argument', 2);
69
+ const today = todayOf(now);
70
+ const { file, waits } = TW.waitsOf(root, { today });
71
+ if (flags.json) { say(JSON.stringify({ ok: true, file, today, waits })); return 0; }
72
+ if (!waits.length) { say('Nothing waits on another team.'); return 0; }
73
+ const late = waits.filter((w) => w.days >= TW.LATE_DAYS).length;
74
+ say(`${waits.length} waiting on other teams${late ? ` · ${late} late` : ''}`);
75
+ for (const w of waits) {
76
+ say(` ${w.days >= TW.LATE_DAYS ? '▲' : '◷'} ${w.title || w.ini || '(no initiative)'} → ${w.team || w.what}${w.team && w.what ? ': ' + w.what : ''}`);
77
+ say(` since ${w.since} · ${w.days} ${w.days === 1 ? 'day' : 'days'}${w.who ? ' · ' + w.who : ''}${w.key ? ' · ' + w.key : ''}${w.sprint ? ' · ' + w.sprint : ''} · ${w.id}`);
78
+ }
79
+ return 0;
80
+ }
81
+
82
+ if (sub === 'wait') {
83
+ if (pos.length) return fail('usage: pmos deps wait --team "<team>" [--what "<what>"] [--ini <id>] …', 2);
84
+ const a = actor();
85
+ const r = TW.add(root, { ini: flags.ini, team: flags.team, what: flags.what, since: flags.since, who: flags.who, email: flags.email, key: flags.key,
86
+ sprint: flags.sprint, sprint_end: flags['sprint-end'] }, { now, by: a.by, via: a.via });
87
+ if (!r.ok) return fail(r.error);
88
+ if (flags.json) { say(JSON.stringify({ ok: true, id: r.id, line: r.line })); return 0; }
89
+ say(`${TW.TAG} ✓ ${r.id}: ${r.line.ini || '(no initiative)'} waits on ${r.line.team || r.line.what} since ${r.line.since}. Work › Dependencies shows it. Undo: pmos deps done ${r.id}`);
90
+ return 0;
91
+ }
92
+
93
+ if (pos.length !== 1) return fail(`usage: pmos deps ${sub} <wait id>`, 2);
94
+ const a = actor();
95
+ const r = (sub === 'done' ? TW.end : TW.back)(root, { id: pos[0] }, { now, by: a.by, via: a.via });
96
+ if (!r.ok) return fail(r.error);
97
+ if (flags.json) { say(JSON.stringify({ ok: true, line: r.line })); return 0; }
98
+ say(sub === 'done' ? `${TW.TAG} ✓ ${pos[0]} is over. Undo: pmos deps undo ${pos[0]}` : `${TW.TAG} ✓ ${pos[0]} is open again.`);
99
+ return 0;
100
+ }
101
+
102
+ module.exports = { run, COMMANDS, USAGE };
@@ -48,6 +48,9 @@
48
48
  * task-pin { task, pinned } the PM's pin on a milestone (feedback batch 13 item 4, XcalmA5Milestones):
49
49
  * true draws it on the Board timeline, false hides it, null goes back to the rule (only the initiative's last milestone).
50
50
  * `task` is a Board task, a breakdown item or a Jira key; the last line wins.
51
+ * task-time { task, start_time?, due_time? } an optional time of day on a task's start and due (task-time-optional):
52
+ * "HH:MM", 24-hour; '' clears one end; a line naming one end leaves the other. The day stays in start and due, untouched.
53
+ * `task` is a Board task or a breakdown item (Jira keeps its tickets' fields); the last line wins.
51
54
  * task-priority { task, priority } the PM's priority, set in the row (inline-sprint-priority):
52
55
  * 'P1', 'P2' or 'P3'; '' takes it out. `task` is a Board task or a breakdown item (Jira keeps its tickets' own); the last line wins.
53
56
  * task-order { initiative, section, tasks: [id] } the PM's order of the open tasks inside one stage of an
@@ -195,11 +198,14 @@ const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept
195
198
  'ini-delete', 'ini-restore',
196
199
  // a task's priority, set in the row (initiative inline-sprint-priority): P1, P2 or P3; '' takes it out
197
200
  'task-priority',
201
+ // an optional time of day on a task's start and due (initiative task-time-optional): "HH:MM"; '' clears one end
202
+ 'task-time',
198
203
  // a task's description (initiative task-descriptions): what it is, why, and when it is done; '' clears it
199
204
  'task-description',
200
205
  // a comment on a task (initiative task-detail-one-column): the task popup's Activity › Comments and `pmos task comment`
201
206
  'task-comment']);
202
207
  const COMMENT_MAX = 2000; // one comment on a task (task-comment)
208
+ const TIME_RE = /^([01]\d|2[0-3]):[0-5]\d$/; // a time of day on a task's start or due (task-time), 24-hour
203
209
  // A task's state is its only stage (Wawan, 2026-10-25): the same five every workflow ends in. An old 'In review' reads as In progress (taskState).
204
210
  const TASK_STATES = Object.freeze(['To do', 'In progress', 'Done', "Won't do", 'Archived']);
205
211
  const taskState = (s) => (s === 'In review' ? 'In progress' : TASK_STATES.includes(s) ? s : null);
@@ -235,6 +241,7 @@ function fold(events) {
235
241
  const pins = new Map(); // task id (or Jira key) → true | false: the PM's pin on a milestone; a null line takes it out (the rule again)
236
242
  const comments = new Map(); // task id → [{ text, by, at }]: its comments, oldest first (task-detail-one-column)
237
243
  const descriptions = new Map(); // task id → { text, by, at, sources }: the task's description (task-descriptions); the last line wins, '' clears
244
+ const times = new Map(); // task id → { start_time, due_time } "HH:MM" or '': the PM's optional times (task-time-optional); a task with neither is left out
238
245
  const priorities = new Map(); // task id → 'P1' | 'P2' | 'P3': the PM's priority (inline-sprint-priority); a '' line takes it out, the last line wins
239
246
  const removed = new Map(); // task id → the task a task-remove took out, so a task-restore (Delete's Undo) puts it back
240
247
  const ticketNotes = new Map(); // key(board, Jira key) → the PM's notes on that ticket (the last ticket-note line wins)
@@ -349,6 +356,10 @@ function fold(events) {
349
356
  comments.get(e.task).push({ text: e.text.slice(0, COMMENT_MAX), by: e.by || null, at: e.at || null });
350
357
  } else if (e.kind === 'task-priority' && typeof e.task === 'string' && e.task && typeof e.priority === 'string' && /^(P[1-3])?$/.test(e.priority)) {
351
358
  if (e.priority) priorities.set(e.task, e.priority); else priorities.delete(e.task);
359
+ } else if (e.kind === 'task-time' && typeof e.task === 'string' && e.task) {
360
+ const was = times.get(e.task) || { start_time: '', due_time: '' }, v = { ...was };
361
+ for (const k of ['start_time', 'due_time']) if (typeof e[k] === 'string' && (e[k] === '' || TIME_RE.test(e[k]))) v[k] = e[k];
362
+ if (v.start_time || v.due_time) times.set(e.task, v); else times.delete(e.task);
352
363
  } else if (e.kind === 'task-pin' && typeof e.task === 'string' && e.task && (typeof e.pinned === 'boolean' || e.pinned === null)) {
353
364
  if (e.pinned === null) pins.delete(e.task); else pins.set(e.task, e.pinned);
354
365
  } else if (e.kind === 'ticket-dates' && b && typeof e.ref === 'string' && JIRA_KEY_RE.test(e.ref)) {
@@ -430,7 +441,7 @@ function fold(events) {
430
441
  suggestNo.set(e.id, { kind: e.of === 'merge' ? 'merge' : 'split', fp: e.fp, at: e.at || null });
431
442
  }
432
443
  }
433
- return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, removed, sections, parents, orders, milestones, pins, priorities, descriptions, comments, ticketNotes, ticketDates, epics, archives, deleted, notDup, iniWf, ends, judged, autoOver, ticketMoves, backlogRank, smOps, smUndone, suggestNo, events: list };
444
+ return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, removed, sections, parents, orders, milestones, pins, priorities, times, descriptions, comments, ticketNotes, ticketDates, epics, archives, deleted, notDup, iniWf, ends, judged, autoOver, ticketMoves, backlogRank, smOps, smUndone, suggestNo, events: list };
434
445
  }
435
446
 
436
447
  /** The stages an initiative runs on a board: its own workflow when one is recorded, else the board's. */
@@ -933,6 +944,6 @@ module.exports = {
933
944
  CATEGORIES, WORKFLOW_TEMPLATES, TOOLS, SELF_LADDER, READING_CAT, STATUSES, ACTIVE, isActive, duplicatesOf, VIEWS, SORTS,
934
945
  templateWorkflow, isTemplateEdited, fold, readingOf, deriveStage, stageOf, catOf, moveWarnings, cardWarnings,
935
946
  applyWorkflowEdit, filterRows, health, counts, sprintsOf, backlogOf, key,
936
- INI_TEMPLATES, TASK_STATES, taskState, isBuildStage, templateBuilds, boardSettings, jiraProjectsOf, JIRA_KEY_RE, JIRA_PROJECT_RE, workflowOf, templateOf, applyIniWorkflow, taskOf, shiftDay,
947
+ INI_TEMPLATES, TASK_STATES, taskState, isBuildStage, templateBuilds, boardSettings, jiraProjectsOf, JIRA_KEY_RE, JIRA_PROJECT_RE, TIME_RE, workflowOf, templateOf, applyIniWorkflow, taskOf, shiftDay,
937
948
  ITEM_PROGRESS, itemStatus, taskItem, rollupItems, wouldCycle, COMMENT_MAX,
938
949
  };
@@ -32,6 +32,7 @@
32
32
  {"id": "initiative", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Make and order initiatives", "say": "Start an initiative and put it in Now, Next or Later on the roadmap.", "cmd": "/initiative", "verb": "initiative", "hint": "<title>"},
33
33
  {"id": "measure", "audience": "user", "status": "ga", "group": "Your product", "name": "Record a measured value", "say": "Write down a KR or health number with where it came from.", "cmd": "/measure", "verb": "measure", "hint": "<kr> <value>"},
34
34
  {"id": "today", "audience": "user", "status": "ga", "group": "Catch up", "name": "What needs you today", "say": "The asks that need you, in the order Today shows them.", "cmd": "/today", "verb": "today"},
35
+ {"id": "tradeoff", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Decide two close items", "say": "Two neighbours on the ranked list side by side; PMOS suggests an order and keeps your reason.", "cmd": "/tradeoff", "verb": "tradeoff", "hint": "list | show <a> <b>"},
35
36
  {"id": "pick", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Pick one thing for the time you have", "say": "Say how many minutes you have; PMOS picks the one ask that fits and unblocks the most.", "cmd": "/pick", "verb": "pick", "hint": "--minutes <n>"},
36
37
  {"id": "board", "audience": "user", "status": "ga", "group": "Catch up", "name": "Every initiative's items", "say": "The items of every initiative by column, or only yours.", "cmd": "/board", "verb": "board"},
37
38
  {"id": "report", "audience": "user", "status": "ga", "group": "Your product", "name": "Draft and issue a report", "say": "Draft a cadence report with every number filled in, then issue it.", "cmd": "/report", "verb": "report", "hint": "<cadence>"},
@@ -57,11 +58,13 @@
57
58
  {"id": "rules", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "Rules PMOS learned", "say": "The standing rules PMOS learned from your corrections, and edit or retire one.", "cmd": "/rules", "verb": "rules"},
58
59
  {"id": "line", "audience": "user", "status": "ga", "group": "Catch up", "name": "Where each initiative stands", "say": "Days in its stage, what is missing, the next move, and whether it is stuck.", "cmd": "/line", "verb": "line", "hint": "<initiative>"},
59
60
  {"id": "hire", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The next hire", "say": "The role your open work most needs, and a one-page role brief to edit.", "cmd": "/hire", "verb": "hire"},
61
+ {"id": "prototype", "audience": "user", "status": "ga", "group": "Before you ship", "name": "Simulated users try the prototype", "say": "Where simulated users, one per persona, got stuck on a prototype, and the personas that walk it.", "cmd": "/prototype", "verb": "prototype", "hint": "findings <initiative>"},
60
62
  {"id": "goals", "audience": "user", "status": "ga", "group": "Your product", "name": "Starter goals", "say": "Up to three goals drafted from your own product, each with its source; keep one and it becomes a goal.", "cmd": "/goals", "verb": "goals"},
61
63
  {"id": "approver", "audience": "user", "status": "ga", "group": "Before you ship", "name": "What an approver asks", "say": "What each approver asked or objected to before, ahead of the next sign-off.", "cmd": "/approver", "verb": "approver", "hint": "<name>"},
62
64
  {"id": "balance", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The mix of a list", "say": "Feature, fix, debt or discovery in one line, with a note when one kind is over your line.", "cmd": "/balance", "verb": "balance"},
63
65
  {"id": "declined", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Asks you declined", "say": "Asks closed without being done, each with a kind reply draft PMOS never sends.", "cmd": "/declined", "verb": "declined"},
64
66
  {"id": "sprint", "audience": "user", "status": "ga", "group": "Catch up", "name": "Sprint retro", "say": "A closed sprint's retro from its close numbers, and its one tracked change.", "cmd": "/sprint", "verb": "sprint"},
67
+ {"id": "deps", "audience": "user", "status": "beta", "group": "Catch up", "name": "Waiting on other teams", "say": "Each piece of your work that waits on another team, since when, with a Chase draft.", "cmd": "/deps", "verb": "deps"},
65
68
  {"id": "quiet", "audience": "user", "status": "ga", "group": "Catch up", "name": "Quiet initiatives", "say": "The weekly sweep of initiatives quiet 30 days or more: keep, park or close each.", "cmd": "/quiet", "verb": "quiet"},
66
69
  {"id": "units", "audience": "user", "status": "ga", "group": "Your product", "name": "Programs, products and projects", "say": "Who owns each initiative, and each owner's brief.", "cmd": "/units", "verb": "units"},
67
70
  {"id": "owner", "audience": "user", "status": "ga", "group": "Your product", "name": "An owner's brief", "say": "A unit owner's daily brief now.", "cmd": "/owner", "verb": "owner", "hint": "<unit>"},
@@ -42,6 +42,7 @@ const PROVIDERS = Object.freeze([
42
42
  'parked-reasons', // parked-reason-way-back (bet A446): a parked initiative whose way back is met, to bring back (kind 7)
43
43
  'product-health', // product-health-score: a product's health score fell 10 points or more against its past week (kind 8)
44
44
  'setup-station', // setup-station: a product that has not passed Setup (tracker read, agreed goal, owner), with the next ✦ (kind 7)
45
+ 'critical-needs', // critical-moved (bet A103): a task on an initiative's critical path moved its start or due date, with go-live (kind 7)
45
46
  ]);
46
47
  /** Kinds that already mean something in the needs queue. A provider may not reuse one. */
47
48
  const RESERVED_KINDS = Object.freeze(['question', 'accept', 'outcome', 'keep', 'evidence', 'plan-flag', 'provider-error']);
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+ /* page-one-answer.js — the one-call check of "every page opens with one answer" (initiative page-one-answer, job #1889, idea A308).
3
+ *
4
+ * Each page (Today, Work, Board, an initiative) counts the calls to act in its first view once per load (pm/page-one-answer.js
5
+ * firstViewCalls: a primary button or a [data-call] above the fold) and posts the count here. LOCAL ONLY: one line per page and day in
6
+ * <runtime>/page-calls.jsonl, the last count of the day wins. Nothing else reads it but `pmos pages calls`.
7
+ *
8
+ * record(dir, { page, calls, labels }, at) → { ok, wrote } | { ok: false, error }
9
+ * readLines(dir) → [{ at, page, calls, labels }]
10
+ * flagged(lines, { now, days }) PURE → [{ page, calls, labels, at }] pages whose last first view had more than ONE call
11
+ * handle(req, res, url, ctx) POST /api/page-calls { page, calls, labels } (the page's own press guard)
12
+ * run(argv, { say, runtimeDir, now }) `pmos pages calls [--days N] [--json] [--count]`
13
+ * No line here sends anything or calls a model. */
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+
17
+ const FILE = 'page-calls.jsonl';
18
+ const PAGES = ['today', 'work', 'board', 'initiative'];
19
+ const MAX_CALLS = 1;
20
+ const DAY = 864e5;
21
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
22
+
23
+ function readLines(dir) {
24
+ if (!dir) return [];
25
+ let txt = '';
26
+ try { txt = fs.readFileSync(path.join(dir, FILE), 'utf8'); } catch { return []; }
27
+ const out = [];
28
+ for (const l of txt.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (isObj(o) && PAGES.includes(o.page)) out.push(o); } catch { /* a torn line is skipped */ } }
29
+ return out;
30
+ }
31
+
32
+ function record(dir, { page, calls, labels } = {}, at = new Date().toISOString()) {
33
+ if (!dir) return { ok: false, error: 'This workspace has no runtime folder.' };
34
+ if (!PAGES.includes(page)) return { ok: false, error: 'page must be one of ' + PAGES.join(', ') };
35
+ const n = Number(calls);
36
+ if (!Number.isInteger(n) || n < 0 || n > 200) return { ok: false, error: 'calls must be a whole number from 0 to 200' };
37
+ const L = (Array.isArray(labels) ? labels : []).slice(0, 10).map((s) => String(s || '').replace(/\s+/g, ' ').slice(0, 60));
38
+ const day = String(at).slice(0, 10);
39
+ const same = readLines(dir).filter((x) => x.page === page && String(x.at).slice(0, 10) === day).pop();
40
+ if (same && same.calls === n && JSON.stringify(same.labels || []) === JSON.stringify(L)) return { ok: true, wrote: false };
41
+ fs.mkdirSync(dir, { recursive: true });
42
+ fs.appendFileSync(path.join(dir, FILE), JSON.stringify({ at, page, calls: n, labels: L }) + '\n');
43
+ return { ok: true, wrote: true };
44
+ }
45
+
46
+ /** PURE. The last line of each page in the window; a page is flagged when that line counted more than one call. */
47
+ function flagged(lines, { now = Date.now(), days = 7 } = {}) {
48
+ const from = now - days * DAY, last = new Map();
49
+ for (const x of lines || []) { const t = Date.parse(x.at); if (!(t >= from)) continue; const p = last.get(x.page); if (!p || Date.parse(p.at) <= t) last.set(x.page, x); }
50
+ return [...last.values()].filter((x) => x.calls > MAX_CALLS).sort((a, b) => b.calls - a.calls || a.page.localeCompare(b.page))
51
+ .map((x) => ({ page: x.page, calls: x.calls, labels: x.labels || [], at: x.at }));
52
+ }
53
+
54
+ async function handle(req, res, url, ctx) {
55
+ const send = (status, body) => { ctx.json(res, body, status); return true; };
56
+ if (url.pathname !== '/api/page-calls') return false;
57
+ if (req.method !== 'POST') return send(405, { ok: false, error: 'POST only' });
58
+ if (req.headers && req.headers['x-pmos-session']) return send(403, { ok: false, error: 'An agent session does not open pages. Only the PM\'s own first views are counted.' });
59
+ const read = await ctx.readJson(req);
60
+ if (!read.ok) return send(400, { ok: false, error: 'the body is not JSON' });
61
+ const body = read.body || {};
62
+ const g = require('./pm-guard.js').requirePagePress(req, body);
63
+ if (!g.ok) return send(g.status, { ok: false, error: g.error });
64
+ const r = record(ctx.runtimeDir || null, body, new Date().toISOString());
65
+ if (r.ok && r.wrote) console.info(`[page-one-answer] recorded page=${body.page} calls=${body.calls}`);
66
+ return r.ok ? send(200, { ok: true, wrote: r.wrote }) : send(400, { ok: false, error: r.error });
67
+ }
68
+
69
+ function run(argv, { say = (s) => console.log(s), runtimeDir = null, now = Date.now() } = {}) {
70
+ const a = argv.slice(argv[0] === 'pages' ? 1 : 0).filter((x) => x !== 'calls');
71
+ const flag = (k) => a.includes('--' + k);
72
+ const di = a.indexOf('--days'), days = di >= 0 ? Number(a[di + 1]) : 7;
73
+ if (!(days > 0 && days <= 90)) { say('✗ --days takes a number from 1 to 90'); return 2; }
74
+ let dir = runtimeDir;
75
+ if (!dir) { try { dir = require('./state-root.js').defaultRoot(); } catch { dir = null; } }
76
+ const lines = readLines(dir), F = flagged(lines, { now, days });
77
+ if (flag('json')) { say(JSON.stringify({ days, pages: F }, null, 2)); return 0; }
78
+ if (flag('count')) { say(String(F.length)); return 0; }
79
+ if (!lines.length) { say('No page has counted its first view yet. Open Today, Work, Board or an initiative and run this again.'); return 0; }
80
+ if (!F.length) { say(`Every page counted in the last ${days} days opens with one call to act or none.`); return 0; }
81
+ for (const x of F) say(`● ${x.page}: ${x.calls} calls to act in the first view (${x.labels.filter(Boolean).join(', ') || 'no labels'}), ${String(x.at).slice(0, 10)}`);
82
+ say('A first view should hold one call to act at most. Fold the others under the answer.');
83
+ return 0;
84
+ }
85
+
86
+ module.exports = { FILE, PAGES, MAX_CALLS, record, readLines, flagged, handle, prefixes: ['/api/page-calls'], run };
@@ -4,13 +4,14 @@
4
4
  *
5
5
  * pmos pages [show] [--ref <ref>] [--json] [--count]
6
6
  * pmos pages check --base <ref> [--ref <ref>|WORKTREE] [--feature] [--gate] [--json]
7
+ * pmos pages calls [--days N] [--json] [--count] (lib/page-one-answer.js: the pages whose first view had more than one call to act)
7
8
  * It reads git only and writes nothing. Exit codes: 0 done, 1 refused (or a finding with --gate), 2 usage.
8
9
  */
9
10
  const path = require('path');
10
11
  const H = require('./page-health.js');
11
12
  const D = require('./design-drift.js');
12
13
 
13
- const COMMANDS = { pages: ['show', 'check'] };
14
+ const COMMANDS = { pages: ['show', 'check', 'calls'] };
14
15
  const USAGE = [
15
16
  'usage: pmos pages — each page\'s fixes, reverts and restores in the last days, so a page that keeps breaking is fixed before it gets new features',
16
17
  ' pmos pages [show] [--ref <ref>] [--json] [--count]',
@@ -19,7 +20,9 @@ const USAGE = [
19
20
  ' --base <ref> the commit the change starts from (for example origin/main)',
20
21
  ' --feature treat the change as a feature even without a feat commit',
21
22
  ' --gate exit 1 when a feature change touches a page over the limit',
22
- 'It reads git only. A product sets window_days and limit in page-health.json in its design-system folder; its pages come from design-drift.json.',
23
+ ' pmos pages calls [--days N] [--json] [--count]',
24
+ ' names each page (Today, Work, Board, an initiative) whose first view had more than one call to act, from this computer\'s record',
25
+ 'show and check read git only. A product sets window_days and limit in page-health.json in its design-system folder; its pages come from design-drift.json.',
23
26
  ];
24
27
  const FLAGS = { show: ['ref', 'json', 'count', 'repo'], check: ['base', 'ref', 'feature', 'gate', 'json', 'repo'] };
25
28
  const BOOL = new Set(['json', 'count', 'feature', 'gate']);
@@ -43,6 +46,7 @@ function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Dat
43
46
  if (['help', '--help', '-h'].includes(args[0])) { for (const l of USAGE) say(l); return 0; }
44
47
  const sub = args[0] && !args[0].startsWith('--') ? args[0] : 'show';
45
48
  if (args[0] === sub) args = args.slice(1);
49
+ if (sub === 'calls') return require('./page-one-answer.js').run(['calls', ...args], { say, now }); // page-one-answer (A308)
46
50
  if (!COMMANDS.pages.includes(sub)) { say(`unknown pages command "${sub}". Use one of: ${COMMANDS.pages.join(', ')}`); return 2; }
47
51
  const { pos, flags } = parse(args);
48
52
  if (pos.length) { say(`✗ pmos pages ${sub} takes no argument`); return 2; }
@@ -157,12 +157,17 @@ const VERBS = Object.freeze({
157
157
  // Not a pm-os-absorb verb (run: null): initiative three-line-why (bet A86) added it through the same table.
158
158
  why: Object.freeze({ module: 'why-cli.js', run: null, guide: 'cli.md',
159
159
  help: 'pmos why <initiative or task> | coverage — why the work exists in three lines: goal, problem, evidence, read from its records (pmos why help)' }),
160
+ // Not a pm-os-absorb verb (run: null): initiative tradeoff-cards (job #1918, A325) added it through the same table.
161
+ tradeoff: Object.freeze({ module: 'tradeoff-cli.js', run: null, guide: 'cli.md',
162
+ help: 'pmos tradeoff [list|show|keep|undo|count] — two close items on the Roadmap side by side, and the reason you kept one first (pmos tradeoff help)' }),
160
163
  // Not a pm-os-absorb verb (run: null): initiative next-hire-draft (job #1876, A75) added it through the same table.
161
164
  // Not a pm-os-absorb verb (run: null): initiative starter-goals (job #1916, A84) added it through the same table.
162
165
  goals: Object.freeze({ module: 'goals-cli.js', run: null, guide: 'cli.md',
163
166
  help: 'pmos goals [starter|draft|keep <n>|drop <n>|undo] — starter goals PMOS drafts from your own product, each with its source; keep one and it becomes a goal (pmos goals help)' }),
164
167
  hire: Object.freeze({ module: 'hire-draft.js', run: null, guide: 'cli.md',
165
168
  help: 'pmos hire [draft|show|count] — the role your open work most needs, per person, and a one-page role brief PMOS drafts for you to edit (pmos hire help)' }),
169
+ prototype: Object.freeze({ module: 'prototype-cli.js', run: null, guide: 'cli.md',
170
+ help: 'pmos prototype findings|personas|persona … — where simulated users (one per persona) got stuck on a prototype, never a score, and the personas that walk it (pmos prototype help)' }),
166
171
  // Not a pm-os-absorb verb (run: null): initiative connector-data (job #1920, A150) added it through the same table.
167
172
  connectors: Object.freeze({ module: 'connectors-cli.js', run: null, guide: 'cli.md',
168
173
  help: 'pmos connectors data [<connector>] — what PMOS reads and writes through each connector, and what leaves this computer (pmos connectors help)' }),
@@ -202,6 +207,9 @@ const VERBS = Object.freeze({
202
207
  // Not a pm-os-absorb verb (run: null): initiative parked-reason-way-back (bet A446) added it through the same table.
203
208
  parked: Object.freeze({ module: 'parked-cli.js', run: null, guide: 'cli.md',
204
209
  help: 'pmos parked list|hold|back|coverage — parked initiatives: why each is parked, what brings it back, and bringing it back (pmos parked help)' }),
210
+ // Not a pm-os-absorb verb (run: null): initiative team-waits (bet A364) added it through the same table.
211
+ deps: Object.freeze({ module: 'deps-cli.js', run: null, guide: 'cli.md',
212
+ help: 'pmos deps waits|wait|done|undo — what your work waits on outside the team, oldest first (Work › Dependencies; pmos deps help)' }),
205
213
  // Not a pm-os-absorb verb (run: null): initiative quiet-work-sweep (bet A503) added it through the same table.
206
214
  quiet: Object.freeze({ module: 'quiet-cli.js', run: null, guide: 'cli.md',
207
215
  help: 'pmos quiet list|keep|park|close|undo — the weekly sweep of initiatives quiet 30 days or more: keep, park or close each (pmos quiet help)' }),
@@ -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 };