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.
@@ -140,8 +140,11 @@ async function autoApply({ file, proposal, actor, ctx = {}, now, stateDir, produ
140
140
  const p = state.proposals.get(proposal);
141
141
  if (!p || p.state !== 'open') return { applied: false, why: 'not open' };
142
142
  const m = mode || D.modeOf(state, p.target.kind === 'work' ? 'work' : null);
143
- const cls = A.classOfDriver(p.what);
144
- const d = A.decide({ stateDir, job: jobOf(p), product, cls, mode: m, undoable: UNDOABLE.has(p.what), now, settingsDir: ctx.settingsDir || null });
143
+ // no source, no auto (A443): a Driver change that cites nothing is class C and waits for the PM
144
+ const cls = A.classOfDriverProposal(p);
145
+ const src = require('./source-guard.js').citedOf(p);
146
+ const d = A.decide({ stateDir, job: jobOf(p), product, cls, mode: m, undoable: UNDOABLE.has(p.what), now, settingsDir: ctx.settingsDir || null, sources: src });
147
+ if (!d.apply && !src.length) A.logHeld(jobOf(p), product, p.id);
145
148
  if (!d.apply) return { applied: false, why: d.why, cls };
146
149
  // board AwI: Intent is the PM's; Claude's change to it is a ✦ proposal on the product page and never applies by itself
147
150
  if (p.what === 'artefact' && p.data && p.data.artefact === 'intent') return { applied: false, why: 'Intent is the PM\'s, so PMOS only proposes', cls };
@@ -155,7 +158,7 @@ async function autoApply({ file, proposal, actor, ctx = {}, now, stateDir, produ
155
158
  // batch 29 item 6: the line keeps what the change was read from (its sources) and the run that made it, so "PMOS did" can say why
156
159
  const from = (p.sources || []).map((x) => x && x.label).filter(Boolean).slice(0, 3);
157
160
  A.recordApplied(stateDir, { job: jobOf(p), product, ref: p.id, title: `${p.what}: ${p.why}`, cls, ini: p.target && p.target.kind === 'initiative' ? p.target.id : null,
158
- why: from.length ? 'From ' + from.join(', ') : '', run: p.run || null }, { now, settingsDir: ctx.settingsDir || null });
161
+ why: from.length ? 'From ' + from.join(', ') : '', run: p.run || null, src: p.sources || [] }, { now, settingsDir: ctx.settingsDir || null });
159
162
  return { applied: true, why: d.why, cls, wrote: r.wrote };
160
163
  } catch (e) { return { applied: false, why: 'the apply failed: ' + String((e && e.message) || e).slice(0, 160) }; }
161
164
  }
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+ /* factory-cli.js — `pmos factory`: one view of everything PMOS changed by itself (initiative one-change-record-no-source-no-auto).
3
+ *
4
+ * pmos factory today [--days N] [--json] [--unsourced] [--root <dir>]
5
+ * Per line (product, project, SDLC) and station: changes, applied by PMOS, kept, undone, ignored, applied with no source, and
6
+ * background runs. --days 7 covers the last 7 days (default: today). --json prints the totals and the lines. --unsourced prints the
7
+ * percent of self-applied changes that cite no source as one number on the last line (the initiative's health number).
8
+ *
9
+ * Read-only: it folds the ledgers with lib/change-record.js and writes nothing. Exit codes: 0 done, 1 refused, 2 usage. */
10
+ const path = require('path');
11
+ const { execFileSync } = require('child_process');
12
+ const CR = require('./change-record.js');
13
+
14
+ const COMMANDS = { factory: ['today'] };
15
+ const USAGE = [
16
+ 'usage: pmos factory today [--days N] [--json] [--unsourced] — everything PMOS changed by itself, in one record',
17
+ ' pmos factory today per line and station: changes, applied, kept, undone, ignored, with no source, runs (today)',
18
+ ' pmos factory today --days 7 the same over the last 7 days',
19
+ ' pmos factory today --unsourced one number: the percent of changes PMOS applied by itself that cite no source',
20
+ 'A change that cites no source never applies by itself: it waits for you (no source, no auto).',
21
+ ];
22
+ const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (args[i + 1] === undefined || args[i + 1].startsWith('--') ? true : args[i + 1]) : undefined; };
23
+ function repoRoot(cwd) { try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; } }
24
+ const pad = (s, n) => String(s).padEnd(n);
25
+ const num = (v, n = 6) => String(v).padStart(n);
26
+
27
+ function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), env = process.env, now = Date.now(), runtimeDir } = {}) {
28
+ const args = argv[0] === 'factory' ? argv.slice(1) : argv.slice();
29
+ const verb = args[0];
30
+ if (!verb || ['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return verb ? 0 : 2; }
31
+ if (!COMMANDS.factory.includes(verb)) { say(`unknown factory command "${verb}" — one of ${COMMANDS.factory.join(', ')}`); return 2; }
32
+ const d = flag(args, 'days');
33
+ const days = d === undefined ? 1 : Number(d);
34
+ if (!Number.isInteger(days) || days < 1 || days > 90) { say('--days is a whole number from 1 to 90'); return 2; }
35
+ const root = typeof flag(args, 'root') === 'string' ? path.resolve(cwd, flag(args, 'root')) : repoRoot(cwd);
36
+ let rt = runtimeDir;
37
+ if (rt === undefined) { try { rt = require('./state-root.js').defaultRoot({ env }); } catch { rt = null; } }
38
+ const input = CR.read(root, { runtimeDir: rt });
39
+ if (!input.stateDir) { say('✗ this repository has no PMOS state folder (pmos/state, state or .pmos)'); return 1; }
40
+ let ws = null; try { ws = require('./driver.js').wsIdOf(root); } catch { /* no id: every outbox draft counts */ }
41
+ if (ws) input.outbox = input.outbox.filter((l) => !l.ws || l.ws === ws);
42
+ const { rows, runs } = CR.rows(input, { now });
43
+ const S = CR.summary(rows, runs, { now, days });
44
+ if (flag(args, 'json')) { say(JSON.stringify({ ok: true, ...S })); return 0; }
45
+ if (flag(args, 'unsourced')) {
46
+ say(`${S.unsourced} of ${S.applied} changes PMOS applied by itself ${days === 1 ? 'today' : `in the last ${days} days`} cite no source`);
47
+ say(String(S.unsourced_pct));
48
+ return 0;
49
+ }
50
+ say(`What PMOS changed ${days === 1 ? 'today' : `in the last ${days} days`}: ${S.total} ${S.total === 1 ? 'change' : 'changes'}, ${S.applied} applied by itself, ${S.unsourced} with no source (${S.unsourced_pct}%)`);
51
+ if (!S.lines.length) { say(' nothing yet'); return 0; }
52
+ say(' ' + pad('Line', 9) + pad('Station', 13) + ['changes', 'applied', 'kept', 'undone', 'ignored', 'no src', 'runs'].map((h) => h.padStart(8)).join(''));
53
+ for (const l of S.lines) say(' ' + pad(CR.LINE_NAMES[l.line] || l.line, 9) + pad(l.station, 13) + [l.changes, l.applied, l.kept, l.undone, l.ignored, l.unsourced, l.runs].map((v) => num(v, 8)).join(''));
54
+ if (S.applied) say(` ${S.joined} of ${S.applied} self-applied changes joined to where they came from`);
55
+ return 0;
56
+ }
57
+
58
+ module.exports = { run, COMMANDS, USAGE };
@@ -171,7 +171,12 @@ function lesson({ stateDir, root, ws, area, run, text, now = Date.now(), env = p
171
171
  const st = L.fold(ledgerOf(stateDir));
172
172
  if ([...st.fixes.values()].some((f) => f.source === run)) return { ok: false, error: 'this run already recorded its one lesson' };
173
173
  const A = require('./autonomy.js');
174
- const d = A.decide({ stateDir, job: JOB, product: ws, cls: 'B', undoable: true, now, env });
174
+ // no source, no auto (A443): the lesson cites the signals of its area; with none it waits for the PM
175
+ const sigs = signals || signalsOf(stateDir);
176
+ const n = sigs.filter((s) => L.slug(s.area) === area).length;
177
+ const src = n ? [`${n} signals in ${area}`] : [];
178
+ const d = A.decide({ stateDir, job: JOB, product: ws, cls: 'B', undoable: true, now, env, sources: src });
179
+ if (d.nosrc) A.logHeld(JOB, ws, area);
175
180
  const ref = 'im-' + crypto.createHash('sha256').update(`${ws}:${area}:${run}:${t}`).digest('hex').slice(0, 10);
176
181
  if (!d.apply) {
177
182
  append(stateDir, { ev: 'wawan', area, why: `a lesson waits for you (${d.why}): ${t}` }, now);
@@ -182,11 +187,9 @@ function lesson({ stateDir, root, ws, area, run, text, now = Date.now(), env = p
182
187
  const stale = new Date(now + STALE_DAYS * L.DAY).toISOString().slice(0, 10);
183
188
  const w = core.write(root, { op: 'add', text: t, by: 'agent:improve', source: `improve:${ref}`, stale_after: stale, confidence: 'unconfirmed' });
184
189
  if (!w.ok) return { ok: false, error: w.error };
185
- const sigs = signals || signalsOf(stateDir);
186
- const n = sigs.filter((s) => L.slug(s.area) === area).length;
187
190
  append(stateDir, { ev: 'fix', fix: ref, area, case: null, source: run, files: [] }, now);
188
191
  append(stateDir, { ev: 'lesson', ref, area, text: t }, now);
189
- A.recordApplied(stateDir, { job: JOB, product: ws, ref, title: `Learned: ${t}`, cls: 'B', why: `${n} signals in ${area}`, run }, { now });
192
+ A.recordApplied(stateDir, { job: JOB, product: ws, ref, title: `Learned: ${t}`, cls: 'B', why: `${n} signals in ${area}`, run, src }, { now });
190
193
  return { ok: true, ref, applied: true };
191
194
  }
192
195
  function propose({ stateDir, ws, area, run, text, ini = null, now = Date.now() } = {}) {
@@ -13,6 +13,8 @@
13
13
  * pmos initiative export <id> the breakdown as markdown on stdout; nothing is written
14
14
  * pmos initiative describe <id> ["<text>"] no text: its description and the cited lines PMOS can draft it from; with text: write
15
15
  * its `description:` line (initiative-description-field). An agent writes only after the PM's yes
16
+ * pmos initiative raised-by <id> ["<who>"|none] no value: who raised it and where that is read from; with a value: write its `raised_by:`
17
+ * line (who-raised-each-idea): you, pmos, tracker, "teammate: <name>" or "customer: <name>"
16
18
  * every command: [--json] [--root <dir>]
17
19
  *
18
20
  * The SAME writers the workspace page uses (lib/initiative-writer.js, lib/placements.js) — no server is needed. Who
@@ -61,12 +63,12 @@ function docNote(docs) {
61
63
  return `Not on the Roadmap · ${docs.length} on a document lane: ${names}. A document lane does not show on Home or the Board. If it is work, set lane: in its record to ${WORK_LANES}.`;
62
64
  }
63
65
 
64
- const COMMANDS = { initiative: ['new', 'top', 'up', 'down', 'bottom', 'after', 'check-by', 'adopt', 'drop', 'list', 'export', 'describe'] };
66
+ const COMMANDS = { initiative: ['new', 'top', 'up', 'down', 'bottom', 'after', 'check-by', 'adopt', 'drop', 'list', 'export', 'describe', 'raised-by'] };
65
67
  /** The horizon verbs D105 retired: they answer with what to use instead. */
66
68
  const RETIRED = Object.freeze(['now', 'next', 'later']);
67
69
  const USAGE = [
68
- 'usage: pmos initiative new|top|up|down|bottom|after|check-by|adopt|drop|list|export|describe — initiatives on the Roadmap',
69
- ' pmos initiative new "<title>" --lane <lane> --anchor <KR|health:id> [--intent "<text>"] [--id <id>] [--kind product|sdlc|project]',
70
+ 'usage: pmos initiative new|top|up|down|bottom|after|check-by|adopt|drop|list|export|describe|raised-by — initiatives on the Roadmap',
71
+ ' pmos initiative new "<title>" --lane <lane> --anchor <KR|health:id> [--intent "<text>"] [--id <id>] [--kind product|sdlc|project] [--raised-by "<who>"]',
70
72
  ' pmos initiative new --from capture-YYYY-MM-DD-<n> [--anchor <anchor>] [--lane <lane>] [--title "<title>"]',
71
73
  ' pmos initiative top|up|down|bottom <id> reorder it on the Roadmap',
72
74
  ' pmos initiative after <id> <other-id> rank it right after another initiative',
@@ -76,6 +78,7 @@ const USAGE = [
76
78
  ' pmos initiative list the Roadmap, ranked, with each lifecycle stage',
77
79
  ' pmos initiative export <id> the breakdown as markdown on stdout',
78
80
  ' pmos initiative describe <id> ["<text>"] read its description and what to draft it from; with text, save it (after the PM\'s yes)',
81
+ ' pmos initiative raised-by <id> ["<who>"|none] who raised it; with a value, save it: you, pmos, tracker, "teammate: <name>", "customer: <name>"',
79
82
  ' --lane is a work lane of this repository: new-feature, improvement, bug-fix, discovery or chore in a product repository',
80
83
  ' (scripts/lane-defs.js; the PMOS repository itself uses feature, discovery, chore, incident, content and prototype)',
81
84
  ' every command: [--json] [--root <dir>]',
@@ -83,7 +86,7 @@ const USAGE = [
83
86
  'Now, Next and Later are retired (D105): the rank says what comes first, the lifecycle stage says where it is.',
84
87
  ];
85
88
  const BOOL = new Set(['json', 'top', 'help']); // --top is kept so an old script gets the retired answer, not a usage error
86
- const VALUE = new Set(['lane', 'anchor', 'intent', 'id', 'from', 'title', 'root', 'kind']);
89
+ const VALUE = new Set(['lane', 'anchor', 'intent', 'id', 'from', 'title', 'root', 'kind', 'raised-by']);
87
90
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
88
91
 
89
92
  function parse(argv) {
@@ -150,6 +153,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
150
153
  }
151
154
  if (flags.title) input.title = flags.title;
152
155
  for (const k of ['lane', 'anchor', 'intent', 'id', 'kind']) if (flags[k]) input[k] = flags[k];
156
+ if (flags['raised-by']) input.raised_by = flags['raised-by'];
153
157
  const actor = actorLib.fromCli(who);
154
158
  const r = writer.createInitiative(root, input, { actor, now });
155
159
  if (!r.ok) return fail(r.error);
@@ -214,6 +218,29 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
214
218
  return done({ written: r.written }, `✓ proposal ${eid} ${verb === 'adopt' ? 'kept' : 'dropped'}`);
215
219
  }
216
220
 
221
+ if (verb === 'raised-by') {
222
+ // who-raised-each-idea (bet A445): read who raised an initiative, or write its raised_by line
223
+ const rid = pos[0];
224
+ if (!rid || pos.length > 2) { say('usage: pmos initiative raised-by <id> ["<who>"|none]'); return 2; }
225
+ const ORIGIN = require('./initiative-origin.js');
226
+ if (pos.length === 2) {
227
+ const r = writer.setRaisedBy(root, rid, pos[1], { actor: actorLib.fromCli(who) });
228
+ if (!r.ok) return fail(r.error, r.status === 400 ? 2 : 1);
229
+ const o = ORIGIN.originOf({ raised_by: r.to, created: ORIGIN.createdBy(root).get(rid) });
230
+ return done({ id: rid, from: r.from || null, raised_by: r.to || null, origin: o, same: !!r.same },
231
+ r.same ? `${rid} says that already.` : `✓ ${rid}: raised by ${o ? o.label : 'not recorded'}. Commit the record to keep it.`);
232
+ }
233
+ const fs = require('fs');
234
+ let text = null;
235
+ for (const rel of ['planning/initiatives', 'pmos/state/initiatives']) { try { text = fs.readFileSync(path.join(root, rel, rid + '.md'), 'utf8'); break; } catch { /* the other layout */ } }
236
+ if (text == null) return fail(`no initiative ${rid} here`);
237
+ const o = ORIGIN.originOf({ raised_by: ORIGIN.raisedByOfText(text), created: ORIGIN.createdBy(root).get(rid) });
238
+ if (json) { say(JSON.stringify({ ok: true, id: rid, origin: o })); return 0; }
239
+ say(o ? `${rid}: raised by ${o.label} (${o.source === 'record' ? 'its raised_by line' : 'the Roadmap line that added it'}).` : `${rid}: who raised it is not recorded.`);
240
+ if (!o || o.source !== 'record') say(`Ask the PM who raised it; after the answer: pmos initiative raised-by ${rid} "<you|pmos|tracker|teammate: name|customer: name>"`);
241
+ return 0;
242
+ }
243
+
217
244
  if (verb === 'describe') {
218
245
  // initiative-description-field: the record's own description. Read with no text; write with text, only after the PM said yes.
219
246
  const did = pos[0];
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+ /* lib/initiative-origin.js — who raised an initiative (bet A445, initiative who-raised-each-idea). The one place the rule lives.
3
+ *
4
+ * parse(text) → { ok: true, kind, name } | { ok: false, error } a `raised_by:` value
5
+ * originOf({ raised_by, created }) → origin | null
6
+ * createdBy(root) → Map(initiative → { by, from }) the Roadmap's `created` lines (lib/placements.js), read once
7
+ * coverage(root) → { total, known, pct, byKind }
8
+ * node lib/initiative-origin.js coverage <root> prints the coverage; its last line is the percent (the build's health number)
9
+ *
10
+ * WHERE AN ORIGIN COMES FROM, in this order, for any product:
11
+ * 1. the record's own `raised_by:` line, which the PM or an agent writes (lib/initiative-writer.js, `pmos initiative raised-by`):
12
+ * `you`, `pmos` (or `agent`), `tracker`, `teammate: <name>`, `customer: <name>`;
13
+ * 2. the Roadmap's `created` line, which the one writer of a record appends: `by: pm:*` is You, `by: agent:*` is PMOS;
14
+ * 3. nothing: the row shows nothing (zero is silence) and falls in "Not recorded" in a group or a filter.
15
+ * PMOS never guesses a person from a ticket or a document: an origin is read, never invented.
16
+ *
17
+ * AN ORIGIN: { kind, name, label, group, source }
18
+ * kind 'you' | 'teammate' | 'customer' | 'pmos' | 'tracker'
19
+ * name the person or company for a teammate or a customer, else null
20
+ * label what a cell says: "You", "Dana · teammate", "Acme · customer", "PMOS", "From the tracker"
21
+ * group what a group or a filter value says: "You", "Teammates", "Customers", "PMOS", "From the tracker"
22
+ * source 'record' (the raised_by line) | 'roadmap' (the created line)
23
+ * The page never sees a session token: the created line's `by` is reduced to its kind here.
24
+ */
25
+ const fs = require('fs');
26
+ const path = require('path');
27
+
28
+ const KINDS = Object.freeze(['you', 'teammate', 'customer', 'pmos', 'tracker']);
29
+ const NAMED = new Set(['teammate', 'customer']);
30
+ const ALIAS = Object.freeze({ pm: 'you', me: 'you', agent: 'pmos' });
31
+ const GROUP = Object.freeze({ you: 'You', teammate: 'Teammates', customer: 'Customers', pmos: 'PMOS', tracker: 'From the tracker' });
32
+ const NONE = 'Not recorded';
33
+ const MAX_NAME = 60;
34
+
35
+ /** A `raised_by:` value → { ok, kind, name } or { ok: false, error }. Quotes around the whole value are dropped. */
36
+ function parse(text) {
37
+ const raw = String(text == null ? '' : text).trim().replace(/^["']|["']$/g, '').trim();
38
+ if (!raw) return { ok: false, error: 'say who raised it: you, pmos, tracker, "teammate: <name>" or "customer: <name>"' };
39
+ if (/[\r\n\x00-\x08\x0b-\x1f]/.test(raw)) return { ok: false, error: 'who raised it must be one line' };
40
+ const m = /^([A-Za-z]+)\s*(?::\s*(.*))?$/.exec(raw);
41
+ const k0 = m ? m[1].toLowerCase() : '';
42
+ const kind = ALIAS[k0] || k0;
43
+ if (!m || !KINDS.includes(kind)) return { ok: false, error: `"${raw.slice(0, 40)}" is not one of: you, pmos, tracker, teammate: <name>, customer: <name>` };
44
+ const name = m[2] != null ? m[2].trim() : '';
45
+ if (NAMED.has(kind)) {
46
+ if (!name) return { ok: false, error: `name the ${kind}: "${kind}: <name>"` };
47
+ if (name.length > MAX_NAME) return { ok: false, error: `the name is at most ${MAX_NAME} characters` };
48
+ return { ok: true, kind, name };
49
+ }
50
+ if (m[2] != null) return { ok: false, error: `${kind} takes no name` };
51
+ return { ok: true, kind, name: null };
52
+ }
53
+
54
+ /** The value a record line holds for a parsed origin: `you`, `teammate: Dana`. */
55
+ const lineValue = (p) => (p.name ? `${p.kind}: ${p.name}` : p.kind);
56
+
57
+ function shape(kind, name, source) {
58
+ const label = name ? `${name} · ${kind}` : kind === 'you' ? 'You' : kind === 'pmos' ? 'PMOS' : kind === 'tracker' ? 'From the tracker' : GROUP[kind];
59
+ return { kind, name: name || null, label, group: GROUP[kind], source };
60
+ }
61
+
62
+ /** The origin of one initiative: its record line first, else the Roadmap's created line, else null. */
63
+ function originOf({ raised_by: rb, created } = {}) {
64
+ if (rb != null && String(rb).trim()) {
65
+ const p = parse(rb);
66
+ if (p.ok) return shape(p.kind, p.name, 'record');
67
+ }
68
+ const by = created && typeof created.by === 'string' ? created.by : '';
69
+ if (by.startsWith('pm:')) return shape('you', null, 'roadmap');
70
+ if (by.startsWith('agent:')) return shape('pmos', null, 'roadmap');
71
+ return null;
72
+ }
73
+
74
+ /** The first `created` line of each initiative in the placements ledger: Map(id → { by, from }). An unreadable ledger is an empty map. */
75
+ function createdBy(root) {
76
+ const out = new Map();
77
+ let lines = [];
78
+ try { lines = require('./plan-ledgers.js').readLines(root, 'placements').lines || []; } catch { return out; }
79
+ for (const { rec } of lines) {
80
+ if (!rec || rec.ev !== 'created' || typeof rec.initiative !== 'string' || out.has(rec.initiative)) continue;
81
+ out.set(rec.initiative, { by: typeof rec.by === 'string' ? rec.by : '', from: rec.from || null });
82
+ }
83
+ return out;
84
+ }
85
+
86
+ /** The `raised_by:` line of a record's front matter, or ''. */
87
+ function raisedByOfText(text) {
88
+ const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(String(text || ''));
89
+ if (!fm) return '';
90
+ const m = /^raised_by:[ \t]*(.*?)[ \t]*$/m.exec(fm[1]);
91
+ return m ? m[1].replace(/^["']|["']$/g, '').replace(/\\"/g, '"') : '';
92
+ }
93
+
94
+ /** The initiative records of a checkout, either layout: planning/initiatives/ (PMOS itself) and pmos/state/initiatives/ (a kit repository). */
95
+ function recordFiles(root) {
96
+ const out = [];
97
+ for (const rel of ['planning/initiatives', 'pmos/state/initiatives']) {
98
+ let names = [];
99
+ try { names = fs.readdirSync(path.join(root, rel)); } catch { continue; }
100
+ for (const n of names) if (n.endsWith('.md') && !/^(readme|index|log)\.md$/i.test(n)) out.push({ id: n.slice(0, -3), file: path.join(root, rel, n) });
101
+ }
102
+ return out;
103
+ }
104
+
105
+ /** How many of a checkout's initiatives show who raised them. → { total, known, pct, byKind: { you, teammate, … , none } } */
106
+ function coverage(root) {
107
+ const created = createdBy(root);
108
+ const byKind = Object.fromEntries([...KINDS, 'none'].map((k) => [k, 0]));
109
+ let total = 0, known = 0;
110
+ for (const { id, file } of recordFiles(root)) {
111
+ let text = '';
112
+ try { text = fs.readFileSync(file, 'utf8'); } catch { continue; }
113
+ if (!/^---\r?\n[\s\S]*?^type:\s*["']?Initiative/m.test(text)) continue;
114
+ total++;
115
+ const o = originOf({ raised_by: raisedByOfText(text), created: created.get(id) });
116
+ if (o) { known++; byKind[o.kind]++; } else byKind.none++;
117
+ }
118
+ return { total, known, pct: total ? Math.round((known / total) * 1000) / 10 : 0, byKind };
119
+ }
120
+
121
+ if (require.main === module) {
122
+ const [cmd, root0] = process.argv.slice(2);
123
+ if (cmd !== 'coverage') { console.log('usage: node lib/initiative-origin.js coverage <checkout>'); process.exit(2); }
124
+ const root = path.resolve(root0 || '.');
125
+ const c = coverage(root);
126
+ const kinds = Object.entries(c.byKind).filter(([, n]) => n).map(([k, n]) => `${k === 'none' ? NONE.toLowerCase() : k} ${n}`).join(', ');
127
+ console.log(`[origin] ${c.known} of ${c.total} initiatives show who raised them${kinds ? ` (${kinds})` : ''}`);
128
+ console.log(String(c.pct));
129
+ }
130
+
131
+ module.exports = { KINDS, GROUP, NONE, parse, lineValue, originOf, createdBy, raisedByOfText, coverage };
@@ -57,8 +57,9 @@ const actorLib = require('./actor.js');
57
57
  const ID_RE = /^[a-z0-9][a-z0-9._-]*$/;
58
58
  const MAX_ID = 60;
59
59
  const WRITER_SET = Object.freeze(['v', 'eid', 'by', 'via', 'at', 'override', 'pm', 'actor', 'nonce', 'timestamp', 'type']);
60
- const INPUT_KEYS = Object.freeze(['id', 'title', 'lane', 'anchor', 'intent', 'specimen_test', 'surface_check', 'from', 'kind']);
60
+ const INPUT_KEYS = Object.freeze(['id', 'title', 'lane', 'anchor', 'intent', 'specimen_test', 'surface_check', 'from', 'kind', 'raised_by']);
61
61
  const WK = require('./work-kind.js');
62
+ const ORIGIN = require('./initiative-origin.js'); // who raised it (who-raised-each-idea): the one parser of a raised_by value
62
63
  const ONE_LINE = (v, max) => typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= max && !/[\r\n\x00-\x08\x0b-\x1f]/.test(v);
63
64
 
64
65
  const refuse = (status, error, field) => ({ ok: false, status, error, field: field || null });
@@ -108,6 +109,11 @@ function createInitiative(root, input, { actor, now } = {}) {
108
109
  }
109
110
  if (has(input, 'kind') && input.kind != null && input.kind !== '' && !WK.valid(input.kind)) return refuse(400, `kind must be one of ${WK.KINDS.join(', ')}`, 'kind');
110
111
  const kind = has(input, 'kind') && WK.valid(input.kind) ? input.kind : WK.DEFAULT;
112
+ let raised = null;
113
+ if (has(input, 'raised_by') && input.raised_by != null && input.raised_by !== '') {
114
+ raised = ORIGIN.parse(input.raised_by);
115
+ if (!raised.ok) return refuse(400, raised.error, 'raised_by');
116
+ }
111
117
  if (has(input, 'from') && input.from != null && !(typeof input.from === 'string' && placements.CAPTURE_RE.test(input.from))) {
112
118
  return refuse(400, 'from must name a capture note, like capture-2026-10-04-1', 'from');
113
119
  }
@@ -132,6 +138,7 @@ function createInitiative(root, input, { actor, now } = {}) {
132
138
  if (input.specimen_test) fm.push(`specimen_test: ${q(input.specimen_test)}`);
133
139
  if (input.surface_check) fm.push(`surface_check: ${q(input.surface_check)}`);
134
140
  fm.push(`kind: ${kind}`);
141
+ if (raised) fm.push(`raised_by: ${q(ORIGIN.lineValue(raised))}`);
135
142
  fm.push('---', '', `# ${title}`, '');
136
143
  if (intent.trim()) fm.push(intent.trim(), '');
137
144
  const text = fm.join('\n');
@@ -343,6 +350,32 @@ function restoreDescription(root, id, from, to, { actor } = {}) {
343
350
  return { ok: true, id };
344
351
  }
345
352
 
353
+ /** Who raised it (who-raised-each-idea, bet A445): only the `raised_by:` line changes, added at the end of the front matter when there is
354
+ * none; `none` (or '') removes it, and the row then reads its origin from the Roadmap's created line again (lib/initiative-origin.js).
355
+ * → { ok: true, id, from, to } where from and to are the line's values ('' for no line), or a refusal (400 for a value parse refuses). */
356
+ function setRaisedBy(root, id, value, { actor } = {}) {
357
+ if (!actorLib.valid(actor)) return refuse(500, 'initiative-writer: the caller must pass the actor from pm-guard.js or actor.js');
358
+ const v = typeof value === 'string' ? value.trim() : '';
359
+ let to = '';
360
+ if (v && v.toLowerCase() !== 'none') {
361
+ const p = ORIGIN.parse(v);
362
+ if (!p.ok) return refuse(400, p.error, 'raised_by');
363
+ to = ORIGIN.lineValue(p);
364
+ }
365
+ const f = recordFile(root, id);
366
+ if (!f.ok) return f;
367
+ const text = fs.readFileSync(f.file, 'utf8');
368
+ const fm = frontOfText(text);
369
+ if (!fm) return refuse(409, `the record of ${id} has no front matter — nothing was saved`, 'id');
370
+ const lines = fm[1].split(/\r?\n/);
371
+ const at = lines.findIndex((l) => /^raised_by:/.test(l));
372
+ const from = at >= 0 ? ORIGIN.raisedByOfText('---\n' + lines[at] + '\n---') : '';
373
+ if (from === to) return { ok: true, id, from, to, same: true };
374
+ if (to) { const line = 'raised_by: ' + q(to); if (at >= 0) lines[at] = line; else lines.push(line); } else lines.splice(at, 1);
375
+ try { fs.writeFileSync(f.file, '---\n' + lines.join('\n') + '\n---' + fm[2] + text.slice(fm[0].length), { flag: 'w' }); } catch { return refuse(500, 'the record could not be written — nothing was saved'); }
376
+ return { ok: true, id, from, to };
377
+ }
378
+
346
379
  /** The kind of work (batch 29 item 11, Viewer KdV1-3): only the `kind:` line changes (added at the end of the front matter when an older
347
380
  * record has none). → { ok: true, id, from, kind } where from is what the record read as before ('product' when it had no line). */
348
381
  function setKind(root, id, kind, { actor } = {}) {
@@ -373,4 +406,4 @@ function withdrawSplit(root, id, want, { actor } = {}) {
373
406
  return { ok: true, removed: true };
374
407
  }
375
408
 
376
- module.exports = { setKind, setDescription, restoreDescription, DESC_MAX, setOutcome, restoreOutcome, createInitiative, renameInitiative, setAnchor, restoreAnchor, withdrawSplit, recordSha, slugOf, ID_RE, INPUT_KEYS };
409
+ module.exports = { setKind, setRaisedBy, setDescription, restoreDescription, DESC_MAX, setOutcome, restoreOutcome, createInitiative, renameInitiative, setAnchor, restoreAnchor, withdrawSplit, recordSha, slugOf, ID_RE, INPUT_KEYS };
@@ -143,6 +143,9 @@ const VERBS = Object.freeze({
143
143
  help: 'pmos owner brief|budget — a unit owner\'s daily brief now, and its Driver runs a day (pmos owner help)' }),
144
144
  driver: Object.freeze({ module: 'driver-cli.js', run: null, guide: 'cli.md',
145
145
  help: 'pmos driver propose|status|keep|return|drop|undo|pause|resume|mode … — the Initiative Driver: class A and B changes apply with Undo, the rest wait for you (pmos driver help)' }),
146
+ // one-change-record-no-source-no-auto: everything PMOS changed by itself, in one record (lib/change-record.js)
147
+ factory: Object.freeze({ module: 'factory-cli.js', run: null, guide: 'cli.md',
148
+ help: 'pmos factory today [--days N] — everything PMOS changed by itself, per line and station, with what cites no source (pmos factory help)' }),
146
149
  // D106 (Full autonomy now): what agents do by themselves, and the goals they work on until done
147
150
  autonomy: Object.freeze({ module: 'autonomy-cli.js', run: null, guide: 'cli.md',
148
151
  help: 'pmos autonomy status|restore — what agents applied by themselves (with Undo) and the jobs back to propose (pmos autonomy help)' }),
@@ -537,7 +537,11 @@ function viewOf(F, ini, o = {}) {
537
537
  const grillHidden = o.grillAll ? [] : grill.slice(GRILL_SHOWN).map((p) => ({ id: p.id, group: 'grill', type: p.type, title: p.title, why: p.why, at: p.at, sig: p.sig, sources: p.sources, data: p.data, items: [] }));
538
538
  if (!o.grillAll) for (const p of grill.slice(GRILL_SHOWN)) props.splice(props.indexOf(p), 1);
539
539
  if (today != null) for (const p of datesOf(ini, T, { today, filed: [...F.props.values()].filter((x) => x.group === 'dates' && x.ini === ini), stages: o.stages, links: o.links, settle: o.settle, drops: F.drops })) if (!kept.has(p.id + ':' + p.sig)) props.push(p);
540
- for (const lp of o.linkProps || []) props.push({ id: 'lk:' + lp.id, group: 'links', type: lp.kind, section: 'sure', link: lp, title: '', why: lp.why || '', sources: [], items: [] });
540
+ // one-change-record-no-source-no-auto: a link cites where it was read (the PRD line, a Jira dependency); a link guessed from the plan's
541
+ // order or from two dates that meet cites nothing, so lib/source-guard.js holds it for the PM instead of adding it by itself
542
+ const SG = require('./source-guard.js');
543
+ for (const lp of o.linkProps || []) props.push({ id: 'lk:' + lp.id, group: 'links', type: lp.kind, section: 'sure', link: lp, title: '', why: lp.why || '',
544
+ sources: SG.LINK_SOURCES[lp.source] ? [{ label: SG.LINK_SOURCES[lp.source], ref: String(lp.why || '').slice(0, 300) }] : [], items: [] });
541
545
  // ✕ on one item drops that item for good: the page sends its signature
542
546
  for (const p of props) if (p.group !== 'links') p.items = p.items.map((x) => ({ ...x, sig: itemSig(p, x) }));
543
547
  props.sort((a, b) => ORDER[a.group] - ORDER[b.group] || (a.group === 'grill' ? ((a.data && a.data.rank) || 5) - ((b.data && b.data.rank) || 5) : 0) || (a.section === 'sure' ? 0 : a.section === 'check' ? 1 : 2) - (b.section === 'sure' ? 0 : b.section === 'check' ? 1 : 2));
@@ -112,6 +112,7 @@ const holdSpans = require('./hold-spans.js');
112
112
  const ledgers = require('./plan-ledgers.js');
113
113
  const intake = require(repoScript('intake.js'));
114
114
  const WK = require('./work-kind.js');
115
+ const ORIGIN = require('./initiative-origin.js'); // who raised each initiative (who-raised-each-idea)
115
116
  const OS = require('./one-stage.js');
116
117
 
117
118
  const LEDGER = 'boards.jsonl';
@@ -421,6 +422,7 @@ function baseRowsRead(w) {
421
422
  const verdicts = require('./outcomes.js').rowOutcomes(w.root, { today: day });
422
423
  const rows = [];
423
424
  const seen = new Set();
425
+ const created = ORIGIN.createdBy(w.root); // the Roadmap's created lines, read once: who added each record
424
426
  for (const id of F.placed.ranked) {
425
427
  if (seen.has(id)) continue;
426
428
  seen.add(id);
@@ -439,6 +441,7 @@ function baseRowsRead(w) {
439
441
  rows.push({
440
442
  id, title: r.title, lane: r.lane || null, kind: WK.kindOf(fm.kind), // batch 29 item 11: no line reads as Product management
441
443
  owner: fm.owner ? String(fm.owner) : null,
444
+ origin: ORIGIN.originOf({ raised_by: fm.raised_by, created: created.get(id) }),
442
445
  anchor: r.anchor || null, rank: Number.isInteger(r.rank) ? r.rank : null, dormant: !!r.dormant,
443
446
  status: statusOf(rec, r.health, end, day, jiraOf(w.root, id), verdicts.get(id)),
444
447
  statusIn: statusIn(rec, r.health, end, day, jiraOf(w.root, id), verdicts.get(id)),
@@ -609,7 +612,7 @@ function boardRow(board, base, folded, lib) {
609
612
  const wf = B.workflowOf(board, base.id, folded);
610
613
  const cat = B.catOf({ workflow: wf }, s.stage);
611
614
  const row = {
612
- id: base.id, title: base.title, lane: base.lane, kind: WK.kindOf(base.kind), stage: s.stage, cat, owner: base.owner, anchor: base.anchor,
615
+ id: base.id, title: base.title, lane: base.lane, kind: WK.kindOf(base.kind), stage: s.stage, cat, owner: base.owner, origin: base.origin || null, anchor: base.anchor,
613
616
  status: base.status, start: ts ? minDay(base.start, ts.start) : base.start, end: ts ? maxDay(base.end, ts.end) : base.end, progress: base.progress, warnings: [],
614
617
  rank: base.rank, health: B.isActive(base) ? base.health : null, updated: base.updated, reading: base.reading, stageSource: s.source, lifecycle: base.lifecycle,
615
618
  stopped: base.stopped || null, archived: archivedOf(folded, base.id), outcome: base.outcome || null,
@@ -154,6 +154,7 @@ function undoCore(ctx, p, g, id) {
154
154
  * mode is not auto stay for the PM. → { applied: [{ ini, batch, group, title }], held: n } */
155
155
  function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
156
156
  const A = require('./autonomy.js');
157
+ const SGc = require('./source-guard.js');
157
158
  const dir = dirOf(ctx, w);
158
159
  const out = { applied: [], held: 0 };
159
160
  if (!dir) return out;
@@ -170,12 +171,14 @@ function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
170
171
  if (!v) continue;
171
172
  for (const x of v.groups.flatMap((gr) => gr.props)) {
172
173
  const cls = A.classOfProposal(x);
173
- const d = A.decide({ stateDir: dir, job: `propose:${x.group}`, product: w.id, cls, mode: modeOf(board.id), undoable: true, now, settingsDir: ctx.runtimeDir || null });
174
+ const src = SGc.citedOf(x); // no source, no auto (A443), in every group
175
+ const d = A.decide({ stateDir: dir, job: `propose:${x.group}`, product: w.id, cls, mode: modeOf(board.id), undoable: true, now, settingsDir: ctx.runtimeDir || null, sources: src });
176
+ if (!d.apply && !src.length) A.logHeld(`propose:${x.group}`, w.id, x.id);
174
177
  if (!d.apply) { out.held++; continue; }
175
178
  try {
176
179
  const r = keepCore(ctx, p, g, f, ini, [x], {}, { auto: true, group: x.group });
177
180
  if (!r.keptIds.length) { out.held++; continue; } // nothing landed (a verdict no longer due, a pull request not opened): nothing to list
178
- A.recordApplied(dir, { job: `propose:${x.group}`, product: w.id, ref: r.batch, title: x.title || x.why || x.group, cls, ini, why: x.title && x.why && x.why !== x.title ? x.why : '' }, { now, settingsDir: ctx.runtimeDir || null });
181
+ A.recordApplied(dir, { job: `propose:${x.group}`, product: w.id, ref: r.batch, title: x.title || x.why || x.group, cls, ini, why: x.title && x.why && x.why !== x.title ? x.why : '', src }, { now, settingsDir: ctx.runtimeDir || null });
179
182
  out.applied.push({ ini, batch: r.batch, group: x.group, title: x.title || x.why || '' });
180
183
  } catch { out.held++; }
181
184
  }
@@ -6,6 +6,9 @@
6
6
  * kindsOf(p) → [kind] the different kinds of source a proposal cites, e.g. ['jira', 'meeting']
7
7
  * kindOf(text) → kind the kind of one source label or ref
8
8
  * bigOf(p) → '' | 'close' | 'rename' | 'date' a change that needs two kinds of source
9
+ * citedOf(x) → [label] what ANY agent change cites (one-change-record-no-source-no-auto): its sources, its items'
10
+ * sources, its claims' sources, a link's PRD or Jira source, a build's work item. [] = no source
11
+ * noReason(why) → bool a reason that says it has none ("No reason found") or is empty
9
12
  *
10
13
  * THE RULE. It applies to the plan changes on a product: the groups in PLAN (dates, status, names, found, links).
11
14
  * 1. No source, or a date proposal that found no reason (`noReason`): held.
@@ -76,4 +79,26 @@ function holdOf(p) {
76
79
  return null;
77
80
  }
78
81
 
79
- module.exports = { holdOf, kindsOf, kindOf, bigOf, shiftOf, PLAN, BIG_DAYS, KIND_NAMES };
82
+ /* ── no source, no auto, in every job kind (initiative one-change-record-no-source-no-auto; idea A443) ──
83
+ * #1440 holds the plan groups above. This widens the one question "does the change cite anything?" to every change an agent makes:
84
+ * a ✦ proposal of any group, an Initiative Driver proposal, a default, a role agent's write. lib/autonomy.js makes a change that cites
85
+ * nothing class C, so it waits for the PM like a change others see. A link's own source (lib/task-links.js proposalsOf) counts when it
86
+ * names where the link was read (the PRD, a Jira dependency, a teammate's link); a link inferred from the plan's order or from two dates
87
+ * that meet is a guess and cites nothing. */
88
+ const LINK_SOURCES = { prd: 'PRD', jira: 'Jira', you: 'You' };
89
+ const NO_REASON = /^\s*(no reason( found)?|none|n\/a|-)?\s*\.?\s*$/i;
90
+ const noReason = (why) => NO_REASON.test(String(why == null ? '' : why));
91
+ function citedOf(x) {
92
+ if (!isObj(x)) return [];
93
+ const out = [];
94
+ const add = (s) => { if (isObj(s)) { const t = [s.label, s.ref].filter((v) => typeof v === 'string' && v.trim()).join(' '); if (t) out.push(t); } else if (typeof s === 'string' && s.trim()) out.push(s); };
95
+ for (const s of Array.isArray(x.sources) ? x.sources : []) add(s);
96
+ for (const it of Array.isArray(x.items) ? x.items : []) if (isObj(it) && it.source) add(String(it.source));
97
+ for (const c of Array.isArray(x.claims) ? x.claims : []) for (const s of (isObj(c) && Array.isArray(c.sources) ? c.sources : [])) add(s);
98
+ if (isObj(x.link) && LINK_SOURCES[x.link.source]) add({ label: LINK_SOURCES[x.link.source], ref: x.link.why || '' });
99
+ if (x.group === 'build' && isObj(x.data) && typeof x.data.item === 'string' && x.data.item) add({ label: 'Work item', ref: x.data.item });
100
+ if (x.noReason === true) return [];
101
+ return [...new Set(out)];
102
+ }
103
+
104
+ module.exports = { citedOf, noReason, LINK_SOURCES, holdOf, kindsOf, kindOf, bigOf, shiftOf, PLAN, BIG_DAYS, KIND_NAMES };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.690.0",
3
+ "version": "0.692.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.690.0",
9
+ "version": "0.692.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.690.0",
3
+ "version": "0.692.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",