create-pmos 0.662.0 → 0.664.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.662.0",
3
+ "version": "0.664.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": {
@@ -34,26 +34,26 @@
34
34
  ],
35
35
  "pmosChanges": [
36
36
  {
37
- "v": "0.662.0",
38
- "at": "2026-11-22T04:06:35.609Z",
37
+ "v": "0.664.0",
38
+ "at": "2026-11-22T04:17:27.653Z",
39
39
  "f": 4,
40
40
  "prs": [
41
41
  {
42
- "n": 1445,
43
- "t": "Pmos design drift, the design drift guard",
44
- "s": "Pmos design drift, the design drift guard",
42
+ "n": 1442,
43
+ "t": "Routine is built from the design system's blocks",
44
+ "s": "Routine is built from the design system's blocks",
45
45
  "k": "new"
46
46
  },
47
47
  {
48
- "n": 1449,
49
- "t": "Rebuild the Intelligence page from Komorebi blocks",
50
- "s": "Rebuild the Intelligence page from Komorebi blocks",
48
+ "n": 1446,
49
+ "t": "A design critic reads each design against every standing rule before the PM sees it",
50
+ "s": "A design critic reads each design against every standing rule before the PM sees it",
51
51
  "k": "new"
52
52
  },
53
53
  {
54
- "n": 1442,
55
- "t": "Routine is built from the design system's blocks",
56
- "s": "Routine is built from the design system's blocks",
54
+ "n": 1448,
55
+ "t": "Check launch readiness before go-live",
56
+ "s": "Check launch readiness before go-live",
57
57
  "k": "new"
58
58
  }
59
59
  ]
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@85d35dcf
1
+ kernel-source: pmos@0cd92a74
2
2
  assembled: 2026-11-22
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-22T04:06:31Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T04:17:24Z"}
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-22T04:06:31Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T04:17:24Z"}
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-22T04:06:31Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T04:17:24Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,25 +1,25 @@
1
1
  [
2
2
  {
3
- "v": "0.662.0",
4
- "at": "2026-11-22T04:06:35.609Z",
3
+ "v": "0.664.0",
4
+ "at": "2026-11-22T04:17:27.653Z",
5
5
  "f": 4,
6
6
  "prs": [
7
7
  {
8
- "n": 1445,
9
- "t": "Pmos design drift, the design drift guard",
10
- "s": "Pmos design drift, the design drift guard",
8
+ "n": 1442,
9
+ "t": "Routine is built from the design system's blocks",
10
+ "s": "Routine is built from the design system's blocks",
11
11
  "k": "new"
12
12
  },
13
13
  {
14
- "n": 1449,
15
- "t": "Rebuild the Intelligence page from Komorebi blocks",
16
- "s": "Rebuild the Intelligence page from Komorebi blocks",
14
+ "n": 1446,
15
+ "t": "A design critic reads each design against every standing rule before the PM sees it",
16
+ "s": "A design critic reads each design against every standing rule before the PM sees it",
17
17
  "k": "new"
18
18
  },
19
19
  {
20
- "n": 1442,
21
- "t": "Routine is built from the design system's blocks",
22
- "s": "Routine is built from the design system's blocks",
20
+ "n": 1448,
21
+ "t": "Check launch readiness before go-live",
22
+ "s": "Check launch readiness before go-live",
23
23
  "k": "new"
24
24
  }
25
25
  ]
@@ -228,6 +228,7 @@ What each part does:
228
228
  - **What the run can do.** A run can only read and write in its own folder in the runtime folder, plus the last version and the files you attached. It has no shell, no web and nothing that sends. Nothing goes into a product repository before your ✓.
229
229
  - **What the canvas can do.** The prototype runs in a sandboxed frame. It cannot reach PMOS. The canvas talks to it only to show a screen, point, pin, play and apply your edits.
230
230
  - **Your prototype rules.** After a version renders and before it opens, PMOS checks it against your prototype rules: no device or browser frame, no instructions on the screen, no sample copy, and each rule PMOS learns from your corrections. When a correction is true of every prototype (for example "no device frame"), the chat adds it as a rule (`pmos lab rule add`). PMOS keeps a rule only when it fails a bad example and passes a good one, so a button such as "See the week" is never read as an instruction. A change to one version ("make the alert orange") or a taste ("calmer") never becomes a rule. A version that breaks a rule gets one fix run, given only the lines that broke it. You see only the fixed version, with one quiet line: "PMOS fixed 3 things before showing you this." When the fix does not reach a rule, the version still opens and the line names the rule it breaks. When nothing was fixed, there is no line. Settings › PMOS › Prototype rules lists the rules with Undo.
231
+ - **The design critic.** After the prototype rules, a separate read-only session reads the version's desk and phone screenshots and its page against every standing design rule of your product. Each rule is a named check: each numbered principle in your design principles and each rule in your `design-rules.json`. A finding must name the rule it breaks, so the critic reports broken rules, not taste. Its findings go into the same one fix run. After the fix it reads only those rules again, so "PMOS fixed n things" is never claimed unchecked. A critic that cannot run never holds the version. `pmos lab critic` runs it on any screenshots, and `PMOS_CRITIC=off` turns it off.
231
232
  - **No time limit.** A version takes as long as the ask needs. While PMOS makes it, the Viewer shows what it is doing now (for example "Building screen 3 of 7"), the steps done, a progress bar and the time so far, with a Stop press. A run that writes nothing for 10 minutes is stuck: PMOS stops it. A version that does not render, that is stuck or that you stop is "not made" with the reason, and the chat says so. The Viewer still opens it: it says why and shows the version it was made from. While a version is being made, a new ask on the same initiative waits: PMOS says what is running.
232
233
  - **Lessons.** Each change sentence, ✓ and ✕ is a Lessons line of the experiment (`pmos artefacts show`). Each version that rendered is a Specimens line. The one you keep is the kept specimen.
233
234
  - **The grill runs after the session, not during it.** When you keep a version, the grill runs once on the kept specimen, as the Review step. Its findings wait under the ✦ (D60 as amended on 2026-11-17).
@@ -248,6 +248,9 @@ The idle lab run uses only the first three commands:
248
248
  - `pmos lab undo <batch> [--ws <id>]`: bring a deleted version back, with its edits.
249
249
  - `pmos lab rule add --json - [--again]`: add one of your prototype rules from a correction. The JSON is `{ "title", "words", "tests": [{ "in": "text" | "attr" | "source", "re", "flags"? }], "bad", "good" }`: `text` reads the screen's words without buttons and links, `attr` reads each element's class and id, and `bad` and `good` are two small HTML pages. PMOS keeps the rule only when it fails `bad` and passes `good`. `--again` adds a rule you undid, only when you say it again. The initiative chat runs it; a background lab run cannot.
250
250
  - `pmos lab rule list`: the rules every prototype version is checked against before it opens. The same list is in Settings › PMOS › Prototype rules.
251
+ - `pmos lab critic <file…> [--ws <id>]`: the design critic reads screenshots (.png, .jpg, .webp) or HTML files, given as full paths, against every standing design rule of the product. Each rule is one named check: each numbered principle in the product's design principles, and each rule in its `design-rules.json`. A product with neither gets a short base set. Each finding names the check it breaks. Use it on a release's screenshots or a design board before anyone else sees them. The running PMOS server starts one read-only session.
252
+ - `pmos lab critic checks [--root <dir>]`: the checks the critic uses for the product in that folder. No server is needed.
253
+ - `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.
251
254
 
252
255
  ### pmos outcomes: expected outcomes
253
256
 
@@ -700,6 +703,13 @@ The skills that read your tools save their reads with these commands. [Settings,
700
703
  - `pmos calendar import --from <file|-> --sensitivity <label>` saves the events the agent read. The label is `public`, `internal`, `confidential` or `private`. `--dry-run` checks the file and saves nothing.
701
704
  - `pmos calendar status` says how many events are saved and when they were read.
702
705
 
706
+ ### pmos launch
707
+
708
+ Before a launch date, `pmos launch` lists what is not ready in one place. It reads the initiative's tasks, its last tracker reading, its sign-offs and the day's question list. It calls no tracker, sends nothing and writes no record, so read the tracker first.
709
+
710
+ - `pmos launch check <initiative> [--date YYYY-MM-DD]` shows the launch date, a verdict (ready, at risk or no data) and each item that is not ready: open tasks (past their date, or due after the launch), tracker tickets still open (with the days since they moved and any block), sign-offs with no answer, and open questions. The launch date is `--date`, else a ◇ milestone named launch, go-live, release or ship, else the committed end, else the last ◇ milestone. With none, the command asks for `--date`. A tracker reading older than 2 days gives a warning.
711
+ - `pmos launch list [--days N]` lists every initiative with a launch in the next N days (14 by default), with its verdict and the number of items not ready.
712
+
703
713
  ### pmos tracker
704
714
 
705
715
  - `pmos tracker done [--moved N] [--left N] [--not-found N]` records the time of the read for this repository and the counts of what it found. It moves no item.
@@ -107,6 +107,7 @@ An "off" switch accepts `off`, `0`, `false` or `no` unless the row says a differ
107
107
  | `PMOS_HEADLESS` | `off` sends every background job back to a terminal pane. | on | — |
108
108
  | `PMOS_AI` | `off` turns every AI job off (the kill switch of [what agents may do](agent-capabilities.md)). | on | `pmos ai off` (the `ai.on` setting) |
109
109
  | `PMOS_AI_<JOB>` | `off` turns one AI job off. The names are `PMOS_AI_PAST_REPEAT`, `PMOS_AI_DECISION_MEMORY`, `PMOS_AI_OUTCOMES`, `PMOS_AI_DESCRIPTIONS`, `PMOS_AI_DRIFT`, `PMOS_AI_REHEARSE`, `PMOS_AI_NEXT_PROMPT`, `PMOS_AI_SHARPEN_PROMPT` and `PMOS_AI_IDLE_LAB`. | on | `pmos ai off <job>` (the `ai.off` setting) |
110
+ | `PMOS_CRITIC` | `off` stops the design critic: no critic reads a prototype version before it opens, and `pmos lab critic` refuses. The prototype rules still run. | on | — |
110
111
  | `PMOS_AUTONOMY` | `off` stops every change PMOS applies by itself (D106) and every goal loop; proposals still wait for your ✓. | on | `pmos ai off` |
111
112
  | `PMOS_BUILD_SANDBOX` | `docker` or `podman` runs `pmos build check` in a container with no network (the image is `check.image` in `pmos/factory.json`). Without it the check runs in the worktree, and only you can run it. | off | — |
112
113
  | `PMOS_FACTORY_GH_TOKEN` | The factory's own GitHub token, when `pmos/factory.json` names it in `identity.token_env`. The name must start with `PMOS_FACTORY_`. PMOS gives it to gh for its own calls and removes it from every agent run. Never put it in a file. | not set: your gh login | — |
@@ -0,0 +1,271 @@
1
+ 'use strict';
2
+ /* design-critic.js — a critic reads each design before the PM sees it (initiative design-critic-pass; bet 4 of the factory line, from the A11
3
+ * proof and A46 "every standing rule becomes a check"; proof: pmos-ideas/proofs/critic, 2 of 2 of the PM's complaints on 0.551.0 caught).
4
+ *
5
+ * EVERY STANDING RULE IS A NAMED CHECK. checksFor(root) reads the PRODUCT's own rules, so it works on any product built with PMOS:
6
+ * principles the first of okf/products/<slug>/references/design-principles.md · design-principles.md · docs/design-principles.md ·
7
+ * design/design-principles.md. Each numbered item "N. **Title.** text" under its "## The principles" heading (or anywhere,
8
+ * when there is no such heading) is the check p<N>.
9
+ * rules design-rules.json beside the principles file, else pmos/design-rules.json: { rules: [{ id, title, rule, source, date }] }. The
10
+ * PM's standing rules that are not principles yet (on PMOS: say PMOS not Claude, icon-only calls to action, phone on the go).
11
+ * base a product with neither gets BASE: the rules that hold for every screen.
12
+ * A FINDING MUST NAME ITS CHECK. parse() drops a finding whose check is not in the list, so the critic reports broken rules, not taste.
13
+ *
14
+ * THE RUN. One read-only session on the existing ask path (origin `briefing-ask:design-critic:<key>`, headless kind `ask`: Read, Glob and
15
+ * Grep only; the same path as the document chat and the Library's search by meaning). No new kind, no dependency. It reads the screenshots
16
+ * and the HTML and answers JSON. A critic that cannot start, times out or answers nonsense never holds a design: the caller goes on, and the
17
+ * ledger says it did not run. PMOS_CRITIC=off runs none.
18
+ *
19
+ * WHERE IT RUNS. lib/live-round.js, after the prototype rules and before a version opens (its findings join the one fix run, and after the
20
+ * fix only the flagged checks are read again); `pmos lab critic <files…>` for any screenshots or HTML (a release, a canvas board).
21
+ *
22
+ * THE LEDGER. <runtime>/design-critic.jsonl, append-only: { kind: 'run', id, at, from, ws?, ini?, version?, key?, read, checks, ok, why?,
23
+ * findings: [{ check, title, screen, what, where }], ms } and { kind: 'label', run, n, label: real | noise, by, at } (the PM's word on finding
24
+ * n, 1-based; the newest label wins). stats() counts them, so the Checker can measure the false-alarm rate.
25
+ *
26
+ * BASE · ORIGIN · MODEL · MAX_FINDINGS · off(env)
27
+ * principlesOf(md, rel) PURE → [check] · rulesOf(json, rel) PURE → [check] · checksFor(root) → { checks, from: [rel], base }
28
+ * promptOf({ checks, targets: [{ abs, label }], product?, only? }) PURE → string
29
+ * parse(text, checks) PURE → [finding] | null (null: the answer could not be read)
30
+ * asFailed(findings, checks) PURE → [{ id: 'critic:<check>', critic: true, check, title, words, lines }] (lib/prototype-rules.js run() shape)
31
+ * critique(ask, { root?, checks?, targets, only?, product? }) → Promise<{ ok, findings, checks, ms } | { ok: false, why, off? }>
32
+ * askVia(spawnSession, { timeoutMs? }) → ask(prompt, { key, addDirs }) → Promise<text | null>
33
+ * file(rt) · record(rt, run) → id · label(rt, run, n, label, { by }) → { ok } | { ok: false, error } · read(rt) → [run + { labels }] · stats(rt) */
34
+ const fs = require('fs');
35
+ const path = require('path');
36
+ const crypto = require('crypto');
37
+
38
+ const FILE = 'design-critic.jsonl';
39
+ const ORIGIN = 'briefing-ask:design-critic:';
40
+ const MODEL = 'claude-opus-5-5'; // design work runs on Opus (the PM's model rule, 2026-11-19)
41
+ const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read' }]);
42
+ const TIMEOUT_MS = 240000;
43
+ const MAX_FINDINGS = 8, MAX_TARGETS = 8, MAX_RULE = 700;
44
+ const IMAGE_RE = /\.(png|jpe?g|webp|gif)$/i, HTML_RE = /\.html?$/i;
45
+ const PRINCIPLE_FILES = ['design-principles.md', 'docs/design-principles.md', 'design/design-principles.md'];
46
+ const ID_RE = /^[a-z0-9][a-z0-9-]{0,59}$/;
47
+ const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
48
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
49
+ const off = (env = process.env) => /^(off|0|false|no)$/i.test(String((env && env.PMOS_CRITIC) || '').trim());
50
+
51
+ /* ── the base set: what holds for every screen, for a product that has not written its own rules yet ── */
52
+ const BASE = Object.freeze([
53
+ { id: 'say-it-once', title: 'Say it once', rule: 'A word that repeats on every row belongs in the group header. No title shown twice, no two buttons that do the same thing.' },
54
+ { id: 'zero-is-silence', title: 'Zero is silence', rule: 'A chip, pill or count whose value is 0, none or nothing is not drawn.' },
55
+ { id: 'plain-words', title: 'Plain words', rule: 'Sentence case in the user\'s words. No internal jargon, codes, record ids or raw field names (true, false, null) on the screen.' },
56
+ { id: 'honest-state', title: 'Honest state', rule: 'The screen claims only what the data backs: no made-up status, no reassuring label on a broken state.' },
57
+ { id: 'one-component-per-job', title: 'One component per job', rule: 'The same function looks and behaves the same everywhere on the screen; one type scale, no odd sizes.' },
58
+ { id: 'nothing-overlaps', title: 'Nothing overlaps or is cut off', rule: 'No element covers another, no text is clipped or truncated so it loses its meaning, nothing runs off the screen at phone width.' },
59
+ { id: 'every-gap-has-a-next-action', title: 'Every gap has its next action', rule: 'An empty or missing state says what to do, with the control in place.' },
60
+ ].map((c) => Object.freeze({ ...c, source: 'PMOS base rules' })));
61
+
62
+ /* ── reading the product's rules ── */
63
+ /** The numbered principles of a principles file → [{ id: 'p<n>', title, rule, source }]. Sub-bullets join the rule text. */
64
+ function principlesOf(md, rel = 'design-principles.md') {
65
+ const text = String(md || '');
66
+ let body = text;
67
+ const h = /^##\s+The principles\s*$/im.exec(text);
68
+ if (h) { const rest = text.slice(h.index + h[0].length); const end = /^##\s+/m.exec(rest); body = end ? rest.slice(0, end.index) : rest; }
69
+ const out = [], seen = new Set();
70
+ let cur = null;
71
+ for (const line of body.split('\n')) {
72
+ const m = /^(\d{1,3})\.\s+\*\*(.+?)\*\*\s*(.*)$/.exec(line);
73
+ if (m) {
74
+ const id = 'p' + m[1];
75
+ if (seen.has(id)) { cur = null; continue; }
76
+ seen.add(id);
77
+ cur = { id, title: one(m[2].replace(/\s*\([^)]*\)\s*\.?\s*$/, '').replace(/[.:]\s*$/, ''), 120), rule: one(m[3], MAX_RULE), source: `${rel} principle ${m[1]}` };
78
+ out.push(cur);
79
+ } else if (cur && /^\s+[-*]\s+/.test(line) && cur.rule.length < MAX_RULE) {
80
+ cur.rule = one(cur.rule + ' ' + line.replace(/^\s+[-*]\s+/, '').replace(/\*/g, ''), MAX_RULE);
81
+ } else if (/^\S/.test(line) && !/^\d/.test(line)) cur = null;
82
+ }
83
+ for (const c of out) c.rule = c.rule.replace(/\*\*/g, '');
84
+ return out;
85
+ }
86
+ /** A design-rules.json → [{ id, title, rule, source }]; a malformed rule is skipped. */
87
+ function rulesOf(json, rel = 'design-rules.json') {
88
+ let j = json;
89
+ if (typeof j === 'string') { try { j = JSON.parse(j); } catch { return []; } }
90
+ const list = isObj(j) && Array.isArray(j.rules) ? j.rules : Array.isArray(j) ? j : [];
91
+ const out = [], seen = new Set();
92
+ for (const r of list) {
93
+ if (!isObj(r) || !ID_RE.test(String(r.id || '')) || !one(r.title, 120) || !one(r.rule, MAX_RULE) || seen.has(r.id)) continue;
94
+ seen.add(r.id);
95
+ out.push({ id: r.id, title: one(r.title, 120), rule: one(r.rule, MAX_RULE), source: one([r.source, r.date].filter(Boolean).join(', ') || rel, 160) });
96
+ }
97
+ return out;
98
+ }
99
+ const readOr = (abs) => { try { return fs.readFileSync(abs, 'utf8'); } catch { return null; } };
100
+ /** The product's checks: its principles and its standing rules, or the base set. */
101
+ function checksFor(root) {
102
+ const R = String(root || '');
103
+ let prin = null, prinRel = '';
104
+ if (R) {
105
+ let slugs = []; try { slugs = fs.readdirSync(path.join(R, 'okf', 'products')).sort(); } catch { slugs = []; }
106
+ const cands = [...slugs.map((s) => `okf/products/${s}/references/design-principles.md`), ...PRINCIPLE_FILES];
107
+ for (const rel of cands) { const t = readOr(path.join(R, rel)); if (t != null) { prin = t; prinRel = rel; break; } }
108
+ }
109
+ const from = [];
110
+ let checks = [];
111
+ if (prin != null) { const p = principlesOf(prin, prinRel); if (p.length) { checks = p; from.push(prinRel); } }
112
+ if (R) {
113
+ const ruleCands = [...(prinRel ? [path.posix.join(path.posix.dirname(prinRel), 'design-rules.json')] : []), 'pmos/design-rules.json'];
114
+ for (const rel of ruleCands) {
115
+ const t = readOr(path.join(R, rel)); if (t == null) continue;
116
+ const rs = rulesOf(t, rel).filter((r) => !checks.some((c) => c.id === r.id));
117
+ if (rs.length) { checks = checks.concat(rs); from.push(rel); }
118
+ break;
119
+ }
120
+ }
121
+ const base = !checks.length;
122
+ if (base) checks = BASE.map((c) => ({ ...c }));
123
+ return { checks, from, base };
124
+ }
125
+
126
+ /* ── the run ── */
127
+ function promptOf({ checks, targets, product = '', only = null }) {
128
+ const list = only && only.length ? checks.filter((c) => only.includes(c.id)) : checks;
129
+ const imgs = targets.filter((t) => IMAGE_RE.test(t.abs)), html = targets.filter((t) => HTML_RE.test(t.abs));
130
+ return [
131
+ `You are PMOS's design critic. Before the user sees this design${product ? ' of ' + one(product, 80) : ''}, check it against the product's standing design rules below. Read every file listed with the Read tool. Do not write or change anything.`,
132
+ imgs.length ? 'Screenshots (look at each):\n' + imgs.map((t) => `- ${t.label}: ${t.abs}`).join('\n') : '',
133
+ html.length ? 'The page source (read it to see words, buttons and labels the screenshots may not show):\n' + html.map((t) => `- ${t.label}: ${t.abs}`).join('\n') : '',
134
+ 'The checks. Each finding must name exactly one of these ids:\n' + list.map((c) => `[${c.id}] ${c.title}: ${c.rule}`).join('\n'),
135
+ `List only concrete, visible violations the user would notice, most serious first, at most ${MAX_FINDINGS}. A finding names the screen, what is wrong in one line, and where (the element or its words). No praise, no taste, no "could be cleaner". If you are not sure a check is broken, leave it out: a false alarm costs the user's trust. If nothing breaks a check, answer an empty list.`,
136
+ 'Answer with JSON only: {"findings":[{"check":"<id>","screen":"<screen label>","what":"<what is wrong>","where":"<element or words>"}]}',
137
+ ].filter(Boolean).join('\n\n');
138
+ }
139
+ /** The critic's answer → findings that each cite a known check, or null when the answer could not be read. */
140
+ function parse(text, checks) {
141
+ const t = String(text || '').replace(/```(?:json)?/gi, '');
142
+ const at = t.indexOf('{'), end = t.lastIndexOf('}');
143
+ if (at < 0 || end < at) return null;
144
+ let o = null;
145
+ try { o = JSON.parse(t.slice(at, end + 1)); } catch {
146
+ const m = /\{\s*"findings"\s*:\s*\[[\s\S]*?\]\s*\}/.exec(t); if (!m) return null;
147
+ try { o = JSON.parse(m[0]); } catch { return null; }
148
+ }
149
+ if (!isObj(o) || !Array.isArray(o.findings)) return null;
150
+ const byId = new Map(checks.map((c) => [c.id, c]));
151
+ const out = [], seen = new Set();
152
+ for (const f of o.findings) {
153
+ if (!isObj(f)) continue;
154
+ const c = byId.get(String(f.check || '').replace(/^\[|\]$/g, '').trim());
155
+ const what = one(f.what, 240);
156
+ if (!c || !what) continue;
157
+ const k = c.id + '|' + what.toLowerCase();
158
+ if (seen.has(k)) continue;
159
+ seen.add(k);
160
+ out.push({ check: c.id, title: c.title, screen: one(f.screen, 60), what, where: one(f.where, 160) });
161
+ if (out.length >= MAX_FINDINGS) break;
162
+ }
163
+ return out;
164
+ }
165
+ /** Findings in the prototype rules' failed shape, one entry per check, so the live round's one fix run quotes them. */
166
+ function asFailed(findings, checks) {
167
+ const byId = new Map(checks.map((c) => [c.id, c]));
168
+ const out = new Map();
169
+ for (const f of findings || []) {
170
+ const c = byId.get(f.check) || { title: f.title || f.check, rule: '' };
171
+ if (!out.has(f.check)) out.set(f.check, { id: 'critic:' + f.check, critic: true, check: f.check, title: c.title, words: c.rule, lines: [] });
172
+ out.get(f.check).lines.push(one(`${f.screen ? f.screen + ': ' : ''}${f.what}${f.where ? ' (' + f.where + ')' : ''}`, 300));
173
+ }
174
+ return [...out.values()];
175
+ }
176
+ /** One critic pass. ask(prompt, { key, addDirs }) → Promise<text | null>. */
177
+ async function critique(ask, { root = '', checks = null, targets = [], only = null, product = '', env = process.env } = {}) {
178
+ if (off(env)) return { ok: false, off: true, why: 'the critic is off (PMOS_CRITIC=off)' };
179
+ if (typeof ask !== 'function') return { ok: false, why: 'PMOS could not start a critic session' };
180
+ const T = (targets || []).filter((t) => t && t.abs && (IMAGE_RE.test(t.abs) || HTML_RE.test(t.abs))).slice(0, MAX_TARGETS);
181
+ if (!T.length) return { ok: false, why: 'nothing to read: give screenshots (.png, .jpg, .webp) or an HTML file' };
182
+ const C = checks || checksFor(root).checks;
183
+ const list = only && only.length ? C.filter((c) => only.includes(c.id)) : C;
184
+ if (!list.length) return { ok: true, findings: [], checks: [], ms: 0 };
185
+ const started = Date.now();
186
+ const key = crypto.createHash('sha1').update(T.map((t) => t.abs).join('\n') + '\n' + list.map((c) => c.id).join(',') + '\n' + started).digest('hex').slice(0, 12);
187
+ let text = null;
188
+ try { text = await ask(promptOf({ checks: list, targets: T, product }), { key, addDirs: [...new Set(T.map((t) => path.dirname(t.abs)))] }); } catch { text = null; }
189
+ const ms = Date.now() - started;
190
+ if (text == null) return { ok: false, why: 'the critic session did not answer', ms };
191
+ const findings = parse(text, list);
192
+ if (!findings) return { ok: false, why: 'the critic\'s answer could not be read', ms };
193
+ return { ok: true, findings, checks: list.map((c) => c.id), ms };
194
+ }
195
+ /** The ask path through the server's spawnSession: a read-only `briefing-ask:` run (kind ask), its answer text or null. */
196
+ function askVia(spawnSession, { timeoutMs = TIMEOUT_MS, name = 'design critic' } = {}) {
197
+ if (typeof spawnSession !== 'function') return null;
198
+ return (prompt, { key = '', addDirs = [] } = {}) => new Promise((resolve) => {
199
+ let settled = false; const done = (v) => { if (settled) return; settled = true; clearTimeout(t); resolve(v); };
200
+ const t = setTimeout(() => done(null), timeoutMs);
201
+ let s = null;
202
+ try {
203
+ s = spawnSession({ name, agent: 'claude', origin: ORIGIN + (key || Date.now().toString(36)), initialInput: prompt, addDirs,
204
+ modelAsk: { explicit: { model: MODEL, effort: 'medium' } }, launchFlags: LEAN.map((f) => ({ ...f })),
205
+ onDone: (d) => { const r = d && d.result; done(r && r.ok && !r.isError ? String(r.text || '') : null); } });
206
+ } catch { s = null; }
207
+ if (!s || s.state === 'exited') done(null);
208
+ });
209
+ }
210
+
211
+ /* ── the ledger ── */
212
+ const file = (rt) => path.join(String(rt || ''), FILE);
213
+ function append(rt, line) {
214
+ if (!rt) return false;
215
+ try { fs.mkdirSync(rt, { recursive: true }); fs.appendFileSync(file(rt), JSON.stringify(line) + '\n'); return true; } catch { return false; }
216
+ }
217
+ /** Record one run. → its id */
218
+ function record(rt, run = {}) {
219
+ const id = 'cr-' + Date.now().toString(36) + crypto.randomBytes(3).toString('hex');
220
+ const line = { kind: 'run', id, at: new Date().toISOString(), from: one(run.from || 'cli', 40),
221
+ ...(run.ws ? { ws: one(run.ws, 80) } : {}), ...(run.ini ? { ini: one(run.ini, 120) } : {}), ...(run.version ? { version: run.version } : {}), ...(run.key ? { key: one(run.key, 4) } : {}),
222
+ ...(run.recheck ? { recheck: true } : {}),
223
+ read: (run.read || []).map((x) => one(x, 300)).slice(0, MAX_TARGETS), checks: (run.checks || []).slice(0, 80), ok: !!run.ok, ...(run.why ? { why: one(run.why, 200) } : {}),
224
+ findings: (run.findings || []).slice(0, MAX_FINDINGS).map((f) => ({ check: f.check, title: one(f.title, 120), screen: one(f.screen, 60), what: one(f.what, 240), where: one(f.where, 160) })),
225
+ ms: Number.isFinite(run.ms) ? run.ms : null };
226
+ append(rt, line);
227
+ return id;
228
+ }
229
+ function lines(rt) {
230
+ let t = ''; try { t = fs.readFileSync(file(rt), 'utf8'); } catch { return []; }
231
+ const out = [];
232
+ for (const l of t.split('\n')) { if (!l) continue; try { const o = JSON.parse(l); if (isObj(o)) out.push(o); } catch { /* a torn line */ } }
233
+ return out;
234
+ }
235
+ /** Runs, oldest first, each with its labels { n → real | noise } (the newest label wins). */
236
+ function read(rt) {
237
+ const runs = new Map();
238
+ for (const l of lines(rt)) {
239
+ if (l.kind === 'run' && l.id) runs.set(l.id, { ...l, labels: {} });
240
+ else if (l.kind === 'label' && runs.has(l.run)) runs.get(l.run).labels[l.n] = l.label;
241
+ }
242
+ return [...runs.values()];
243
+ }
244
+ /** The PM's word on finding n (1-based) of a run: real or noise. */
245
+ function label(rt, run, n, lab, { by = 'pm:cli' } = {}) {
246
+ const r = read(rt).find((x) => x.id === run);
247
+ if (!r) return { ok: false, error: `there is no critic run ${one(run, 40)}: pmos lab critic stats lists them` };
248
+ const i = Number(n);
249
+ if (!Number.isInteger(i) || i < 1 || i > r.findings.length) return { ok: false, error: `run ${r.id} has ${r.findings.length} finding${r.findings.length === 1 ? '' : 's'}: give a number from 1` };
250
+ if (lab !== 'real' && lab !== 'noise') return { ok: false, error: 'the label is real or noise' };
251
+ append(rt, { kind: 'label', run: r.id, n: i, label: lab, by: one(by, 80), at: new Date().toISOString() });
252
+ return { ok: true, finding: r.findings[i - 1] };
253
+ }
254
+ /** The counts the Checker reads: runs, runs that did not run, findings, and how many the PM called real or noise. */
255
+ function stats(rt) {
256
+ const R = read(rt).filter((r) => !r.recheck);
257
+ const s = { runs: R.length, notRun: 0, flagged: 0, findings: 0, real: 0, noise: 0, unlabelled: 0, byCheck: {} };
258
+ for (const r of R) {
259
+ if (!r.ok) { s.notRun++; continue; }
260
+ if (r.findings.length) s.flagged++;
261
+ r.findings.forEach((f, i) => {
262
+ s.findings++;
263
+ s.byCheck[f.check] = (s.byCheck[f.check] || 0) + 1;
264
+ const l = r.labels[i + 1];
265
+ if (l === 'real') s.real++; else if (l === 'noise') s.noise++; else s.unlabelled++;
266
+ });
267
+ }
268
+ return s;
269
+ }
270
+
271
+ module.exports = { FILE, BASE, ORIGIN, MODEL, MAX_FINDINGS, IMAGE_RE, HTML_RE, off, principlesOf, rulesOf, checksFor, promptOf, parse, asFailed, critique, askVia, file, record, read, label, stats };
@@ -40,7 +40,7 @@
40
40
  *
41
41
  * JOB · VERSION · MAX_RESULTS · candidates(input) PURE · nextOf(cands) PURE · promptOf(skill, c, o) PURE
42
42
  * readRuns(rt) · appendRun(rt, line, now?) · spentIn(rt, month) · pagesDir(rt, run) · pendingFile(rt, run) · runSpecimenDir(rt, run)
43
- * pageRef(run, n, line) · guardProposal(entry, { run }) PURE · renderCheck(abs, { phone? }) · ensureReplay(rt) (phone: also at 390 px, nothing wider)
43
+ * pageRef(run, n, line) · guardProposal(entry, { run }) PURE · renderCheck(abs, { phone?, shots? }) · ensureReplay(rt) (phone: also at 390 px, nothing wider; shots: a folder for desk.png and phone.png, the design critic's eyes)
44
44
  * create(deps) → { tick(turn), finish(run, r), active(), status(), products(now) }
45
45
  */
46
46
  const fs = require('fs');
@@ -250,7 +250,7 @@ function guardProposal(e, { run }) {
250
250
  }
251
251
 
252
252
  /** Open one specimen in a headless browser, with the network shut but the fonts. → { ok, w, h, why? } */
253
- async function renderCheck(abs, { browser = null, phone = false } = {}) {
253
+ async function renderCheck(abs, { browser = null, phone = false, shots = '' } = {}) {
254
254
  let exe = browser;
255
255
  try { if (!exe) exe = require('./find-browser.js').findBrowser(); } catch { exe = null; }
256
256
  if (!exe) return { ok: false, why: 'there is no headless browser on this computer to prove it renders' };
@@ -268,14 +268,19 @@ async function renderCheck(abs, { browser = null, phone = false } = {}) {
268
268
  if (!m) return { ok: false, why: 'it has no body' };
269
269
  if (errors.length) return { ok: false, why: 'a script error: ' + errors[0] };
270
270
  if (m.h < 100 || m.w < 200 || (m.text < 20 && m.els < 10)) return { ok: false, why: `it renders almost nothing (${m.w}×${m.h}, ${m.els} elements)` };
271
+ // shots: the design critic's eyes (lib/design-critic.js): one desk and one phone screenshot in that folder, best effort
272
+ const saved = [];
273
+ const shoot = async (name, label) => { if (!shots) return; try { fs.mkdirSync(shots, { recursive: true }); const f = path.join(shots, name); await page.screenshot({ path: f, fullPage: true, timeout: 10000 }); saved.push({ abs: f, label }); } catch { /* the critic reads the HTML alone */ } };
274
+ await shoot('desk.png', 'desk 1280 px');
271
275
  // phone: the live round's viewport pin (lib/live-round.js; dry run finding a): at 390 px nothing may run wider than the screen
272
276
  if (phone) {
273
277
  await page.setViewportSize({ width: 390, height: 844 });
274
278
  const p = await page.evaluate(() => ({ w: document.documentElement.scrollWidth, h: document.documentElement.scrollHeight }));
275
279
  if (p.w > 398) return { ok: false, why: `it is wider than a phone: ${p.w} px at 390 px, so part of it is cut off` };
276
- return { ok: true, w: 390, h: p.h };
280
+ await shoot('phone.png', 'phone 390 px');
281
+ return { ok: true, w: 390, h: p.h, ...(saved.length ? { shots: saved } : {}) };
277
282
  }
278
- return { ok: true, w: m.w, h: m.h };
283
+ return { ok: true, w: m.w, h: m.h, ...(saved.length ? { shots: saved } : {}) };
279
284
  } catch (e) {
280
285
  return { ok: false, why: 'it did not open: ' + one(e && e.message, 160) };
281
286
  } finally { if (b) try { await b.close(); } catch { /* closed */ } }
@@ -12,6 +12,10 @@
12
12
  * --chat: the initiative chat's own agent started it, so the chat is told when the version renders
13
13
  * the live round (lib/live-round.js): the running server starts three runs now, or one on B; --propose
14
14
  * files its ✦ ask for the PM's ✓ instead (the initiative chat's way)
15
+ * pmos lab critic <file…> [--ws <id>] | critic checks [--root <dir>] | critic label <run> <n> real|noise | critic stats
16
+ * the design critic (lib/design-critic.js, initiative design-critic-pass): it reads screenshots or HTML
17
+ * against every standing design rule of the product, each a named check, through the running server
18
+ * (a read-only ask run). checks, label and stats need no server
15
19
  * pmos lab rule add --json - [--again] | rule list the PM's prototype rules (lib/prototype-rules.js): the chat's agent turns a correction
16
20
  * that is true of every prototype into a check. PMOS keeps it only when it fails its bad example and
17
21
  * passes its good one; --again re-adds a rule the PM undid, only when the PM says it again
@@ -23,7 +27,7 @@ const path = require('path');
23
27
  const dns = require('dns');
24
28
  const E = require('./idle-lab-engine.js');
25
29
 
26
- const COMMANDS = { lab: ['page', 'file', 'status', 'round', 'delete', 'undo', 'rule'] };
30
+ const COMMANDS = { lab: ['page', 'file', 'status', 'round', 'delete', 'undo', 'rule', 'critic'] };
27
31
  const GROUPS = { 'prototype-new': ['prototyped'], 'prototype-improve': ['improved'], 'scan-new': ['scanned', 'scan'], 'scan-improve': ['scanned', 'scan'] };
28
32
  const USAGE = [
29
33
  'usage: pmos lab page|file|status — the idle lab: PMOS prototypes and scans while you are away; each result waits under ✦ for your ✓',
@@ -44,6 +48,9 @@ const USAGE = [
44
48
  ' pmos lab rule add --json - [--again] a prototype rule from the PM\'s correction: { "title", "words", "tests": [{ "in": "text"|"attr"|"source", "re", "flags"? }],',
45
49
  ' "bad": "<html that breaks it>", "good": "<html that keeps it>" }. Kept only when it fails bad and passes good',
46
50
  ' pmos lab rule list the rules every prototype version is checked against before it opens',
51
+ ' pmos lab critic <file…> [--ws <id>] the design critic reads screenshots or HTML files (full paths) against the product\'s design rules',
52
+ ' pmos lab critic checks [--root <dir>] every standing design rule of the product, one named check each (no server needed)',
53
+ ' pmos lab critic label <run> <n> real|noise your word on finding n of a critic run · pmos lab critic stats runs, findings, real, noise',
47
54
  'A specimen must open and render; every claim must quote what was read. What is not proven is dropped. Nothing is sent.',
48
55
  ];
49
56
  const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (args[i + 1] === undefined || args[i + 1].startsWith('--') ? true : args[i + 1]) : undefined; };
@@ -182,6 +189,46 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
182
189
  return 0;
183
190
  }
184
191
 
192
+ if (verb === 'critic') {
193
+ const CR = require('./design-critic.js'), sub = args[1];
194
+ if (sub === 'checks') {
195
+ const root = typeof flag(args, 'root') === 'string' ? path.resolve(flag(args, 'root')) : process.cwd();
196
+ const K = CR.checksFor(root);
197
+ say(K.base ? `${root} has no design principles or design-rules.json yet, so the critic uses the ${K.checks.length} base checks:` : `${K.checks.length} checks from ${K.from.join(' and ')}:`);
198
+ for (const c of K.checks) say(` [${c.id}] ${c.title}: ${one(c.rule, 160)}`);
199
+ return 0;
200
+ }
201
+ if (run) { say('✗ a lab run cannot run the design critic'); return 1; }
202
+ const rt = () => require('./state-root.js').defaultRoot({ env });
203
+ if (sub === 'stats') {
204
+ const st = CR.stats(rt()), R = CR.read(rt()).filter((r) => !r.recheck);
205
+ say(`${st.runs} critic run${st.runs === 1 ? '' : 's'}${st.notRun ? ` (${st.notRun} did not run)` : ''} · ${st.flagged} flagged something · ${st.findings} finding${st.findings === 1 ? '' : 's'}: ${st.real} real, ${st.noise} noise, ${st.unlabelled} not labelled`);
206
+ for (const r of R.slice(-5).reverse()) if (r.ok && r.findings.length) say(` ${r.id} · ${r.at.slice(0, 16).replace('T', ' ')} · ${r.ini ? r.ini + ' v' + (r.version || 1) + ' ' + (r.key || '') : r.read.map((x) => path.basename(x.split(': ').pop())).join(', ')} · ${r.findings.length} finding${r.findings.length === 1 ? '' : 's'}`);
207
+ return 0;
208
+ }
209
+ if (sub === 'label') {
210
+ const [id, n, lab] = args.slice(2);
211
+ if (!id || !n || !lab) { say('usage: pmos lab critic label <run> <n> real|noise'); return 2; }
212
+ let by = ''; try { by = require('./actor.js').fromCli({ env }).by || ''; } catch { by = ''; }
213
+ const r = CR.label(rt(), id, n, lab, { by: by || 'pm:cli' });
214
+ if (!r.ok) { say('✗ ' + r.error); return 1; }
215
+ say(`✓ finding ${n} of ${id} is ${lab}: [${r.finding.check}] ${r.finding.what}`);
216
+ return 0;
217
+ }
218
+ const files = [];
219
+ for (let i = 1; i < args.length; i++) { if (args[i] === '--ws') { i++; continue; } if (!args[i].startsWith('--')) files.push(args[i]); }
220
+ if (!files.length || sub === 'help') { say('usage: pmos lab critic <screenshot or html file…> [--ws <id>] | checks [--root <dir>] | label <run> <n> real|noise | stats'); return 2; }
221
+ if (typeof call !== 'function') { say('✗ no PMOS server answers: start PMOS, then ask again'); return 1; }
222
+ const ws = flag(args, 'ws');
223
+ let r = null; try { r = await call('POST', '/api/lab/critic', { files: files.map((f) => path.resolve(f)), ...(typeof ws === 'string' ? { ws } : {}) }); } catch { r = null; }
224
+ if (!r) { say('✗ no PMOS server answers: start PMOS, then ask again'); return 1; }
225
+ if (!r.ok) { say('✗ ' + (r.error || 'the critic did not run')); return 1; }
226
+ say(r.findings.length ? `${r.findings.length} finding${r.findings.length === 1 ? '' : 's'} against ${r.checks} checks${r.base ? ' (the base set: this product has no design rules yet)' : ''} · run ${r.run}` : `✓ no rule broken (${r.checks} checks${r.base ? ', the base set' : ''}) · run ${r.run}`);
227
+ r.findings.forEach((f, i) => say(` ${i + 1}. [${f.check}] ${f.title} · ${f.screen ? f.screen + ': ' : ''}${f.what}${f.where ? ' (' + f.where + ')' : ''}`));
228
+ if (r.findings.length) say(`Label each: pmos lab critic label ${r.run} <n> real|noise`);
229
+ return 0;
230
+ }
231
+
185
232
  if (verb === 'rule') {
186
233
  // the PM's prototype rules: the chat's agent adds one from a correction; a background lab run never does
187
234
  if (run) { say('✗ a lab run cannot change the PM\'s prototype rules'); return 1; }
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+ /* launch-cli.js — `pmos launch …`: what is not ready before a launch date (initiative launch-readiness-check, lib/launch-readiness.js).
3
+ * pmos launch check <initiative> [--date YYYY-MM-DD] [--json] open tasks, tracker tickets, sign-offs and questions before the launch
4
+ * pmos launch list [--days N] [--json] every initiative with a launch in the next N days (14), with its verdict
5
+ * The repository is the one this terminal is in (or --root). Read-only: it calls no tracker, sends nothing and writes no record.
6
+ * Exit codes: 0 done, 1 refused (no launch date, no such initiative), 2 usage. */
7
+ const path = require('path');
8
+ const { execFileSync } = require('child_process');
9
+ const LR = require('./launch-readiness.js');
10
+
11
+ const COMMANDS = { launch: ['check', 'list'] };
12
+ const USAGE = [
13
+ 'usage: pmos launch check|list — what is not ready before a launch date',
14
+ ' pmos launch check <initiative> [--date YYYY-MM-DD] open tasks, tracker tickets, sign-offs with no answer and open questions',
15
+ ' The launch date: --date, else a ◇ milestone named launch, go-live, release or ship, else the committed end, else the last ◇ milestone.',
16
+ ' pmos launch list [--days N] every initiative with a launch in the next N days (default 14), and its verdict',
17
+ ' every command: [--json] [--root <repository>]',
18
+ 'Read-only: it calls no tracker and sends nothing. Read the tracker first so the tickets are fresh.',
19
+ ];
20
+
21
+ function parseArgs(argv) {
22
+ const out = { _: [] };
23
+ for (let i = 0; i < argv.length; i++) {
24
+ const t = argv[i];
25
+ if (!t.startsWith('--')) { out._.push(t); continue; }
26
+ const eq = t.indexOf('=');
27
+ const key = eq > 0 ? t.slice(2, eq) : t.slice(2);
28
+ if (key === 'json' || key === 'help') out[key] = true;
29
+ else if (eq > 0) out[key] = t.slice(eq + 1);
30
+ else if (argv[i + 1] !== undefined) out[key] = argv[++i];
31
+ else out[key] = '';
32
+ }
33
+ return out;
34
+ }
35
+ function repoRoot(cwd) {
36
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
37
+ catch { return cwd; }
38
+ }
39
+ const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
40
+
41
+ function run(argv, { say = console.log, cwd = process.cwd(), now = () => new Date() } = {}) {
42
+ const a = parseArgs(argv[0] === 'launch' ? argv.slice(1) : argv);
43
+ const sub = a._[0];
44
+ const fail = (error, code = 1) => { if (a.json) say(JSON.stringify({ ok: false, error })); else say('✗ ' + error); return code; };
45
+ if (!sub || a.help || sub === 'help') { USAGE.forEach((l) => say(l)); return sub || a.help ? 0 : 2; }
46
+ if (!COMMANDS.launch.includes(sub)) { say(`✗ pmos launch ${sub} is not a command`); USAGE.forEach((l) => say(l)); return 2; }
47
+ for (const k of Object.keys(a)) if (!['_', 'json', 'help', 'root', 'date', 'days', 'today'].includes(k)) return fail(`unknown option --${k}`, 2);
48
+ if (a.date !== undefined && (sub !== 'check' || !DAY_RE.test(a.date))) return fail(sub !== 'check' ? '--date is an option of check' : '--date takes YYYY-MM-DD', 2);
49
+ if (a.today !== undefined && !DAY_RE.test(a.today)) return fail('--today takes YYYY-MM-DD', 2);
50
+ const root = a.root ? path.resolve(cwd, a.root) : repoRoot(cwd);
51
+ const today = a.today || now().toISOString().slice(0, 10);
52
+ const SR = require('./stage-read.js');
53
+ const { w, ctx } = SR.cliCtx(root);
54
+ if (!ctx.stateDirFor()) return fail('this repository has no PMOS state folder (pmos/state, state or .pmos)');
55
+
56
+ if (sub === 'check') {
57
+ const id = a._[1];
58
+ if (!id || a._.length > 2) { say('usage: pmos launch check <initiative> [--date YYYY-MM-DD] [--json]'); return 2; }
59
+ const got = LR.read(root, id, { date: a.date, ctx, w });
60
+ if (got.error) return fail(got.error);
61
+ if (!got.launch) return fail(`${id} has no launch date: no ◇ milestone and no committed end. Give one with --date YYYY-MM-DD.`);
62
+ const res = LR.check(got.input, { launch: got.launch.date, launchTask: got.launch.task, today });
63
+ if (a.json) { say(JSON.stringify({ ok: true, initiative: id, title: got.title, launchFrom: got.launch.from, ...res })); return 0; }
64
+ say(LR.render(res, { title: got.title, id, launchFrom: LR.FROM_WORDS[got.launch.from] }));
65
+ return 0;
66
+ }
67
+
68
+ // list
69
+ const n = a.days === undefined ? 14 : Number(a.days);
70
+ if (!Number.isInteger(n) || n < 0 || n > 365) return fail('--days takes a whole number from 0 to 365', 2);
71
+ const rowsLib = require('./initiative-rows.js');
72
+ const d = rowsLib.deriveNow(root);
73
+ if (!d.ok) return fail(d.error || 'the initiative records could not be read');
74
+ const until = new Date(Date.parse(today + 'T00:00:00Z') + n * 86400000).toISOString().slice(0, 10);
75
+ const out = [];
76
+ for (const row of d.rows || []) {
77
+ if (!row || row.ok === false || row.stopped) continue;
78
+ let got; try { got = LR.read(root, row.id, { ctx, w }); } catch { continue; }
79
+ if (!got || got.error || !got.launch || got.launch.date < today || got.launch.date > until) continue;
80
+ const res = LR.check(got.input, { launch: got.launch.date, launchTask: got.launch.task, today });
81
+ out.push({ initiative: row.id, title: got.title, launch: res.launch, daysLeft: res.daysLeft, launchFrom: got.launch.from, verdict: res.verdict, items: res.items.length, notes: res.notes.length });
82
+ }
83
+ out.sort((x, y) => x.launch.localeCompare(y.launch) || x.initiative.localeCompare(y.initiative));
84
+ if (a.json) { say(JSON.stringify({ ok: true, today, until, launches: out })); return 0; }
85
+ if (!out.length) { say(`No launch in the next ${n} days.`); return 0; }
86
+ for (const x of out) say(`${x.launch} (${x.daysLeft === 0 ? 'today' : 'in ' + x.daysLeft + (x.daysLeft === 1 ? ' day' : ' days')}) · ${x.title} · ${x.verdict}${x.items ? ' · ' + x.items + (x.items === 1 ? ' item' : ' items') + ' not ready' : ''} · pmos launch check ${x.initiative}`);
87
+ return 0;
88
+ }
89
+
90
+ module.exports = { run, COMMANDS, USAGE };
@@ -0,0 +1,176 @@
1
+ 'use strict';
2
+ /* launch-readiness.js — what is not ready before an initiative's launch date (initiative launch-readiness-check; bet A172 with A188 and
3
+ * A194 in pmos-ideas/proofs). Works on any product built with PMOS: it reads only the initiative's own records.
4
+ *
5
+ * launchOf({ tasks, end, date }) → { date, from } | null PURE. The launch date: `date` (--date) first, then a ◇ milestone task whose
6
+ * title says launch, go-live, release or ship (the latest), then the committed end, then the last
7
+ * dated ◇ milestone. from: 'given' | 'milestone' | 'end' | 'last-milestone'.
8
+ * check(input, { launch, launchTask, today, idleDays, staleDays }) → the result PURE. launchTask: the id of the ◇ milestone the date came
9
+ * from (launchOf().task), which is not itself flagged. input:
10
+ * tasks [{ id, title, state, owner, due, milestone }] `pmos task list --all` rows (lib/stage-read.js tasksOf)
11
+ * tracker { fetchedAt, tickets: [reading] } | null the last tracker reading (lib/jira-status.js readSnapshot)
12
+ * signoffs [{ id, who, what, asked, due, state }] | null null: this product records no sign-offs (lib/signoffs.js)
13
+ * questions [{ owner, text, n }] the initiative's held questions (lib/question-batch.js)
14
+ * gaps [{ ticket, n, q }] open questions the ticket dry-run found, when present
15
+ * read(root, ini, o) → { input, launch, title } | { error } the I/O: reads the records above, writes nothing.
16
+ *
17
+ * THE RESULT: { launch, daysLeft, verdict: 'ready' | 'at risk' | 'no data', counts, items: [{ kind, id, title, why, who? }], notes: [line] }.
18
+ * kind: task | ticket | signoff | question. A reading is never counted as ready by default: no tasks and no tickets is 'no data', a
19
+ * tracker reading older than `staleDays` adds a note with its age, and a product with no sign-off record says so. Nothing writes. */
20
+
21
+ const DAY = 86400000;
22
+ const IDLE_DAYS = 14;
23
+ const STALE_DAYS = 2;
24
+ const LAUNCH_WORDS = /\b(launch|go[- ]?live|release|ship|cut-?over)\b/i;
25
+ const OPEN_TASK = new Set(['To do', 'In progress']);
26
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
27
+ const one = (v, n = 140) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
28
+ const dayOf = (v) => { const m = /^(\d{4}-\d{2}-\d{2})/.exec(String(v || '')); return m ? m[1] : ''; };
29
+ const days = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(a + 'T00:00:00Z')) / DAY);
30
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
31
+
32
+ /** The launch date of an initiative. PURE. */
33
+ function launchOf({ tasks, end, date } = {}) {
34
+ if (dayOf(date)) return { date: dayOf(date), from: 'given' };
35
+ const ms = (tasks || []).filter((t) => isObj(t) && t.milestone && dayOf(t.due)).sort((a, b) => dayOf(a.due).localeCompare(dayOf(b.due)));
36
+ const named = ms.filter((t) => LAUNCH_WORDS.test(String(t.title || '')));
37
+ if (named.length) { const t = named[named.length - 1]; return { date: dayOf(t.due), from: 'milestone', title: one(t.title, 80), task: String(t.id || '') }; }
38
+ if (dayOf(end)) return { date: dayOf(end), from: 'end' };
39
+ if (ms.length) { const t = ms[ms.length - 1]; return { date: dayOf(t.due), from: 'last-milestone', title: one(t.title, 80), task: String(t.id || '') }; }
40
+ return null;
41
+ }
42
+
43
+ function taskItems(tasks, launch, today, launchTask) {
44
+ const out = [];
45
+ for (const t of tasks || []) {
46
+ if (!isObj(t) || !OPEN_TASK.has(t.state)) continue;
47
+ if (launchTask && String(t.id) === launchTask) continue; // the ◇ launch milestone itself is open until the launch
48
+ const due = dayOf(t.due);
49
+ let why;
50
+ if (due && due > launch) why = `due ${due}, after the launch`;
51
+ else if (due && due < today) why = `past its date (${due}), still ${t.state}`;
52
+ else if (due) why = `${t.state}, due ${due}`;
53
+ else why = `${t.state}, no date`;
54
+ out.push({ kind: 'task', id: String(t.id || ''), title: one(t.title, 120), why, ...(t.owner ? { who: one(t.owner, 60) } : {}) });
55
+ }
56
+ return out;
57
+ }
58
+
59
+ function ticketItems(tracker, today, idleDays) {
60
+ const out = [];
61
+ if (!tracker) return out;
62
+ for (const r of tracker.tickets || []) {
63
+ if (!isObj(r) || r.category === 'done') continue;
64
+ const parts = [String(r.status || 'Open')];
65
+ const upd = dayOf(r.updated);
66
+ const idle = upd ? days(upd, today) : null;
67
+ if (idle != null && idle >= idleDays) parts.push(`not moved for ${idle} days`);
68
+ if (r.flagged) parts.push(one(r.reason || 'flagged', 80));
69
+ if (r.stale) parts.push('not in the last tracker reading');
70
+ out.push({ kind: 'ticket', id: String(r.key || ''), title: one(r.summary, 120), why: parts.join(', '), ...(r.assignee ? { who: one(r.assignee, 60) } : {}), ...(idle != null ? { idle } : {}) });
71
+ }
72
+ return out.sort((a, b) => (b.idle || 0) - (a.idle || 0));
73
+ }
74
+
75
+ function signoffItems(signoffs, today) {
76
+ const out = [];
77
+ for (const s of signoffs || []) {
78
+ if (!isObj(s) || s.state !== 'open') continue;
79
+ const asked = dayOf(s.asked), due = dayOf(s.due);
80
+ const parts = [asked ? `asked ${asked}, ${plural(days(asked, today), 'day', 'days')} with no answer` : 'no answer recorded'];
81
+ if (due && due < today) parts.push(`was due ${due}`);
82
+ out.push({ kind: 'signoff', id: 'signoff:' + String(s.id || ''), title: one(s.what, 120), why: parts.join(', '), who: one(s.who || 'someone outside the team', 60) });
83
+ }
84
+ return out;
85
+ }
86
+
87
+ function questionItems(questions, gaps) {
88
+ const out = [];
89
+ for (const q of questions || []) if (isObj(q) && q.text) out.push({ kind: 'question', id: String(q.key || ''), title: one(q.text, 200), why: 'held: PMOS found no source', who: one(q.owner || '', 60) });
90
+ for (const g of gaps || []) if (isObj(g) && g.q) out.push({ kind: 'question', id: String(g.ticket || ''), title: one(g.q, 200), why: `open question in ${g.ticket || 'a ticket'}` });
91
+ return out;
92
+ }
93
+
94
+ /** The readiness of one initiative for its launch. PURE. */
95
+ function check(input = {}, { launch, launchTask = '', today, idleDays = IDLE_DAYS, staleDays = STALE_DAYS } = {}) {
96
+ const t0 = dayOf(today) || new Date().toISOString().slice(0, 10);
97
+ const L = dayOf(launch);
98
+ const tasks = (input.tasks || []).filter(isObj);
99
+ const tracker = isObj(input.tracker) ? input.tracker : null;
100
+ const items = [
101
+ ...taskItems(tasks, L || '9999-12-31', t0, launchTask),
102
+ ...ticketItems(tracker, t0, idleDays),
103
+ ...signoffItems(input.signoffs, t0),
104
+ ...questionItems(input.questions, input.gaps),
105
+ ];
106
+ const notes = [];
107
+ const read = tracker && dayOf(tracker.fetchedAt);
108
+ if (!tracker) notes.push('No tracker reading for this initiative: run the tracker read first, or the tickets are not counted.');
109
+ else if (read && days(read, t0) > staleDays) notes.push(`The tracker reading is ${plural(days(read, t0), 'day', 'days')} old (${read}). Read the tracker again before you trust this.`);
110
+ if (input.signoffs == null) notes.push('Sign-offs: not recorded for this product, so outside answers are not checked.');
111
+ const nTickets = tracker ? (tracker.tickets || []).length : 0;
112
+ const counts = {
113
+ tasks: { done: tasks.filter((t) => t.state === 'Done').length, total: tasks.filter((t) => t.state !== "Won't do" && t.state !== 'Archived').length },
114
+ tickets: { done: tracker ? (tracker.tickets || []).filter((r) => isObj(r) && r.category === 'done').length : 0, total: nTickets },
115
+ signoffs: items.filter((x) => x.kind === 'signoff').length,
116
+ questions: items.filter((x) => x.kind === 'question').length,
117
+ };
118
+ const verdict = !tasks.length && !nTickets ? 'no data' : items.length ? 'at risk' : 'ready';
119
+ return { launch: L || null, daysLeft: L ? days(t0, L) : null, today: t0, verdict, counts, items, notes };
120
+ }
121
+
122
+ /** One paragraph for a terminal or a chat. */
123
+ function render(res, { title = '', id = '', launchFrom } = {}) {
124
+ const name = title || id;
125
+ const when = res.daysLeft == null ? '' : res.daysLeft < 0 ? `${plural(-res.daysLeft, 'day', 'days')} ago` : res.daysLeft === 0 ? 'today' : `in ${plural(res.daysLeft, 'day', 'days')}`;
126
+ const head = `${name}: launch ${res.launch}${when ? ' (' + when + ')' : ''}${launchFrom ? ', from ' + launchFrom : ''}. ${res.verdict === 'ready' ? 'Ready: nothing open.' : res.verdict === 'no data' ? 'No data: no task and no tracker ticket.' : 'At risk: ' + plural(res.items.length, 'item is', 'items are') + ' not ready.'}`;
127
+ const out = [head];
128
+ const c = res.counts;
129
+ // zero is silence: a part with nothing in it is left out
130
+ const sum = [c.tasks.total ? `tasks ${c.tasks.done} of ${c.tasks.total} done` : '', c.tickets.total ? `tickets ${c.tickets.done} of ${c.tickets.total} done` : '',
131
+ c.signoffs ? `${plural(c.signoffs, 'sign-off', 'sign-offs')} waiting` : '', c.questions ? plural(c.questions, 'open question', 'open questions') : ''].filter(Boolean);
132
+ if (sum.length) out.push(sum.join(' · ').replace(/^./, (x) => x.toUpperCase()) + '.');
133
+ const LABEL = { task: 'Tasks', ticket: 'Tracker tickets', signoff: 'Sign-offs with no answer', question: 'Open questions' };
134
+ for (const k of ['signoff', 'ticket', 'task', 'question']) {
135
+ const xs = res.items.filter((x) => x.kind === k);
136
+ if (!xs.length) continue;
137
+ out.push('', `${LABEL[k]} (${xs.length}):`);
138
+ for (const x of xs) out.push(` ${x.id ? x.id + ' ' : ''}${x.title} | ${x.why}${x.who ? ' | ' + x.who : ''}`);
139
+ }
140
+ if (res.notes.length) out.push('', ...res.notes);
141
+ return out.join('\n');
142
+ }
143
+
144
+ const FROM_WORDS = { given: 'the date you gave', milestone: 'the milestone', end: 'the committed end', 'last-milestone': 'the last milestone' };
145
+
146
+ /** Read one initiative's records. Writes nothing. o: { date, ctx, w } (lib/stage-read.js cliCtx). */
147
+ function read(root, ini, o = {}) {
148
+ const SR = require('./stage-read.js');
149
+ const { w, ctx } = o.ctx ? { w: o.w, ctx: o.ctx } : SR.cliCtx(root);
150
+ if (!ctx.stateDirFor()) return { error: 'this repository has no PMOS state folder (pmos/state, state or .pmos)' };
151
+ const r = SR.rowOf(ctx, w, ini);
152
+ if (!r || !r.ok) return { error: (r && r.error) || `no initiative ${ini}` };
153
+ let tasks = [];
154
+ try { tasks = SR.tasksOf(ctx, w, ini); } catch { tasks = []; }
155
+ const launch = launchOf({ tasks, end: r.row.end, date: o.date });
156
+ let tracker = null;
157
+ try {
158
+ const snap = require('./jira-status.js').readSnapshot(root, ini);
159
+ if (snap) tracker = { fetchedAt: snap.fetchedAt, tickets: [...snap.tickets.values()] };
160
+ } catch { tracker = null; }
161
+ // sign-offs and ticket gaps come from lib/signoffs.js and the ticket dry-run when this PMOS has them; without them, nothing is guessed
162
+ let signoffs = null, gaps = [];
163
+ try {
164
+ const SO = require('./signoffs.js'), JT = require('./jira-tickets.js');
165
+ if (typeof SO.list === 'function' && typeof SO.fileOf === 'function' && typeof JT.stateDirOf === 'function') signoffs = SO.list(SO.fileOf(JT.stateDirOf(root)), { ini });
166
+ } catch { signoffs = null; }
167
+ try { const JT = require('./jira-tickets.js'); if (typeof JT.dryRunGaps === 'function') gaps = JT.dryRunGaps(root, ini) || []; } catch { gaps = []; }
168
+ let questions = [];
169
+ try {
170
+ const held = require('./routes-proposals.js').heldOf(ctx, w).filter((h) => h.ini === ini);
171
+ questions = require('./question-batch.js').questionsOf(held, { pm: 'PM' });
172
+ } catch { questions = []; }
173
+ return { title: r.row.title || ini, launch, input: { tasks, tracker, signoffs, questions, gaps } };
174
+ }
175
+
176
+ module.exports = { launchOf, check, render, read, FROM_WORDS, IDLE_DAYS, STALE_DAYS, LAUNCH_WORDS };
@@ -35,6 +35,10 @@
35
35
  * each rule the chat's agent adds from a correction). A version that breaks one gets ONE fix run (fixPromptOf) given only the failed lines;
36
36
  * then it is rendered and checked again. It opens either way: fixed ("PMOS fixed n things before showing you this"), or with the rule it
37
37
  * still breaks, never hidden. A fix that breaks the render puts the draft back. The draft is kept next to it as <key>.draft.html.
38
+ * THE CRITIC (initiative design-critic-pass, bet 4 of the factory line). After the rules, a read-only critic run (lib/design-critic.js, deps.critic:
39
+ * the server's ask path) reads the version's desk and phone screenshots and its HTML against every standing design rule of the product, each
40
+ * a named check. Its findings join the same one fix run; after the fix it reads only the flagged checks again, so "fixed" is never claimed
41
+ * unchecked. A critic that cannot run never holds the version. PMOS_CRITIC=off, or no deps.critic, runs none.
38
42
  * LESSONS. Every feedback sentence is a Lessons line of the experiment (lib/artefacts.js); ✓ and ✕ add theirs (lib/routes-proposals.js).
39
43
  * The specimens a round made are Specimens lines; the one the PM keeps is its `kept` field.
40
44
  *
@@ -62,6 +66,7 @@ const PR = require('./proposals.js');
62
66
  const LAB = require('./idle-lab.js');
63
67
  const E = require('./idle-lab-engine.js');
64
68
  const RULES = require('./prototype-rules.js');
69
+ const CR = require('./design-critic.js');
65
70
  const DS = require('./design-system.js');
66
71
 
67
72
  const JOB = 'live-round';
@@ -315,7 +320,7 @@ function fixPromptOf({ file, dir, failed }) {
315
320
  const L = ['You fix ONE prototype before the product manager sees it. It renders, but it breaks rules the PM set for every prototype. Be quick: no planning, no questions, no summary.',
316
321
  '', `The prototype: ${file}. Read it, then overwrite it with the Write tool.`, '', 'The rules it breaks, each with the lines that broke it:'];
317
322
  for (const f of failed || []) {
318
- L.push(`- ${one(f.title, 80)}${f.words ? ' (the PM said: "' + one(f.words, 200) + '")' : ''}`);
323
+ L.push(`- ${one(f.title, 80)}${f.words ? (f.critic ? ' (the design rule: "' : ' (the PM said: "') + one(f.words, 200) + '")' : ''}`);
319
324
  for (const l of f.lines || []) L.push(` > ${one(l, 160)}`);
320
325
  }
321
326
  L.push('', 'Change only what these lines need. Keep everything else as it is: the screens, their ids, every data-* attribute and copy key, the CSS and <meta name="pmos-changed">.',
@@ -530,15 +535,17 @@ function roundLine(R, now) {
530
535
  /**
531
536
  * deps: { runtimeDir() → folder, product(ws) → { w: { id, root }, dir } | null, info(ws, ini) → { title, board, description?, intent? } | null,
532
537
  * spawn(spec) → session (server spawnSession: { name, agent, ws, origin, initialInput, initiative, writePaths, addDirs, onDone }),
533
- * stop(session), render?(abs) → Promise<{ ok, w, h, why? }>, artefact?(dir, line) (lib/artefacts.js set, as agent:live-round),
538
+ * stop(session), render?(abs, { shots? }) → Promise<{ ok, w, h, why?, shots? }>, critic?(prompt, { key, addDirs }) → Promise<text | null>, artefact?(dir, line) (lib/artefacts.js set, as agent:live-round),
534
539
  * ownRoot? (PMOS's own folder, for the scaffold), pollMs?, stallMs?, now?() , warn(what, e) }
535
540
  */
536
541
  function create(deps) {
537
542
  const warn = deps.warn || (() => {});
538
543
  const now = () => (deps.now ? deps.now() : Date.now());
539
- const render = deps.render || ((abs) => E.renderCheck(abs, { phone: true })); // proven at 390 px too: the viewport pin
544
+ const render = deps.render || ((abs, o = {}) => E.renderCheck(abs, { phone: true, ...o })); // proven at 390 px too: the viewport pin; o.shots: the critic's screenshots
540
545
  // the PM's prototype rules (lib/prototype-rules.js), read for each version so an Undo in Settings counts at once
541
546
  const rulesOf = deps.rules || (() => { try { return RULES.active(deps.runtimeDir ? deps.runtimeDir() : null); } catch (e) { warn('prototype rules', e); return []; } });
547
+ // the design critic (lib/design-critic.js, initiative design-critic-pass): deps.critic is the server's read-only ask path; none, no critic
548
+ const ask = typeof deps.critic === 'function' ? deps.critic : null;
542
549
  const pollMs = deps.pollMs || 1000;
543
550
  const rounds = new Map(); // id → round
544
551
 
@@ -684,7 +691,7 @@ function create(deps) {
684
691
  let v;
685
692
  if (!st || !st.isFile()) v = { ok: false, why: 'the run ended without writing its file' };
686
693
  else if (st.size > 2e6) v = { ok: false, why: 'the file is over 2 MB' };
687
- else { try { v = await render(s.abs); } catch (e) { v = { ok: false, why: 'it did not open: ' + one(e && e.message, 120) }; } }
694
+ else { try { v = await render(s.abs, { shots: shotsDir(R, s) }); } catch (e) { v = { ok: false, why: 'it did not open: ' + one(e && e.message, 120) }; } }
688
695
  if (s.state !== 'proving') return; // stopped while it rendered (Undo, the budget)
689
696
  const fx = s.fixing || null;
690
697
  if ((!v || !v.ok) && fx && fx.draft) {
@@ -695,9 +702,21 @@ function create(deps) {
695
702
  if (!v || !v.ok) { s.state = 'working'; return notMade(R, s, 'not proven: ' + ((v && v.why) || 'it did not render')); }
696
703
  if (!fx) {
697
704
  let failed = []; try { failed = RULES.run(fs.readFileSync(s.abs, 'utf8'), rulesOf()); } catch (e) { warn('prototype rules', e); failed = []; }
705
+ // then the critic: every standing design rule of the product as a named check; its findings join the one fix run
706
+ const crit = await critic(R, s, v);
707
+ if (s.state !== 'proving') return;
708
+ if (crit) failed = failed.concat(crit);
698
709
  if (failed.length && fix(R, s, failed, v, cost)) return;
699
710
  } else if (!fx.left) {
700
- try { fx.left = RULES.run(fs.readFileSync(s.abs, 'utf8'), fx.failed.map((f) => rulesOf().find((r) => r.id === f.id)).filter(Boolean)); } catch (e) { warn('prototype rules', e); fx.left = fx.failed; }
711
+ const plain = fx.failed.filter((f) => !f.critic), cf = fx.failed.filter((f) => f.critic);
712
+ try { fx.left = RULES.run(fs.readFileSync(s.abs, 'utf8'), plain.map((f) => rulesOf().find((r) => r.id === f.id)).filter(Boolean)); } catch (e) { warn('prototype rules', e); fx.left = plain; }
713
+ if (cf.length) {
714
+ // the critic reads only the checks it flagged; a fix is never counted as done unless it read the version again
715
+ const again = await critic(R, s, v, cf.map((f) => f.check));
716
+ if (s.state !== 'proving') return;
717
+ const still = again ? new Set(again.map((f) => f.check)) : null;
718
+ fx.left = fx.left.concat(still ? cf.filter((f) => still.has(f.check)) : cf);
719
+ }
701
720
  }
702
721
  const fd = s.fixing || null; // set by fix(), also when its run could not start
703
722
  if (fd) {
@@ -717,6 +736,22 @@ function create(deps) {
717
736
  if (deps.artefact && R.slots.length === 1 && R.from !== 'cli') try { deps.artefact(R.dir, { scope: 'experiment:' + R.ini, artefact: 'specimens', field: 'kept', text: one(`Version ${R.n}: ${s.said || s.title} (${LAB.specimenUrl(s.file)})`, 600), sources: [{ label: 'live round', ref: LAB.specimenUrl(s.file) }] }, 'agent:live-round'); } catch (e) { warn('live round kept', e); }
718
737
  write(R); settle(R);
719
738
  }
739
+ /** The critic's screenshots of a version: <runtime>/idle-lab/critic/<round>/<key>/ (desk.png, phone.png), never in the run's own folder. */
740
+ function shotsDir(R, s) { return ask && R.rt && !CR.off(process.env) ? path.join(R.rt, 'idle-lab', 'critic', String(R.id), String(s.key)) : ''; }
741
+ /** One critic pass on a rendered version (only: the checks to read again after the fix). → failed entries, or null when it did not run.
742
+ * It never holds the version: no session, a timeout or an unreadable answer is null, and the ledger says so. */
743
+ async function critic(R, s, v, only = null) {
744
+ if (!ask || CR.off(process.env)) return null;
745
+ let root = ''; try { const p = deps.product ? deps.product(R.ws) : null; root = (p && p.w && p.w.root) || ''; } catch { root = ''; }
746
+ let checks = []; try { checks = CR.checksFor(root).checks; } catch (e) { warn('design critic checks', e); return null; }
747
+ const targets = [...((v && Array.isArray(v.shots)) ? v.shots : []), { abs: s.abs, label: 'page source' }];
748
+ s.progress = { now: only ? 'Checking the fix against your design rules' : 'Checking it against your design rules', done: 0, total: 0 };
749
+ write(R);
750
+ let r; try { r = await CR.critique(ask, { checks, targets, only }); } catch (e) { r = { ok: false, why: one(e && e.message, 120) }; }
751
+ try { CR.record(R.rt, { from: 'live-round', ws: R.ws, ini: R.ini, version: R.n, key: s.key, recheck: !!only, read: targets.map((t) => t.label + ': ' + t.abs), checks: r.checks || [], ok: r.ok, why: r.why, findings: r.findings, ms: r.ms }); } catch (e) { warn('design critic ledger', e); }
752
+ if (s.state === 'proving') s.progress = null;
753
+ return r.ok ? CR.asFailed(r.findings, checks) : null;
754
+ }
720
755
  /** The one fix run: the draft is kept, the run gets only the failed lines and writes the same file. false when it could not start. */
721
756
  function fix(R, s, failed, v, cost) {
722
757
  const fx = { failed, v, cost: Number.isFinite(cost) ? cost : null, draft: s.abs.replace(/\.html$/, '.draft.html'), session: null, run: s.run + '-fix', done: false, left: null };
@@ -54,6 +54,9 @@ const VERBS = Object.freeze({
54
54
  // Not a pm-os-absorb verb (run: null): workspace-data-freshness added it through the same table.
55
55
  calendar: Object.freeze({ module: 'calendar-cli.js', run: null, guide: 'cli.md',
56
56
  help: 'pmos calendar import|status — the calendar events an agent session read, saved for Briefing and Calendar (pmos calendar help)' }),
57
+ // Not a pm-os-absorb verb (run: null): launch-readiness-check added it through the same table.
58
+ launch: Object.freeze({ module: 'launch-cli.js', run: null, guide: 'cli.md',
59
+ help: 'pmos launch check|list — what is not ready before a launch date: tasks, tracker tickets, sign-offs, open questions (pmos launch help)' }),
57
60
  // Not a pm-os-absorb verb (run: null): tracker-read-freshness added it through the same table.
58
61
  tracker: Object.freeze({ module: 'tracker-cli.js', run: null, guide: 'cli.md',
59
62
  help: 'pmos tracker done|status — record when the tracker-refresh skill finished a read of this repository (pmos tracker help)' }),
@@ -26,6 +26,9 @@
26
26
  * GET /api/lab/rules → { ok, rules: [{ id, title, words, at, on, seed, undoneAt? }] } the PM's prototype rules (lib/prototype-rules.js)
27
27
  * POST /api/lab/rules { op: add, rule, again? } | { op: undo | restore, id } → { ok, rule } add: `pmos lab rule add` (the chat's agent, no
28
28
  * Origin, D98); undo and restore: Settings › PMOS › Prototype rules (a page press)
29
+ * POST /api/lab/critic { files: [abs], ws? } → { ok, run, findings, checks, from, base } | { ok: false, error } the design critic
30
+ * (lib/design-critic.js) on any screenshots or HTML, against the workspace product's own rules:
31
+ * `pmos lab critic` (no Origin, D98, like the live round); a read-only ask run, recorded in its ledger
29
32
  * POST /api/lab/comment { ws, ini, file, el?, label?, text, x?, y?, send? } → { ok, id } a comment pinned to an element (send: it was
30
33
  * sent to PMOS as the next change; else it is kept for the team)
31
34
  *
@@ -344,6 +347,28 @@ function protoRules(ctx, res, b, by) {
344
347
  ctx.json(res, r);
345
348
  return true;
346
349
  }
350
+ /** POST /api/lab/critic: one critic pass on the files, against the product's own design rules; recorded in <runtime>/design-critic.jsonl. */
351
+ async function designCritic(ctx, res, b) {
352
+ const CR = require('./design-critic.js'), path = require('path');
353
+ const w = wsOf(ctx, typeof b.ws === 'string' && b.ws ? b.ws : null);
354
+ const files = Array.isArray(b.files) ? b.files.slice(0, 8) : [];
355
+ const targets = [];
356
+ for (const f of files) {
357
+ const abs = typeof f === 'string' && path.isAbsolute(f) ? path.resolve(f) : '';
358
+ if (!abs || !(CR.IMAGE_RE.test(abs) || CR.HTML_RE.test(abs))) return fail(ctx, res, 400, `${String(f).slice(0, 120)}: give the full path of a screenshot (.png, .jpg, .webp) or an HTML file`);
359
+ let st = null; try { st = fs.statSync(abs); } catch { st = null; }
360
+ if (!st || !st.isFile() || st.size > 15e6) return fail(ctx, res, 400, `${abs}: no such file, or over 15 MB`);
361
+ targets.push({ abs, label: path.basename(abs) });
362
+ }
363
+ if (!targets.length) return fail(ctx, res, 400, 'files lists the screenshots or HTML files to check');
364
+ if (CR.off(process.env)) return fail(ctx, res, 409, 'the design critic is off (PMOS_CRITIC=off)');
365
+ const K = CR.checksFor(w ? w.root : '');
366
+ const r = await CR.critique(typeof ctx.critic === 'function' ? ctx.critic : CR.askVia(ctx.spawnSession), { checks: K.checks, targets });
367
+ const run = ctx.runtimeDir ? CR.record(ctx.runtimeDir, { from: 'cli', ws: w ? w.id : '', read: targets.map((t) => t.abs), checks: r.checks || [], ok: r.ok, why: r.why, findings: r.findings, ms: r.ms }) : null;
368
+ if (!r.ok) return fail(ctx, res, 502, r.why);
369
+ ctx.json(res, { ok: true, run, findings: r.findings, checks: r.checks.length, from: K.from, base: K.base });
370
+ return true;
371
+ }
347
372
  const readsDrop = (dir, b) => LAB.readLines(LAB.ledgerFile(dir)).some((l) => l.kind === 'drop' && l.batch === b);
348
373
 
349
374
  module.exports = {
@@ -353,12 +378,17 @@ module.exports = {
353
378
  if (req.method === 'GET') { const fn = READS[p0]; if (!fn) return fail(ctx, res, 404, 'not found'); return fn(ctx, res, url); }
354
379
  if (req.method !== 'POST') return fail(ctx, res, 405, 'GET or POST only');
355
380
  const fn = WRITES[p0];
356
- if (!fn && !['/api/lab/round', '/api/lab/delete', '/api/lab/restore', '/api/lab/rules'].includes(p0)) return fail(ctx, res, 404, 'not found');
381
+ if (!fn && !['/api/lab/round', '/api/lab/delete', '/api/lab/restore', '/api/lab/rules', '/api/lab/critic'].includes(p0)) return fail(ctx, res, 404, 'not found');
357
382
  const got = await ctx.readJson(req);
358
383
  if (!got.ok || !isObj(got.body)) return fail(ctx, res, 400, 'the body must be a JSON object');
359
384
  // the live round (lib/live-round.js): `pmos lab round` reaches it with no Origin (D98: an agent does what it was asked; the PM's own
360
385
  // terminal too). It starts a round, or with propose: true only files the ✦ ask the PM's ✓ starts. Never a write of a record.
361
386
  if (p0 === '/api/lab/round') return liveRound(ctx, res, got.body);
387
+ // the design critic on any screenshots or HTML: `pmos lab critic` (no Origin, D98); from a page, a page press
388
+ if (p0 === '/api/lab/critic') {
389
+ if (req.headers.origin) { const g = guard.requirePagePress(req, got.body); if (!g.ok) return fail(ctx, res, g.status, g.error); }
390
+ return designCritic(ctx, res, got.body);
391
+ }
362
392
  // the PM's prototype rules: the chat's agent adds one (no Origin, D98, like the live round); a page's Undo and Restore are page presses
363
393
  if (p0 === '/api/lab/rules') {
364
394
  let by;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.662.0",
3
+ "version": "0.664.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.662.0",
9
+ "version": "0.664.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.662.0",
3
+ "version": "0.664.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -171,6 +171,7 @@ const WIDE = new Set([
171
171
  * a page route, a name used outside any function or route block) reaches every suite.
172
172
  * - lib/routes-<x>.js (a route module that lib/route-modules.js loads): every '/api/…' route the file names under the
173
173
  * prefixes it declares (a route it only calls through ctx is left out). With no prefixes it can read: every route it names.
174
+ * - lib/pmos-verbs.js, when the diff only adds a verb (its module line and its help line): the suites that name pmos-verbs or the new module.
174
175
  * - lib/route-modules.js, when the diff only adds module names to its list: what each added lib/routes-<x>.js reaches. Any other change to it is the rule below.
175
176
  * - Any other file: the files that name it (a require, an import or a path string), followed the same way: server.js
176
177
  * through the names it binds the module to, a lib/ file through its own users, a suite directly. A lib/ file that no
@@ -628,6 +629,9 @@ function traceChanges(changes, ctx) {
628
629
  if (inList.has(g)) { picked.add(g); continue; }
629
630
  if (SUITE_NAME.test(g)) continue; // a suite of another group: nothing depends on it
630
631
  if (WIDE.has(g)) return `${f} is used by ${g}`;
632
+ // a verb module is named by the verb table only as `module: '<x>-cli.js'`: only `pmos <verb>` runs it, so its own suites are its users,
633
+ // not every user of the table (launch-readiness-check: a new verb module reached 177 suites through bin/pmos.js)
634
+ if (g === VERBS_FILE && /^lib\/[\w-]+-cli\.js$/.test(f) && new RegExp(`module: '${reEsc(stemOf(f))}\\.js'`).test(t)) continue;
631
635
  if (g.startsWith('public/')) { viaPublic(g); continue; }
632
636
  if (g === 'server.js') {
633
637
  const names = []; const inline = []; const factories = []; const whole = [];
@@ -699,6 +703,11 @@ function traceChanges(changes, ctx) {
699
703
  for (const s of list) if (s === 'headless.test.js' || rk.some((x) => (get(s) || '').includes(x))) picked.add(s);
700
704
  continue;
701
705
  }
706
+ const nv = f === VERBS_FILE ? newVerbOnly(sget(f), lines) : null;
707
+ if (nv) { // a new verb: only `pmos <verb>` calls reach it, so the suites that name the table or the verb's module
708
+ for (const s of list) { const t = get(s) || ''; if (t.includes('pmos-verbs') || nv.some((m) => t.includes(m))) picked.add(s); }
709
+ continue;
710
+ }
702
711
  let why = null;
703
712
  const before = picked.size;
704
713
  if (get(f) == null) { // removed: only the names in the suites can say who used it
@@ -722,6 +731,24 @@ function traceChanges(changes, ctx) {
722
731
  return { suites: list.filter((s) => picked.has(s)), why: `${changes.length} changed file(s) reach these suites` };
723
732
  }
724
733
 
734
+ /* launch-readiness-check: bin/pmos.js asks lib/pmos-verbs.js for every verb, so a change there reaches every suite. A change that only
735
+ * ADDS a verb is narrower: its `<verb>: Object.freeze({ module: '<x>-cli.js', …` line and its `help: '…' }),` line change only `pmos <verb>`.
736
+ * Returns the new modules' stems, or null when any changed line is something else. `src` is without comments. */
737
+ const VERBS_FILE = ['lib', 'pmos-verbs'].join('/') + '.js'; // built, so this file does not read as a user of it
738
+ function newVerbOnly(src, lines) {
739
+ if (src == null || !Array.isArray(lines) || !lines.length) return null;
740
+ const all = src.split('\n'), mods = [];
741
+ for (const n of lines) {
742
+ const l = all[n - 1];
743
+ if (l == null) return null;
744
+ if (!l.trim() || /^\s*help: '.*' \}\),\s*$/.test(l)) continue;
745
+ const m = /^\s*'?[\w-]+'?: Object\.freeze\(\{ module: '([\w-]+-cli)\.js', run: null, guide: '[\w.-]+',\s*$/.exec(l);
746
+ if (!m) return null;
747
+ mods.push(m[1]);
748
+ }
749
+ return mods.length ? mods : null;
750
+ }
751
+
725
752
  /* live-round (W1): lib/headless.js decides the kind of EVERY spawn through kindFor(), so a change there reaches every suite. A change that
726
753
  * only ADDS a kind is narrower: a new `const X_ORIGINS = Object.freeze(['p:'])`, its `if (X_ORIGINS.some(...)) return 'k';` line in kindFor,
727
754
  * its TOOLS entry and its name on WRITE_DIR_KINDS or WRITE_PATH_KINDS change only runs whose origin starts with 'p:'. Returns the new
@@ -3492,6 +3492,8 @@ const liveRound = require('./lib/live-round.js').install({
3492
3492
  spawn: (spec) => spawnSession({ name: spec.name, agent: 'claude', ws: spec.ws, origin: spec.origin, initialInput: spec.initialInput, initiative: spec.initiative,
3493
3493
  writePaths: spec.writePaths, addDirs: spec.addDirs, autoDelete: undefined, onDone: spec.onDone }),
3494
3494
  stop: (s) => { if (s && s.child) stopHeadless(s); },
3495
+ // the design critic (lib/design-critic.js, initiative design-critic-pass): a read-only ask run reads each version before the PM sees it
3496
+ critic: require('./lib/design-critic.js').askVia(spawnSession),
3495
3497
  artefact: (dir, line, by) => { const AF = require('./lib/artefacts.js'); return AF.set(AF.file(dir), line, { by }); },
3496
3498
  // the chat explains the change (initiative live-round-iterative): a line typed into the initiative's chat session, when one is open
3497
3499
  tell: (ws, ini, text) => { const id = require('./lib/briefing-premium-agent.js').chatSessionOf(STATE, 'init:' + ini); return id ? sendToSession(id, text) : false; },
@@ -0,0 +1,7 @@
1
+ {
2
+ "_comment": "Design critic (initiative design-critic-pass, bet 4 of the factory line): every standing design rule of the product as a named check; a read-only ask run reads each live round version before it opens, its findings join the one fix run and the fix is read again; pmos lab critic for any screenshots; ledger with the PM's real/noise labels (lib/design-critic.js, lib/live-round.js, lib/routes-lab.js /api/lab/critic, lib/lab-cli.js, lib/idle-lab-engine.js renderCheck shots). Backend only.",
3
+ "modules": [
4
+ "design-critic.test.js"
5
+ ],
6
+ "seconds": { "design-critic.test.js": 1 }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Launch readiness check (initiative launch-readiness-check, done test C1-C12): before a launch date, pmos launch check lists open tasks, tracker tickets, sign-offs with no answer and open questions. Pure checks plus the commands on a scratch product. No server, connector, model or network.",
3
+ "modules": [
4
+ "launch-readiness.test.js"
5
+ ],
6
+ "seconds": {
7
+ "launch-readiness.test.js": 15
8
+ }
9
+ }