create-pmos 0.690.0 → 0.692.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.690.0",
3
+ "version": "0.692.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -34,8 +34,21 @@
34
34
  ],
35
35
  "pmosChanges": [
36
36
  {
37
- "v": "0.690.0",
38
- "at": "2026-11-22T09:18:54.354Z",
37
+ "v": "0.692.0",
38
+ "at": "2026-11-22T09:33:00.888Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1515,
43
+ "t": "Show who raised each initiative (Raised by column, group, sort and filter on Work)",
44
+ "s": "Show who raised each initiative (Raised by column, group, sort and filter on Work)",
45
+ "k": "new"
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "v": "0.691.0",
51
+ "at": "2026-11-22T09:21:12.074Z",
39
52
  "f": 4,
40
53
  "prs": [
41
54
  {
@@ -55,6 +68,12 @@
55
68
  "t": "Kind marks each lifecycle stage owned, watched or hidden",
56
69
  "s": "Kind marks each lifecycle stage owned, watched or hidden",
57
70
  "k": "new"
71
+ },
72
+ {
73
+ "n": 1503,
74
+ "t": "One record of every agent change, and no source, no auto (A443)",
75
+ "s": "One record of every agent change, and no source, no auto (A443)",
76
+ "k": "new"
58
77
  }
59
78
  ]
60
79
  },
@@ -399,19 +418,6 @@
399
418
  "k": "fix"
400
419
  }
401
420
  ]
402
- },
403
- {
404
- "v": "0.651.0",
405
- "at": "2026-11-20T07:19:20.677Z",
406
- "f": 4,
407
- "prs": [
408
- {
409
- "n": 1433,
410
- "t": "Quick edit in a row and full popups for a task and a milestone",
411
- "s": "Quick edit in a row and full popups for a task and a milestone",
412
- "k": "new"
413
- }
414
- ]
415
421
  }
416
422
  ]
417
423
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@b5c57f64
1
+ kernel-source: pmos@083c7b32
2
2
  assembled: 2026-11-22
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-22T09:18:51Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T09:32:57Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-22T09:18:51Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T09:32:57Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-22T09:18:51Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T09:32:57Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,7 +1,20 @@
1
1
  [
2
2
  {
3
- "v": "0.690.0",
4
- "at": "2026-11-22T09:18:54.354Z",
3
+ "v": "0.692.0",
4
+ "at": "2026-11-22T09:33:00.888Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1515,
9
+ "t": "Show who raised each initiative (Raised by column, group, sort and filter on Work)",
10
+ "s": "Show who raised each initiative (Raised by column, group, sort and filter on Work)",
11
+ "k": "new"
12
+ }
13
+ ]
14
+ },
15
+ {
16
+ "v": "0.691.0",
17
+ "at": "2026-11-22T09:21:12.074Z",
5
18
  "f": 4,
6
19
  "prs": [
7
20
  {
@@ -21,6 +34,12 @@
21
34
  "t": "Kind marks each lifecycle stage owned, watched or hidden",
22
35
  "s": "Kind marks each lifecycle stage owned, watched or hidden",
23
36
  "k": "new"
37
+ },
38
+ {
39
+ "n": 1503,
40
+ "t": "One record of every agent change, and no source, no auto (A443)",
41
+ "s": "One record of every agent change, and no source, no auto (A443)",
42
+ "k": "new"
24
43
  }
25
44
  ]
26
45
  },
@@ -205,6 +205,13 @@ Before you share a spec, a strategy, a roadmap or a report, PMOS reads it as a s
205
205
 
206
206
  [What PMOS does behind the scenes](agent-capabilities.md) lists the jobs and their queue names.
207
207
 
208
+ ### pmos factory: everything PMOS changed by itself
209
+
210
+ - `pmos factory today` shows one record of every change PMOS made: for each line (product, project, SDLC) and station, how many changes, how many PMOS applied by itself, how many were kept, undone or ignored, how many cite no source, and how many background runs it used.
211
+ - `pmos factory today --days 7` shows the last 7 days. `--json` prints the totals.
212
+ - `pmos factory today --unsourced` prints one number on its last line: the percent of changes PMOS applied by itself that cite no source.
213
+ - A change that cites no source never applies by itself. It waits for you, as a change others see does.
214
+
208
215
  ### pmos autonomy: what agents applied by themselves
209
216
 
210
217
  - `pmos autonomy status` lists what agents applied in the last 14 days (D106), each with its id, and the jobs that went back to propose.
@@ -360,7 +367,7 @@ A page that keeps breaking should get fixed before it gets a new feature. This c
360
367
 
361
368
  | Command | What it does |
362
369
  |---|---|
363
- | `pmos initiative new "<title>" --lane <lane> --anchor <anchor> [--intent "<text>"] [--id <id>]` | Makes the record and puts it at the end of the Roadmap. |
370
+ | `pmos initiative new "<title>" --lane <lane> --anchor <anchor> [--intent "<text>"] [--id <id>] [--raised-by "<who>"]` | Makes the record and puts it at the end of the Roadmap. |
364
371
  | `pmos initiative new --from <capture> [--anchor <anchor>]` | Adds the initiative a capture proposes. |
365
372
  | `pmos initiative top <id>` | Ranks it first. |
366
373
  | `pmos initiative up <id>` | Moves it one place up. |
@@ -374,6 +381,8 @@ A page that keeps breaking should get fixed before it gets a new feature. This c
374
381
  | `pmos initiative export <id>` | Writes the breakdown as markdown to the terminal. |
375
382
  | `pmos initiative describe <id>` | Shows the description, and the lines PMOS can draft it from. |
376
383
  | `pmos initiative describe <id> "<text>"` | Saves the description. PMOS runs this only after your yes. |
384
+ | `pmos initiative raised-by <id>` | Shows who raised it: you, a teammate, a customer, PMOS or the tracker. |
385
+ | `pmos initiative raised-by <id> "<who>"` | Saves who raised it: `you`, `pmos`, `tracker`, `"teammate: <name>"` or `"customer: <name>"`. `none` removes it. |
377
386
 
