create-pmos 0.851.0 → 0.853.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 +83 -227
- package/payload/AGENTS.md +64 -0
- 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 +82 -22
- package/workspace/guide/cli.md +20 -0
- package/workspace/guide/initiatives-and-next-steps.md +11 -0
- package/workspace/guide/programs.md +1 -0
- package/workspace/lib/answer-cache.js +15 -8
- package/workspace/lib/features.json +2 -0
- package/workspace/lib/knowledge-cli.js +6 -0
- package/workspace/lib/on-item-routes.js +68 -0
- package/workspace/lib/on-item.js +272 -0
- package/workspace/lib/one-person-knows.js +403 -0
- package/workspace/lib/pmos-verbs.js +6 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-board-premium.js +8 -0
- package/workspace/lib/routes-capture.js +1 -1
- package/workspace/lib/routes-one-person-knows.js +40 -0
- package/workspace/lib/routes-screen-map.js +47 -0
- package/workspace/lib/routes-stage-signoffs.js +4 -1
- package/workspace/lib/screen-map.js +381 -0
- package/workspace/lib/signoffs.js +4 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-discuss-landing-test.js +15 -8
- package/workspace/public/pm/bd-prog-panel.js +25 -1
- package/workspace/public/pm/cozy-board.css +3 -0
- package/workspace/public/pm/cozy-pop-work.js +5 -2
- package/workspace/public/pm/home-app.js +5 -0
- package/workspace/public/pm/on-item.js +155 -0
- package/workspace/public/pm/one-person-knows.js +66 -0
- package/workspace/public/pm/premium-board.js +2 -0
- package/workspace/public/pm/screen-map.css +23 -0
- package/workspace/public/pm/screen-map.js +187 -0
- package/workspace/public/premium-board.html +2 -0
- package/workspace/rename-test.js +5 -1
- package/workspace/run-tests.js +9 -1
- package/workspace/test-lists/kit-agents-verbs.json +9 -0
- package/workspace/test-lists/one-person-knows.json +9 -0
- package/workspace/test-lists/screen-map.json +9 -0
- package/workspace/test-lists/surface-on-item.json +9 -0
|
@@ -151,6 +151,17 @@ When PMOS drafts a document for an initiative, for example a stage's plan that y
|
|
|
151
151
|
|
|
152
152
|
Each issue offers Undo. Issuing marks the draft as the current version. Nothing is sent to anyone. When there are several drafts of one document, only the newest can be issued: it replaces the older ones.
|
|
153
153
|
|
|
154
|
+
### What PMOS can do here shows on the initiative
|
|
155
|
+
|
|
156
|
+
You do not need to know what to ask. When an initiative's own files say it is time, the initiative page shows it in the side column. When nothing applies, nothing shows.
|
|
157
|
+
|
|
158
|
+
- **Sign-offs.** Under Details, each open sign-off says who must say yes and to what. Under it, **Asked before** lists what that person asked or objected to on other work, with where it was said. When the sign-off has no source yet, PMOS shows the lines in the initiative's files that name that person with a yes. Press ✓ on the right one: it becomes the sign-off's source, and Today can then record the sign-off. Undo takes it back.
|
|
159
|
+
- **Can it conclude?** An experiment whose metric is a rate and that has a check date, but no `baseline`, `min_change` or `weekly_traffic`, shows a ✦ line under the Overview. Press ✓: PMOS drafts the three numbers from the records in the background. Press ✓ on the draft to write them into the record, with Undo. Then the Overview says whether it can conclude by the check date.
|
|
160
|
+
- **Press release.** A feature at Plan (or Discovery) with no press release shows a ✦ line. Press ✓: PMOS drafts the press release and FAQ in the background (`pmos press-release <id>`), and it lands in Artefacts. Undo stops it.
|
|
161
|
+
- **Grill.** PMOS grills an initiative that was never grilled by itself, as part of its monthly look, and again before it leaves a stage or when its PRD changes. The Overview says so while it runs, and the findings come under the ✦.
|
|
162
|
+
|
|
163
|
+
Press ✕ on a ✦ line to hide it for that initiative on this computer. The chat and the `pmos` commands do the same things.
|
|
164
|
+
|
|
154
165
|
### Now, Next and Later are retired (D105)
|
|
155
166
|
|
|
156
167
|
Earlier versions put each initiative in one of three horizons: Now, Next and Later. They are retired. Nothing you placed is lost:
|
|
@@ -125,6 +125,7 @@ PMOS suggests milestones for a program and checks them again when something chan
|
|
|
125
125
|
- Press the pencil to open the charter with the change filled in. Change it, then press **Save**.
|
|
126
126
|
- Press **✕** to drop a change. PMOS does not suggest it again unless its source changes.
|
|
127
127
|
- PMOS checks when a program is new, when an initiative joins or leaves, when a ◆ date moves, when a milestone's date comes, and every Monday from 09:00, inside your working hours. When nothing changed, nothing new shows.
|
|
128
|
+
- A program with no milestones and no suggestion yet shows a ✦ line above **Add the first milestone**: "PMOS can draft 3 first milestones from the initiatives' dates." Press ✓ and they show as suggestions with Keep and Decline, with Undo. Press ✕ to hide the line on this computer. The chat and `pmos program draft <id>` do the same.
|
|
128
129
|
- The charter says when PMOS last checked. Press the refresh icon beside it to check now.
|
|
129
130
|
- The review is a background run. It reads the initiatives' records, plan items and meeting notes, and Jira where your Claude Code settings allow it. Its only write is `pmos program suggest`, which files a suggestion for you to keep, change or drop. `PMOS_MS_REVIEW=off` turns the review off.
|
|
130
131
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* warm(url, run, ctx) read this answer in the background, once the server is idle, so its first open is fast too
|
|
14
14
|
* onKept(fn) fn(url, body, ctx) after each fresh answer is kept: route-modules warms what the page opens next from it
|
|
15
15
|
* watch(roots) watch each workspace's records for a write made outside the server (an agent's `pmos` command, an editor)
|
|
16
|
-
* stats() · reset() for the tests
|
|
16
|
+
* stats() · reset() stats() also lists the last drops and what caused each (GET /api/board-premium/cache); reset() for the tests
|
|
17
17
|
*
|
|
18
18
|
* THE RULES
|
|
19
19
|
* - A kept answer is shown only when nothing was written since it was read (GEN). A write the PM makes (any POST, PUT, PATCH or
|
|
@@ -51,6 +51,8 @@ const AGAIN_MAX = 12; // kept answers read again after a write, newest first
|
|
|
51
51
|
const QUEUE_MAX = 40;
|
|
52
52
|
|
|
53
53
|
let GEN = 0;
|
|
54
|
+
const DROPS_MAX = 30;
|
|
55
|
+
const drops = []; // the last DROPS_MAX drops, newest last: { at, why } (GET /api/board-premium/cache), so a cache that keeps nothing says what keeps writing
|
|
54
56
|
// the background read answers nobody: a route that touches `res` itself finds a response that takes nothing
|
|
55
57
|
const DUMMY = { headersSent: false, setHeader() {}, getHeader() {}, writeHead() { return this; }, write() { return true; }, end() {}, on() {} };
|
|
56
58
|
const kept = new Map(); // key → { gen, day, at, body, again } again(): the background read of the same question
|
|
@@ -73,11 +75,12 @@ function bump(method, pathname) {
|
|
|
73
75
|
if (m === 'GET' || m === 'HEAD' || m === 'OPTIONS') return false;
|
|
74
76
|
if (!String(pathname || '').startsWith('/api/')) return false;
|
|
75
77
|
if (QUIET.some((re) => re.test(pathname))) return false;
|
|
76
|
-
return drop();
|
|
78
|
+
return drop(m + ' ' + pathname);
|
|
77
79
|
}
|
|
78
|
-
/** Every kept answer is too old from now on; the newest are read again once the server is idle. */
|
|
79
|
-
function drop() {
|
|
80
|
+
/** Every kept answer is too old from now on; the newest are read again once the server is idle. why: what wrote, for stats(). */
|
|
81
|
+
function drop(why) {
|
|
80
82
|
GEN++; n.bumped++; queue.clear(); ahead.clear();
|
|
83
|
+
drops.push({ at: Date.now(), why: String(why || 'a chat turn ended').slice(0, 200) }); if (drops.length > DROPS_MAX) drops.shift();
|
|
81
84
|
// the newest kept answers are read again once the server is idle; until then a read waits for its own fresh answer
|
|
82
85
|
const last = [...kept.entries()].slice(-AGAIN_MAX).reverse();
|
|
83
86
|
for (const [key, e] of last) if (e.again) queue.set(key, e.again);
|
|
@@ -105,11 +108,15 @@ function watchDir(dir, recursive) {
|
|
|
105
108
|
try {
|
|
106
109
|
const w = fs.watch(dir, { recursive: recursive && !tree, persistent: false }, (ev, f) => {
|
|
107
110
|
if (f && SKIP.test(String(f))) return;
|
|
108
|
-
|
|
111
|
+
// the workspace folder itself is watched only to see planning/ or pmos/ appear: a file beside them (a log the server appends, an
|
|
112
|
+
// editor's swap file) is no record. On the Mac the server's own state folder is a workspace, and its refresh-log.jsonl, appended
|
|
113
|
+
// every 20-30 s, emptied every kept answer (page-open-200ms, measured 2026-11-26)
|
|
114
|
+
if (!recursive && f && f !== 'planning' && f !== 'pmos') return;
|
|
115
|
+
n.outside++; drop('changed: ' + (f ? path.join(dir, String(f)) : dir));
|
|
109
116
|
if (!recursive && (f === 'planning' || f === 'pmos')) watchDir(path.join(dir, f), true);
|
|
110
117
|
else if (tree && f) watchDir(path.join(dir, String(f)), true); // a new sub-folder (a file is not a folder: it is skipped)
|
|
111
118
|
});
|
|
112
|
-
w.on('error', () => { try { w.close(); } catch { /* closed */ } watched.set(dir, 'blind'); blind = true; drop(); });
|
|
119
|
+
w.on('error', () => { try { w.close(); } catch { /* closed */ } watched.set(dir, 'blind'); blind = true; drop('cannot watch ' + dir); });
|
|
113
120
|
watched.set(dir, w);
|
|
114
121
|
} catch { watched.set(dir, 'blind'); blind = true; return; }
|
|
115
122
|
if (tree) {
|
|
@@ -190,7 +197,7 @@ async function serve(req, res, url, ctx, run) {
|
|
|
190
197
|
return true;
|
|
191
198
|
}
|
|
192
199
|
|
|
193
|
-
function stats() { return { ...n, size: kept.size, gen: GEN, queued: queue.size, ahead: ahead.size }; }
|
|
194
|
-
function reset() { for (const w of watched.values()) if (w && typeof w === 'object') { try { w.close(); } catch { /* closed */ } } watched.clear(); blind = false; kept.clear(); queue.clear(); ahead.clear(); GEN = 0; if (timer) clearTimeout(timer); timer = null; busy = false; lastReq = 0; follower = null; for (const k of Object.keys(n)) n[k] = 0; }
|
|
200
|
+
function stats() { return { ...n, size: kept.size, gen: GEN, queued: queue.size, ahead: ahead.size, blind, drops: drops.slice() }; }
|
|
201
|
+
function reset() { for (const w of watched.values()) if (w && typeof w === 'object') { try { w.close(); } catch { /* closed */ } } watched.clear(); blind = false; kept.clear(); queue.clear(); ahead.clear(); GEN = 0; drops.length = 0; if (timer) clearTimeout(timer); timer = null; busy = false; lastReq = 0; follower = null; for (const k of Object.keys(n)) n[k] = 0; }
|
|
195
202
|
|
|
196
203
|
module.exports = { SLOW, QUIET, FRESH_MS, MAX_AGE_MS, IDLE_MS, AHEAD_IDLE_MS, AGAIN_MAX, cacheable, serve, bump, drop, idle, warm, onKept, watch, stats, reset, keyOf };
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
{"id": "try", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "Try what shipped", "say": "The changes your recent updates brought, how to try each, and your answer.", "cmd": "/try", "verb": "try"},
|
|
62
62
|
{"id": "rules", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "Rules PMOS learned", "say": "The standing rules PMOS learned from your corrections, and edit or retire one.", "cmd": "/rules", "verb": "rules"},
|
|
63
63
|
{"id": "line", "audience": "user", "status": "ga", "group": "Catch up", "name": "Where each initiative stands", "say": "Days in its stage, what is missing, the next move, and whether it is stuck.", "cmd": "/line", "verb": "line", "hint": "<initiative>", "ask": ["initiative"]},
|
|
64
|
+
{"id": "knowledge", "audience": "user", "status": "ga", "group": "Your product", "name": "Only one person knows this", "say": "The areas only one person touched in 6 months, and a pairing or write-up before their leave.", "cmd": "/knowledge", "verb": "knowledge"},
|
|
64
65
|
{"id": "hire", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The next hire", "say": "The role your open work most needs, and a one-page role brief to edit.", "cmd": "/hire", "verb": "hire"},
|
|
65
66
|
{"id": "compare", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Compare two items", "say": "Two items or two versions of one file side by side, with the differences marked.", "cmd": "/compare", "verb": "compare", "hint": "<item> <item>", "place": "board"},
|
|
66
67
|
{"id": "experiment", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Copy and layout tests", "say": "Try new words or a new layout on an initiative: PMOS drafts the test, you start it, one line says how sure the winner is.", "cmd": "/experiment", "verb": "experiment", "hint": "draft <initiative> \"<what to try>\""},
|
|
@@ -102,6 +103,7 @@
|
|
|
102
103
|
{"id": "impact", "audience": "agent", "status": "ga", "group": "Your product", "name": "Impact findings", "say": "An impact run files a finding for you to check.", "cmd": "/impact", "verb": "impact"},
|
|
103
104
|
{"id": "coredoc", "audience": "agent", "status": "ga", "group": "Plan and decide", "name": "Core document drafts", "say": "A run writes one draft of a core document; you issue it on the page.", "cmd": "/coredoc", "verb": "coredoc"},
|
|
104
105
|
{"id": "mcp", "audience": "agent", "status": "ga", "group": "Find your way", "name": "PMOS cards for other agents", "say": "PMOS cards for another agent, over MCP.", "cmd": "/mcp-cards", "verb": "mcp"},
|
|
106
|
+
{"id": "screens", "audience": "user", "status": "beta", "group": "Your product", "name": "Screen map", "say": "Every screen of your product and the flows between them, with duplicates, dead ends and deep flows marked.", "cmd": "/screens", "verb": "screens", "sub": "show"},
|
|
105
107
|
{"id": "raid", "audience": "user", "status": "beta", "group": "Catch up", "name": "RAID list", "say": "Risks, assumptions, late tasks and dependencies of one initiative, with owner, next date and what has gone stale.", "cmd": "/raid", "verb": "raid", "hint": "show <initiative>"}
|
|
106
108
|
]
|
|
107
109
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* knowledge-cli.js — `pmos knowledge`: the areas only one person knows (initiative one-person-knows, job #1899, idea A391).
|
|
3
|
+
* The verb module lib/pmos-verbs.js names; the rules, the ledger and the CLI itself are lib/one-person-knows.js. */
|
|
4
|
+
const K = require('./one-person-knows.js');
|
|
5
|
+
|
|
6
|
+
module.exports = { run: K.run, COMMANDS: K.COMMANDS, USAGE: K.USAGE };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* on-item-routes.js — what PMOS can do for the open initiative or program, shown on it with no typed ask (job #1986, surface-on-item;
|
|
3
|
+
* lib/on-item.js).
|
|
4
|
+
*
|
|
5
|
+
* GET /api/on-item?ws=<id>&ini=<id>&stage=<name> → { ok, signoffs, numbers, press } read only
|
|
6
|
+
* POST /api/on-item/evidence { ws, ini, id, ref, quote } | { ws, ini, id, undo: true, before } a picked line becomes the sign-off's source
|
|
7
|
+
* POST /api/on-item/numbers { ws, ini, baseline, min_change, weekly_traffic } | { ws, ini, undo: true, before }
|
|
8
|
+
* POST /api/on-item/press-release { ws, ini } | { ws, ini, undo: true } pmos press-release in the background, or stop it
|
|
9
|
+
* GET /api/on-item/program-drafts?program=<id> → { ok, n } n: PMOS's first milestones for a program with none and no open suggestion
|
|
10
|
+
* POST /api/on-item/program-drafts { program } | { program, undo: true } pmos program draft, or an empty review (none stays open)
|
|
11
|
+
*
|
|
12
|
+
* lib/routes-stage-signoffs.js owns the prefix and hands it here. Every POST is a page press (lib/pm-guard.js requirePagePress). Nothing is sent. */
|
|
13
|
+
const OI = require('./on-item.js');
|
|
14
|
+
|
|
15
|
+
let spawnForTest = null;
|
|
16
|
+
/** Tests stub the press release's background run. */
|
|
17
|
+
function setSpawn(fn) { spawnForTest = fn || null; }
|
|
18
|
+
|
|
19
|
+
async function handle(req, res, url, ctx) {
|
|
20
|
+
const p = url.pathname;
|
|
21
|
+
if (p !== '/api/on-item' && !p.startsWith('/api/on-item/')) return false;
|
|
22
|
+
const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
|
|
23
|
+
let body = {};
|
|
24
|
+
if (req.method === 'POST') {
|
|
25
|
+
const got = await ctx.readJson(req);
|
|
26
|
+
if (!got.ok) return bad('invalid JSON body');
|
|
27
|
+
body = got.body || {};
|
|
28
|
+
const g = require('./pm-guard.js').requirePagePress(req, body);
|
|
29
|
+
if (!g.ok) return bad(g.error, g.status);
|
|
30
|
+
} else if (req.method !== 'GET') return bad('GET or POST only', 405);
|
|
31
|
+
const q = (k) => (req.method === 'POST' ? body[k] : url.searchParams.get(k));
|
|
32
|
+
|
|
33
|
+
if (p === '/api/on-item/program-drafts') {
|
|
34
|
+
const id = String(q('program') || '');
|
|
35
|
+
const prog = (require('./routes-programs.js').all(ctx) || []).find((x) => x.id === id);
|
|
36
|
+
if (!prog) return bad('no such program', 404);
|
|
37
|
+
let w = null; try { w = ctx.getWs(prog.home || null); } catch { w = null; }
|
|
38
|
+
if (!w || !w.root) return bad('the charter of this program is in a product this computer does not have', 404);
|
|
39
|
+
const empty = !(prog.milestones || []).length && !((prog.review && prog.review.open) || []).length;
|
|
40
|
+
if (req.method === 'GET') { ctx.json(res, { ok: true, n: empty ? OI.programDrafts(w.root, id).n : 0 }); return true; }
|
|
41
|
+
if (body.undo === true) { ctx.json(res, OI.undoProgramDrafts(w.root, id)); return true; }
|
|
42
|
+
if (!empty) return bad('this program has milestones or suggestions already');
|
|
43
|
+
const r = OI.fileProgramDrafts(w.root, id);
|
|
44
|
+
ctx.json(res, r, r.ok ? 200 : 400);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let w = null; try { w = ctx.getWs(q('ws') || null); } catch { w = null; }
|
|
49
|
+
if (!w || !w.root) return bad('no such workspace', 404);
|
|
50
|
+
const ini = String(q('ini') || '');
|
|
51
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(ini)) return bad('name the initiative');
|
|
52
|
+
|
|
53
|
+
if (p === '/api/on-item') {
|
|
54
|
+
if (req.method !== 'GET') return bad('GET only', 405);
|
|
55
|
+
ctx.json(res, OI.readOf(w.root, ini, { stage: url.searchParams.get('stage') || '' }));
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (req.method !== 'POST') return bad('POST only', 405);
|
|
59
|
+
let r;
|
|
60
|
+
if (p === '/api/on-item/evidence') r = body.undo === true ? OI.undoEvidence(w.root, { id: body.id, before: body.before || null }) : OI.setEvidence(w.root, { ini, id: body.id, ref: body.ref, quote: body.quote });
|
|
61
|
+
else if (p === '/api/on-item/numbers') r = body.undo === true ? OI.undoNumbers(w.root, ini, body.before || {}) : OI.setNumbers(w.root, ini, body);
|
|
62
|
+
else if (p === '/api/on-item/press-release') r = body.undo === true ? OI.stopPress(w.root, ini) : OI.startPress(w.root, ini, { spawn: spawnForTest });
|
|
63
|
+
else return bad('no such route', 404);
|
|
64
|
+
ctx.json(res, r, r.ok ? 200 : 400);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = { prefixes: ['/api/on-item'], handle, setSpawn };
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* on-item.js — what PMOS can do for the initiative or program that is open shows on it, with no typed ask (job #1986, surface-on-item;
|
|
3
|
+
* LINE.md Rule 12; board SfA on the Exploring 3 canvas, page `surface`, agreed 2026-11-25). Before this, six features answered only a
|
|
4
|
+
* typed ask: what an approver asked before (#1878), where a sign-off's yes is written (#1869), the numbers that say whether an experiment
|
|
5
|
+
* can conclude (#1849), the press release and FAQ at Plan (#1624) and a program's first milestones (#1702). (The grill, #1830, already
|
|
6
|
+
* starts by itself: lib/grill-runs.js grills an initiative never grilled in its monthly look.)
|
|
7
|
+
*
|
|
8
|
+
* readOf(root, ini, { stage, now, runtimeDir }) → { ok, signoffs: [signoff], numbers: offer | null, press: offer | null } READ ONLY
|
|
9
|
+
* signoff { id, who, what, asked, due, past: [approver-memory item], evidence: { ref, quote, ok, why } | null, picks: [{ ref, quote }] }
|
|
10
|
+
* past: what that person asked or objected to on other work (lib/approver-memory.js historyOf), at most 3, newest first
|
|
11
|
+
* picks: with no source yet, the lines in the initiative's own files that name them with a yes, at most 3
|
|
12
|
+
* numbers { metric, due, missing: [key], ask } the record's outcome_metric is a rate and it has a check date, but not the numbers
|
|
13
|
+
* lib/experiment-power.js needs; ask is the ✦ draft's words (lib/star-draft.js runs it)
|
|
14
|
+
* press { say, state: 'offer' | 'drafting' } a feature at Plan (or Discovery) with no press release beside its record
|
|
15
|
+
* setEvidence(root, { ini, id, ref, quote }, now) → { ok, before } the pick becomes the sign-off's source (lib/signoffs.js evidence)
|
|
16
|
+
* undoEvidence(root, { id, before }, now) → { ok } the source it had, or none
|
|
17
|
+
* setNumbers(root, ini, { baseline, min_change, weekly_traffic }) → { ok, before } | { ok: false, error } three frontmatter keys
|
|
18
|
+
* undoNumbers(root, ini, before) → { ok } the keys as they were
|
|
19
|
+
* startPress(root, ini, { spawn, now }) → { ok, started } `pmos press-release <ini>` in the background
|
|
20
|
+
* stopPress(root, ini) → { ok, removed } stops it, and removes a draft it wrote
|
|
21
|
+
* programDrafts(home, id, { env, now }) → { n } pmos program draft's count for a program with no milestones
|
|
22
|
+
* fileProgramDrafts(home, id, o) · undoProgramDrafts(home, id, o) file them as suggestions · file an empty review (none stays open)
|
|
23
|
+
*
|
|
24
|
+
* Zero is silence: every part is empty when its condition is false. Every write is a page press (lib/on-item-routes.js) and has an Undo.
|
|
25
|
+
* Nothing is sent. The copy says PMOS, never Claude. */
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
|
|
29
|
+
const TAG = '[on-item]';
|
|
30
|
+
const MAX_PAST = 3;
|
|
31
|
+
const MAX_PICKS = 3;
|
|
32
|
+
const MAX_FILES = 400;
|
|
33
|
+
const MAX_SIZE = 256 * 1024;
|
|
34
|
+
const FOLDERS = ['planning', 'docs', 'notes', path.join('pmos', 'state')];
|
|
35
|
+
const YES_RE = /\b(yes|approv(?:e|ed|al|es)|agree(?:d|s)?|signed[- ]?off|sign[- ]?off given|go[- ]ahead|lgtm|accept(?:ed|s)?|confirm(?:ed|s)?)\b/i;
|
|
36
|
+
const NOT_FEATURE = new Set(['chore', 'incident', 'discovery', 'content', 'prototype']);
|
|
37
|
+
const PLAN_RE = /\b(plan|planning|discover|discovery|define|shape|shaping)\b/i;
|
|
38
|
+
const RATE_RE = /%|\brate\b|\bshare\b|\bpercent|\bconversion|\bratio\b|\bproportion\b|\bout of\b/i;
|
|
39
|
+
const NUM_KEYS = ['baseline', 'min_change', 'weekly_traffic'];
|
|
40
|
+
const PRESS = new Map(); // root|ini → { child, at, file }: the press release drafts this server started
|
|
41
|
+
|
|
42
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
43
|
+
const esc = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
44
|
+
const dayOf = (v) => { const m = /^(\d{4}-\d{2}-\d{2})/.exec(String(v || '').trim()); return m ? m[1] : ''; };
|
|
45
|
+
|
|
46
|
+
function signoffFile(root) {
|
|
47
|
+
let dir = null;
|
|
48
|
+
try { dir = require('./jira-tickets.js').stateDirOf(root); } catch { dir = null; }
|
|
49
|
+
return dir ? require('./signoffs.js').fileOf(dir) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The markdown files that may hold an initiative's notes: under planning/, docs/, notes/ and pmos/state/, the ones whose path names the
|
|
53
|
+
* initiative or whose text does, newest first. */
|
|
54
|
+
function filesOf(root, ini) {
|
|
55
|
+
const out = [], top = path.resolve(root);
|
|
56
|
+
let seen = 0;
|
|
57
|
+
const walk = (dir, depth) => {
|
|
58
|
+
if (depth > 5 || seen > MAX_FILES) return;
|
|
59
|
+
let list = [];
|
|
60
|
+
try { list = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
61
|
+
for (const e of list) {
|
|
62
|
+
if (seen > MAX_FILES) return;
|
|
63
|
+
if (e.name.startsWith('.') || e.name === 'node_modules') continue;
|
|
64
|
+
const f = path.join(dir, e.name);
|
|
65
|
+
if (e.isDirectory()) { walk(f, depth + 1); continue; }
|
|
66
|
+
if (!/\.(md|txt)$/i.test(e.name)) continue;
|
|
67
|
+
seen++;
|
|
68
|
+
let st; try { st = fs.statSync(f); } catch { continue; }
|
|
69
|
+
if (st.size > MAX_SIZE) continue;
|
|
70
|
+
const rel = path.relative(top, f).split(path.sep).join('/');
|
|
71
|
+
out.push({ rel, abs: f, at: st.mtimeMs, named: rel.toLowerCase().includes(ini.toLowerCase()) });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
for (const d of FOLDERS) walk(path.join(top, d), 0);
|
|
75
|
+
return out.sort((a, b) => b.at - a.at);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The lines of the initiative's files that name `who` with a yes ("Ana: approved the PRD"), each as a source the sign-off check reads. */
|
|
79
|
+
function picksOf(root, ini, who) {
|
|
80
|
+
const first = String(who || '').trim().split(/\s+/)[0];
|
|
81
|
+
if (!first || first.length < 2) return [];
|
|
82
|
+
const name = new RegExp('(^|[^\\p{L}])' + esc(first) + '($|[^\\p{L}])', 'iu');
|
|
83
|
+
const LD = require('./line-driver.js'), read = LD.readerOf(root, ini);
|
|
84
|
+
const out = [];
|
|
85
|
+
for (const f of filesOf(root, ini)) {
|
|
86
|
+
let text = '';
|
|
87
|
+
try { text = fs.readFileSync(f.abs, 'utf8'); } catch { continue; }
|
|
88
|
+
if (!f.named && !text.includes(ini)) continue;
|
|
89
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
90
|
+
const line = raw.replace(/^\s*(?:[-*+>]|\d+[.)])\s*/, '').trim();
|
|
91
|
+
if (line.length < 12 || line.length > 400 || !name.test(line) || !YES_RE.test(line)) continue;
|
|
92
|
+
if (!LD.quoteCheck([{ item: 'pick', quote: line, ref: f.rel }], read).ok) continue;
|
|
93
|
+
out.push({ ref: f.rel, quote: line });
|
|
94
|
+
if (out.length >= MAX_PICKS) return out;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function signoffsOf(root, ini) {
|
|
101
|
+
const file = signoffFile(root); if (!file) return [];
|
|
102
|
+
const SO = require('./signoffs.js'), SS = require('./stage-signoffs.js'), AM = require('./approver-memory.js');
|
|
103
|
+
const open = SO.list(file, { ini, open: true });
|
|
104
|
+
if (!open.length) return [];
|
|
105
|
+
let items = [];
|
|
106
|
+
try { items = AM.itemsOf(root); } catch { items = []; }
|
|
107
|
+
return open.map((s) => {
|
|
108
|
+
const ev = s.evidence && s.evidence.ref ? s.evidence : null;
|
|
109
|
+
const c = ev ? SS.checkOf(root, ini, ev, s.what) : null;
|
|
110
|
+
return { id: s.id, who: s.who, what: s.what, asked: s.asked || null, due: s.due || null,
|
|
111
|
+
past: AM.historyOf(items, s.who, { except: ini }).slice(0, MAX_PAST),
|
|
112
|
+
evidence: ev ? { ref: ev.ref, quote: ev.quote, ok: !!c.ok, why: c.why } : null,
|
|
113
|
+
picks: ev ? [] : picksOf(root, ini, s.who) };
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function recordOf(root, ini) {
|
|
118
|
+
const I = require('./item-why.js');
|
|
119
|
+
const f = I.recordPathOf(root, ini); if (!f) return null;
|
|
120
|
+
let text = ''; try { text = fs.readFileSync(f, 'utf8'); } catch { return null; }
|
|
121
|
+
return { file: f, text, fm: I.frontOf(text) };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function numbersOf(rec, today) {
|
|
125
|
+
if (!rec) return null;
|
|
126
|
+
const fm = rec.fm, EP = require('./experiment-power.js');
|
|
127
|
+
if (EP.inputsOf(fm)) return null;
|
|
128
|
+
const metric = one(fm.outcome_metric, 300), due = dayOf(fm.outcome_horizon) || dayOf(fm.check_date);
|
|
129
|
+
if (!metric || !RATE_RE.test(metric) || !due || due < today) return null;
|
|
130
|
+
const missing = NUM_KEYS.filter((k) => fm[k] == null || String(fm[k]).trim() === '');
|
|
131
|
+
const title = one(fm.title, 160) || '';
|
|
132
|
+
const ask = `Draft the three numbers that tell whether the experiment "${title}" can conclude by ${due}. Its metric: ${metric}. `
|
|
133
|
+
+ 'Read its record, its metric readings and its notes. Answer with exactly three lines and nothing else:\n'
|
|
134
|
+
+ 'baseline: <the metric today, like 12%>\nmin_change: <the smallest change worth seeing, like 2pp>\nweekly_traffic: <people a week in the experiment, both arms, like 4000>\n'
|
|
135
|
+
+ 'Write "unknown" after a key when the records do not say it. This is a draft for the PM to read.';
|
|
136
|
+
return { metric, due, missing, ask };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function pressOf(root, ini, rec, stage) {
|
|
140
|
+
if (!rec) return null;
|
|
141
|
+
const lane = String(rec.fm.lane || '').trim().toLowerCase();
|
|
142
|
+
if (NOT_FEATURE.has(lane) || !PLAN_RE.test(String(stage || ''))) return null;
|
|
143
|
+
const file = path.join(require('./press-release.js').dirOf(rec.file), ini + '.md');
|
|
144
|
+
const run = PRESS.get(root + '|' + ini);
|
|
145
|
+
if (run && !fs.existsSync(file) && Date.now() - run.at < 10 * 60e3) return { state: 'drafting', say: 'PMOS is drafting the press release and FAQ. It lands in Artefacts.' };
|
|
146
|
+
if (fs.existsSync(file)) return null;
|
|
147
|
+
return { state: 'offer', say: 'At Plan, a press release and FAQ says what this bet promises. PMOS drafts it from the record.' };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function readOf(root, ini, { stage = '', now = Date.now() } = {}) {
|
|
151
|
+
if (!root || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(String(ini || ''))) return { ok: false, error: 'name the initiative' };
|
|
152
|
+
const today = new Date(now).toISOString().slice(0, 10);
|
|
153
|
+
let signoffs = [];
|
|
154
|
+
try { signoffs = signoffsOf(root, ini); } catch { signoffs = []; }
|
|
155
|
+
const rec = recordOf(root, ini);
|
|
156
|
+
const numbers = numbersOf(rec, today), press = pressOf(root, ini, rec, stage);
|
|
157
|
+
console.info(`${TAG} ini=${ini} signoffs=${signoffs.length} past=${signoffs.filter((s) => s.past.length).length} picks=${signoffs.reduce((n, s) => n + s.picks.length, 0)} numbers=${numbers ? 1 : 0} press=${press ? press.state : 0}`);
|
|
158
|
+
return { ok: true, signoffs, numbers, press };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* ── writes, each on the PM's press ── */
|
|
162
|
+
|
|
163
|
+
function setEvidence(root, { ini, id, ref, quote } = {}, now = Date.now()) {
|
|
164
|
+
const file = signoffFile(root); if (!file) return { ok: false, error: 'this product has no PMOS state folder' };
|
|
165
|
+
const SO = require('./signoffs.js'), SS = require('./stage-signoffs.js');
|
|
166
|
+
const s = SO.list(file, { ini }).find((x) => x.id === id);
|
|
167
|
+
if (!s || s.state !== 'open') return { ok: false, error: 'no open sign-off ' + id };
|
|
168
|
+
const c = SS.checkOf(root, ini, { ref, quote }, s.what);
|
|
169
|
+
if (!c.quote.ok) return { ok: false, error: c.quote.why };
|
|
170
|
+
const before = s.evidence && s.evidence.ref ? { ref: s.evidence.ref, quote: s.evidence.quote, doc: s.evidence.doc || null } : null;
|
|
171
|
+
const r = SO.evidence(file, id, { ref, quote }, now);
|
|
172
|
+
if (!r.ok) return r;
|
|
173
|
+
console.info(`${TAG} evidence ini=${ini} id=${id} ref=${one(ref, 120)}`);
|
|
174
|
+
return { ok: true, before, check: c };
|
|
175
|
+
}
|
|
176
|
+
function undoEvidence(root, { id, before } = {}, now = Date.now()) {
|
|
177
|
+
const file = signoffFile(root); if (!file) return { ok: false, error: 'this product has no PMOS state folder' };
|
|
178
|
+
const SO = require('./signoffs.js');
|
|
179
|
+
const r = before && before.ref ? SO.evidence(file, id, before, now) : SO.clearEvidence(file, id, now);
|
|
180
|
+
if (r.ok) console.info(`${TAG} evidence undone id=${id}`);
|
|
181
|
+
return r.ok ? { ok: true } : r;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The record with these frontmatter keys set (null removes one). Keys not in the frontmatter go at its end. PURE. */
|
|
185
|
+
function withFront(text, kv) {
|
|
186
|
+
const L = String(text).split('\n');
|
|
187
|
+
if (!/^---\s*$/.test(L[0] || '')) return null;
|
|
188
|
+
let end = L.findIndex((l, i) => i > 0 && /^---\s*$/.test(l));
|
|
189
|
+
if (end < 0) return null;
|
|
190
|
+
for (const [k, v] of Object.entries(kv)) {
|
|
191
|
+
const at = L.findIndex((l, i) => i > 0 && i < end && new RegExp('^' + esc(k) + ':').test(l));
|
|
192
|
+
if (v == null) { if (at > 0) { L.splice(at, 1); end--; } continue; }
|
|
193
|
+
const line = k + ': ' + JSON.stringify(String(v));
|
|
194
|
+
if (at > 0) L[at] = line; else { L.splice(end, 0, line); end++; }
|
|
195
|
+
}
|
|
196
|
+
return L.join('\n');
|
|
197
|
+
}
|
|
198
|
+
function setNumbers(root, ini, given = {}) {
|
|
199
|
+
const rec = recordOf(root, ini); if (!rec) return { ok: false, error: 'no record for ' + ini };
|
|
200
|
+
const kv = {};
|
|
201
|
+
for (const k of NUM_KEYS) { const v = one(given[k], 40); if (!v || /unknown/i.test(v)) return { ok: false, error: `the draft has no ${k.replace('_', ' ')}: write it in the record, or draft again` }; kv[k] = v; }
|
|
202
|
+
const next = withFront(rec.text, kv);
|
|
203
|
+
if (!next) return { ok: false, error: 'the record has no frontmatter' };
|
|
204
|
+
if (!require('./experiment-power.js').inputsOf(require('./item-why.js').frontOf(next))) return { ok: false, error: 'PMOS cannot read these as numbers: a baseline like 12%, a change like 2pp, a weekly traffic like 4000' };
|
|
205
|
+
const before = Object.fromEntries(NUM_KEYS.map((k) => [k, rec.fm[k] == null ? null : rec.fm[k]]));
|
|
206
|
+
fs.writeFileSync(rec.file, next);
|
|
207
|
+
console.info(`${TAG} numbers ini=${ini} ${NUM_KEYS.map((k) => k + '=' + kv[k]).join(' ')}`);
|
|
208
|
+
return { ok: true, before };
|
|
209
|
+
}
|
|
210
|
+
function undoNumbers(root, ini, before = {}) {
|
|
211
|
+
const rec = recordOf(root, ini); if (!rec) return { ok: false, error: 'no record for ' + ini };
|
|
212
|
+
const kv = Object.fromEntries(NUM_KEYS.map((k) => [k, before && before[k] != null ? before[k] : null]));
|
|
213
|
+
const next = withFront(rec.text, kv); if (!next) return { ok: false, error: 'the record has no frontmatter' };
|
|
214
|
+
fs.writeFileSync(rec.file, next);
|
|
215
|
+
console.info(`${TAG} numbers undone ini=${ini}`);
|
|
216
|
+
return { ok: true };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function startPress(root, ini, { spawn, now = Date.now() } = {}) {
|
|
220
|
+
const rec = recordOf(root, ini); if (!rec) return { ok: false, error: 'no record for ' + ini };
|
|
221
|
+
const file = path.join(require('./press-release.js').dirOf(rec.file), ini + '.md');
|
|
222
|
+
if (fs.existsSync(file)) return { ok: false, error: 'this bet already has a press release' };
|
|
223
|
+
const key = root + '|' + ini, run = PRESS.get(key);
|
|
224
|
+
if (run && now - run.at < 10 * 60e3) return { ok: true, started: false };
|
|
225
|
+
const args = [path.join(__dirname, '..', 'bin', 'pmos.js'), 'press-release', ini, '--root', root];
|
|
226
|
+
const sp = spawn || ((cmd, a) => { const c = require('child_process').spawn(cmd, a, { cwd: root, stdio: 'ignore', detached: true }); c.unref(); return c; });
|
|
227
|
+
let child = null;
|
|
228
|
+
try { child = sp(process.execPath, args); } catch (e) { return { ok: false, error: 'PMOS could not start the draft: ' + one(e && e.message, 120) }; }
|
|
229
|
+
PRESS.set(key, { child, at: now, file });
|
|
230
|
+
console.info(`${TAG} press-release started ini=${ini}`);
|
|
231
|
+
return { ok: true, started: true };
|
|
232
|
+
}
|
|
233
|
+
function stopPress(root, ini) {
|
|
234
|
+
const key = root + '|' + ini, run = PRESS.get(key);
|
|
235
|
+
PRESS.delete(key);
|
|
236
|
+
if (!run) return { ok: true, removed: false };
|
|
237
|
+
try { if (run.child && run.child.kill && run.child.exitCode == null) run.child.kill(); } catch { /* it ended */ }
|
|
238
|
+
let removed = false;
|
|
239
|
+
try { const st = fs.statSync(run.file); if (st.mtimeMs >= run.at - 1000) { fs.unlinkSync(run.file); removed = true; } } catch { /* nothing written */ }
|
|
240
|
+
console.info(`${TAG} press-release stopped ini=${ini} removed=${removed}`);
|
|
241
|
+
return { ok: true, removed };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* ── a program's first milestones (pmos program draft, lib/program-cli.js lineVerb) ── */
|
|
245
|
+
|
|
246
|
+
function lineCall(home, verb, args, o = {}) {
|
|
247
|
+
const lines = [];
|
|
248
|
+
const code = require('./program-cli.js').lineVerb(verb, args, { say: (l) => lines.push(String(l)), cwd: home, env: o.env || process.env, now: o.now || Date.now(), read: o.read });
|
|
249
|
+
return { code, lines };
|
|
250
|
+
}
|
|
251
|
+
function programDrafts(home, id, o = {}) {
|
|
252
|
+
const r = lineCall(home, 'line', [id, '--json'], o);
|
|
253
|
+
let j = null; try { j = JSON.parse(r.lines[r.lines.length - 1] || ''); } catch { j = null; }
|
|
254
|
+
const L = j && j.ok ? (j.programs || []).find((x) => x.id === id) : null;
|
|
255
|
+
return { n: L ? require('./program-line.js').draftsOf(L).length : 0 };
|
|
256
|
+
}
|
|
257
|
+
function fileProgramDrafts(home, id, o = {}) {
|
|
258
|
+
const r = lineCall(home, 'draft', [id], o);
|
|
259
|
+
console.info(`${TAG} program drafts filed program=${id} code=${r.code}`);
|
|
260
|
+
return r.code === 0 ? { ok: true, said: r.lines[0] || '' } : { ok: false, error: (r.lines[0] || 'PMOS could not draft the milestones').replace(/^✗\s*/, '') };
|
|
261
|
+
}
|
|
262
|
+
function undoProgramDrafts(home, id, { now = Date.now() } = {}) {
|
|
263
|
+
const dir = require('./driver.js').stateDirOf(home); if (!dir) return { ok: false, error: 'this product has no PMOS state folder' };
|
|
264
|
+
const MS = require('./milestone-suggest.js'), PI = require('./pm-items.js'), file = MS.fileOf(dir), run = 'undo' + now.toString(36), at = new Date(now);
|
|
265
|
+
PI.appendEvent(file, { kind: 'review-start', program: id, run, why: 'line', members: '' }, at);
|
|
266
|
+
PI.appendEvent(file, { kind: 'review-end', program: id, run, ok: true }, at);
|
|
267
|
+
console.info(`${TAG} program drafts undone program=${id}`);
|
|
268
|
+
return { ok: true };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
module.exports = { TAG, readOf, picksOf, filesOf, withFront, setEvidence, undoEvidence, setNumbers, undoNumbers, startPress, stopPress,
|
|
272
|
+
programDrafts, fileProgramDrafts, undoProgramDrafts, NUM_KEYS };
|