create-pmos 0.683.0 → 0.685.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.683.0",
3
+ "version": "0.685.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -33,6 +33,25 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.685.0",
38
+ "at": "2026-11-22T08:45:20.465Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1497,
43
+ "t": "A decision journal with dated outcome checks (A331)",
44
+ "s": "A decision journal with dated outcome checks (A331)",
45
+ "k": "new"
46
+ },
47
+ {
48
+ "n": 1495,
49
+ "t": "A daily standup digest from the tracker",
50
+ "s": "A daily standup digest from the tracker",
51
+ "k": "new"
52
+ }
53
+ ]
54
+ },
36
55
  {
37
56
  "v": "0.683.0",
38
57
  "at": "2026-11-22T08:20:39.884Z",
@@ -369,19 +388,6 @@
369
388
  "k": "new"
370
389
  }
371
390
  ]
372
- },
373
- {
374
- "v": "0.648.0",
375
- "at": "2026-11-20T05:58:53.312Z",
376
- "f": 4,
377
- "prs": [
378
- {
379
- "n": 1430,
380
- "t": "Work's This sprint tab holds all work in the sprint's dates",
381
- "s": "Work's This sprint tab holds all work in the sprint's dates",
382
- "k": "new"
383
- }
384
- ]
385
391
  }
386
392
  ]
