create-pmos 0.741.0 → 0.744.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 (38) hide show
  1. package/package.json +266 -66
  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/briefing-premium-board-test.js +3 -2
  7. package/workspace/briefing-premium-insights-test.js +1 -1
  8. package/workspace/changelog.json +265 -27
  9. package/workspace/guide/cli.md +28 -0
  10. package/workspace/guide/layout.md +3 -3
  11. package/workspace/lib/briefing-premium-agent.js +8 -2
  12. package/workspace/lib/decision-journal.js +107 -6
  13. package/workspace/lib/decisions-cli.js +24 -8
  14. package/workspace/lib/driver-decide.js +18 -1
  15. package/workspace/lib/parked-reasons.js +4 -1
  16. package/workspace/lib/pmos-verbs.js +6 -0
  17. package/workspace/lib/route-modules.js +1 -0
  18. package/workspace/lib/routes-proposals.js +23 -4
  19. package/workspace/lib/routes-try.js +39 -0
  20. package/workspace/lib/signal-cli.js +41 -0
  21. package/workspace/lib/try-it.js +194 -0
  22. package/workspace/package-lock.json +2 -2
  23. package/workspace/package.json +1 -1
  24. package/workspace/public/pm/cozy-board.css +2 -0
  25. package/workspace/public/pm/cozy-ev.css +8 -0
  26. package/workspace/public/pm/cozy-settings.js +12 -2
  27. package/workspace/public/pm/home-app.js +6 -1
  28. package/workspace/public/pm/library-keys.js +41 -0
  29. package/workspace/public/pm/live-edit.js +1 -1
  30. package/workspace/public/pm/page-chat.js +21 -1
  31. package/workspace/public/pm/premium-board.js +23 -1
  32. package/workspace/public/pm/premium-library.js +5 -12
  33. package/workspace/public/pm/try-view.js +99 -0
  34. package/workspace/public/premium-board.html +2 -0
  35. package/workspace/server.js +2 -0
  36. package/workspace/test-lists/decisions-from-approvals.json +5 -0
  37. package/workspace/test-lists/try-what-shipped.json +9 -0
  38. package/workspace/test-lists/work-ask-chat.json +9 -0
@@ -23,6 +23,18 @@
23
23
  * onTime, due, open, reversals: [{ id, decided, replacedBy, why }] }
24
24
  * checkDate(text, today) → 'YYYY-MM-DD' | null a date, or +N d / w / m from today
25
25
  *
