create-pmos 0.792.0 → 0.794.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.
@@ -35,6 +35,25 @@
35
35
  * loggedCount(rows, { days, now }) → number lines from presses in the last `days` days, not undone (the health number)
36
36
  * CLI: node lib/decision-journal.js logged <root> [--days 7] prints `[decision-log] …` and the count alone on the last line
37
37
  *
38
+ * COMING BACK (initiative decisions-come-back, bet A509). A decision may carry a THRESHOLD (the line it must hold, in words) and a REVIEW
39
+ * TRIGGER: a date to look again (`review_on`), a goal number crossing a line (`metric` { rid, op, value }, read from the newest good reading
40
+ * in <state>/metric-reads.jsonl), or both. More lines:
41
+ * { type: 'trigger', id, threshold?, review_on?, metric?, off?, at, by, via } the PM sets or turns off a decision's trigger later
42
+ * { type: 'review', id, choice: keep | change, next?, to?, at, by, via } the PM's answer when the decision came back
43
+ * { type: 'undo-step', id, of, at, by, via } undoes the trigger or review line written at `of`
44
+ * A decision with no trigger of its own gets one DRAFTED from its evidence (draftTrigger, never written): an expected outcome with a number
45
+ * gives the threshold on the other side of that number and the check date; a drop with a reason comes back `dropBackDays` (Settings
46
+ * decisions.dropBack, default 90) after the decision. A trigger the PM set or turned off always wins over a draft.
47
+ * draftTrigger(entry, { dropBackDays }) → { threshold, review_on, metric: null, drafted: true, source } | null
48
+ * comeBack(entry, { today, reading }) → { why, on } | null an open or logged decision whose review date came, or whose metric's newest
49
+ * reading is past the line and newer than the last Keep. Due, checked, replaced: never
50
+ * setTrigger(root, { id, threshold?, review?, metric?, off? }, who) · keep(root, { id, next? }, who) · change(root, { id, decided, expected?,
51
+ * changed_mind }, who) · undoStep(root, { id }, who) each appends one line (change: the new decision and a review line)
52
+ * entriesOf(root, { today, dropBackDays }) also sets e.trigger (set or drafted, or null) and e.back (comeBack) on every entry
53
+ * CLI: node lib/decision-journal.js triggers <root> the share of live decisions with a trigger, alone on the last line
54
+ * node lib/decision-journal.js answered <root> [--days 30] Keep and Change answers in the window, alone on the last line
55
+ * Reading, drafting and coming back write nothing: only the PM's press or command appends a line.
56
+ *
38
57
  * A verdict is the PM's: PMOS never records one from a metric alone, and every verdict carries evidence. Nothing here sends anything.
39
58
  */
40
59
  const fs = require('fs');
@@ -99,7 +118,16 @@ function fold(rows, { today = todayOf() } = {}) {
99
118
  if (!r || r.type !== 'decision' || typeof r.id !== 'string' || by.has(r.id) || undone.has(r.id)) continue;
100
119
  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 || '',
101
120
  why: r.why || '', against: r.against || '', initiative: r.initiative || '', replaces: r.replaces || '', changed_mind: r.changed_mind || '',
102
- replacedBy: '', replacedWhy: '', replacedAt: '', checks: [], verdict: null, dueAt: '', at: r.at || '', by: r.by || '', from: r.from || '', ref: r.ref || '' });
121
+ replacedBy: '', replacedWhy: '', replacedAt: '', checks: [], verdict: null, dueAt: '', at: r.at || '', by: r.by || '', from: r.from || '', ref: r.ref || '',
122
+ own: r.threshold || r.review_on || r.metric ? { threshold: r.threshold || '', review_on: r.review_on || '', metric: r.metric || null, at: r.at || '' } : null, reviews: [] });
123
+ }
124
+ const gone = stepsUndone(rows);
125
+ for (const r of rows || []) {
126
+ if (!r || (r.type !== 'trigger' && r.type !== 'review') || gone.has(r.id + '|' + r.at)) continue;
127
+ const e = by.get(r.id);
128
+ if (!e) continue;
129
+ if (r.type === 'trigger') e.own = r.off ? { off: true, at: r.at || '' } : { threshold: r.threshold || '', review_on: r.review_on || '', metric: r.metric || null, at: r.at || '' };
130
+ else if (r.choice === 'keep' || r.choice === 'change') e.reviews.push(r);
103
131
  }
