create-pmos 0.682.0 → 0.684.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.682.0",
3
+ "version": "0.684.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,32 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.684.0",
38
+ "at": "2026-11-22T08:41:57.186Z",
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
+ },
49
+ {
50
+ "v": "0.683.0",
51
+ "at": "2026-11-22T08:20:39.884Z",
52
+ "f": 4,
53
+ "prs": [
54
+ {
55
+ "n": 1494,
56
+ "t": "Acceptance criteria on each ticket, written from the done test",
57
+ "s": "Acceptance criteria on each ticket, written from the done test",
58
+ "k": "new"
59
+ }
60
+ ]
61
+ },
36
62
  {
37
63
  "v": "0.682.0",
38
64
  "at": "2026-11-22T07:57:47.146Z",
@@ -356,32 +382,6 @@
356
382
  "k": "new"
357
383
  }
358
384
  ]
359
- },
360
- {
361
- "v": "0.648.0",
362
- "at": "2026-11-20T05:58:53.312Z",
363
- "f": 4,
364
- "prs": [
365
- {
366
- "n": 1430,
367
- "t": "Work's This sprint tab holds all work in the sprint's dates",
368
- "s": "Work's This sprint tab holds all work in the sprint's dates",
369
- "k": "new"
370
- }
371
- ]
372
- },
373
- {
374
- "v": "0.647.0",
375
- "at": "2026-11-20T05:31:50.958Z",
376
- "f": 4,
377
- "prs": [
378
- {
379
- "n": 1429,
380
- "t": "Work's Initiatives tab built from design system blocks",
381
- "s": "Work's Initiatives tab built from design system blocks",
382
- "k": "new"
383
- }
384
- ]
385
385
  }
386
386
  ]