387
393
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@9303acc0
1
+ kernel-source: pmos@2d2c3eed
2
2
  assembled: 2026-11-22
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-22T08:20:37Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:45:16Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-22T08:20:37Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:45:16Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-22T08:20:37Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:45:16Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,23 @@
1
1
  [
2
+ {
3
+ "v": "0.685.0",
4
+ "at": "2026-11-22T08:45:20.465Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1497,
9
+ "t": "A decision journal with dated outcome checks (A331)",
10
+ "s": "A decision journal with dated outcome checks (A331)",
11
+ "k": "new"
12
+ },
13
+ {
14
+ "n": 1495,
15
+ "t": "A daily standup digest from the tracker",
16
+ "s": "A daily standup digest from the tracker",
17
+ "k": "new"
18
+ }
19
+ ]
20
+ },
2
21
  {
3
22
  "v": "0.683.0",
4
23
  "at": "2026-11-22T08:20:39.884Z",
@@ -276,6 +276,18 @@ Run them in the product's repository, or pass `--root <dir>`.
276
276
  - When you record `didnt-work`, the initiative shows **At risk** on every page, with the check as the reason. PMOS compares the evidence with the kill condition and files one next step under the initiative's ✦. If the evidence meets the kill condition, PMOS suggests that you stop the initiative. If this is the second check that did not work, it suggests a new experiment. Otherwise it suggests one more round with a new check date. The Board's Next column asks you the same question. Nothing happens until you press ✓. Undo reverses the step.
277
277
  - `pmos outcomes propose` also reads the experiment's hypothesis. When the hypothesis names a different KR from the initiative's anchor, the draft tells you.
278
278
 
279
+ ### pmos decisions: a decision journal
280
+
281
+ Write one line for each product decision, also one that is smaller than an initiative. Each decision has an expected outcome and a date to check it. Run the commands in the product's repository, or pass `--root <dir>`. The journal is `decision-journal.jsonl` in the runs folder (`pmos/state/` in a product, `planning/runs/` in PMOS itself). Commit it to keep it.
282
+
283
+ - `pmos decisions add "<what was decided>" --expect "<what should happen>"` adds a decision. The check date is 30 days later. `--check <YYYY-MM-DD>` or `--check +2w` sets another date. `--why "<text>"`, `--against "<who disagreed, and why>"` and `--initiative <id>` are optional.
284
+ - `pmos decisions add "<new decision>" --expect "<text>" --replaces <id> --changed-mind "<evidence>"` reverses an earlier decision. You must say what evidence changed your mind. The old decision then shows as reversed and is not checked.
285
+ - `pmos decisions list` shows the checks that are due, then the open decisions. `--all` also shows the closed ones.
286
+ - `pmos decisions show <id>` shows one decision, its checks and its reversal.
287
+ - `pmos decisions check <id> <worked|didnt-work|cant-tell> --evidence "<text>"` records your verdict. With `cant-tell`, `--again <date>` sets a new date to look again.
288
+ - `pmos decisions record` shows how your decisions turned out: for each quarter, the decisions that worked, did not work and could not be told, and the hit rate (worked divided by worked plus did not work). It also shows the reversals and their reasons.
289
+ - On the check date, the decision shows on Today as a gate that waits for you, with the command to record the verdict. PMOS never records a verdict for you.
290
+
279
291
  ### pmos rehearse: rehearse a change
280
292
 
281
293
  - `pmos rehearse move <task> --by <days>` — the task moves later by whole days, or earlier with a minus (`--by -2`).
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+ /* decision-journal-needs.js — the needs provider of the decision journal (initiative decision-journal-outcome-checks, done test C4).
3
+ * lib/needs-providers.js folds these rows into server.js deriveNeeds, and from there into /api/needs and Today.
4
+ *
5
+ * kinds: decision-check
6
+ * rowsFor(w, { lead }) → rows · sig(w) → string
7
+ *
8
+ * decision-check one row per journal decision whose check date is today or past, with no verdict (lib/decision-journal.js fold, state
9
+ * `due`). Kind 1 (a gate is owed). The act is the command that records the verdict. The row goes when a verdict is
10
+ * recorded, when cant-tell moves the date, or when a later decision replaces it.
11
+ *
12
+ * The journal is repository-wide, so a tree that is not the lead returns []. Nothing here writes or sends. */
13
+ const J = require('./decision-journal.js');
14
+
15
+ const NAME = 'decision-journal-needs';
16
+ const clip = (s, n) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
17
+
18
+ function rowsFor(w, { lead } = {}) {
19
+ if (!lead || !w || !w.root) return [];
20
+ const { entries, file } = J.entriesOf(w.root, { today: J.todayOf() });
21
+ return entries.filter((e) => e.state === 'due').map((e) => {
22
+ const cause = `Did it work? You decided: ${clip(e.decided, 140)}. You expected: ${clip(e.expected, 140)}.`;
23
+ return {
24
+ run_id: `${NAME}:${w.id}:${e.id}`, kind: 'decision-check', initiative_id: e.initiative || null, question: cause, doc: file, ws: w.id,
25
+ today: { kind: 1, source: NAME, cause, evidence: `${file} · check date ${e.check}`,
26
+ act: { label: 'Check', cli: `pmos decisions check ${e.id} worked|didnt-work|cant-tell --evidence "<what shows it>"` } },
27
+ };
28
+ });
29
+ }
30
+ // the date is in the signature: a decision becomes due at midnight with no change to the file
31
+ function sig(w) { return w && w.root ? J.stamp(w.root) + '@' + J.todayOf() : ''; }
32
+
33
+ module.exports = { kinds: ['decision-check'], rowsFor, sig };
@@ -0,0 +1,238 @@
1
+ 'use strict';
2
+ /* decision-journal.js — one line per product decision, with a dated outcome check (initiative decision-journal-outcome-checks, bet A331
3
+ * with A412). THE CORE of `pmos decisions` (lib/decisions-cli.js) and of the Today card a due check makes (lib/decision-journal-needs.js).
4
+ *
5
+ * Decisions are made without a stated expected outcome or a date to look again (A331 proof: 0 of 34 initiative records on 2 products state
6
+ * one), and many decisions are smaller than an initiative, so they have no record at all. The journal holds them in any repository built with
7
+ * PMOS: `decision-journal.jsonl` in the runs folder (PMOS-self: planning/runs/; kit layout: pmos/state/). It is append-only; nothing is
8
+ * rewritten. Two kinds of line:
9
+ * { type: 'decision', id, date, decided, expected, check, why?, against?, initiative?, replaces?, changed_mind?, at, by, via }
10
+ * { type: 'check', id, verdict: worked | didnt-work | cant-tell, evidence, date, again?, at, by, via }
11
+ *
12
+ * read(root) → { rows, file, layout } every line, from the runs folder and (in a kit tree) the state folder
13
+ * fold(rows, { today }) → [entry] one entry per decision, with its state:
14
+ * open the check date is after today
15
+ * due the check date is today or before, and no verdict closes it
16
+ * checked a verdict closes it (worked, didnt-work, or cant-tell with no --again date)
17
+ * replaced a later decision replaces it (a reversal) before a verdict closed it; it leaves the due list
18
+ * An entry: { id, date, decided, expected, check (the date it is due now), why, against, initiative, replaces, changed_mind, replacedBy,
19
+ * replacedWhy, checks: [line], verdict (the closing check line or null), dueAt (the date the closing verdict answered), state, days }
20
+ * add(root, fields, { now, by, via }) → { ok, id, line, file } | { ok: false, error }
21
+ * check(root, { id, verdict, evidence, again }, { now, by, via }) → { ok, line, file } | { ok: false, error }
22
+ * record(entries, { today }) → { quarters: [{ quarter, worked, didnt, cantTell, hitRate }], total, worked, didnt, cantTell, hitRate,
23
+ * onTime, due, open, reversals: [{ id, decided, replacedBy, why }] }
24
+ * checkDate(text, today) → 'YYYY-MM-DD' | null a date, or +N d / w / m from today
25
+ *
26
+ * A verdict is the PM's: PMOS never records one from a metric alone, and every verdict carries evidence. Nothing here sends anything.
27
+ */
28
+ const fs = require('fs');
29
+ const path = require('path');
30
+
31
+ const FILE = 'decision-journal.jsonl';
32
+ const DAY = 86400000;
33
+ const DEFAULT_DAYS = 30;
34
+ const ON_TIME_DAYS = 7;
35
+ const VERDICTS = Object.freeze(['worked', 'didnt-work', 'cant-tell']);
36
+ const VERDICT_WORDS = Object.freeze({ worked: 'worked', 'didnt-work': "didn't work", 'cant-tell': "can't tell" });
37
+ const ID_RE = /^[a-z0-9][a-z0-9._-]{0,79}$/;
38
+ const MAX = { decided: 300, expected: 300, why: 600, against: 600, evidence: 1000, changed: 600 };
39
+
40
+ const one = (s) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim();
41
+ const isDate = (s) => /^\d{4}-\d{2}-\d{2}$/.test(String(s || '')) && Number.isFinite(Date.parse(s + 'T00:00:00Z'));
42
+ const todayOf = (now = Date.now()) => new Date(now).toISOString().slice(0, 10);
43
+ const addDays = (day, n) => new Date(Date.parse(day + 'T00:00:00Z') + n * DAY).toISOString().slice(0, 10);
44
+ const daysBetween = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(a + 'T00:00:00Z')) / DAY);
45
+ const quarterOf = (d) => (isDate(d) ? d.slice(0, 4) + '-Q' + (Math.floor((+d.slice(5, 7) - 1) / 3) + 1) : '');
46
+ const rel = (root, f) => path.relative(root, f).split(path.sep).join('/');
47
+
48
+ function layoutOf(root) {
49
+ try { const l = require('./console-state').loadEngine(); if (l.ok) return l.engine.layout(root); } catch { /* fall through */ }
50
+ const kit = fs.existsSync(path.join(root, 'pmos', 'state'));
51
+ return { root, kit, runsDir: kit ? path.join(root, 'pmos', 'state') : path.join(root, 'planning', 'runs') };
52
+ }
53
+
54
+ /** The journal files a repository may hold, the one this module writes first. */
55
+ function filesOf(root) {
56
+ const L = layoutOf(root);
57
+ return { layout: L, file: path.join(L.runsDir, FILE), all: [...new Set([path.join(L.runsDir, FILE), path.join(root, 'pmos', 'state', FILE), path.join(root, 'planning', 'runs', FILE)])] };
58
+ }
59
+
60
+ function read(root) {
61
+ root = path.resolve(root);
62
+ const F = filesOf(root);
63
+ const rows = [];
64
+ for (const f of F.all) {
65
+ let text = '';
66
+ try { text = fs.readFileSync(f, 'utf8'); } catch { continue; }
67
+ for (const s of text.split('\n')) { if (!s.trim()) continue; try { const o = JSON.parse(s); if (o && typeof o === 'object' && !Array.isArray(o)) rows.push(o); } catch { /* a torn line is skipped */ } }
68
+ }
69
+ rows.sort((a, b) => String(a.at || '').localeCompare(String(b.at || '')));
70
+ return { rows, file: F.file, layout: F.layout };
71
+ }
72
+
73
+ /** A check date from text: YYYY-MM-DD, or +N d|w|m (days, weeks, months of 30 days) from today. */
74
+ function checkDate(text, today) {
75
+ const t = one(text).toLowerCase();
76
+ if (isDate(t)) return t;
77
+ const m = /^\+?(\d{1,3})\s*(d|day|days|w|week|weeks|m|month|months)$/.exec(t);
78
+ if (!m || !isDate(today)) return null;
79
+ const n = +m[1] * (m[2][0] === 'w' ? 7 : m[2][0] === 'm' ? 30 : 1);
80
+ return n > 0 ? addDays(today, n) : null;
81
+ }
82
+
83
+ function fold(rows, { today = todayOf() } = {}) {
84
+ const by = new Map();
85
+ for (const r of rows || []) {
86
+ if (!r || r.type !== 'decision' || typeof r.id !== 'string' || by.has(r.id)) continue;
87
+ 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
+ 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 || '' });
90
+ }
91
+ for (const r of rows || []) {
92
+ if (!r || r.type !== 'check') continue;
93
+ const e = by.get(r.id);
94
+ if (!e || !VERDICTS.includes(r.verdict)) continue;
95
+ e.checks.push(r);
96
+ if (r.verdict === 'cant-tell' && isDate(r.again)) { e.verdict = null; e.check = r.again; continue; }
97
+ e.verdict = r; e.dueAt = e.check;
98
+ }
99
+ for (const e of by.values()) {
100
+ if (!e.replaces || !by.has(e.replaces)) continue;
101
+ const old = by.get(e.replaces);
102
+ if (!old.replacedBy) { old.replacedBy = e.id; old.replacedWhy = e.changed_mind; old.replacedAt = e.date; }
103
+ }
104
+ const out = [...by.values()];
105
+ for (const e of out) {
106
+ e.state = e.verdict ? 'checked' : e.replacedBy ? 'replaced' : isDate(e.check) && e.check <= today ? 'due' : 'open';
107
+ e.days = isDate(e.check) && isDate(today) ? daysBetween(e.check, today) : 0; // > 0: days past the check date
108
+ }
109
+ return out;
110
+ }
111
+
112
+ const ORDER = { due: 0, open: 1, checked: 2, replaced: 3 };
113
+ /** Due checks first (oldest first), then open ones by check date, then the closed ones, newest first. */
114
+ function sorted(entries) {
115
+ 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)))
117
+ || a.id.localeCompare(b.id));
118
+ }
119
+
120
+ function slugOf(text) {
121
+ const w = one(text).toLowerCase().replace(/[^a-z0-9\s-]/g, ' ').split(/\s+/).filter((x) => x && !/^(the|a|an|to|of|and|we|i|will|for|on|in)$/.test(x)).slice(0, 5);
122
+ return (w.join('-') || 'decision').slice(0, 48).replace(/-+$/, '');
123
+ }
124
+
125
+ function append(file, line) {
126
+ fs.mkdirSync(path.dirname(file), { recursive: true });
127
+ const st = (() => { try { return fs.lstatSync(file); } catch { return null; } })();
128
+ if (st && !st.isFile()) throw new Error('the decision journal is not a plain file');
129
+ fs.appendFileSync(file, JSON.stringify(line) + '\n');
130
+ }
131
+
132
+ function add(root, f = {}, { now = Date.now(), by, via } = {}) {
133
+ root = path.resolve(root);
134
+ const today = todayOf(now);
135
+ const decided = one(f.decided), expected = one(f.expected);
136
+ if (decided.length < 8) return { ok: false, error: 'say what was decided, in a few words (at least 8 characters)' };
137
+ if (expected.length < 8) return { ok: false, error: 'say what you expect to happen because of it (--expect, at least 8 characters): a decision with no expected outcome cannot be checked' };
138
+ if (decided.length > MAX.decided || expected.length > MAX.expected) return { ok: false, error: `keep the decision and the expected outcome under ${MAX.decided} characters each` };
139
+ let check = addDays(today, DEFAULT_DAYS);
140
+ if (f.check != null && f.check !== '') {
141
+ check = checkDate(f.check, today);
142
+ if (!check) return { ok: false, error: '--check is a date (YYYY-MM-DD) or a time from today (+30d, +2w, +3m)' };
143
+ if (check <= today) return { ok: false, error: 'the check date must be after today: an outcome needs time to show' };
144
+ }
145
+ const why = one(f.why), against = one(f.against), initiative = one(f.initiative), replaces = one(f.replaces), changed = one(f.changed_mind);
146
+ 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' };
147
+ if (initiative && !ID_RE.test(initiative)) return { ok: false, error: '--initiative takes the initiative\'s id' };
148
+ const J = read(root);
149
+ const E = fold(J.rows, { today });
150
+ if (replaces) {
151
+ const old = E.find((e) => e.id === replaces);
152
+ if (!old) return { ok: false, error: `no decision ${replaces} in this journal (pmos decisions list shows the ids)` };
153
+ if (old.replacedBy) return { ok: false, error: `${replaces} was already replaced by ${old.replacedBy}` };
154
+ if (changed.length < 12) return { ok: false, error: 'a reversal says what changed your mind (--changed-mind, at least 12 characters): the evidence, not only the new view' };
155
+ } else if (changed) return { ok: false, error: '--changed-mind goes with --replaces <id>' };
156
+ const base = today.replace(/-/g, '') + '-' + slugOf(decided);
157
+ let id = base, n = 2;
158
+ const have = new Set(E.map((e) => e.id));
159
+ while (have.has(id)) id = base + '-' + n++;
160
+ const line = { type: 'decision', id, date: today, decided, expected, check, ...(why ? { why } : {}), ...(against ? { against } : {}),
161
+ ...(initiative ? { initiative } : {}), ...(replaces ? { replaces, changed_mind: changed } : {}), at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
162
+ 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) }; }
163
+ return { ok: true, id, line, file: rel(root, J.file) };
164
+ }
165
+
166
+ function check(root, { id, verdict, evidence, again } = {}, { now = Date.now(), by, via } = {}) {
167
+ root = path.resolve(root);
168
+ const today = todayOf(now);
169
+ if (!VERDICTS.includes(verdict)) return { ok: false, error: 'the verdict is worked, didnt-work or cant-tell' };
170
+ const ev = one(evidence);
171
+ if (ev.length < 12) return { ok: false, error: 'say what shows it (--evidence, at least 12 characters): a number, a link or what you saw' };
172
+ if (ev.length > MAX.evidence) return { ok: false, error: `keep the evidence under ${MAX.evidence} characters` };
173
+ let next = '';
174
+ if (again != null && again !== '') {
175
+ if (verdict !== 'cant-tell') return { ok: false, error: '--again goes with cant-tell: a new date to look again' };
176
+ next = checkDate(again, today);
177
+ if (!next || next <= today) return { ok: false, error: '--again is a date after today (YYYY-MM-DD, or +30d, +2w, +3m)' };
178
+ }
179
+ const J = read(root);
180
+ const e = fold(J.rows, { today }).find((x) => x.id === id);
181
+ if (!e) return { ok: false, error: `no decision ${id} in this journal (pmos decisions list shows the ids)` };
182
+ if (e.state === 'checked') return { ok: false, error: `${id} was already checked: ${VERDICT_WORDS[e.verdict.verdict]} on ${e.verdict.date}` };
183
+ const line = { type: 'check', id, verdict, evidence: ev, date: today, ...(next ? { again: next } : {}), at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
184
+ try { append(J.file, line); } catch (err) { return { ok: false, error: 'the decision journal could not be written: ' + String((err && err.message) || err).slice(0, 160) }; }
185
+ return { ok: true, line, file: rel(root, J.file) };
186
+ }
187
+
188
+ const rate = (w, d) => (w + d ? Math.round((100 * w) / (w + d)) : null);
189
+
190
+ /** The track record: how the user's calls turned out, per quarter of the date each check answered. */
191
+ function record(entries, { today = todayOf() } = {}) {
192
+ const q = new Map();
193
+ let worked = 0, didnt = 0, cantTell = 0, acted = 0, onTime = 0;
194
+ for (const e of entries || []) {
195
+ if (e.checks.length) {
196
+ // on time: the first verdict line came within ON_TIME_DAYS of the date the check was first due
197
+ const first = e.checks[0], dueFirst = firstDue(e);
198
+ acted++;
199
+ if (isDate(first.date) && isDate(dueFirst) && daysBetween(dueFirst, first.date) <= ON_TIME_DAYS) onTime++;
200
+ }
201
+ if (!e.verdict) continue;
202
+ const k = quarterOf(e.dueAt || e.verdict.date);
203
+ if (!q.has(k)) q.set(k, { quarter: k, worked: 0, didnt: 0, cantTell: 0 });
204
+ const row = q.get(k);
205
+ if (e.verdict.verdict === 'worked') { row.worked++; worked++; }
206
+ else if (e.verdict.verdict === 'didnt-work') { row.didnt++; didnt++; }
207
+ else { row.cantTell++; cantTell++; }
208
+ }
209
+ const quarters = [...q.values()].sort((a, b) => a.quarter.localeCompare(b.quarter)).map((r) => ({ ...r, hitRate: rate(r.worked, r.didnt) }));
210
+ const reversals = (entries || []).filter((e) => e.replacedBy).map((e) => ({ id: e.id, decided: e.decided, replacedBy: e.replacedBy, why: e.replacedWhy, date: e.replacedAt }));
211
+ return { total: (entries || []).length, worked, didnt, cantTell, hitRate: rate(worked, didnt), quarters,
212
+ onTime: acted ? Math.round((100 * onTime) / acted) : null, acted,
213
+ due: (entries || []).filter((e) => e.state === 'due').length, open: (entries || []).filter((e) => e.state === 'open').length, reversals, today };
214
+ }
215
+ /** The date a decision was first due: its decision line's check date (a cant-tell --again only moves it later). */
216
+ function firstDue(e) { return e._check0 || e.check; }
217
+
218
+ /** fold() keeps the moved date in `check`; remember the first one for the on-time count. */
219
+ function foldWithFirst(rows, opts) {
220
+ const first = new Map();
221
+ for (const r of rows || []) if (r && r.type === 'decision' && r.id && !first.has(r.id)) first.set(r.id, r.check);
222
+ return fold(rows, opts).map((e) => Object.assign(e, { _check0: first.get(e.id) || e.check }));
223
+ }
224
+
225
+ /** Every entry of a repository's journal, sorted for a reader. */
226
+ function entriesOf(root, { today = todayOf() } = {}) {
227
+ const J = read(root);
228
+ return { entries: sorted(foldWithFirst(J.rows, { today })), file: rel(path.resolve(root), J.file) };
229
+ }
230
+
231
+ /** A signature that changes when a journal file changes. */
232
+ function stamp(root) {
233
+ const out = [];
234
+ for (const f of filesOf(path.resolve(root)).all) { try { const st = fs.statSync(f); out.push(st.mtimeMs + ':' + st.size); } catch { /* none */ } }
235
+ return out.join('|');
236
+ }
237
+
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 };
@@ -0,0 +1,152 @@
1
+ 'use strict';
2
+ /* decisions-cli.js — `pmos decisions`: a decision journal with dated outcome checks (initiative decision-journal-outcome-checks; lib/decision-journal.js).
3
+ *
4
+ * pmos decisions add "<what was decided>" --expect "<what should happen>" [--check <YYYY-MM-DD|+30d>] [--why "<text>"]
5
+ * [--against "<who disagreed, and why>"] [--initiative <id>] [--replaces <id> --changed-mind "<evidence>"]
6
+ * one line in the journal; the check date is 30 days later unless --check says otherwise
7
+ * pmos decisions list [--all] [--json] due checks first, then the open ones; --all adds the checked and replaced ones
8
+ * pmos decisions show <id> [--json] one decision, its checks, and the decision that replaced it
9
+ * pmos decisions check <id> <worked|didnt-work|cant-tell> --evidence "<text>" [--again <date>]
10
+ * the verdict on a decision; cant-tell --again sets a new date to look again
11
+ * pmos decisions record [--json] the track record: per quarter, worked, didn't work, can't tell and the hit rate
12
+ * every command: [--root <dir>] (default: this repository)
13
+ *
14
+ * 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:
15
+ * never record one from a metric alone. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent.
16
+ */
17
+ const path = require('path');
18
+ const { execFileSync } = require('child_process');
19
+ const J = require('./decision-journal.js');
20
+
21
+ const COMMANDS = { decisions: ['add', 'list', 'show', 'check', 'record'] };
22
+ const USAGE = [
23
+ 'usage: pmos decisions add|list|show|check|record — a decision journal: each decision has an expected outcome and a date to check it',
24
+ ' pmos decisions add "<what was decided>" --expect "<what should happen>" [--check <YYYY-MM-DD|+30d>] [--why "<text>"] [--against "<who disagreed, and why>"] [--initiative <id>]',
25
+ ' pmos decisions add "<new decision>" --expect "<text>" --replaces <id> --changed-mind "<the evidence that changed your mind>"',
26
+ ' pmos decisions list [--all] [--json] due checks first, then the open ones',
27
+ ' pmos decisions show <id> [--json] one decision and its checks',
28
+ ' pmos decisions check <id> <worked|didnt-work|cant-tell> --evidence "<text>" [--again <date>] your verdict on a decision',
29
+ ' pmos decisions record [--json] how your decisions turned out, per quarter',
30
+ '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
+ ];
32
+ 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'] };
34
+ const BOOL = new Set(['json', 'all']);
35
+
36
+ function parse(args) {
37
+ const pos = [], flags = {};
38
+ for (let i = 0; i < args.length; i++) {
39
+ const a = args[i];
40
+ if (!a.startsWith('--')) { pos.push(a); continue; }
41
+ const k = a.slice(2);
42
+ if (BOOL.has(k)) flags[k] = true;
43
+ else flags[k] = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
44
+ }
45
+ return { pos, flags };
46
+ }
47
+ function repoRoot(cwd) {
48
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; }
49
+ }
50
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
51
+ const short = (d) => { const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(d || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] + ' ' + m[1] : String(d || ''); };
52
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
53
+ const pct = (n) => (n == null ? 'no verdict yet' : n + '%');
54
+
55
+ function line(e) {
56
+ const when = e.state === 'due' ? `check due ${e.days > 0 ? 'since ' + short(e.check) : 'today'}`
57
+ : e.state === 'open' ? `check on ${short(e.check)}`
58
+ : e.state === 'checked' ? `${J.VERDICT_WORDS[e.verdict.verdict]} (${short(e.verdict.date)})`
59
+ : `reversed by ${e.replacedBy}`;
60
+ return ` ${e.id} — ${e.decided}\n expected: ${e.expected} · ${when}`;
61
+ }
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,
63
+ 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
+ verdict: e.verdict ? { verdict: e.verdict.verdict, evidence: e.verdict.evidence, date: e.verdict.date } : null,
65
+ 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 });
66
+
67
+ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now(), isTTY } = {}) {
68
+ const args = argv[0] === 'decisions' ? argv.slice(1) : argv.slice();
69
+ const sub = args[0];
70
+ if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
71
+ if (!COMMANDS.decisions.includes(sub)) { say(`unknown decisions command "${sub}". Use one of: ${COMMANDS.decisions.join(', ')}`); return 2; }
72
+ const { pos, flags } = parse(args.slice(1));
73
+ for (const k of Object.keys(flags)) if (!ALLOWED[sub].includes(k)) { say(`✗ --${k} is not an option of pmos decisions ${sub}`); return 2; }
74
+ const root = path.resolve(flags.root || repoRoot(cwd));
75
+ const today = J.todayOf(now);
76
+ const fail = (error, code = 1) => { say(flags.json ? JSON.stringify({ ok: false, error }) : '✗ ' + error); return code; };
77
+ const actor = () => require('./actor.js').fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env });
78
+
79
+ if (sub === 'add') {
80
+ if (pos.length !== 1) return fail('usage: pmos decisions add "<what was decided>" --expect "<what should happen>" (put the decision in quotes)', 2);
81
+ const a = actor();
82
+ const r = J.add(root, { decided: pos[0], expected: flags.expect, check: flags.check, why: flags.why, against: flags.against, initiative: flags.initiative,
83
+ replaces: flags.replaces, changed_mind: flags['changed-mind'] }, { now, by: a.by, via: a.via });
84
+ if (!r.ok) return fail(r.error);
85
+ if (flags.json) { say(JSON.stringify({ ok: true, id: r.id, check: r.line.check, file: r.file })); return 0; }
86
+ say(`✓ ${r.id}: check on ${short(r.line.check)}${r.line.replaces ? ` · replaces ${r.line.replaces}` : ''} (${r.file}). Commit it to keep it.`);
87
+ say(` On that date it shows on Today. Then: pmos decisions check ${r.id} worked|didnt-work|cant-tell --evidence "<what shows it>"`);
88
+ return 0;
89
+ }
90
+
91
+ const { entries, file } = J.entriesOf(root, { today });
92
+
93
+ if (sub === 'list') {
94
+ 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');
96
+ if (flags.json) { say(JSON.stringify({ ok: true, file, total: entries.length, decisions: shown.map(pub) })); return 0; }
97
+ 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`);
100
+ if (due.length) say(`\n${plural(due.length, 'check', 'checks')} due:\n` + due.map(line).join('\n'));
101
+ if (open.length) say('\nOpen:\n' + open.map(line).join('\n'));
102
+ if (rest.length) say('\nClosed:\n' + rest.map(line).join('\n'));
103
+ if (due.length) say('\nRecord a verdict: pmos decisions check <id> worked|didnt-work|cant-tell --evidence "<what shows it>"');
104
+ return 0;
105
+ }
106
+
107
+ if (sub === 'show') {
108
+ if (pos.length !== 1) return fail('usage: pmos decisions show <id>', 2);
109
+ const e = entries.find((x) => x.id === pos[0]);
110
+ if (!e) return fail(`no decision ${pos[0]} in this journal (pmos decisions list shows the ids)`);
111
+ 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}`);
113
+ if (e.why) say(' why: ' + e.why);
114
+ if (e.against) say(' disagreed: ' + e.against);
115
+ if (e.initiative) say(' initiative: ' + e.initiative);
116
+ if (e.replaces) say(` replaces ${e.replaces}: ${e.changed_mind}`);
117
+ 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)})` : ''}`);
118
+ if (e.replacedBy) say(` reversed by ${e.replacedBy} on ${short(e.replacedAt)}: ${e.replacedWhy}`);
119
+ return 0;
120
+ }
121
+
122
+ if (sub === 'check') {
123
+ if (pos.length !== 2) return fail('usage: pmos decisions check <id> <worked|didnt-work|cant-tell> --evidence "<text>"', 2);
124
+ const verdict = VERDICT[String(pos[1]).toLowerCase()];
125
+ if (!verdict) return fail('the verdict is worked, didnt-work or cant-tell', 2);
126
+ const a = actor();
127
+ const r = J.check(root, { id: pos[0], verdict, evidence: flags.evidence, again: flags.again }, { now, by: a.by, via: a.via });
128
+ if (!r.ok) return fail(r.error);
129
+ if (flags.json) { say(JSON.stringify({ ok: true, file: r.file, line: r.line })); return 0; }
130
+ say(`✓ ${pos[0]}: ${J.VERDICT_WORDS[verdict]}${r.line.again ? `, look again on ${short(r.line.again)}` : ''} (${r.file}). Commit it to keep it.`);
131
+ return 0;
132
+ }
133
+
134
+ // record
135
+ if (pos.length) return fail('pmos decisions record takes no argument', 2);
136
+ const R = J.record(entries, { today });
137
+ if (flags.json) {
138
+ say(JSON.stringify({ ok: true, file, total: R.total, worked: R.worked, didnt_work: R.didnt, cant_tell: R.cantTell, hit_rate: R.hitRate, on_time: R.onTime, due: R.due, open: R.open,
139
+ quarters: R.quarters.map((q) => ({ quarter: q.quarter, worked: q.worked, didnt_work: q.didnt, cant_tell: q.cantTell, hit_rate: q.hitRate })), reversals: R.reversals }));
140
+ return 0;
141
+ }
142
+ if (!R.total) { say('No decisions in this journal yet. Add one: pmos decisions add "<what was decided>" --expect "<what should happen>"'); return 0; }
143
+ const checked = R.worked + R.didnt + R.cantTell;
144
+ say(`${plural(R.total, 'decision', 'decisions')} · ${checked} checked · hit rate ${pct(R.hitRate)} (worked ${R.worked}, didn't work ${R.didnt}, can't tell ${R.cantTell})`);
145
+ if (R.quarters.length) say('\nBy quarter of the check date:\n' + R.quarters.map((q) => ` ${q.quarter} hit rate ${pct(q.hitRate)} · worked ${q.worked} · didn't work ${q.didnt} · can't tell ${q.cantTell}`).join('\n'));
146
+ if (R.onTime != null) say(`\n${R.onTime}% of checks were answered within ${J.ON_TIME_DAYS} days of their date.`);
147
+ if (R.due) say(`${plural(R.due, 'check is', 'checks are')} due now: pmos decisions list`);
148
+ if (R.reversals.length) say(`\n${plural(R.reversals.length, 'reversal', 'reversals')}:\n` + R.reversals.map((v) => ` ${v.id} → ${v.replacedBy}: ${v.why}`).join('\n'));
149
+ return 0;
150
+ }
151
+
152
+ module.exports = { run, COMMANDS, USAGE, VERDICT };
@@ -20,6 +20,7 @@
20
20
  * pmos jira moved <move id> --status "<Jira status>" | --refused "<why>" the agent's answer for one move