104
132
  for (const r of rows || []) {
105
133
  if (!r || r.type !== 'check') continue;
@@ -155,6 +183,8 @@ function add(root, f = {}, { now = Date.now(), by, via } = {}) {
155
183
  if (!check) return { ok: false, error: '--check is a date (YYYY-MM-DD) or a time from today (+30d, +2w, +3m)' };
156
184
  if (check <= today) return { ok: false, error: 'the check date must be after today: an outcome needs time to show' };
157
185
  }
186
+ const T = triggerOf(f, today);
187
+ if (T.error) return { ok: false, error: T.error };
158
188
  const why = one(f.why), against = one(f.against), initiative = one(f.initiative), replaces = one(f.replaces), changed = one(f.changed_mind);
159
189
  if (why.length > MAX.why || against.length > MAX.against || changed.length > MAX.changed) return { ok: false, error: 'keep --why, --against and --changed-mind under 600 characters each' };
160
190
  if (initiative && !ID_RE.test(initiative)) return { ok: false, error: '--initiative takes the initiative\'s id' };
@@ -171,7 +201,7 @@ function add(root, f = {}, { now = Date.now(), by, via } = {}) {
171
201
  const have = new Set(E.map((e) => e.id));
172
202
  while (have.has(id)) id = base + '-' + n++;
173
203
  const line = { type: 'decision', id, date: today, decided, expected, check, ...(why ? { why } : {}), ...(against ? { against } : {}),
174
- ...(initiative ? { initiative } : {}), ...(replaces ? { replaces, changed_mind: changed } : {}), at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
204
+ ...(initiative ? { initiative } : {}), ...(replaces ? { replaces, changed_mind: changed } : {}), ...T.fields, at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
175
205
  try { append(J.file, line); } catch (e) { return { ok: false, error: 'the decision journal could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
176
206
  return { ok: true, id, line, file: rel(root, J.file) };
177
207
  }
@@ -275,6 +305,228 @@ function loggedCount(rows, { days = 7, now = Date.now() } = {}) {
275
305
  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
306
  }
277
307
 
308
+ /* ── coming back (decisions-come-back) ── */
309
+ const BACK_TAG = '[decision-back]';
310
+ const DROP_BACK_DAYS = 90;
311
+ const DAILY_MAX = 3;
312
+ const MIN_GAP = 7;
313
+ const OPS = Object.freeze(['<', '<=', '>', '>=']);
314
+ const METRIC_RE = /^([a-z0-9][a-z0-9._:-]{0,79})\s*(<=|>=|<|>)\s*(-?\d+(?:\.\d+)?)\s*%?$/i;
315
+
316
+ /** "<goal id> <op> <number>" → { rid, op, value } | null */
317
+ function parseMetric(text) {
318
+ const m = METRIC_RE.exec(one(text));
319
+ return m ? { rid: m[1], op: m[2], value: +m[3] } : null;
320
+ }
321
+ const crosses = (v, m) => Number.isFinite(v) && (m.op === '<' ? v < m.value : m.op === '<=' ? v <= m.value : m.op === '>' ? v > m.value : v >= m.value);
322
+ const metricWords = (m) => m ? `${m.rid} ${m.op} ${m.value}` : '';
323
+
324
+ /** The trigger fields of an add or a trigger command, checked. → { fields } | { error } */
325
+ function triggerOf(f, today) {
326
+ const fields = {};
327
+ const threshold = one(f.threshold);
328
+ if (threshold) {
329
+ if (threshold.length < 3 || threshold.length > MAX.decided) return { error: `--threshold says the line the decision must hold, in 3 to ${MAX.decided} characters` };
330
+ fields.threshold = threshold;
331
+ }
332
+ if (f.review != null && f.review !== '') {
333
+ const d = checkDate(f.review, today);
334
+ if (!d || d <= today) return { error: '--review is a date after today (YYYY-MM-DD, or +30d, +2w, +3m)' };
335
+ fields.review_on = d;
336
+ }
337
+ if (f.metric != null && f.metric !== '') {
338
+ const m = parseMetric(f.metric);
339
+ if (!m) return { error: '--metric is a goal id, a sign and a number, for example "weekly-signups < 50"' };
340
+ fields.metric = m;
341
+ }
342
+ return { fields };
343
+ }
344
+
345
+ /** The steps (trigger and review lines) an `undo-step` line took back, as "id|at". */
346
+ function stepsUndone(rows) {
347
+ const out = new Set();
348
+ for (const r of rows || []) if (r && r.type === 'undo-step' && typeof r.id === 'string' && typeof r.of === 'string') out.add(r.id + '|' + r.of);
349
+ return out;
350
+ }
351
+
352
+ const UP = /\b(at least|more than|over|above|exceed(?:s|ing)?|reach(?:es)?|hit(?:s)?|grow(?:s)? to|rise(?:s)? to|>=?)\s*([$€£]?\d[\d,]*(?:\.\d+)?\s*%?)/i;
353
+ const DOWN = /\b(at most|less than|fewer than|under|below|no more than|drop(?:s)? to|fall(?:s)? to|<=?)\s*([$€£]?\d[\d,]*(?:\.\d+)?\s*%?)/i;
354
+ const ANY_NUM = /([$€£]?\d[\d,]*(?:\.\d+)?\s*%?)/;
355
+ const clipTo = (s, n) => { const t = one(s); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
356
+
357
+ /** A trigger drafted from the decision's own evidence, or null. Never written: it shows as drafted until the PM sets one. */
358
+ function draftTrigger(e, { dropBackDays = DROP_BACK_DAYS } = {}) {
359
+ if (!e) return null;
360
+ const ex = one(e.expected);
361
+ if (ex) {
362
+ const up = UP.exec(ex), down = DOWN.exec(ex), any = ANY_NUM.exec(ex);
363
+ const n = (up && up[2]) || (down && down[2]) || (any && any[1]);
364
+ if (n) {
365
+ const num = one(n);
366
+ const threshold = up ? `falls below ${num}` : down ? `goes above ${num}` : `misses ${num}`;
367
+ return { threshold, review_on: isDate(e.check) ? e.check : '', metric: null, drafted: true, source: `expected: ${clipTo(ex, 140)}` };
368
+ }
369
+ }
370
+ const days = Number.isFinite(+dropBackDays) ? Math.max(0, Math.round(+dropBackDays)) : DROP_BACK_DAYS;
371
+ if (e.from === 'drop' && one(e.why) && days > 0 && isDate(e.date)) {
372
+ return { threshold: `the reason no longer holds: ${clipTo(e.why, 140)}`, review_on: addDays(e.date, days), metric: null, drafted: true, source: `dropped because: ${clipTo(e.why, 140)}` };
373
+ }
374
+ return null;
375
+ }
376
+
377
+ /** The trigger in force: the PM's own (set or off) wins over a draft. */
378
+ function triggerIn(e, o) {
379
+ if (e.own) return e.own.off ? null : { threshold: e.own.threshold, review_on: e.own.review_on, metric: e.own.metric, drafted: false, source: '', at: e.own.at };
380
+ return draftTrigger(e, o);
381
+ }
382
+
383
+ const lastKeep = (e) => { const k = (e.reviews || []).filter((r) => r.choice === 'keep'); return k.length ? k[k.length - 1] : null; };
384
+
385
+ /** Whether a decision is back, and why. reading: the newest good reading of its metric goal ({ value, day, at }) or null. */
386
+ function comeBack(e, { today = todayOf(), reading = null } = {}) {
387
+ if (!e || (e.state !== 'open' && e.state !== 'logged')) return null;
388
+ if ((e.reviews || []).some((r) => r.choice === 'change')) return null;
389
+ const t = e.trigger !== undefined ? e.trigger : triggerIn(e, {});
390
+ if (!t) return null;
391
+ const k = lastKeep(e);
392
+ const keptAfter = k && String(k.at) > String(t.at || '');
393
+ const date = keptAfter ? k.next : t.review_on;
394
+ if (isDate(date) && date <= today) return { why: `its review date ${date} came`, on: date };
395
+ if (t.metric && reading && Number.isFinite(reading.value)) {
396
+ const since = String(k ? k.at : '') > String(t.at || e.at || '') ? String(k.at) : String(t.at || e.at || '');
397
+ if (String(reading.at || '') > since && crosses(reading.value, t.metric)) return { why: `${t.metric.rid} read ${reading.value} on ${reading.day || String(reading.at).slice(0, 10)}, past ${t.metric.op} ${t.metric.value}`, on: reading.day || String(reading.at).slice(0, 10) };
398
+ }
399
+ return null;
400
+ }
401
+
402
+ /** The folder metric-reads.jsonl lives in for this repository (the state folder), or null. */
403
+ function stateDirOf(root) {
404
+ for (const r of [['pmos', 'state'], ['state'], ['.pmos']]) { const d = path.join(root, ...r); try { if (fs.statSync(d).isDirectory()) return d; } catch { /* next */ } }
405
+ return null;
406
+ }
407
+ /** rid → the newest good reading, for the goals some trigger watches. */
408
+ function readingsOf(root, rids) {
409
+ const out = new Map();
410
+ if (!rids.size) return out;
411
+ const dir = stateDirOf(root);
412
+ if (!dir) return out;
413
+ try {
414
+ const F = require('./metric-reads.js').read(dir);
415
+ for (const rid of rids) { const x = F.rids.get(rid); if (x && x.good && Number.isFinite(x.good.value)) out.set(rid, { value: x.good.value, day: x.good.day || '', at: x.good.at || '' }); }
416
+ } catch { /* no readings */ }
417
+ return out;
418
+ }
419
+ function metricFile(root) { const d = stateDirOf(root); return d ? path.join(d, 'metric-reads.jsonl') : null; }
420
+
421
+ /** Settings › decisions.dropBack: the days after which a dropped decision comes back (0: never). */
422
+ function dropBackSetting(env = process.env) {
423
+ try { const v = require('./settings-store.js').get(require('./state-root.js').defaultRoot({ env }), 'decisions.dropBack'); return Number.isFinite(+v) ? +v : DROP_BACK_DAYS; } catch { return DROP_BACK_DAYS; }
424
+ }
425
+
426
+ /** Sets trigger and back on each entry. */
427
+ function withBack(root, entries, { today = todayOf(), dropBackDays = DROP_BACK_DAYS } = {}) {
428
+ for (const e of entries) e.trigger = triggerIn(e, { dropBackDays });
429
+ const rids = new Set(entries.filter((e) => e.trigger && e.trigger.metric).map((e) => e.trigger.metric.rid));
430
+ const R = readingsOf(root, rids);
431
+ for (const e of entries) e.back = comeBack(e, { today, reading: e.trigger && e.trigger.metric ? R.get(e.trigger.metric.rid) || null : null });
432
+ return entries;
433
+ }
434
+
435
+ function liveEntry(root, id, today) {
436
+ const J = read(root);
437
+ const e = fold(J.rows, { today }).find((x) => x.id === id);
438
+ if (!e) return { J, error: `no decision ${id} in this journal (pmos decisions list shows the ids)` };
439
+ if (e.state === 'checked' || e.state === 'replaced') return { J, error: `${id} is closed (${e.state}); it does not come back` };
440
+ return { J, e };
441
+ }
442
+ const fail = (e) => ({ ok: false, error: 'the decision journal could not be written: ' + String((e && e.message) || e).slice(0, 160) });
443
+
444
+ function setTrigger(root, f = {}, { now = Date.now(), by, via } = {}) {
445
+ root = path.resolve(root);
446
+ const today = todayOf(now);
447
+ const { J, e, error } = liveEntry(root, f.id, today);
448
+ if (error) return { ok: false, error };
449
+ let fields;
450
+ if (f.off) fields = { off: true };
451
+ else {
452
+ const T = triggerOf(f, today);
453
+ if (T.error) return { ok: false, error: T.error };
454
+ if (!T.fields.review_on && !T.fields.metric) return { ok: false, error: 'a trigger needs --review <date> or --metric "<goal id> < <number>" (or --off to turn it off)' };
455
+ fields = T.fields;
456
+ }
457
+ const line = { type: 'trigger', id: e.id, ...fields, at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
458
+ try { append(J.file, line); } catch (err) { return fail(err); }
459
+ console.log(`${BACK_TAG} trigger ${e.id}${fields.off ? ' off' : ''}`);
460
+ return { ok: true, id: e.id, line, file: rel(root, J.file) };
461
+ }
462
+
463
+ function keep(root, { id, next } = {}, { now = Date.now(), by, via, dropBackDays = DROP_BACK_DAYS } = {}) {
464
+ root = path.resolve(root);
465
+ const today = todayOf(now);
466
+ const { J, e, error } = liveEntry(root, id, today);
467
+ if (error) return { ok: false, error };
468
+ let nextDay = '';
469
+ if (next != null && next !== '') {
470
+ nextDay = checkDate(next, today);
471
+ if (!nextDay || nextDay <= today) return { ok: false, error: '--next is a date after today (YYYY-MM-DD, or +30d, +2w, +3m)' };
472
+ } else {
473
+ const t = triggerIn(e, { dropBackDays });
474
+ if (!t) return { ok: false, error: `${id} has no review trigger, so there is nothing to keep (pmos decisions trigger ${id} --review +30d sets one)` };
475
+ if (t.review_on) {
476
+ const k = lastKeep(e), from = k && k.next && String(k.at) > String(t.at || '') ? String(k.at).slice(0, 10) : e.date;
477
+ const prev = k && k.next && String(k.at) > String(t.at || '') ? k.next : t.review_on;
478
+ nextDay = addDays(today, Math.max(MIN_GAP, isDate(from) && isDate(prev) ? daysBetween(from, prev) : DEFAULT_DAYS));
479
+ }
480
+ }
481
+ const line = { type: 'review', id: e.id, choice: 'keep', ...(nextDay ? { next: nextDay } : {}), at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
482
+ try { append(J.file, line); } catch (err) { return fail(err); }
483
+ console.log(`${BACK_TAG} keep ${e.id}${nextDay ? ' next ' + nextDay : ''}`);
484
+ return { ok: true, id: e.id, line, file: rel(root, J.file) };
485
+ }
486
+
487
+ function change(root, { id, decided, expected, changed_mind } = {}, o = {}) {
488
+ root = path.resolve(root);
489
+ const today = todayOf(o.now || Date.now());
490
+ const { e, error } = liveEntry(root, id, today);
491
+ if (error) return { ok: false, error };
492
+ const r = add(root, { decided, expected: one(expected) || e.expected, replaces: id, changed_mind }, o);
493
+ if (!r.ok) return r;
494
+ const J = read(root);
495
+ const line = { type: 'review', id, choice: 'change', to: r.id, at: new Date(o.now || Date.now()).toISOString(), by: o.by || 'agent:unknown', via: o.via || 'cli' };
496
+ try { append(J.file, line); } catch (err) { return fail(err); }
497
+ console.log(`${BACK_TAG} change ${id} to ${r.id}`);
498
+ return { ok: true, id, to: r.id, line, file: r.file };
499
+ }
500
+
501
+ function undoStep(root, { id } = {}, { now = Date.now(), by, via } = {}) {
502
+ try {
503
+ root = path.resolve(root);
504
+ const J = read(root);
505
+ const gone = stepsUndone(J.rows);
506
+ const steps = J.rows.filter((r) => r && (r.type === 'trigger' || r.type === 'review') && r.id === id && typeof r.at === 'string' && !gone.has(r.id + '|' + r.at));
507
+ const last = steps.pop();
508
+ if (!last) return { ok: false, error: `${id} has no Keep, Change or trigger to undo` };
509
+ const line = { type: 'undo-step', id, of: last.at, at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
510
+ append(J.file, line);
511
+ let also = null;
512
+ if (last.type === 'review' && last.choice === 'change' && last.to) { const u = undo(root, { id: last.to }, { now, by, via }); if (u.ok) also = last.to; }
513
+ console.log(`${BACK_TAG} undo ${id} ${last.type}${last.choice ? ' ' + last.choice : ''}`);
514
+ return { ok: true, id, undid: last.type === 'review' ? last.choice : 'trigger', also, line, file: rel(root, J.file) };
515
+ } catch (e) { return fail(e); }
516
+ }
517
+
518
+ /** The health number: live decisions (open, logged, due) with a trigger, set or drafted. */
519
+ function triggerShare(entries) {
520
+ const live = (entries || []).filter((e) => e.state === 'open' || e.state === 'logged' || e.state === 'due');
521
+ const withT = live.filter((e) => e.trigger), drafted = withT.filter((e) => e.trigger.drafted);
522
+ return { live: live.length, withTrigger: withT.length, drafted: drafted.length, pct: live.length ? Math.round((100 * withT.length) / live.length) : 0 };
523
+ }
524
+ /** The outcome number: Keep and Change answers in the last `days` days, not undone. */
525
+ function answeredCount(rows, { days = 30, now = Date.now() } = {}) {
526
+ const gone = stepsUndone(rows), since = now - days * DAY;
527
+ return (rows || []).filter((r) => r && r.type === 'review' && (r.choice === 'keep' || r.choice === 'change') && !gone.has(r.id + '|' + r.at) && Date.parse(r.at) >= since && Date.parse(r.at) <= now).length;
528
+ }
529
+
278
530
  const rate = (w, d) => (w + d ? Math.round((100 * w) / (w + d)) : null);
279
531
 
280
532
  /** The track record: how the user's calls turned out, per quarter of the date each check answered. */
@@ -313,26 +565,40 @@ function foldWithFirst(rows, opts) {
313
565
  }
314
566
 
315
567
  /** Every entry of a repository's journal, sorted for a reader. */
316
- function entriesOf(root, { today = todayOf() } = {}) {
568
+ function entriesOf(root, { today = todayOf(), dropBackDays = DROP_BACK_DAYS } = {}) {
317
569
  const J = read(root);
318
- return { entries: sorted(foldWithFirst(J.rows, { today })), file: rel(path.resolve(root), J.file) };
570
+ return { entries: withBack(path.resolve(root), sorted(foldWithFirst(J.rows, { today })), { today, dropBackDays }), file: rel(path.resolve(root), J.file) };
319
571
  }
320
572
 
321
573
  /** A signature that changes when a journal file changes. */
322
574
  function stamp(root) {
323
575
  const out = [];
324
- for (const f of filesOf(path.resolve(root)).all) { try { const st = fs.statSync(f); out.push(st.mtimeMs + ':' + st.size); } catch { /* none */ } }
576
+ for (const f of [...filesOf(path.resolve(root)).all, metricFile(path.resolve(root))].filter(Boolean)) { try { const st = fs.statSync(f); out.push(st.mtimeMs + ':' + st.size); } catch { /* none */ } }
325
577
  return out.join('|');
326
578
  }
327
579
 
328
580
  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 };
581
+ logFrom, undo, onLifecycle, loggedCount,
582
+ BACK_TAG, DROP_BACK_DAYS, DAILY_MAX, OPS, parseMetric, draftTrigger, comeBack, setTrigger, keep, change, undoStep, triggerShare, answeredCount, dropBackSetting, metricWords };
330
583
 
331
584
  if (require.main === module) {
332
585
  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); }
586
+ if (!['logged', 'triggers', 'answered'].includes(a[0])) { console.error('usage: node lib/decision-journal.js logged|triggers|answered <root> [--days N]'); process.exit(2); }
334
587
  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;
588
+ const i = a.indexOf('--days');
589
+ if (a[0] === 'triggers') {
590
+ const S = triggerShare(entriesOf(root, { dropBackDays: dropBackSetting() }).entries);
591
+ console.log(`${BACK_TAG} ${S.withTrigger} of ${S.live} live decisions have a review trigger (${S.drafted} drafted by PMOS)`);
592
+ console.log(String(S.pct));
593
+ process.exit(0);
594
+ }
595
+ if (a[0] === 'answered') {
596
+ const d = i > 0 ? Math.max(1, +a[i + 1] || 30) : 30, n = answeredCount(read(root).rows, { days: d });
597
+ console.log(`${BACK_TAG} ${n} ${n === 1 ? 'decision that came back was' : 'decisions that came back were'} kept or changed in the last ${d} days`);
598
+ console.log(String(n));
599
+ process.exit(0);
600
+ }
601
+ const days = i > 0 ? Math.max(1, +a[i + 1] || 7) : 7;
336
602
  const n = loggedCount(read(root).rows, { days });
337
603
  console.log(`${TAG} ${n} decision ${n === 1 ? 'line was' : 'lines were'} logged from presses in the last ${days} days and not undone`);
338
604
  console.log(String(n));
@@ -10,6 +10,12 @@
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
12
  * pmos decisions undo <id> [--json] takes a decision out of the journal (one `undo` line), e.g. one logged from a press
13
+ * pmos decisions undo <id> --step undoes the latest Keep, Change or trigger of a decision (the Undo of Today's Keep)
14
+ * pmos decisions trigger <id> [--threshold "<text>"] [--review <date|+30d>] [--metric "<goal id> < <number>"] | --off
15
+ * when the decision comes back on Today (decisions-come-back); add takes the same three
16
+ * pmos decisions keep <id> [--next <date|+30d>] it came back and still holds: look again on the next date (the same gap again by default)
17
+ * pmos decisions change <id> "<new decision>" --changed-mind "<what changed>" [--expect "<text>"] it came back and no longer holds
18
+ * pmos decisions back-days [0|30|60|90|180] the days after which a decision dropped with a reason comes back (Settings, default 90)
13
19
  * every command: [--root <dir>] (default: this repository)
14
20
  *
15
21
  * 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:
@@ -19,9 +25,9 @@ const path = require('path');
19
25
  const { execFileSync } = require('child_process');
20
26
  const J = require('./decision-journal.js');
21
27
 
22
- const COMMANDS = { decisions: ['add', 'list', 'show', 'check', 'record', 'undo'] };
28
+ const COMMANDS = { decisions: ['add', 'list', 'show', 'check', 'record', 'undo', 'trigger', 'keep', 'change', 'back-days'] };
23
29
  const USAGE = [
24
- 'usage: pmos decisions add|list|show|check|record — a decision journal: each decision has an expected outcome and a date to check it',
30
+ 'usage: pmos decisions add|list|show|check|record|trigger|keep|change — a decision journal: each decision has an expected outcome and a date to check it',
25
31
  ' pmos decisions add "<what was decided>" --expect "<what should happen>" [--check <YYYY-MM-DD|+30d>] [--why "<text>"] [--against "<who disagreed, and why>"] [--initiative <id>]',
26
32
  ' pmos decisions add "<new decision>" --expect "<text>" --replaces <id> --changed-mind "<the evidence that changed your mind>"',
27
33
  ' pmos decisions list [--all] [--json] due checks first, then the open ones',
@@ -29,11 +35,16 @@ const USAGE = [
29
35
  ' pmos decisions check <id> <worked|didnt-work|cant-tell> --evidence "<text>" [--again <date>] your verdict on a decision',
30
36
  ' pmos decisions record [--json] how your decisions turned out, per quarter',
31
37
  ' pmos decisions undo <id> [--json] take a decision out of the journal, for example one logged from a press',
38
+ ' pmos decisions trigger <id> [--threshold "<line it must hold>"] [--review <date|+30d>] [--metric "<goal id> < <number>"] | --off when it comes back',
39
+ ' pmos decisions keep <id> [--next <date|+30d>] it came back and still holds; undo with: pmos decisions undo <id> --step',
40
+ ' pmos decisions change <id> "<new decision>" --changed-mind "<what changed>" [--expect "<text>"]',
41
+ ' pmos decisions back-days [0|30|60|90|180] the days after which a dropped decision comes back (default 90)',
32
42
  'Run it in the product\'s repository, or pass --root <dir>. The check date is 30 days after the decision unless --check says otherwise.',
33
43
  ];
34
44
  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' };
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'] };
36
- const BOOL = new Set(['json', 'all']);
45
+ const ALLOWED = { add: ['json', 'root', 'expect', 'check', 'why', 'against', 'initiative', 'replaces', 'changed-mind', 'threshold', 'review', 'metric'], list: ['json', 'root', 'all'], show: ['json', 'root'], check: ['json', 'root', 'evidence', 'again'], record: ['json', 'root'], undo: ['json', 'root', 'step'],
46
+ trigger: ['json', 'root', 'threshold', 'review', 'metric', 'off'], keep: ['json', 'root', 'next'], change: ['json', 'root', 'changed-mind', 'expect'], 'back-days': ['json'] };
47
+ const BOOL = new Set(['json', 'all', 'step', 'off']);
37
48
 
38
49
  function parse(args) {
39
50
  const pos = [], flags = {};
@@ -60,13 +71,20 @@ function line(e) {
60
71
  : e.state === 'checked' ? `${J.VERDICT_WORDS[e.verdict.verdict]} (${short(e.verdict.date)})`
61
72
  : e.state === 'logged' ? `${FROM_WORDS[e.from] || 'logged'} on ${short(e.date)}`
62
73
  : `reversed by ${e.replacedBy}`;
63
- return ` ${e.id} — ${e.decided}\n ${e.expected ? 'expected: ' + e.expected + ' · ' : ''}${when}`;
74
+ return ` ${e.id} — ${e.decided}\n ${e.expected ? 'expected: ' + e.expected + ' · ' : ''}${when}${e.back ? ' · back now: ' + e.back.why : e.trigger && e.trigger.review_on ? ' · comes back ' + short(e.trigger.review_on) : ''}`;
75
+ }
76
+ const trig = (t) => t ? { threshold: t.threshold || null, review_on: t.review_on || null, metric: t.metric || null, drafted: !!t.drafted, source: t.source || null } : null;
77
+ function trigWords(t) {
78
+ if (!t) return 'no review trigger';
79
+ return [t.threshold ? `holds while it never ${t.threshold}` : '', t.review_on ? `comes back ${short(t.review_on)}` : '', t.metric ? `or when ${J.metricWords(t.metric)}` : ''].filter(Boolean).join(' · ')
80
+ + (t.drafted ? ` (drafted by PMOS from ${t.source}; set your own with pmos decisions trigger)` : '');
64
81
  }
65
82
  const FROM_WORDS = { approval: 'approved', card: 'picked on a card', drop: 'dropped with a reason', park: 'parked with a reason' };
66
83
  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,
67
84
  initiative: e.initiative || null, replaces: e.replaces || null, changed_mind: e.changed_mind || null, replaced_by: e.replacedBy || null, replaced_why: e.replacedWhy || null,
68
85
  verdict: e.verdict ? { verdict: e.verdict.verdict, evidence: e.verdict.evidence, date: e.verdict.date } : null,
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 });
86
+ 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,
87
+ trigger: trig(e.trigger), back: e.back || null, reviews: (e.reviews || []).map((r) => ({ choice: r.choice, at: r.at, ...(r.next ? { next: r.next } : {}), ...(r.to ? { to: r.to } : {}) })) });
70
88
 
71
89
  async function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now(), isTTY } = {}) {
72
90
  const args = argv[0] === 'decisions' ? argv.slice(1) : argv.slice();
@@ -84,7 +102,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
84
102
  if (pos.length !== 1) return fail('usage: pmos decisions add "<what was decided>" --expect "<what should happen>" (put the decision in quotes)', 2);
85
103
  const a = actor();
86
104
  const r = J.add(root, { decided: pos[0], expected: flags.expect, check: flags.check, why: flags.why, against: flags.against, initiative: flags.initiative,
87
- replaces: flags.replaces, changed_mind: flags['changed-mind'] }, { now, by: a.by, via: a.via });
105
+ replaces: flags.replaces, changed_mind: flags['changed-mind'], threshold: flags.threshold, review: flags.review, metric: flags.metric }, { now, by: a.by, via: a.via });
88
106
  if (!r.ok) return fail(r.error);
89
107
  if (flags.json) { say(JSON.stringify({ ok: true, id: r.id, check: r.line.check, file: r.file })); return 0; }
90
108
  say(`✓ ${r.id}: check on ${short(r.line.check)}${r.line.replaces ? ` · replaces ${r.line.replaces}` : ''} (${r.file}). Commit it to keep it.`);
@@ -92,6 +110,49 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
92
110
  return 0;
93
111
  }
94
112
 
113
+ if (sub === 'back-days') {
114
+ const SS = require('./settings-store.js'), dir = require('./state-root.js').defaultRoot({ env });
115
+ if (pos.length > 1) return fail('usage: pmos decisions back-days [0|30|60|90|180]', 2);
116
+ if (pos.length) {
117
+ const r = SS.set(dir, 'decisions.dropBack', Number(pos[0]));
118
+ if (!r.ok) return fail(r.error || 'back-days is one of 0, 30, 60, 90, 180');
119
+ }
120
+ const v = SS.get(dir, 'decisions.dropBack');
121
+ say(flags.json ? JSON.stringify({ ok: true, days: v }) : v ? `A decision dropped with a reason comes back ${v} days later.` : 'Dropped decisions do not come back by themselves.');
122
+ return 0;
123
+ }
124
+
125
+ if (sub === 'trigger' || sub === 'keep' || sub === 'change') {
126
+ const a = actor(), who = { now, by: a.by, via: a.via, dropBackDays: J.dropBackSetting(env) };
127
+ let r;
128
+ if (sub === 'trigger') {
129
+ if (pos.length !== 1) return fail('usage: pmos decisions trigger <id> [--threshold "<text>"] [--review <date|+30d>] [--metric "<goal id> < <number>"] | --off', 2);
130
+ r = J.setTrigger(root, { id: pos[0], threshold: flags.threshold, review: flags.review, metric: flags.metric, off: !!flags.off }, who);
131
+ } else if (sub === 'keep') {
132
+ if (pos.length !== 1) return fail('usage: pmos decisions keep <id> [--next <date|+30d>]', 2);
133
+ r = J.keep(root, { id: pos[0], next: flags.next }, who);
134
+ } else {
135
+ if (pos.length !== 2) return fail('usage: pmos decisions change <id> "<the new decision>" --changed-mind "<what changed>" (put the new decision in quotes)', 2);
136
+ r = J.change(root, { id: pos[0], decided: pos[1], expected: flags.expect, changed_mind: flags['changed-mind'] }, who);
137
+ }
138
+ if (!r.ok) return fail(r.error);
139
+ if (flags.json) { say(JSON.stringify({ ok: true, id: r.id, ...(r.to ? { to: r.to } : {}), line: r.line, file: r.file })); return 0; }
140
+ if (sub === 'trigger') say(r.line.off ? `✓ ${r.id} will not come back by itself (${r.file}).` : `✓ ${r.id} comes back ${[r.line.review_on ? 'on ' + short(r.line.review_on) : '', r.line.metric ? 'when ' + J.metricWords(r.line.metric) : ''].filter(Boolean).join(' or ')} (${r.file}).`);
141
+ else if (sub === 'keep') say(`✓ Kept ${r.id}${r.line.next ? `; it comes back on ${short(r.line.next)}` : ''}. Undo: pmos decisions undo ${r.id} --step`);
142
+ else say(`✓ ${r.to} replaces ${r.id}. Undo: pmos decisions undo ${r.id} --step`);
143
+ return 0;
144
+ }
145
+
146
+ if (sub === 'undo' && flags.step) {
147
+ if (pos.length !== 1) return fail('usage: pmos decisions undo <id> --step', 2);
148
+ const a = actor();
149
+ const r = J.undoStep(root, { id: pos[0] }, { now, by: a.by, via: a.via });
150
+ if (!r.ok) return fail(r.error);
151
+ if (flags.json) { say(JSON.stringify({ ok: true, id: r.id, undid: r.undid, also: r.also, file: r.file })); return 0; }
152
+ say(`✓ Undid the ${r.undid} on ${r.id}${r.also ? ` and took ${r.also} out` : ''} (${r.file}).`);
153
+ return 0;
154
+ }
155
+
95
156
  if (sub === 'undo') {
96
157
  if (pos.length !== 1) return fail('usage: pmos decisions undo <id>', 2);
97
158
  const a = actor();
@@ -102,7 +163,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
102
163
  return 0;
103
164
  }
104
165
 
105
- const { entries, file } = J.entriesOf(root, { today });
166
+ const { entries, file } = J.entriesOf(root, { today, dropBackDays: J.dropBackSetting(env) });
106
167
 
107
168
  if (sub === 'list') {
108
169
  if (pos.length) return fail('pmos decisions list takes no argument', 2);
@@ -132,6 +193,9 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
132
193
  if (e.replaces) say(` replaces ${e.replaces}: ${e.changed_mind}`);
133
194
  for (const c of e.checks) say(` ${short(c.date)}: ${J.VERDICT_WORDS[c.verdict]} — ${c.evidence}${c.again ? ` (look again on ${short(c.again)})` : ''}`);
134
195
  if (e.replacedBy) say(` reversed by ${e.replacedBy} on ${short(e.replacedAt)}: ${e.replacedWhy}`);
196
+ if (e.state === 'open' || e.state === 'logged' || e.state === 'due') say(' comes back: ' + trigWords(e.trigger));
197
+ for (const r of e.reviews || []) say(` ${short(String(r.at).slice(0, 10))}: ${r.choice === 'keep' ? 'kept' + (r.next ? ', back on ' + short(r.next) : '') : 'changed to ' + r.to}`);
198
+ if (e.back) say(` back now: ${e.back.why}. Keep: pmos decisions keep ${e.id} · Change: pmos decisions change ${e.id} "<new decision>" --changed-mind "<what changed>"`);
135
199
  return 0;
136
200
  }
137
201
 
@@ -47,6 +47,7 @@ const KEYS = Object.freeze({
47
47
  'pmos.routine.kind', 'pmos.routine.scope.v1',
48
48
  'pmos.intel.tiles.off', 'pmos.guide.folded', 'pmos.order.notnow', 'pmos.listen.where',
49
49
  'pmos.home.cardfold', 'pmos-report-orders-hidden', 'cz-live-side',
50
+ 'pmos.pop.five', // the work popup's four toolbar actions, worked out weekly from use (idea A498, pm/pop-cap.js)
50
51
  ]),
51
52
  prefix: Object.freeze(['pmos.board.', 'pmos.pv.tab:', 'pmos.dash.view:', 'cz-vw-fold:']),
52
53
  });
