create-pmos 0.565.0 → 0.567.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 (57) hide show
  1. package/package.json +33 -27
  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/scripts/gate-initiative.sh +6 -3
  6. package/payload/scripts/workflow-state.js +18 -7
  7. package/payload/state/discoveries.md +1 -1
  8. package/workspace/changelog.json +32 -0
  9. package/workspace/fixtures/initiatives-api/list.json +2 -1
  10. package/workspace/guide/cli.md +5 -3
  11. package/workspace/guide/initiatives-and-next-steps.md +4 -4
  12. package/workspace/guide/jira.md +3 -1
  13. package/workspace/lib/agent-team.js +1 -1
  14. package/workspace/lib/autonomy.js +1 -0
  15. package/workspace/lib/board-premium.js +2 -0
  16. package/workspace/lib/description-props.js +53 -2
  17. package/workspace/lib/engine/workflow-state.js +18 -7
  18. package/workspace/lib/grill-cli.js +4 -4
  19. package/workspace/lib/impact-cli.js +3 -3
  20. package/workspace/lib/initiative-cli.js +7 -4
  21. package/workspace/lib/jira-cli.js +2 -0
  22. package/workspace/lib/jira-tickets.js +78 -5
  23. package/workspace/lib/lab-cli.js +1 -1
  24. package/workspace/lib/lead-cli.js +1 -1
  25. package/workspace/lib/measure-cli.js +13 -7
  26. package/workspace/lib/measurements.js +34 -11
  27. package/workspace/lib/metrics-cli.js +4 -4
  28. package/workspace/lib/outcome-props.js +58 -4
  29. package/workspace/lib/outcomes-cli.js +9 -3
  30. package/workspace/lib/outcomes.js +188 -11
  31. package/workspace/lib/program-cli.js +2 -2
  32. package/workspace/lib/proposals.js +12 -3
  33. package/workspace/lib/propose-cli.js +2 -2
  34. package/workspace/lib/report-draft.js +5 -5
  35. package/workspace/lib/report-engine.js +1 -1
  36. package/workspace/lib/routes-artefacts.js +3 -2
  37. package/workspace/lib/routes-board-premium.js +2 -0
  38. package/workspace/lib/routes-boards.js +12 -6
  39. package/workspace/lib/routes-initiatives.js +1 -1
  40. package/workspace/lib/routes-proposals.js +26 -0
  41. package/workspace/lib/routes-stage-tools.js +1 -1
  42. package/workspace/lib/status-signal.js +6 -2
  43. package/workspace/lib/team-cli.js +4 -1
  44. package/workspace/lib/today-cli.js +1 -1
  45. package/workspace/lib/vendor/scripts/workflow-state.js +18 -7
  46. package/workspace/lib/work-kind.js +16 -4
  47. package/workspace/lib/workflow-cli.js +23 -1
  48. package/workspace/package-lock.json +2 -2
  49. package/workspace/package.json +1 -1
  50. package/workspace/public/pm/bd-asks.js +1 -1
  51. package/workspace/public/pm/bd-ini-panel.js +1 -1
  52. package/workspace/public/pm/bd-next.js +17 -5
  53. package/workspace/public/pm/bd-views.js +1 -1
  54. package/workspace/public/pm/ini-agent.js +14 -7
  55. package/workspace/public/pm/premium-board.js +1 -1
  56. package/workspace/public/pm/work-kind.js +10 -6
  57. package/workspace/skills/measure.skill +6 -6
@@ -11,7 +11,7 @@
11
11
  * pmos initiative drop <proposal-eid>
12
12
  * pmos initiative list
13
13
  * pmos initiative export <id> the breakdown as markdown on stdout; nothing is written
14
- * pmos initiative describe <id> ["<text>"] no text: its description and the cited lines Claude can draft it from; with text: write
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
16
  * every command: [--json] [--root <dir>]
17
17
  *
@@ -76,6 +76,8 @@ const USAGE = [
76
76
  ' pmos initiative list the Roadmap, ranked, with each lifecycle stage',
77
77
  ' pmos initiative export <id> the breakdown as markdown on stdout',
78
78
  ' pmos initiative describe <id> ["<text>"] read its description and what to draft it from; with text, save it (after the PM\'s yes)',
79
+ ' --lane is a work lane of this repository: new-feature, improvement, bug-fix, discovery or chore in a product repository',
80
+ ' (scripts/lane-defs.js; the PMOS repository itself uses feature, discovery, chore, incident, content and prototype)',
79
81
  ' every command: [--json] [--root <dir>]',
80
82
  'An agent session\'s move applies at once and names the agent. A new initiative lands at the end of the Roadmap.',
81
83
  'Now, Next and Later are retired (D105): the rank says what comes first, the lifecycle stage says where it is.',
@@ -154,7 +156,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
154
156
  startOnDefault(root, r, actor);
155
157
  // no initiative without an expected outcome (outcome-for-every-initiative): say what Claude drafts next, or that the PM names it
156
158
  return done({ id: r.id, path: r.path }, `✓ ${r.id} added at the end of the Roadmap (${r.path}). Commit the record to keep it.\n`
157
- + `✦ It needs an expected outcome and a date to check it. Claude drafts them from the PRD's success criteria once it is written (pmos outcomes propose ${r.id}); until then, ask the PM what should change once it ships.`);
159
+ + `✦ It needs an expected outcome and a date to check it. PMOS drafts them from the PRD's success criteria once it is written (pmos outcomes propose ${r.id}); until then, ask the PM what should change once it ships.`);
158
160
  }
159
161
 
160
162
  if (verb === 'list') {
@@ -226,11 +228,12 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
226
228
  const it = S.subjects.find((x) => x.id === did);
227
229
  if (!it) return fail(`no initiative ${did} here (or it is stopped, or on a document lane)`);
228
230
  const cur = it.fm.description ? String(it.fm.description.value || '') : '';
229
- const srcs = [DP.fromPrd(S, it), DP.fromRecord(S, it)].filter(Boolean);
231
+ const ex = DP.fromExperiment(S, it);
232
+ const srcs = [DP.fromPrd(S, it), ...(ex ? ex.parts : []), DP.fromRecord(S, it)].filter(Boolean);
230
233
  if (json) { say(JSON.stringify({ ok: true, id: did, description: cur || null, sources: srcs.map((x) => ({ label: x.source.label, ref: x.source.ref, text: x.text })) })); return 0; }
231
234
  say(cur ? `${did}: ${cur}` : `${did} has no description yet.`);
232
235
  if (srcs.length) say('Draft it from:\n' + srcs.map((x) => ` · ${x.source.label} [${x.source.ref}]: ${x.text}`).join('\n'));
233
- else say('Nothing readable to draft it from (no PRD paragraph, no paragraph in its record): ask the PM what it is.');
236
+ else say('Nothing readable to draft it from (no PRD paragraph, no experiment hypothesis or problem, no paragraph in its record): ask the PM what it is.');
234
237
  say(`Show the draft to the PM; after a yes: pmos initiative describe ${did} "<text>"`);
235
238
  return 0;
236
239
  }