387
387
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@2fa031e4
1
+ kernel-source: pmos@299ca86a
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-22T07:57:44Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:41:53Z"}
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-22T07:57:44Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:41:53Z"}
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-22T07:57:44Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:41:53Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,30 @@
1
1
  [
2
+ {
3
+ "v": "0.684.0",
4
+ "at": "2026-11-22T08:41:57.186Z",
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
+ },
15
+ {
16
+ "v": "0.683.0",
17
+ "at": "2026-11-22T08:20:39.884Z",
18
+ "f": 4,
19
+ "prs": [
20
+ {
21
+ "n": 1494,
22
+ "t": "Acceptance criteria on each ticket, written from the done test",
23
+ "s": "Acceptance criteria on each ticket, written from the done test",
24
+ "k": "new"
25
+ }
26
+ ]
27
+ },
2
28
  {
3
29
  "v": "0.682.0",
4
30
  "at": "2026-11-22T07:57:47.146Z",
@@ -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`).
@@ -639,6 +651,7 @@ The benchmark needs a signed-in agent CLI. It never pushes and never opens a pul
639
651
  - `pmos jira moved <move id> --status "<Jira status>"` or `--refused "<why>"`
640
652
  - `pmos jira guesses <initiative> [--from <file|->]`
641
653
  - `pmos jira answer <initiative> <ticket> <n> --text "<answer>"` or `--keep-default`
654
+ - `pmos jira criteria <initiative>`: the done-test checks each ticket carries as acceptance criteria, and the checks on no ticket
642
655
 
643
656
  Every command takes `--json` and `--root <dir>`.
644
657
 
@@ -92,6 +92,28 @@ To see every ticket in the terminal:
92
92
  pmos jira show <initiative>
93
93
  ```
94
94
 
95
+ ## Acceptance criteria from the done test
96
+
97
+ The people who build a ticket often never see the initiative's done test. So when the initiative has a done test (`done_test_path`), each drafted ticket carries the checks that apply to it, at the end of its Acceptance Criteria, under **From the done test**. Each check is written as Given / When / Then:
98
+
99
+ - **Given** the ticket's work is built,
100
+ - **When** a reviewer checks it the way the done test says,
101
+ - **Then** the check holds.
102
+
103
+ PMOS puts a check on a ticket in this order:
104
+
105
+ 1. A check that names a ticket id, such as TD-01, goes to that ticket.
106
+ 2. With one ticket, every check goes to it.
107
+ 3. Otherwise a check goes to the ticket that shares the most words with it (at least two).
108
+
109
+ A check that fits no ticket is not put on a ticket. `pmos jira draft` and `pmos jira criteria` list it as "on no ticket". To place it, name the ticket id in the check, or add the criteria to a ticket yourself.
110
+
111
+ Your own criteria stay above the block. A ticket you edited, selected or pushed is not changed. When the done test changes, the next draft updates the block on the tickets PMOS may still change. Nothing is sent to Jira until you select a ticket and push it.
112
+
113
+ ```
114
+ pmos jira criteria <initiative>
115
+ ```
116
+
95
117
  ## The dry run: where a builder would guess
96
118
 
97
119
  A ticket points to the PRD, but the builder holds only the ticket. Before you select the tickets, PMOS dry-runs them: the initiative's background run reads each drafted ticket as a builder would, and lists every point where it would have to guess. For each guess it quotes the PRD lines that answer it.
@@ -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 criteria <initiative> the done-test checks each ticket carries, and the checks on no ticket (A384)
23
24
  * every command: [--json] [--root <dir>]
24
25
  *
25
26
  * This command never talks to Jira. An agent session does, with the PM's own Atlassian connection (D53, D88), and
@@ -35,7 +36,7 @@ const jiraMoves = require('./jira-moves.js');
35
36
  const planItems = require('./plan-items.js');
36
37
  const guard = require('./pm-guard.js');
37
38
 
38
- const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which', 'moves', 'moved', 'guesses', 'answer'] };
39
+ const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which', 'moves', 'moved', 'guesses', 'answer', 'criteria'] };
39
40
  const USAGE = [
40
41
  'usage: pmos jira draft|show|epic|approve|pending|record|query|sync|summary|which — Jira tickets from the PRD, and their status',
41
42
  ' pmos jira draft <initiative> [--dry-run] draft one ticket per PRD item, in the ticket template',
@@ -45,6 +46,7 @@ const USAGE = [
45
46
  ' Quotes not found word for word in the PRD, done test or record are dropped. Gaps go to the day\'s question list.',
46
47
  ' pmos jira guesses <initiative> the dry run so far: the guesses of each ticket and the open gaps',
47
48
  ' pmos jira answer <initiative> <ticket> <n> --text "<answer>" | --keep-default the PM\'s answer to gap n, or keep its default: it goes into the ticket',
49
+ ' pmos jira criteria <initiative> the done-test checks each ticket carries as acceptance criteria, and the checks on no ticket',
48
50
  ' pmos jira epic <initiative> new|<KEY or link> [--group <g>] create a new epic at the first push, or use an existing one',
49
51
  ' pmos jira approve <initiative> <ID> … select tickets to push (you, in your own terminal)',
50
52
  ' pmos jira pending <initiative> what the push creates or updates in Jira',
@@ -219,6 +221,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
219
221
  if (r.from === 'done-test' || r.from === 'tasks') lines.push(` From ${r.from === 'done-test' ? 'the done test\'s checks' : 'the open tasks'} (${r.sources.join(', ')}): the PRD has no stories section.`);
220
222
  else if (r.from === 'plan') lines.push(' From the plan: each milestone is an epic, with the tasks that end before it. A Project has no PRD.');
221
223
  for (const c of r.changes) lines.push(` ${c.what.padEnd(9)} ${c.ticket} · ${c.summary}${c.why ? ` (${c.why})` : ''}`);
224
+ if (r.criteria) lines.push(` Acceptance criteria from the done test (${r.criteria.doneTest}): ${r.criteria.checks - r.criteria.unmatched.length} of ${r.criteria.checks} checks on a ticket${r.criteria.unmatched.length ? `; on no ticket: ${r.criteria.unmatched.join(', ')} (see pmos jira criteria ${initiative})` : ''}.`);
222
225
  lines.push('Read them on the Jira tickets tab, or with pmos jira show. Select the ready ones there, or with pmos jira approve.');
223
226
  return out(r, lines);
224
227
  }
@@ -243,6 +246,16 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
243
246
  if (r.gaps) lines.push(` The ${r.gaps === 1 ? 'gap goes' : r.gaps + ' gaps go'} to the PM's question list for today or tomorrow.`);
244
247
  return out(r, lines);
245
248
  }
249
+ if (verb === 'criteria') {
250
+ const r = jiraTickets.criteria(root, initiative);
251
+ if (!r.ok) return fail(r.error);
252
+ if (!r.doneTest) return out(r, [`${initiative} · no done test: give the record a done_test_path, then run pmos jira draft ${initiative}`]);
253
+ const lines = [`${initiative} · ${r.tickets_with_criteria} of ${r.tickets.length} ${r.tickets.length === 1 ? 'ticket carries' : 'tickets carry'} acceptance criteria from ${r.doneTest} · ${r.checks_on_a_ticket} of ${r.checks} checks on a ticket`];
254
+ for (const t of r.tickets) lines.push(` ${t.id} · ${t.checks.length ? `checks ${t.checks.join(', ')}` : 'no check'} · ${t.summary}`);
255
+ for (const u of r.unmatched) lines.push(` on no ticket: ${u.label} · ${u.check}`);
256
+ if (r.unmatched.length) lines.push('Name the ticket id in the check, or add the criteria to a ticket by hand, then run pmos jira draft again.');
257
+ return out(r, lines);
258
+ }
246
259
  if (verb === 'answer') {
247
260
  const [, ticket, n] = pos;
248
261
  if (!ticket || !n || (!flags.text === !flags['keep-default'])) return need('<initiative> <ticket> <n> --text "<the answer>" | --keep-default');
@@ -52,6 +52,7 @@ const planItems = require('./plan-items.js');
52
52
  const planTree = require('./plan-tree.js');
53
53
  const consoleState = require('./console-state');
54
54
  const { repoScript } = require('./repo-script.js');
55
+ const TAm = () => require('./ticket-acceptance.js');
55
56
 
56
57
  const KEY_RE = /^[A-Za-z][A-Za-z0-9_]*-\d+$/;
57
58
  const KEY_IN = /\b([A-Z][A-Z0-9_]+-\d+)\b/;
@@ -215,22 +216,9 @@ function readPrd(root, prd) {
215
216
  try { return fs.readFileSync(path.join(root, prd), 'utf8'); } catch { /* the main tree */ }
216
217
  try { return fs.readFileSync(path.join(mainRoot(root), prd), 'utf8'); } catch { return null; }
217
218
  }
218
- /** The checks of a done test (D107): its table rows `| n | check | how |`, else its top-level bullets. → [{ n, check, how }] */
219
- function checksInDoneTest(text) {
220
- const lines = stripFm(text).split('\n');
221
- const out = [];
222
- for (const l of lines) {
223
- const m = /^\|\s*(\d+)\s*\|\s*(.+?)\s*\|\s*(.*?)\s*\|?\s*$/.exec(l);
224
- if (m && m[2] && !/^-+$/.test(m[2])) out.push({ n: Number(m[1]), check: m[2].replace(/\\\|/g, '|'), how: m[3] || '' });
225
- }
226
- if (out.length) return out;
227
- let n = 0;
228
- for (const l of lines) {
229
- const b = /^[-*] (?:\[[ xX]\] )?(.+)$/.exec(l);
230
- if (b) out.push({ n: ++n, check: b[1].trim(), how: '' });
231
- }
232
- return out;
233
- }
219
+ /** The checks of a done test (D107): its table rows `| 1 | check | how |` or `| Q1 | … |`, else its top-level bullets.
220
+ * → [{ label, n, check, how }] (lib/ticket-acceptance.js) */
221
+ function checksInDoneTest(text) { return TAm().checksOf(text); }
234
222
  /** The done test a record names, read from the worktree or the main tree (a kit repository may name it under pmos/). */
235
223
  function readDoneTest(root, rfm) {
236
224
  const p = rfm && isStr(rfm.done_test_path) ? rfm.done_test_path.trim() : '';
@@ -244,12 +232,14 @@ function readDoneTest(root, rfm) {
244
232
  }
245
233
  return null;
246
234
  }
247
- /** One ticket item per done-test check: the check is the requirement, and how to check it is the acceptance. */
235
+ /** One ticket item per done-test check: the check is the requirement, and how to check it is the acceptance. `check` names the
236
+ * done-test row, so the criteria block (ticket-acceptance-from-done-test) writes it as Given / When / Then in place of these lines. */
248
237
  function itemsFromDoneTest(dt, title) {
249
238
  return checksInDoneTest(dt.text).map((c) => {
250
239
  const check = oneLine(c.check);
251
240
  return {
252
- id: `DT-${String(c.n).padStart(2, '0')}`, title: clip(check.replace(/\.$/, ''), 120), epic: null, refLabel: 'Done test', source: dt.path,
241
+ id: /^\d+$/.test(c.label) ? `DT-${String(c.n).padStart(2, '0')}` : `DT-${c.label}`, check: c.label,
242
+ title: clip(check.replace(/\.$/, ''), 120), epic: null, refLabel: 'Done test', source: dt.path,
253
243
  body: [`### User Story`, `As the PM of ${title}, I want this check of the done test to pass: ${check}`,
254
244
  `### Functional Requirements`, check,
255
245
  `### Acceptance Criteria`, `- ${check}`, ...(c.how ? [`- How to check: ${oneLine(c.how)}`] : [])].join('\n'),
@@ -537,18 +527,84 @@ function draft(root, initiative, { dryRun = false, now } = {}) {
537
527
  }
538
528
  // Tickets whose item is gone stay, at the end: the tab says so and Jira is not touched (J10).
539
529
  for (const t of byId.values()) out.push(t);
530
+ // Acceptance criteria from the done test (ticket-acceptance-from-done-test, A384), on every ticket PMOS may still write.
531
+ const crit = applyCriteria(root, initiative, st, out);
532
+ const listed = new Set(changes.map((c) => c.ticket));
533
+ for (const id of crit.written) if (!listed.has(id)) { const t = out.find((x) => x.id === id); changes.push({ ticket: id, what: 'criteria', summary: t.summary, why: 'its acceptance criteria from the done test changed' }); }
540
534
  const fm = old ? { ...old.fm } : {};
541
535
  if (!fm.epic_mode) {
542
536
  const anchor = anchorOf(recordFm(root, initiative) || {});
543
537
  fm.epic_mode = anchor ? 'existing' : 'new';
544
538
  if (anchor && !fm.epic) fm.epic = anchor;
545
539
  }
546
- const result = { ok: true, initiative, draft: draftRel(root, initiative), sources: st.sources, from: st.from, tickets: out.length, changes, changed: !old || changes.length > 0 };
540
+ const result = { ok: true, initiative, draft: draftRel(root, initiative), sources: st.sources, from: st.from, tickets: out.length, changes, changed: !old || changes.length > 0,
541
+ criteria: crit.doneTest ? { doneTest: crit.doneTest, checks: crit.checks, unmatched: crit.unmatched } : null };
547
542
  if (dryRun || (old && !changes.length)) return result;
548
543
  writeDraft(root, initiative, { fm, tickets: out }, { now, prd: st.prd });
549
544
  return result;
550
545
  }
551
546
 
547
+ // ── acceptance criteria from the done test (initiative ticket-acceptance-from-done-test; A384) ──────────
548
+ /** What a ticket says, for matching it to a check: summary, story, flow, requirements, end states and the PM's own criteria. */
549
+ function ticketWords(t) {
550
+ const sec = t.sections || {};
551
+ return [t.summary, sec.story, sec.flow, sec.functional, sec.terminal, TAm().withBlock(sec.acceptance, '')].filter(Boolean).join('\n');
552
+ }
553
+ /**
554
+ * Put each ticket's done-test checks, as Given / When / Then, at the end of its Acceptance Criteria. Only tickets PMOS may still
555
+ * write (dryRunWritable). A ticket drafted from one check alone carries the block in place of its plain lines.
556
+ * → { doneTest, checks, unmatched: [label], written: [id] }
557
+ */
558
+ function applyCriteria(root, initiative, st, tickets) {
559
+ const rfm = recordFm(root, initiative) || {};
560
+ const dt = readDoneTest(root, rfm);
561
+ const checks = dt ? checksInDoneTest(dt.text) : [];
562
+ if (!dt || !checks.length) return { doneTest: null, checks: 0, unmatched: [], written: [] };
563
+ const own = new Map((st && st.ok ? st.items : []).filter((x) => x.check).map((x) => [x.id, x.check]));
564
+ const a = TAm().assign(checks, tickets.map((t) => ({ id: t.id, text: ticketWords(t) })), { own });
565
+ const byLabel = new Map(checks.map((c) => [c.label, c]));
566
+ const title = oneLine(rfm.title || initiative);
567
+ const written = [];
568
+ for (const t of tickets) {
569
+ if (!dryRunWritable(t)) continue;
570
+ const labels = a.byTicket.get(t.id) || [];
571
+ const block = TAm().blockOf(labels.map((l) => byLabel.get(l)), { path: dt.path, subject: own.has(t.id) ? title : oneLine(t.summary) });
572
+ const base = own.has(t.id) && block ? '' : t.sections.acceptance;
573
+ const next = TAm().withBlock(base, block);
574
+ if (next === (t.sections.acceptance || '')) continue;
575
+ t.sections.acceptance = next; t.drafted = contentHash(t); written.push(t.id);
576
+ }
577
+ return { doneTest: dt.path, checks: checks.length, unmatched: a.unmatched, written };
578
+ }
579
+ /** The labels of the checks a ticket's text carries in its "From the done test" block. */
580
+ function criteriaLabelsOf(t) {
581
+ const s = String((t.sections || {}).acceptance || '');
582
+ const i = s.indexOf(TAm().MARK);
583
+ if (i < 0) return [];
584
+ return [...s.slice(i).matchAll(/^- Check (\S+)\s*$/gm)].map((m) => m[1]);
585
+ }
586
+ /**
587
+ * The coverage of the done test by the drafted tickets, read from the ticket text itself: which checks each ticket carries, and
588
+ * which checks no ticket carries. → { ok, doneTest, tickets: [{ id, summary, checks: [label] }], tickets_with_criteria, checks,
589
+ * checks_on_a_ticket, unmatched: [{ label, check }] } | { ok: false, status, error }
590
+ */
591
+ function criteria(root, initiative) {
592
+ const rfm = recordFm(root, initiative);
593
+ if (!rfm) return { ok: false, status: 404, error: `no initiative ${initiative} in this repository` };
594
+ const { d, error } = mustDraft(root, initiative);
595
+ if (error) return { ok: false, status: 404, error };
596
+ const dt = readDoneTest(root, rfm);
597
+ const checks = dt ? checksInDoneTest(dt.text) : [];
598
+ const tickets = d.tickets.map((t) => ({ id: t.id, summary: t.summary, checks: criteriaLabelsOf(t) }));
599
+ const on = new Set(tickets.flatMap((t) => t.checks));
600
+ return {
601
+ ok: true, initiative, doneTest: dt ? dt.path : null, tickets: tickets.length ? tickets : [],
602
+ tickets_with_criteria: tickets.filter((t) => t.checks.length).length, checks: checks.length,
603
+ checks_on_a_ticket: checks.filter((c) => on.has(c.label)).length,
604
+ unmatched: checks.filter((c) => !on.has(c.label)).map((c) => ({ label: c.label, check: oneLine(c.check) })),
605
+ };
606
+ }
607
+
552
608
  // ── the dry run (initiative dry-run-tickets-before-build; A194) ─────────────────────────────────────
553
609
  /** The dry-run helpers, loaded when a dry run is read or written. */
554
610
  /** The state folder of the repository: <state>/tracker/ holds the ticket drafts, dry runs and sign-offs. */
@@ -713,7 +769,7 @@ function view(root, initiative, { snapshot } = {}) {
713
769
  : waiting ? 'pushing' : edited ? 'edited' : null;
714
770
  return {
715
771
  id: t.id, summary: t.summary, type: t.type, priority: t.priority, estimate: t.estimate, depends: t.depends,
716
- epic: t.epic ? groupId(t.epic) : null, sections: t.sections, key: t.jira, inJira: !!t.jira, edited, prdChanged, removed, missing, waiting,
772
+ epic: t.epic ? groupId(t.epic) : null, sections: t.sections, doneTestChecks: criteriaLabelsOf(t), key: t.jira, inJira: !!t.jira, edited, prdChanged, removed, missing, waiting,
717
773
  selectable: !missing.length && !removed && (!t.jira || t.pushed !== h), flag,
718
774
  jira: r ? { status: r.status, category: r.category, sprint: r.sprint, subtasks: r.subtasks, flagged: !!r.flagged, reason: r.reason || null, url: r.url || null, stale: !!r.stale,
719
775
  assignee: (typeof r.assignee === 'string' && r.assignee.trim()) || (r.assignee && (r.assignee.displayName || r.assignee.name)) || null } : null,
@@ -1011,4 +1067,5 @@ module.exports = {
1011
1067
  readDraft, parseDraft, pushedTickets, draftedInitiatives, epicInitiatives, epicKeysOf, linkedEpics, anchorOf, missingOf, contentHash, describe,
1012
1068
  draftPath, draftRel, jiraDir, relOf, recordFm, prdOf,
1013
1069
  dryRun, answerDryRun, dryRunGaps, dryRunView, dryRunInitiatives, dryRunPath, stateDirOf,
1070
+ criteria, checksInDoneTest,
1014
1071
  };
@@ -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,120 @@
1
+ 'use strict';
2
+ /* ticket-acceptance.js — acceptance criteria on each drafted ticket, written from the initiative's done test
3
+ * (initiative ticket-acceptance-from-done-test; bet A384 in pmos-ideas proofs/A384-ac).
4
+ *
5
+ * On three test products, 69% of recent tickets stated no acceptance criteria, and the done test the PM agreed lived only in
6
+ * PMOS. So each ticket PMOS drafts carries the done-test checks that apply to it, as Given / When / Then, and the checks that fit
7
+ * no ticket are listed so the PM can place them.
8
+ *
9
+ * checksOf(text) → [{ label, n, check, how }] the done test's rows (`| 1 |` or `| Q1 |`), else bullets PURE
10
+ * gwt(check, { subject }) → { given, when, then } PURE
11
+ * assign(checks, tickets) → { byTicket: Map(id → [label]), unmatched: [label] } PURE
12
+ * blockOf(rows, { path, subject }) → the block that goes at the end of Acceptance Criteria, or '' PURE
13
+ * withBlock(text, block) → the section text with the old block replaced PURE
14
+ *
15
+ * MATCHING. A check that names a ticket id (TD-01) goes to that ticket. With one ticket, every check goes to it. Else a check goes
16
+ * to the ticket, or the tied tickets, that share most of its words (summary, story and requirements), when they share at least
17
+ * two. A check that fits no ticket is never guessed onto one: it is listed as not on any ticket. No model, nothing sent.
18
+ */
19
+
20
+ const MARK = '**From the done test**';
21
+ const MIN_SHARED = 2;
22
+ const STOP = new Set(('a an and are as at be been by can cannot does each every for from has have how in into is it its it\'s more no not ' +
23
+ 'of on one or our per same says so than that the their them then there these they this those to two was we were what when where which who ' +
24
+ 'will with without would you your check checks test tests done pass passes run runs ticket tickets item items shows show read reads ' +
25
+ 'still only also any all some other new use used uses user users pmos').split(' '));
26
+
27
+ const one = (s) => String(s == null ? '' : s).replace(/[\r\n\t]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
28
+ const stripFm = (text) => String(text).replace(/^---\n[\s\S]*?\n---\n?/, '');
29
+ const words = (s) => {
30
+ const out = new Set();
31
+ for (const w of String(s || '').toLowerCase().replace(/`[^`]*`/g, (m) => m.replace(/[^a-z0-9]+/g, ' ')).split(/[^a-z0-9]+/)) {
32
+ if (w.length < 3 || STOP.has(w) || /^\d+$/.test(w)) continue;
33
+ out.add(w.length > 4 ? w.replace(/(ies|es|s|ed|ing)$/, '') : w); // a light stem: "tickets" and "ticket", "drafted" and "draft"
34
+ }
35
+ return out;
36
+ };
37
+ const sentence = (s) => one(s).replace(/[.;:,\s]+$/, '');
38
+ const lowerFirst = (s) => (/^[A-Z](?![A-Z0-9_-])/.test(s) ? s[0].toLowerCase() + s.slice(1) : s); // "A reader" → "a reader"; "PW-3", "API" kept
39
+
40
+ /** The checks of a done test: its table rows `| 1 | check | how |` or `| Q1 | … |`, else its top-level bullets. */
41
+ function checksOf(text) {
42
+ const lines = stripFm(text).split('\n');
43
+ const out = [];
44
+ for (const l of lines) {
45
+ if (!/^\s*\|/.test(l)) continue;
46
+ // cells split on pipes, an escaped pipe (\|) kept as text
47
+ const cells = l.replace(/\\\|/g, '\u0000').trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((c) => c.replace(/\u0000/g, '|').trim());
48
+ const [label, check, how] = cells;
49
+ if (!/^[A-Za-z]{0,4}-?\d+[a-z]?$/.test(label || '') || !check || /^:?-+:?$/.test(check)) continue;
50
+ out.push({ label, n: Number(/(\d+)/.exec(label)[1]), check, how: how || '' });
51
+ }
52
+ if (out.length) return out;
53
+ let n = 0;
54
+ for (const l of lines) {
55
+ const b = /^[-*] (?:\[[ xX]\] )?(.+)$/.exec(l);
56
+ if (b) { n++; out.push({ label: String(n), n, check: b[1].trim(), how: '' }); }
57
+ }
58
+ return out;
59
+ }
60
+
61
+ /** A check as Given / When / Then. subject: what is built (the ticket's summary, or the initiative's title). */
62
+ function gwt(c, { subject } = {}) {
63
+ const what = sentence(subject) || 'this work';
64
+ const how = sentence(c && c.how);
65
+ return {
66
+ given: `${what} is built`,
67
+ when: how ? `a reviewer checks it: ${lowerFirst(how)}` : 'a reviewer checks it',
68
+ then: lowerFirst(sentence(c && c.check)),
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Which checks go on which ticket. tickets: [{ id, text }] where text is what the ticket says (summary, story, requirements).
74
+ * own: optional Map(ticket id → label) for tickets drafted from one check each (a draft from the done test alone).
75
+ */
76
+ function assign(checks, tickets, { own } = {}) {
77
+ const byTicket = new Map(tickets.map((t) => [t.id, []]));
78
+ const unmatched = [];
79
+ const tw = tickets.map((t) => ({ id: t.id, w: words(t.text) }));
80
+ for (const c of checks) {
81
+ let to = [];
82
+ if (own) for (const [id, label] of own) if (label === c.label && byTicket.has(id)) to.push(id);
83
+ if (!to.length) {
84
+ const named = tickets.filter((t) => new RegExp(`(^|[^A-Za-z0-9-])${t.id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([^A-Za-z0-9-]|$)`).test(`${c.check} ${c.how}`));
85
+ to = named.map((t) => t.id);
86
+ }
87
+ if (!to.length && tickets.length === 1) to = [tickets[0].id];
88
+ if (!to.length) {
89
+ const cw = words(`${c.check} ${c.how}`);
90
+ let best = 0;
91
+ const score = tw.map((t) => { let s = 0; for (const w of cw) if (t.w.has(w)) s++; if (s > best) best = s; return { id: t.id, s }; });
92
+ if (best >= MIN_SHARED) to = score.filter((x) => x.s === best).map((x) => x.id);
93
+ }
94
+ if (!to.length) { unmatched.push(c.label); continue; }
95
+ for (const id of to) byTicket.get(id).push(c.label);
96
+ }
97
+ return { byTicket, unmatched };
98
+ }
99
+
100
+ /** The block for one ticket: each check as Given / When / Then. rows: [{ label, check, how }]. '' when there is none. */
101
+ function blockOf(rows, { path, subject } = {}) {
102
+ if (!rows || !rows.length) return '';
103
+ const lines = [`${MARK}${path ? ` (\`${path}\`)` : ''}`, ''];
104
+ for (const c of rows) {
105
+ const g = gwt(c, { subject });
106
+ lines.push(`- Check ${c.label}`, ` - Given ${g.given}`, ` - When ${g.when}`, ` - Then ${g.then}`);
107
+ }
108
+ return lines.join('\n');
109
+ }
110
+
111
+ /** The section text with the old block taken out and the new one put at its end. */
112
+ function withBlock(text, block) {
113
+ const s = String(text || '');
114
+ const i = s.indexOf(MARK);
115
+ const base = (i >= 0 ? s.slice(0, i) : s).replace(/\s+$/, '');
116
+ const clean = /^[\s—–-]*$/.test(base) ? '' : base;
117
+ return [clean, block].filter(Boolean).join('\n\n');
118
+ }
119
+
120
+ module.exports = { MARK, checksOf, gwt, assign, blockOf, withBlock, words };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.682.0",
3
+ "version": "0.684.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.682.0",
9
+ "version": "0.684.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.682.0",
3
+ "version": "0.684.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,9 @@
1
+ {
2
+ "_comment": "Acceptance criteria from the done test (initiative ticket-acceptance-from-done-test, done test AC1-AC9): each drafted ticket carries the done-test checks that apply to it as Given / When / Then, and the checks on no ticket are listed. Synthetic kit-layout repositories. No connector, model or network.",
3
+ "modules": [
4
+ "ticket-acceptance.test.js"
5
+ ],
6
+ "seconds": {
7
+ "ticket-acceptance.test.js": 5
8
+ }
9
+ }