@@ -2124,8 +2124,9 @@ const WRITES = {
2124
2124
  * POST /api/boards/ini-plan-end { ws, board, id, to } → { ok, task, title, from: { due }, to, said } | { ok: true, same: true, said }
2125
2125
  * The plan end is not stored: it is the latest due day of the initiative's PMOS tasks and breakdown items. The open one that sets it
2126
2126
  * today gets `to` as its due day. A Done task that sets it, or no dated task at all, is { ask: true }.
2127
- * POST /api/boards/ini-close-open { ws, board, id } → { ok, closed: [{ task, title, from }], said }
2128
- * Every open PMOS task and breakdown item goes to Done. A Jira ticket is Jira's and is never written here. Undo: tasks/state with
2127
+ * POST /api/boards/ini-close-open { ws, board, id } → { ok, closed: [{ task, title, from }], jira, said }
2128
+ * Every open PMOS task and breakdown item goes to Done. A Jira ticket is Jira's and is never written here: `jira` counts the open
2129
+ * ones left to Jira, and `said` says so. Undo: tasks/state with
2129
2130
  * each `from`.
2130
2131
  * POST /api/boards/ini-reopen { ws, board, id } → { ok, did: 'wontdo' | 'stage', to, undo: { route, body }, said }
2131
2132
  * Won't do: out of Won't do, back to the stage it was in. The last stage: back to the stage of the last move into it, else the stage
@@ -2174,6 +2175,10 @@ Object.assign(WRITES, {
2174
2175
  const f = directFrame(ctx, res, body);
2175
2176
  if (!f) return;
2176
2177
  const open = workOfIni(f.p, body.id).filter((x) => OPEN_STATES.includes(x.state));
2178
+ // the open Jira tickets of the initiative stay Jira's: never written here, counted in the answer (direct-plain-actions C2)
2179
+ let jira = 0;
2180
+ try { jira = itemsOf(f.p.w, f.p.fr, f.p.board, [f.row]).filter((x) => x.src === 'jira' && x.kind !== 'Epic' && x.ini === body.id && x.status !== 'Done').length; } catch { jira = 0; }
2181
+ const left = jira ? ' ' + jira + (jira === 1 ? ' Jira ticket is' : ' Jira tickets are') + ' left to Jira.' : '';
2177
2182
  if (!open.length) return askBack(ctx, res, 'it has no open PMOS task: the open ones are Jira tickets, and Jira owns them');
2178
2183
  const closed = [], failed = [];
2179
2184
  for (const x of open) {
@@ -2181,7 +2186,7 @@ Object.assign(WRITES, {
2181
2186
  if (r.body && r.body.ok !== false) closed.push({ task: x.id, title: x.title, from: x.state }); else failed.push(x.title);
2182
2187
  }
2183
2188
  if (!closed.length) return fail(ctx, res, 500, 'no task was closed: ' + failed.join(', '));
2184
- ctx.json(res, { ok: true, closed, said: closed.length + (closed.length === 1 ? ' task' : ' tasks') + ' closed.' + (failed.length ? ' Not closed: ' + failed.join(', ') + '.' : '') });
2189
+ ctx.json(res, { ok: true, closed, jira, said: closed.length + (closed.length === 1 ? ' task' : ' tasks') + ' closed.' + (failed.length ? ' Not closed: ' + failed.join(', ') + '.' : '') + left });
2185
2190
  },
2186
2191
  '/api/boards/ini-reopen': (ctx, res, body, g) => {
2187
2192
  const f = directFrame(ctx, res, body);
@@ -6,6 +6,7 @@
6
6
  * POST /api/use-log { events } → { ok, wrote } the page side (public/pm/use-log.js), in batches
7
7
  * POST /api/use-log/clear {} → { ok } Clear, in Settings (also forgets what pages showed)
8
8
  * GET /api/use-log/ease → { ok, window, bar, slow, pages } Settings › Use log › Ease check (bet A453, lib/ease-check.js)
9
+ * GET /api/use-log/pop → { ok, counts, span } the work popup's four actions (idea A498, pm/pop-cap.js)
9
10
  * Hide the buttons nobody presses (idea A454; the store and the rule are lib/unused-controls.js):
10
11
  * GET /api/use-log/hidden[?page=] → { ok, hidden: [{ page, control, at }] } the page at load; Settings › Use log
11
12
  * POST /api/use-log/unused { page, present } → { ok, hidden, propose } what the page shows (ids), and the ✦
@@ -25,7 +26,7 @@ const POSTS = ['', 'clear', 'unused', 'hide', 'show', 'decline'];
25
26
  async function handle(req, res, url, ctx) {
26
27
  const send = (status, body) => { ctx.json(res, body, status); return true; };
27
28
  const what = url.pathname.replace(/^\/api\/use-log\/?/, '');
28
- if (!POSTS.includes(what) && what !== 'hidden' && what !== 'ease') return send(404, { ok: false, error: 'no such use-log route' });
29
+ if (!POSTS.includes(what) && what !== 'hidden' && what !== 'ease' && what !== 'pop') return send(404, { ok: false, error: 'no such use-log route' });
29
30
  const dir = ctx.runtimeDir || null;
30
31
  if (what === 'ease') {
31
32
  if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
@@ -33,6 +34,10 @@ async function handle(req, res, url, ctx) {
33
34
  console.log(`[ease-check] read: ${r.pages.length} pages, ${r.slow} slow`);
34
35
  return send(200, { ok: true, ...r });
35
36
  }
37
+ if (what === 'pop') {
38
+ if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
39
+ return send(200, { ok: true, ...UL.pop(UL.readLines(dir)) });
40
+ }
36
41
  if (what === '' && req.method === 'GET') return send(200, { ok: true, ...UL.summary(UL.readLines(dir)) });
37
42
  if (what === 'hidden') {
38
43
  if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
@@ -109,6 +109,9 @@ const DEFS = Object.freeze({
109
109
  // report-reader-review: PMOS reads each report draft as the CFO, the engineer and the sceptic and files their questions under the ✦
110
110
  // (lib/report-readers.js). On by default (Wawan, 2026-11-24: "Yes, on every report draft").
111
111
  'critic.reports': one('checks', 'computer', ['on', 'off'], 'on'),
112
+ // decisions-come-back: the days after which a decision dropped with a reason comes back on Today (0: never). 90 by default (2026-11-24).
113
+ // `pmos decisions back-days [n]` reads and sets it (lib/decision-journal.js dropBackSetting).
114
+ 'decisions.dropBack': one('checks', 'computer', [0, 30, 60, 90, 180], 90),
112
115
  // Background use with no dollar limit (Wawan 2026-11-17: the runs use the subscription plan). On: the step-5 spend hold never holds
113
116
  // (lib/bg-queue.js spendHold); the usage-limit hold a failed run leaves is the brake. `pmos grill cap unlimited` sets it.
114
117
  'ai.unlimited': bool('checks', 'computer', false),
@@ -25,7 +25,9 @@
25
25
  * node lib/use-log.js keys [--days 7] → [action-keys] used n, [action-keys] missed n, then the hit percent on its last line
26
26
  * node lib/use-log.js control <id> [--days 7] → the uses of one control on its last line (day-tint: bet A339's health number)
27
27
  * node lib/use-log.js focus [--days 7] → [focus-mode] entered n, [focus-mode] missed n, then the hit percent on its last line (bet A335)
28
- * focus(lines, days, now) → { entered, missed, pct } PURE, focus mode (bet A335) */
28
+ * focus(lines, days, now) → { entered, missed, pct } PURE, focus mode (bet A335)
29
+ * pop(lines, now) → { counts: { who: n, … }, span } PURE, the work popup's actions (idea A498, pm/pop-cap.js): the `pop-<action>` presses
30
+ * of the last KEEP_DAYS days, and span = the whole days the log covers (the four are worked out only at 30 or more) */
29
31
  const fs = require('fs');
30
32
  const path = require('path');
31
33
 
@@ -171,6 +173,21 @@ function controlCount(lines, control, days = 7, now = Date.now()) {
171
173
  }
172
174
  module.exports.controlCount = controlCount;
173
175
 
176
+ /** PURE: the work popup's action presses (idea A498): counts per action over the last KEEP_DAYS days, and the days of use the log covers. */
177
+ function pop(lines, now = Date.now()) {
178
+ const from = now - KEEP_DAYS * DAY, counts = {};
179
+ let first = Infinity;
180
+ for (const l of lines || []) {
181
+ const t = Date.parse(l && l.at);
182
+ if (!(t >= from)) continue;
183
+ if (t < first) first = t;
184
+ const m = l.kind === 'use' && /^pop-([a-z]{1,20})$/.exec(l.control || '');
185
+ if (m) counts[m[1]] = (counts[m[1]] || 0) + 1;
186
+ }
187
+ return { counts, span: first === Infinity ? 0 : Math.floor((now - first) / DAY) };
188
+ }
189
+ module.exports.pop = pop;
190
+
174
191
  if (require.main === module) {
175
192
  const cmd = process.argv[2];
176
193
  const usage = 'usage: node lib/use-log.js count (the distinct days with a line in the last ' + KEEP_DAYS + ' days)\n'
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.792.0",
3
+ "version": "0.794.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.792.0",
9
+ "version": "0.794.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.792.0",
3
+ "version": "0.794.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",