create-pmos 0.717.0 → 0.719.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 (34) hide show
  1. package/package.json +51 -33
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/changelog.json +50 -0
  8. package/workspace/fixtures/premium-viewer-fixtures.js +10 -5
  9. package/workspace/guide/cli.md +14 -0
  10. package/workspace/guide/home.md +1 -1
  11. package/workspace/guide/layout.md +8 -2
  12. package/workspace/lib/item-why.js +235 -0
  13. package/workspace/lib/needs-providers.js +1 -0
  14. package/workspace/lib/pinned-views.js +26 -0
  15. package/workspace/lib/pmos-verbs.js +5 -0
  16. package/workspace/lib/product-health-cli.js +13 -0
  17. package/workspace/lib/product-health.js +259 -0
  18. package/workspace/lib/routes-search.js +4 -2
  19. package/workspace/lib/search-answer.js +164 -0
  20. package/workspace/lib/why-cli.js +79 -0
  21. package/workspace/package-lock.json +2 -2
  22. package/workspace/package.json +1 -1
  23. package/workspace/public/pm/cozy-nav.js +14 -3
  24. package/workspace/public/pm/cozy-search.js +18 -2
  25. package/workspace/public/pm/palette-all.js +101 -0
  26. package/workspace/public/pm/pinned-views.css +17 -0
  27. package/workspace/public/pm/pinned-views.js +130 -0
  28. package/workspace/public/pm/premium-board.js +53 -3
  29. package/workspace/public/premium-board.html +1 -0
  30. package/workspace/test-lists/item-why.json +9 -0
  31. package/workspace/test-lists/palette-all.json +9 -0
  32. package/workspace/test-lists/pinned-filter-views.json +9 -0
  33. package/workspace/test-lists/product-health.json +9 -0
  34. package/workspace/test-lists/search-answers-first.json +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.717.0",
3
+ "version": "0.719.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": {
@@ -33,6 +33,56 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.719.0",
38
+ "at": "2026-11-23T00:11:29.887Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1594,
43
+ "t": "Meeting test stand-in answers the week the page asks for",
44
+ "s": "Meeting test stand-in answers the week the page asks for",
45
+ "k": "fix"
46
+ },
47
+ {
48
+ "n": 1596,
49
+ "t": "Pin a filter as a view beside the product switcher (job #1558)",
50
+ "s": "Pin a filter as a view beside the product switcher (job #1558)",
51
+ "k": "new"
52
+ },
53
+ {
54
+ "n": 1595,
55
+ "t": "Ctrl+K reaches every page, item and action (job #1562)",
56
+ "s": "Ctrl+K reaches every page, item and action (job #1562)",
57
+ "k": "new"
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ "v": "0.718.0",
63
+ "at": "2026-11-22T23:44:48.503Z",
64
+ "f": 4,
65
+ "prs": [
66
+ {
67
+ "n": 1589,
68
+ "t": "Search answers first, with its source",
69
+ "s": "Search answers first, with its source",
70
+ "k": "new"
71
+ },
72
+ {
73
+ "n": 1592,
74
+ "t": "Pmos why, the three-line why of any initiative or task",
75
+ "s": "Pmos why, the three-line why of any initiative or task",
76
+ "k": "new"
77
+ },
78
+ {
79
+ "n": 1590,
80
+ "t": "One health score per product, shown only when it drops",
81
+ "s": "One health score per product, shown only when it drops",
82
+ "k": "new"
83
+ }
84
+ ]
85
+ },
36
86
  {
37
87
  "v": "0.717.0",
38
88
  "at": "2026-11-22T21:55:40.797Z",
@@ -446,38 +496,6 @@
446
496
  "k": "fix"
447
497
  }
448
498
  ]
449
- },
450
- {
451
- "v": "0.683.0",
452
- "at": "2026-11-22T08:20:39.884Z",
453
- "f": 4,
454
- "prs": [
455
- {
456
- "n": 1494,
457
- "t": "Acceptance criteria on each ticket, written from the done test",
458
- "s": "Acceptance criteria on each ticket, written from the done test",
459
- "k": "new"
460
- }
461
- ]
462
- },
463
- {
464
- "v": "0.682.0",
465
- "at": "2026-11-22T07:57:47.146Z",
466
- "f": 4,
467
- "prs": [
468
- {
469
- "n": 1487,
470
- "t": "Design drift guard counts token bypasses, with a ratchet",
471
- "s": "Design drift guard counts token bypasses, with a ratchet",
472
- "k": "new"
473
- },
474
- {
475
- "n": 1478,
476
- "t": "Work breakdown keeps done tasks in date order and folds a finished stage",
477
- "s": "Work breakdown keeps done tasks in date order and folds a finished stage",
478
- "k": "new"
479
- }
480
- ]
481
499
  }
482
500
  ]
483
501
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@cb32d99a
2
- assembled: 2026-11-22
1
+ kernel-source: pmos@147e078f
2
+ assembled: 2026-11-23
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-22T21:55:37Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-23T00:11:26Z"}
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-22T21:55:37Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-23T00:11:26Z"}
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-22T21:55:37Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-23T00:11:26Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  Newest first, ISO dates.
4
4
 