@@ -35,6 +35,7 @@ const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record
35
35
  const USAGE = [
36
36
  'usage: pmos jira draft|show|epic|approve|pending|record|query|sync|summary|which — Jira tickets from the PRD, and their status',
37
37
  ' pmos jira draft <initiative> [--dry-run] draft one ticket per PRD item, in the ticket template',
38
+ ' With no PRD stories section: one ticket per done-test check, else one per open task.',
38
39
  ' pmos jira show <initiative> every ticket, what needs you, and its status in Jira',
39
40
  ' pmos jira epic <initiative> new|<KEY or link> [--group <g>] create a new epic at the first push, or use an existing one',
40
41
  ' pmos jira approve <initiative> <ID> … select tickets to push (you, in your own terminal)',
@@ -188,6 +189,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
188
189
  const r = jiraTickets.draft(root, initiative, { dryRun: !!flags['dry-run'], now });
189
190
  if (!r.ok) return fail(r.error);
190
191
  const lines = [`${initiative} · ${r.tickets} ${r.tickets === 1 ? 'ticket' : 'tickets'} in ${r.draft}${r.changed ? '' : ' · no change'}${flags['dry-run'] ? ' · dry run, nothing written' : ''}`];
192
+ if (r.from === 'done-test' || r.from === 'tasks') lines.push(` From ${r.from === 'done-test' ? 'the done test\'s checks' : 'the open tasks'} (${r.sources.join(', ')}): the PRD has no stories section.`);
191
193
  for (const c of r.changes) lines.push(` ${c.what.padEnd(9)} ${c.ticket} · ${c.summary}${c.why ? ` (${c.why})` : ''}`);
192
194
  lines.push('Read them on the Jira tickets tab, or with pmos jira show. Select the ready ones there, or with pmos jira approve.');
193
195
  return out(r, lines);
@@ -2,7 +2,9 @@
2
2
  /* jira-tickets.js — Jira tickets drafted from the PRD in the PM's template, selected by the PM, then pushed (initiative
3
3
  * jira-wbs, PRD J1 to J10 and J12, proposed D88).
4
4
  *
5
- * items(root, initiative) → { items, sources, prd } J1: the ticket items of the PRD and story files
5
+ * items(root, initiative) → { items, sources, prd, from } J1: the ticket items of the PRD and story files;
6
+ * with none, the done test's checks (D107), else the initiative's open tasks
7
+ * (launch simulation W4). `from` is 'prd', 'done-test' or 'tasks'.
6
8
  * fromItem(item, prd) → a ticket J2: one item in the PM's template
7
9
  * draft(root, initiative, opts) → the merged draft, written J3: new items added, unedited ones redrafted
8
10
  * view(root, initiative) → what the tab draws J4, J5, J10, J12
@@ -213,6 +215,65 @@ function readPrd(root, prd) {
213
215
  try { return fs.readFileSync(path.join(root, prd), 'utf8'); } catch { /* the main tree */ }
214
216
  try { return fs.readFileSync(path.join(mainRoot(root), prd), 'utf8'); } catch { return null; }
215
217
  }
