create-pmos 0.566.0 → 0.568.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 +27 -27
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/workflow-state.js +20 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +26 -0
- package/workspace/guide/cli.md +3 -1
- package/workspace/guide/initiatives-and-next-steps.md +20 -1
- package/workspace/lib/autonomy.js +1 -0
- package/workspace/lib/board-premium.js +2 -0
- package/workspace/lib/engine/workflow-state.js +20 -1
- package/workspace/lib/engine/workflows.js +71 -7
- package/workspace/lib/jira-cli.js +1 -0
- package/workspace/lib/jira-tickets.js +23 -0
- package/workspace/lib/kind-control.js +232 -0
- package/workspace/lib/outcome-props.js +58 -4
- package/workspace/lib/outcomes-cli.js +7 -1
- package/workspace/lib/outcomes.js +188 -11
- package/workspace/lib/proposals.js +12 -3
- package/workspace/lib/rehearse-read.js +3 -1
- package/workspace/lib/rehearse.js +30 -2
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-boards.js +56 -8
- package/workspace/lib/routes-initiatives.js +3 -1
- package/workspace/lib/routes-kind-control.js +95 -0
- package/workspace/lib/routes-proposals.js +26 -0
- package/workspace/lib/status-signal.js +6 -2
- package/workspace/lib/vendor/scripts/workflow-state.js +20 -1
- package/workspace/lib/work-kind.js +16 -4
- package/workspace/lib/workflow-cli.js +23 -1
- package/workspace/lib/workflows-store.js +2 -2
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/bd-next.js +8 -0
- package/workspace/public/pm/ini-agent.js +16 -6
- package/workspace/public/pm/ini-kind.js +59 -0
- package/workspace/public/pm/ini-view.css +23 -0
- package/workspace/public/pm/ini-view.js +5 -2
- package/workspace/test-lists/kind-workflows.json +5 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* kind-control.js — what the Viewer shows for a Project and a Full SDLC initiative (launch simulation W5; main canvas boards WfA and WfB,
|
|
3
|
+
* agreed by Wawan 2026-11-12). PURE: no file, no clock, no network. lib/routes-kind-control.js reads the inputs through the pmos readers.
|
|
4
|
+
*
|
|
5
|
+
* project(input) → { kind: 'project', gate, rows, critical, ontrack, proposal, baselineAt }
|
|
6
|
+
* sdlc(input) → { kind: 'sdlc', gate }
|
|
7
|
+
* baselineOf(lines, uids, at) → Map uid → { start, due } each task's dates as they stood when the plan was set (or its first dates)
|
|
8
|
+
* dateIn(text, today) → 'YYYY-MM-DD' | '' a date a title or a KR names ("launch 15 Dec", "by Dec 15", "2026-12-15")
|
|
9
|
+
* wbsOf(tasks) → [{ milestone, tasks }] a Project's milestones with the tasks that end before each (pmos jira draft)
|
|
10
|
+
*
|
|
11
|
+
* PROJECT CONTROL. Everything here comes from task dates and task links. A status someone typed is never read: a task's colour, the critical
|
|
12
|
+
* path and the on-track answer are worked out, so they cannot drift from the plan (the design principle "honest state").
|
|
13
|
+
* baseline each task's start and due when the initiative left Plan (the ini-wf line that moved it out of `plan`), else its first dates.
|
|
14
|
+
* The outline in the Viewer is the baseline; the filled bar is now (the forecast).
|
|
15
|
+
* forecast an open task that is past its due ends today at the earliest; then the approved links (lib/task-links.js settle) push what
|
|
16
|
+
* waits on it. Go-live is the initiative's last ◇ milestone, else its last task.
|
|
17
|
+
* critical walked back from go-live through the links that hold each task tight (the predecessor that sets its start or its due).
|
|
18
|
+
* With no links into go-live there is no critical path to name, and the Viewer says nothing about it.
|
|
19
|
+
* colour done: done. Red: it ends later than its baseline, it is on the critical path and go-live misses the goal date. Amber: it ends
|
|
20
|
+
* later than its baseline otherwise, or it has not started and its start has passed. Green: on its baseline. None: no dates.
|
|
21
|
+
* on track "On track for <goal date>?" Yes when the forecast go-live is on or before the goal date; No with the slip and the first
|
|
22
|
+
* slipping task on the critical path (the cause); unknown with the reason when a date is missing.
|
|
23
|
+
* proposal on a No: a ✦ that moves the go-live milestone to its forecast. It never changes the goal, the KR or the title: those are
|
|
24
|
+
* Wawan's, and `pmos rehearse end` names each one that the new date breaks.
|
|
25
|
+
* THE GATE TO LEAVE PLAN (WfA): a dated plan (every milestone has a due day, or plan_path is set), every milestone owned by someone in People,
|
|
26
|
+
* and the go-live date matching the goal date and the date in the title. Each part says what is missing.
|
|
27
|
+
* FULL SDLC (WfB): the gate before the first pull request is the done test plus the kill condition, written in the record. Who builds is
|
|
28
|
+
* the Experiment's line (pm/ini-agent.js kindRows), the one wording the honest-copy work keeps true per repository. */
|
|
29
|
+
const TL = require('./task-links.js');
|
|
30
|
+
|
|
31
|
+
const MON = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
32
|
+
const ALL = { has: () => true };
|
|
33
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
34
|
+
const days = (n) => (Math.abs(n) === 1 ? '1 day' : Math.abs(n) + ' days');
|
|
35
|
+
const iso = TL.isoN, md = TL.md, dn = TL.dn;
|
|
36
|
+
const listOf = (a) => (a.length < 2 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1]);
|
|
37
|
+
|
|
38
|
+
/** A date a line names, as YYYY-MM-DD; a day with no year is this year's, or next year's when this year's has passed. '' when none. */
|
|
39
|
+
function dateIn(text, today) {
|
|
40
|
+
const t = str(text), y0 = +str(today).slice(0, 4) || new Date().getUTCFullYear();
|
|
41
|
+
let m = /\b(\d{4})-(\d{2})-(\d{2})\b/.exec(t);
|
|
42
|
+
if (m) return m[0];
|
|
43
|
+
let d = 0, k = -1, y = 0;
|
|
44
|
+
m = /\b(\d{1,2})\s+(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?(?:,?\s+(\d{4}))?/i.exec(t);
|
|
45
|
+
if (m) { d = +m[1]; k = MON.indexOf(m[2].toLowerCase()); y = m[3] ? +m[3] : 0; }
|
|
46
|
+
else {
|
|
47
|
+
m = /\b(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?\s+(\d{1,2})\b(?:,?\s+(\d{4}))?/i.exec(t);
|
|
48
|
+
if (m) { d = +m[2]; k = MON.indexOf(m[1].toLowerCase()); y = m[3] ? +m[3] : 0; }
|
|
49
|
+
}
|
|
50
|
+
if (!m || k < 0 || d < 1 || d > 31) return '';
|
|
51
|
+
const at = (yy) => yy + '-' + String(k + 1).padStart(2, '0') + '-' + String(d).padStart(2, '0');
|
|
52
|
+
return y ? at(y) : at(y0) >= str(today) ? at(y0) : at(y0 + 1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Each task's dates as they stood at `at` (ISO time), read from task ledger lines of either shape: a Board task ({ kind: 'task' |
|
|
56
|
+
* 'task-update', task, start?, due? }) or a breakdown item ({ ev, item, start?, due?, fields: { start?, due? } }). A task first dated after
|
|
57
|
+
* `at` keeps its first dates. No `at`: every task's first dates. → Map uid → { start, due } */
|
|
58
|
+
function baselineOf(lines, uids, at) {
|
|
59
|
+
const first = new Map(), asOf = new Map();
|
|
60
|
+
for (const e of lines || []) {
|
|
61
|
+
if (!e || typeof e !== 'object') continue;
|
|
62
|
+
const id = typeof e.task === 'string' ? e.task : typeof e.item === 'string' ? e.item : null;
|
|
63
|
+
if (!id || (uids && !uids.has(id))) continue;
|
|
64
|
+
const f = e.fields && typeof e.fields === 'object' ? e.fields : e;
|
|
65
|
+
const s = typeof f.start === 'string' ? f.start : undefined, d = typeof f.due === 'string' ? f.due : undefined;
|
|
66
|
+
if (s === undefined && d === undefined) continue;
|
|
67
|
+
const cur = { ...(first.get(id) || { start: null, due: null }) };
|
|
68
|
+
if (!first.has(id) || first.get(id).start == null || first.get(id).due == null) {
|
|
69
|
+
if (cur.start == null && s !== undefined) cur.start = s;
|
|
70
|
+
if (cur.due == null && d !== undefined) cur.due = d;
|
|
71
|
+
first.set(id, cur);
|
|
72
|
+
}
|
|
73
|
+
if (at && e.at && String(e.at) <= String(at)) {
|
|
74
|
+
const a = { ...(asOf.get(id) || { start: null, due: null }) };
|
|
75
|
+
if (s !== undefined) a.start = s;
|
|
76
|
+
if (d !== undefined) a.due = d;
|
|
77
|
+
asOf.set(id, a);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const out = new Map();
|
|
81
|
+
for (const [id, f] of first) out.set(id, asOf.get(id) || f);
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The forecast: open past-due tasks end today at the earliest, then the links push what waits on them. → Map uid → task (TL shape) */
|
|
86
|
+
function forecastOf(tasks, links, today) {
|
|
87
|
+
const T = new Map();
|
|
88
|
+
for (const x of tasks) {
|
|
89
|
+
const t = TL.taskOf(x);
|
|
90
|
+
if (!t.closed && t.e != null && today != null && t.e < today) { const len = t.s != null ? t.e - t.s : 0; t.e = today; if (t.s != null && t.status === 'To do') t.s = Math.max(t.s, today - len); }
|
|
91
|
+
T.set(t.uid, t);
|
|
92
|
+
}
|
|
93
|
+
const L = (links || []).filter((l) => l && T.has(l.from) && T.has(l.to));
|
|
94
|
+
const S = TL.settle(T, L, { today, ini: '', mode: 'quiet', allow: ALL });
|
|
95
|
+
for (const m of S.moves || []) { const t = T.get(m.uid); if (t) T.set(m.uid, { ...t, s: m.to.s, e: m.to.e }); }
|
|
96
|
+
return { T, links: L };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Walk back from `end` through the links that hold each task tight. → [uid] oldest first */
|
|
100
|
+
function criticalOf(T, links, end, today) {
|
|
101
|
+
if (!end) return [];
|
|
102
|
+
const path = [end.uid], seen = new Set(path);
|
|
103
|
+
let cur = end;
|
|
104
|
+
for (let guard = 0; guard < 200; guard++) {
|
|
105
|
+
let best = null;
|
|
106
|
+
for (const l of links) {
|
|
107
|
+
if (l.to !== cur.uid || seen.has(l.from)) continue;
|
|
108
|
+
const a = T.get(l.from); if (!a) continue;
|
|
109
|
+
const need = TL.needOf(l, a, today);
|
|
110
|
+
const tight = (need.start != null && cur.s != null && need.start >= cur.s) || (need.due != null && cur.e != null && need.due >= cur.e);
|
|
111
|
+
if (tight && (!best || (a.e || 0) > (best.e || 0))) best = a;
|
|
112
|
+
}
|
|
113
|
+
if (!best) break;
|
|
114
|
+
path.unshift(best.uid); seen.add(best.uid); cur = best;
|
|
115
|
+
}
|
|
116
|
+
return path.length > 1 ? path : [];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** People's names and handles, lower case, for "owner linked to People". */
|
|
120
|
+
function peopleSet(people) {
|
|
121
|
+
const S = new Set();
|
|
122
|
+
for (const p of people || []) {
|
|
123
|
+
if (!p) continue;
|
|
124
|
+
if (p.name) S.add(String(p.name).toLowerCase().trim());
|
|
125
|
+
for (const h of p.handles || []) S.add(String(h).toLowerCase().replace(/^person:/, '').trim());
|
|
126
|
+
}
|
|
127
|
+
return S;
|
|
128
|
+
}
|
|
129
|
+
const ownerName = (o) => str(o).replace(/^person:/, '').trim();
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* input: { today, title, goal: { id, title, byAt } | null, end (the committed end) | null, record: { plan_path? },
|
|
133
|
+
* tasks: [{ uid, title, start, end, status, milestone, owner }] (this initiative's), links, baseline: Map, baselineAt, people }
|
|
134
|
+
*/
|
|
135
|
+
function project(input) {
|
|
136
|
+
const I = input || {}, today = dn(I.today);
|
|
137
|
+
const tasks = (I.tasks || []).filter((x) => x && (x.uid || x.key) && x.kind !== 'Epic');
|
|
138
|
+
const base = I.baseline instanceof Map ? I.baseline : new Map();
|
|
139
|
+
const { T, links } = forecastOf(tasks, I.links, today);
|
|
140
|
+
const ms = [...T.values()].filter((t) => t.ms);
|
|
141
|
+
const pickEnd = (L) => L.filter((t) => t.e != null).sort((a, b) => b.e - a.e)[0] || null;
|
|
142
|
+
const goLive = pickEnd(ms) || pickEnd([...T.values()]);
|
|
143
|
+
const crit = criticalOf(T, links, goLive, today);
|
|
144
|
+
const critSet = new Set(crit);
|
|
145
|
+
// the goal date: the KR's by-date, else the committed end, else the date the title names
|
|
146
|
+
const titleDate = dateIn(I.title, I.today);
|
|
147
|
+
const goalIso = (I.goal && I.goal.byAt ? str(I.goal.byAt).slice(0, 10) : '') || (I.end ? str(I.end).slice(0, 10) : '') || titleDate;
|
|
148
|
+
const goalN = dn(goalIso), fgo = goLive ? goLive.e : null;
|
|
149
|
+
const misses = goalN != null && fgo != null && fgo > goalN;
|
|
150
|
+
|
|
151
|
+
const raw = new Map(tasks.map((x) => [x.uid || x.key, x]));
|
|
152
|
+
const rows = [];
|
|
153
|
+
for (const t of T.values()) {
|
|
154
|
+
const b = base.get(t.uid) || null, bs = b ? dn(b.start || b.due) : null, be = b ? dn(b.due || b.start) : null;
|
|
155
|
+
const slip = be != null && t.e != null ? t.e - be : 0;
|
|
156
|
+
const startLate = !t.closed && t.status === 'To do' && t.s != null && today != null && dn((raw.get(t.uid) || {}).start) != null && dn(raw.get(t.uid).start) < today;
|
|
157
|
+
let rag = 'g';
|
|
158
|
+
if (t.closed) rag = 'done';
|
|
159
|
+
else if (t.s == null && t.e == null) rag = 'n';
|
|
160
|
+
else if (slip > 0 && critSet.has(t.uid) && misses) rag = 'r';
|
|
161
|
+
else if (slip > 0 || startLate) rag = 'a';
|
|
162
|
+
const owner = ownerName((raw.get(t.uid) || {}).owner);
|
|
163
|
+
rows.push({ uid: t.uid, title: t.title, milestone: t.ms, owner: owner || null, ownerLinked: !!owner && peopleSet(I.people).has(owner.toLowerCase()),
|
|
164
|
+
rag, critical: critSet.has(t.uid), base: { start: iso(bs), due: iso(be) }, now: { start: iso(t.s), due: iso(t.e) }, slip: slip > 0 ? slip : 0,
|
|
165
|
+
words: t.closed ? 'done' : rag === 'n' ? 'no dates' : slip > 0 ? days(slip) + ' late' : startLate ? 'start passed' : 'on time' });
|
|
166
|
+
}
|
|
167
|
+
rows.sort((a, b) => (dn(a.now.start || a.now.due) || 0) - (dn(b.now.start || b.now.due) || 0) || a.title.localeCompare(b.title));
|
|
168
|
+
|
|
169
|
+
// on track for the goal date?
|
|
170
|
+
let ontrack;
|
|
171
|
+
const src = 'Read from ' + tasks.length + (tasks.length === 1 ? ' task date' : ' task dates') + (links.length ? ' and ' + links.length + (links.length === 1 ? ' link' : ' links') : '');
|
|
172
|
+
if (!goLive) ontrack = { answer: 'unknown', words: 'No task has a date yet, so PMOS cannot say.', src };
|
|
173
|
+
else if (goalN == null) ontrack = { answer: 'unknown', forecast: iso(fgo), words: 'Go-live forecasts ' + md(fgo) + '. No goal date to compare: the KR, the end and the title name none.', src };
|
|
174
|
+
else if (!misses) ontrack = { answer: 'yes', date: goalIso, forecast: iso(fgo), words: 'Yes. Go-live forecasts ' + md(fgo) + (fgo < goalN ? ', ' + days(goalN - fgo) + ' early' : '') + '.', src };
|
|
175
|
+
else {
|
|
176
|
+
const cause = crit.map((u) => rows.find((r) => r.uid === u)).find((r) => r && r.slip > 0) || rows.filter((r) => r.slip > 0).sort((a, b) => b.slip - a.slip)[0] || null;
|
|
177
|
+
const after = cause ? crit.slice(crit.indexOf(cause.uid) + 1).map((u) => (T.get(u) || {}).title).filter(Boolean) : [];
|
|
178
|
+
ontrack = { answer: 'no', date: goalIso, forecast: iso(fgo), slip: fgo - goalN,
|
|
179
|
+
words: 'No. Forecast ' + md(fgo) + ', ' + days(fgo - goalN) + ' late.', cause: cause ? { uid: cause.uid, title: cause.title, slip: cause.slip } : null,
|
|
180
|
+
why: cause ? '"' + cause.title + '" ends ' + days(cause.slip) + ' after its baseline' + (cause.critical ? ' and sits on the critical path' + (after.length ? ', so ' + listOf(after.map((x) => '"' + x + '"')) + (after.length === 1 ? ' moves' : ' move') : '') : '') + '.' : 'Open work is past its due day.', src };
|
|
181
|
+
}
|
|
182
|
+
// the ✦: move the go-live milestone to its forecast. Never the goal, the KR or the title.
|
|
183
|
+
let proposal = null;
|
|
184
|
+
if (ontrack.answer === 'no' && goLive && goLive.ms) {
|
|
185
|
+
const raw0 = raw.get(goLive.uid) || {}, was = dn(raw0.end != null ? raw0.end : raw0.due);
|
|
186
|
+
if (was != null && was < fgo) proposal = { kind: 'milestone-date', task: goLive.uid, title: goLive.title, from: iso(was), to: iso(fgo),
|
|
187
|
+
text: 'Move ◇ "' + goLive.title + '" to its forecast, ' + md(fgo) + '. Its baseline stays. ' + (I.goal && I.goal.title ? 'The goal "' + I.goal.title + '"' : 'The goal date') + ' and the title stay until you change them.' };
|
|
188
|
+
}
|
|
189
|
+
// the gate to leave Plan
|
|
190
|
+
const dated = ms.length ? ms.every((t) => t.e != null) : !!str((I.record || {}).plan_path) || tasks.some((x) => x.end || x.due);
|
|
191
|
+
const msRows = rows.filter((r) => r.milestone);
|
|
192
|
+
const owned = msRows.length > 0 && msRows.every((r) => r.ownerLinked);
|
|
193
|
+
const goIso = goLive ? iso(dn((raw.get(goLive.uid) || {}).end != null ? raw.get(goLive.uid).end : (raw.get(goLive.uid) || {}).due) || goLive.e) : '';
|
|
194
|
+
const krIso = I.goal && I.goal.byAt ? str(I.goal.byAt).slice(0, 10) : '';
|
|
195
|
+
const matches = !!goIso && (!krIso || krIso === goIso) && (!titleDate || titleDate === goIso) && !!(krIso || titleDate || I.end);
|
|
196
|
+
const unowned = msRows.filter((r) => !r.ownerLinked).map((r) => r.title);
|
|
197
|
+
const gate = { label: 'Gate to leave Plan', parts: [
|
|
198
|
+
{ text: 'dated plan', ok: dated, ...(dated ? {} : { note: ms.length ? 'A milestone has no due day' : 'No milestone and no plan_path yet' }) },
|
|
199
|
+
{ text: 'owners in People', ok: owned, ...(owned ? {} : { note: msRows.length ? 'No owner in People: ' + unowned.slice(0, 3).join(', ') + (unowned.length > 3 ? ' and ' + (unowned.length - 3) + ' more' : '') : 'No milestone yet' }) },
|
|
200
|
+
{ text: 'go-live matches the goal', ok: matches, ...(matches ? {} : { note: !goIso ? 'Go-live has no date' : [krIso && krIso !== goIso ? 'KR says ' + md(dn(krIso)) : '', titleDate && titleDate !== goIso ? 'title says ' + md(dn(titleDate)) : '', !(krIso || titleDate || I.end) ? 'no KR date, end or title date to match' : ''].filter(Boolean).join('; ') + (goIso ? ' (go-live ' + md(dn(goIso)) + ')' : '') }) },
|
|
201
|
+
] };
|
|
202
|
+
return { kind: 'project', gate, rows, critical: crit.map((u) => (T.get(u) || {}).title).filter(Boolean), goLive: goLive ? { uid: goLive.uid, title: goLive.title, due: iso(goLive.e) } : null,
|
|
203
|
+
ontrack, proposal, baselineAt: I.baselineAt || null };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Full SDLC: the gate before the first pull request reads the record's done test and kill condition (WfB). */
|
|
207
|
+
function sdlc(input) {
|
|
208
|
+
const r = (input && input.record) || {};
|
|
209
|
+
const dt = !!str(r.done_test_path).trim(), kill = !!str(r.kill).trim();
|
|
210
|
+
return { kind: 'sdlc', gate: { label: 'Gate to the first pull request', parts: [
|
|
211
|
+
{ text: 'done test', ok: dt, ...(dt ? {} : { note: 'No done test is written yet' }) },
|
|
212
|
+
{ text: 'kill condition', ok: kill, ...(kill ? {} : { note: 'No kill condition is written yet' }) },
|
|
213
|
+
] } };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** A Project as a work breakdown (pmos jira draft): each ◇ milestone in date order with the open tasks that end on or before it and after
|
|
217
|
+
* the milestone before; tasks after the last milestone go under "After the last milestone". → [{ milestone: { uid, title, due } | null, tasks }] */
|
|
218
|
+
function wbsOf(tasks) {
|
|
219
|
+
const T = (tasks || []).filter((x) => x && x.kind !== 'Epic').map((x) => ({ uid: x.uid || x.key, title: str(x.title), due: str(x.end || x.due).slice(0, 10) || null, owner: ownerName(x.owner) || null, milestone: !!x.milestone }));
|
|
220
|
+
const ms = T.filter((t) => t.milestone).sort((a, b) => String(a.due || '9').localeCompare(String(b.due || '9')));
|
|
221
|
+
const rest = T.filter((t) => !t.milestone);
|
|
222
|
+
const out = ms.map((m) => ({ milestone: m, tasks: [] }));
|
|
223
|
+
const tail = { milestone: null, tasks: [] };
|
|
224
|
+
for (const t of rest) {
|
|
225
|
+
const g = out.find((x) => t.due && x.milestone.due && t.due <= x.milestone.due) || (out.length && !t.due ? out[out.length - 1] : null);
|
|
226
|
+
(g || tail).tasks.push(t);
|
|
227
|
+
}
|
|
228
|
+
if (tail.tasks.length) out.push(tail);
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
module.exports = { project, sdlc, baselineOf, dateIn, wbsOf, forecastOf, criticalOf };
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
* takes a few weeks of mornings, or `pmos outcomes propose` in a sitting). A draft the PM dropped (✕) or kept is not filed again. When a
|
|
20
20
|
* record has its outcome by another way (`pmos outcomes declare`, an edit), the open draft is dropped. It never writes a record: only the PM's ✓.
|
|
21
21
|
*
|
|
22
|
+
* A REFUTED OUTCOME (launch simulation W2). Every tick (not once a day) the server reads each product's outcome ledger, and for a verdict
|
|
23
|
+
* that says it did not work, files PMOS's next step under the ✦ (lib/outcomes.js refutedDrafts): stop it when the evidence meets the
|
|
24
|
+
* kill condition, a new experiment after a second refuted check, else one more round. Class C (lib/autonomy.js): only the PM's ✓ does it.
|
|
25
|
+
*
|
|
22
26
|
* deps: { workspaces() → [w], isLead(w), stateDirFor(w), boardOf(w, id) → board id | null, runtime() → the per-user state folder, open(now),
|
|
23
27
|
* env, every (ms, its own timer), mayRun(), warn(what, err) }
|
|
24
28
|
*/
|
|
@@ -32,12 +36,17 @@ const off = (env) => flagOff((env || process.env).PMOS_OUTCOMES);
|
|
|
32
36
|
const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
33
37
|
const guardLib = () => { try { return require('./ai-guard.js'); } catch { return null; } };
|
|
34
38
|
const versionOf = (w) => O.VERSION + ':' + w.id;
|
|
35
|
-
const typeOf = (d) => (d.data.kind === 'undated' ? 'date' : 'new');
|
|
39
|
+
const typeOf = (d) => (d.data.kind === 'undated' ? 'date' : d.data.kind === 'refuted' ? 'refuted' : 'new');
|
|
36
40
|
|
|
37
41
|
/** The proposals line a draft becomes. */
|
|
38
42
|
function lineOf(d, board, run) {
|
|
39
43
|
const type = typeOf(d), ini = d.data.initiative;
|
|
40
44
|
const sources = d.claims.flatMap((c) => c.sources).map((s) => ({ label: s.label, ref: s.ref }));
|
|
45
|
+
if (type === 'refuted') {
|
|
46
|
+
// one per check: a later refuted check files again (its key is the check's own line)
|
|
47
|
+
const c = PR.clean('outcome', 'refuted', { title: d.title, why: d.say, sources, items: [{ id: 'next', title: O.NEXT_WORDS[d.data.next], ...(d.data.horizon ? { due: d.data.horizon } : {}) }], data: d.data });
|
|
48
|
+
return c.error ? null : { kind: 'propose', ini, board, run, id: PR.idOf(ini, 'outcome', type, d.data.ref || d.data.check), ...c.prop };
|
|
49
|
+
}
|
|
41
50
|
const c = PR.clean('outcome', type, { title: type === 'date' ? 'A date to check the outcome' : 'What should change once it ships', why: d.say, sources,
|
|
42
51
|
items: [{ id: 'outcome', title: d.data.metric, due: d.data.horizon }], data: { metric: d.data.metric, horizon: d.data.horizon } });
|
|
43
52
|
if (c.error) return null;
|
|
@@ -47,7 +56,7 @@ function lineOf(d, board, run) {
|
|
|
47
56
|
/** One product's replay cases: its own drafts must all pass, and an initiative with nothing to cite gets no draft. */
|
|
48
57
|
function cases(S, list) {
|
|
49
58
|
const out = [{ name: 'the drafts of ' + S.root.split(/[\\/]/).pop(), run: async () => list.slice(0, PER_DAY), expect: { filed: Math.min(PER_DAY, list.length) } }];
|
|
50
|
-
out.push({ name: 'nothing to cite, no draft', run: async () => O.drafts({ ...S, due: [], undated: [], missing: [{ id: 'zz-no-source', title: 'No source', fm: {}, prd: '', anchor: '' }] }, { tasks: [] }).drafts, expect: { none: true } });
|
|
59
|
+
out.push({ name: 'nothing to cite, no draft', run: async () => O.drafts({ ...S, subjects: [], due: [], undated: [], missing: [{ id: 'zz-no-source', title: 'No source', fm: {}, prd: '', anchor: '' }] }, { tasks: [] }).drafts, expect: { none: true } });
|
|
51
60
|
return out;
|
|
52
61
|
}
|
|
53
62
|
|
|
@@ -64,7 +73,7 @@ function create(deps) {
|
|
|
64
73
|
// a record that has its outcome now: its open draft goes (zero is silence)
|
|
65
74
|
const has = new Map(S.subjects.map((it) => [it.id, it]));
|
|
66
75
|
for (const p of F.props.values()) {
|
|
67
|
-
if (p.group !== 'outcome' || kept.has(p.id)) continue;
|
|
76
|
+
if (p.group !== 'outcome' || p.type === 'refuted' || kept.has(p.id)) continue; // a refuted outcome's next step: refutedPass keeps it
|
|
68
77
|
const it = has.get(p.ini), sig = PR.sigOf(p);
|
|
69
78
|
if (F.drops.has(sig)) continue;
|
|
70
79
|
if (!it || (it.metric && (p.type === 'new' || it.horizon))) PR.append(dir, { by: 'pmos:outcomes' }, { kind: 'drop', ini: p.ini, sig });
|
|
@@ -92,8 +101,53 @@ function create(deps) {
|
|
|
92
101
|
return { ws: w.id, filed: (r.filed || []).length, held: !!r.held, off: r.off || null };
|
|
93
102
|
}
|
|
94
103
|
|
|
104
|
+
/** A refuted outcome's next step (launch simulation W2): filed at the tick after the PM's verdict, not once a day. Quiet hours do not
|
|
105
|
+
* hold it back: the PM just recorded the verdict. One ✦ per check; a ✦ the PM kept or dropped is not filed again. */
|
|
106
|
+
async function refutedPass(w, { now = Date.now() } = {}) {
|
|
107
|
+
const dir = deps.stateDirFor(w); if (!dir) return { ws: w.id, filed: 0 };
|
|
108
|
+
if (!O.anyRefuted(w.root)) return { ws: w.id, filed: 0 }; // most products: no refuted check, so no scan every tick
|
|
109
|
+
const S = O.scan(w.root, { today: localDay(now) });
|
|
110
|
+
const D = O.refutedDrafts(S);
|
|
111
|
+
const F = PR.read(dir), kept = PR.keptIds(F), fresh = [];
|
|
112
|
+
const live = new Set(D.map((d) => d.data.initiative + '|' + d.data.ref));
|
|
113
|
+
for (const p of F.props.values()) {
|
|
114
|
+
if (p.group !== 'outcome' || p.type !== 'refuted' || kept.has(p.id) || F.drops.has(PR.sigOf(p))) continue;
|
|
115
|
+
if (!live.has(p.ini + '|' + ((p.data && (p.data.ref || p.data.check)) || ''))) PR.append(dir, { by: 'pmos:outcomes' }, { kind: 'drop', ini: p.ini, sig: PR.sigOf(p) }); // answered another way: zero is silence
|
|
116
|
+
}
|
|
117
|
+
for (const d of D) {
|
|
118
|
+
const board = deps.boardOf(w, d.data.initiative); if (!board) continue;
|
|
119
|
+
const l = lineOf(d, board, ''); if (!l) continue;
|
|
120
|
+
const prev = F.props.get(l.id);
|
|
121
|
+
if (kept.has(l.id) || (prev && (F.drops.has(PR.sigOf(prev)) || prev.data.next === l.data.next))) continue;
|
|
122
|
+
fresh.push({ d, board });
|
|
123
|
+
}
|
|
124
|
+
if (!fresh.length) return { ws: w.id, filed: 0 };
|
|
125
|
+
const AG = guardLib(); if (!AG) return { ws: w.id, filed: 0, why: 'the shared guard is not installed' };
|
|
126
|
+
const rt = deps.runtime && deps.runtime(), version = versionOf(w), run = 'or' + now.toString(36) + crypto.randomBytes(3).toString('hex');
|
|
127
|
+
if (!AG.off(O.JOB, { env: deps.env || process.env, settingsDir: rt }) && !AG.ready(rt, O.JOB, version)) {
|
|
128
|
+
const rep = await AG.replay(O.JOB, version, cases(S, fresh.map((x) => x.d)), { root: w.root, stateDir: rt, max: PER_DAY });
|
|
129
|
+
if (!rep.ok) { warn('outcomes replay ' + w.id, new Error(rep.failed.map((f) => f.name + ': ' + f.why).join('; '))); return { ws: w.id, filed: 0, replay: rep }; }
|
|
130
|
+
}
|
|
131
|
+
const byId = new Map(fresh.map((x) => [x.d.id, x]));
|
|
132
|
+
const r = await AG.file({ job: O.JOB, version, run, root: w.root, stateDir: rt, settingsDir: rt, env: deps.env || process.env, max: PER_DAY }, fresh.map((x) => x.d),
|
|
133
|
+
async (acc) => { for (const p of acc) { const x = byId.get(p.id); const l = x && lineOf(x.d, x.board, run); if (l) PR.append(dir, { by: 'agent:outcomes' }, l); } });
|
|
134
|
+
return { ws: w.id, filed: (r.filed || []).length, held: !!r.held, off: r.off || null };
|
|
135
|
+
}
|
|
136
|
+
|
|
95
137
|
async function tick({ now = Date.now() } = {}) {
|
|
96
138
|
if (off(deps.env) || busy) return { off: off(deps.env), running: busy };
|
|
139
|
+
busy = true;
|
|
140
|
+
const refuted = [];
|
|
141
|
+
try {
|
|
142
|
+
for (const w of deps.workspaces()) {
|
|
143
|
+
try { if (deps.isLead && !deps.isLead(w)) continue; } catch { continue; }
|
|
144
|
+
try { refuted.push(await refutedPass(w, { now })); } catch (e) { warn('outcomes refuted ' + w.id, e); }
|
|
145
|
+
}
|
|
146
|
+
} finally { busy = false; }
|
|
147
|
+
const r = await dailyTick({ now });
|
|
148
|
+
return { ...r, refuted };
|
|
149
|
+
}
|
|
150
|
+
async function dailyTick({ now = Date.now() } = {}) {
|
|
97
151
|
let open = true;
|
|
98
152
|
try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
|
|
99
153
|
if (!open) return { closed: true };
|
|
@@ -114,7 +168,7 @@ function create(deps) {
|
|
|
114
168
|
const t = setInterval(() => { try { if (deps.mayRun && !deps.mayRun()) return; } catch { /* no lock: run */ } tick({}).catch((e) => warn('outcomes tick', e)); }, deps.every);
|
|
115
169
|
if (t.unref) t.unref();
|
|
116
170
|
}
|
|
117
|
-
return { tick, runProduct };
|
|
171
|
+
return { tick, runProduct, refutedPass };
|
|
118
172
|
}
|
|
119
173
|
|
|
120
174
|
module.exports = { create, cases, lineOf, off, PER_DAY };
|
|
@@ -47,7 +47,8 @@ function repoRoot(cwd) {
|
|
|
47
47
|
}
|
|
48
48
|
const wsIdOf = (root) => { try { return require('./driver.js').wsIdOf(root); } catch { return require('crypto').createHash('sha1').update(path.resolve(root)).digest('hex').slice(0, 10); } };
|
|
49
49
|
const draftText = (p) => `✦ ${p.title}\n ${p.say}\n${p.claims.map((c) => ' · ' + c.text + ' [' + c.sources.map((s) => s.ref).join(', ') + ']').join('\n')}`
|
|
50
|
-
+ (p.data && p.data.kind
|
|
50
|
+
+ (p.data && p.data.kind === 'refuted' ? `\n It waits under the initiative's ✦ for the PM's ✓ (${O.NEXT_WORDS[p.data.next]}); a ✕ with a reason leaves it as it is.`
|
|
51
|
+
: p.data && p.data.kind !== 'due' ? `\n Yes → pmos outcomes declare ${p.data.initiative} --metric ${JSON.stringify(p.data.metric)} --horizon ${p.data.horizon}`
|
|
51
52
|
: p.data ? `\n Verdict → pmos outcomes record ${p.data.initiative} worked|didnt-work|cant-tell --evidence "<what shows it>"` : '');
|
|
52
53
|
|
|
53
54
|
async function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now(), isTTY, runtime } = {}) {
|
|
@@ -132,6 +133,11 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
|
|
|
132
133
|
if (!r.ok) return fail(r.error);
|
|
133
134
|
if (flags.json) { say(JSON.stringify({ ok: true, file: r.file, line: r.line })); return 0; }
|
|
134
135
|
say(`✓ ${id}: ${disposition} — ${r.line.evidence} (${r.file}). Commit it to keep it.`);
|
|
136
|
+
// launch simulation W2: a refuted outcome reads at risk on every surface now, and PMOS says the next step it files under the ✦
|
|
137
|
+
if (disposition === 'refuted') {
|
|
138
|
+
const d = O.refutedDrafts(O.scan(root, { today }), { only: id })[0];
|
|
139
|
+
if (d) { say(` Its status reads at risk until you pick the next step. PMOS suggests: ${O.NEXT_WORDS[d.data.next]}.`); say(' ' + d.say); say(' The workspace files it under the initiative\'s ✦ for your ✓.'); }
|
|
140
|
+
}
|
|
135
141
|
return 0;
|
|
136
142
|
}
|
|
137
143
|
|
|
@@ -78,6 +78,10 @@ function ledger(root, L, name) {
|
|
|
78
78
|
return files.flatMap(jsonRows);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/** The record's check date moved past the one a check answered: the check line's own horizon (written since launch simulation W2), else its
|
|
82
|
+
* date. Then the outcome is open again. */
|
|
83
|
+
const reopened = (it, row) => !!(it.horizon && it.horizon > String(row.horizon || row.date || String(row.at || '').slice(0, 10)));
|
|
84
|
+
|
|
81
85
|
const STOPPED = new Set(['paused', 'cancelled', 'canceled', 'stopped', 'dropped', 'archived', 'killed']);
|
|
82
86
|
function workGroup(root) { try { return require('./initiative-rows.js').workGroupOf(root) || {}; } catch { return {}; } }
|
|
83
87
|
|
|
@@ -123,7 +127,9 @@ function scan(root, { today = todayOf() } = {}) {
|
|
|
123
127
|
subjects.push(it);
|
|
124
128
|
if (!it.metric) { if (it.accepted) shippedWithout++; else missing.push(it); continue; }
|
|
125
129
|
const d = disposedBy.get(id);
|
|
126
|
-
|
|
130
|
+
// a check date moved past the one the last check answered (the PM chose one more round on a refuted outcome) opens the outcome again
|
|
131
|
+
const checked = d && !reopened(it, d);
|
|
132
|
+
if (checked) disposed.push({ ...it, disposition: d.disposition });
|
|
127
133
|
else if (!it.horizon) undated.push(it);
|
|
128
134
|
else if (it.horizon <= today) due.push(it);
|
|
129
135
|
else pending.push(it);
|
|
@@ -193,8 +199,11 @@ function anchorMetric(root, it) {
|
|
|
193
199
|
if (i < 0) continue;
|
|
194
200
|
const text = Ls[i];
|
|
195
201
|
const cells = text.split('|').map((c) => c.trim()).filter(Boolean);
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
// the KR's own words, without its list marker, its bold and its id: "- **KR1** — 2,000 …" and "- **KR1 —** 2,000 …" read "2,000 …"
|
|
203
|
+
// (the launch simulation drafted "Moves KR1: — 2,000 …")
|
|
204
|
+
const bare = text.replace(/^\s*(?:[-*+]|\d+[.)])\s+/, '').replace(/\*\*/g, '').replace(/`/g, '');
|
|
205
|
+
const words = cells.length > 1 ? cells.filter((c) => !c.includes(token)).sort((p, q) => q.length - p.length)[0] : bare.replace(token, '');
|
|
206
|
+
const m = metricText(String(words || '').replace(/^[:\s—–.-]+/, ''));
|
|
198
207
|
if (m.replace(/[^A-Za-z0-9]/g, '').length < 12) continue;
|
|
199
208
|
return { metric: 'Moves ' + a + ': ' + m, source: src(root, f, i + 1, text, 'Anchor ' + clip(a, 40)) };
|
|
200
209
|
}
|
|
@@ -257,15 +266,21 @@ function undatedDraft(S, it, tasks) {
|
|
|
257
266
|
}
|
|
258
267
|
|
|
259
268
|
function missingDraft(S, it, tasks) {
|
|
260
|
-
|
|
269
|
+
// the experiment's hypothesis is its predicted outcome (D107): read it beside the anchor, and say when the two name different KRs
|
|
270
|
+
const hyp = experimentField(S.root, it, 'hypothesis');
|
|
271
|
+
const other = hyp ? krMismatch(hyp.text, it.anchor) : null;
|
|
272
|
+
const m = prdMetric(S.root, it) || (hyp && !other ? { metric: metricText(hyp.text), source: hyp.source, hyp: true } : null) || anchorMetric(S.root, it);
|
|
261
273
|
if (!m) return null; // nothing to cite: the PM names it (proven-only)
|
|
262
274
|
const h = horizonFor(S, it, tasks);
|
|
263
|
-
const
|
|
275
|
+
const said = m.hyp ? 'Its hypothesis' : m.source.label.startsWith('PRD') ? 'Its PRD' : 'Its anchor';
|
|
276
|
+
const claims = [claim(`${said} says: ${m.metric}`, [m.source])];
|
|
277
|
+
if (hyp && !m.hyp) claims.push(claim(`Its hypothesis: ${clip(hyp.text, 160)}`, [hyp.source]));
|
|
264
278
|
if (h.source) claims.push(claim(`Its last task is due on ${short(h.lastDue)}`, [h.source]));
|
|
279
|
+
const flag = other ? ` Its hypothesis names ${other}, but it is anchored to ${it.anchor}: check which one it should move before you say yes.` : '';
|
|
265
280
|
return {
|
|
266
|
-
id: `outcome-new:${it.id}`, title: `Expected outcome for ${clip(it.title, 80)}`, confidence: claims.length > 1 &&
|
|
267
|
-
say: `It has no expected outcome yet. I suggest: "${m.metric}", checked on ${short(h.horizon)} (${h.why})
|
|
268
|
-
data: { kind: 'missing', initiative: it.id, metric: m.metric, horizon: h.horizon },
|
|
281
|
+
id: `outcome-new:${it.id}`, title: `Expected outcome for ${clip(it.title, 80)}`, confidence: other ? 'low' : claims.length > 1 && !said.endsWith('anchor') ? 'medium' : 'low', claims,
|
|
282
|
+
say: `It has no expected outcome yet. I suggest: "${m.metric}", checked on ${short(h.horizon)} (${h.why}).${flag}`,
|
|
283
|
+
data: { kind: 'missing', initiative: it.id, metric: m.metric, horizon: h.horizon, ...(other ? { mismatch: other } : {}) },
|
|
269
284
|
};
|
|
270
285
|
}
|
|
271
286
|
|
|
@@ -273,7 +288,7 @@ function missingDraft(S, it, tasks) {
|
|
|
273
288
|
function drafts(S, { only = null, tasks } = {}) {
|
|
274
289
|
const T = tasks || tasksOf(S.root);
|
|
275
290
|
const pick = (list) => (only ? list.filter((it) => it.id === only) : list);
|
|
276
|
-
const out =
|
|
291
|
+
const out = refutedDrafts(S, { only }), ask = []; // a refuted outcome's next step comes first: the status already reads at risk
|
|
277
292
|
for (const it of pick(S.due)) out.push(dueDraft(S, it));
|
|
278
293
|
for (const it of pick(S.undated)) out.push(undatedDraft(S, it, T));
|
|
279
294
|
for (const it of pick(S.missing)) {
|
|
@@ -283,6 +298,167 @@ function drafts(S, { only = null, tasks } = {}) {
|
|
|
283
298
|
return { drafts: out, ask };
|
|
284
299
|
}
|
|
285
300
|
|
|
301
|
+
/* ── the experiment (D107): its hypothesis and kill condition, from the record or the Experiment artefact ───────────────────────── */
|
|
302
|
+
|
|
303
|
+
/** The newest set of one Experiment field in the product's artefact ledger, with its path:line. → { text, file, n, line } | null */
|
|
304
|
+
function artefactField(root, id, field) {
|
|
305
|
+
let dir = null; try { dir = require('./driver.js').stateDirOf(root); } catch { dir = null; }
|
|
306
|
+
if (!dir) return null;
|
|
307
|
+
const file = path.join(dir, 'artefacts.jsonl'), Ls = linesOf(file);
|
|
308
|
+
if (!Ls) return null;
|
|
309
|
+
const scopes = new Set(['experiment:' + id, 'initiative:' + id]);
|
|
310
|
+
let best = null; const undone = new Set();
|
|
311
|
+
Ls.forEach((l, i) => {
|
|
312
|
+
let o = null; try { o = JSON.parse(l); } catch { return; }
|
|
313
|
+
if (!o || !scopes.has(o.scope)) return;
|
|
314
|
+
if (o.ev === 'undo' && o.ref) undone.add(o.ref);
|
|
315
|
+
if (o.ev === 'set' && o.artefact === 'experiment' && o.field === field && typeof o.text === 'string') best = { text: o.text, file, n: i + 1, line: l, id: o.id };
|
|
316
|
+
});
|
|
317
|
+
return best && !undone.has(best.id) && best.text.trim() ? best : null;
|
|
318
|
+
}
|
|
319
|
+
/** The experiment's hypothesis or kill condition: the record's own line (`hypothesis:`, `kill:`) wins, else the Experiment artefact.
|
|
320
|
+
* → { text, source: { label, ref, quote } } | null */
|
|
321
|
+
function experimentField(root, it, field) {
|
|
322
|
+
const label = field === 'kill' ? 'Kill condition' : 'Hypothesis';
|
|
323
|
+
const e = it.fm && it.fm[field];
|
|
324
|
+
if (e && String(e.value || '').trim()) return { text: String(e.value).trim(), source: src(root, path.join(root, it.record), e.n, e.text, label) };
|
|
325
|
+
const a = artefactField(root, it.id, field);
|
|
326
|
+
return a ? { text: a.text.trim(), source: src(root, a.file, a.n, a.line, label) } : null;
|
|
327
|
+
}
|
|
328
|
+
const KR_IN = /\bKR-?[A-Z]?\d+(?:\.\d+)*\b/gi;
|
|
329
|
+
const norm = (k) => k.toUpperCase().replace(/-/g, '');
|
|
330
|
+
const krOf = (s) => [...new Set((String(s || '').match(KR_IN) || []).map(norm))];
|
|
331
|
+
/** A hypothesis that names a KR the anchor does not: the draft says so (launch simulation, proposal 2). → 'KR-A2' (as written) | null */
|
|
332
|
+
function krMismatch(hypothesis, anchor) {
|
|
333
|
+
const named = String(hypothesis || '').match(KR_IN) || [], a = krOf(anchor);
|
|
334
|
+
if (!named.length || !a.length || named.some((k) => a.includes(norm(k)))) return null;
|
|
335
|
+
return [...new Set(named)].join(', ');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/* ── a refuted outcome: the kill condition, the next step, the status ─────────────────────────────────────────────────────────── */
|
|
339
|
+
|
|
340
|
+
const NUM = /(\d{1,3}(?:,\d{3})+|\d+(?:\.\d+)?)\s*(%)?/g;
|
|
341
|
+
const numbersIn = (s) => {
|
|
342
|
+
const M = '(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\\.?';
|
|
343
|
+
const t = String(s || '').replace(/\b\d{4}-\d{2}-\d{2}\b/g, ' ') // a date is not a reading: 2026-11-11, 11 Nov, Nov 11, Q4, week 3
|
|
344
|
+
.replace(new RegExp('\\b\\d{1,2}(?:st|nd|rd|th)?\\s+' + M, 'gi'), ' ').replace(new RegExp('\\b' + M + '\\s+\\d{1,2}\\b', 'gi'), ' ').replace(/\b(?:q[1-4]|week\s*\d+|w\d+)\b/gi, ' ');
|
|
345
|
+
const out = [];
|
|
346
|
+
for (const m of t.matchAll(NUM)) {
|
|
347
|
+
if (!m[2] && !m[1].includes(',') && /^(19|20)\d\d$/.test(m[1])) continue; // a year
|
|
348
|
+
out.push({ v: Number(m[1].replace(/,/g, '')), pct: !!m[2] });
|
|
349
|
+
}
|
|
350
|
+
return out;
|
|
351
|
+
};
|
|
352
|
+
const LT = /(fewer than|less than|lower than|below|under|at most|no more than|drops? (?:to|below)|falls? (?:to|below)|<=?)\s*(\d{1,3}(?:,\d{3})+|\d+(?:\.\d+)?)\s*(%)?/i;
|
|
353
|
+
const GT = /(more than|greater than|higher than|above|over|at least|exceeds?|rises? (?:to|above)|>=?)\s*(\d{1,3}(?:,\d{3})+|\d+(?:\.\d+)?)\s*(%)?/i;
|
|
354
|
+
/** Does the evidence meet the kill condition? Only a number on the same side of the condition's own number counts, so a condition with no
|
|
355
|
+
* number, or evidence with none, is not judged (null): the PM judges it. → { met: true|false|null, why } */
|
|
356
|
+
function killMet(kill, evidence) {
|
|
357
|
+
if (!String(kill || '').trim()) return { met: null, why: 'It names no kill condition to compare with.' };
|
|
358
|
+
const lt = LT.exec(kill), gt = lt ? null : GT.exec(kill), m = lt || gt;
|
|
359
|
+
if (!m) return { met: null, why: 'Its kill condition has no number I can compare with.' };
|
|
360
|
+
const bar = Number(m[2].replace(/,/g, '')), pct = !!m[3];
|
|
361
|
+
const seen = numbersIn(evidence).filter((x) => x.pct === pct && x.v !== bar);
|
|
362
|
+
if (!seen.length) return { met: null, why: 'The evidence has no number to compare with its kill condition.' };
|
|
363
|
+
const hit = seen.find((x) => (lt ? (/at most|no more than|<=/i.test(m[1]) ? x.v <= bar : x.v < bar) : (/at least|>=/i.test(m[1]) ? x.v >= bar : x.v > bar)));
|
|
364
|
+
const fmt = (x) => x.v.toLocaleString('en-US') + (x.pct ? '%' : '');
|
|
365
|
+
return hit ? { met: true, why: `The evidence reads ${fmt(hit)}, which meets its kill condition.` }
|
|
366
|
+
: { met: false, why: `The evidence reads ${fmt(seen[0])}, which does not meet its kill condition.` };
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Does any outcome ledger of the repository hold a refuted check? A cheap read before a scan. */
|
|
370
|
+
function anyRefuted(root) {
|
|
371
|
+
const L = layoutOf(path.resolve(root));
|
|
372
|
+
return [...new Set([path.join(L.runsDir, 'outcome_checks.jsonl'), path.join(root, 'pmos', 'state', 'outcome_checks.jsonl'), path.join(root, 'planning', 'runs', 'outcome_checks.jsonl')])]
|
|
373
|
+
.some((f) => { try { return fs.readFileSync(f, 'utf8').includes('"refuted"'); } catch { return false; } });
|
|
374
|
+
}
|
|
375
|
+
/** Every outcome check of the repository with its path:line, oldest first. → [{ row, ref, quote, file, n }] */
|
|
376
|
+
function checkLines(root, L) {
|
|
377
|
+
const files = [...new Set([path.join(L.runsDir, 'outcome_checks.jsonl'), path.join(root, 'pmos', 'state', 'outcome_checks.jsonl'), path.join(root, 'planning', 'runs', 'outcome_checks.jsonl')])];
|
|
378
|
+
const out = [];
|
|
379
|
+
for (const f of files) (linesOf(f) || []).forEach((l, i) => { let o = null; try { o = JSON.parse(l); } catch { return; } if (o && o.initiative_id && DISPOSITIONS.includes(o.disposition)) out.push({ row: o, file: f, n: i + 1, ref: rel(root, f) + ':' + (i + 1), quote: cut(l) }); });
|
|
380
|
+
return out.sort((a, b) => String(a.row.at || a.row.date || '').localeCompare(String(b.row.at || b.row.date || '')));
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** The verdict that stands on each initiative: its newest outcome check. A refuted one is CURRENT until the PM chose what next: a check date
|
|
384
|
+
* after the check (iterate), or a stop (lifecycle, which drops it from the scan). → Map id → { it, verdict, date, evidence, check, refutes,
|
|
385
|
+
* current, kill, killMet, hypothesis, next } where next is PMOS's recommendation for a current refuted one: kill | iterate | new */
|
|
386
|
+
function verdictsOf(S) {
|
|
387
|
+
const by = new Map(), refutes = new Map();
|
|
388
|
+
for (const c of checkLines(S.root, S.layout)) {
|
|
389
|
+
const id = String(c.row.initiative_id);
|
|
390
|
+
by.set(id, c);
|
|
391
|
+
if (c.row.disposition === 'refuted') refutes.set(id, (refutes.get(id) || 0) + 1);
|
|
392
|
+
}
|
|
393
|
+
const out = new Map();
|
|
394
|
+
for (const it of S.subjects) {
|
|
395
|
+
const c = by.get(it.id); if (!c) continue;
|
|
396
|
+
const date = String(c.row.date || String(c.row.at || '').slice(0, 10));
|
|
397
|
+
const v = { it, verdict: c.row.disposition, date, evidence: String(c.row.evidence || ''), check: c, refutes: refutes.get(it.id) || 0 };
|
|
398
|
+
v.current = v.verdict === 'refuted' && !reopened(it, c.row);
|
|
399
|
+
if (v.current) {
|
|
400
|
+
v.kill = experimentField(S.root, it, 'kill');
|
|
401
|
+
v.hypothesis = experimentField(S.root, it, 'hypothesis');
|
|
402
|
+
v.killMet = killMet(v.kill && v.kill.text, v.evidence);
|
|
403
|
+
v.next = v.killMet.met === true ? 'kill' : v.refutes >= 2 ? 'new' : 'iterate';
|
|
404
|
+
}
|
|
405
|
+
out.set(it.id, v);
|
|
406
|
+
}
|
|
407
|
+
return out;
|
|
408
|
+
}
|
|
409
|
+
/** What a row carries for the status signal and the Board's Next cell. → { verdict, date, evidence, current, next } | null */
|
|
410
|
+
const outcomeOfRow = (v) => (v ? { verdict: v.verdict, date: v.date, evidence: clip(v.evidence, 300), current: !!v.current, ...(v.current ? { next: v.next } : {}) } : null);
|
|
411
|
+
/** The verdicts of a repository for the rows (lib/routes-boards.js), in one read. → Map id → outcomeOfRow */
|
|
412
|
+
function rowOutcomes(root, { today = todayOf() } = {}) {
|
|
413
|
+
const out = new Map();
|
|
414
|
+
try { for (const [id, v] of verdictsOf(scan(root, { today }))) out.set(id, outcomeOfRow(v)); } catch { /* no verdicts read: rows say nothing */ }
|
|
415
|
+
return out;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const NEXT_WORDS = { kill: 'Stop it', iterate: 'One more round, then check again', new: 'Start a new experiment and stop this one' };
|
|
419
|
+
/** The ✦ for a current refuted outcome: PMOS's next step, with what it rests on. */
|
|
420
|
+
function refutedDraft(S, v) {
|
|
421
|
+
// one more round: a new check DAYS_AFTER days out, and always past the date the refuted check answered (so the outcome opens again)
|
|
422
|
+
const it = v.it, answered = String(v.check.row.horizon || v.date), h0 = addDays(S.today, DAYS_AFTER), h = h0 > answered ? h0 : addDays(answered, DAYS_AFTER);
|
|
423
|
+
const claims = [claim(`The check on ${short(v.date)} said it did not work: ${clip(v.evidence, 160)}`, [{ label: 'Outcome check', ref: v.check.ref, quote: v.check.quote }])];
|
|
424
|
+
if (v.kill) claims.push(claim(`Its kill condition: ${clip(v.kill.text, 160)}`, [v.kill.source]));
|
|
425
|
+
if (v.hypothesis) claims.push(claim(`Its hypothesis: ${clip(v.hypothesis.text, 160)}`, [v.hypothesis.source]));
|
|
426
|
+
const said = `The check on ${short(v.date)} said "${clip(v.it.metric, 100)}" did not happen: ${clip(v.evidence, 140)}.`;
|
|
427
|
+
const say = v.next === 'kill' ? `${said} ${v.killMet.why} I suggest stopping it. ✓ cancels it with this reason; Undo brings it back.`
|
|
428
|
+
: v.next === 'new' ? `${said} This is check ${v.refutes} that said it did not work, so I suggest a new experiment on ${it.anchor || 'the same goal'} and stopping this one. ${v.killMet.met === null ? v.killMet.why + ' ' : ''}✓ adds the new experiment and cancels this one; Undo puts both back.`
|
|
429
|
+
: `${said} ${v.killMet.why} I suggest one more round: a task to change what the check showed, and a new check on ${short(h)}. ✓ does both; Undo takes them back.`;
|
|
430
|
+
return {
|
|
431
|
+
id: `outcome-refuted:${it.id}:${v.check.n}`, title: `${NEXT_WORDS[v.next]}: ${clip(it.title, 80)}`, confidence: v.killMet.met === null ? 'low' : 'medium', claims, say,
|
|
432
|
+
data: { kind: 'refuted', initiative: it.id, next: v.next, check: v.date, ref: v.check.ref, evidence: clip(v.evidence, 300), metric: it.metric, horizon: v.next === 'iterate' ? h : null,
|
|
433
|
+
killMet: v.killMet.met, anchor: it.anchor || '', title: it.title, lane: it.lane, work: (it.fm.kind && it.fm.kind.value) || '' },
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
/** The ✦ next steps of every current refuted outcome (or of one initiative). → [proposal] */
|
|
437
|
+
function refutedDrafts(S, { only = null } = {}) {
|
|
438
|
+
const out = [];
|
|
439
|
+
for (const v of verdictsOf(S).values()) if (v.current && (!only || v.it.id === only)) out.push(refutedDraft(S, v));
|
|
440
|
+
return out;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** The PM's stop of an experiment, as the Board's ⋯ Cancel writes it (D70 lifecycle line, POST /api/lifecycle): the ✓ of a "Stop it" or
|
|
444
|
+
* "Start a new experiment" ✦, and its Undo (state active). → { ok, file, from } | { ok: false, error } */
|
|
445
|
+
function setLife(root, id, state, reason, actor) {
|
|
446
|
+
root = path.resolve(root);
|
|
447
|
+
if (!ID_RE.test(String(id || ''))) return { ok: false, error: 'name the initiative by its id' };
|
|
448
|
+
if (!['cancelled', 'active'].includes(state)) return { ok: false, error: 'state is cancelled or active' };
|
|
449
|
+
const L = layoutOf(root), dir = L.runsDir, file = path.join(dir, 'lifecycle.jsonl');
|
|
450
|
+
let from = null;
|
|
451
|
+
for (const r of jsonRows(file)) if (r && r.initiative_id === id && r.state) from = String(r.state);
|
|
452
|
+
try {
|
|
453
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
454
|
+
const st = (() => { try { return fs.lstatSync(file); } catch { return null; } })();
|
|
455
|
+
if (st && !st.isFile()) return { ok: false, error: 'the lifecycle ledger is not a plain file — nothing was saved' };
|
|
456
|
+
let pm = 'pm'; try { pm = require('./actor.js').PM_SLUG || pm; } catch { /* default */ }
|
|
457
|
+
fs.appendFileSync(file, JSON.stringify({ initiative_id: id, state, reason: String(reason || '').slice(0, 500), pm, by: (actor && actor.by) || 'agent:unknown', via: (actor && actor.via) || 'ui', at: new Date().toISOString() }) + '\n');
|
|
458
|
+
return { ok: true, file: rel(root, file), from };
|
|
459
|
+
} catch (e) { return { ok: false, error: 'the lifecycle ledger could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
460
|
+
}
|
|
461
|
+
|
|
286
462
|
/* ── the outcome ledger: the one writer behind `pmos outcomes record` ───────────────────────────────────────── */
|
|
287
463
|
|
|
288
464
|
/** Append the PM's verdict. Evidence is required for all three (an `inconclusive` with no reason is the cheapest lie). */
|
|
@@ -303,10 +479,11 @@ function recordCheck(root, { initiative, disposition, evidence, by, via }, { now
|
|
|
303
479
|
fs.mkdirSync(dir, { recursive: true });
|
|
304
480
|
const st = (() => { try { return fs.lstatSync(file); } catch { return null; } })();
|
|
305
481
|
if (st && !st.isFile()) return { ok: false, error: 'the outcome ledger is not a plain file — nothing was saved' };
|
|
306
|
-
const line = { initiative_id: initiative, disposition, evidence: ev, date: todayOf(now), at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
|
|
482
|
+
const line = { initiative_id: initiative, disposition, evidence: ev, date: todayOf(now), ...(it.horizon ? { horizon: it.horizon } : {}), at: new Date(now).toISOString(), by: by || 'agent:unknown', via: via || 'cli' };
|
|
307
483
|
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
308
484
|
return { ok: true, file: rel(root, file), line };
|
|
309
485
|
} catch (e) { return { ok: false, error: 'the outcome ledger could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
310
486
|
}
|
|
311
487
|
|
|
312
|
-
module.exports = { VERSION, JOB, DAYS_AFTER, DEFAULT_DAYS, DISPOSITIONS, scan, drafts, prdMetric, anchorMetric, horizonFor, recordCheck, todayOf, short, frontOf
|
|
488
|
+
module.exports = { VERSION, JOB, DAYS_AFTER, DEFAULT_DAYS, DISPOSITIONS, scan, drafts, prdMetric, anchorMetric, horizonFor, recordCheck, todayOf, short, frontOf,
|
|
489
|
+
experimentField, krMismatch, killMet, anyRefuted, verdictsOf, rowOutcomes, outcomeOfRow, refutedDrafts, setLife, NEXT_WORDS };
|