378
387
  Every command takes `--json` and `--root <dir>`. The command does not accept `--by` or `--via`. `pmos initiative now`, `next` and `later` are retired: they write nothing, say what to use instead and exit 2.
379
388
 
@@ -29,6 +29,12 @@
29
29
  *
30
30
  * CLASSES · DRIVER_CLASS · PROPOSAL_CLASS · DEMOTE_DAYS · UNDO_DAYS · RATE_LIMIT · RATE_MIN
31
31
  * classOfDriver(what) · classOfProposal(p) → 'A' | 'B' | 'C'
32
+ * classOfDriverProposal(p) → 'A' | 'B' | 'C' classOfDriver plus the source rule
33
+ *
34
+ * NO SOURCE, NO AUTO (initiative one-change-record-no-source-no-auto, idea A443). In every job kind, a change that cites nothing
35
+ * (lib/source-guard.js citedOf: no source, no item or claim source, a link guessed from the plan, "No reason found") is class C: it waits
36
+ * for the PM. decide() takes the change's `sources` and refuses an auto apply when they are given and empty; recordApplied keeps them as
37
+ * `src`, so lib/change-record.js counts unsourced changes without a join. Every refusal logs one [no-source-no-auto] line.
32
38
  * file(stateDir) · read(stateDir) → lines · fold(lines, { now }) → state the ledger
33
39
  * recordApplied(stateDir, { job, product, ref, title, cls, ini?, why?, run? }, { now, settingsDir }) writes the way the job acted with
