create-pmos 0.661.0 → 0.663.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.661.0",
3
+ "version": "0.663.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,21 +34,27 @@
34
34
  ],
35
35
  "pmosChanges": [
36
36
  {
37
- "v": "0.661.0",
38
- "at": "2026-11-22T04:04:22.455Z",
37
+ "v": "0.663.0",
38
+ "at": "2026-11-22T04:09:31.042Z",
39
39
  "f": 4,
40
40
  "prs": [
41
- {
42
- "n": 1445,
43
- "t": "Pmos design drift, the design drift guard",
44
- "s": "Pmos design drift, the design drift guard",
45
- "k": "new"
46
- },
47
41
  {
48
42
  "n": 1449,
49
43
  "t": "Rebuild the Intelligence page from Komorebi blocks",
50
44
  "s": "Rebuild the Intelligence page from Komorebi blocks",
51
45
  "k": "new"
46
+ },
47
+ {
48
+ "n": 1442,
49
+ "t": "Routine is built from the design system's blocks",
50
+ "s": "Routine is built from the design system's blocks",
51
+ "k": "new"
52
+ },
53
+ {
54
+ "n": 1446,
55
+ "t": "A design critic reads each design against every standing rule before the PM sees it",
56
+ "s": "A design critic reads each design against every standing rule before the PM sees it",
57
+ "k": "new"
52
58
  }
53
59
  ]
54
60
  },
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@6ad955bd
1
+ kernel-source: pmos@41fb08b4
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:04:19Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T04:09:27Z"}
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:04:19Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T04:09:27Z"}
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:04:19Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T04:09:27Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,20 +1,26 @@
1
1
  [
2
2
  {
3
- "v": "0.661.0",
4
- "at": "2026-11-22T04:04:22.455Z",
3
+ "v": "0.663.0",
4
+ "at": "2026-11-22T04:09:31.042Z",
5
5
  "f": 4,
6
6
  "prs": [
7
- {
8
- "n": 1445,
9
- "t": "Pmos design drift, the design drift guard",
10
- "s": "Pmos design drift, the design drift guard",
11
- "k": "new"
12
- },
13
7
  {
14
8
  "n": 1449,
15
9
  "t": "Rebuild the Intelligence page from Komorebi blocks",
16
10
  "s": "Rebuild the Intelligence page from Komorebi blocks",
17
11
  "k": "new"
12
+ },
13
+ {
14
+ "n": 1442,
15
+ "t": "Routine is built from the design system's blocks",
16
+ "s": "Routine is built from the design system's blocks",
17
+ "k": "new"
18
+ },
19
+ {
20
+ "n": 1446,
21
+ "t": "A design critic reads each design against every standing rule before the PM sees it",
22
+ "s": "A design critic reads each design against every standing rule before the PM sees it",
23
+ "k": "new"
18
24
  }
19
25
  ]
20
26
  },
@@ -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
 
@@ -10,14 +10,13 @@ Routine is the place for everything PMOS does by itself on a schedule, and for y
10
10
 
11
11
  ## The table
12
12
 
13
- Routine is drawn from the PMOS design system. A switch that is on is green. A late Next shows as a rust-coloured label. Undo is the arrow in the toast at the bottom.
13
+ Routine is built from the PMOS design system's blocks. One "PMOS did" line is at the top, then the kinds as tabs, then one table. A switch that is on is green. A late Next shows as a rust-coloured label. Undo is the arrow in the toast at the bottom.
14
14
 
15
- Routine is one table. Each row has these columns:
15
+ Routine is one table. The group a row is in says its type, so there is no Type column. Each row has these columns:
16
16
 
17
17
  | Column | What it shows |
18
18
  |---|---|
19
19
  | Routine | The name of the report, the source, the job or the task. |
20
- | Type | Report, Read, PMOS job or Your task. |
21
20
  | Product | The product the routine belongs to, by the same name as on every other page (IDPF, not a folder name). This column shows only when the table holds routines of two products or more. |
22
21
  | What it does | For a report, who it tells. A report that names no reader tells you. For a read or a job, what it does. |
23
22
  | When | How often it repeats, in short words, for example "Every two weeks, Wed 09:00". |
@@ -32,7 +31,7 @@ The rows are in these groups, in this order:
32
31
  4. **PMOS jobs.** The jobs PMOS runs by itself, such as the day check and the initiative driver.
33
32
  5. **Your tasks.** Your own scheduled tasks.
34
33
 
35
- A group with no rows does not show. Use the kinds at the top (All, Reports, Reads, PMOS jobs, Your tasks) to show one kind. Each kind shows how many routines it holds. PMOS remembers the kind you chose on this computer.
34
+ A group with no rows does not show. Use the kinds at the top (All, Reports, Reads, Jobs, Your tasks) to show one kind. Each kind shows how many routines it holds. PMOS remembers the kind you chose on this computer.
36
35
 
37
36
  The chip on the left of the kinds is the same chip as on Events. Tick products, programs or projects to show only their routines. The products you tick are the same as on Work. A report shows under a program or a project when its setup is about it. Reads and PMOS jobs serve every product, so they always show. When you tick a program or a project, they fold to their heading, so its reports come first. Press the heading to open them. When the chip hides routines, one grey line says how many. Press **Show all** to show them on this page. What you ticked does not change.
38
37
 
@@ -44,7 +43,7 @@ The line at the top says how many things PMOS did since yesterday, and how many
44
43
 
45
44
  ## Open a routine
46
45
 
47
- Press a row. The routine opens in the popup. When Ask PMOS is hidden, press **Ask PMOS** to show it on the right.
46
+ Press a row. On a desk, the first press shows the routine at the right: what it does, its product, when it runs, what it reads, its template and its last runs. When PMOS sees a pattern, for example the last two runs failed, a suggestion sits under it. Press the row again, press Enter or press Open in full to open it in the popup. When Ask PMOS is hidden, press **Ask PMOS** to show it on the right.
48
47
 
49
48
  Every routine has the same parts:
50
49
 
@@ -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; }