create-pmos 0.760.0 → 0.762.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +39 -33
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/changelog.json +38 -0
  7. package/workspace/guide/cli.md +7 -1
  8. package/workspace/guide/home.md +1 -1
  9. package/workspace/guide/notes.md +15 -0
  10. package/workspace/lib/actor.js +8 -3
  11. package/workspace/lib/contradictions.js +137 -0
  12. package/workspace/lib/jira-cli.js +7 -2
  13. package/workspace/lib/jira-tiers.js +75 -10
  14. package/workspace/lib/meeting-focus.js +14 -1
  15. package/workspace/lib/open-questions.js +23 -5
  16. package/workspace/lib/outcome-judge.js +1 -1
  17. package/workspace/lib/outcome-props.js +51 -5
  18. package/workspace/lib/outcomes-cli.js +49 -3
  19. package/workspace/lib/plan-baseline.js +106 -0
  20. package/workspace/lib/proposal-runs.js +1 -1
  21. package/workspace/lib/proposals.js +1 -1
  22. package/workspace/lib/propose-cli.js +16 -7
  23. package/workspace/lib/routes-drift.js +30 -0
  24. package/workspace/lib/routes-meeting-focus.js +6 -1
  25. package/workspace/lib/routes-open-questions.js +9 -2
  26. package/workspace/lib/tracker-digest.js +23 -3
  27. package/workspace/lib/week-moves.js +8 -2
  28. package/workspace/package-lock.json +2 -2
  29. package/workspace/package.json +1 -1
  30. package/workspace/premium-rec-tab-test.js +2 -1
  31. package/workspace/public/pm/buddy-core.js +162 -0
  32. package/workspace/public/pm/buddy-float.js +63 -0
  33. package/workspace/public/pm/cozy-buddy.css +26 -0
  34. package/workspace/public/pm/cozy-buddy.js +59 -7
  35. package/workspace/public/pm/cozy-rec-tab.js +10 -2
  36. package/workspace/public/pm/moves-view.js +11 -1
  37. package/workspace/public/pm/open-questions-view.js +1 -0
  38. package/workspace/public/premium-buddy.html +4 -0
  39. package/workspace/skills/initiative-propose.skill +2 -2
  40. package/workspace/skills/jira-sync.skill +1 -1
  41. package/workspace/test-lists/outcome-checks-finish.json +9 -0
  42. package/workspace/test-lists/slip-baseline-contradictions.json +9 -0
  43. package/workspace/test-lists/tracker-digest.json +7 -3
@@ -13,13 +13,14 @@
13
13
  * THE SOURCES. (1) The day's question list (lib/question-batch.js, annotated by lib/default-decisions.js): the plan changes PMOS holds for
14
14
  * want of a source, a drafted ticket's dry-run gaps and the outside sign-offs. Each question already has its owner, `waiting` (days on the
15
15
  * list), and `default` or `waits`. (2) The open Driver drafts: a proposal in driver.jsonl with no keep, return or drop. Your move does not
16
- * list them, and on four test products all 56 were older than 14 days.
16
+ * list them, and on four test products all 56 were older than 14 days. (3) Records that disagree with each other (lib/contradictions.js,
17
+ * initiative slip-baseline-contradictions): kind `record`, one line to the PM per initiative, never a default.
17
18
  *
18
19
  * THE DEFAULT OF A DRAFT. A draft is a proposal: nothing lands until the PM keeps it. So the safe answer is to drop it, and nothing on the