26
+ * LOGGED FROM A PRESS (initiative decisions-from-approvals, bet A475). The PM's ✓ on a ✦ proposal, a picked card, a ✕ or a Drop with a
27
+ * reason, the Keep of an agent proposal and a hold with a reason each write one decision line by themselves, with `from` (approval, card,
28
+ * drop, park) and `ref` (the press it came from). Such a line has no check date unless it names an expected outcome, so it never makes a
29
+ * Today card by itself; it folds with state `logged`. The Undo of the press undoes the line; so does `pmos decisions undo <id>`.
30
+ * logFrom(root, { from, decided, ref, initiative?, why?, expected? }, { now, by, via }) → { ok, id, line?, existed? } | { ok: false, error }
31
+ * the same ref (not undone) is written once. Never throws
32
+ * undo(root, { id } | { ref }, { now, by, via }) → { ok, id, line } | { ok: false, error } one `undo` line; the fold leaves it out
33
+ * onLifecycle(root, rec, { now }) → result | null a lifecycle line the PM wrote: on-hold with a reason logs a park; active with reason
34
+ * `undo` (the hold's Undo) undoes the latest park line of that initiative
35
+ * loggedCount(rows, { days, now }) → number lines from presses in the last `days` days, not undone (the health number)
36
+ * CLI: node lib/decision-journal.js logged <root> [--days 7] prints `[decision-log] …` and the count alone on the last line
37
+ *
26
38
  * A verdict is the PM's: PMOS never records one from a metric alone, and every verdict carries evidence. Nothing here sends anything.
27
39
  */
28
40
  const fs = require('fs');
@@ -82,11 +94,12 @@ function checkDate(text, today) {
82
94
 
83
95
  function fold(rows, { today = todayOf() } = {}) {
84
96
  const by = new Map();
97
+ const undone = undoneOf(rows);
85
98
  for (const r of rows || []) {
86
- if (!r || r.type !== 'decision' || typeof r.id !== 'string' || by.has(r.id)) continue;
99
+ if (!r || r.type !== 'decision' || typeof r.id !== 'string' || by.has(r.id) || undone.has(r.id)) continue;
87
100
  by.set(r.id, { id: r.id, date: r.date || String(r.at || '').slice(0, 10), decided: r.decided || '', expected: r.expected || '', check: r.check || '',
88
101
  why: r.why || '', against: r.against || '', initiative: r.initiative || '', replaces: r.replaces || '', changed_mind: r.changed_mind || '',
89
- replacedBy: '', replacedWhy: '', replacedAt: '', checks: [], verdict: null, dueAt: '', at: r.at || '', by: r.by || '' });
102
+ replacedBy: '', replacedWhy: '', replacedAt: '', checks: [], verdict: null, dueAt: '', at: r.at || '', by: r.by || '', from: r.from || '', ref: r.ref || '' });
90
103
  }
91
104
  for (const r of rows || []) {
92
105
  if (!r || r.type !== 'check') continue;
@@ -103,17 +116,17 @@ function fold(rows, { today = todayOf() } = {}) {
103
116
  }
104
117
  const out = [...by.values()];
105
118
  for (const e of out) {
106
- e.state = e.verdict ? 'checked' : e.replacedBy ? 'replaced' : isDate(e.check) && e.check <= today ? 'due' : 'open';
119
+ e.state = e.verdict ? 'checked' : e.replacedBy ? 'replaced' : !isDate(e.check) ? 'logged' : e.check <= today ? 'due' : 'open';
107
120
  e.days = isDate(e.check) && isDate(today) ? daysBetween(e.check, today) : 0; // > 0: days past the check date
108
121
  }
109
122
  return out;
110
123
  }
111
124
 
112
- const ORDER = { due: 0, open: 1, checked: 2, replaced: 3 };
125
+ const ORDER = { due: 0, open: 1, logged: 2, checked: 3, replaced: 4 };
113
126
  /** Due checks first (oldest first), then open ones by check date, then the closed ones, newest first. */
114
127
  function sorted(entries) {
115
128
  return entries.slice().sort((a, b) => ORDER[a.state] - ORDER[b.state]
116
- || (a.state === 'due' || a.state === 'open' ? a.check.localeCompare(b.check) : String(b.verdict ? b.verdict.date : b.replacedAt).localeCompare(String(a.verdict ? a.verdict.date : a.replacedAt)))
129
+ || (a.state === 'due' || a.state === 'open' ? a.check.localeCompare(b.check) : a.state === 'logged' ? String(b.at).localeCompare(String(a.at)) : String(b.verdict ? b.verdict.date : b.replacedAt).localeCompare(String(a.verdict ? a.verdict.date : a.replacedAt)))
117
130
  || a.id.localeCompare(b.id));
118
131
  }
119
132
 
@@ -185,6 +198,83 @@ function check(root, { id, verdict, evidence, again } = {}, { now = Date.now(),
185
198
  return { ok: true, line, file: rel(root, J.file) };
186
199
  }
187
200
 
201
+ /* ── logged from a press (decisions-from-approvals) ── */
202
+ const FROM = Object.freeze(['approval', 'card', 'drop', 'park']);
203
+ const TAG = '[decision-log]';
204
+
205
+ /** The ids an `undo` line took out. */
206
+ function undoneOf(rows) {
207
+ const out = new Set();
208
+ for (const r of rows || []) if (r && r.type === 'undo' && typeof r.id === 'string') out.add(r.id);
209
+ return out;
210
+ }
211
+
212
+ function logFrom(root, f = {}, { now = Date.now(), by, via } = {}) {
213
+ try {
214
+ root = path.resolve(root);
215
+ const from = String(f.from || '');
216
+ if (!FROM.includes(from)) return { ok: false, error: `from is one of ${FROM.join(', ')}` };
217
+ const decided = one(f.decided).slice(0, MAX.decided), ref = one(f.ref).slice(0, 160);
218
+ if (decided.length < 3) return { ok: false, error: 'say what was decided' };
219
+ if (!ref) return { ok: false, error: 'ref names the press the decision came from' };
220
+ const initiative = one(f.initiative), why = one(f.why).slice(0, MAX.why), expected = one(f.expected).slice(0, MAX.expected);
221
+ const today = todayOf(now);
222
+ const J = read(root);
223
+ const undone = undoneOf(J.rows);
224
+ const had = J.rows.find((r) => r && r.type === 'decision' && r.ref === ref && !undone.has(r.id));
225
+ if (had) return { ok: true, id: had.id, existed: true };
226
+ const base = today.replace(/-/g, '') + '-' + slugOf(decided);
227
+ const have = new Set(J.rows.filter((r) => r && r.type === 'decision').map((r) => r.id));
228
+ let id = base, n = 2;
229
+ while (have.has(id)) id = base + '-' + n++;
230
+ const line = { type: 'decision', id, date: today, decided, expected, check: expected.length >= 8 ? addDays(today, DEFAULT_DAYS) : '', from, ref,
231
+ ...(initiative && ID_RE.test(initiative) ? { initiative } : {}), ...(why ? { why } : {}), at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'ui' };
232
+ append(J.file, line);
233
+ console.log(`${TAG} logged ${id} from=${from} ref=${ref}`);
234
+ return { ok: true, id, line, file: rel(root, J.file) };
235
+ } catch (e) { return { ok: false, error: 'the decision journal could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
236
+ }
237
+
238
+ function undo(root, { id, ref } = {}, { now = Date.now(), by, via } = {}) {
239
+ try {
240
+ root = path.resolve(root);
241
+ const J = read(root);
242
+ const undone = undoneOf(J.rows);
243
+ const all = J.rows.filter((r) => r && r.type === 'decision' && (id ? r.id === id : ref && r.ref === ref));
244
+ if (!all.length) return { ok: false, error: id ? `no decision ${id} in this journal (pmos decisions list shows the ids)` : 'no decision came from that press' };
245
+ const live = all.filter((r) => !undone.has(r.id)).pop();
246
+ if (!live) return { ok: false, error: `${all[all.length - 1].id} was already undone` };
247
+ const line = { type: 'undo', id: live.id, at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'ui' };
248
+ append(J.file, line);
249
+ console.log(`${TAG} undone ${live.id}`);
250
+ return { ok: true, id: live.id, line, file: rel(root, J.file) };
251
+ } catch (e) { return { ok: false, error: 'the decision journal could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
252
+ }
253
+
254
+ /** A lifecycle line the PM wrote (server.js /api/lifecycle). Never throws. */
255
+ function onLifecycle(root, rec, { now = Date.now() } = {}) {
256
+ if (!rec || typeof rec.initiative_id !== 'string') return null;
257
+ const who = { now, by: rec.by, via: rec.via };
258
+ const reason = one(rec.reason);
259
+ if (rec.state === 'on-hold' && reason) {
260
+ return logFrom(root, { from: 'park', decided: `Park ${rec.initiative_id}: ${reason}`, ref: `park:${rec.initiative_id}:${rec.at || new Date(now).toISOString()}`,
261
+ initiative: rec.initiative_id, why: reason + (rec.back ? ` (back on ${rec.back})` : '') }, who);
262
+ }
263
+ if (rec.state === 'active' && reason.toLowerCase() === 'undo') {
264
+ let J; try { J = read(root); } catch { return null; }
265
+ const undone = undoneOf(J.rows);
266
+ const last = J.rows.filter((r) => r && r.type === 'decision' && r.from === 'park' && r.initiative === rec.initiative_id && !undone.has(r.id)).pop();
267
+ return last ? undo(root, { id: last.id }, who) : null;
268
+ }
269
+ return null;
270
+ }
271
+
272
+ /** Lines written from presses in the last `days` days and not undone. */
273
+ function loggedCount(rows, { days = 7, now = Date.now() } = {}) {
274
+ const undone = undoneOf(rows), since = now - days * DAY;
275
+ return (rows || []).filter((r) => r && r.type === 'decision' && FROM.includes(r.from) && !undone.has(r.id) && Date.parse(r.at) >= since && Date.parse(r.at) <= now).length;
276
+ }
277
+
188
278
  const rate = (w, d) => (w + d ? Math.round((100 * w) / (w + d)) : null);
189
279
 
190
280
  /** The track record: how the user's calls turned out, per quarter of the date each check answered. */
@@ -235,4 +325,15 @@ function stamp(root) {
235
325
  return out.join('|');
236
326
  }
237
327
 
238
- module.exports = { FILE, VERDICTS, VERDICT_WORDS, DEFAULT_DAYS, ON_TIME_DAYS, read, fold: foldWithFirst, sorted, add, check, record, entriesOf, checkDate, quarterOf, todayOf, stamp, filesOf };
328
+ module.exports = { FILE, VERDICTS, VERDICT_WORDS, DEFAULT_DAYS, ON_TIME_DAYS, FROM, TAG, read, fold: foldWithFirst, sorted, add, check, record, entriesOf, checkDate, quarterOf, todayOf, stamp, filesOf,
329
+ logFrom, undo, onLifecycle, loggedCount };
330
+
331
+ if (require.main === module) {
332
+ const a = process.argv.slice(2);
333
+ if (a[0] !== 'logged') { console.error('usage: node lib/decision-journal.js logged <root> [--days 7]'); process.exit(2); }
334
+ const root = path.resolve(a[1] && !a[1].startsWith('--') ? a[1] : '.');
335
+ const i = a.indexOf('--days'), days = i > 0 ? Math.max(1, +a[i + 1] || 7) : 7;
336
+ const n = loggedCount(read(root).rows, { days });
337
+ console.log(`${TAG} ${n} decision ${n === 1 ? 'line was' : 'lines were'} logged from presses in the last ${days} days and not undone`);
338
+ console.log(String(n));
339
+ }
@@ -9,6 +9,7 @@
9
9
  * pmos decisions check <id> <worked|didnt-work|cant-tell> --evidence "<text>" [--again <date>]
10
10
  * the verdict on a decision; cant-tell --again sets a new date to look again
11
11
  * pmos decisions record [--json] the track record: per quarter, worked, didn't work, can't tell and the hit rate
12
+ * pmos decisions undo <id> [--json] takes a decision out of the journal (one `undo` line), e.g. one logged from a press
12
13
  * every command: [--root <dir>] (default: this repository)
13
14
  *
14
15
  * The agent runs add and check only after the PM said yes in the chat; the line names who wrote it (lib/actor.js). A verdict is the PM's:
@@ -18,7 +19,7 @@ const path = require('path');
18
19
  const { execFileSync } = require('child_process');
19
20
  const J = require('./decision-journal.js');
20
21
 
21
- const COMMANDS = { decisions: ['add', 'list', 'show', 'check', 'record'] };
22
+ const COMMANDS = { decisions: ['add', 'list', 'show', 'check', 'record', 'undo'] };
22
23
  const USAGE = [
23
24
  'usage: pmos decisions add|list|show|check|record — a decision journal: each decision has an expected outcome and a date to check it',
24
25
  ' pmos decisions add "<what was decided>" --expect "<what should happen>" [--check <YYYY-MM-DD|+30d>] [--why "<text>"] [--against "<who disagreed, and why>"] [--initiative <id>]',
@@ -27,10 +28,11 @@ const USAGE = [
27
28
  ' pmos decisions show <id> [--json] one decision and its checks',
28
29
  ' pmos decisions check <id> <worked|didnt-work|cant-tell> --evidence "<text>" [--again <date>] your verdict on a decision',
29
30
  ' pmos decisions record [--json] how your decisions turned out, per quarter',
31
+ ' pmos decisions undo <id> [--json] take a decision out of the journal, for example one logged from a press',
30
32
  'Run it in the product\'s repository, or pass --root <dir>. The check date is 30 days after the decision unless --check says otherwise.',
31
33
  ];
32
34
  const VERDICT = { worked: 'worked', validated: 'worked', 'didnt-work': 'didnt-work', "didn't-work": 'didnt-work', refuted: 'didnt-work', 'cant-tell': 'cant-tell', "can't-tell": 'cant-tell', inconclusive: 'cant-tell' };
33
- const ALLOWED = { add: ['json', 'root', 'expect', 'check', 'why', 'against', 'initiative', 'replaces', 'changed-mind'], list: ['json', 'root', 'all'], show: ['json', 'root'], check: ['json', 'root', 'evidence', 'again'], record: ['json', 'root'] };
35
+ const ALLOWED = { add: ['json', 'root', 'expect', 'check', 'why', 'against', 'initiative', 'replaces', 'changed-mind'], list: ['json', 'root', 'all'], show: ['json', 'root'], check: ['json', 'root', 'evidence', 'again'], record: ['json', 'root'], undo: ['json', 'root'] };
34
36
  const BOOL = new Set(['json', 'all']);
35
37
 
36
38
  function parse(args) {
@@ -56,10 +58,12 @@ function line(e) {
56
58
  const when = e.state === 'due' ? `check due ${e.days > 0 ? 'since ' + short(e.check) : 'today'}`
57
59
  : e.state === 'open' ? `check on ${short(e.check)}`
58
60
  : e.state === 'checked' ? `${J.VERDICT_WORDS[e.verdict.verdict]} (${short(e.verdict.date)})`
61
+ : e.state === 'logged' ? `${FROM_WORDS[e.from] || 'logged'} on ${short(e.date)}`
59
62
  : `reversed by ${e.replacedBy}`;
60
- return ` ${e.id} — ${e.decided}\n expected: ${e.expected} · ${when}`;
63
+ return ` ${e.id} — ${e.decided}\n ${e.expected ? 'expected: ' + e.expected + ' · ' : ''}${when}`;
61
64
  }
62
- const pub = (e) => ({ id: e.id, state: e.state, date: e.date, decided: e.decided, expected: e.expected, check: e.check, why: e.why || null, against: e.against || null,
65
+ const FROM_WORDS = { approval: 'approved', card: 'picked on a card', drop: 'dropped with a reason', park: 'parked with a reason' };
66
+ const pub = (e) => ({ id: e.id, state: e.state, from: e.from || null, ref: e.ref || null, date: e.date, decided: e.decided, expected: e.expected, check: e.check, why: e.why || null, against: e.against || null,
63
67
  initiative: e.initiative || null, replaces: e.replaces || null, changed_mind: e.changed_mind || null, replaced_by: e.replacedBy || null, replaced_why: e.replacedWhy || null,
64
68
  verdict: e.verdict ? { verdict: e.verdict.verdict, evidence: e.verdict.evidence, date: e.verdict.date } : null,
65
69
  checks: e.checks.map((c) => ({ verdict: c.verdict, evidence: c.evidence, date: c.date, ...(c.again ? { again: c.again } : {}) })), days_past: e.state === 'due' ? e.days : 0 });
@@ -88,17 +92,29 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
88
92
  return 0;
89
93
  }
90
94
 
95
+ if (sub === 'undo') {
96
+ if (pos.length !== 1) return fail('usage: pmos decisions undo <id>', 2);
97
+ const a = actor();
98
+ const r = J.undo(root, { id: pos[0] }, { now, by: a.by, via: a.via });
99
+ if (!r.ok) return fail(r.error);
100
+ if (flags.json) { say(JSON.stringify({ ok: true, id: r.id, file: r.file })); return 0; }
101
+ say(`✓ ${r.id} is out of the journal (${r.file}). Commit it to keep it.`);
102
+ return 0;
103
+ }
104
+
91
105
  const { entries, file } = J.entriesOf(root, { today });
92
106
 
93
107
  if (sub === 'list') {
94
108
  if (pos.length) return fail('pmos decisions list takes no argument', 2);
95
- const shown = flags.all ? entries : entries.filter((e) => e.state === 'due' || e.state === 'open');
109
+ const shown = flags.all ? entries : entries.filter((e) => e.state === 'due' || e.state === 'open' || e.state === 'logged');
96
110
  if (flags.json) { say(JSON.stringify({ ok: true, file, total: entries.length, decisions: shown.map(pub) })); return 0; }
97
111
  if (!entries.length) { say('No decisions in this journal yet. Add one: pmos decisions add "<what was decided>" --expect "<what should happen>"'); return 0; }
98
- const due = shown.filter((e) => e.state === 'due'), open = shown.filter((e) => e.state === 'open'), rest = shown.filter((e) => e.state === 'checked' || e.state === 'replaced');
99
- say(`${plural(entries.length, 'decision', 'decisions')} · ${due.length} due · ${open.length} open · ${entries.length - due.length - open.length} closed`);
112
+ const due = shown.filter((e) => e.state === 'due'), open = shown.filter((e) => e.state === 'open'), logged = shown.filter((e) => e.state === 'logged'), rest = shown.filter((e) => e.state === 'checked' || e.state === 'replaced');
113
+ const nLogged = entries.filter((e) => e.state === 'logged').length;
114
+ say(`${plural(entries.length, 'decision', 'decisions')} · ${due.length} due · ${open.length} open${nLogged ? ` · ${nLogged} logged` : ''} · ${entries.length - due.length - open.length - nLogged} closed`);
100
115
  if (due.length) say(`\n${plural(due.length, 'check', 'checks')} due:\n` + due.map(line).join('\n'));
101
116
  if (open.length) say('\nOpen:\n' + open.map(line).join('\n'));
117
+ if (logged.length) say('\nLogged from your presses:\n' + logged.map(line).join('\n') + '\n Undo one: pmos decisions undo <id>');
102
118
  if (rest.length) say('\nClosed:\n' + rest.map(line).join('\n'));
103
119
  if (due.length) say('\nRecord a verdict: pmos decisions check <id> worked|didnt-work|cant-tell --evidence "<what shows it>"');
104
120
  return 0;
@@ -109,7 +125,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
109
125
  const e = entries.find((x) => x.id === pos[0]);
110
126
  if (!e) return fail(`no decision ${pos[0]} in this journal (pmos decisions list shows the ids)`);
111
127
  if (flags.json) { say(JSON.stringify({ ok: true, decision: pub(e) })); return 0; }
112
- say(`${e.id} (${short(e.date)})\n decided: ${e.decided}\n expected: ${e.expected}\n check: ${short(e.check)} · ${e.state}`);
128
+ say(`${e.id} (${short(e.date)})\n decided: ${e.decided}` + (e.expected ? `\n expected: ${e.expected}` : '') + (e.check ? `\n check: ${short(e.check)} · ${e.state}` : `\n ${FROM_WORDS[e.from] || e.state}`));
113
129
  if (e.why) say(' why: ' + e.why);
114
130
  if (e.against) say(' disagreed: ' + e.against);
115
131
  if (e.initiative) say(' initiative: ' + e.initiative);
@@ -25,6 +25,8 @@
25
25
  * Every other kind (evidence, sizing, assumption, stakeholders, follow-up, note) is kept as a decision only: the PM's choice to
26
26
  * rely on it. A follow-up is never sent: the PM sends it from their own session. The driver never moves a stage by itself (D3).
27
27
  * RETURN needs a note and DROP may carry one; each logs one correction (the north star counts it) and a return wakes a run.
28
+ * THE DECISION JOURNAL (decisions-from-approvals): the PM's Keep, and a Drop with a note, also write one line to the product's decision journal
29
+ * (lib/decision-journal.js logFrom, ref `driver:<proposal>`) when ctx.root names the product; Undo takes the line out.
28
30
  */
29
31
  const fs = require('fs');
30
32
  const path = require('path');
@@ -127,7 +129,21 @@ async function decide(verb, { file, proposal, note, actor, ctx = {}, now, auto =
127
129
  } catch { /* the driver ledger already holds the correction */ }
128
130
  }
129
131
  }
130
- return { ok: true, proposal: D.fold(D.readLines(file)).proposals.get(p.id), wrote, warnings };
132
+ const decision = journalOf(verb, p, text, actor, ctx, t, auto);
133
+ return { ok: true, proposal: D.fold(D.readLines(file)).proposals.get(p.id), wrote, warnings, ...(decision ? { decision } : {}) };
134
+ }
135
+
136
+ /* decisions-from-approvals (bet A475): the PM's Keep, and a Drop with a note, write one line to the product's decision journal
137
+ * (lib/decision-journal.js logFrom). An automatic keep and a Return write none. Never fails the decision. → the journal id or null */
138
+ function journalOf(verb, p, note, actor, ctx, now, auto) {
139
+ if (auto || !ctx.root || !actorLib.isPm(actor) || !(verb === 'keep' || (verb === 'drop' && note))) return null;
140
+ const DJ = require('./decision-journal.js');
141
+ const what = String(p.what || 'proposal').replace(/-/g, ' '), why = String(p.why || '').trim();
142
+ const ini = p.target && p.target.kind === 'initiative' ? p.target.id : '';
143
+ const r = DJ.logFrom(ctx.root, verb === 'keep'
144
+ ? { from: 'approval', decided: `Kept the ${what} proposal${ini ? ' on ' + ini : ''}${why ? ': ' + why : ''}`, ref: `driver:${p.id}`, initiative: ini, why }
145
+ : { from: 'drop', decided: `Dropped the ${what} proposal${ini ? ' on ' + ini : ''}`, ref: `driver:${p.id}`, initiative: ini, why: note }, { now, by: actor.by, via: actor.via });
146
+ return r.ok ? r.id : null;
131
147
  }
132
148
 
133
149
  const jobOf = (p) => `driver:${p.what}`;
@@ -202,6 +218,7 @@ async function undo({ file, proposal, actor, ctx = {}, now, stateDir, product =
202
218
  record: { kind: 'correction', run: p.run, reason: 'driver:undo', by: actorLib.isPm(actor) ? 'pm' : actor.by } }) + '\n');
203
219
  } catch { /* the driver ledger already holds the correction */ }
204
220
  }
221
+ if (ctx.root) require('./decision-journal.js').undo(ctx.root, { ref: `driver:${p.id}` }, { now: t, by: actor.by, via: actor.via }); // its journal line goes too (none for an automatic keep)
205
222
  const s = p.auto && stateDir ? require('./autonomy.js').recordSetback(stateDir, { job: jobOf(p), product, ref: p.id, kind: 'undo' }, { now: t }) : { demoted: null };
206
223
  return { ok: true, back, demoted: s.demoted || null };
207
224
  }
@@ -170,8 +170,11 @@ function hold(root, { id, why, back, after } = {}, { now = Date.now(), by, via }
170
170
  if (after === id) return { ok: false, error: 'an initiative cannot wait on itself' };
171
171
  if (!ids.has(after)) return { ok: false, error: `no initiative ${after} here to wait on` };
172
172
  }
173
- return append(root, L, { initiative_id: id, state: 'on-hold', reason, ...(back ? { back: String(back) } : {}), ...(after ? { after } : {}),
173
+ const r = append(root, L, { initiative_id: id, state: 'on-hold', reason, ...(back ? { back: String(back) } : {}), ...(after ? { after } : {}),
174
174
  pm: pmSlug(), by: by || 'agent:unknown', via: via || 'cli', at: new Date(now).toISOString() });
175
+ // decisions-from-approvals: a hold with a reason is one line in the decision journal (lib/decision-journal.js onLifecycle)
176
+ if (r && r.ok && r.line) { try { const d = require('./decision-journal.js').onLifecycle(root, r.line, { now }); if (d && d.ok) r.decision = d.id; } catch { /* the hold stands */ } }
177
+ return r;
175
178
  }
176
179
 
177
180
  /** Bring a parked initiative back. One `active` line marked as brought back through its way back. */
@@ -139,6 +139,9 @@ const VERBS = Object.freeze({
139
139
  // Not a pm-os-absorb verb (run: null): initiative open-questions-register (bet A420) added it through the same table.
140
140
  questions: Object.freeze({ module: 'questions-cli.js', run: null, guide: 'cli.md',
141
141
  help: 'pmos questions [age] — every unanswered question across initiatives, oldest first, with who can answer, its age and its default (pmos questions help)' }),
142
+ // Not a pm-os-absorb verb (run: null): initiative try-what-shipped added it through the same table.
143
+ try: Object.freeze({ module: 'try-it.js', run: null, guide: 'cli.md',
144
+ help: 'pmos try [works|broken|note|undo|later|count] — the changes your recent updates brought, how to try each, and your answer (beta only; pmos try help)' }),
142
145
  // Not a pm-os-absorb verb (run: null): initiative three-line-why (bet A86) added it through the same table.
143
146
  why: Object.freeze({ module: 'why-cli.js', run: null, guide: 'cli.md',
144
147
  help: 'pmos why <initiative or task> | coverage — why the work exists in three lines: goal, problem, evidence, read from its records (pmos why help)' }),
@@ -195,6 +198,9 @@ const VERBS = Object.freeze({
195
198
  // Not a pm-os-absorb verb (run: null): feedback batch 25 item 1 added it through the same table.
196
199
  'git-identity': Object.freeze({ module: 'git-identity-cli.js', run: null, guide: 'cli.md',
197
200
  help: 'pmos git-identity [set --name <n> --email <e> --login <gh>] — which git identity and GitHub login this repository uses; save your choice for it' }),
201
+ // Not a pm-os-absorb verb (run: null): roadmap-signal-verb (bet A157) added it through the same table.
202
+ signal: Object.freeze({ module: 'signal-cli.js', run: null, guide: 'cli.md',
203
+ help: 'pmos signal add|remove|list|count — the customer signals behind each roadmap item; the Board shows the count (pmos signal help)' }),
198
204
  launcher: Object.freeze({ module: 'launcher-cli.js', run: null, guide: 'cli.md',
199
205
  help: 'pmos launcher on|off|status — a PMOS app and a login item, so the workspace starts without a terminal' }),
200
206
  });
@@ -51,6 +51,7 @@ const MODULES = Object.freeze([
51
51
  'routes-doc-health', // console3 B2: the six document health checks, recomputed from text
52
52
  'routes-outbox', // console3 B3: the outbox queue, hash-bound confirm (no channel connected)
53
53
  'routes-waiting', // home-your-move-waiting: Waiting on others, derived from records, with its exit rule
54
+ 'routes-try', // try-what-shipped: the changes to try after an update, and the user's Works / Didn't work / note (beta only; try/answers.jsonl)
54
55
  'routes-glossary', // glossary-hover (A386): the glossary of the products a page shows (read only; pmos glossary writes it)
55
56
  'routes-open-questions', // open-questions-register (A420): one register of every unanswered question, with owner, age and default
56
57
  'routes-calendar-views', // console3 C2: Day/Week/Month/Quarter/Year cells, Gantt and the strategy lens (read-only)
@@ -7,7 +7,8 @@
7
7
  * GET /api/proposals?ws&board&initiative[&grill=all] → { ok, props, found } props: lib/proposals.js viewOf (null: nothing to show); grill=all unfolds every grill finding
8
8
  * POST /api/proposals/keep { ws, board, initiative, ids?: [id] | all: true, choices?: { <from>><to>: 'keep' | 'ignore' } }
9
9
  * → { ok, batch, said, counts, props } ✓ one proposal, or ✓ in the header (all: every one Claude is sure of;
10
- * Check these and a Jira ticket's comment never ride on it). One batch, one toast, one Undo.
10
+ * Check these and a Jira ticket's comment never ride on it). One batch, one toast, one Undo. The PM's ✓ also
11
+ * writes one line to the product's decision journal (`decision`: its id; `card` when choices were picked); Undo takes it out
11
12
  * POST /api/proposals/drop { ws, board, initiative, sig, why? } → { ok } why: the PM's reason (the idle lab asks for one); ✕ on a proposal or on one item of it, for good (rule 7); the line
12
13
  * also keeps its facts (PR.factsOf), so a re-sectioned task or a new day does not bring it back
13
14
  * POST /api/proposals/undo { ws, board, batch } → { ok, back, kept } the whole batch; a task changed since keeps its change
@@ -27,6 +28,16 @@ const PR = require('./proposals.js');
27
28
  const TL = require('./task-links.js');
28
29
  const RB = require('./routes-boards.js');
29
30
  const TLR = require('./routes-task-links.js');
31
+ const DJ = require('./decision-journal.js');
32
+
33
+ /** decisions-from-approvals (bet A475): what the PM's ✓ decided, in one line for the decision journal. PURE.
34
+ * want: the kept proposals; picked: the PM chose among a card's answers (body.choices). → { from, decided, why } */
35
+ function keepText(want, ini, picked) {
36
+ const names = (want || []).map((x) => String((x && (x.title || x.why || x.type || x.group)) || '').replace(/\s+/g, ' ').trim()).filter(Boolean);
37
+ const head = names.slice(0, 3).join('; ') + (names.length > 3 ? ` and ${names.length - 3} more` : '');
38
+ const why = (want || []).map((x) => String((x && x.why) || '').trim()).filter(Boolean)[0] || '';
39
+ return { from: picked ? 'card' : 'approval', decided: `${picked ? 'Picked' : 'Approved'} on ${ini}: ${head || plural((want || []).length, 'proposal', 'proposals')}`, why: why.slice(0, 300) };
40
+ }
30
41
 
31
42
  const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
32
43
  const fail = (ctx, res, status, error, extra = {}) => { ctx.json(res, { ok: false, error, ...extra }, status); return true; };
@@ -138,6 +149,7 @@ function undoCore(ctx, p, g, id) {
138
149
  if (r && r.body && r.body.ok) back++; else kept++;
139
150
  }
140
151
  PR.append(dir, g.actor, { kind: 'undo', batch: id });
152
+ try { DJ.undo(p.w.root, { ref: 'proposals:' + id }, { by: g.actor && g.actor.by, via: g.actor && g.actor.via }); } catch { /* a batch PMOS kept by itself has no journal line */ }
141
153
  // D106: the Undo of a change an agent applied by itself is a setback of its job (lib/autonomy.js), which may demote the job
142
154
  const line = PR.readLines(PR.ledgerFile(dir)).find((l) => l.kind === 'keep' && l.batch === id);
143
155
  let demoted = null;
@@ -528,9 +540,13 @@ const WRITES = {
528
540
  const { batch, wrote, plans, failed } = keepCore(ctx, p, g, f, ini, want, isObj(body.choices) ? body.choices : {});
529
541
  // a draft pull request that could not open (W7): nothing was written, the proposal stays open, and the page says why
530
542
  if (failed.length && !wrote.length) return fail(ctx, res, 409, failed[0].why);
543
+ // the PM's ✓ is a decision: one line in the product's decision journal, undone with this batch (decisions-from-approvals)
544
+ const picked = isObj(body.choices) && Object.keys(body.choices).length > 0;
545
+ const kt = keepText(want, ini, picked);
546
+ const dj = DJ.logFrom(p.w.root, { ...kt, ref: 'proposals:' + batch, initiative: ini }, { by: g.actor && g.actor.by, via: g.actor && g.actor.via });
531
547
  const v2 = view(ctx, p, ini);
532
548
  const left = v2 ? v2.groups.flatMap((x) => x.props).filter((x) => x.section === 'check').length : 0;
533
- ctx.json(res, { ok: true, batch, said: saidOf(wrote, plans, body.all === true ? left : 0), counts: { wrote: wrote.length }, props: v2, found: PR.foundOf(PR.read(dir), ini) });
549
+ ctx.json(res, { ok: true, batch, ...(dj.ok ? { decision: dj.id } : {}), said: saidOf(wrote, plans, body.all === true ? left : 0), counts: { wrote: wrote.length }, props: v2, found: PR.foundOf(PR.read(dir), ini) });
534
550
  },
535
551
  '/api/proposals/drop': (ctx, res, body, g, p) => {
536
552
  const sig = String(body.sig || ''), ini = String(body.initiative || '');
@@ -557,8 +573,11 @@ const WRITES = {
557
573
  try { const AF = require('./artefacts.js'); AF.set(AF.file(dirOf(ctx, p.w)), { scope: 'experiment:' + ini, artefact: 'lessons', field: 'line', text: `✕ dropped "${String(of.title || '').slice(0, 140)}"${why ? ': ' + why : ''}`, sources: [{ label: 'live round' }] }, { by: g.actor && /^(pm|agent):/.test(String(g.actor.by)) ? g.actor.by : 'agent:live-round' }); } catch { /* the drop line holds it */ }
558
574
  }
559
575
  // the reason becomes curated memory by itself, so every later run knows it (lib/corrections-memory.js)
576
+ // a ✕ with a reason is a decision too (decisions-from-approvals): one line in the product's decision journal
577
+ let decision = null;
578
+ if (why) { const r = DJ.logFrom(p.w.root, { from: 'drop', decided: `Dropped on ${ini}: ${String((of && (of.title || of.why)) || 'a proposal').slice(0, 200)}`, ref: `proposals-drop:${ini}:${sig}`, initiative: ini, why }, { by: g.actor && g.actor.by, via: g.actor && g.actor.via }); if (r.ok) decision = r.id; }
560
579
  if (why) require('./corrections-memory.js').remember(p.w.root, { what: `a ${(of && (of.group || of.type)) || ''} proposal on ${ini}`.replace(/ +/g, ' '), why, source: 'proposal:' + (which.id || sig), ini });
561
- ctx.json(res, { ok: true });
580
+ ctx.json(res, { ok: true, ...(decision ? { decision } : {}) });
562
581
  },
563
582
  '/api/proposals/undo': (ctx, res, body, g, p) => {
564
583
  const r = undoCore(ctx, p, g, String(body.batch || ''));
@@ -586,7 +605,7 @@ const WRITES = {
586
605
 
587
606
  module.exports = {
588
607
  prefixes: ['/api/proposals'],
589
- viewFor, saidOf, prdRename, keepCore, undoCore, autoKeep, heldOf, keepDefault,
608
+ viewFor, saidOf, prdRename, keepCore, undoCore, autoKeep, heldOf, keepDefault, keepText,
590
609
  handle: async (req, res, url, ctx) => {
591
610
  const p0 = url.pathname;
592
611
  if (req.method === 'GET') {
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ /* routes-try.js — try what shipped (initiative try-what-shipped; lib/try-it.js is the store and the list).
3
+ *
4
+ * GET /api/try → { ok, beta, items: [card], total, shown, later, row } the changes to try (beta only)
5
+ * POST /api/try/answer { key, verdict, note? } → { ok, line } works | broken | note | undo, the PM's press
6
+ * POST /api/try/later {} → { ok } hide Home's row until tomorrow
7
+ *
8
+ * Every POST passes pm-guard requirePagePress: the page only (pmos try is the chat's way). Answers stay in <state>/try/answers.jsonl on
9
+ * this computer; nothing is sent. A computer on the GA line gets an empty list. */
10
+ const guard = require('./pm-guard.js');
11
+ const T = require('./try-it.js');
12
+
13
+ module.exports = {
14
+ prefixes: ['/api/try'],
15
+ handle: async (req, res, url, ctx) => {
16
+ const p = url.pathname;
17
+ if (p !== '/api/try' && p !== '/api/try/answer' && p !== '/api/try/later') return false;
18
+ if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'PMOS has no state folder here, so it cannot keep your answers' }, 503); return true; }
19
+ const C = T.ctxOf({ stateDir: ctx.runtimeDir, appDir: ctx.tryAppDir || undefined, beta: ctx.tryBeta });
20
+ if (p === '/api/try') {
21
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
22
+ const F = T.fold(T.readLines(C.stateDir));
23
+ const L = T.listOf({ changes: C.changes, installed: C.installed, answers: F.answers, now: C.now, beta: C.beta });
24
+ ctx.json(res, { ok: true, ...L, later: F.later, row: T.rowOf(L, { later: F.later }) });
25
+ return true;
26
+ }
27
+ if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
28
+ const got = await ctx.readJson(req);
29
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
30
+ const body = got.body || {};
31
+ const g = guard.requirePagePress(req, body);
32
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
33
+ if (!C.beta) { ctx.json(res, { ok: false, error: 'This computer follows the GA line, so there is nothing to try here' }, 409); return true; }
34
+ if (p === '/api/try/later') { T.later(C.stateDir, { now: C.now }); ctx.json(res, { ok: true }); return true; }
35
+ const r = T.answer(C.stateDir, { key: String(body.key || ''), verdict: String(body.verdict || ''), note: body.note }, C);
36
+ ctx.json(res, r, r.ok ? 200 : 400);
37
+ return true;
38
+ },
39
+ };
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+ /* signal-cli.js — `pmos signal`: the customer signals behind each roadmap item (roadmap-signal-verb, bet A157).
3
+ *
4
+ * pmos signal add <initiative> --who "<customer>" [--where ticket|call|email|chat|survey|review|other] [--link <url>] [--note "<one line>"]
5
+ * pmos signal remove <sid>
6
+ * pmos signal list [<initiative>] [--json]
7
+ * pmos signal count [<checkout>]
8
+ *
9
+ * A thin verb over lib/customer-signals.js main(): the same ledger (planning/runs/customer-signals.jsonl) that the Board's
10
+ * count and the item panel read, so a signal a chat adds shows on the roadmap at the next read. Without --root it works on
11
+ * the git root of the current folder. Exit codes: 0 done, 1 refused, 2 usage.
12
+ */
13
+ const { execFileSync } = require('child_process');
14
+ const CS = require('./customer-signals.js');
15
+
16
+ const COMMANDS = { signal: ['add', 'remove', 'list', 'count'] };
17
+ const USAGE = [
18
+ 'usage: pmos signal add <initiative> --who "<customer>" [--where ' + CS.WHERE.join('|') + '] [--link <url>] [--note "<one line>"] [--root <dir>]',
19
+ ' pmos signal remove <sid> [--root <dir>]',
20
+ ' pmos signal list [<initiative>] [--json] [--root <dir>]',
21
+ ' pmos signal count [<checkout>]',
22
+ 'The Board shows the count on each roadmap item, and a press (or a tap on the item on a phone) lists them.',
23
+ ];
24
+
25
+ function gitRoot(cwd = process.cwd()) {
26
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
27
+ catch { return cwd; }
28
+ }
29
+
30
+ function run(argv, { say = console.log } = {}) {
31
+ const rest = argv.slice(1);
32
+ const sub = rest[0];
33
+ if (!sub || sub === 'help' || rest.includes('--help') || !COMMANDS.signal.includes(sub)) { USAGE.forEach((l) => say(l)); return 2; }
34
+ const args = rest.slice();
35
+ const hasRoot = args.includes('--root');
36
+ if (sub === 'count') { if (!hasRoot && !args.slice(1).some((a) => !a.startsWith('--'))) args.push(gitRoot()); }
37
+ else if (!hasRoot) args.push('--root', gitRoot());
38
+ return CS.main(args, say);
39
+ }
40
+
41
+ module.exports = { run, COMMANDS, USAGE };