21
21
  * pmos jira guesses <initiative> [--from <file|->] a ticket dry run (lib/ticket-dry-run.js), recorded or shown
22
22
  * pmos jira answer <initiative> <ticket> <n> --text "<answer>" | --keep-default the PM's answer to one dry-run gap, or its default kept
23
+ * pmos jira digest [--since <YYYY-MM-DD or time>] the standup facts from the stored reads (lib/tracker-digest.js)
23
24
  * pmos jira criteria <initiative> the done-test checks each ticket carries, and the checks on no ticket (A384)
24
25
  * every command: [--json] [--root <dir>]
25
26
  *
@@ -36,7 +37,7 @@ const jiraMoves = require('./jira-moves.js');
36
37
  const planItems = require('./plan-items.js');
37
38
  const guard = require('./pm-guard.js');
38
39
 
39
- const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which', 'moves', 'moved', 'guesses', 'answer', 'criteria'] };
40
+ const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which', 'moves', 'moved', 'guesses', 'answer', 'criteria', 'digest'] };
40
41
  const USAGE = [
41
42
  'usage: pmos jira draft|show|epic|approve|pending|record|query|sync|summary|which — Jira tickets from the PRD, and their status',
42
43
  ' pmos jira draft <initiative> [--dry-run] draft one ticket per PRD item, in the ticket template',
@@ -62,11 +63,12 @@ const USAGE = [
62
63
  ' pmos jira which <KEY> [<KEY> …] the initiative a Jira key belongs to',
63
64
  ' pmos jira moves the status moves asked in PMOS that wait for Jira',
64
65
  ' pmos jira moved <move id> --status "<status>" | --refused "<why>" what Jira did with one move',
66
+ ' pmos jira digest [--since <YYYY-MM-DD or time>] what moved since the last working day, who moved it, and what is worth a question',
65
67
  ' every command: [--json] [--root <dir>]',
66
68
  'This command never calls Jira. Your agent reads and writes Jira with your own connection.',
67
69
  ];
68
70
  const BOOL = new Set(['json', 'dry-run', 'help', 'sprints', 'keep-default']);
69
- const VALUE = new Set(['from', 'query', 'root', 'epic', 'updated', 'group', 'status', 'refused', 'sprint', 'text']);
71
+ const VALUE = new Set(['from', 'query', 'root', 'epic', 'updated', 'group', 'status', 'refused', 'sprint', 'text', 'since']);
70
72
  const FLAG_TEXT = { 'prd-changed': 'PRD changed', removed: 'Removed from PRD', blocked: 'Blocked', incomplete: 'Missing text', pushing: 'Selected, waiting for the push', edited: 'Edited, not in Jira yet' };
71
73
 
72
74
  function parse(argv) {
@@ -126,6 +128,12 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
126
128
  try {
127
129
  if (flags.sprints && verb !== 'query' && verb !== 'sync') return fail('--sprints goes with query or sync', 2);
128
130
  if (flags.sprint != null && verb !== 'query' && verb !== 'sync') return fail('--sprint goes with query or sync', 2);
131
+ if (flags.since != null && verb !== 'digest') return fail('--since goes with digest', 2);
132
+ if (verb === 'digest') {
133
+ const d = require('./tracker-digest.js').gather(root, { now: now == null ? Date.now() : now, since: flags.since || null });
134
+ if (!d.ok) return fail(d.error, 2);
135
+ return out(d, require('./tracker-digest.js').render(d));
136
+ }
129
137
  if (verb === 'query' && flags.sprint != null) {
130
138
  const q = jiraStatus.sprintQueryOne(root, flags.sprint);
131
139
  if (!q.ok) return fail(q.error);
@@ -33,7 +33,8 @@
33
33
  * A task that names a key follows its reading: lib/task-jira.js trackerLines sets its state in memory when the read is newer (no
34
34
  * plan item or ledger line is written, D88 still holds).
35
35
  *
36
- * BOUNDARY (J15). No network module, no child process. The only write is the snapshot file.
36
+ * BOUNDARY (J15). No network module, no child process. The only writes are the snapshot file and the append-only status moves
37
+ * (lib/tracker-digest.js, <state>/tracker/jira/_moves.jsonl) the daily digest folds.
37
38
  */
38
39
  const fs = require('fs');
39
40
  const path = require('path');
@@ -362,7 +363,10 @@ function sync(root, initiative, raw, { query, dryRun = false, now } = {}) {
362
363
  const tmp = `${file}.${process.pid}.tmp`;
363
364
  fs.writeFileSync(tmp, renderSnapshot({ initiative, fetchedAt, query: query || (prev && prev.query) || null, readings, ids }));
364
365
  fs.renameSync(tmp, file);
365
- return { ...result, fetchedAt };
366
+ // the status moves this read saw, kept for the daily digest (daily-digest-from-tracker): the snapshot keeps only the latest state
367
+ const TD = require('./tracker-digest.js');
368
+ const moved = TD.append(root, TD.movesOf(prev ? prev.tickets : null, readings, { at: fetchedAt, initiative }));
369
+ return { ...result, fetchedAt, moved };
366
370
  }
367
371
 
368
372
  // ── the whole sprint (jira-sprint-scope) ─────────────────────────────────────────────────────────────
@@ -439,7 +443,9 @@ function syncSprints(root, raw, { query, dryRun = false, now, backfill = null }
439
443
  const tmp = `${file}.${process.pid}.tmp`;
440
444
  fs.writeFileSync(tmp, renderSnapshot({ initiative: SPRINTS_FILE, title: 'every issue in the sprints', fetchedAt, query: query || (prev && prev.query) || null, readings: kept, ids: new Map() }));
441
445
  fs.renameSync(tmp, file);
442
- return { ...result, fetchedAt };
446
+ const TD = require('./tracker-digest.js'); // the sprint tickets' status moves, for the daily digest
447
+ const moved = TD.append(root, TD.movesOf(prev ? prev.tickets : null, kept, { at: fetchedAt }));
448
+ return { ...result, fetchedAt, moved };
443
449
  }
444
450
  function readSprints(root) { return readSnapshot(root, SPRINTS_FILE); }
445
451
 
@@ -38,6 +38,7 @@ const PROVIDERS = Object.freeze([
38
38
  'report-structure-needs', // report-structure: a Chrome or computer source that failed its check while a draft waits for it (kind 8)
39
39
  'folder-needs', // folder repair: a folder PMOS could not put back on its default branch alone, in one plain sentence (kind 8)
40
40
  'factory-needs', // factory-builder-inner-loop: a work item blocked after the Builder's CI-fix rounds, with the reason (kind 8)
41
+ 'decision-journal-needs', // decision-journal-outcome-checks: a journal decision whose check date came, with no verdict (kind 1)
41
42
  ]);
42
43
  /** Kinds that already mean something in the needs queue. A provider may not reuse one. */
43
44
  const RESERVED_KINDS = Object.freeze(['question', 'accept', 'outcome', 'keep', 'evidence', 'plan-flag', 'provider-error']);
@@ -130,6 +130,9 @@ const VERBS = Object.freeze({
130
130
  // Not a pm-os-absorb verb (run: null): initiative outcome-for-every-initiative added it through the same table.
131
131
  outcomes: Object.freeze({ module: 'outcomes-cli.js', run: null, guide: 'cli.md',
132
132
  help: 'pmos outcomes list|propose|declare|record — every initiative\'s expected outcome and check date: Claude\'s cited drafts, the PM\'s yes, and the verdict when a check is due (pmos outcomes help)' }),
133
+ // Not a pm-os-absorb verb (run: null): initiative decision-journal-outcome-checks added it through the same table.
134
+ decisions: Object.freeze({ module: 'decisions-cli.js', run: null, guide: 'cli.md',
135
+ help: 'pmos decisions add|list|show|check|record — a decision journal: what you decided, what you expect, a date to check, and how your calls turned out (pmos decisions help)' }),
133
136
  // Not a pm-os-absorb verb (run: null): chief-unit-owners (Wawan 2026-11-18) added both through the same table.
134
137
  units: Object.freeze({ module: 'units-cli.js', run: null, guide: 'cli.md',
135
138
  help: 'pmos units [list|show <unit>] — the programs, products and projects, who owns each initiative, and each owner\'s brief (pmos units help)' }),
@@ -0,0 +1,230 @@
1
+ 'use strict';
2
+ /* tracker-digest.js — the standup facts from the tracker, with no meeting (initiative daily-digest-from-tracker; bet A23, proofs A23 and
3
+ * A23-three-products, 2026-11-22).
4
+ *
5
+ * WHY. A standup asks what moved, who moved it and what is blocked. The tracker holds those facts, and PMOS reads it every day
6
+ * (read-tracker-daily). PMOS kept only the latest read, so a move from one read to the next was printed once by `pmos jira sync` and
7
+ * lost. On 22 Nov one Jira search gave the idpf standup, and 7 of the 8 tickets that moved were not in PMOS (40 of 54 on Scarlet).
8
+ *
9
+ * THE FILE. <state>/tracker/jira/_moves.jsonl, append-only, written only by append() (from `pmos jira sync`, one initiative or
10
+ * --sprints). One line per status move a read saw, against the ticket's last reading:
11
+ * { at, k (key), n (title), f (from status), fc (from category), s (to status), c (to category: todo|doing|done), w? (assignee), i? (initiative) }
12
+ * A first read, an unchanged status and a dry run add nothing.
13
+ *
14
+ * movesOf(prev, readings, { at, initiative }) PURE → [line] the status moves between two readings of the same tickets
15
+ * append(root, lines) → number of lines written
16
+ * readMoves(root) → [line]
17
+ * windowOf(now, since) PURE → ISO time the digest starts: --since, else 24 hours back, on Monday 72 hours
18
+ * build({ moves, snapshots, sprints, known, titles, now, since }) PURE → the digest (see DIGEST)
19
+ * gather(root, { now, since }) → build() over the stored reads of one workspace
20
+ * render(digest) PURE → [line of text]
21
+ *
22
+ * DIGEST { since, now, read: false } when no Jira read is stored, else
23
+ * { since, now, read: true, readAt, stale, moved: [{ key, summary, from, to, category, who, group, url, inPmos }],
24
+ * groups: [{ name, items }], untracked: { count, of }, questions: [{ kind, key, text }], more }
25
+ * A ticket's moves in the window fold to one line, first state to last; one back at its first state is left out. A ticket Jira resolved
26
+ * in the window with no move kept (the first day after the release) shows as done, from an unknown state.
27
+ *
28
+ * BOUNDARY. No network, no child process. Reads Jira only through the files the read path saved; writes only the moves file.
29
+ */
30
+ const fs = require('fs');
31
+ const path = require('path');
32
+
33
+ const FILE = '_moves.jsonl';
34
+ const H = 3600 * 1000;
35
+ const DAY = 24 * H;
36
+ const STALE_MS = 26 * H; // the same as lib/task-jira.js: the Jira read is due every day
37
+ const STUCK_DAYS = 5; // in progress with no change for this many days is worth a question
38
+ const MAX_QUESTIONS = 8;
39
+ const OTHER = 'Other work in the sprint';
40
+ const KEY_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
41
+ const isStr = (v) => typeof v === 'string';
42
+ const ms = (v) => { const t = Date.parse(isStr(v) ? v : ''); return Number.isFinite(t) ? t : null; };
43
+ const iso = (t) => new Date(t).toISOString().replace(/\.\d{3}Z$/, 'Z');
44
+
45
+ function jiraDir(root) { return require('./jira-tickets.js').jiraDir(root); }
46
+ function fileOf(root) { return path.join(jiraDir(root), FILE); }
47
+
48
+ // ── keeping the moves ────────────────────────────────────────────────────────────────────────────────
49
+ /** prev: Map key → reading (the last read) or null; readings: the new readings. A move is a status that differs from the last reading. */
50
+ function movesOf(prev, readings, { at, initiative = null } = {}) {
51
+ if (!prev || !prev.size) return [];
52
+ const out = [];
53
+ for (const r of Array.isArray(readings) ? readings : []) {
54
+ if (!r || !r.key || r.stale) continue;
55
+ const was = prev.get(r.key);
56
+ if (!was || was.status === r.status) continue;
57
+ out.push({ at, k: r.key, n: r.summary || '', f: was.status, fc: was.category || null, s: r.status, c: r.category || null,
58
+ ...(r.assignee ? { w: r.assignee } : {}), ...(initiative ? { i: initiative } : {}) });
59
+ }
60
+ return out;
61
+ }
62
+ function append(root, lines) {
63
+ if (!Array.isArray(lines) || !lines.length) return 0;
64
+ const file = fileOf(root);
65
+ fs.mkdirSync(path.dirname(file), { recursive: true });
66
+ fs.appendFileSync(file, lines.map((l) => JSON.stringify(l)).join('\n') + '\n');
67
+ return lines.length;
68
+ }
69
+ function readMoves(root) {
70
+ let text;
71
+ try { text = fs.readFileSync(fileOf(root), 'utf8'); } catch { return []; }
72
+ const out = [];
73
+ for (const l of text.split('\n')) {
74
+ if (!l.trim()) continue;
75
+ let x; try { x = JSON.parse(l); } catch { continue; }
76
+ if (x && isStr(x.k) && KEY_RE.test(x.k) && ms(x.at) != null && isStr(x.s)) out.push(x);
77
+ }
78
+ return out;
79
+ }
80
+
81
+ // ── the window ───────────────────────────────────────────────────────────────────────────────────────
82
+ /** --since as a day (YYYY-MM-DD, from its start) or a time; else 24 hours back, or 72 on a Monday so Friday's moves are in. */
83
+ function windowOf(now, since) {
84
+ if (since != null && since !== '') {
85
+ const s = String(since).trim();
86
+ const t = /^\d{4}-\d{2}-\d{2}$/.test(s) ? ms(s + 'T00:00:00Z') : ms(s);
87
+ if (t == null) return null;
88
+ return iso(t);
89
+ }
90
+ const back = new Date(now).getDay() === 1 ? 3 * DAY : DAY;
91
+ return iso(now - back);
92
+ }
93
+
94
+ // ── the digest ───────────────────────────────────────────────────────────────────────────────────────
95
+ /**
96
+ * moves [line] from readMoves
97
+ * snapshots [{ initiative, fetchedAt, tickets: Map }] each initiative's stored read
98
+ * sprints { fetchedAt, tickets: Map } | null the whole-sprint read
99
+ * known Set of keys PMOS has a task for (named by a task, or pushed by an initiative)
100
+ * titles Map initiative → title
101
+ */
102
+ function build({ moves = [], snapshots = [], sprints = null, known = new Set(), titles = new Map(), now = Date.now(), since = null } = {}) {
103
+ const from = windowOf(now, since);
104
+ if (!from) return { ok: false, error: `--since "${since}" is not a day (YYYY-MM-DD) or a time` };
105
+ const fromMs = ms(from);
106
+ const base = { ok: true, since: from, now: iso(now) };
107
+ const reads = [...snapshots.filter((s) => s && s.tickets), ...(sprints && sprints.tickets ? [{ ...sprints, initiative: null }] : [])];
108
+ if (!reads.length) return { ...base, read: false };
109
+
110
+ // every ticket, from its newest reading; the initiative it belongs to is kept from the initiative's own read
111
+ const R = new Map();
112
+ let readAt = null;
113
+ for (const s of reads) {
114
+ const at = ms(s.fetchedAt) || 0;
115
+ if (s.fetchedAt && (!readAt || s.fetchedAt < readAt)) readAt = s.fetchedAt;
116
+ for (const t of s.tickets.values()) {
117
+ if (!t || !t.key) continue;
118
+ const had = R.get(t.key);
119
+ const ini = (had && had.ini) || s.initiative || null;
120
+ if (!had || at >= had.at) R.set(t.key, { r: t, at, ini });
121
+ else if (!had.ini && ini) had.ini = ini;
122
+ }
123
+ }
124
+ const stale = readAt ? now - ms(readAt) > STALE_MS : true;
125
+
126
+ // the moves in the window, folded per ticket: first state to last
127
+ const inWin = moves.filter((m) => { const t = ms(m.at); return t != null && t >= fromMs && t <= now; })
128
+ .sort((a, b) => ms(a.at) - ms(b.at));
129
+ const byKey = new Map();
130
+ for (const m of inWin) { if (!byKey.has(m.k)) byKey.set(m.k, []); byKey.get(m.k).push(m); }
131
+ const groupOf = (key, ini) => {
132
+ const e = R.get(key);
133
+ const i = ini || (e && e.ini);
134
+ if (i) return titles.get(i) || i;
135
+ const r = e && e.r;
136
+ if (r && (r.parentName || r.parent)) return r.parentName || r.parent;
137
+ return OTHER;
138
+ };
139
+ const moved = [];
140
+ for (const [key, ms_] of byKey) {
141
+ const first = ms_[0]; const last = ms_[ms_.length - 1];
142
+ if (first.f === last.s) continue; // went back to where it started
143
+ const e = R.get(key); const r = e ? e.r : null;
144
+ moved.push({ key, summary: (r && r.summary) || last.n || '', from: first.f, fromCategory: first.fc || null, to: last.s, category: last.c || (r && r.category) || null,
145
+ who: (r && r.assignee) || last.w || null, group: groupOf(key, last.i), url: (r && r.url) || null, inPmos: known.has(key), at: last.at });
146
+ }
147
+ // resolved in the window with no move kept (a ticket first read already done, or the first day after the release)
148
+ // Jira gives the resolution as a day: a ticket with an earlier move kept, or a last update before the window, closed before it.
149
+ const fromDay = from.slice(0, 10);
150
+ const everMoved = new Set(moves.map((m) => m.k));
151
+ for (const [key, e] of R) {
152
+ const r = e.r;
153
+ if (byKey.has(key) || everMoved.has(key) || r.category !== 'done' || !isStr(r.resolved) || r.resolved < fromDay || r.stale) continue;
154
+ if (ms(r.updated) != null && ms(r.updated) < fromMs) continue;
155
+ moved.push({ key, summary: r.summary || '', from: null, fromCategory: null, to: r.status, category: 'done', who: r.assignee || null,
156
+ group: groupOf(key, null), url: r.url || null, inPmos: known.has(key), at: r.resolved });
157
+ }
158
+ // done first, then in progress, then the rest; by key inside
159
+ const rank = { done: 0, doing: 1, todo: 2 };
160
+ moved.sort((a, b) => (rank[a.category] ?? 3) - (rank[b.category] ?? 3) || a.key.localeCompare(b.key, 'en', { numeric: true }));
161
+ const groups = [];
162
+ for (const m of moved) { let g = groups.find((x) => x.name === m.group); if (!g) { g = { name: m.group, items: [] }; groups.push(g); } g.items.push(m); }
163
+ groups.sort((a, b) => (a.name === OTHER) - (b.name === OTHER) || b.items.length - a.items.length || a.name.localeCompare(b.name));
164
+
165
+ // worth a question, the most pressing kind first
166
+ const q = [];
167
+ const seen = new Set();
168
+ const ask = (kind, key, text) => { if (seen.has(kind + key)) return; seen.add(kind + key); q.push({ kind, key, text }); };
169
+ for (const [key, e] of R) { const r = e.r; if (r.flagged && r.category !== 'done' && !r.stale) ask('blocked', key, `${key} is blocked${r.reason ? ` (${r.reason})` : ''}. Who can unblock it?`); }
170
+ for (const m of moved) if (m.fromCategory === 'done' && m.category !== 'done') ask('reopened', m.key, `${m.key} went from ${m.from} back to ${m.to}. Why was it reopened?`);
171
+ for (const m of moved) if (!m.who) ask('unassigned', m.key, `${m.key} moved to ${m.to} with nobody assigned. Who did it?`);
172
+ const stuck = [];
173
+ for (const [key, e] of R) {
174
+ const r = e.r; const up = ms(r.updated);
175
+ if (r.category !== 'doing' || r.stale || up == null) continue;
176
+ const days = Math.floor((now - up) / DAY);
177
+ if (days >= STUCK_DAYS) stuck.push({ key, days, r });
178
+ }
179
+ stuck.sort((a, b) => b.days - a.days);
180
+ for (const s of stuck) ask('stuck', s.key, `${s.key} has been ${s.r.status} with no change for ${s.days} days${s.r.assignee ? ` (${s.r.assignee})` : ''}.`);
181
+ for (const [key, e] of R) if (e.r.stale) ask('missing', key, `${key} was not in the last Jira read. Was it moved to another project or deleted?`);
182
+ const untracked = { count: moved.filter((m) => !m.inPmos).length, of: moved.length };
183
+ return { ...base, read: true, readAt, stale, moved, groups, untracked, questions: q.slice(0, MAX_QUESTIONS), more: Math.max(0, q.length - MAX_QUESTIONS) };
184
+ }
185
+
186
+ /** The stored reads of one workspace → build(). */
187
+ function gather(root, { now = Date.now(), since = null } = {}) {
188
+ const JS = require('./jira-status.js');
189
+ const JT = require('./jira-tickets.js');
190
+ const TJ = require('./task-jira.js');
191
+ const snapshots = []; const titles = new Map(); const known = new Set();
192
+ let byIni = new Map(); try { byIni = TJ.readKeys(root); } catch { byIni = new Map(); }
193
+ for (const keys of byIni.values()) for (const k of keys) known.add(k);
194
+ let linked = []; try { linked = JS.linkedInitiatives(root).filter((x) => x.linked); } catch { linked = []; }
195
+ for (const q of linked) {
196
+ try { for (const k of JT.pushedTickets(root, q.initiative).tickets.keys()) known.add(k); } catch { /* no draft */ }
197
+ const fm = JT.recordFm(root, q.initiative) || {};
198
+ if (isStr(fm.title) && fm.title.trim()) titles.set(q.initiative, fm.title.trim());
199
+ const s = JS.readSnapshot(root, q.initiative);
200
+ if (s) snapshots.push({ initiative: q.initiative, fetchedAt: s.fetchedAt, tickets: s.tickets });
201
+ }
202
+ let sprints = null; try { sprints = JS.readSprints(root); } catch { sprints = null; }
203
+ return build({ moves: readMoves(root), snapshots, sprints, known, titles, now, since });
204
+ }
205
+
206
+ // ── the text ─────────────────────────────────────────────────────────────────────────────────────────
207
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
208
+ const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
209
+ const pad = (n) => String(n).padStart(2, '0');
210
+ function when(v) { const d = new Date(ms(v)); return `${WD[d.getDay()]} ${d.getDate()} ${MON[d.getMonth()]}, ${pad(d.getHours())}:${pad(d.getMinutes())}`; }
211
+ function render(d) {
212
+ if (!d || !d.ok) return [d && d.error ? d.error : 'no digest'];
213
+ if (!d.read) return ['Jira has not been read in this workspace yet, so there is no digest. The daily Jira read starts it.'];
214
+ const out = [`Standup digest since ${when(d.since)}`];
215
+ if (d.stale) out.push(`Jira not read since ${d.readAt ? when(d.readAt) : 'its first read'}. This digest may miss moves.`);
216
+ if (!d.moved.length) out.push(`Nothing moved since ${when(d.since)}.`);
217
+ for (const g of d.groups) {
218
+ out.push('', g.name);
219
+ for (const m of g.items) out.push(` ${m.key} ${m.summary}: ${m.from ? `${m.from} → ${m.to}` : m.to}${m.who ? ` (${m.who})` : ' (nobody assigned)'}${m.inPmos ? '' : ' · no task in PMOS'}`);
220
+ }
221
+ if (d.untracked.count) out.push('', `${d.untracked.count} of ${d.untracked.of} moved tickets have no task in PMOS.`);
222
+ if (d.questions.length) {
223
+ out.push('', 'Worth a question');
224
+ for (const x of d.questions) out.push(` ${x.text}`);
225
+ if (d.more) out.push(` and ${d.more} more`);
226
+ }
227
+ return out;
228
+ }
229
+
230
+ module.exports = { FILE, STALE_MS, STUCK_DAYS, MAX_QUESTIONS, OTHER, fileOf, movesOf, append, readMoves, windowOf, build, gather, render };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.683.0",
3
+ "version": "0.685.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.683.0",
9
+ "version": "0.685.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.683.0",
3
+ "version": "0.685.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",
@@ -0,0 +1,5 @@
1
+ {
2
+ "_comment": "decision-journal-outcome-checks (bet A331 with A412): a decision journal with dated outcome checks. The ledger and its fold, pmos decisions, the Today card from the needs provider, reversals and the track record (lib/decision-journal.js, lib/decisions-cli.js, lib/decision-journal-needs.js).",
3
+ "modules": ["decision-journal.test.js"],
4
+ "seconds": { "decision-journal.test.js": 2 }
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "_comment": "daily-digest-from-tracker: the status moves each Jira read keeps (lib/jira-status.js → <state>/tracker/jira/_moves.jsonl) and the standup digest folded from them and the stored reads (lib/tracker-digest.js, `pmos jira digest`), on a synthetic repository with no network.",
3
+ "modules": ["tracker-digest.test.js"],
4
+ "seconds": { "tracker-digest.test.js": 2 }
5
+ }