19
20
  * plan changes. It is due DRAFT_DAYS after the draft was filed (Your move's expiry window). The register says the default; it takes none.
20
21
  * Taking defaults stays with lib/default-decisions.js.
21
22
  *
22
- * A LINE: { key, owner, toPm, ini, title, n, kinds: { change?, ask?, draft? }, since, age, default: { say, due } | null, waits, text, ids }.
23
+ * A LINE: { key, owner, toPm, ini, title, n, kinds: { change?, ask?, draft?, record? }, since, age, default: { say, due } | null, waits, text, ids }.
23
24
  * A line has a default only when every part of it has one; otherwise `waits` says why. Never both, never neither. Oldest first.
24
25
  * Nothing here writes or sends anything. */
25
26
 
@@ -57,7 +58,7 @@ function draftsOf(state, { titleOf = () => '' } = {}) {
57
58
  /** One register: the day's questions and the open drafts, one line per owner and initiative, oldest first. PURE.
58
59
  * questions: lib/routes-your-move.js questions().questions (each { key, owner, toPm, ini, title, ids, n, text, default, waits, waiting }).
59
60
  * drafts: draftsOf(). today: 'YYYY-MM-DD'. pm: the owner word for the PM. */
60
- function registerOf({ questions = [], drafts = [], today = '', pm = 'PM' } = {}) {
61
+ function registerOf({ questions = [], drafts = [], records = [], today = '', pm = 'PM' } = {}) {
61
62
  const t = dn(today);
62
63
  const by = new Map();
63
64
  const seen = new Set();
@@ -107,6 +108,21 @@ function registerOf({ questions = [], drafts = [], today = '', pm = 'PM' } = {})
107
108
  const shown = ds.slice(0, MAX_ID_SHOW).map((d) => d.text);
108
109
  l.parts.push(`${plural(ds.length, 'draft from PMOS', 'drafts from PMOS')}: ${shown.join('; ')}${ds.length > shown.length ? `; and ${ds.length - shown.length} more` : ''}.`);
109
110
  }
111
+ // (3) records that disagree (lib/contradictions.js): one line to the PM per initiative, no default (which record is wrong is the PM's call)
112
+ for (const c of records || []) {
113
+ if (!isObj(c) || !c.ini || !c.kind) continue;
114
+ const id = 'record:' + c.kind + ':' + c.ini;
115
+ if (seen.has(id)) continue;
116
+ seen.add(id);
117
+ const l = lineOf(pm, true, c.ini, c.title);
118
+ l.kinds.record = (l.kinds.record || 0) + 1;
119
+ l.n += 1;
120
+ l.ids.push(id);
121
+ const d = dn(c.at);
122
+ l.ages.push(d != null && t != null ? Math.max(0, t - d) : 0);
123
+ l.waits.push('The records disagree, and which one is wrong is your call: PMOS changes neither by itself.');
124
+ l.parts.push(one(`${c.say || ''} ${c.ask || ''}`, 300));
125
+ }
110
126
  const out = [];
111
127
  for (const l of by.values()) {
112
128
  const age = l.ages.length ? Math.max(...l.ages) : 0;
@@ -143,7 +159,7 @@ function diskQuestions(root, { now = Date.now() } = {}) {
143
159
  }
144
160
 
145
161
  /** The register of a repository. questions: the day's list from the server; without it the disk asks. */
146
- function read(root, { now = Date.now(), questions = null, pm = 'PM' } = {}) {
162
+ function read(root, { now = Date.now(), questions = null, records = null, pm = 'PM' } = {}) {
147
163
  const D = require('./driver.js');
148
164
  const today = localDay(now);
149
165
  let drafts = [];
@@ -156,7 +172,9 @@ function read(root, { now = Date.now(), questions = null, pm = 'PM' } = {}) {
156
172
  }
157
173
  } catch { drafts = []; }
158
174
  const qs = Array.isArray(questions) ? questions : diskQuestions(root, { now });
159
- const lines = registerOf({ questions: qs, drafts, today, pm });
175
+ let recs = records;
176
+ if (!Array.isArray(recs)) { try { recs = require('./contradictions.js').forRepo(root, { now }).items; } catch { recs = []; } }
177
+ const lines = registerOf({ questions: qs, drafts, records: recs, today, pm });
160
178
  return { today, lines, median_age: medianAge(lines) };
161
179
  }
162
180
 
@@ -130,7 +130,7 @@ function judge({ root, it, src, recordsDir, stateDir, refDir = stateDir, today }
130
130
  return { kind: 'verdict', disposition, evidence, reading, rec, claims };
131
131
  }
132
132
 
133
- const WORDS = Object.freeze({ validated: 'It worked', refuted: 'It did not work' });
133
+ const WORDS = Object.freeze({ validated: 'It worked', refuted: 'It did not work', inconclusive: 'Can\'t tell yet' });
134
134
 
135
135
  /** The drafts of the due outcomes of one scan (lib/outcomes.js scan). → [{ judged, it, draft | null }] (draft null: nothing to file now) */
136
136
  function drafts(S, { src, recordsDir, stateDir, refDir = stateDir, only = null } = {}) {
@@ -29,7 +29,9 @@
29
29
  * A DUE CHECK (initiative outcome-checks-run-themselves, bet 1 of the factory line). Every tick in the hours the PM allows, PMOS judges each
30
30
  * outcome whose check date passed (duePass, lib/outcome-judge.js): the anchor goal's own reading files a verdict ✦ (class B: recorded by
31
31
  * itself with Undo); a goal PMOS failed to read twice the same way files ONE ask (class C); else one short run per initiative and check date
32
- * reads the records (deps.startRun, <state>/outcome-runs.jsonl). What none of these can tell stays due, and Your move asks the PM once.
32
+ * reads the records (deps.startRun, <state>/outcome-runs.jsonl). The run files worked, didn't work or can't tell (initiative
33
+ * outcome-checks-finish); a run that ends, or goes quiet for a day, with no verdict gets PMOS's own can't tell on the next pass (silentDraft),
34
+ * with what the run read. Only a run the PM stopped, or a pass with the switch off, leaves it due, and then Your move asks the PM once.
33
35
  *
34
36
  * A BLOCKED CHECK (bet A451). A check whose place of measure runs an older version than the one that shipped the change (lib/outcomes.js
35
37
  * scan `blocked`) is not due: it is never judged and starts no run. The pass logs one `[outcome-blocked]` line when a check becomes blocked
@@ -214,9 +216,17 @@ function create(deps) {
214
216
  filed = (r.filed || []).length; held = !!r.held;
215
217
  if (r.off) return { ws: w.id, filed, runs: 0, off: r.off }; // the AI switch is off: no run either
216
218
  }
219
+ // a run that ended (or went quiet for a day) with no verdict: PMOS records "can't tell" itself, so the PM is not left the question
220
+ const startedRuns = runsOf(dir);
221
+ for (const x of toRun) {
222
+ const st = startedRuns.get(x.it.id + '|' + x.it.horizon);
223
+ if (!st || verdictFiled(x.it.id, x.it.horizon)) continue;
224
+ const l = silentDraft(dir, x.it, st, x.why, x.board, { now });
225
+ if (l && !F.props.has(l.id)) { PR.append(dir, { by: 'agent:outcomes' }, l); filed++; log(`[outcome-rate] ${w.id} ${x.it.id} can't tell after a silent run ${st.run}`); }
226
+ }
217
227
  let runs = 0;
218
228
  if (deps.startRun && toRun.length) {
219
- const started = runsOf(dir);
229
+ const started = startedRuns;
220
230
  for (const x of toRun) {
221
231
  if (runs >= RUNS_PER_PASS) break;
222
232
  const key = x.it.id + '|' + x.it.horizon;
@@ -298,12 +308,48 @@ function create(deps) {
298
308
 
299
309
  /** The outcome runs started, as `ini|horizon` keys (<state>/outcome-runs.jsonl). */
300
310
  function runsOf(dir) {
301
- const out = new Set();
311
+ const out = new Map(); // 'ini|horizon' → { run, at } of the one run started for it (a Map, so `has` reads as before)
302
312
  let text = ''; try { text = fs.readFileSync(path.join(dir, RUNS), 'utf8'); } catch { return out; }
303
- for (const l of text.split('\n')) { try { const o = JSON.parse(l); if (o && o.ini && o.horizon) out.add(o.ini + '|' + o.horizon); } catch { /* torn */ } }
313
+ for (const l of text.split('\n')) { try { const o = JSON.parse(l); if (o && o.ini && o.horizon && !out.has(o.ini + '|' + o.horizon)) out.set(o.ini + '|' + o.horizon, { run: o.run || null, at: o.at || '' }); } catch { /* torn */ } }
304
314
  return out;
305
315
  }
306
316
 
317
+ /** A SILENT RUN (initiative outcome-checks-finish). The one check run of a due outcome ended, or started more than SILENT_AFTER ago, and filed no
318
+ * verdict: PMOS records "can't tell" itself, from what the run read (its `src` lines) and why the goal's reading did not decide it. A run
319
+ * the PM stopped gets nothing (the PM took it over). Sources: the record's outcome line and the run's own lines in the proposals ledger,
320
+ * so it is never a change with no source. → the proposals line to append | null */
321
+ const SILENT_AFTER = 864e5;
322
+ function silentDraft(dir, it, started, why, board, { now = Date.now() } = {}) {
323
+ if (!started || !started.run) return null;
324
+ const file = PR.ledgerFile(dir);
325
+ let L = []; try { L = fs.readFileSync(file, 'utf8').split('\n'); } catch { return null; }
326
+ const read = [], refs = [];
327
+ let ended = false, stopped = false;
328
+ L.forEach((raw, i) => {
329
+ let o = null; try { o = JSON.parse(raw); } catch { return; }
330
+ if (!o || o.run !== started.run || o.ini !== it.id) return;
331
+ if (o.kind === 'end') { ended = true; stopped = stopped || !!o.stopped; }
332
+ if (o.kind === 'src' && o.state === 'done') { read.push(o.n ? `${o.source} (${String(o.what || '').trim() || o.n + ' found'})` : `${o.source} (nothing)`); refs.push({ label: 'What the run read: ' + o.source, ref: 'state:' + path.relative(dir, file).split(path.sep).join('/') + ':' + (i + 1) }); }
333
+ });
334
+ if (stopped) return null;
335
+ const age = now - Date.parse(started.at || '');
336
+ if (!ended && !(age > SILENT_AFTER)) return null; // still running: wait for it
337
+ const day = String(started.at || '').slice(0, 10);
338
+ const reason = String(why || '').replace(/\s+/g, ' ').trim().replace(/[.\s]+$/, '');
339
+ const evidence = (`PMOS's check run on ${day ? O.short(day) : 'its check date'} ${ended ? 'ended' : 'stopped answering'} without a verdict. `
340
+ + (read.length ? `It read ${read.join('; ')}. ` : 'It read nothing it could cite. ')
341
+ + (reason ? `The goal's own reading did not decide it: ${reason}.` : 'No reading of the goal decides it.')).slice(0, 600);
342
+ const sources = [];
343
+ if (it.fm && it.fm.outcome_metric) sources.push({ label: 'Expected outcome', ref: it.record + ':' + it.fm.outcome_metric.n });
344
+ sources.push(...refs.slice(0, 7 - sources.length));
345
+ if (!sources.length) return null;
346
+ const c = PR.clean('outcome', 'verdict', { title: `${J.WORDS.inconclusive}: ${it.title}`.slice(0, 120),
347
+ why: `Its check date was ${O.short(it.horizon)}. ${read.length ? 'PMOS read ' + read.length + ' source' + (read.length === 1 ? '' : 's') + ' and could not tell whether it worked' : 'PMOS could not tell whether it worked'}. PMOS recorded "can't tell". Undo takes it back.`,
348
+ sources, items: [{ id: 'verdict', title: J.WORDS.inconclusive }], data: { disposition: 'inconclusive', evidence, horizon: it.horizon } });
349
+ if (c.error) return null;
350
+ return { kind: 'propose', ini: it.id, board, run: started.run, id: PR.idOf(it.id, 'outcome', 'verdict', it.horizon), ...c.prop };
351
+ }
352
+
307
353
  /** The refuted outcomes whose ✦ next step still waits for the PM (launch simulation W6): every current refuted verdict, less the ones whose
308
354
  * ✦ the PM kept (✓) or dropped (✕). Read without a server (`pmos today --root`), so a ✦ the server has not filed yet is listed too.
309
355
  * → [{ ini, title, next, say, id }] */
@@ -324,4 +370,4 @@ function waiting(root, stateDir, { today } = {}) {
324
370
  return out;
325
371
  }
326
372
 
327
- module.exports = { create, cases, lineOf, off, waiting, runsOf, PER_DAY, RUNS };
373
+ module.exports = { create, cases, lineOf, off, waiting, runsOf, silentDraft, SILENT_AFTER, PER_DAY, RUNS };
@@ -19,6 +19,9 @@
19
19
  * left out when the bet already has a named test.
20
20
  * pmos outcomes tests [--count] [--json] the ranked bets with no smallest test, the tests waiting for a result, and the results;
21
21
  * --count prints the number of bets with a result in the last 14 days (the health number).
22
+ * pmos outcomes rate [--days <n>] [--json] the bet's number (outcome-checks-finish): checks due in the last n days (30) and at least 2
23
+ * days past, how many got a verdict within 2 days, how many of those PMOS recorded; the last
24
+ * line is that percent. Reads only.
22
25
  * every command: [--root <dir>] (default: this repository)
23
26
  *
24
27
  * The agent runs declare and record only after the PM said yes in the chat; the line names who wrote it (lib/actor.js). A verdict is the
@@ -29,7 +32,7 @@ const { execFileSync } = require('child_process');
29
32
  const O = require('./outcomes.js');
30
33
  const ST = require('./smallest-test.js');
31
34
 
32
- const COMMANDS = { outcomes: ['list', 'propose', 'declare', 'record', 'live', 'test', 'tests'] };
35
+ const COMMANDS = { outcomes: ['list', 'propose', 'declare', 'record', 'live', 'test', 'tests', 'rate'] };
33
36
  const USAGE = [
34
37
  'usage: pmos outcomes list|propose|declare|record|live|test|tests — every initiative has an expected outcome and a date to check it',
35
38
  ' pmos outcomes list [--json] checks due, outcomes with no date, initiatives with no outcome; reads only',
@@ -40,8 +43,37 @@ const USAGE = [
40
43
  ' pmos outcomes test <id> --test "<text>" [--method data-count|fake-door|concierge|other] [--result planned|holds|fails|unclear] [--evidence "<text>"]',
41
44
  ' the smallest test that could kill a ranked bet, and what it showed',
42
45
  ' pmos outcomes tests [--count] [--json] ranked bets with no test, tests waiting for a result, results; --count: results in 14 days',
46
+ ' pmos outcomes rate [--days <n>] [--json] checks due in the last n days (30) that got a verdict within 2 days, and how many PMOS did',
43
47
  'Run it in the product\'s repository, or pass --root <dir>. Show each ✦ to the PM and write only after a yes.',
44
48
  ];
49
+ /* `pmos outcomes rate` (initiative outcome-checks-finish): the bet's own number. A check counts when its date fell in the last `days` days
50
+ * and is at least ON_TIME_DAYS past (so it had its full chance); it is on time when a live verdict (not undone) for that date was recorded
51
+ * no later than ON_TIME_DAYS after it, and PMOS's when an agent wrote it. A blocked check is not due (lib/outcomes.js), so it is left out. */
52
+ const RATE_DAYS = 30, ON_TIME_DAYS = 2;
53
+ const addDays = (day, n) => new Date(Date.parse(day + 'T00:00:00Z') + n * 864e5).toISOString().slice(0, 10);
54
+ function rateOf(root, { today, days = RATE_DAYS } = {}) {
55
+ const S = O.scan(root, { today });
56
+ const from = addDays(today, -days), to = addDays(today, -ON_TIME_DAYS);
57
+ const rows = [];
58
+ for (const f of [...new Set([path.join(S.layout.runsDir, 'outcome_checks.jsonl'), path.join(root, 'pmos', 'state', 'outcome_checks.jsonl'), path.join(root, 'planning', 'runs', 'outcome_checks.jsonl')])]) {
59
+ let t = ''; try { t = require('fs').readFileSync(f, 'utf8'); } catch { continue; }
60
+ for (const l of t.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object') rows.push(o); } catch { /* torn */ } }
61
+ }
62
+ const live = O.liveChecks(rows).filter((c) => c && c.initiative_id && O.DISPOSITIONS.includes(c.disposition));
63
+ const blocked = new Set(S.blocked.map((it) => it.id));
64
+ const due = [];
65
+ for (const it of S.subjects) {
66
+ if (!it.metric || !it.horizon || it.horizon < from || it.horizon > to || blocked.has(it.id)) continue;
67
+ const mine = live.filter((c) => c.initiative_id === it.id && (!c.horizon || c.horizon === it.horizon) && String(c.date || c.at || '').slice(0, 10) >= it.horizon)
68
+ .sort((a, b) => String(a.at || a.date).localeCompare(String(b.at || b.date)));
69
+ const v = mine[0] || null, vDate = v ? String(v.date || v.at).slice(0, 10) : null;
70
+ const onTime = !!v && vDate <= addDays(it.horizon, ON_TIME_DAYS);
71
+ due.push({ id: it.id, horizon: it.horizon, onTime, byPmos: onTime && /^agent:/.test(String(v.by || '')), verdict: v ? { disposition: v.disposition, date: vDate, by: v.by || null } : null });
72
+ }
73
+ const byPmos = due.filter((x) => x.byPmos).length;
74
+ return { from, to, days, onTimeDays: ON_TIME_DAYS, due, onTime: due.filter((x) => x.onTime).length, byPmos, pct: due.length ? Math.round((100 * byPmos) / due.length) : null };
75
+ }
76
+
45
77
  const VERDICT = { worked: 'validated', validated: 'validated', 'didnt-work': 'refuted', "didn't-work": 'refuted', refuted: 'refuted', 'cant-tell': 'inconclusive', "can't-tell": 'inconclusive', inconclusive: 'inconclusive' };
46
78
 
47
79
  function parse(args) {
@@ -71,7 +103,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
71
103
  if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
72
104
  if (!COMMANDS.outcomes.includes(sub)) { say(`unknown outcomes command "${sub}". Use one of: ${COMMANDS.outcomes.join(', ')}`); return 2; }
73
105
  const { pos, flags } = parse(args.slice(1));
74
- const allowed = { list: ['json', 'root'], propose: ['json', 'root', 'max'], declare: ['json', 'root', 'metric', 'horizon'], record: ['json', 'root', 'evidence'], live: ['json', 'root', 'where', 'version'], test: ['json', 'root', 'test', 'method', 'result', 'evidence'], tests: ['json', 'root', 'count'] }[sub];
106
+ const allowed = { list: ['json', 'root'], propose: ['json', 'root', 'max'], declare: ['json', 'root', 'metric', 'horizon'], record: ['json', 'root', 'evidence'], live: ['json', 'root', 'where', 'version'], test: ['json', 'root', 'test', 'method', 'result', 'evidence'], tests: ['json', 'root', 'count'], rate: ['json', 'root', 'days'] }[sub];
75
107
  for (const k of Object.keys(flags)) if (!allowed.includes(k)) { say(`✗ --${k} is not an option of pmos outcomes ${sub}`); return 2; }
76
108
  const root = path.resolve(flags.root || repoRoot(cwd));
77
109
  const today = O.todayOf(now);
@@ -95,6 +127,20 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
95
127
  return 0;
96
128
  }
97
129
 
130
+ if (sub === 'rate') {
131
+ if (pos.length) return fail('pmos outcomes rate takes no argument', 2);
132
+ const days = flags.days === undefined ? RATE_DAYS : Number(flags.days);
133
+ if (!Number.isInteger(days) || days < ON_TIME_DAYS || days > 366) return fail(`--days is a whole number from ${ON_TIME_DAYS} to 366`, 2);
134
+ const r = rateOf(root, { today, days });
135
+ if (flags.json) { say(JSON.stringify({ ok: true, ...r })); return 0; }
136
+ const n = r.due.length, onTime = r.due.filter((x) => x.onTime).length;
137
+ say(n ? `${n} check${n === 1 ? '' : 's'} came due from ${O.short(r.from)} to ${O.short(r.to)} · ${onTime} got a verdict within ${ON_TIME_DAYS} days · ${r.byPmos} by PMOS with no PM step`
138
+ : `No check came due from ${O.short(r.from)} to ${O.short(r.to)}.`);
139
+ for (const x of r.due.filter((y) => !y.onTime)) say(` late: ${x.id} — due ${O.short(x.horizon)}${x.verdict ? `, verdict on ${O.short(x.verdict.date)}` : ', no verdict yet'}`);
140
+ say(r.pct == null ? 'none due' : r.pct + '%');
141
+ return 0;
142
+ }
143
+
98
144
  if (sub === 'propose') {
99
145
  if (pos.length > 1) return fail('pmos outcomes propose takes at most one initiative id', 2);
100
146
  const max = flags.max === undefined ? 3 : Number(flags.max);
@@ -194,4 +240,4 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
194
240
  return 0;
195
241
  }
196
242
 
197
- module.exports = { run, COMMANDS, USAGE, VERDICT };
243
+ module.exports = { rateOf, ON_TIME_DAYS, run, COMMANDS, USAGE, VERDICT };
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* plan-baseline.js — every slip against a baseline (initiative slip-baseline-contradictions; bet 1c, proof A102). READ-ONLY: it writes nothing.
4
+ *
5
+ * Proof A102: PMOS moved 96 due dates with no evidence on two products, about 1,470 task-days, and with no baseline the plan still looked on
6
+ * time. The baseline of a task is the FIRST due date its lines ever set. It is derived from the ledgers, never declared, so no record has to
7
+ * be kept in step and every product that has task lines has a baseline today.
8
+ *
9
+ * baselineOf(task) → { baseline, due, open, removed, moves: [line] } PURE. task: a lib/drift-facts.js task
10
+ * daysBetween(a, b) → whole days from day a to day b (YYYY-MM-DD)
11
+ * slipOf(facts, { today }) → { today, initiatives: [row], tasks, days, unsourced_days } PURE. facts: one factsOf result or a list
12
+ * forRepo(root, { now }) → slipOf of one checkout (its state folder found as `pmos drift` finds it)
13
+ *
14
+ * A TASK IS BEHIND when it is open (not Done, not Won't do), not removed, and its current due date is later than its baseline. Its days
15
+ * behind are the days from the baseline to the current due. They count as UNSOURCED when any move after the baseline rests on no source, by
16
+ * the rule of the weekly what-moved list (lib/week-moves.js sourceOf). A task moved earlier, done, removed or never dated is not behind.
17
+ *
18
+ * AN INITIATIVE ROW: { product, name, ini, title, tasks, days, unsourced_days, worst: { task, title, baseline, due, behind, sourced, owner } }
19
+ *
20
+ * CLI: node lib/plan-baseline.js list|count [<root>] [--json]. `count` ends with the unsourced task-days on its last line.
21
+ * Every log line carries [baseline]. */
22
+ const path = require('path');
23
+
24
+ const TAG = '[baseline]';
25
+ const DAY = 86400000;
26
+ const CLOSED = /^(done|won'?t do|cancel+ed|closed)$/i;
27
+ const isDate = (s) => /^\d{4}-\d{2}-\d{2}/.test(String(s || ''));
28
+ const dayOf = (s) => String(s).slice(0, 10);
29
+ const dayMs = (s) => Date.parse(dayOf(s) + 'T00:00:00Z');
30
+ const pad = (n) => String(n).padStart(2, '0');
31
+ const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); };
32
+
33
+ /** Whole days from day a to day b. */
34
+ function daysBetween(a, b) { return Math.round((dayMs(b) - dayMs(a)) / DAY); }
35
+
36
+ /** A task's first due date, its current one, whether it is open, and the lines that moved its date after the first. PURE. */
37
+ function baselineOf(t) {
38
+ const lines = (t && t.lines ? t.lines : []).filter((l) => Number.isFinite(l.at)).slice().sort((a, b) => a.at - b.at);
39
+ let baseline = null, due = null, state, removed = false, owner;
40
+ const moves = [];
41
+ for (const l of lines) {
42
+ if (l.kind === 'task-remove') removed = true;
43
+ if (l.kind === 'task-restore') removed = false;
44
+ if (typeof l.state === 'string' && l.state) state = l.state;
45
+ if (typeof l.owner === 'string' && l.owner.trim()) owner = l.owner;
46
+ if (l.due === undefined) continue;
47
+ const next = isDate(l.due) ? dayOf(l.due) : null;
48
+ if (baseline === null) { if (next) baseline = next; due = next; continue; }
49
+ if (next !== due) moves.push(l);
50
+ due = next;
51
+ }
52
+ return { baseline, due, state: state || '', open: !CLOSED.test(String(state || '').trim()), removed, owner, moves };
53
+ }
54
+
55
+ /** Task-days behind the first plan, per initiative and per product. PURE. */
56
+ function slipOf(facts, { today = localDay(Date.now()) } = {}) {
57
+ const WM = require('./week-moves.js');
58
+ const list = (Array.isArray(facts) ? facts : [facts]).filter(Boolean);
59
+ const rows = [];
60
+ for (const f of list) {
61
+ const titles = new Map((f.initiatives || []).map((i) => [i.id, i.title || i.id]));
62
+ const by = new Map();
63
+ for (const t of f.tasks || []) {
64
+ const b = baselineOf(t);
65
+ if (!b.open || b.removed || !b.baseline || !b.due || b.due <= b.baseline) continue;
66
+ const behind = daysBetween(b.baseline, b.due);
67
+ const sourced = b.moves.every((l) => WM.sourceOf(l).sourced);
68
+ const r = by.get(t.initiative) || { product: f.ws, name: f.name || f.ws, ini: t.initiative, title: titles.get(t.initiative) || t.initiative, tasks: 0, days: 0, unsourced_days: 0, worst: null };
69
+ r.tasks++; r.days += behind; if (!sourced) r.unsourced_days += behind;
70
+ if (!r.worst || behind > r.worst.behind) r.worst = { task: t.id, title: t.title, baseline: b.baseline, due: b.due, behind, sourced, owner: WM.ownerOf(b.owner).owner };
71
+ by.set(t.initiative, r);
72
+ }
73
+ rows.push(...by.values());
74
+ }
75
+ rows.sort((a, b) => b.unsourced_days - a.unsourced_days || b.days - a.days || String(a.title).localeCompare(String(b.title)));
76
+ const sum = (k) => rows.reduce((s, r) => s + r[k], 0);
77
+ return { today, initiatives: rows, tasks: sum('tasks'), days: sum('days'), unsourced_days: sum('unsourced_days') };
78
+ }
79
+
80
+ /** One checkout's slip. Reads its ledgers; writes nothing. */
81
+ function forRepo(root, { now = Date.now(), name } = {}) {
82
+ const Dr = require('./driver.js');
83
+ const f = require('./drift-facts.js').factsOf({ id: Dr.wsIdOf(root), name: name || path.basename(root), root }, { stateDir: Dr.stateDirOf(root) });
84
+ return { notRead: f.notRead, ...slipOf(f, { today: localDay(now) }) };
85
+ }
86
+
87
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
88
+
89
+ function main(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Date.now() } = {}) {
90
+ const pos = [], flags = {};
91
+ for (const a of argv) { if (a === '--json') flags.json = true; else pos.push(a); }
92
+ const [sub = 'list', rootArg] = pos;
93
+ if (!['list', 'count'].includes(sub)) { say('usage: node lib/plan-baseline.js list|count [<root>] [--json] — open tasks behind their first plan, and the days with no source'); return 2; }
94
+ const root = path.resolve(cwd, rootArg || '.');
95
+ let r;
96
+ try { r = forRepo(root, { now }); } catch (e) { say(`${TAG} could not read ${root}: ${(e && e.message) || e}`); return 1; }
97
+ if (flags.json) { say(JSON.stringify(sub === 'count' ? { today: r.today, tasks: r.tasks, days: r.days, unsourced_days: r.unsourced_days, notRead: r.notRead } : r)); return 0; }
98
+ if (sub === 'list') for (const x of r.initiatives) say(`${x.unsourced_days ? '!' : ' '} ${x.title} · ${plural(x.tasks, 'task', 'tasks')} · ${plural(x.days, 'day', 'days')} behind the first plan, ${x.unsourced_days} with no source · worst: ${x.worst.title} (due ${x.worst.baseline} → ${x.worst.due})`);
99
+ say(`${TAG} ${plural(r.tasks, 'open task', 'open tasks')} behind the first plan, ${plural(r.days, 'task-day', 'task-days')} in all, ${r.unsourced_days} with no source${r.notRead.length ? ' (not read: ' + r.notRead.join(', ') + ')' : ''}`);
100
+ if (sub === 'count') say(String(r.unsourced_days));
101
+ return 0;
102
+ }
103
+
104
+ module.exports = { baselineOf, daysBetween, slipOf, forRepo, main, TAG };
105
+
106
+ if (require.main === module) process.exitCode = main(process.argv.slice(2));
@@ -45,7 +45,7 @@ const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-'
45
45
  const WHY = {
46
46
  populate: 'The PM just added this initiative. It most likely already lives elsewhere: find it in every connected source and file what you find (Found elsewhere).',
47
47
  check: 'The morning check: some tasks are late or at risk. Find why each one slipped and file new dates, "looks done" and tidy names.',
48
- outcome: 'Its outcome check date has passed and its goal\'s own reading did not decide it. Read its records and file whether it worked (`pmos propose verdict`), or file nothing when you cannot tell.',
48
+ outcome: 'Its outcome check date has passed and its goal\'s own reading did not decide it. Read its records and file whether it worked (`pmos propose verdict`); when you cannot tell, file `cant-tell` with what you read and what was missing.',
49
49
  };
50
50
 
51
51
  function promptOf(skill, o) {
@@ -192,7 +192,7 @@ function clean(group, type, input) {
192
192
  // PMOS's own verdict on a due outcome (initiative outcome-checks-run-themselves; lib/outcome-judge.js, or the outcome run's `pmos propose
193
193
  // verdict`). Class B: applied by itself with Undo, it records the check in outcome_checks.jsonl (lib/outcomes.js recordCheck)
194
194
  const d = isObj(input.data) ? input.data : {};
195
- if (!['validated', 'refuted'].includes(d.disposition)) return { error: 'data.disposition is validated or refuted (when PMOS cannot tell, it files nothing: the PM is asked)' };
195
+ if (!['validated', 'refuted', 'inconclusive'].includes(d.disposition)) return { error: 'data.disposition is validated, refuted or inconclusive (can\'t tell, with what was read and what was missing: initiative outcome-checks-finish)' };
196
196
  const evidence = one(d.evidence, 600);
197
197
  if (evidence.length < 12) return { error: 'data.evidence says what shows it, at least 12 characters' };
198
198
  if (!DAY_RE.test(str(d.horizon))) return { error: 'data.horizon is the check date it answers, YYYY-MM-DD' };
@@ -87,8 +87,11 @@ const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (a
87
87
 
88
88
  /** `pmos propose verdict`: the outcome run's verdict on a due check (initiative outcome-checks-run-themselves). Every claim's quote must be
89
89
  * on its path:line in the repository (lib/ai-guard.js check) or nothing is filed. It files the class B verdict ✦; the server records it
90
- * with Undo (lib/routes-proposals.js applyOne). "cant-tell" files nothing: the check stays due and Your move asks the PM. */
91
- const VERDICT = { worked: 'validated', 'didnt-work': 'refuted', validated: 'validated', refuted: 'refuted' };
90
+ * with Undo (lib/routes-proposals.js applyOne). "cant-tell" is a verdict too (initiative outcome-checks-finish): it files the same class B ✦ as
91
+ * `inconclusive`, with what the run read and what was missing as its evidence, so the PM is not left a question. Its claims are optional;
92
+ * any it gives still pass the guard. */
93
+ const VERDICT = { worked: 'validated', 'didnt-work': 'refuted', validated: 'validated', refuted: 'refuted', 'cant-tell': 'inconclusive', inconclusive: 'inconclusive' };
94
+ const SAID = { validated: 'worked', refuted: 'didn\'t work', inconclusive: 'can\'t tell' };
92
95
  function verdict(args, { say, stdin, env, file, runId, ini, board, F, line }) {
93
96
  const root = env.PMOS_PROPOSE_ROOT;
94
97
  if (!root) { say('✗ pmos propose verdict is for PMOS\'s outcome run (the server pins PMOS_PROPOSE_ROOT)'); return 1; }
@@ -96,17 +99,23 @@ function verdict(args, { say, stdin, env, file, runId, ini, board, F, line }) {
96
99
  if (!src) { say('usage: pmos propose verdict --json <file|->'); return 2; }
97
100
  const r = readJson(src, stdin); if (r.error) { say('✗ ' + r.error); return 1; }
98
101
  const b = r.body && typeof r.body === 'object' && !Array.isArray(r.body) ? r.body : {};
99
- if (b.disposition === 'cant-tell' || b.disposition === 'inconclusive') { say('filed nothing: the check stays due and Your move asks the PM'); return 0; }
100
102
  const disposition = VERDICT[b.disposition];
101
103
  if (!disposition) { say('✗ refused: disposition is worked, didnt-work or cant-tell'); return 1; }
102
104
  const O = require('./outcomes.js'), AG = require('./ai-guard.js'), J = require('./outcome-judge.js');
103
105
  const it = O.scan(root).due.find((x) => x.id === ini);
104
106
  if (!it) { say(`✗ refused: ${ini} has no outcome check due now`); return 1; }
105
107
  const evidence = String(b.evidence || '').replace(/\s+/g, ' ').trim();
106
- const c0 = AG.check({ id: 'outcome-verdict:' + ini, title: J.WORDS[disposition], say: evidence || '-', confidence: 'medium', cls: 'B', claims: b.claims }, { root, stateDir: require('path').dirname(file) });
107
- if (!c0.ok) { say('✗ refused: ' + c0.errors.join('; ')); return 1; }
108
- const sources = c0.p.claims.flatMap((c) => c.sources).filter((x) => x.verified).map((x) => ({ label: x.label, ref: x.ref }));
109
- const why = `Its check date was ${O.short(it.horizon)}. ${evidence.replace(/[.\s]+$/, '')}. PMOS recorded "${disposition === 'validated' ? 'worked' : 'didn\'t work'}". Undo takes it back.`;
108
+ const cant = disposition === 'inconclusive';
109
+ if (cant && evidence.length < 24) { say('✗ refused: a can\'t tell needs its evidence: what you read and what was missing (at least 24 characters)'); return 1; }
110
+ let sources = [];
111
+ if (!cant || (Array.isArray(b.claims) && b.claims.length)) {
112
+ const c0 = AG.check({ id: 'outcome-verdict:' + ini, title: J.WORDS[disposition], say: evidence || '-', confidence: 'medium', cls: 'B', claims: b.claims }, { root, stateDir: require('path').dirname(file) });
113
+ if (!c0.ok) { say('✗ refused: ' + c0.errors.join('; ')); return 1; }
114
+ sources = c0.p.claims.flatMap((c) => c.sources).filter((x) => x.verified).map((x) => ({ label: x.label, ref: x.ref }));
115
+ }
116
+ // a can't tell with no claims cites the record's outcome line, so it is never a change with no source (lib/autonomy.js)
117
+ if (!sources.length && it.fm && it.fm.outcome_metric) sources = [{ label: 'Expected outcome', ref: it.record + ':' + it.fm.outcome_metric.n }];
118
+ const why = `Its check date was ${O.short(it.horizon)}. ${evidence.replace(/[.\s]+$/, '')}. PMOS recorded "${SAID[disposition]}". Undo takes it back.`;
110
119
  const c = PR.clean('outcome', 'verdict', { title: `${J.WORDS[disposition]}: ${it.title}`.slice(0, 120), why, sources, items: [{ id: 'verdict', title: J.WORDS[disposition] }], data: { disposition, evidence, horizon: it.horizon } });
111
120
  if (c.error) { say('✗ refused: ' + c.error); return 1; }
112
121
  const id = PR.idOf(ini, 'outcome', 'verdict', it.horizon);
@@ -10,6 +10,9 @@
10
10
  * POST /api/drift/looked { week } → { ok } the card was shown for that week
11
11
  * GET /api/drift/moves?ws=<id>[&week=YYYY-MM-DD] → { ok, ws, name, week, label, notRead, rows, total, unsourced } the weekly what-moved list of
12
12
  * one product (initiative weekly-what-moved, lib/week-moves.js): last week by default; read-only
13
+ * GET /api/drift/slip?ws=<id> → { ok, ws, name, notRead, today, initiatives, tasks, days, unsourced_days } open tasks behind
14
+ * their first plan (initiative slip-baseline-contradictions, lib/plan-baseline.js); read-only
15
+ * GET /api/drift/contradictions?ws=<id> → { ok, ws, name, notRead, items, total } records that disagree (lib/contradictions.js); read-only
13
16
  *
14
17
  * THE SWITCH. PMOS_DRIFT=off, or the shared guard's switch (lib/ai-guard.js off: PMOS_AI, the ai settings): every GET answers { ok, on: false }
15
18
  * and every POST 409. WHO WRITES: a POST that carries an agent session header is refused (403); pm-guard requirePagePress checks the page. */
@@ -60,6 +63,33 @@ async function handle(req, res, url, ctx) {
60
63
  return send(bad(500, 'The moves could not be read.'));
61
64
  }
62
65
  }
66
+ if (what === 'slip' || what === 'contradictions') {
67
+ // every slip against the first plan (lib/plan-baseline.js) and records that disagree (lib/contradictions.js): initiative
68
+ // slip-baseline-contradictions. Read-only, no model, so the drift switch does not gate them.
69
+ if (req.method !== 'GET') return send(bad(405, 'GET only'));
70
+ let w = null;
71
+ try { w = ctx.getWs(url.searchParams.get('ws') || null); } catch { w = null; }
72
+ if (!w || !w.root) return send(bad(404, 'no such workspace'));
73
+ const mod = what === 'slip' ? require('./plan-baseline.js') : require('./contradictions.js');
74
+ try {
75
+ const stateDir = ctx.stateDirFor ? ctx.stateDirFor(w) : null;
76
+ let rows = [];
77
+ try { const IR = require('./initiative-rows.js').rowsFor(w.root); rows = IR && IR.ok ? IR.rows : []; } catch { rows = []; }
78
+ const f = require('./drift-facts.js').factsOf({ id: w.id, name: w.name || w.id, root: w.root }, { stateDir, rows });
79
+ const now = nowMs(ctx);
80
+ if (what === 'slip') {
81
+ const r = mod.slipOf(f, { today: new Date(now).toISOString().slice(0, 10) });
82
+ console.log(`${mod.TAG} ws=${w.id} tasks=${r.tasks} days=${r.days} unsourced_days=${r.unsourced_days}`);
83
+ return send({ status: 200, body: { ok: true, ws: w.id, name: w.name || w.id, notRead: f.notRead, ...r } });
84
+ }
85
+ const items = mod.contradictionsOf(f, { now });
86
+ console.log(`${mod.TAG} ws=${w.id} items=${items.length}`);
87
+ return send({ status: 200, body: { ok: true, ws: w.id, name: w.name || w.id, notRead: f.notRead, items, total: items.length } });
88
+ } catch (e) {
89
+ console.warn(mod.TAG + ' could not read ' + w.id + ': ' + ((e && e.message) || e));
90
+ return send(bad(500, 'The records could not be read.'));
91
+ }
92
+ }
63
93
  if (!['drop', 'undo', 'looked'].includes(what)) return send(bad(404, 'no such drift route'));
64
94
  if (req.method !== 'POST') return send(bad(405, 'POST only'));
65
95
  if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'Only you drop an item, from the page.'));
@@ -123,12 +123,17 @@ async function realBrief(ctx, ev, date) {
123
123
  const layers = require('./calendar-layers.js');
124
124
  const views = require('./routes-calendar-views.js');
125
125
  let inis = [];
126
- if (root) { try { const facts = await require('./facts-async.js').readFactsAsync(root); inis = ((facts && facts.inis) || []).filter((i) => i && i.id).map((i) => ({ id: i.id, title: i.title || i.id, status: null })); } catch { inis = []; } }
126
+ if (root) { try { const facts = await require('./facts-async.js').readFactsAsync(root); inis = ((facts && facts.inis) || []).filter((i) => i && i.id).map((i) => ({ id: i.id, title: i.title || i.id, status: null, parent_kr: i.parent_kr || null })); } catch { inis = []; } }
127
127
  const src = root ? views.readers(root, ctx.runtimeDir).readContextSources() : { notes: [], planItems: [], ownItems: [] };
128
128
  const mine = (src.notes || []).filter((n) => n.meeting && (n.meeting.event_id === ev.id || n.meeting.event_id === baseId(ev.id)));
129
129
  let links = null; try { links = require('./calendar-links.js').read(ctx.runtimeDir); } catch { links = null; }
130
130
  let boards = null; try { boards = require('./routes-boards.js').meetingBoards(ctx); } catch { boards = null; }
131
131
  brief = layers.briefOf(ev, mine, src, { today: localDay(Date.now()), inis, links, boards }).brief || null;
132
+ // meeting-float: the initiative's goal, from its anchor (a key result, an objective or a health budget)
133
+ if (brief && brief.initiative && root) {
134
+ const row = inis.find((i) => i.id === brief.initiative.id);
135
+ if (row && row.parent_kr) { try { const g = F.goalOf(row.parent_kr, require('./initiative-rows.js').anchorsOf(root).resolve); if (g) brief.initiative.goal = g; } catch { /* no goal */ } }
136
+ }
132
137
  } catch { brief = null; }
133
138
  briefCache.set(key, { at: Date.now(), brief });
134
139
  return brief;
@@ -5,7 +5,8 @@
5
5
  * GET /api/open-questions?ws=<id> → { ok, ws, today, lines: [lib/open-questions.js line], median_age }
6
6
  *
7
7
  * The day's question list comes from lib/routes-your-move.js questions() with take: false, so this read never takes a default (taking
8
- * stays with Your move, lib/default-decisions.js). The open Driver drafts come from the repository's driver.jsonl. Nothing is sent. */
8
+ * stays with Your move, lib/default-decisions.js). The open Driver drafts come from the repository's driver.jsonl. Records that disagree come
9
+ * from lib/contradictions.js (initiative slip-baseline-contradictions). Nothing is sent. */
9
10
  const OQ = require('./open-questions.js');
10
11
 
11
12
  module.exports = {
@@ -19,8 +20,14 @@ module.exports = {
19
20
  const now = Date.now(), today = OQ.localDay(now);
20
21
  let questions = null;
21
22
  try { questions = require('./routes-your-move.js').questions(ctx, w, today, { take: false }).questions; } catch { questions = null; }
23
+ // records that disagree (lib/contradictions.js): from the initiative rows as already read, never a synchronous derive on a request
24
+ let records = [];
22
25
  try {
23
- const r = OQ.read(w.root, { now, questions });
26
+ const IR = require('./initiative-rows.js').rowsFor(w.root);
27
+ if (IR && IR.ok) records = require('./contradictions.js').forRepo(w.root, { now, rows: IR.rows, id: w.id, name: w.name, stateDir: ctx.stateDirFor ? ctx.stateDirFor(w) : undefined }).items;
28
+ } catch { records = []; }
29
+ try {
30
+ const r = OQ.read(w.root, { now, questions, records });
24
31
  console.log(`${OQ.TAG} ws=${w.id} lines=${r.lines.length} median_age=${r.median_age}`);
25
32
  ctx.json(res, { ok: true, ws: w.id, ...r });
26
33
  } catch (e) { ctx.json(res, { ok: false, error: String((e && e.message) || e) }, 500); }
@@ -37,6 +37,7 @@ const STALE_MS = 26 * H; // the same as lib/task-jira.js: the Jira read
37
37
  const STUCK_DAYS = 5; // in progress with no change for this many days is worth a question
38
38
  const MAX_QUESTIONS = 8;
39
39
  const OTHER = 'Other work in the sprint';
40
+ const NEW = 'Not in PMOS yet'; // a ticket the standup search saw move and no read holds (initiative standup-from-one-read)
40
41
  const KEY_RE = /^[A-Z][A-Z0-9_]*-\d+$/;
41
42
  const isStr = (v) => typeof v === 'string';
42
43
  const ms = (v) => { const t = Date.parse(isStr(v) ? v : ''); return Number.isFinite(t) ? t : null; };
@@ -128,8 +129,9 @@ function build({ moves = [], snapshots = [], sprints = null, known = new Set(),
128
129
  .sort((a, b) => ms(a.at) - ms(b.at));
129
130
  const byKey = new Map();
130
131
  for (const m of inWin) { if (!byKey.has(m.k)) byKey.set(m.k, []); byKey.get(m.k).push(m); }
131
- const groupOf = (key, ini) => {
132
+ const groupOf = (key, ini, untracked) => {
132
133
  const e = R.get(key);
134
+ if (!e && !ini && untracked) return NEW;
133
135
  const i = ini || (e && e.ini);
134
136
  if (i) return titles.get(i) || i;
135
137
  const r = e && e.r;
@@ -142,7 +144,7 @@ function build({ moves = [], snapshots = [], sprints = null, known = new Set(),
142
144
  if (first.f === last.s) continue; // went back to where it started
143
145
  const e = R.get(key); const r = e ? e.r : null;
144
146
  moved.push({ key, summary: (r && r.summary) || last.n || '', from: first.f, fromCategory: first.fc || null, to: last.s, category: last.c || (r && r.category) || null,
145
- who: (r && r.assignee) || last.w || null, group: groupOf(key, last.i), url: (r && r.url) || null, inPmos: known.has(key), at: last.at });
147
+ who: (r && r.assignee) || last.w || null, group: groupOf(key, last.i, last.u === 1), url: (r && r.url) || null, inPmos: known.has(key), at: last.at });
146
148
  }
147
149
  // resolved in the window with no move kept (a ticket first read already done, or the first day after the release)
148
150
  // Jira gives the resolution as a day: a ticket with an earlier move kept, or a last update before the window, closed before it.
@@ -160,7 +162,8 @@ function build({ moves = [], snapshots = [], sprints = null, known = new Set(),
160
162
  moved.sort((a, b) => (rank[a.category] ?? 3) - (rank[b.category] ?? 3) || a.key.localeCompare(b.key, 'en', { numeric: true }));
161
163
  const groups = [];
162
164
  for (const m of moved) { let g = groups.find((x) => x.name === m.group); if (!g) { g = { name: m.group, items: [] }; groups.push(g); } g.items.push(m); }
163
- groups.sort((a, b) => (a.name === OTHER) - (b.name === OTHER) || b.items.length - a.items.length || a.name.localeCompare(b.name));
165
+ const tail = (g) => (g.name === NEW ? 2 : g.name === OTHER ? 1 : 0);
166
+ groups.sort((a, b) => tail(a) - tail(b) || b.items.length - a.items.length || a.name.localeCompare(b.name));
164
167
 
165
168
  // worth a question, the most pressing kind first
166
169
  const q = [];
@@ -227,4 +230,21 @@ function render(d) {
227
230
  return out;
228
231
  }
229
232
 
233
+ /** The health number of standup-from-one-read: moves of tickets no initiative holds, kept in the last `days` days. */
234
+ function untrackedCount(root, { days = 7, now = Date.now() } = {}) {
235
+ const from = now - days * DAY;
236
+ return readMoves(root).filter((m) => m.u === 1 && ms(m.at) >= from && ms(m.at) <= now).length;
237
+ }
238
+
239
+ // `node lib/tracker-digest.js untracked [root] [--days N]`: the count on the last line
240
+ function main(a) {
241
+ if (a[0] !== 'untracked') { process.stderr.write('usage: node lib/tracker-digest.js untracked [root] [--days N]\n'); process.exitCode = 2; return null; }
242
+ let days = 7; let dir = '.';
243
+ for (let i = 1; i < a.length; i++) { if (a[i] === '--days') { const v = Number(a[++i]); if (Number.isFinite(v) && v > 0) days = v; } else dir = a[i]; }
244
+ const n = untrackedCount(path.resolve(dir), { days });
245
+ process.stdout.write(`[standup-from-one-read] moves of tickets no initiative holds, last ${days} days\n${n}\n`);
246
+ return n;
247
+ }
248
+ const ran = require.main === module ? main(process.argv.slice(2)) : null;
249
+
230
250
  module.exports = { FILE, STALE_MS, STUCK_DAYS, MAX_QUESTIONS, OTHER, fileOf, movesOf, append, readMoves, windowOf, build, gather, render };
@@ -19,6 +19,8 @@
19
19
  * dates that meet are a guess) is not sourced.
20
20
  * owner who to ask: the task's owner, else the PM ('you', toPm) when the plan names nobody or names an agent
21
21
  * ref path:line of the line it came from, and `quote` that line's text (lib/drift-facts.js)
22
+ * baseline a date row's first due date (the task's first plan) and `behind` the days from it to the new date, negative when ahead
23
+ * (initiative slip-baseline-contradictions, lib/plan-baseline.js)
22
24
  *
23
25
  * CLI: node lib/week-moves.js list|count [<root>] [--week YYYY-MM-DD] [--json]. `count` ends with the number of moves on its last line.
24
26
  * Every log line carries [moves]. */
@@ -74,7 +76,7 @@ function productMoves(f, from, to) {
74
76
  const rows = [], scope = new Map();
75
77
  for (const t of f.tasks || []) {
76
78
  const lines = (t.lines || []).filter((l) => Number.isFinite(l.at)).slice().sort((a, b) => a.at - b.at);
77
- let due, owner;
79
+ let due, owner, first = null; // first: the task's first due date, its baseline (lib/plan-baseline.js; initiative slip-baseline-contradictions)
78
80
  for (const l of lines) {
79
81
  if (typeof l.owner === 'string' && l.owner.trim()) owner = l.owner;
80
82
  const inWeek = l.at >= from && l.at < to;
@@ -89,7 +91,11 @@ function productMoves(f, from, to) {
89
91
  }
90
92
  if (l.due !== undefined) {
91
93
  const next = isDate(l.due) ? String(l.due).slice(0, 10) : '';
92
- if (inWeek && l.kind === 'task-update' && due !== undefined && next !== due) rows.push({ ...base(), kind: 'date', n: 1, titles: [t.title], was: due || null, now: next || null });
94
+ if (inWeek && l.kind === 'task-update' && due !== undefined && next !== due) {
95
+ const behind = first && next ? Math.round((Date.parse(next + 'T00:00:00Z') - Date.parse(first + 'T00:00:00Z')) / 86400000) : null;
96
+ rows.push({ ...base(), kind: 'date', n: 1, titles: [t.title], was: due || null, now: next || null, baseline: first, behind });
97
+ }
98
+ if (first === null && next) first = next;
93
99
  due = next;
94
100
  }
95
101
  }