5
- ## 2026-11-22
5
+ ## 2026-11-23
6
6
 
7
7
  - Adopted OKF v0.2 (D73).
@@ -1,4 +1,54 @@
1
1
  [
2
+ {
3
+ "v": "0.719.0",
4
+ "at": "2026-11-23T00:11:29.887Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1594,
9
+ "t": "Meeting test stand-in answers the week the page asks for",
10
+ "s": "Meeting test stand-in answers the week the page asks for",
11
+ "k": "fix"
12
+ },
13
+ {
14
+ "n": 1596,
15
+ "t": "Pin a filter as a view beside the product switcher (job #1558)",
16
+ "s": "Pin a filter as a view beside the product switcher (job #1558)",
17
+ "k": "new"
18
+ },
19
+ {
20
+ "n": 1595,
21
+ "t": "Ctrl+K reaches every page, item and action (job #1562)",
22
+ "s": "Ctrl+K reaches every page, item and action (job #1562)",
23
+ "k": "new"
24
+ }
25
+ ]
26
+ },
27
+ {
28
+ "v": "0.718.0",
29
+ "at": "2026-11-22T23:44:48.503Z",
30
+ "f": 4,
31
+ "prs": [
32
+ {
33
+ "n": 1589,
34
+ "t": "Search answers first, with its source",
35
+ "s": "Search answers first, with its source",
36
+ "k": "new"
37
+ },
38
+ {
39
+ "n": 1592,
40
+ "t": "Pmos why, the three-line why of any initiative or task",
41
+ "s": "Pmos why, the three-line why of any initiative or task",
42
+ "k": "new"
43
+ },
44
+ {
45
+ "n": 1590,
46
+ "t": "One health score per product, shown only when it drops",
47
+ "s": "One health score per product, shown only when it drops",
48
+ "k": "new"
49
+ }
50
+ ]
51
+ },
2
52
  {
3
53
  "v": "0.717.0",
4
54
  "at": "2026-11-22T21:55:40.797Z",
@@ -18,14 +18,19 @@ function world(now = new Date()) {
18
18
  const RAIL = new Date(minute + 30 * 60000), RAIL_END = new Date(RAIL.getTime() + 30 * 60000);
19
19
  const LIVE = new Date(Math.max(mid.getTime(), minute - 12 * 60000)), LIVE_END = new Date(LIVE.getTime() + 30 * 60000);
20
20
  const lvl = { kind: 'initiative', id: 'viewer', ws: 'w1', name: 'Viewer' };
21
- const week = () => {
21
+ // the week that holds `date` ('YYYY-MM-DD', as the page asks for it), like the real route: late on a Sunday "Rail review" (now + 30 min) falls
22
+ // in next week, and the page asks for that week by date. Answering this week instead left the meeting without its calendar row.
23
+ const week = (date) => {
24
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date || '');
25
+ const wk = m ? new Date(+m[1], +m[2] - 1, +m[3]) : new Date(mon);
26
+ if (m) wk.setDate(wk.getDate() - ((wk.getDay() + 6) % 7));
22
27
  const cells = [];
23
- for (let i = 0; i < 7; i++) { const d = new Date(mon.getFullYear(), mon.getMonth(), mon.getDate() + i); cells.push({ key: dayKey(d), start: dayKey(d), end: dayKey(d), events: [] }); }
28
+ for (let i = 0; i < 7; i++) { const d = new Date(wk.getFullYear(), wk.getMonth(), wk.getDate() + i); cells.push({ key: dayKey(d), start: dayKey(d), end: dayKey(d), events: [] }); }
24
29
  const cell = (d) => cells.find((c) => c.key === dayKey(d));
25
- cell(SYNC).events.push({ id: 'ev-sync', at: iso(SYNC), end: iso(SYNC_END), title: 'Viewer sync', attendees: ['Ana', 'Dita', 'Wawan'], series: 'viewer-sync' });
30
+ if (cell(SYNC)) cell(SYNC).events.push({ id: 'ev-sync', at: iso(SYNC), end: iso(SYNC_END), title: 'Viewer sync', attendees: ['Ana', 'Dita', 'Wawan'], series: 'viewer-sync' });
26
31
  if (cell(RAIL)) cell(RAIL).events.push({ id: 'ev-rail', at: iso(RAIL), end: iso(RAIL_END), title: 'Rail review', attendees: ['Sam', 'Wawan'] });
27
32
  if (cell(LIVE)) cell(LIVE).events.push({ id: 'ev-live', at: iso(LIVE), end: iso(LIVE_END), title: 'Design crit', attendees: ['Ana', 'Wawan'] });
28
- for (let i = 0; i < 5; i++) { const d = new Date(mon.getFullYear(), mon.getMonth(), mon.getDate() + i, 15, 0); if (dayKey(d) !== dayKey(mid)) cell(d).events.push({ id: 'ev-1on1-' + i, at: iso(d), end: iso(new Date(d.getTime() + 30 * 60000)), title: '1:1 with Dita', attendees: ['Dita'] }); }
33
+ for (let i = 0; i < 5; i++) { const d = new Date(wk.getFullYear(), wk.getMonth(), wk.getDate() + i, 15, 0); if (dayKey(d) !== dayKey(mid)) cell(d).events.push({ id: 'ev-1on1-' + i, at: iso(d), end: iso(new Date(d.getTime() + 30 * 60000)), title: '1:1 with Dita', attendees: ['Dita'] }); }
29
34
  return { ok: true, view: 'week', range: { start: cells[0].key, end: cells[6].key }, cells, events_source: 'calendar-memory', today: dayKey(now), context: { 'ev-sync': { level: lvl }, 'ev-rail': { level: lvl } }, link_boards: [{ id: 'b1', ws: 'w1', name: 'Growth' }], gantt: [] };
30
35
  };
31
36
  const NOTE = {
@@ -73,7 +78,7 @@ function install(page, o = {}) {
73
78
  if (S.scene === 'prep' || o.noLive) delete S.store.n2;
74
79
  const notesRows = () => S.rows;
75
80
  return Promise.all([
76
- page.route('**/api/calendar-views*', (r) => json(r, W.week())),
81
+ page.route('**/api/calendar-views*', (r) => { const u = new URL(r.request().url()).searchParams; return json(r, W.week(u.get('view') === 'week' ? u.get('date') : '')); }),
77
82
  page.route(/\/api\/notes(\?.*)?$/, (r) => (r.request().method() === 'GET' ? json(r, { ok: true, notes: notesRows(), series_open: { 'viewer-sync': { open: 2, carried: true } } }) : json(r, { ok: true }))),
78
83
  page.route('**/api/notes/one*', (r) => {
79
84
  const id = new URL(r.request().url()).searchParams.get('id'), n = S.store[id];
@@ -212,6 +212,12 @@ Before you share a spec, a strategy, a roadmap or a report, PMOS reads it as a s
212
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
213
  - A change that cites no source never applies by itself. It waits for you, as a change others see does.
214
214
 
215
+ ### pmos health: one health score for this product
216
+
217
+ - `pmos health score` shows this product's health score from 0 to 100 and its three parts: checks (the passing share of the latest runs of your product's own checks), pull requests stuck on failing checks, and setbacks this week (reverts, fixes after a merge, failed checks, missed outcomes). The score is on the last line. When nothing is recorded yet, it says so and prints -1.
218
+ - `pmos health trend` shows the score of each day this month. `pmos health drops` shows each past drop and how many days it took to recover.
219
+ - Today shows a card only when the score falls 10 points or more below the best of the past week. While the score holds, there is no card.
220
+
215
221
  ### pmos autonomy: what agents applied by themselves
216
222
 
217
223
  - `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.
@@ -272,6 +278,14 @@ The idle lab run uses only the first three commands:
272
278
  - `pmos lab critic checks [--root <dir>]`: the checks the critic uses for the product in that folder. No server is needed.
273
279
  - `pmos lab critic label <run> <n> real|noise`: your word on finding `n` of a critic run. `pmos lab critic stats` counts the runs, the findings, and how many you called real or noise.
274
280
 
281
+ ### pmos why: why the work exists, in three lines
282
+
283
+ Anyone can run it, not only the PM: an engineer or a stakeholder who wants to know why an initiative or a task exists. Run it in the product's repository, or pass `--root <dir>`. It reads the records on disk, needs no running workspace and changes nothing.
284
+
285
+ - `pmos why <initiative or task>` prints the goal, the problem and the evidence, one line each. A task id (`<initiative>.<10 characters>`) shows the why of its initiative. `pmos why show <id>` does the same. Add `--from` to see the file and section each line came from.
286
+ - Each line comes from the initiative's own record or its PRD: the goal from Goal, the problem from Intent or the PRD's Problem, the evidence from an Evidence section or the first problem sentence that names a number or a link. A line the records do not hold says "not written". PMOS does not guess it.
287
+ - `pmos why coverage` says how many active initiatives have all three lines and which lines the others miss. Its last line is the percent, so a script can read it.
288
+
275
289
  ### pmos outcomes: expected outcomes
276
290
 
277
291
  Run them in the product's repository, or pass `--root <dir>`.
@@ -174,7 +174,7 @@ Some features, such as Notes, open as a plain card in the Viewer. Each one works
174
174
  ## Search, Guide and Settings
175
175
 
176
176
  - **Guide** (the **?** icon in the menu) opens this guide in the Viewer.
177
- - **Search** (Ctrl K or ⌘K, or `/`) finds initiatives, documents, sessions and files in your work. It always reads the repository and all its worktrees, so it has no worktree picker.
177
+ - **Search** (Ctrl K or ⌘K, or `/`) finds initiatives, documents, sessions and files in your work. It always reads the repository and all its worktrees, so it has no worktree picker. It also reaches every page, each Settings section, the themes and the actions of the item you last pointed at: type "lib" to go to Library, or "conn" for Settings › Connectors.
178
178
  - **Dates** show the year only when the year is not this year, for example "Jun 23 ’27". New for you shows a due date as "due 25 Nov".
179
179
  - **Settings** holds the workspace settings. **General** holds the theme (Light, Dark or Auto) and **Product**, which names the product the page reads. **Connectors** shows when PMOS last read each source. A source that is old or failed has an amber dot and ↻ to read it again. ↻ in the Connectors header reads every source again. While a source is old, an amber box at the top of Settings names it, with ↻.
180
180
 
@@ -2,7 +2,7 @@
2
2
  type: Guide
3
3
  title: "Layout and first run: the places, the navigation, the Viewer, the launcher and Adler"
4
4
  description: "The places, the navigation at the left, the Viewer, the keys and the phone; the first run; when features appear; the PMOS app; and Adler."
5
- timestamp: 2026-11-22
5
+ timestamp: 2026-11-23
6
6
  ---
7
7
 
8
8
  # Layout and first run
@@ -100,6 +100,8 @@ On a computer, Work is built from the parts of the PMOS design system. The top l
100
100
  - **Initiatives.** A table with the columns you choose (the tune icon also sorts and filters). Press a column heading to sort by it. The timeline shows done in green, now in blue and planned in grey, with a red line for today. A milestone is a diamond on its initiative's row; a late one is red. Milestones less than 8 days apart are one numbered diamond: point at it to see them. Pick the scale with **Week**, **Month**, **Quarter**, **Year** or **Full**. Move the timeline with the arrows, with a sideways swipe on a trackpad, or by dragging it; the middle arrow goes back to today. A late date has a red badge, for example "8 days late". Closed initiatives fold into one line at the end.
101
101
  - **Next milestones.** The next ten milestones of all initiatives on one line, each with its date, its name and its initiative. The line has its own time range, apart from the table: it starts at today (or at a milestone that became late in the last 30 days) and ends at the last of the ten, so they all show across the full width without scrolling. Labels never cover each other: a label that is too close moves down a row, and a label near the right end reads to the left of its diamond. Scroll sideways on the line (or drag it) to move only the line. A milestone outside the line is in a **+N** mark at the end: press it to move the line there. After the line moves, the button at the top right puts it back at today. Press a diamond to open the milestone.
102
102
 
103
+ **Pinned views.** When a filter is on, the line "Showing …" over the table has a pin button. Press it to keep the filter as a view, named by what it shows (for example "Blocked · Acme, Globex"). Pinned views sit after the products at the top. Press one to open it: it replaces the filter that is on. Point at a view and press × to unpin it, with **Undo**. When you use the same filter a third time, PMOS suggests pinning it: ✓ pins it, ✕ means PMOS does not suggest that filter again. Pinned views follow you to your other browsers, as your other view choices do.
104
+
103
105
  **Backlog** is the open work outside the sprint, in one rank across initiatives.
104
106
 
105
107
  - **Where it stands.** A few lines: how many items wait, how many are ready to pull into the next sprint and from which initiatives, how many have not changed in 60 days, and how many have no initiative. An item is ready when it has an initiative and an owner, is not started, and PMOS is not working on it. Under it, PMOS suggests pulling the top ready items into the next sprint. ✓ gives the PMOS tasks the next sprint's dates (with Undo) and lists the Jira tickets for you to add in Jira, because PMOS does not change Jira. The pencil ticks the items on the **Ready** tab so you can change the pick first, and ✕ says not now.
@@ -263,11 +265,15 @@ Reports are routine jobs, so they live in Routine.
263
265
 
264
266
  The Board shows initiatives by stage, with programs, a timeline and a list. Intelligence shows the goals from each product's OKR file. A panel on either page (an initiative, a program, a goal, the chat) can dock on the left or the right: drag its header to that half of the window, or press **Arrange** in its header. Each kind of panel stays on its side after a reload. [Programs on the Board](programs.md) and [Intelligence reads your OKR file](intelligence-okr-goals.md) explain them.
265
267
 
268
+ ## Search answers first
269
+
270
+ When the words you type in Search point clearly to one thing, the first row is the answer: one sentence from your own files, then where it came from. Type an initiative's name and the answer is its goal, with its check date. Ask "when is the pilot launch" and the answer is the sentence in your plan that holds the date. Press Enter on the answer to open its source. PMOS copies the sentence as it is written and does not write it. When no one sentence holds all your words, or two initiatives match equally, there is no answer row, and the matches show as before.
271
+
266
272
  ## Keys
267
273
 
268
274
  | Key | What it does |
269
275
  |---|---|
270
- | ⌘K (Ctrl-K) or / | Open Search from any page. A second press focuses the box. |
276
+ | ⌘K (Ctrl-K) or / | Open Search from any page. A second press focuses the box. Search also reaches pages (**Go to**), Settings sections, themes, the Guide and the calendar (**Do**), and the actions of the item you last pointed at (**On this item**): type "sprint" to move that item to the next sprint. |
271
277
  | Esc | Close Search or the menu, then the Viewer. |
272
278
  | ↑ ↓ and Enter | Move through Search results and open one. |
273
279
  | Y | Say yes to what PMOS proposes on the item you point at. |
@@ -0,0 +1,235 @@
1
+ 'use strict';
2
+ /* item-why.js — "Why are we building this?" in three lines, for anyone (initiative three-line-why, bet A86).
3
+ *
4
+ * whyOf({ id, front, body, prd, recordPath, prdPath }) → { id, title, goal, problem, evidence, complete }
5
+ * each line is { text, from } | null. `from` names the file and the section the line was read from.
6
+ * frontOf(text) · sectionsOf(text) the record's frontmatter as { key: value }; its `## ` sections as Map title → text
7
+ * initiativeIdOf(ref) → id a task id `<initiative>.<10 characters>` reads as its initiative
8
+ * recordPathOf(root, id) → path | null planning/initiatives/<id>.md, else pmos/state/initiatives/<id>.md (kit layout)
9
+ * readWhy(root, ref) → why | null reads the record and the PRD it names, from disk
10
+ * activeIds(root) → [id] every record that is not closed, cancelled or accepted (lifecycle.jsonl, acceptances.jsonl)
11
+ * coverage(root) → { active, complete, percent, missing: [{ id, lines: ['goal'|'problem'|'evidence'] }] }
12
+ *
13
+ * THE LINES, in the order each is tried. A line the records do not hold is null: nothing is made up from the title.
14
+ * goal : the record's Goal · the PRD's Goal or Goals · `outcome_metric`
15
+ * problem : the record's Intent · the PRD's Problem · a "Why it exists", "Why this exists" or "The defect" section
16
+ * evidence : an Evidence, "Why it exists", "Why this exists" or "The finding" section of the record, else of the PRD · else the first
17
+ * sentence of the problem's own text that holds a number or a link (the record names what it saw)
18
+ * Each line is the first one or two sentences, markdown taken off, at most MAX characters, one line.
19
+ *
20
+ * Reads only. No server, no network, no writes. Works on PMOS-self and on any product in kit layout.
21
+ */
22
+ const fs = require('fs');
23
+ const path = require('path');
24
+
25
+ const MAX = 200;
26
+ const LAYOUTS = [['planning', 'initiatives'], ['pmos', 'state', 'initiatives']];
27
+ const LEDGER_DIRS = [['planning', 'runs'], ['pmos', 'state']];
28
+ const TASK_ID = /^([A-Za-z0-9][A-Za-z0-9._-]*)\.[A-Za-z0-9_-]{10}$/;
29
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/;
30
+ const STOPPED = new Set(['closed', 'cancelled', 'canceled', 'killed']);
31
+
32
+ const unquote = (v) => {
33
+ const t = String(v == null ? '' : v).trim();
34
+ if (/^".*"$/.test(t)) return t.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
35
+ if (/^'.*'$/.test(t)) return t.slice(1, -1).replace(/''/g, "'");
36
+ return t;
37
+ };
38
+
39
+ /** The leading frontmatter as { key: value } (one line per key; quotes taken off). */
40
+ function frontOf(text) {
41
+ const L = String(text || '').split('\n'); const out = {};
42
+ if (!/^---\s*$/.test(L[0] || '')) return out;
43
+ for (let i = 1; i < L.length && !/^---\s*$/.test(L[i]); i++) {
44
+ const m = L[i].match(/^([A-Za-z_][\w-]*):\s*(.*)$/); if (m) out[m[1]] = unquote(m[2]);
45
+ }
46
+ return out;
47
+ }
48
+
49
+ /** The body after the frontmatter. */
50
+ function bodyOf(text) {
51
+ const s = String(text || '');
52
+ const m = s.match(/^---\s*\n[\s\S]*?\n---\s*(\n|$)/);
53
+ return m ? s.slice(m[0].length) : s;
54
+ }
55
+
56
+ /** Every `## ` section as Map lower-case title (numbering such as "2." taken off) → its text. The first of a title wins. */
57
+ function sectionsOf(text) {
58
+ const out = new Map(); let title = null; let buf = [];
59
+ const flush = () => { if (title !== null && !out.has(title)) out.set(title, buf.join('\n').trim()); };
60
+ for (const line of bodyOf(text).split('\n')) {
61
+ const m = line.match(/^##\s+(.+?)\s*$/);
62
+ if (m && !/^###/.test(line)) { flush(); title = m[1].replace(/^[\d.]+\s*/, '').trim().toLowerCase(); buf = []; }
63
+ else if (title !== null) buf.push(line);
64
+ }
65
+ flush();
66
+ return out;
67
+ }
68
+
69
+ /** Markdown taken off: links keep their text, bold, italics, code marks, list bullets, quotes and table pipes go. */
70
+ function plain(s) {
71
+ return String(s || '')
72
+ .replace(/<!--[\s\S]*?-->/g, ' ')
73
+ .replace(/!\[[^\]]*\]\([^)]*\)/g, ' ')
74
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
75
+ .replace(/`+([^`]*)`+/g, '$1')
76
+ .replace(/(\*\*|__)(.+?)\1/g, '$2')
77
+ .replace(/(^|[\s(])[*_]([^*_\s][^*_]*?)[*_](?=[\s).,;:!?]|$)/g, '$1$2')
78
+ .replace(/^\s{0,3}(?:[-*+]|\d+\.)\s+/gm, '')
79
+ .replace(/^\s*>\s?/gm, '')
80
+ .replace(/^\s*\|.*\|\s*$/gm, ' ')
81
+ .replace(/^#+\s+/gm, '')
82
+ .replace(/\s+/g, ' ')
83
+ .trim();
84
+ }
85
+
86
+ /** The sentences of a text (a period, question or exclamation mark followed by a space and a capital, digit or quote). */
87
+ function sentences(s) {
88
+ return String(s || '').split(/(?<=[.!?])\s+(?=[A-Z0-9"'(“])/).map((x) => x.trim()).filter(Boolean);
89
+ }
90
+
91
+ /** One line of at most MAX characters: the first sentence, and the second when both fit; cut on a word with an ellipsis. */
92
+ function clip(text) {
93
+ const all = sentences(plain(text));
94
+ if (!all.length) return '';
95
+ let out = all[0];
96
+ if (all[1] && out.length + 1 + all[1].length <= MAX) out = `${out} ${all[1]}`;
97
+ if (out.length > MAX) { const cut = out.slice(0, MAX - 1); const sp = cut.lastIndexOf(' '); out = `${(sp > MAX * 0.6 ? cut.slice(0, sp) : cut).replace(/[\s,;:–—-]+$/, '')}…`; }
98
+ return out;
99
+ }
100
+
101
+ const SEEN = /\d|https?:\/\/|\]\(|#\d+|\bPR\b|\bissue\b/;
102
+ /** The first sentence of a text that names what was seen: a number, a link or a PR. */
103
+ function evidenceSentence(raw) {
104
+ // Links are read from the raw text (plain() keeps only their words), then the sentence itself from the plain text.
105
+ for (const para of String(raw || '').split(/\n\s*\n/)) {
106
+ for (const s of sentences(plain(para))) if (SEEN.test(s) || (/\]\(/.test(para) && s.length > 20)) return s;
107
+ }
108
+ return null;
109
+ }
110
+
111
+ const line = (text, file, section) => (text ? { text: clip(text), from: section ? `${file} › ${section}` : file } : null);
112
+
113
+ /** The first section of `secs` whose title is in `names` and holds text: { name, text } | null. */
114
+ function pick(secs, names) {
115
+ for (const n of names) { const t = secs && secs.get(n); if (t && plain(t)) return { name: n, text: t }; }
116
+ return null;
117
+ }
118
+ const cap = (n) => n.charAt(0).toUpperCase() + n.slice(1);
119
+
120
+ /**
121
+ * The three lines of one initiative. `body` and `prd` are whole file texts (frontmatter allowed); `front` defaults to the body's.
122
+ */
123
+ function whyOf({ id, front, body, prd, recordPath, prdPath } = {}) {
124
+ const fm = front || frontOf(body);
125
+ const rec = sectionsOf(body);
126
+ const doc = prd ? sectionsOf(prd) : new Map();
127
+ const recFile = recordPath || 'record';
128
+ const prdFile = prdPath || 'PRD';
129
+
130
+ let goal = null;
131
+ const g1 = pick(rec, ['goal']);
132
+ const g2 = !g1 && pick(doc, ['goal', 'goals']);
133
+ if (g1) goal = line(g1.text, recFile, 'Goal');
134
+ else if (g2) goal = line(g2.text, prdFile, cap(g2.name));
135
+ else if (fm.outcome_metric) goal = line(fm.outcome_metric, recFile, 'outcome_metric');
136
+
137
+ let problem = null; let problemRaw = null; let problemFrom = null;
138
+ const p1 = pick(rec, ['intent']);
139
+ const p2 = !p1 && pick(doc, ['problem']);
140
+ const p3 = !p1 && !p2 && pick(rec, ['problem', 'why it exists', 'why this exists', 'the defect']);
141
+ if (p1) { problemRaw = p1.text; problemFrom = [recFile, 'Intent']; }
142
+ else if (p2) { problemRaw = p2.text; problemFrom = [prdFile, 'Problem']; }
143
+ else if (p3) { problemRaw = p3.text; problemFrom = [recFile, cap(p3.name)]; }
144
+ if (problemRaw) problem = line(problemRaw, ...problemFrom);
145
+
146
+ let evidence = null;
147
+ const EV = ['evidence', 'why it exists', 'why this exists', 'the finding'];
148
+ const e1 = pick(rec, EV.filter((n) => !(p3 && p3.name === n)));
149
+ const e2 = !e1 && pick(doc, ['evidence']);
150
+ if (e1) evidence = line(e1.text, recFile, cap(e1.name));
151
+ else if (e2) evidence = line(e2.text, prdFile, 'Evidence');
152
+ else if (problemRaw) { const s = evidenceSentence(problemRaw); if (s) evidence = line(s, ...problemFrom); }
153
+
154
+ return {
155
+ id: id || fm.id || null,
156
+ title: fm.title || null,
157
+ goal, problem, evidence,
158
+ complete: !!(goal && problem && evidence),
159
+ };
160
+ }
161
+
162
+ /** A task id `<initiative>.<10 characters>` reads as its initiative; anything else is the id itself. */
163
+ function initiativeIdOf(ref) {
164
+ const s = String(ref || '').trim();
165
+ const m = s.match(TASK_ID);
166
+ return m ? m[1] : s;
167
+ }
168
+
169
+ function recordPathOf(root, id) {
170
+ if (!ID_RE.test(String(id || ''))) return null;
171
+ for (const parts of LAYOUTS) { const f = path.join(root, ...parts, `${id}.md`); if (fs.existsSync(f)) return f; }
172
+ return null;
173
+ }
174
+
175
+ const readText = (f) => { try { return fs.readFileSync(f, 'utf8'); } catch { return null; } };
176
+ const rel = (root, f) => path.relative(root, f).split(path.sep).join('/');
177
+
178
+ /** The why of an initiative or a task, read from disk; null when there is no record. */
179
+ function readWhy(root, ref) {
180
+ let id = String(ref || '').trim();
181
+ let f = recordPathOf(root, id);
182
+ if (!f) { id = initiativeIdOf(id); f = recordPathOf(root, id); }
183
+ if (!f) return null;
184
+ const body = readText(f) || '';
185
+ const fm = frontOf(body);
186
+ let prd = null; let prdPath = null;
187
+ if (fm.prd_path && !/^(n\/a|na|none|-)$/i.test(fm.prd_path)) {
188
+ const p = String(fm.prd_path).replace(/^\/+/, '');
189
+ for (const base of [root, path.join(root, 'pmos')]) { const t = readText(path.join(base, p)); if (t != null) { prd = t; prdPath = p; break; } }
190
+ }
191
+ return whyOf({ id, front: fm, body, prd, recordPath: rel(root, f), prdPath });
192
+ }
193
+
194
+ function readJsonl(f) {
195
+ const t = readText(f); if (!t) return [];
196
+ const out = [];
197
+ for (const l of t.split('\n')) { if (!l.trim()) continue; try { out.push(JSON.parse(l)); } catch { /* a torn line is skipped */ } }
198
+ return out;
199
+ }
200
+
201
+ /** Every record id that is not closed, cancelled or accepted: the newest lifecycle line decides, an accepted line ends it. */
202
+ function activeIds(root) {
203
+ const ids = new Set();
204
+ for (const parts of LAYOUTS) {
205
+ let names = []; try { names = fs.readdirSync(path.join(root, ...parts)); } catch { continue; }
206
+ for (const n of names) if (n.endsWith('.md') && n !== 'README.md' && n !== 'index.md' && n !== 'log.md') ids.add(n.slice(0, -3));
207
+ }
208
+ const state = new Map();
209
+ for (const parts of LEDGER_DIRS) {
210
+ for (const r of readJsonl(path.join(root, ...parts, 'lifecycle.jsonl'))) {
211
+ if (!r || typeof r.initiative_id !== 'string') continue;
212
+ const prev = state.get(r.initiative_id);
213
+ if (!prev || String(r.at || '') >= String(prev.at || '')) state.set(r.initiative_id, { state: String(r.state || ''), at: r.at });
214
+ }
215
+ }
216
+ const accepted = new Set();
217
+ for (const parts of LEDGER_DIRS) {
218
+ for (const r of readJsonl(path.join(root, ...parts, 'acceptances.jsonl'))) if (r && typeof r.initiative_id === 'string' && r.accepted !== false) accepted.add(r.initiative_id);
219
+ }
220
+ return [...ids].filter((id) => !accepted.has(id) && !STOPPED.has((state.get(id) || {}).state)).sort();
221
+ }
222
+
223
+ /** The share of active initiatives whose why reads all three lines. */
224
+ function coverage(root) {
225
+ const ids = activeIds(root);
226
+ const missing = []; let complete = 0;
227
+ for (const id of ids) {
228
+ const w = readWhy(root, id);
229
+ if (w && w.complete) { complete++; continue; }
230
+ missing.push({ id, lines: w ? ['goal', 'problem', 'evidence'].filter((k) => !w[k]) : ['goal', 'problem', 'evidence'] });
231
+ }
232
+ return { active: ids.length, complete, percent: ids.length ? Math.round((complete / ids.length) * 100) : 0, missing };
233
+ }
234
+
235
+ module.exports = { MAX, whyOf, frontOf, sectionsOf, plain, clip, initiativeIdOf, recordPathOf, readWhy, activeIds, coverage };
@@ -40,6 +40,7 @@ const PROVIDERS = Object.freeze([
40
40
  'factory-needs', // factory-builder-inner-loop: a work item blocked after the Builder's CI-fix rounds, with the reason (kind 8)
41
41
  'decision-journal-needs', // decision-journal-outcome-checks: a journal decision whose check date came, with no verdict (kind 1)
42
42
  'parked-reasons', // parked-reason-way-back (bet A446): a parked initiative whose way back is met, to bring back (kind 7)
43
+ 'product-health', // product-health-score: a product's health score fell 10 points or more against its past week (kind 8)
43
44
  ]);
44
45
  /** Kinds that already mean something in the needs queue. A provider may not reuse one. */
45
46
  const RESERVED_KINDS = Object.freeze(['question', 'accept', 'outcome', 'keep', 'evidence', 'plan-flag', 'provider-error']);
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* pinned-views.js — the health number of pinned filter views (bet A395, initiative pinned-filter-views; the page side is
4
+ * public/pm/pinned-views.js). A pinned view's chip is a button whose first data attribute is data-pvw, so the local use log
5
+ * (lib/use-log.js, bet A466) notes each open. Nothing here writes anything.
6
+ *
7
+ * opens(lines, now) → n PURE. Presses of a pinned view (control data-pvw) in the use log, last 14 days.
8
+ * CLI: node lib/pinned-views.js count → opens of the last 14 days on its last line (the health number); other lines say [pinned-views] */
9
+ const OPEN_DAYS = 14;
10
+ const CONTROL = 'data-pvw';
11
+
12
+ function opens(lines, now = Date.now()) {
13
+ const cut = now - OPEN_DAYS * 864e5;
14
+ return (lines || []).filter((l) => l && l.kind === 'use' && l.control === CONTROL && Date.parse(l.at) >= cut && Date.parse(l.at) <= now + 864e5).length;
15
+ }
16
+
17
+ module.exports = { OPEN_DAYS, CONTROL, opens };
18
+
19
+ if (require.main === module) {
20
+ if (process.argv[2] !== 'count') { console.error('usage: node lib/pinned-views.js count (opens of a pinned view in the last ' + OPEN_DAYS + ' days)'); process.exit(2); }
21
+ const UL = require('./use-log.js');
22
+ const dir = require('./state-root.js').defaultRoot({ env: process.env });
23
+ const lines = UL.readLines(dir);
24
+ console.log(`[pinned-views] ${lines.length} use-log lines in ${dir}`);
25
+ console.log(String(opens(lines)));
26
+ }
@@ -133,6 +133,9 @@ const VERBS = Object.freeze({
133
133
  // Not a pm-os-absorb verb (run: null): initiative page-fix-count-first (bet A462) added it through the same table.
134
134
  pages: Object.freeze({ module: 'pages-cli.js', run: null, guide: 'cli.md',
135
135
  help: 'pmos pages [show|check] — each page\'s fixes, reverts and restores in the last 14 days, and a feature change that adds to a page that keeps breaking (pmos pages help)' }),
136
+ // Not a pm-os-absorb verb (run: null): initiative three-line-why (bet A86) added it through the same table.
137
+ why: Object.freeze({ module: 'why-cli.js', run: null, guide: 'cli.md',
138
+ help: 'pmos why <initiative or task> | coverage — why the work exists in three lines: goal, problem, evidence, read from its records (pmos why help)' }),
136
139
  // Not a pm-os-absorb verb (run: null): initiative outcome-for-every-initiative added it through the same table.
137
140
  outcomes: Object.freeze({ module: 'outcomes-cli.js', run: null, guide: 'cli.md',
138
141
  help: 'pmos outcomes list|propose|declare|record|live — every initiative\'s expected outcome and check date: Claude\'s cited drafts, the PM\'s yes, the verdict when a check is due, and the version a place runs (pmos outcomes help)' }),
@@ -150,6 +153,8 @@ const VERBS = Object.freeze({
150
153
  driver: Object.freeze({ module: 'driver-cli.js', run: null, guide: 'cli.md',
151
154
  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)' }),
152
155
  // one-change-record-no-source-no-auto: everything PMOS changed by itself, in one record (lib/change-record.js)
156
+ health: Object.freeze({ module: 'product-health-cli.js', run: null, guide: 'cli.md',
157
+ help: 'pmos health [score|trend|drops] — this product\'s health score (0 to 100), its trend this month and its past drops (pmos health help)' }),
153
158
  factory: Object.freeze({ module: 'factory-cli.js', run: null, guide: 'cli.md',
154
159
  help: 'pmos factory today [--days N] — everything PMOS changed by itself, per line and station, with what cites no source (pmos factory help)' }),
155
160
  // D106 (Full autonomy now): what agents do by themselves, and the goals they work on until done
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+ /* product-health-cli.js — `pmos health`: this product's health score, its trend and its past drops (initiative product-health-score).
3
+ * The work is in lib/product-health.js; this file is the verb's entry in lib/pmos-verbs.js. Read-only except the day's score line. */
4
+ const PH = require('./product-health.js');
5
+
6
+ const COMMANDS = { health: ['score', 'trend', 'drops'] };
7
+ const USAGE = PH.USAGE;
8
+ function run(argv, { say = (s) => console.log(s) } = {}) {
9
+ const args = argv[0] === 'health' ? argv.slice(1) : argv.slice();
10
+ return PH.cli(args, { say });
11
+ }
12
+
13
+ module.exports = { COMMANDS, USAGE, run };