create-pmos 0.717.0 → 0.718.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +26 -20
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +25 -0
- package/workspace/guide/cli.md +14 -0
- package/workspace/guide/layout.md +4 -0
- package/workspace/lib/item-why.js +235 -0
- package/workspace/lib/needs-providers.js +1 -0
- package/workspace/lib/pmos-verbs.js +5 -0
- package/workspace/lib/product-health-cli.js +13 -0
- package/workspace/lib/product-health.js +259 -0
- package/workspace/lib/routes-search.js +4 -2
- package/workspace/lib/search-answer.js +164 -0
- package/workspace/lib/why-cli.js +79 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-search.js +18 -2
- package/workspace/test-lists/item-why.json +9 -0
- package/workspace/test-lists/product-health.json +9 -0
- 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.
|
|
3
|
+
"version": "0.718.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,31 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.718.0",
|
|
38
|
+
"at": "2026-11-22T23:44:48.503Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1589,
|
|
43
|
+
"t": "Search answers first, with its source",
|
|
44
|
+
"s": "Search answers first, with its source",
|
|
45
|
+
"k": "new"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"n": 1592,
|
|
49
|
+
"t": "Pmos why, the three-line why of any initiative or task",
|
|
50
|
+
"s": "Pmos why, the three-line why of any initiative or task",
|
|
51
|
+
"k": "new"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"n": 1590,
|
|
55
|
+
"t": "One health score per product, shown only when it drops",
|
|
56
|
+
"s": "One health score per product, shown only when it drops",
|
|
57
|
+
"k": "new"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
},
|
|
36
61
|
{
|
|
37
62
|
"v": "0.717.0",
|
|
38
63
|
"at": "2026-11-22T21:55:40.797Z",
|
|
@@ -459,25 +484,6 @@
|
|
|
459
484
|
"k": "new"
|
|
460
485
|
}
|
|
461
486
|
]
|
|
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
487
|
}
|
|
482
488
|
]
|
|
483
489
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T23:44:43Z"}
|
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T23:44:43Z"}
|
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T23:44:43Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.718.0",
|
|
4
|
+
"at": "2026-11-22T23:44:48.503Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1589,
|
|
9
|
+
"t": "Search answers first, with its source",
|
|
10
|
+
"s": "Search answers first, with its source",
|
|
11
|
+
"k": "new"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"n": 1592,
|
|
15
|
+
"t": "Pmos why, the three-line why of any initiative or task",
|
|
16
|
+
"s": "Pmos why, the three-line why of any initiative or task",
|
|
17
|
+
"k": "new"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"n": 1590,
|
|
21
|
+
"t": "One health score per product, shown only when it drops",
|
|
22
|
+
"s": "One health score per product, shown only when it drops",
|
|
23
|
+
"k": "new"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
2
27
|
{
|
|
3
28
|
"v": "0.717.0",
|
|
4
29
|
"at": "2026-11-22T21:55:40.797Z",
|
package/workspace/guide/cli.md
CHANGED
|
@@ -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>`.
|
|
@@ -263,6 +263,10 @@ Reports are routine jobs, so they live in Routine.
|
|
|
263
263
|
|
|
264
264
|
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
265
|
|
|
266
|
+
## Search answers first
|
|
267
|
+
|
|
268
|
+
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.
|
|
269
|
+
|
|
266
270
|
## Keys
|
|
267
271
|
|
|
268
272
|
| Key | What it does |
|
|
@@ -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']);
|
|
@@ -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 };
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* product-health.js — one health score per product, with its trend over the month, shown only when it drops
|
|
3
|
+
* (initiative product-health-score, bet A166).
|
|
4
|
+
*
|
|
5
|
+
* partsOf(root, { now }) → { checks, ci, setbacks } each { value 0..100, detail } or null (no data)
|
|
6
|
+
* scoreOf(parts) → 0..100 | null weighted mean of the parts that have data
|
|
7
|
+
* record(root, { now, parts }) → { day, score, parts, written } at most one line per day per score
|
|
8
|
+
* historyOf(root) → [{ day, score, parts }] the last line of each day, oldest first
|
|
9
|
+
* trendOf(history, { now, days }) → [{ day, score }] the month's points
|
|
10
|
+
* dropOf(history, { now }) → { from, to, since, fell: [part] } | null
|
|
11
|
+
* drops(history) → { drops: [{ day, from, to, recovered_day, recovery_days }], median_recovery_days }
|
|
12
|
+
* kinds · rowsFor(w, { lead }) · sig(w) the needs provider (lib/needs-providers.js)
|
|
13
|
+
*
|
|
14
|
+
* node workspace/lib/product-health.js score|trend|drops [<root>] [--json]
|
|
15
|
+
*
|
|
16
|
+
* THE PARTS, read from the product's state folder (lib/driver.js stateDirOf), so the score works on any product:
|
|
17
|
+
* checks factory-checks.jsonl the product's own declared checks (test, lint, audit…) that PMOS ran: the passing share
|
|
18
|
+
* of the newest CHECK_RUNS runs in MONTH_DAYS days
|
|
19
|
+
* ci factory-ci.jsonl 100 less CI_COST per pull request whose newest CI step in MONTH_DAYS days is blocked
|
|
20
|
+
* setbacks improve-signals.jsonl 100 less SETBACK_COST per setback signal in WEEK_DAYS days (see SETBACKS)
|
|
21
|
+
* A part with no data is null and the score is the weighted mean of the others. With no part at all the score is null:
|
|
22
|
+
* "not enough to tell" is the honest state, never 100.
|
|
23
|
+
*
|
|
24
|
+
* THE HISTORY is <state>/product-health.jsonl, one line { v: 1, day, at, score, parts } when the day's score changes.
|
|
25
|
+
* A DROP is a score DROP_POINTS or more under the highest score of the previous WEEK_DAYS days. A low score that has
|
|
26
|
+
* held for longer than that is the product's new level, not a drop. Today shows a drop as one card (kind 8); a score that
|
|
27
|
+
* holds shows nothing (zero is silence). */
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
const path = require('path');
|
|
30
|
+
|
|
31
|
+
const NAME = 'product-health';
|
|
32
|
+
const KIND = 'health-drop';
|
|
33
|
+
const LEDGER = 'product-health.jsonl';
|
|
34
|
+
const DAY = 86400000;
|
|
35
|
+
const WEEK_DAYS = 7;
|
|
36
|
+
const MONTH_DAYS = 30;
|
|
37
|
+
const CHECK_RUNS = 10;
|
|
38
|
+
const CI_COST = 25;
|
|
39
|
+
const SETBACK_COST = 15;
|
|
40
|
+
const DROP_POINTS = 10;
|
|
41
|
+
const RECOVER_POINTS = 5;
|
|
42
|
+
const WEIGHTS = Object.freeze({ checks: 40, setbacks: 35, ci: 25 });
|
|
43
|
+
const LABEL = Object.freeze({ checks: 'Checks', setbacks: 'Setbacks', ci: 'Pull requests' });
|
|
44
|
+
const SETBACKS = Object.freeze(['revert', 'fix-after-merge', 'ci-fail', 'verifier-fail', 'factory-setback', 'outcome-missed', 'release-check-fail', 'undo']);
|
|
45
|
+
const STUCK = new Set(['blocked', 'block-failed']);
|
|
46
|
+
const TAG = '[product-health]';
|
|
47
|
+
|
|
48
|
+
const dayOf = (t) => new Date(t).toISOString().slice(0, 10);
|
|
49
|
+
const ms = (s) => { const n = Date.parse(s); return Number.isFinite(n) ? n : null; };
|
|
50
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
51
|
+
function stateDir(root) { try { return require('./driver.js').stateDirOf(root); } catch { return null; } }
|
|
52
|
+
function jsonl(file) {
|
|
53
|
+
let t = '';
|
|
54
|
+
try { t = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
55
|
+
return t.split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
|
56
|
+
}
|
|
57
|
+
const within = (rows, now, days) => rows.filter((r) => { const t = ms(r.at); return t !== null && t <= now && now - t <= days * DAY; });
|
|
58
|
+
|
|
59
|
+
// ── the parts ────────────────────────────────────────────────────────────────────────────────────────────
|
|
60
|
+
function checksPart(rows, now) {
|
|
61
|
+
const runs = within(rows, now, MONTH_DAYS).sort((a, b) => ms(b.at) - ms(a.at)).slice(0, CHECK_RUNS);
|
|
62
|
+
if (!runs.length) return null;
|
|
63
|
+
const ok = runs.filter((r) => r.ok === true).length;
|
|
64
|
+
return { value: Math.round((100 * ok) / runs.length), detail: `${ok} of ${plural(runs.length, 'check run', 'check runs')} passed` };
|
|
65
|
+
}
|
|
66
|
+
function ciPart(rows, now) {
|
|
67
|
+
const recent = within(rows, now, MONTH_DAYS);
|
|
68
|
+
if (!recent.length) return null;
|
|
69
|
+
const last = new Map();
|
|
70
|
+
for (const r of recent.sort((a, b) => ms(a.at) - ms(b.at))) if (r.item) last.set(r.item, r);
|
|
71
|
+
const stuck = [...last.values()].filter((r) => STUCK.has(r.step)).length;
|
|
72
|
+
return { value: Math.max(0, 100 - CI_COST * stuck), detail: stuck ? `${plural(stuck, 'pull request', 'pull requests')} stuck on failing checks` : 'no pull request stuck' };
|
|
73
|
+
}
|
|
74
|
+
function setbacksPart(rows, now) {
|
|
75
|
+
if (!rows.length) return null;
|
|
76
|
+
const n = within(rows, now, WEEK_DAYS).filter((r) => SETBACKS.includes(r.kind)).length;
|
|
77
|
+
return { value: Math.max(0, 100 - SETBACK_COST * n), detail: n ? `${plural(n, 'setback', 'setbacks')} this week` : 'no setback this week' };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** → { checks, ci, setbacks }: each { value, detail } or null. `now` defaults to the clock. */
|
|
81
|
+
function partsOf(root, { now = Date.now() } = {}) {
|
|
82
|
+
const sd = stateDir(root);
|
|
83
|
+
if (!sd) return { checks: null, ci: null, setbacks: null };
|
|
84
|
+
return {
|
|
85
|
+
checks: checksPart(jsonl(path.join(sd, 'factory-checks.jsonl')), now),
|
|
86
|
+
ci: ciPart(jsonl(path.join(sd, 'factory-ci.jsonl')), now),
|
|
87
|
+
setbacks: setbacksPart(jsonl(path.join(sd, 'improve-signals.jsonl')), now),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function scoreOf(parts) {
|
|
92
|
+
let sum = 0, wsum = 0;
|
|
93
|
+
for (const [k, w] of Object.entries(WEIGHTS)) {
|
|
94
|
+
const p = parts && parts[k];
|
|
95
|
+
if (!p || !Number.isFinite(p.value)) continue;
|
|
96
|
+
sum += w * p.value; wsum += w;
|
|
97
|
+
}
|
|
98
|
+
return wsum ? Math.round(sum / wsum) : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ── the history ──────────────────────────────────────────────────────────────────────────────────────────
|
|
102
|
+
function historyOf(root) {
|
|
103
|
+
const sd = stateDir(root);
|
|
104
|
+
if (!sd) return [];
|
|
105
|
+
const byDay = new Map();
|
|
106
|
+
for (const l of jsonl(path.join(sd, LEDGER))) if (/^\d{4}-\d{2}-\d{2}$/.test(l.day) && Number.isFinite(l.score)) byDay.set(l.day, { day: l.day, score: l.score, parts: l.parts || {} });
|
|
107
|
+
return [...byDay.values()].sort((a, b) => (a.day < b.day ? -1 : 1));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Keep today's score: one line when the day's score changes. A null score writes nothing. */
|
|
111
|
+
function record(root, { now = Date.now(), parts = null, log = (s) => console.log(s) } = {}) {
|
|
112
|
+
const p = parts || partsOf(root, { now });
|
|
113
|
+
const score = scoreOf(p);
|
|
114
|
+
const day = dayOf(now);
|
|
115
|
+
const out = { day, score, parts: p, written: false };
|
|
116
|
+
if (score === null) return out;
|
|
117
|
+
const hist = historyOf(root);
|
|
118
|
+
const last = hist[hist.length - 1];
|
|
119
|
+
if (last && last.day === day && last.score === score) return out;
|
|
120
|
+
const sd = stateDir(root);
|
|
121
|
+
if (!sd) return out;
|
|
122
|
+
const flat = {};
|
|
123
|
+
for (const k of Object.keys(WEIGHTS)) flat[k] = p[k] ? p[k].value : null;
|
|
124
|
+
try { fs.appendFileSync(path.join(sd, LEDGER), JSON.stringify({ v: 1, day, at: new Date(now).toISOString(), score, parts: flat }) + '\n'); }
|
|
125
|
+
catch { return out; }
|
|
126
|
+
out.written = true;
|
|
127
|
+
const prev = last ? ` (was ${last.score} on ${last.day})` : '';
|
|
128
|
+
try { log(`${TAG} ${path.basename(path.resolve(root))} scored ${score} on ${day}${prev}`); } catch { /* a log line never fails the record */ }
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function trendOf(history, { now = Date.now(), days = MONTH_DAYS } = {}) {
|
|
133
|
+
const from = dayOf(now - days * DAY);
|
|
134
|
+
return (history || []).filter((h) => h.day > from && h.day <= dayOf(now)).map((h) => ({ day: h.day, score: h.score }));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The best score of the WEEK_DAYS days before `day`, from `history`, or null. */
|
|
138
|
+
function baselineBefore(history, day) {
|
|
139
|
+
const t = ms(day + 'T00:00:00Z');
|
|
140
|
+
const from = dayOf(t - WEEK_DAYS * DAY);
|
|
141
|
+
let best = null;
|
|
142
|
+
for (const h of history) if (h.day >= from && h.day < day && (!best || h.score > best.score)) best = h;
|
|
143
|
+
return best;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Today's drop against the past week, or null. `history` includes today's line when it was recorded. */
|
|
147
|
+
function dropOf(history, { now = Date.now() } = {}) {
|
|
148
|
+
const day = dayOf(now);
|
|
149
|
+
const hist = history || [];
|
|
150
|
+
const today = hist.find((h) => h.day === day);
|
|
151
|
+
if (!today) return null;
|
|
152
|
+
const base = baselineBefore(hist, day);
|
|
153
|
+
if (!base || base.score - today.score < DROP_POINTS) return null;
|
|
154
|
+
const fell = Object.keys(WEIGHTS).filter((k) => {
|
|
155
|
+
const a = base.parts && base.parts[k], b = today.parts && today.parts[k];
|
|
156
|
+
return Number.isFinite(a) && Number.isFinite(b) ? b < a : Number.isFinite(b) && b < 100 && !Number.isFinite(a);
|
|
157
|
+
});
|
|
158
|
+
return { from: base.score, to: today.score, since: base.day, fell };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Every past drop (the first day of each) and the days it took to come back within RECOVER_POINTS of where it fell from. */
|
|
162
|
+
function drops(history) {
|
|
163
|
+
const hist = history || [];
|
|
164
|
+
const out = [];
|
|
165
|
+
let open = null;
|
|
166
|
+
for (const h of hist) {
|
|
167
|
+
if (open) {
|
|
168
|
+
if (h.score >= open.from - RECOVER_POINTS) {
|
|
169
|
+
open.recovered_day = h.day;
|
|
170
|
+
open.recovery_days = Math.round((ms(h.day + 'T00:00:00Z') - ms(open.day + 'T00:00:00Z')) / DAY);
|
|
171
|
+
open = null;
|
|
172
|
+
}
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const base = baselineBefore(hist, h.day);
|
|
176
|
+
if (base && base.score - h.score >= DROP_POINTS) { open = { day: h.day, from: base.score, to: h.score, recovered_day: null, recovery_days: null }; out.push(open); }
|
|
177
|
+
}
|
|
178
|
+
const done = out.filter((d) => d.recovery_days !== null).map((d) => d.recovery_days).sort((a, b) => a - b);
|
|
179
|
+
const median = !done.length ? null : done.length % 2 ? done[(done.length - 1) / 2] : (done[done.length / 2 - 1] + done[done.length / 2]) / 2;
|
|
180
|
+
return { drops: out, median_recovery_days: median };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// ── the needs provider ───────────────────────────────────────────────────────────────────────────────────
|
|
184
|
+
const short = (day) => new Date(day + 'T00:00:00Z').toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' });
|
|
185
|
+
function stamp(file) { try { const s = fs.statSync(file); return `${s.mtimeMs}:${s.size}`; } catch { return '-'; } }
|
|
186
|
+
function sig(w) {
|
|
187
|
+
const sd = w && w.root ? stateDir(w.root) : null;
|
|
188
|
+
if (!sd) return '';
|
|
189
|
+
return [dayOf(Date.now()), ...['factory-checks.jsonl', 'factory-ci.jsonl', 'improve-signals.jsonl', LEDGER].map((f) => stamp(path.join(sd, f)))].join('|');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function rowsFor(w, { lead, now = Date.now(), log } = {}) {
|
|
193
|
+
if (!lead || !w || !w.root) return [];
|
|
194
|
+
const rec = record(w.root, { now, ...(log ? { log } : {}) });
|
|
195
|
+
if (rec.score === null) return [];
|
|
196
|
+
const d = dropOf(historyOf(w.root), { now });
|
|
197
|
+
if (!d) return [];
|
|
198
|
+
const name = w.name || path.basename(path.resolve(w.root));
|
|
199
|
+
const cause = `Health of ${name} fell from ${d.from} to ${d.to} since ${short(d.since)}`;
|
|
200
|
+
const evidence = (d.fell.length ? d.fell : Object.keys(WEIGHTS)).filter((k) => rec.parts[k]).map((k) => `${LABEL[k]}: ${rec.parts[k].detail}`).join(' · ');
|
|
201
|
+
return [{
|
|
202
|
+
run_id: `${NAME}:${w.id}:${dayOf(now)}`, kind: KIND, initiative_id: null, question: cause, doc: null, ws: w.id,
|
|
203
|
+
today: { kind: 8, source: NAME, cause, evidence, act: { label: 'See the health trend', cli: 'pmos health trend' } },
|
|
204
|
+
}];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ── the command line ─────────────────────────────────────────────────────────────────────────────────────
|
|
208
|
+
const USAGE = [
|
|
209
|
+
'usage: pmos health [score|trend|drops] [--json] [--root <dir>] — this product\'s health score (0 to 100)',
|
|
210
|
+
' pmos health score today\'s score and its parts; the score on the last line (-1: not enough to tell)',
|
|
211
|
+
' pmos health trend the score of each day this month',
|
|
212
|
+
' pmos health drops each past drop and the days it took to recover, with the median',
|
|
213
|
+
];
|
|
214
|
+
function cli(argv, { say = (s) => console.log(s), cwd = process.cwd(), now = Date.now() } = {}) {
|
|
215
|
+
const args = argv.slice();
|
|
216
|
+
const json = args.includes('--json');
|
|
217
|
+
const ri = args.indexOf('--root');
|
|
218
|
+
let root = null;
|
|
219
|
+
if (ri >= 0) { root = args[ri + 1]; args.splice(ri, 2); }
|
|
220
|
+
const pos = args.filter((a) => !a.startsWith('--'));
|
|
221
|
+
const verb = pos[0] || 'score';
|
|
222
|
+
if (['help', '-h'].includes(verb) || args.includes('--help')) { for (const l of USAGE) say(l); return 0; }
|
|
223
|
+
if (!['score', 'trend', 'drops'].includes(verb)) { say(`unknown health command "${verb}" — one of score, trend, drops`); return 2; }
|
|
224
|
+
root = path.resolve(cwd, root || pos[1] || '.');
|
|
225
|
+
if (!stateDir(root)) { say(`${TAG} this repository has no PMOS state folder (pmos/state, state or .pmos)`); if (verb === 'score') say('-1'); return 1; }
|
|
226
|
+
const rec = record(root, { now, log: () => {} });
|
|
227
|
+
const hist = historyOf(root);
|
|
228
|
+
if (verb === 'score') {
|
|
229
|
+
if (json) { say(JSON.stringify({ day: rec.day, score: rec.score, parts: rec.parts, drop: dropOf(hist, { now }) })); return 0; }
|
|
230
|
+
if (rec.score === null) say(`${TAG} not enough to tell: no check runs, pull request checks or setbacks recorded yet`);
|
|
231
|
+
else for (const k of Object.keys(WEIGHTS)) if (rec.parts[k]) say(`${TAG} ${LABEL[k]}: ${rec.parts[k].value} (${rec.parts[k].detail})`);
|
|
232
|
+
const d = dropOf(hist, { now });
|
|
233
|
+
if (d) say(`${TAG} fell from ${d.from} to ${d.to} since ${short(d.since)}`);
|
|
234
|
+
say(String(rec.score === null ? -1 : rec.score));
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
if (verb === 'trend') {
|
|
238
|
+
const t = trendOf(hist, { now });
|
|
239
|
+
if (json) { say(JSON.stringify({ trend: t })); return 0; }
|
|
240
|
+
if (!t.length) say(`${TAG} no score recorded this month`);
|
|
241
|
+
for (const p of t) say(`${TAG} ${p.day} ${String(p.score).padStart(3)}`);
|
|
242
|
+
say(String(t.length));
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
const r = drops(hist);
|
|
246
|
+
if (json) { say(JSON.stringify(r)); return 0; }
|
|
247
|
+
if (!r.drops.length) say(`${TAG} no drop recorded`);
|
|
248
|
+
for (const d of r.drops) say(`${TAG} ${d.day} ${d.from} → ${d.to} ${d.recovery_days === null ? 'not recovered yet' : `recovered in ${plural(d.recovery_days, 'day', 'days')}`}`);
|
|
249
|
+
say(String(r.median_recovery_days === null ? -1 : r.median_recovery_days));
|
|
250
|
+
return 0;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
module.exports = {
|
|
254
|
+
NAME, KIND, LEDGER, WEIGHTS, SETBACKS, DROP_POINTS, WEEK_DAYS, MONTH_DAYS, USAGE,
|
|
255
|
+
partsOf, scoreOf, record, historyOf, trendOf, dropOf, drops, cli,
|
|
256
|
+
kinds: [KIND], rowsFor, sig,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
if (require.main === module) process.exitCode = cli(process.argv.slice(2));
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* routes-search.js — Search across the repository and every worktree (initiative premium-uncovered-features, E1; lib/search-index.js).
|
|
3
3
|
*
|
|
4
|
-
* GET /api/find?q=<words>&ws=<id>&wt=<id,id> → { ok, q, worktrees, counts, results, more } wt: the worktrees to search (none: all)
|
|
4
|
+
* GET /api/find?q=<words>&ws=<id>&wt=<id,id> → { ok, q, worktrees, counts, results, more, answer? } wt: the worktrees to search (none: all)
|
|
5
|
+
* answer: one sentence from the user's own files with its source (lib/search-answer.js); absent when nothing is clear
|
|
5
6
|
* GET /api/find/file?ws=<id>&wt=<id>&path=<p> → { ok, wt, branch, main, path, text, mtime } one file of a listed worktree, for the Viewer
|
|
6
7
|
*
|
|
7
8
|
* Read-only: nothing here writes or calls anything outside this machine. The repository is the workspace's own (ws, else the home one). */
|
|
8
9
|
const Search = require('./search-index.js');
|
|
10
|
+
const Answer = require('./search-answer.js'); // the answer first, with its source (search-answers-first)
|
|
9
11
|
|
|
10
12
|
function wsOf(ctx, id) {
|
|
11
13
|
const w = typeof ctx.getWs === 'function' ? ctx.getWs(id || '') : null;
|
|
@@ -29,7 +31,7 @@ module.exports = {
|
|
|
29
31
|
try { const l = ctx.runtimeDir ? require('./notes.js').list(ctx.runtimeDir) : null; notes = l && l.ok ? l.notes : []; } catch { notes = []; }
|
|
30
32
|
const only = (url.searchParams.get('wt') || '').split(',').map((x) => x.trim()).filter(Boolean);
|
|
31
33
|
try {
|
|
32
|
-
ctx.json(res, { ws: w.id, ...
|
|
34
|
+
ctx.json(res, { ws: w.id, ...Answer.find({ root: w.root, q: url.searchParams.get('q') || '', only, notes }) });
|
|
33
35
|
} catch (e) {
|
|
34
36
|
ctx.json(res, { ok: false, error: 'the search could not run: ' + String((e && e.message) || e).slice(0, 160) }, 500);
|
|
35
37
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* search-answer.js — Search answers first (initiative search-answers-first, bet A388; done test planning/done-tests/search-answers-first.md).
|
|
3
|
+
*
|
|
4
|
+
* keyWords(q) → the query's words without question words ("when is the pilot launch" → ['pilot', 'launch']) PURE
|
|
5
|
+
* searchWords(q) → keyWords joined by spaces: what Search looks for when the whole question finds nothing PURE
|
|
6
|
+
* answerOf({ root, q, results }) → { text, facts, source: { kind, title, path, wt, main, id? } } | null READ-ONLY
|
|
7
|
+
* find({ root, q, only, notes, now }) → lib/search-index.js search() plus `answer` READ-ONLY
|
|
8
|
+
* probe(root) → the health number: the percent of initiatives whose own name gets an answer from their own record
|
|
9
|
+
* CLI: node lib/search-answer.js --probe <root> prints that number on its last line
|
|
10
|
+
*
|
|
11
|
+
* The answer is never written: it is one sentence copied word for word from the user's own files, so it says where it came from and
|
|
12
|
+
* cannot be wrong about it. An initiative whose name holds every key word answers with its Goal's first sentence and its check date. Else
|
|
13
|
+
* the first sentence, in the best matches, that holds every key word ("when" prefers a sentence with a date). A worktree's draft answers
|
|
14
|
+
* only when main has none. Nothing clear (no sentence holds every word, or two initiatives match equally well) gives no answer: zero is
|
|
15
|
+
* silence. No model call, nothing written, nothing sent. Works on any product built with PMOS (planning/initiatives/ or pmos/state/initiatives/). */
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const Search = require('./search-index.js');
|
|
19
|
+
|
|
20
|
+
const STOP = new Set(('a an the is are was were be been am do does did of to in on at for by with from and or what when where who whom whose which why how '
|
|
21
|
+
+ 'tell me show find give about any there this that these those it its i my our we you your can could should would will shall has have had').split(' '));
|
|
22
|
+
const INI_DIRS = ['planning/initiatives', 'pmos/state/initiatives'];
|
|
23
|
+
const MAX_DOCS = 12;
|
|
24
|
+
const MONTH = '(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*';
|
|
25
|
+
const DATE = new RegExp(`\\b\\d{4}-\\d{2}-\\d{2}\\b|\\b\\d{1,2}(?:st|nd|rd|th)?\\s+${MONTH}\\b|\\b${MONTH}\\s+\\d{1,2}\\b|\\b(?:mon|tues|wednes|thurs|fri|satur|sun)day\\b|\\b(?:today|tomorrow|next week)\\b`, 'i');
|
|
26
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
27
|
+
|
|
28
|
+
const wordsOf = (s) => String(s || '').toLowerCase().split(/[^a-z0-9%]+/).filter(Boolean);
|
|
29
|
+
/** The query's words without question words. A query of only question words keeps all its words. Pure. */
|
|
30
|
+
function keyWords(q) {
|
|
31
|
+
const all = wordsOf(q);
|
|
32
|
+
const keys = all.filter((w) => !STOP.has(w));
|
|
33
|
+
return keys.length ? keys : all;
|
|
34
|
+
}
|
|
35
|
+
const searchWords = (q) => keyWords(q).join(' ');
|
|
36
|
+
const isWhen = (q) => /^\s*(when|what date|what day|by when|how long)\b/i.test(String(q || ''));
|
|
37
|
+
/** Every key word starts a word of s. */
|
|
38
|
+
const holdsAll = (s, keys) => keys.every((k) => new RegExp('(^|[^a-z0-9])' + esc(k), 'i').test(s));
|
|
39
|
+
|
|
40
|
+
const body = (text) => String(text || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
|
|
41
|
+
const fm = (text, key) => { const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(String(text || '')); if (!m) return ''; const v = new RegExp('^' + key + ':\\s*["\']?(.+?)["\']?\\s*$', 'm').exec(m[1]); return v ? v[1].trim() : ''; };
|
|
42
|
+
|
|
43
|
+
/** The answerable sentences of a Markdown text, in order: each is word for word in the text. Headings, tables and code are skipped. */
|
|
44
|
+
function sentences(text) {
|
|
45
|
+
const out = [];
|
|
46
|
+
let code = false;
|
|
47
|
+
for (const raw of body(text).split('\n')) {
|
|
48
|
+
const line = raw.trim();
|
|
49
|
+
if (/^(```|~~~)/.test(line)) { code = !code; continue; }
|
|
50
|
+
if (code || !line || /^#/.test(line) || line.includes('|') || /^<[^>]+>/.test(line)) continue;
|
|
51
|
+
const s = line.replace(/^(?:[-*+>]\s+|\d+[.)]\s+)+/, '').replace(/^\[[ xX]\]\s+/, '');
|
|
52
|
+
for (const part of s.split(/(?<=[.!?])\s+(?=[A-Z0-9"“(])/)) {
|
|
53
|
+
const t = part.trim();
|
|
54
|
+
if (t.length >= 12 && t.length <= 240 && t.split(/\s+/).length >= 4) out.push(t);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
/** The sentence an initiative record answers with: its Goal's first sentence, else its first body sentence. */
|
|
60
|
+
function goalOf(text) {
|
|
61
|
+
const b = body(text);
|
|
62
|
+
const g = /^##\s+Goal\s*$([\s\S]*?)(?=^#{1,2}\s|(?![\s\S]))/im.exec(b);
|
|
63
|
+
return (g && sentences(g[1])[0]) || sentences(b)[0] || '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The initiatives of the main checkout: { id, title, path, text }. A deleted one is left out. */
|
|
67
|
+
function initiativesOf(root) {
|
|
68
|
+
let gone = new Set();
|
|
69
|
+
try { gone = require('./ini-deleted.js').ids(root); } catch { gone = new Set(); }
|
|
70
|
+
const list = [];
|
|
71
|
+
for (const dir of INI_DIRS) {
|
|
72
|
+
let names = [];
|
|
73
|
+
try { names = fs.readdirSync(path.join(root, dir)).filter((f) => f.endsWith('.md') && f !== 'index.md' && f !== 'log.md'); } catch { continue; }
|
|
74
|
+
for (const f of names) {
|
|
75
|
+
const id = f.slice(0, -3);
|
|
76
|
+
if (gone.has(id)) continue;
|
|
77
|
+
let text = '';
|
|
78
|
+
try { text = fs.readFileSync(path.join(root, dir, f), 'utf8'); } catch { continue; }
|
|
79
|
+
list.push({ id, title: Search.titleOf(text, f), path: dir + '/' + f, text });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return list;
|
|
83
|
+
}
|
|
84
|
+
/** An initiative whose name holds every key word: the one with the fewest other words in its name. A tie gives none. */
|
|
85
|
+
function initiativeAnswer(keys, inis) {
|
|
86
|
+
const hits = inis.filter((x) => holdsAll(x.title + ' ' + x.id.replace(/[-_]/g, ' '), keys))
|
|
87
|
+
.map((x) => ({ x, extra: wordsOf(x.title).filter((w) => !keys.includes(w) && !STOP.has(w)).length }))
|
|
88
|
+
.sort((a, b) => a.extra - b.extra);
|
|
89
|
+
if (!hits.length || (hits[1] && hits[1].extra === hits[0].extra)) return null;
|
|
90
|
+
const { x } = hits[0];
|
|
91
|
+
const text = goalOf(x.text);
|
|
92
|
+
if (!text) return null;
|
|
93
|
+
const when = fm(x.text, 'outcome_horizon');
|
|
94
|
+
return { text, facts: /^\d{4}-\d{2}-\d{2}$/.test(when) ? [{ key: 'check', date: when }] : [], source: { kind: 'initiative', title: x.title, path: x.path, wt: 'main', main: true, id: x.id } };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** One answer for q from the search's results, or null when nothing is clear. Reads files inside the repository's worktrees only. */
|
|
98
|
+
function answerOf({ root, q, results = [], inis = null } = {}) {
|
|
99
|
+
const keys = keyWords(q);
|
|
100
|
+
if (!root || String(q || '').trim().length < 2 || !keys.length) return null;
|
|
101
|
+
const ini = initiativeAnswer(keys, inis || initiativesOf(root));
|
|
102
|
+
if (ini) return ini;
|
|
103
|
+
const wts = new Map(Search.worktrees(root).map((w) => [w.id, w]));
|
|
104
|
+
const docs = (results || []).filter((r) => r && r.path && /\.(md|mdx|txt)$/i.test(r.path) && ['document', 'report', 'initiative'].includes(r.kind));
|
|
105
|
+
const ordered = docs.filter((r) => r.main).concat(docs.filter((r) => !r.main)).slice(0, MAX_DOCS);
|
|
106
|
+
const when = isWhen(q);
|
|
107
|
+
let best = null;
|
|
108
|
+
for (const r of ordered) {
|
|
109
|
+
if (best && r.main === false && best.r.main) break; // a draft answers only when main has none
|
|
110
|
+
const w = wts.get(r.wt || 'main'); if (!w) continue;
|
|
111
|
+
const abs = path.resolve(w.path, r.path);
|
|
112
|
+
if (!abs.startsWith(path.resolve(w.path) + path.sep)) continue;
|
|
113
|
+
let text = '';
|
|
114
|
+
try { const st = fs.statSync(abs); if (!st.isFile() || st.size > 256 * 1024) continue; text = fs.readFileSync(abs, 'utf8'); } catch { continue; }
|
|
115
|
+
for (const s of sentences(text)) {
|
|
116
|
+
if (!holdsAll(s, keys)) continue;
|
|
117
|
+
const score = (when && DATE.test(s) ? 2 : 0) + (r.why === 'name' ? 1 : 0);
|
|
118
|
+
if (!best || score > best.score) best = { r, s, score };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!best) return null;
|
|
122
|
+
const { r, s } = best;
|
|
123
|
+
const source = { kind: r.kind, title: r.title, path: r.path, wt: r.wt || 'main', main: r.main !== false };
|
|
124
|
+
if (r.kind === 'initiative' && r.id) source.id = r.id;
|
|
125
|
+
if (r.branch) source.branch = r.branch;
|
|
126
|
+
return { text: s, facts: [], source };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Search, then the answer. A question that finds nothing as a whole string is searched again by its key words, then by its longest one. */
|
|
130
|
+
function find({ root, q, only = null, notes = [], now } = {}) {
|
|
131
|
+
let res = Search.search({ root, q, only, notes, now });
|
|
132
|
+
const keys = keyWords(q);
|
|
133
|
+
if (res.ok && !res.results.length && String(q || '').trim().length >= 2) {
|
|
134
|
+
for (const alt of [keys.join(' '), keys.slice().sort((a, b) => b.length - a.length)[0] || '']) {
|
|
135
|
+
if (alt.length < 2 || alt === res.q) continue;
|
|
136
|
+
const r2 = Search.search({ root, q: alt, only, notes, now });
|
|
137
|
+
if (r2.ok && r2.results.length) { res = { ...r2, q: res.q, by: alt }; break; }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!res.ok) return res;
|
|
141
|
+
let answer = null;
|
|
142
|
+
try { answer = answerOf({ root, q, results: res.results }); } catch { answer = null; }
|
|
143
|
+
try { console.log(answer ? '[search-answer] given kind=' + answer.source.kind : '[search-answer] none'); } catch { /* no console */ }
|
|
144
|
+
return answer ? { ...res, answer } : res;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The health number: of the initiatives, the percent whose own name, typed into Search, is answered from their own record. */
|
|
148
|
+
function probe(root) {
|
|
149
|
+
const inis = initiativesOf(root);
|
|
150
|
+
if (!inis.length) return 0;
|
|
151
|
+
let hit = 0;
|
|
152
|
+
for (const x of inis) { const a = initiativeAnswer(keyWords(x.title), inis); if (a && a.source.id === x.id) hit++; }
|
|
153
|
+
return Math.round((100 * hit) / inis.length);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = { keyWords, searchWords, sentences, goalOf, initiativesOf, answerOf, find, probe };
|
|
157
|
+
|
|
158
|
+
if (require.main === module) {
|
|
159
|
+
const i = process.argv.indexOf('--probe');
|
|
160
|
+
if (i < 0) { console.error('usage: node lib/search-answer.js --probe <root>'); process.exit(2); }
|
|
161
|
+
const root = path.resolve(process.argv[i + 1] || '.');
|
|
162
|
+
const n = probe(root);
|
|
163
|
+
console.log(`initiatives answered from their own record when their name is searched (percent):\n${n}`);
|
|
164
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* why-cli.js — `pmos why …`: why an initiative or a task exists, in three lines anyone can read (initiative three-line-why, bet A86).
|
|
3
|
+
*
|
|
4
|
+
* pmos why <initiative or task> the goal, the problem and the evidence, each with where it was read
|
|
5
|
+
* pmos why show <initiative or task> the same
|
|
6
|
+
* pmos why coverage the share of active initiatives whose why reads all three lines; the last line is the number
|
|
7
|
+
* every command: [--json] [--root <dir>]
|
|
8
|
+
*
|
|
9
|
+
* Reads the record and its PRD from disk through lib/item-why.js. Needs no server, writes nothing, uses no network.
|
|
10
|
+
* Exit codes: 0 done, 1 no such initiative, 2 usage.
|
|
11
|
+
*/
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { execFileSync } = require('child_process');
|
|
14
|
+
const why = require('./item-why.js');
|
|
15
|
+
|
|
16
|
+
const TAG = '[item-why]';
|
|
17
|
+
const COMMANDS = { why: ['show', 'coverage'] };
|
|
18
|
+
const USAGE = [
|
|
19
|
+
'usage: pmos why <initiative or task> — why the work exists: its goal, problem and evidence in three lines',
|
|
20
|
+
' pmos why <id> the three lines for an initiative, or for the initiative a task belongs to',
|
|
21
|
+
' pmos why show <id> the same',
|
|
22
|
+
' pmos why coverage how many active initiatives have all three lines, and which lines the others miss',
|
|
23
|
+
' every command: [--json] [--root <dir>]',
|
|
24
|
+
'A line the records do not hold says "not written". Nothing is guessed.',
|
|
25
|
+
];
|
|
26
|
+
const LABEL = { goal: 'Goal', problem: 'Problem', evidence: 'Evidence' };
|
|
27
|
+
|
|
28
|
+
function repoRoot(cwd) {
|
|
29
|
+
try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
|
|
30
|
+
catch { return cwd; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parse(argv) {
|
|
34
|
+
const pos = []; const flags = {};
|
|
35
|
+
for (let i = 0; i < argv.length; i++) {
|
|
36
|
+
const a = argv[i];
|
|
37
|
+
if (a === '--root') flags.root = argv[++i];
|
|
38
|
+
else if (a.startsWith('--root=')) flags.root = a.slice(7);
|
|
39
|
+
else if (a.startsWith('--')) flags[a.slice(2)] = true;
|
|
40
|
+
else if (a === '-h') flags.help = true;
|
|
41
|
+
else pos.push(a);
|
|
42
|
+
}
|
|
43
|
+
return { pos, flags };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function run(argv, { say = (s) => console.log(s), cwd = process.cwd() } = {}) {
|
|
47
|
+
const { pos, flags } = parse(argv[0] === 'why' ? argv.slice(1) : argv.slice());
|
|
48
|
+
if (flags.help || pos[0] === 'help') { for (const l of USAGE) say(l); return 0; }
|
|
49
|
+
const root = path.resolve(flags.root || repoRoot(cwd));
|
|
50
|
+
const json = !!flags.json;
|
|
51
|
+
|
|
52
|
+
if (pos[0] === 'coverage' || flags.coverage) {
|
|
53
|
+
const c = why.coverage(root);
|
|
54
|
+
if (json) { say(JSON.stringify(c)); return 0; }
|
|
55
|
+
say(`${TAG} ${c.complete} of ${c.active} active initiatives have a three-line why (goal, problem, evidence).`);
|
|
56
|
+
for (const m of c.missing.slice(0, 20)) say(` ${m.id}: no ${m.lines.join(', ')}`);
|
|
57
|
+
if (c.missing.length > 20) say(` … and ${c.missing.length - 20} more (--json lists them all)`);
|
|
58
|
+
say(String(c.percent));
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ref = pos[0] === 'show' ? pos[1] : pos[0];
|
|
63
|
+
if (!ref) { for (const l of USAGE) say(l); return 2; }
|
|
64
|
+
const w = why.readWhy(root, ref);
|
|
65
|
+
if (!w) {
|
|
66
|
+
say(json ? JSON.stringify({ ok: false, error: `no initiative "${ref}" in this repository` }) : `✗ no initiative "${ref}" in this repository (pmos initiative list shows them)`);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
if (json) { say(JSON.stringify({ ok: true, ...w })); return 0; }
|
|
70
|
+
say(`${w.title || w.id} (${w.id})`);
|
|
71
|
+
for (const k of ['goal', 'problem', 'evidence']) {
|
|
72
|
+
const l = w[k];
|
|
73
|
+
say(`${LABEL[k]}: ${l ? l.text : 'not written'}`);
|
|
74
|
+
if (l && flags.from) say(` from ${l.from}`);
|
|
75
|
+
}
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.718.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.718.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* a page's own find, the U2 scope, keeps its own hits above it):
|
|
7
7
|
* it puts the words in the one chat, over the page you are on (pm/page-chat.js openCos), or in Home's own box on Home. ↑ ↓ move, ↵ opens,
|
|
8
8
|
* Esc closes. On a phone it is the whole screen.
|
|
9
|
+
* Above everything, when the words clearly point to one thing, one answer: a sentence copied from the user's own files, with its source
|
|
10
|
+
* and the check date when it is an initiative (search-answers-first, lib/search-answer.js). ↵ on it opens the source. No answer: no row.
|
|
9
11
|
* openSearch({ go?, q?, scope? }) go: the page's own opener ({ ini } | { ses } | { doc }), used before a page change
|
|
10
12
|
* scope: the page Search opens from (UI grill U2: one search; the Board's and Intelligence's own find boxes are gone). { name, hits(q) }
|
|
11
13
|
* where hits returns [{ label, rows: [{ id?, title, sub?, tag?, icon?, open() }] }]: the page's own groups, drawn first ("On this Board ·
|
|
@@ -140,12 +142,16 @@ function drawList() {
|
|
|
140
142
|
if (ownIds.size) rows = rows.filter((r) => !(r.kind === 'initiative' && ownIds.has(r.id)));
|
|
141
143
|
const groups = own.concat(searchGroups(rows, { phone: isPhone() }));
|
|
142
144
|
const ask = q.length >= 2 ? { kind: 'ask', title: q } : null;
|
|
145
|
+
// search-answers-first: the answer, with its source, is the first row; only for the words it answered and on All
|
|
146
|
+
const A = S.res && S.res.answer && S.kind === 'all' && q.length >= 2 && String(S.res.q || '').trim() === q ? S.res.answer : null;
|
|
147
|
+
const ansRow = A && A.source ? { kind: 'answer', answer: A } : null;
|
|
143
148
|
// chief-of-staff C5: the one chat is the first row of Search; a page's own find (U2 scope) keeps its own hits first, then the chat
|
|
144
149
|
const ownRows = own.flatMap((g) => g.rows);
|
|
145
|
-
S.rows =
|
|
150
|
+
S.rows = (ansRow ? [ansRow] : []).concat(ownRows, ask ? [ask] : [], groups.slice(own.length).flatMap((g) => g.rows));
|
|
146
151
|
S.at = Math.min(S.at, Math.max(0, S.rows.length - 1));
|
|
147
152
|
let h = '', i = 0;
|
|
148
153
|
const askHtml = () => `<button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}">${svg(ICON.chat, 18)}<span class="ev-t">Ask PMOS: <b>“${esc(q)}”</b></span><span class="ev-k">${onHome() ? 'In the chat' : 'Opens the chat here'}</span></button>`;
|
|
154
|
+
if (ansRow && !S.err) { h += answerHtml(ansRow.answer, i); i++; }
|
|
149
155
|
// the page's own groups first (UI grill U2): what Search itself could not read is said after them
|
|
150
156
|
own.forEach((g) => { h += `<p class="ev-mlbl">${esc(g.label)}</p>` + g.rows.map((r) => rowHtml(r, i++)).join(''); });
|
|
151
157
|
if (ask) { h += askHtml(); i++; }
|
|
@@ -154,7 +160,7 @@ function drawList() {
|
|
|
154
160
|
else if (S.err) h += cantRead({ what: 'Search', why: S.err, sources: false });
|
|
155
161
|
else if (S.busy && !rest.length) h += skelRows(3);
|
|
156
162
|
// nothing found: Adler with his magnifier (canvas AdU4); the words stay the same
|
|
157
|
-
else if (!groups.length) h += `<div class="ev-sp-empty ev-sp-ad" role="status">${adler('needs-you', 'l', { label: false, prop: 'magnifier' })}<p>Nothing matches “${esc(q)}”${S.kind !== 'all' ? ' in this kind' : ''}.</p></div>`;
|
|
163
|
+
else if (!groups.length && !ansRow) h += `<div class="ev-sp-empty ev-sp-ad" role="status">${adler('needs-you', 'l', { label: false, prop: 'magnifier' })}<p>Nothing matches “${esc(q)}”${S.kind !== 'all' ? ' in this kind' : ''}.</p></div>`;
|
|
158
164
|
rest.forEach((g, gi) => {
|
|
159
165
|
h += `<p class="ev-mlbl">${esc(g.label)}</p>` + g.rows.map((r) => rowHtml(r, i++)).join('');
|
|
160
166
|
if (gi === 0 && isPhone() && g.key === 'initiative') h += '<div class="ev-sp-chips ev-phchips" aria-hidden="true"></div>';
|
|
@@ -169,6 +175,15 @@ function drawList() {
|
|
|
169
175
|
const r = box.querySelector('[data-ev-retry]'); if (r) r.onclick = () => run();
|
|
170
176
|
const a = box.querySelector('#evo' + S.at); if (a) { S.el.querySelector('#evQ').setAttribute('aria-activedescendant', a.id); a.scrollIntoView({ block: 'nearest' }); }
|
|
171
177
|
}
|
|
178
|
+
/** The answer row: the sentence in full (it wraps), then the check date and where it came from. */
|
|
179
|
+
const dayOf = (iso) => { const d = new Date(String(iso) + 'T00:00:00'); return isNaN(d) ? '' : d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short' }); };
|
|
180
|
+
function answerHtml(a, i) {
|
|
181
|
+
const src = a.source, kind = { initiative: 'initiative', document: 'document', report: 'report', slides: 'slides' }[src.kind] || 'file';
|
|
182
|
+
const facts = (a.facts || []).filter((f) => f.key === 'check' && dayOf(f.date)).map((f) => 'Check ' + dayOf(f.date));
|
|
183
|
+
const from = 'From ' + (src.title || src.path) + ' (' + kind + (src.main === false ? ', draft in ' + (src.branch || src.wt) : '') + ')';
|
|
184
|
+
// the plain wrapper keeps the row as tall as its lines: the list is a flex column and would squeeze the button to its min-height
|
|
185
|
+
return `<div role="none"><button type="button" class="ev-mi${i === S.at ? ' hl' : ''}" role="option" id="evo${i}" data-ev-i="${i}" aria-selected="${i === S.at}" aria-label="${esc(a.text + ' ' + facts.concat(from).join(' · '))}">${svg(KIND_ICON[src.kind] || ICON.doc, 18)}<span><b>${esc(a.text)}</b><br><span class="ev-small ev-mut">${esc(facts.concat(from).join(' · '))}</span></span></button></div>`;
|
|
186
|
+
}
|
|
172
187
|
function draw() { if (!S.el || S.el.hidden) return; drawChips(); drawList(); }
|
|
173
188
|
addEventListener('resize', () => draw());
|
|
174
189
|
|
|
@@ -178,6 +193,7 @@ function homeUrl(params) { const q = new URLSearchParams(params); if (wsParam())
|
|
|
178
193
|
function go(r) {
|
|
179
194
|
closeSearch();
|
|
180
195
|
if (r.kind === 'ask') { askClaude(r.title); return; }
|
|
196
|
+
if (r.kind === 'answer') { const src = r.answer.source; go({ ...src, kind: src.kind || 'document', title: src.title || src.path }); return; }
|
|
181
197
|
if (r.kind === 'scoped') { if (typeof r.open === 'function') r.open(); return; }
|
|
182
198
|
if (r.kind === 'initiative') { if (S.go) { S.go({ ini: r.id }); return; } location.assign(homeUrl(r.board ? { ini: r.id, board: r.board } : { ini: r.id })); return; }
|
|
183
199
|
if (r.kind === 'session') { if (S.go) { S.go({ ses: r.id }); return; } location.assign(homeUrl({ session: r.id })); return; }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "product-health-score: one health score per product from its state ledgers, the daily history, the drop card on Today and pmos health (lib/product-health.js, lib/product-health-cli.js). Temp product folders only.",
|
|
3
|
+
"modules": [
|
|
4
|
+
"product-health.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"product-health.test.js": 1
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Initiative search-answers-first (bet A388): Search shows one answer, with its source, above the matches. The pure answer and the route run in node; the row in pm/cozy-search.js has no browser test (TESTS rule: no new browser tests).",
|
|
3
|
+
"modules": [
|
|
4
|
+
"search-answer.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"search-answer.test.js": 2
|
|
8
|
+
}
|
|
9
|
+
}
|