34
40
  * (wayAt: quiet or show, the kept count, the PM's setting), so the line can say why it was quiet
@@ -117,9 +123,18 @@ function waysSet(settingsDir) {
117
123
  const autoWay = ({ kept = 0, demoted = false } = {}) => (demoted ? 'ask' : kept >= SHOW_UNTIL ? 'quiet' : 'show');
118
124
 
119
125
  const classOfDriver = (what) => DRIVER_CLASS[what] || 'C';
126
+ const SG = () => require('./source-guard.js');
127
+ /** A Driver proposal's class: its kind's class, and C when it cites no source (no source, no auto). */
128
+ function classOfDriverProposal(p) {
129
+ if (!isObj(p)) return 'C';
130
+ const c = classOfDriver(p.what);
131
+ return c !== 'C' && !SG().citedOf(p).length ? 'C' : c;
132
+ }
120
133
  function classOfProposal(p) {
121
134
  if (!isObj(p)) return 'C';
122
135
  const c = PROPOSAL_CLASS[p.group] || 'C';
136
+ // no source, no auto, in every group (A443): the plan groups' finer rule below (two kinds for a big change) still applies
137
+ if (c !== 'C' && p.group !== 'build' && !SG().citedOf(p).length) return 'C';
123
138
  // act-alone-only-with-a-source: a plan change with no source, or a close, rename or big date move on one kind of source, is the owner's
124
139
  // question (lib/source-guard.js); it joins the day's question list instead of applying by itself
125
140
  if (c !== 'C' && require('./source-guard.js').holdOf(p)) return 'C';
@@ -130,7 +145,7 @@ function classOfProposal(p) {
130
145
  // a live round's prototype (lib/live-round.js, data.live) is the PM's to keep: PMOS never keeps one by itself (2026-11-18: a test round it
131
146
  // kept became the initiative's design). The newest version is the prototype anyway (lib/proposals.js currentOf).
132
147
  if ((p.group === 'prototyped' || p.group === 'improved') && isObj(p.data) && isObj(p.data.live)) return 'C';
133
- if (p.group === 'build') return 'B'; // stopping or replacing an experiment is the PM's call (launch simulation W2)
148
+ if (p.group === 'build') return SG().citedOf(p).length ? 'B' : 'C'; // stopping or replacing an experiment is the PM's call (launch simulation W2)
134
149
  // a maybe, or a duplicate already in another initiative (type link, or an item with `other`), is a question for the PM, not a change
135
150
  // found type stage moves the initiative's stage: a stage move is C (as the Driver's `move`)
136
151
  if (p.group === 'found' && (p.type === 'stage' || p.type === 'maybe' || p.type === 'link' || (p.items || []).some((x) => x && x.other))) return 'C';
@@ -172,7 +187,7 @@ function fold(lines) {
172
187
  const j = get(l.job, l.product);
173
188
  if (l.ev === 'applied') {
174
189
  const a = { ref: l.ref || null, title: l.title || '', cls: l.cls || null, job: l.job, product: l.product || null, ini: l.ini || null, why: l.why || '', at: l.at, undone: false, undoneAt: null,
175
- run: l.run || null, rec: WAYS.includes(l.way) && Number.isInteger(l.kept) ? { way: l.way, kept: l.kept, set: l.set === true } : null, checked: null };
190
+ run: l.run || null, src: Array.isArray(l.src) ? l.src : null, rec: WAYS.includes(l.way) && Number.isInteger(l.kept) ? { way: l.way, kept: l.kept, set: l.set === true } : null, checked: null };
176
191
  j.applied.push(a);
177
192
  if (a.ref) applied.set(a.ref, a);
178
193
  } else if (l.ev === 'setback') {
@@ -221,11 +236,14 @@ function wayAt(stateDir, job, product, { settingsDir = null } = {}) {
221
236
  return own && own !== 'ask' ? { way: own, kept, set: true } : { way: autoWay({ kept }), kept, set: false };
222
237
  }
223
238
 
224
- function recordApplied(stateDir, { job, product, ref, title, cls, ini, why, run }, { now, settingsDir = null } = {}) {
239
+ /** src: what the change cited (labels, or { label, ref } sources); kept as up to 3 labels, [] when it cited nothing (lib/change-record.js). */
240
+ const srcOf = (src) => (Array.isArray(src) ? [...new Set(src.map((s) => (isObj(s) ? s.label || s.ref : s)).filter((s) => typeof s === 'string' && s.trim()).map((s) => one(s, 80)))].slice(0, 3) : null);
241
+ function recordApplied(stateDir, { job, product, ref, title, cls, ini, why, run, src }, { now, settingsDir = null } = {}) {
225
242
  if (!JOB_RE.test(String(job || ''))) return null;
226
243
  const w = wayAt(stateDir, job, product, { settingsDir });
244
+ const s = srcOf(src);
227
245
  return append(stateDir, { ev: 'applied', job, product: product || null, ref: ref ? one(ref, 120) : null, title: one(title, 200), cls: CLASSES.includes(cls) ? cls : null,
228
- ...(ini ? { ini: one(ini, 80) } : {}), ...(why ? { why: one(why, 200) } : {}), ...(run ? { run: one(run, 80) } : {}),
246
+ ...(ini ? { ini: one(ini, 80) } : {}), ...(why ? { why: one(why, 200) } : {}), ...(run ? { run: one(run, 80) } : {}), ...(s ? { src: s } : {}),
229
247
  way: w.way, kept: w.kept, ...(w.set ? { set: true } : {}) }, { now });
230
248
  }
231
249
 
@@ -252,11 +270,24 @@ function killed({ env = process.env, settingsDir = null } = {}) {
252
270
  return null;
253
271
  }
254
272
 
255
- function decide({ stateDir, job, product, cls, mode = 'auto', undoable = true, now, env = process.env, settingsDir = null } = {}) {
273
+ const NO_SOURCE_WHY = 'no source: the change cites nothing, so PMOS asks instead of applying it';
274
+ const logged = new Set();
275
+ /** One [no-source-no-auto] log line per held change per process (the health log of one-change-record-no-source-no-auto). */
276
+ function logHeld(job, product, ref, { log = console.error } = {}) {
277
+ const k = `${job}|${product || '*'}|${ref || ''}`;
278
+ if (logged.has(k)) return false;
279
+ if (logged.size > 5000) logged.clear();
280
+ logged.add(k);
281
+ try { log(`[no-source-no-auto] held ${job}${product ? ' on ' + product : ''}${ref ? ' ' + one(ref, 80) : ''}: it cites no source`); } catch { /* a log never stops the apply step */ }
282
+ return true;
283
+ }
284
+ /** sources: what the change cites (lib/source-guard.js citedOf). Given and empty: no source, no auto, whatever the class. */
285
+ function decide({ stateDir, job, product, cls, mode = 'auto', undoable = true, now, env = process.env, settingsDir = null, sources } = {}) {
256
286
  const k = killed({ env, settingsDir });
257
287
  if (k) return { apply: false, why: k };
258
288
  if (mode !== 'auto') return { apply: false, why: `the mode is ${mode}` };
259
- if (cls === 'C' || !CLASSES.includes(cls)) return { apply: false, why: 'class C: seen by others or not reversible, so it waits for the daily press' };
289
+ if (cls === 'C' || !CLASSES.includes(cls)) return { apply: false, why: 'class C: seen by others or not reversible, so it waits for the daily press', ...(Array.isArray(sources) && !sources.length ? { nosrc: true } : {}) };
290
+ if (Array.isArray(sources) && !sources.length) return { apply: false, why: NO_SOURCE_WHY, nosrc: true };
260
291
  if (!undoable) return { apply: false, why: 'no Undo for this change, so it waits' };
261
292
  const set = waysSet(settingsDir)[kindOf(job)];
262
293
  if (set === 'ask') return { apply: false, why: 'you set this kind to Ask first' };
@@ -270,9 +301,10 @@ function decide({ stateDir, job, product, cls, mode = 'auto', undoable = true, n
270
301
 
271
302
  /** For a caller with no mode of its own (a role agent, an AI job): does class `cls` apply by itself now? With `stateDir` and `job`
272
303
  * the demotion of that job counts too. Class C never does. */
273
- function autoFor(cls, { stateDir = null, job = null, product = null, undoable = true, now, env = process.env, settingsDir = null } = {}) {
304
+ function autoFor(cls, { stateDir = null, job = null, product = null, undoable = true, now, env = process.env, settingsDir = null, sources } = {}) {
305
+ if (Array.isArray(sources) && !sources.length) return false; // no source, no auto
274
306
  if (!stateDir || !job) return !killed({ env, settingsDir }) && (cls === 'A' || cls === 'B') && !!undoable;
275
- return decide({ stateDir, job, product, cls, mode: 'auto', undoable, now, env, settingsDir }).apply;
307
+ return decide({ stateDir, job, product, cls, mode: 'auto', undoable, now, env, settingsDir, sources }).apply;
276
308
  }
277
309
 
278
310
  function notices(stateDir, { now } = {}) {
@@ -414,5 +446,5 @@ function restore(stateDir, { job, product }, actor, { now } = {}) {
414
446
  module.exports = {
415
447
  wayAt, toCheck, recordCheck, fromRuns, VERDICTS, WAYS, SHOW_UNTIL, KIND_LIST, kindOf, waysSet, autoWay, kindsOf,
416
448
  LEDGER, CLASSES, DRIVER_CLASS, PROPOSAL_CLASS, DEMOTE_DAYS, UNDO_DAYS, RATE_LIMIT, RATE_MIN, KINDS,
417
- classOfDriver, classOfProposal, killed, autoFor, file, read, fold, recordApplied, reasonOf, recordSetback, decide, demotedNow, notices, markSeen, done, undoOpen, restore,
449
+ classOfDriver, classOfDriverProposal, classOfProposal, NO_SOURCE_WHY, logHeld, srcOf, killed, autoFor, file, read, fold, recordApplied, reasonOf, recordSetback, decide, demotedNow, notices, markSeen, done, undoOpen, restore,
418
450
  };
@@ -275,6 +275,14 @@ const gapsOf = (r) => (Array.isArray(r.gaps) ? r.gaps : []).filter((g) => g && d
275
275
  /** Where the dated work of each stage runs (batch 11 item 13): the » of a skipped stage sits between two of them. */
276
276
  const stageSpansOf = (r) => (Array.isArray(r.stageSpans) ? r.stageSpans : []).filter((x) => x && stageKey(x.stage) && dayOr(x.start) && dayOr(x.due)).slice(0, 40)
277
277
  .map((x) => ({ stage: stageKey(x.stage), start: x.start, due: x.due }));
278
+ /** Who raised the row (lib/initiative-origin.js, built by the route): kept only in its known shape, else null (a row with none shows nothing). */
279
+ const ORIGIN_KINDS = ['you', 'teammate', 'customer', 'pmos', 'tracker'];
280
+ function originOf(r) {
281
+ const o = r && r.origin;
282
+ if (!o || !ORIGIN_KINDS.includes(o.kind) || typeof o.label !== 'string' || typeof o.group !== 'string') return null;
283
+ return { kind: o.kind, name: typeof o.name === 'string' ? clip(o.name, 60) : null, label: clip(o.label, 80), group: o.group, source: o.source === 'record' ? 'record' : 'roadmap' };
284
+ }
285
+
278
286
  function rowOf(r0, wf, today) {
279
287
  // T3 (lib/status-proof.js): a status word the row cannot prove (no source, no read time) says No signal, on every surface that reads it
280
288
  const r = r0 && r0.status ? { ...r0, status: SP.provenStatus(r0) } : r0;
@@ -282,7 +290,7 @@ function rowOf(r0, wf, today) {
282
290
  const bad = r.status === 'late' || r.status === 'at risk';
283
291
  const facts = [
284
292
  ['Lane', r.lane], ['Stage', r.stage ? r.stage + (r.stageSource ? ' (' + r.stageSource + ')' : '') : ''], ['Anchor', r.anchor], ['Rank', Number.isInteger(r.rank) ? '#' + (r.rank + 1) + ' on the Roadmap' : ''],
285
- ['Status', STATUS_LABEL[r.status] || (r.status ? r.status.charAt(0).toUpperCase() + r.status.slice(1) : '')], ['Owner', r.owner],
293
+ ['Status', STATUS_LABEL[r.status] || (r.status ? r.status.charAt(0).toUpperCase() + r.status.slice(1) : '')], ['Owner', r.owner], ['Raised by', originOf(r) ? originOf(r).label : ''],
286
294
  ['Progress', pctOf(r.progress) != null ? pctOf(r.progress) + '%' : ''], ['Starts', r.start ? shortDate(r.start) : ''], ['Ends', r.end ? shortDate(r.end) : ''],
287
295
  ['Last changed', r.updated ? shortDate(String(r.updated).slice(0, 10)) : ''], ['Possible duplicate of', r.dupOf], ['Warnings', (r.warnings || []).map((w) => (typeof w === 'string' ? w : w && (w.text || w.message || w.id)) || '').filter(Boolean).join('; ')],
288
296
  ].filter((x) => x[1]);
@@ -294,7 +302,7 @@ function rowOf(r0, wf, today) {
294
302
  stage: r.stage || null, cat: r.cat || null, stageNote: r.stageSource === 'derived' ? 'derived' : null,
295
303
  seg: names.map((n, j) => (j < cur ? 'p' : j === cur ? 'n' : '')), progress: pctOf(r.progress),
296
304
  finish: r.end ? shortDate(r.end) : 'Not planned', over: !!over, start: r.start || null, end: r.end || null,
297
- owner: r.owner || null, lane: r.lane || null, kind: KINDS.includes(r.kind) ? r.kind : 'product', anchor: r.anchor || null, kr: krShort(r.anchor), rank: Number.isInteger(r.rank) ? r.rank : null, warnings: (r.warnings || []).filter((w) => typeof w === 'string').slice(0, 12), epics: Array.isArray(r.epics) ? r.epics.filter((e) => typeof e === 'string').slice(0, 6) : [], updated: r.updated || null, reading: r.reading || null, overDays: over ? days(r.end, today) : 0,
305
+ owner: r.owner || null, origin: originOf(r), lane: r.lane || null, kind: KINDS.includes(r.kind) ? r.kind : 'product', anchor: r.anchor || null, kr: krShort(r.anchor), rank: Number.isInteger(r.rank) ? r.rank : null, warnings: (r.warnings || []).filter((w) => typeof w === 'string').slice(0, 12), epics: Array.isArray(r.epics) ? r.epics.filter((e) => typeof e === 'string').slice(0, 6) : [], updated: r.updated || null, reading: r.reading || null, overDays: over ? days(r.end, today) : 0,
298
306
  acts: actsOf(r, names),
299
307
  // the PM's standing verdict on the outcome (launch simulation W2): the Next cell stops asking "did it work?" once it is answered
300
308
  outcome: r.outcome && r.outcome.verdict ? { verdict: r.outcome.verdict, current: !!r.outcome.current, ...(r.outcome.next ? { next: r.outcome.next } : {}) } : null,
@@ -0,0 +1,303 @@
1
+ 'use strict';
2
+ /* change-record.js — one record of every agent change (initiative one-change-record-no-source-no-auto; idea A443; the factory grill
3
+ * W24NtYWFttw8DkqFVuoJCB, slice 1). READ-ONLY: this file never writes a line anywhere.
4
+ *
5
+ * PMOS changes a product by itself from six ledgers, each with its own writer: autonomy.jsonl (what an agent applied, lib/autonomy.js),
6
+ * proposals.jsonl (the ✦, lib/proposals.js), driver.jsonl (the Initiative Driver, lib/driver.js), bg-queue.jsonl (the background runs,
7
+ * lib/bg-queue.js), the outbox (drafts to people, lib/outbox-store.js) and each initiative's outcome check date (its record's
8
+ * outcome_horizon). This folds them into ONE ROW PER CHANGE, so a PM can see in one place what PMOS changed, why, and whether it held.
9
+ *
10
+ * rows(input, { now }) → { rows, runs } PURE. input: { autonomy, proposals, driver, bgQueue, outbox: raw ledger lines; checks: { ini: date } }
11
+ * read(root, { runtimeDir }) → input reads the ledgers of one repository (any layout lib/driver.js stateDirOf knows), no write
12
+ * summary(rows, runs, { now, days }) → { from, lines: [{ line, station, changes, applied, kept, undone, ignored, unsourced, runs }],
13
+ * total, placed, joined, unsourced_pct }
14
+ *
15
+ * A ROW: { at, line, station, job, product, ini, ref, title, cls, state, source: [label], sourced, joined, check }
16
+ * line pm (product decisions: problem, evidence, outcome, description, what was found, grill, the idle lab, role agents, goal loops)
17
+ * · project (the plan and its status: dates, done, names, links, stage moves, defaults, sends) · sdlc (the factory's builds)
18
+ * station the module that made it: Proposals, Driver, Defaults, Role agents, Goal loops, Lessons, Outbox, Factory
19
+ * state proposed · applied (by an agent, inside its 14-day Undo) · kept (by the PM, or applied and past its Undo) · undone · dropped
20
+ * · expired (a ✦ nobody answered) · sent (outbox)
21
+ * sourced true: it cites a source. false: it cites none ("No reason found", an empty reason). The applied line's own `src` decides when
22
+ * the ledger has it (lib/autonomy.js recordApplied, from this build on); else what its origin (✦ or Driver proposal) cites;
23
+ * else a reason that names a source kind (lib/source-guard.js kindOf). Nothing found counts as unsourced.
24
+ * joined the applied line was matched to its origin. Keys, in order: its ref is a ✦ keep batch, a kept ✦ id, or a Driver proposal id;
25
+ * else the ✦ keep (auto) or Driver keep (auto) of the same initiative and job within JOIN_MS of it (A443: on Scarlet only
26
+ * 10 of 57 refs joined by batch, so the ref alone is not enough). A row that joins nothing is still placed by its job.
27
+ * check the initiative's outcome check date, when its record names one
28
+ *
29
+ * A change PMOS applied by itself is one row even though it is in two ledgers (the applied line and its ✦ or Driver keep).
30
+ * The source rule the rows measure lives in lib/autonomy.js (no source, no auto). */
31
+ const fs = require('fs');
32
+ const path = require('path');
33
+
34
+ const DAY = 86400000;
35
+ const JOIN_MS = 3 * 60 * 1000;
36
+ const UNDO_DAYS = 14;
37
+ const IGNORED_MS = 3 * DAY; // a proposal nobody answered for 3 days is ignored (the grill's draft expiry is 72 hours)
38
+ const LINES = Object.freeze(['pm', 'project', 'sdlc']);
39
+ const LINE_NAMES = Object.freeze({ pm: 'Product', project: 'Project', sdlc: 'SDLC' });
40
+ const PROJECT_GROUPS = new Set(['dates', 'status', 'names', 'links', 'default', 'ask', 'tidy']);
41
+ const PROJECT_DRIVER = new Set(['move', 'follow-up']);
42
+ const NO_REASON = /^\s*(no reason( found)?|none|n\/a|-)?\s*\.?\s*$/i;
43
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
44
+ const str = (v) => (typeof v === 'string' ? v : '');
45
+ const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
46
+ const ms = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : null; };
47
+
48
+ /** The line and station of a job (`propose:<group>`, `driver:<what>`, `ai:<role>`, `goal:<name>`). */
49
+ function placeOf(job) {
50
+ const [kind, name = ''] = String(job || '').split(':');
51
+ if (kind === 'propose') {
52
+ if (name === 'default') return { line: 'project', station: 'Defaults' };
53
+ if (name === 'build') return { line: 'sdlc', station: 'Factory' };
54
+ return { line: PROJECT_GROUPS.has(name) ? 'project' : 'pm', station: 'Proposals' };
55
+ }
56
+ if (kind === 'driver') return { line: PROJECT_DRIVER.has(name) ? 'project' : 'pm', station: 'Driver' };
57
+ if (kind === 'ai') {
58
+ if (name === 'improve') return { line: 'pm', station: 'Lessons' };
59
+ if (/factory|build|review/.test(name)) return { line: 'sdlc', station: 'Factory' };
60
+ return { line: 'pm', station: 'Role agents' };
61
+ }
62
+ if (kind === 'goal') return { line: 'pm', station: 'Goal loops' };
63
+ return { line: null, station: null };
64
+ }
65
+
66
+ /** The labels a list of { label, ref } sources (or strings) names. */
67
+ const labelsOf = (src) => (Array.isArray(src) ? src.map((s) => (isObj(s) ? str(s.label) || str(s.ref) : str(s))).map((s) => one(s, 80)).filter(Boolean) : []);
68
+ /** What a reason text names as its source, or [] (a reason is not a source unless it names one: Jira, a PRD, a meeting, a document…). */
69
+ function namedIn(why) {
70
+ const t = str(why);
71
+ if (!t || NO_REASON.test(t) || /no reason found/i.test(t)) return [];
72
+ const SG = require('./source-guard.js');
73
+ const k = SG.kindOf(t);
74
+ if (k !== 'other' && k !== 'plan') return [SG.KIND_NAMES[k] || k];
75
+ if (/^\s*(prd|from)\b/i.test(t)) return [one(t.replace(/^\s*from\s+/i, ''), 80)];
76
+ return [];
77
+ }
78
+ /** What one ✦ proposal (a propose line) cites. */
79
+ function citesOfProp(p) {
80
+ try { return labelsOf(require('./source-guard.js').citedOf(p)); } catch { return labelsOf(p && p.sources); }
81
+ }
82
+ /** What a ✦ keep's writes cite: each write's source, else a reason that names one. */
83
+ function citesOfWrote(wrote) {
84
+ const out = [];
85
+ for (const w of Array.isArray(wrote) ? wrote : []) {
86
+ if (!isObj(w)) continue;
87
+ if (str(w.source) && !/^(agent|plan|dates)$/i.test(w.source)) out.push(one(w.source, 80));
88
+ else out.push(...namedIn(w.why));
89
+ }
90
+ return [...new Set(out)];
91
+ }
92
+
93
+ /* ── the fold ── */
94
+ function rows(input = {}, { now = Date.now() } = {}) {
95
+ const out = [];
96
+ const A = Array.isArray(input.autonomy) ? input.autonomy : [];
97
+ const P = Array.isArray(input.proposals) ? input.proposals : [];
98
+ const Dr = Array.isArray(input.driver) ? input.driver : [];
99
+ const checks = isObj(input.checks) ? input.checks : {};
100
+ const checkOf = (ini) => (ini && checks[ini]) || null;
101
+
102
+ // ✦ ledger: propose lines (newest per id), keep lines (with auto and group), undo, expire, drop
103
+ const props = new Map(), keeps = [], undone = new Set(), expired = [], drops = [];
104
+ for (const l of P) {
105
+ if (!isObj(l)) continue;
106
+ if (l.kind === 'propose' && str(l.id)) props.set(l.id, l);
107
+ else if (l.kind === 'keep' && str(l.batch)) keeps.push({ ...l, _t: ms(l.at), _used: false });
108
+ else if (l.kind === 'undo' && str(l.batch)) undone.add(l.batch);
109
+ else if (l.kind === 'expire') expired.push(l);
110
+ else if (l.kind === 'drop' && !l.default) drops.push(l);
111
+ }
112
+ const keepByBatch = new Map(keeps.map((k) => [k.batch, k]));
113
+ const keepById = new Map();
114
+ for (const k of keeps) for (const id of Array.isArray(k.ids) ? k.ids : []) keepById.set(String(id).split(':')[0], k);
115
+
116
+ // Driver ledger: proposals and their decisions
117
+ const dprops = new Map();
118
+ for (const l of Dr) {
119
+ if (!isObj(l)) continue;
120
+ if (l.ev === 'proposal' && str(l.id) && !dprops.has(l.id)) dprops.set(l.id, { ...l, state: 'open', _used: false, auto: false, decided_at: null });
121
+ else if ((l.ev === 'keep' || l.ev === 'return' || l.ev === 'drop') && dprops.has(l.proposal)) {
122
+ const p = dprops.get(l.proposal);
123
+ if (p.state !== 'open') continue;
124
+ p.state = l.ev === 'keep' ? 'kept' : 'dropped'; p.auto = l.auto === true; p.decided_at = l.at || null;
125
+ } else if (l.ev === 'undo' && dprops.has(l.proposal)) dprops.get(l.proposal).state = 'undone';
126
+ }
127
+
128
+ // autonomy ledger: applied lines, their setbacks and checks
129
+ const setback = new Map(); // ref → kind
130
+ for (const l of A) if (isObj(l) && l.ev === 'setback' && l.ref && ['undo', 'revert', 'verifier-fail'].includes(l.kind)) setback.set(l.ref, l.kind);
131
+ for (const l of A) if (isObj(l) && l.ev === 'checked' && l.verdict === 'FAIL' && l.ref) setback.set(l.ref, setback.get(l.ref) || 'verifier-fail');
132
+
133
+ const near = (t, u) => t != null && u != null && Math.abs(t - u) <= JOIN_MS;
134
+ for (const l of A) {
135
+ if (!isObj(l) || l.ev !== 'applied' || typeof l.job !== 'string') continue;
136
+ const t = ms(l.at);
137
+ const [kind, name] = l.job.split(':');
138
+ let origin = null, cites = null;
139
+ if (kind === 'propose') {
140
+ let k = (l.ref && keepByBatch.get(l.ref)) || (l.ref && keepById.get(l.ref)) || null;
141
+ if (!k) k = keeps.find((x) => !x._used && x.auto === true && (!l.ini || x.ini === l.ini) && (!x.group || x.group === name) && near(x._t, t)) || null;
142
+ if (k) {
143
+ k._used = true; origin = k;
144
+ const ids = (Array.isArray(k.ids) ? k.ids : []).map((id) => String(id).split(':')[0]);
145
+ cites = [...new Set([...ids.flatMap((id) => (props.has(id) ? citesOfProp(props.get(id)) : [])), ...citesOfWrote(k.wrote)])];
146
+ }
147
+ } else if (kind === 'driver') {
148
+ let p = (l.ref && dprops.get(l.ref)) || null;
149
+ if (!p) p = [...dprops.values()].find((x) => !x._used && x.auto && x.what === name && (!l.ini || (x.target && x.target.id === l.ini)) && near(ms(x.decided_at), t)) || null;
150
+ if (p) { p._used = true; origin = p; cites = citesOfProp(p); }
151
+ }
152
+ const src = Array.isArray(l.src) ? labelsOf(l.src) : null;
153
+ const source = src || (cites && cites.length ? cites : null) || namedIn(l.why);
154
+ const sb = l.ref ? setback.get(l.ref) : null;
155
+ const age = t == null ? 0 : now - t;
156
+ const { line, station } = placeOf(l.job);
157
+ out.push({ at: l.at || null, line, station, job: l.job, product: l.product || null, ini: l.ini || (origin && (origin.ini || (origin.target && origin.target.id))) || null,
158
+ ref: l.ref || null, title: one(l.title, 200), cls: l.cls || null, by: 'agent', state: sb ? 'undone' : age > UNDO_DAYS * DAY ? 'kept' : 'applied',
159
+ source, sourced: source.length > 0, joined: !!origin || !!src, check: checkOf(l.ini) });
160
+ }
161
+
162
+ // ✦ proposals that were not applied by an agent: kept by the PM, still open, or expired
163
+ for (const k of keeps) {
164
+ if (k._used || k.auto === true) continue; // an auto keep with no applied line: the applied line is the record (a torn write is skipped)
165
+ const ids = (Array.isArray(k.ids) ? k.ids : []).map((id) => String(id).split(':')[0]);
166
+ const g = str(k.group) || (ids.map((id) => props.get(id)).find(Boolean) || {}).group || (/^lk:/.test(ids[0] || '') ? 'links' : 'dates');
167
+ const { line, station } = placeOf('propose:' + g);
168
+ const source = [...new Set([...ids.flatMap((id) => (props.has(id) ? citesOfProp(props.get(id)) : [])), ...citesOfWrote(k.wrote)])];
169
+ out.push({ at: k.at || null, line, station, job: 'propose:' + g, product: null, ini: k.ini || null, ref: k.batch, title: one((props.get(ids[0]) || {}).title || g, 200),
170
+ cls: null, by: 'pm', state: undone.has(k.batch) ? 'undone' : 'kept', source, sourced: source.length > 0, joined: true, check: checkOf(k.ini) });
171
+ }
172
+ const answered = new Set([...keepById.keys(), ...drops.map((d) => str(d.id)).filter(Boolean), ...expired.map((e) => str(e.id)).filter(Boolean)]);
173
+ for (const p of props.values()) {
174
+ if (answered.has(p.id)) continue;
175
+ const { line, station } = placeOf('propose:' + p.group);
176
+ const source = citesOfProp(p);
177
+ out.push({ at: p.at || null, line, station, job: 'propose:' + str(p.group), product: null, ini: p.ini || null, ref: p.id, title: one(p.title || p.why, 200), cls: null, by: 'agent',
178
+ state: 'proposed', source, sourced: source.length > 0, joined: true, check: checkOf(p.ini) });
179
+ }
180
+ for (const e of expired) {
181
+ const { line, station } = placeOf('propose:' + str(e.group));
182
+ out.push({ at: e.at || null, line, station, job: 'propose:' + str(e.group), product: null, ini: e.ini || null, ref: str(e.id) || null, title: one(e.title || e.why, 200), cls: null,
183
+ by: 'agent', state: 'expired', source: [], sourced: false, joined: true, check: checkOf(e.ini) });
184
+ }
185
+ // Driver proposals that were not applied by an agent
186
+ for (const p of dprops.values()) {
187
+ if (p._used || (p.auto && p.state !== 'open')) continue;
188
+ const { line, station } = placeOf('driver:' + p.what);
189
+ const ini = p.target && p.target.kind === 'initiative' ? p.target.id : null;
190
+ const source = citesOfProp(p);
191
+ out.push({ at: p.at || null, line, station, job: 'driver:' + str(p.what), product: (p.target && p.target.ws) || null, ini, ref: p.id, title: one(`${p.what}: ${p.why}`, 200),
192
+ cls: null, by: p.state === 'open' ? 'agent' : 'pm', state: p.state === 'open' ? 'proposed' : p.state, source, sourced: source.length > 0, joined: true, check: checkOf(ini) });
193
+ }
194
+ // the outbox: drafts to people (class C, never applied by an agent)
195
+ const ob = new Map();
196
+ for (const l of Array.isArray(input.outbox) ? input.outbox : []) {
197
+ if (!isObj(l) || !l.id) continue;
198
+ const cur = ob.get(l.id) || { id: l.id, at: l.at || null, state: 'proposed', title: '', ws: null, ini: null };
199
+ if (l.event === 'queued' || l.event === 'edited') { cur.title = one(l.text || l.title || l.subject || cur.title, 200); cur.ws = l.ws || cur.ws; cur.ini = l.initiative || l.ini || cur.ini; }
200
+ else if (l.event === 'sent') cur.state = 'sent';
201
+ else if (l.event === 'discarded') cur.state = 'dropped';
202
+ else if (l.event === 'restored') cur.state = 'proposed';
203
+ ob.set(l.id, cur);
204
+ }
205
+ for (const e of ob.values()) out.push({ at: e.at, line: 'project', station: 'Outbox', job: 'outbox', product: e.ws, ini: e.ini, ref: e.id, title: e.title, cls: 'C', by: 'agent',
206
+ state: e.state, source: [], sourced: null, joined: true, check: checkOf(e.ini) });
207
+
208
+ // the background runs: what each station spent (a run is one background agent session)
209
+ const runs = [];
210
+ for (const l of Array.isArray(input.bgQueue) ? input.bgQueue : []) if (isObj(l) && l.kind === 'done' && l.job) runs.push({ at: l.at || null, job: String(l.job), ini: l.ini || null, ws: l.ws || null });
211
+
212
+ out.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')));
213
+ return { rows: out, runs };
214
+ }
215
+
216
+ /** The station a background run's job spends for (lib/bg-queue.js JOBS ids). */
217
+ function stationOfRun(job) {
218
+ const j = String(job || '');
219
+ if (/driver/.test(j)) return { line: 'pm', station: 'Driver' };
220
+ if (/goal/.test(j)) return { line: 'pm', station: 'Goal loops' };
221
+ if (/team|role/.test(j)) return { line: 'pm', station: 'Role agents' };
222
+ if (/improve/.test(j)) return { line: 'pm', station: 'Lessons' };
223
+ if (/build|factory|verif/.test(j)) return { line: 'sdlc', station: 'Factory' };
224
+ if (/proposal|grill|lab|scan|outcome|doc|metric/.test(j)) return { line: 'pm', station: 'Proposals' };
225
+ return { line: 'project', station: 'Schedules' };
226
+ }
227
+
228
+ /** Per line and station over the last `days` days (today only when days is 1). */
229
+ function summary(R, runs = [], { now = Date.now(), days = 1 } = {}) {
230
+ const d = new Date(now);
231
+ const from = days <= 1 ? Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()) : now - days * DAY;
232
+ const inWin = (at) => { const t = ms(at); return t != null && t >= from && t <= now + 60000; };
233
+ const W = R.filter((r) => inWin(r.at));
234
+ const key = (line, station) => `${line}|${station}`;
235
+ const by = new Map();
236
+ const get = (line, station) => { const k = key(line, station); if (!by.has(k)) by.set(k, { line, station, changes: 0, applied: 0, kept: 0, undone: 0, ignored: 0, unsourced: 0, runs: 0 }); return by.get(k); };
237
+ for (const r of W) {
238
+ if (!r.line) continue;
239
+ const g = get(r.line, r.station);
240
+ g.changes++;
241
+ const self = r.by === 'agent' && (r.state === 'applied' || r.state === 'kept' || r.state === 'undone') && r.job !== 'outbox';
242
+ if (self) { g.applied++; if (!r.sourced) g.unsourced++; }
243
+ if (r.state === 'kept') g.kept++;
244
+ if (r.state === 'undone') g.undone++;
245
+ if (r.state === 'expired' || (r.state === 'proposed' && now - (ms(r.at) || now) > IGNORED_MS)) g.ignored++;
246
+ }
247
+ for (const u of runs) if (inWin(u.at)) { const s = stationOfRun(u.job); get(s.line, s.station).runs++; }
248
+ const lines = [...by.values()].sort((a, b) => LINES.indexOf(a.line) - LINES.indexOf(b.line) || b.changes - a.changes || a.station.localeCompare(b.station));
249
+ const self = W.filter((r) => r.by === 'agent' && ['applied', 'kept', 'undone'].includes(r.state) && r.job !== 'outbox');
250
+ const unsourced = self.filter((r) => !r.sourced).length;
251
+ return {
252
+ from: new Date(from).toISOString(), days,
253
+ lines,
254
+ total: W.length,
255
+ placed: W.filter((r) => r.line && r.station && r.state).length,
256
+ applied: self.length,
257
+ joined: self.filter((r) => r.joined).length,
258
+ unsourced,
259
+ unsourced_pct: self.length ? Math.round((unsourced / self.length) * 1000) / 10 : 0,
260
+ };
261
+ }
262
+
263
+ /* ── the read (no write) ── */
264
+ function linesOf(file) {
265
+ let text = '';
266
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
267
+ const out = [];
268
+ for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (isObj(l)) out.push(l); } catch { /* a torn line is skipped */ } }
269
+ return out;
270
+ }
271
+ /** Each initiative's outcome check date from its record (planning/initiatives or pmos/state/initiatives). */
272
+ function checksOf(root) {
273
+ const out = {};
274
+ for (const dir of [path.join(root, 'planning', 'initiatives'), path.join(root, 'pmos', 'state', 'initiatives')]) {
275
+ let names = [];
276
+ try { names = fs.readdirSync(dir).filter((n) => n.endsWith('.md')); } catch { continue; }
277
+ for (const n of names) {
278
+ let head = '';
279
+ try { head = fs.readFileSync(path.join(dir, n), 'utf8').slice(0, 6000); } catch { continue; }
280
+ const m = /^outcome_horizon:\s*["']?(\d{4}-\d{2}-\d{2})/m.exec(head);
281
+ const id = (/^id:\s*["']?([^"'\n]+)/m.exec(head) || [])[1] || n.slice(0, -3);
282
+ if (m && !out[id.trim()]) out[id.trim()] = m[1];
283
+ }
284
+ }
285
+ return out;
286
+ }
287
+ function read(root, { runtimeDir = null } = {}) {
288
+ const D = require('./driver.js');
289
+ const dir = D.stateDirOf(root);
290
+ const pick = (name) => [dir, runtimeDir].filter(Boolean).map((d) => path.join(d, name)).find((f) => fs.existsSync(f)) || null;
291
+ const ob = runtimeDir ? path.join(runtimeDir, 'outbox', 'outbox.jsonl') : null;
292
+ return {
293
+ stateDir: dir,
294
+ autonomy: dir ? linesOf(path.join(dir, 'autonomy.jsonl')) : [],
295
+ proposals: dir ? linesOf(path.join(dir, 'proposals.jsonl')) : [],
296
+ driver: dir ? linesOf(path.join(dir, 'driver.jsonl')) : [],
297
+ bgQueue: pick('bg-queue.jsonl') ? linesOf(pick('bg-queue.jsonl')) : [],
298
+ outbox: ob && fs.existsSync(ob) ? linesOf(ob) : [],
299
+ checks: checksOf(root),
300
+ };
301
+ }
302
+
303
+ module.exports = { rows, summary, read, placeOf, namedIn, checksOf, stationOfRun, LINES, LINE_NAMES, JOIN_MS, IGNORED_MS };
@@ -171,7 +171,8 @@ function take(dir, held, { dayLines = [], today = '', product = '', pm, now, env
171
171
  ...(facts.length ? { facts } : {}), why, default: true, batch });
172
172
  }
173
173
  const title = `Left the plan as it was on ${one(q.title, 80)}: ${plural(hs.length, 'change', 'changes')} nobody answered by ${md(dueDay)}`;
174
- A.recordApplied(dir, { job: JOB, product, ref: batch, title, cls: 'B', ini: q.ini, why }, { now, settingsDir });
174
+ // its source is the owner's own question, unanswered by its deadline (the record counts it as sourced)
175
+ A.recordApplied(dir, { job: JOB, product, ref: batch, title, cls: 'B', ini: q.ini, why, src: [`Unanswered question, due ${dueDay}`] }, { now, settingsDir });
175
176
  out.taken.push({ batch, ini: q.ini, board: q.board, ids: hs.map((h) => String(h.prop.id)), title });
176
177
  }
177
178
  return out;