218
+ /** The checks of a done test (D107): its table rows `| n | check | how |`, else its top-level bullets. → [{ n, check, how }] */
219
+ function checksInDoneTest(text) {
220
+ const lines = stripFm(text).split('\n');
221
+ const out = [];
222
+ for (const l of lines) {
223
+ const m = /^\|\s*(\d+)\s*\|\s*(.+?)\s*\|\s*(.*?)\s*\|?\s*$/.exec(l);
224
+ if (m && m[2] && !/^-+$/.test(m[2])) out.push({ n: Number(m[1]), check: m[2].replace(/\\\|/g, '|'), how: m[3] || '' });
225
+ }
226
+ if (out.length) return out;
227
+ let n = 0;
228
+ for (const l of lines) {
229
+ const b = /^[-*] (?:\[[ xX]\] )?(.+)$/.exec(l);
230
+ if (b) out.push({ n: ++n, check: b[1].trim(), how: '' });
231
+ }
232
+ return out;
233
+ }
234
+ /** The done test a record names, read from the worktree or the main tree (a kit repository may name it under pmos/). */
235
+ function readDoneTest(root, rfm) {
236
+ const p = rfm && isStr(rfm.done_test_path) ? rfm.done_test_path.trim() : '';
237
+ if (!p) return null;
238
+ for (const base of [root, mainRoot(root)]) {
239
+ for (const rel of [p, path.join('pmos', p)]) {
240
+ const abs = path.resolve(base, rel);
241
+ if (abs !== path.resolve(base) && !abs.startsWith(path.resolve(base) + path.sep)) continue;
242
+ try { return { path: path.relative(mainRoot(root), abs).split(path.sep).join('/') || rel, text: fs.readFileSync(abs, 'utf8') }; } catch { /* next */ }
243
+ }
244
+ }
245
+ return null;
246
+ }
247
+ /** One ticket item per done-test check: the check is the requirement, and how to check it is the acceptance. */
248
+ function itemsFromDoneTest(dt, title) {
249
+ return checksInDoneTest(dt.text).map((c) => {
250
+ const check = oneLine(c.check);
251
+ return {
252
+ id: `DT-${String(c.n).padStart(2, '0')}`, title: clip(check.replace(/\.$/, ''), 120), epic: null, refLabel: 'Done test', source: dt.path,
253
+ body: [`### User Story`, `As the PM of ${title}, I want this check of the done test to pass: ${check}`,
254
+ `### Functional Requirements`, check,
255
+ `### Acceptance Criteria`, `- ${check}`, ...(c.how ? [`- How to check: ${oneLine(c.how)}`] : [])].join('\n'),
256
+ };
257
+ });
258
+ }
259
+ /** One ticket item per open task of the initiative (its breakdown in plan-items.jsonl), in breakdown order. */
260
+ function itemsFromTasks(root, initiative, title) {
261
+ let fold;
262
+ try { fold = planItems.readFold(root, { now: 0 }); } catch { return []; }
263
+ const rel = path.relative(mainRoot(root), planItems.ledgerPath(root)).split(path.sep).join('/');
264
+ return (fold.order || []).map((id) => fold.items[id]).filter((it) => it && it.initiative === initiative && it.state !== 'done' && !it.proposed)
265
+ .map((it) => {
266
+ const what = oneLine(it.title);
267
+ const note = oneLine(it.note || '');
268
+ return {
269
+ id: `TK-${slug(what)}`, title: clip(what, 120), epic: null, refLabel: 'Task', source: rel, task: it.id,
270
+ body: [`### User Story`, `As the PM of ${title}, I want this task done: ${what}`,
271
+ ...(note ? [`### Additional Context`, note] : []),
272
+ `### Functional Requirements`, what,
273
+ `### Acceptance Criteria`, `- ${what}${it.due ? ` by ${it.due}` : ''}`].join('\n'),
274
+ };
275
+ });
276
+ }
216
277
  function items(root, initiative) {
217
278
  const fm = recordFm(root, initiative);
218
279
  if (!fm) return { ok: false, error: `no initiative ${initiative} in this repository` };
@@ -237,6 +298,18 @@ function items(root, initiative) {
237
298
  for (const x of s) x.source = rel;
238
299
  if (s.length) { found.push(...s); sources.push(rel); }
239
300
  }
301
+ // D107: no PRD stories section. The done test says what must be true, else the breakdown says what to do (launch simulation W4).
302
+ let from = found.length ? 'prd' : null;
303
+ const title = oneLine(fm.title || initiative);
304
+ if (!found.length) {
305
+ const dt = readDoneTest(root, fm);
306
+ const s = dt ? itemsFromDoneTest(dt, title) : [];
307
+ if (s.length) { found.push(...s); sources.push(dt.path); from = 'done-test'; }
308
+ }
309
+ if (!found.length) {
310
+ const s = itemsFromTasks(root, initiative, title);
311
+ if (s.length) { found.push(...s); sources.push(s[0].source); from = 'tasks'; }
312
+ }
240
313
  // Ids: the item's own (TD-01, S3) or a slug of its title; a repeat gets -2, -3.
241
314
  const seen = new Map();
242
315
  for (const s of found) {
@@ -248,7 +321,7 @@ function items(root, initiative) {
248
321
  s.epic = s.epic || null;
249
322
  s.hash = sha(s.title + '\n' + s.body + (s.epic ? '\n' + s.epic : ''));
250
323
  }
251
- return { ok: true, initiative, items: found, sources, prd: prd || null };
324
+ return { ok: true, initiative, items: found, sources, prd: prd || null, from };
252
325
  }
253
326
 
254
327
  // ── J2 · one item in the PM's template ─────────────────────────────────────────────────────────────
@@ -307,7 +380,7 @@ function fromItem(item, prd) {
307
380
  if (k === 'refs') continue;
308
381
  for (const l of lines) for (const m of l.matchAll(LINK_RE)) if (!own.includes(m[0]) && !links.includes(m[0])) links.push(m[0]);
309
382
  }
310
- const refs = [prd ? `- PRD: \`${prd}\` · ${item.id}` : `- Item: ${item.id}`];
383
+ const refs = [prd ? `- ${item.refLabel || 'PRD'}: \`${prd}\` · ${item.task || item.id}` : `- Item: ${item.id}`];
311
384
  if (own) refs.push(own);
312
385
  for (const l of links) refs.push(`- ${l}`);
313
386
  t.sections.refs = refs.join('\n');
@@ -414,7 +487,7 @@ function anchorOf(rfm) {
414
487
  function draft(root, initiative, { dryRun = false, now } = {}) {
415
488
  const st = items(root, initiative);
416
489
  if (!st.ok) return st;
417
- if (!st.items.length) return { ok: false, error: `no ticket items found for ${initiative} — add a "User stories" or "Tickets" section to its PRD${st.prd ? ` (${st.prd})` : ''}, one subheading per ticket, such as "### TD-01 · Title"` };
490
+ if (!st.items.length) return { ok: false, error: `no ticket items found for ${initiative} — add a "User stories" or "Tickets" section to its PRD${st.prd ? ` (${st.prd})` : ''}, one subheading per ticket, such as "### TD-01 · Title"; or give it a done test (done_test_path) with its checks, or tasks (pmos item)` };
418
491
  const old = readDraft(root, initiative);
419
492
  const prev = old ? old.tickets : [];
420
493
  const byId = new Map(prev.map((t) => [t.id, t]));
@@ -447,7 +520,7 @@ function draft(root, initiative, { dryRun = false, now } = {}) {
447
520
  fm.epic_mode = anchor ? 'existing' : 'new';
448
521
  if (anchor && !fm.epic) fm.epic = anchor;
449
522
  }
450
- const result = { ok: true, initiative, draft: draftRel(root, initiative), sources: st.sources, tickets: out.length, changes, changed: !old || changes.length > 0 };
523
+ const result = { ok: true, initiative, draft: draftRel(root, initiative), sources: st.sources, from: st.from, tickets: out.length, changes, changed: !old || changes.length > 0 };
451
524
  if (dryRun || (old && !changes.length)) return result;
452
525
  writeDraft(root, initiative, { fm, tickets: out }, { now, prd: st.prd });
453
526
  return result;
@@ -17,7 +17,7 @@ const E = require('./idle-lab-engine.js');
17
17
  const COMMANDS = { lab: ['page', 'file', 'status'] };
18
18
  const GROUPS = { 'prototype-new': ['prototyped'], 'prototype-improve': ['improved'], 'scan-new': ['scanned', 'scan'], 'scan-improve': ['scanned', 'scan'] };
19
19
  const USAGE = [
20
- 'usage: pmos lab page|file|status — the idle lab: Claude prototypes and scans while you are away; each result waits under ✦ for your ✓',
20
+ 'usage: pmos lab page|file|status — the idle lab: PMOS prototypes and scans while you are away; each result waits under ✦ for your ✓',
21
21
  ' pmos lab page <url> (scan run) read one public page; it prints the page with line numbers',
22
22
  ' pmos lab page <n> [--from <line>] (scan run) print page n of this run again, from a line',
23
23
  ' pmos lab file prototyped --json - { "title", "why", "specimens": [{ "key": "A", "title", "caption", "file": "a.html" }] (2 or 3),',
@@ -12,7 +12,7 @@ const SR = require('./source-reads.js');
12
12
 
13
13
  const COMMANDS = { lead: ['put', 'show', 'due'] };
14
14
  const USAGE = [
15
- 'usage: pmos lead put|show|due — Claude\'s short lead for a popup, written ahead and shown first',
15
+ 'usage: pmos lead put|show|due — PMOS\'s short lead for a popup, written ahead and shown first',
16
16
  ' pmos lead put --key <pop:kind:id> --text "<lead>" [--cite "<what you read, when>"] …',
17
17
  ' the lead: why it matters now, what is asked or blocking, and what to do, in at most 400 characters; at most 4 cites',
18
18
  ' pmos lead show [<key>] the stored lead of one popup, or every stored lead',
@@ -2,13 +2,14 @@
2
2
  /* measure-cli.js — `pmos measure …`: record a measured value of a KR or a health budget, with its source (pm-os-absorb
3
3
  * Run 2, PRD R17, R23, R24).
4
4
  *
5
- * pmos measure add <anchor> <value> --source <path>@<sha> [--target <number>] [--unit <unit>] [--as-of YYYY-MM-DD]
5
+ * pmos measure add <anchor> <value> --source <path>@<sha>|connector:<name>|document:<path or link> [--how "<how it was read>"]
6
+ * [--target <number>] [--unit <unit>] [--as-of YYYY-MM-DD]
6
7
  * pmos measure list [<anchor>]
7
8
  * every command: [--json] [--root <dir>]
8
9
  *
9
10
  * The SAME writer the workspace page uses (lib/measurements.js). A measurement is evidence, not a PM act, so an agent
10
11
  * may write one: the line is attributed by lib/actor.js fromCli (the PM at a terminal, the bound agent session from
11
- * PMOS_SESSION, `agent:unknown` otherwise). The source is required: the workspace never computes a KR value, so a
12
+ * PMOS_SESSION, `agent:unknown` otherwise). The source is required, and a connector or document source needs --how: the workspace never computes a KR value, so a
12
13
  * group shows a value only from a line that says where it was read. `--as-of` is today (UTC) when it is not given.
13
14
  * Exit codes: 0 done, 1 refused, 2 usage.
14
15
  */
@@ -21,14 +22,18 @@ const { parseArgs } = require('./schedule-cli');
21
22
  const COMMANDS = { measure: ['add', 'list'] };
22
23
  const USAGE = [
23
24
  'usage: pmos measure add|list — measured values of KRs and health budgets',
24
- ' pmos measure add <anchor> <value> --source <path>@<sha> [--target <number>] [--unit <unit>] [--as-of YYYY-MM-DD]',
25
+ ' pmos measure add <anchor> <value> --source <source> [--how "<how it was read>"] [--target <number>] [--unit <unit>] [--as-of YYYY-MM-DD]',
25
26
  ' pmos measure list [<anchor>]',
26
27
  ' every command: [--json] [--root <dir>]',
27
28
  'The anchor is the parent_kr an initiative names: a KR such as "KR 2.1", or health:<id>. Quote an anchor with a space.',
28
- 'The source is the file the value was read from and the commit it was read at, for example planning/okrs/q4.md@1a2b3c4.',
29
+ 'The source is where the value was read:',
30
+ ' <path>@<sha> a file in this repository at a commit, for example planning/okrs/q4.md@1a2b3c4',
31
+ ' connector:<name> an analytics tool or tracker read through a connector, for example connector:amplitude',
32
+ ' document:<path or link> a shared document or sheet outside the repository',
33
+ 'A connector or document source needs --how: the query, chart or cell, so the value can be read again. --as-of is the day it was read.',
29
34
  ];
30
35
  const BOOL = new Set(['json', 'help']);
31
- const VALUE = new Set(['source', 'target', 'unit', 'as-of', 'root']);
36
+ const VALUE = new Set(['source', 'how', 'target', 'unit', 'as-of', 'root']);
32
37
 
33
38
  function parse(argv) {
34
39
  const rest = []; const bools = {};
@@ -70,7 +75,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
70
75
  if (json) { say(JSON.stringify({ ok: true, byAnchor: Object.fromEntries(anchors.map((a) => [a, (m.byAnchor[a] || []).map((x) => ({ ...x, by: actorLib.pageName(x.by) }))])), flags: m.flags })); return 0; }
71
76
  if (!anchors.length) say('No measurements yet.');
72
77
  for (const a of anchors) {
73
- for (const x of m.byAnchor[a] || []) say(`${a} · ${x.value}${x.unit || ''}${x.target === null ? '' : ` → ${x.target}${x.unit || ''}`} on ${x.as_of} · ${x.source} · ${actorLib.pageName(x.by)}`);
78
+ for (const x of m.byAnchor[a] || []) say(`${a} · ${x.value}${x.unit || ''}${x.target === null ? '' : ` → ${x.target}${x.unit || ''}`} on ${x.as_of} · ${x.source}${x.how ? ` (${x.how})` : ''} · ${actorLib.pageName(x.by)}`);
74
79
  }
75
80
  for (const f of m.flags) say(`! ${f.why}`);
76
81
  return 0;
@@ -89,11 +94,12 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
89
94
  if (flags.unit !== undefined) ev.unit = flags.unit;
90
95
  ev.as_of = flags['as-of'] || new Date(now == null ? Date.now() : now).toISOString().slice(0, 10);
91
96
  if (flags.source !== undefined) ev.source = flags.source;
97
+ if (flags.how !== undefined) ev.how = String(flags.how).trim();
92
98
  const actor = actorLib.fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env: env === undefined ? process.env : env });
93
99
  const r = measurements.appendFromCli(root, [ev], { actor, now });
94
100
  if (!r.ok) return fail(r.error);
95
101
  if (json) say(JSON.stringify({ ok: true, written: r.written, eid: r.lines[0].eid }));
96
- else say(`✓ ${anchor}: ${value}${ev.unit || ''} on ${ev.as_of} recorded (source ${ev.source})`);
102
+ else say(`✓ ${anchor}: ${value}${ev.unit || ''} on ${ev.as_of} recorded (source ${ev.source}${ev.how ? `, ${ev.how}` : ''})`);
97
103
  return 0;
98
104
  }
99
105
 
@@ -4,13 +4,15 @@
4
4
  *
5
5
  * readMeasurements(root) → {
6
6
  * ok: true,
7
- * byAnchor: { [anchor]: [{ value, target, unit, as_of, source, by, at }] }, oldest first; `source` is "path@sha"
7
+ * byAnchor: { [anchor]: [{ value, target, unit, as_of, source, how, by, at }] }, oldest first; `source` is "path@sha",
8
+ * "connector:<name>" or "document:<path or link>"; `how` is null for path@sha
8
9
  * flags: [{ kind, eid, why }],
9
10
  * }
10
11
  * latest(result, anchor) → the newest measurement of `anchor` by as_of, or null
11
12
  * appendFromUi(root, events, { actor, now }) → { ok, written, lines } | { ok: false, status, error, index }
12
13
  * appendFromCli(root, events, { actor, now }) → the same
13
14
  * checkEvent(ev) → null | error text the caller-side checks, shared with `pmos measure`
15
+ * sourceKind(source) → 'repo' | 'connector' | 'document' | null
14
16
  *
15
17
  * `anchor` is the initiative's parent_kr as written (a KR id, or `health:<id>`, D59). A measurement needs a source; an
16
18
  * agent may write one (it is evidence, not a PM act), so the actor comes from actor.js, never from the caller.
@@ -18,12 +20,18 @@
18
20
  *
19
21
  * THE `measured` LINE (the shared contract):
20
22
  * { v: 1, eid, ev: 'measured', anchor, value: <number>, target: <number> | null, unit?: '%'|…, as_of: 'YYYY-MM-DD',
21
- * source: '<path>@<sha>', by, via, at }
23
+ * source: '<path>@<sha>' | 'connector:<name>' | 'document:<path or link>', how?: '<how it was read>', by, via, at }
22
24
  * pmOnly(rec) → false: a measurement is evidence, not a PM act.
23
25
  *
24
- * `source` is a repository-relative path, `@`, and a commit sha of 7 to 40 hex characters: the file the number was
25
- * read from, at the commit it was read at. The writer does not open it (no read outside the call's own checks), so a
26
- * wrong path is the writer's caller's error; scripts/check-measurements.js reports a path that is not in the tree.
26
+ * `source` is one of three kinds:
27
+ * repo a repository-relative path, `@`, and a commit sha of 7 to 40 hex characters: the file the number was read
28
+ * from, at the commit it was read at.
29
+ * connector `connector:<name>`: an analytics tool or tracker read through a connector (Amplitude, GA4, Jira, …).
30
+ * document `document:<path or link>`: a shared document or sheet outside the repository.
31
+ * A connector or document source carries `how`, one line on how the value was read (the query, the chart, the cell), so
32
+ * a reader can read it again; `as_of` is the date it was read. This matches `pmos report read` (launch simulation W4).
33
+ * The writer does not open a source (no read outside the call's own checks), so a wrong path is the writer's caller's
34
+ * error; scripts/check-measurements.js reports a path that is not in the tree.
27
35
  *
28
36
  * The fold is order-free, like lib/plan-items.js: byte-identical duplicates count once, one eid with two contents keeps
29
37
  * the first. The ledger is one per repository: lib/plan-ledgers.js ledgerPath(root, 'measurements'). Nothing is cached.
@@ -42,9 +50,12 @@ const AT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
42
50
  /** A KR id as the OKR files write it, or a health budget or a domain (D59, D67). One line, no control characters. */
43
51
  const ANCHOR_RE = /^(?:health:[a-z0-9][a-z0-9-]{0,59}|domain:[a-z0-9][a-z0-9-]{0,59}|[A-Za-z0-9][A-Za-z0-9 .:_-]{0,79})$/;
44
52
  const SOURCE_RE = /^([A-Za-z0-9_][A-Za-z0-9_./-]{0,239})@([0-9a-f]{7,40})$/;
53
+ const CONNECTOR_RE = /^connector:([A-Za-z0-9][A-Za-z0-9 ._-]{0,59})$/;
54
+ const DOCUMENT_RE = /^document:([^\x00-\x1f\x7f]{1,300})$/;
55
+ const HOW_RE = /^[^\x00-\x1f\x7f]{1,200}$/;
45
56
  const UNIT_RE = /^[^\s\x00-\x1f]{1,12}$/;
46
57
  const WRITER_SET = Object.freeze(['v', 'eid', 'by', 'via', 'at', 'override', 'pm', 'actor', 'nonce']);
47
- const CALLER_KEYS = Object.freeze(['anchor', 'value', 'target', 'unit', 'as_of', 'source']);
58
+ const CALLER_KEYS = Object.freeze(['anchor', 'value', 'target', 'unit', 'as_of', 'source', 'how']);
48
59
  const STORED_KEYS = Object.freeze(['v', 'eid', 'ev', 'by', 'via', 'at', ...CALLER_KEYS]);
49
60
  const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
50
61
 
@@ -73,6 +84,15 @@ function parseSource(s) {
73
84
  return { path: m[1], sha: m[2] };
74
85
  }
75
86
 
87
+ /** 'repo' (path@sha), 'connector' (connector:<name>), 'document' (document:<path or link>), or null. */
88
+ function sourceKind(s) {
89
+ if (!isStr(s) || s !== s.trim()) return null;
90
+ if (parseSource(s)) return 'repo';
91
+ if (CONNECTOR_RE.test(s)) return 'connector';
92
+ const d = DOCUMENT_RE.exec(s);
93
+ return d && d[1].trim() ? 'document' : null;
94
+ }
95
+
76
96
  /** The checks on what a caller sends (the writer runs them; `pmos measure` runs them before it writes). */
77
97
  function checkEvent(ev) {
78
98
  if (!ev || typeof ev !== 'object' || Array.isArray(ev)) return 'each line must be a JSON object';
@@ -86,8 +106,11 @@ function checkEvent(ev) {
86
106
  if (has(ev, 'target') && ev.target !== null && (typeof ev.target !== 'number' || !Number.isFinite(ev.target))) return 'target must be a number, or null';
87
107
  if (has(ev, 'unit') && !(isStr(ev.unit) && UNIT_RE.test(ev.unit))) return 'unit must be a short word with no spaces, like %';
88
108
  if (!dateOk(ev.as_of)) return 'as_of must be YYYY-MM-DD';
89
- if (!has(ev, 'source') || ev.source === '' || ev.source == null) return 'a measurement needs a source: <path>@<commit sha>';
90
- if (!parseSource(ev.source)) return 'source must be <repository-relative path>@<commit sha of 7 to 40 hex characters>';
109
+ if (!has(ev, 'source') || ev.source === '' || ev.source == null) return 'a measurement needs a source: <path>@<commit sha>, connector:<name> or document:<path or link>';
110
+ const kind = sourceKind(ev.source);
111
+ if (!kind) return 'source must be <repository-relative path>@<commit sha of 7 to 40 hex characters>, connector:<name> or document:<path or link>';
112
+ if (has(ev, 'how') && !(isStr(ev.how) && HOW_RE.test(ev.how) && ev.how.trim() === ev.how)) return 'how must be one line of at most 200 characters';
113
+ if (kind !== 'repo' && !has(ev, 'how')) return `a ${kind} source needs how the value was read (the query, chart or cell), so it can be read again`;
91
114
  return null;
92
115
  }
93
116
 
@@ -127,7 +150,7 @@ function readMeasurements(root) {
127
150
  seen.set(rec.eid, text);
128
151
  (out.byAnchor[rec.anchor] = out.byAnchor[rec.anchor] || []).push({
129
152
  value: rec.value, target: Number.isFinite(rec.target) ? rec.target : null, unit: rec.unit || null,
130
- as_of: rec.as_of, source: rec.source, by: rec.by, at: rec.at,
153
+ as_of: rec.as_of, source: rec.source, how: isStr(rec.how) ? rec.how : null, by: rec.by, at: rec.at,
131
154
  });
132
155
  }
133
156
  for (const rows of Object.values(out.byAnchor)) rows.sort((a, b) => String(a.as_of).localeCompare(String(b.as_of)) || String(a.at).localeCompare(String(b.at)));
@@ -164,7 +187,7 @@ function append(root, events, actor, { now } = {}) {
164
187
  last = Math.max(clock, last + 1);
165
188
  const rec = { v: 1, eid: newEventId(), ev: 'measured', anchor: ev.anchor, value: ev.value, target: has(ev, 'target') ? ev.target : null };
166
189
  if (has(ev, 'unit')) rec.unit = ev.unit;
167
- Object.assign(rec, { as_of: ev.as_of, source: ev.source, by: actor.by, via: actor.via, at: new Date(last).toISOString() });
190
+ Object.assign(rec, { as_of: ev.as_of, source: ev.source }, has(ev, 'how') ? { how: ev.how } : {}, { by: actor.by, via: actor.via, at: new Date(last).toISOString() });
168
191
  return rec;
169
192
  });
170
193
  let file;
@@ -186,4 +209,4 @@ function appendFromUi(root, events, { actor, now } = {}) { return append(root, e
186
209
  /** `pmos measure` (actor.fromCli's actor; an agent may write a measurement). */
187
210
  function appendFromCli(root, events, { actor, now } = {}) { return append(root, events, actor, { now }); }
188
211
 
189
- module.exports = { MAX_LINES, readMeasurements, latest, pmOnly, checkEvent, parseSource, lineErr, appendFromUi, appendFromCli };
212
+ module.exports = { MAX_LINES, readMeasurements, latest, pmOnly, checkEvent, parseSource, sourceKind, lineErr, appendFromUi, appendFromCli };
@@ -31,7 +31,7 @@ const MR = require('./metric-reads.js');
31
31
  const COMMANDS = { metrics: ['draft', 'reading'] };
32
32
  const SUBS = ['read', 'step', 'row', 'fix', 'end', 'status'];
33
33
  const USAGE = [
34
- 'usage: pmos metrics draft read|step|row|end|status — the metrics Claude drafts for the PM to keep or drop',
34
+ 'usage: pmos metrics draft read|step|row|end|status — the metrics PMOS drafts for the PM to keep or drop',
35
35
  ' pmos metrics draft read "<source>" --found "<what it says, one line>" [--state done|now|wait]',
36
36
  ' pmos metrics draft step shape|measure|target|ready',
37
37
  ' pmos metrics draft row --json <file|->',
@@ -59,7 +59,7 @@ function reading(args, { say, env, now }) {
59
59
  const file = env.PMOS_METRIC_READ_FILE, runId = env.PMOS_METRIC_READ_RUN, root = env.PMOS_METRIC_READ_RECORDS, ws = env.PMOS_METRIC_READ_WS;
60
60
  const rids = String(env.PMOS_METRIC_READ_RIDS || '').split(',').filter(Boolean), test = !!env.PMOS_METRIC_READ_TEST;
61
61
  if (!args[0] || ['help', '--help', '-h'].includes(args[0])) { for (const l of USAGE.filter((x) => /reading|Every/.test(x))) say(l); return args[0] ? 0 : 1; }
62
- if (!file || !runId || !rids.length || (!test && !root)) { say('✗ pmos metrics reading is for Claude\'s reading run. The PM adds a reading on the goal\'s page.'); return 1; }
62
+ if (!file || !runId || !rids.length || (!test && !root)) { say('✗ pmos metrics reading is for PMOS\'s reading run. The PM adds a reading on the goal\'s page.'); return 1; }
63
63
  const F = MR.fold(MR.readLines(file)), R = F.runs.get(runId);
64
64
  if (!R || R.ended) { say('✗ this run is not reading now. It ended, or the PM pressed Stop. File nothing more.'); return 1; }
65
65
  const records = () => require(require('./repo-script.js').repoScript('records/index.js'));
@@ -156,7 +156,7 @@ function reading(args, { say, env, now }) {
156
156
  const L = require(require('./repo-script.js').repoScript('trust/ledger.js'));
157
157
  const actor = L.actorFrom({ env, isTTY: !!(process.stdout && process.stdout.isTTY) }) || { by: 'claude-code/metric-read', via: 'cli' };
158
158
  const reading = { at: day, value: v, source: src, via: R.why === 'press' ? 'press' : 'run', read_at: at, ...(num !== undefined ? { num } : {}), ...(den !== undefined ? { den } : {}), ...(period ? { period } : {}) };
159
- let r; try { r = records().addReading(root, rid, reading, actor, R.why === 'press' ? 'Claude read it now, as the PM asked' : 'Claude read it with its recipe'); } catch (e) { r = { ok: false, reasons: [String((e && e.message) || e).slice(0, 160)] }; }
159
+ let r; try { r = records().addReading(root, rid, reading, actor, R.why === 'press' ? 'PMOS read it now, as the PM asked' : 'PMOS read it with its recipe'); } catch (e) { r = { ok: false, reasons: [String((e && e.message) || e).slice(0, 160)] }; }
160
160
  if (!r.ok) { say('✗ refused: ' + r.reasons.join('; ')); return 1; }
161
161
  }
162
162
  lineOut({ kind: 'read', value: v, day, source: src, ...extra });
@@ -179,7 +179,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
179
179
  if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
180
180
  if (!SUBS.includes(sub)) { say(`unknown draft command "${sub}". Use one of: ${SUBS.join(', ')}`); return 2; }
181
181
  const file = env.PMOS_METRIC_DRAFT_FILE, runId = env.PMOS_METRIC_DRAFT_RUN, scope = env.PMOS_METRIC_DRAFT_SCOPE, id = env.PMOS_METRIC_DRAFT_ID;
182
- if (!file || !runId || !MD.SCOPES.includes(scope) || !id) { say('✗ pmos metrics draft is for Claude\'s metric-draft run. The PM keeps and drops drafts on the page.'); return 1; }
182
+ if (!file || !runId || !MD.SCOPES.includes(scope) || !id) { say('✗ pmos metrics draft is for PMOS\'s metric-draft run. The PM keeps and drops drafts on the page.'); return 1; }
183
183
  const F = MD.fold(MD.readLines(file)), s = F.scopes.get(MD.keyOf(scope, id));
184
184
  const at = new Date(now).toISOString();
185
185
  const line = (ev) => { fs.appendFileSync(file, JSON.stringify({ at, by: null, scope, id, run: runId, ...ev }) + '\n'); };
@@ -19,6 +19,10 @@
19
19
  * takes a few weeks of mornings, or `pmos outcomes propose` in a sitting). A draft the PM dropped (✕) or kept is not filed again. When a
20
20
  * record has its outcome by another way (`pmos outcomes declare`, an edit), the open draft is dropped. It never writes a record: only the PM's ✓.
21
21
  *
22
+ * A REFUTED OUTCOME (launch simulation W2). Every tick (not once a day) the server reads each product's outcome ledger, and for a verdict
23
+ * that says it did not work, files PMOS's next step under the ✦ (lib/outcomes.js refutedDrafts): stop it when the evidence meets the
24
+ * kill condition, a new experiment after a second refuted check, else one more round. Class C (lib/autonomy.js): only the PM's ✓ does it.
25
+ *
22
26
  * deps: { workspaces() → [w], isLead(w), stateDirFor(w), boardOf(w, id) → board id | null, runtime() → the per-user state folder, open(now),
23
27
  * env, every (ms, its own timer), mayRun(), warn(what, err) }
24
28
  */
@@ -32,12 +36,17 @@ const off = (env) => flagOff((env || process.env).PMOS_OUTCOMES);
32
36
  const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
33
37
  const guardLib = () => { try { return require('./ai-guard.js'); } catch { return null; } };
34
38
  const versionOf = (w) => O.VERSION + ':' + w.id;
35
- const typeOf = (d) => (d.data.kind === 'undated' ? 'date' : 'new');
39
+ const typeOf = (d) => (d.data.kind === 'undated' ? 'date' : d.data.kind === 'refuted' ? 'refuted' : 'new');
36
40
 
37
41
  /** The proposals line a draft becomes. */
38
42
  function lineOf(d, board, run) {
39
43
  const type = typeOf(d), ini = d.data.initiative;
40
44
  const sources = d.claims.flatMap((c) => c.sources).map((s) => ({ label: s.label, ref: s.ref }));
45
+ if (type === 'refuted') {
46
+ // one per check: a later refuted check files again (its key is the check's own line)
47
+ const c = PR.clean('outcome', 'refuted', { title: d.title, why: d.say, sources, items: [{ id: 'next', title: O.NEXT_WORDS[d.data.next], ...(d.data.horizon ? { due: d.data.horizon } : {}) }], data: d.data });
48
+ return c.error ? null : { kind: 'propose', ini, board, run, id: PR.idOf(ini, 'outcome', type, d.data.ref || d.data.check), ...c.prop };
49
+ }
41
50
  const c = PR.clean('outcome', type, { title: type === 'date' ? 'A date to check the outcome' : 'What should change once it ships', why: d.say, sources,
42
51
  items: [{ id: 'outcome', title: d.data.metric, due: d.data.horizon }], data: { metric: d.data.metric, horizon: d.data.horizon } });
43
52
  if (c.error) return null;
@@ -47,7 +56,7 @@ function lineOf(d, board, run) {
47
56
  /** One product's replay cases: its own drafts must all pass, and an initiative with nothing to cite gets no draft. */
48
57
  function cases(S, list) {
49
58
  const out = [{ name: 'the drafts of ' + S.root.split(/[\\/]/).pop(), run: async () => list.slice(0, PER_DAY), expect: { filed: Math.min(PER_DAY, list.length) } }];
50
- out.push({ name: 'nothing to cite, no draft', run: async () => O.drafts({ ...S, due: [], undated: [], missing: [{ id: 'zz-no-source', title: 'No source', fm: {}, prd: '', anchor: '' }] }, { tasks: [] }).drafts, expect: { none: true } });
59
+ out.push({ name: 'nothing to cite, no draft', run: async () => O.drafts({ ...S, subjects: [], due: [], undated: [], missing: [{ id: 'zz-no-source', title: 'No source', fm: {}, prd: '', anchor: '' }] }, { tasks: [] }).drafts, expect: { none: true } });
51
60
  return out;
52
61
  }
53
62
 
@@ -64,7 +73,7 @@ function create(deps) {
64
73
  // a record that has its outcome now: its open draft goes (zero is silence)
65
74
  const has = new Map(S.subjects.map((it) => [it.id, it]));
66
75
  for (const p of F.props.values()) {
67
- if (p.group !== 'outcome' || kept.has(p.id)) continue;
76
+ if (p.group !== 'outcome' || p.type === 'refuted' || kept.has(p.id)) continue; // a refuted outcome's next step: refutedPass keeps it
68
77
  const it = has.get(p.ini), sig = PR.sigOf(p);
69
78
  if (F.drops.has(sig)) continue;
70
79
  if (!it || (it.metric && (p.type === 'new' || it.horizon))) PR.append(dir, { by: 'pmos:outcomes' }, { kind: 'drop', ini: p.ini, sig });
@@ -92,8 +101,53 @@ function create(deps) {
92
101
  return { ws: w.id, filed: (r.filed || []).length, held: !!r.held, off: r.off || null };
93
102
  }
94
103
 
104
+ /** A refuted outcome's next step (launch simulation W2): filed at the tick after the PM's verdict, not once a day. Quiet hours do not
105
+ * hold it back: the PM just recorded the verdict. One ✦ per check; a ✦ the PM kept or dropped is not filed again. */
106
+ async function refutedPass(w, { now = Date.now() } = {}) {
107
+ const dir = deps.stateDirFor(w); if (!dir) return { ws: w.id, filed: 0 };
108
+ if (!O.anyRefuted(w.root)) return { ws: w.id, filed: 0 }; // most products: no refuted check, so no scan every tick
109
+ const S = O.scan(w.root, { today: localDay(now) });
110
+ const D = O.refutedDrafts(S);
111
+ const F = PR.read(dir), kept = PR.keptIds(F), fresh = [];
112
+ const live = new Set(D.map((d) => d.data.initiative + '|' + d.data.ref));
113
+ for (const p of F.props.values()) {
114
+ if (p.group !== 'outcome' || p.type !== 'refuted' || kept.has(p.id) || F.drops.has(PR.sigOf(p))) continue;
115
+ if (!live.has(p.ini + '|' + ((p.data && (p.data.ref || p.data.check)) || ''))) PR.append(dir, { by: 'pmos:outcomes' }, { kind: 'drop', ini: p.ini, sig: PR.sigOf(p) }); // answered another way: zero is silence
116
+ }
117
+ for (const d of D) {
118
+ const board = deps.boardOf(w, d.data.initiative); if (!board) continue;
119
+ const l = lineOf(d, board, ''); if (!l) continue;
120
+ const prev = F.props.get(l.id);
121
+ if (kept.has(l.id) || (prev && (F.drops.has(PR.sigOf(prev)) || prev.data.next === l.data.next))) continue;
122
+ fresh.push({ d, board });
123
+ }
124
+ if (!fresh.length) return { ws: w.id, filed: 0 };
125
+ const AG = guardLib(); if (!AG) return { ws: w.id, filed: 0, why: 'the shared guard is not installed' };
126
+ const rt = deps.runtime && deps.runtime(), version = versionOf(w), run = 'or' + now.toString(36) + crypto.randomBytes(3).toString('hex');
127
+ if (!AG.off(O.JOB, { env: deps.env || process.env, settingsDir: rt }) && !AG.ready(rt, O.JOB, version)) {
128
+ const rep = await AG.replay(O.JOB, version, cases(S, fresh.map((x) => x.d)), { root: w.root, stateDir: rt, max: PER_DAY });
129
+ if (!rep.ok) { warn('outcomes replay ' + w.id, new Error(rep.failed.map((f) => f.name + ': ' + f.why).join('; '))); return { ws: w.id, filed: 0, replay: rep }; }
130
+ }
131
+ const byId = new Map(fresh.map((x) => [x.d.id, x]));
132
+ const r = await AG.file({ job: O.JOB, version, run, root: w.root, stateDir: rt, settingsDir: rt, env: deps.env || process.env, max: PER_DAY }, fresh.map((x) => x.d),
133
+ async (acc) => { for (const p of acc) { const x = byId.get(p.id); const l = x && lineOf(x.d, x.board, run); if (l) PR.append(dir, { by: 'agent:outcomes' }, l); } });
134
+ return { ws: w.id, filed: (r.filed || []).length, held: !!r.held, off: r.off || null };
135
+ }
136
+
95
137
  async function tick({ now = Date.now() } = {}) {
96
138
  if (off(deps.env) || busy) return { off: off(deps.env), running: busy };
139
+ busy = true;
140
+ const refuted = [];
141
+ try {
142
+ for (const w of deps.workspaces()) {
143
+ try { if (deps.isLead && !deps.isLead(w)) continue; } catch { continue; }
144
+ try { refuted.push(await refutedPass(w, { now })); } catch (e) { warn('outcomes refuted ' + w.id, e); }
145
+ }
146
+ } finally { busy = false; }
147
+ const r = await dailyTick({ now });
148
+ return { ...r, refuted };
149
+ }
150
+ async function dailyTick({ now = Date.now() } = {}) {
97
151
  let open = true;
98
152
  try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
99
153
  if (!open) return { closed: true };
@@ -114,7 +168,7 @@ function create(deps) {
114
168
  const t = setInterval(() => { try { if (deps.mayRun && !deps.mayRun()) return; } catch { /* no lock: run */ } tick({}).catch((e) => warn('outcomes tick', e)); }, deps.every);
115
169
  if (t.unref) t.unref();
116
170
  }
117
- return { tick, runProduct };
171
+ return { tick, runProduct, refutedPass };
118
172
  }
119
173
 
120
174
  module.exports = { create, cases, lineOf, off, PER_DAY };
@@ -24,7 +24,7 @@ const COMMANDS = { outcomes: ['list', 'propose', 'declare', 'record'] };
24
24
  const USAGE = [
25
25
  'usage: pmos outcomes list|propose|declare|record — every initiative has an expected outcome and a date to check it',
26
26
  ' pmos outcomes list [--json] checks due, outcomes with no date, initiatives with no outcome; reads only',
27
- ' pmos outcomes propose [<id>] [--max <n>] [--json] Claude\'s ✦ drafts from the PRD and the KR, each one cited',
27
+ ' pmos outcomes propose [<id>] [--max <n>] [--json] PMOS\'s ✦ drafts from the PRD and the KR, each one cited',
28
28
  ' pmos outcomes declare <id> --metric "<text>" --horizon <YYYY-MM-DD> the PM said yes: write the outcome and its check date',
29
29
  ' pmos outcomes record <id> <worked|didnt-work|cant-tell> --evidence "<text>" the PM\'s verdict on a due check',
30
30
  'Run it in the product\'s repository, or pass --root <dir>. Show each ✦ to the PM and write only after a yes.',
@@ -47,7 +47,8 @@ function repoRoot(cwd) {
47
47
  }
48
48
  const wsIdOf = (root) => { try { return require('./driver.js').wsIdOf(root); } catch { return require('crypto').createHash('sha1').update(path.resolve(root)).digest('hex').slice(0, 10); } };
49
49
  const draftText = (p) => `✦ ${p.title}\n ${p.say}\n${p.claims.map((c) => ' · ' + c.text + ' [' + c.sources.map((s) => s.ref).join(', ') + ']').join('\n')}`
50
- + (p.data && p.data.kind !== 'due' ? `\n Yes → pmos outcomes declare ${p.data.initiative} --metric ${JSON.stringify(p.data.metric)} --horizon ${p.data.horizon}`
50
+ + (p.data && p.data.kind === 'refuted' ? `\n It waits under the initiative's ✦ for the PM's ✓ (${O.NEXT_WORDS[p.data.next]}); a ✕ with a reason leaves it as it is.`
51
+ : p.data && p.data.kind !== 'due' ? `\n Yes → pmos outcomes declare ${p.data.initiative} --metric ${JSON.stringify(p.data.metric)} --horizon ${p.data.horizon}`
51
52
  : p.data ? `\n Verdict → pmos outcomes record ${p.data.initiative} worked|didnt-work|cant-tell --evidence "<what shows it>"` : '');
52
53
 
53
54
  async function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now(), isTTY, runtime } = {}) {
@@ -74,7 +75,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
74
75
  if (S.missing.length) say(`\n${S.missing.length} under way with no expected outcome${S.recent ? ` (${S.recent} edited in the last 30 days)` : ''}:\n` + S.missing.slice(0, 15).map((it) => ` ${it.id} — ${it.title}`).join('\n') + (S.missing.length > 15 ? `\n … and ${S.missing.length - 15} more (--json lists all)` : ''));
75
76
  if (S.shippedWithout) say(`\n${S.shippedWithout} accepted with no outcome: too late to declare, counted only.`);
76
77
  if (S.notRead.length) say('Not read: ' + S.notRead.join(', '));
77
- if (S.due.length || S.undated.length || S.missing.length) say('\nClaude drafts each one: pmos outcomes propose');
78
+ if (S.due.length || S.undated.length || S.missing.length) say('\nPMOS drafts each one: pmos outcomes propose');
78
79
  return 0;
79
80
  }
80
81
 
@@ -132,6 +133,11 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
132
133
  if (!r.ok) return fail(r.error);
133
134
  if (flags.json) { say(JSON.stringify({ ok: true, file: r.file, line: r.line })); return 0; }
134
135
  say(`✓ ${id}: ${disposition} — ${r.line.evidence} (${r.file}). Commit it to keep it.`);
136
+ // launch simulation W2: a refuted outcome reads at risk on every surface now, and PMOS says the next step it files under the ✦
137
+ if (disposition === 'refuted') {
138
+ const d = O.refutedDrafts(O.scan(root, { today }), { only: id })[0];
139
+ if (d) { say(` Its status reads at risk until you pick the next step. PMOS suggests: ${O.NEXT_WORDS[d.data.next]}.`); say(' ' + d.say); say(' The workspace files it under the initiative\'s ✦ for your ✓.'); }
140
+ }
135
141
  return 0;
136
142
  }
137
143