create-pmos 0.607.0 → 0.608.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 +14 -14
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +13 -0
- package/workspace/guide/agent-capabilities.md +1 -0
- package/workspace/guide/cli.md +2 -0
- package/workspace/guide/settings-and-switches.md +8 -0
- package/workspace/lib/idle-lab.js +3 -1
- package/workspace/lib/lab-cli.js +29 -1
- package/workspace/lib/live-round.js +96 -3
- package/workspace/lib/prototype-rules.js +176 -0
- package/workspace/lib/routes-lab.js +23 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-proto.css +1 -0
- package/workspace/public/pm/cozy-proto.js +10 -1
- package/workspace/public/pm/cozy-settings.js +31 -4
- package/workspace/test-lists/prototype-rules.json +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.608.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,19 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.608.0",
|
|
38
|
+
"at": "2026-11-18T14:09:00.418Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1356,
|
|
43
|
+
"t": "Prototype rules: each correction becomes a check before a version opens",
|
|
44
|
+
"s": "Prototype rules: each correction becomes a check before a version opens",
|
|
45
|
+
"k": "new"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
36
49
|
{
|
|
37
50
|
"v": "0.607.0",
|
|
38
51
|
"at": "2026-11-18T11:44:39.758Z",
|
|
@@ -303,19 +316,6 @@
|
|
|
303
316
|
"k": "new"
|
|
304
317
|
}
|
|
305
318
|
]
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
"v": "0.588.0",
|
|
309
|
-
"at": "2026-11-17T10:44:25.596Z",
|
|
310
|
-
"f": 4,
|
|
311
|
-
"prs": [
|
|
312
|
-
{
|
|
313
|
-
"n": 1324,
|
|
314
|
-
"t": "Share a meeting note with people who have no PMOS",
|
|
315
|
-
"s": "Share a meeting note with people who have no PMOS",
|
|
316
|
-
"k": "new"
|
|
317
|
-
}
|
|
318
|
-
]
|
|
319
319
|
}
|
|
320
320
|
]
|
|
321
321
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T14:08:57Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T14:08:57Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T14:08:57Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.608.0",
|
|
4
|
+
"at": "2026-11-18T14:09:00.418Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1356,
|
|
9
|
+
"t": "Prototype rules: each correction becomes a check before a version opens",
|
|
10
|
+
"s": "Prototype rules: each correction becomes a check before a version opens",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"v": "0.607.0",
|
|
4
17
|
"at": "2026-11-18T11:44:39.758Z",
|
|
@@ -216,6 +216,7 @@ What each part does:
|
|
|
216
216
|
- **What the run gets.** Each run gets the product's token sheet and the start of its component sheet (or PMOS's own), the initiative's name and the product's Intent, the files you attached, the element you pointed at, and your copy edits and sliders. A prototype must fit a 390 px phone screen.
|
|
217
217
|
- **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 ✓.
|
|
218
218
|
- **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.
|
|
219
|
+
- **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.
|
|
219
220
|
- **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.
|
|
220
221
|
- **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.
|
|
221
222
|
- **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).
|
package/workspace/guide/cli.md
CHANGED
|
@@ -243,6 +243,8 @@ The idle lab run uses only the first three commands:
|
|
|
243
243
|
- `pmos lab round <initiative> --brief "<what to show>" [--one] [--base B] [--dirs "A: …|B: …|C: …"] [--of <round> [--from n]] [--propose] [--chat] [--ws <id>]`: a live round. With `--one`, PMOS makes one version with its flow, swimlane and copy, and shows it on the Viewer's canvas as soon as it renders; without it, PMOS starts three runs at once, one version each, side by side. With `--base B`, PMOS makes one new round of B from the brief: of the current prototype, or of the round that `--of` names (and its version n with `--from n`). With `--propose`, PMOS files the ✦ ask instead, and your ✓ starts it. With `--chat`, the initiative chat started it: the chat is told when the version renders, and the version becomes the initiative's prototype (a round from a terminal without it waits for your ✓). A background lab run cannot use this command. See [The live round](agent-capabilities.md).
|
|
244
244
|
- `pmos lab delete <initiative> [--file <round>/<A>/<a>.html | --version <n> [--key A]] [--ws <id>]`: delete one prototype version. Without `--file` or `--version`, PMOS deletes the prototype now. The version goes out of the Viewer and is not used for the next version. Its folder, with your edits, is kept aside, so the command prints the Undo. The Viewer's trash in the version bar does the same. A background lab run cannot use this command.
|
|
245
245
|
- `pmos lab undo <batch> [--ws <id>]`: bring a deleted version back, with its edits.
|
|
246
|
+
- `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.
|
|
247
|
+
- `pmos lab rule list`: the rules every prototype version is checked against before it opens. The same list is in Settings › PMOS › Prototype rules.
|
|
246
248
|
|
|
247
249
|
### pmos outcomes: expected outcomes
|
|
248
250
|
|
|
@@ -76,6 +76,14 @@ PMOS grills an initiative by itself and files what it finds under the initiative
|
|
|
76
76
|
|
|
77
77
|
**Monthly credit for checks.** The most PMOS's checks may spend in a month: $5, $10, $20 or $50. The bar under it shows what this month used. At the limit PMOS pauses and the row says so; it never spends beyond the limit. `pmos grill mode` and `pmos grill cap` change the same two settings.
|
|
78
78
|
|
|
79
|
+
## PMOS › Prototype rules: what every prototype version is checked for
|
|
80
|
+
|
|
81
|
+
PMOS checks each prototype version against these rules after it renders and before it opens in the Viewer (see [The live round](agent-capabilities.md)). A version that breaks one gets one fix run, and you see only the fixed version. Each rule comes from your own words: the row shows the rule, what you said and the date. There is no button to run the checks and nothing to pick: PMOS adds a rule from a correction in the chat that is true of every prototype.
|
|
82
|
+
|
|
83
|
+
The first three come from the corrections of 18 Nov: **No device or browser frame**, **No instructions on the screen** and **No sample or placeholder copy**.
|
|
84
|
+
|
|
85
|
+
**Undo** stops PMOS from checking that rule. The rule stays in the list, with **Bring back**. PMOS does not add an undone rule again unless you say it again. `pmos lab rule list` shows the same list.
|
|
86
|
+
|
|
79
87
|
## Where the settings are kept
|
|
80
88
|
|
|
81
89
|
Each setting is saved when you change it. The settings are kept in the PMOS state directory, in `settings.json` for this computer and in `settings-ws/<workspace>.json` for each workspace. Only you can read these files. `GET /api/settings` returns every setting with its value and default. A change goes through `POST /api/settings` and must come from the workspace page. A variable in the environment where PMOS starts, such as `PMOS_GRILL=off`, wins over the page, and the row says so.
|
|
@@ -303,7 +303,9 @@ function compareOf(P, id, { key = '', titleOf = () => '', proven = PROVEN } = {}
|
|
|
303
303
|
...(file ? { file } : {}), ...(lost ? { notMade: lost.why || (lost.state === 'working' ? 'its run stopped before it finished' : 'it did not render'), ...(fromFile ? { fallback: fromFile, fallbackN: p.data.from } : {}) } : {}), ...(upd ? { updated: upd, also: p.data.also || '' } : {}), ...(slotNow && slotNow.parts ? { parts: slotNow.parts } : {}),
|
|
304
304
|
...(live ? { live: true, run: p.data.live.id || '', startedAt: p.data.live.startedAt || '', working: (p.data.live.slots || []).some((s) => s.state === 'working' || s.state === 'proving' || Object.values(s.parts || {}).includes('working')) } : {}),
|
|
305
305
|
// what the run is doing now (its progress.json, lib/live-round.js progressOf): the Viewer's progress line while it is made
|
|
306
|
-
...(slotNow && slotNow.progress && making ? { progress: slotNow.progress } : {})
|
|
306
|
+
...(slotNow && slotNow.progress && making ? { progress: slotNow.progress } : {}),
|
|
307
|
+
// the PM's prototype rules (lib/prototype-rules.js): how many PMOS fixed before it opened, and any it still breaks (never hidden)
|
|
308
|
+
...(slotNow && !making && (slotNow.fixed || (slotNow.missed || []).length) ? { checks: { fixed: slotNow.fixed || 0, missed: (slotNow.missed || []).slice(0, 6) } } : {}) };
|
|
307
309
|
}
|
|
308
310
|
|
|
309
311
|
/** PURE. The initiative's prototype rounds, newest first, open or not: a kept or dropped round stays reachable from the initiative page
|
package/workspace/lib/lab-cli.js
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
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 rule add --json - [--again] | rule list the PM's prototype rules (lib/prototype-rules.js): the chat's agent turns a correction
|
|
16
|
+
* that is true of every prototype into a check. PMOS keeps it only when it fails its bad example and
|
|
17
|
+
* passes its good one; --again re-adds a rule the PM undid, only when the PM says it again
|
|
15
18
|
*
|
|
16
19
|
* The run verbs need the run's environment (PMOS_LAB_RUN, _KIND, _PENDING, and _PAGES or _SPECIMENS, set by the server); outside a run they
|
|
17
20
|
* refuse. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
|
|
@@ -20,7 +23,7 @@ const path = require('path');
|
|
|
20
23
|
const dns = require('dns');
|
|
21
24
|
const E = require('./idle-lab-engine.js');
|
|
22
25
|
|
|
23
|
-
const COMMANDS = { lab: ['page', 'file', 'status', 'round', 'delete', 'undo'] };
|
|
26
|
+
const COMMANDS = { lab: ['page', 'file', 'status', 'round', 'delete', 'undo', 'rule'] };
|
|
24
27
|
const GROUPS = { 'prototype-new': ['prototyped'], 'prototype-improve': ['improved'], 'scan-new': ['scanned', 'scan'], 'scan-improve': ['scanned', 'scan'] };
|
|
25
28
|
const USAGE = [
|
|
26
29
|
'usage: pmos lab page|file|status — the idle lab: PMOS prototypes and scans while you are away; each result waits under ✦ for your ✓',
|
|
@@ -38,6 +41,9 @@ const USAGE = [
|
|
|
38
41
|
' pmos lab delete <initiative> [--file <round>/<A>/<a>.html | --version <n> [--key A]] [--ws <id>]',
|
|
39
42
|
' delete one prototype version (no --file or --version: the prototype now). It prints the batch',
|
|
40
43
|
' pmos lab undo <batch> [--ws <id>] bring a deleted version back',
|
|
44
|
+
' pmos lab rule add --json - [--again] a prototype rule from the PM\'s correction: { "title", "words", "tests": [{ "in": "text"|"attr"|"source", "re", "flags"? }],',
|
|
45
|
+
' "bad": "<html that breaks it>", "good": "<html that keeps it>" }. Kept only when it fails bad and passes good',
|
|
46
|
+
' pmos lab rule list the rules every prototype version is checked against before it opens',
|
|
41
47
|
'A specimen must open and render; every claim must quote what was read. What is not proven is dropped. Nothing is sent.',
|
|
42
48
|
];
|
|
43
49
|
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; };
|
|
@@ -176,6 +182,28 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
|
|
|
176
182
|
return 0;
|
|
177
183
|
}
|
|
178
184
|
|
|
185
|
+
if (verb === 'rule') {
|
|
186
|
+
// the PM's prototype rules: the chat's agent adds one from a correction; a background lab run never does
|
|
187
|
+
if (run) { say('✗ a lab run cannot change the PM\'s prototype rules'); return 1; }
|
|
188
|
+
const sub = args[1];
|
|
189
|
+
if (sub !== 'add' && sub !== 'list') { say('usage: pmos lab rule add --json - [--again] | pmos lab rule list'); return 2; }
|
|
190
|
+
if (typeof call !== 'function') { say('✗ no PMOS server answers: start PMOS, then ask again'); return 1; }
|
|
191
|
+
if (sub === 'list') {
|
|
192
|
+
let r = null; try { r = await call('GET', '/api/lab/rules'); } catch { r = null; }
|
|
193
|
+
if (!r || !r.ok) { say('✗ ' + ((r && r.error) || 'no PMOS server answers: start PMOS, then ask again')); return 1; }
|
|
194
|
+
for (const x of r.rules || []) say(`${x.on ? '✓' : '·'} ${x.id} · ${x.title}${x.on ? '' : ' (undone by the PM)'}${x.words ? ' · "' + one(x.words, 120) + '"' : ''}`);
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
const src = flag(args, 'json'); if (typeof src !== 'string') { say('usage: pmos lab rule add --json <file|-> [--again]'); return 2; }
|
|
198
|
+
const j = readJson(src, stdin); if (j.error) { say('✗ ' + j.error); return 1; }
|
|
199
|
+
let by = ''; try { by = require('./actor.js').fromCli({ env }).by || ''; } catch { by = ''; }
|
|
200
|
+
let r = null; try { r = await call('POST', '/api/lab/rules', { op: 'add', rule: j.body, ...(flag(args, 'again') ? { again: true } : {}), ...(by ? { by } : {}) }); } catch { r = null; }
|
|
201
|
+
if (!r) { say('✗ no PMOS server answers: start PMOS, then ask again'); return 1; }
|
|
202
|
+
if (!r.ok) { say('✗ ' + (r.error || 'the rule was not added')); return 1; }
|
|
203
|
+
say(`✓ ${r.replaced ? 'updated' : 'added'} "${r.rule.title}": every prototype version is checked against it before it opens. The PM can undo it in Settings › PMOS › Prototype rules.`);
|
|
204
|
+
return 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
179
207
|
if (verb === 'status') {
|
|
180
208
|
if (run && env.PMOS_LAB_PENDING) {
|
|
181
209
|
let lines = [];
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
* PROOF PER FILE (proven-only rule). PMOS watches each run's folder. When a file lands and stops growing it opens it in a headless browser
|
|
31
31
|
* (lib/idle-lab-engine.js renderCheck, at desk width and at 390 px: a version wider than the phone is not proven) and only then puts it on the card. The card exists from the start, so the PM sees honest state: a
|
|
32
32
|
* slot is working, made (a thumbnail) or not made (why). Nothing is written to a product repository before ✓ (D60, D65).
|
|
33
|
+
* THE PM'S RULES (initiative prototype-rules, step 2 of "Prototypes right on the first try", agreed 2026-11-18). After a version renders and
|
|
34
|
+
* before it opens, PMOS runs the PM's prototype rules on it (lib/prototype-rules.js: no device frame, no instructions, no sample copy, and
|
|
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
|
+
* 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
|
+
* 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.
|
|
33
38
|
* LESSONS. Every feedback sentence is a Lessons line of the experiment (lib/artefacts.js); ✓ and ✕ add theirs (lib/routes-proposals.js).
|
|
34
39
|
* The specimens a round made are Specimens lines; the one the PM keeps is its `kept` field.
|
|
35
40
|
*
|
|
@@ -56,6 +61,7 @@ const crypto = require('crypto');
|
|
|
56
61
|
const PR = require('./proposals.js');
|
|
57
62
|
const LAB = require('./idle-lab.js');
|
|
58
63
|
const E = require('./idle-lab-engine.js');
|
|
64
|
+
const RULES = require('./prototype-rules.js');
|
|
59
65
|
|
|
60
66
|
const JOB = 'live-round';
|
|
61
67
|
const ORIGIN = 'live-round';
|
|
@@ -290,6 +296,21 @@ function promptOf(o) {
|
|
|
290
296
|
return L.join('\n');
|
|
291
297
|
}
|
|
292
298
|
|
|
299
|
+
/** PURE. The one fix run's prompt: only the rules the version broke and the lines that broke them (failed: lib/prototype-rules.js run). */
|
|
300
|
+
function fixPromptOf({ file, dir, failed }) {
|
|
301
|
+
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.',
|
|
302
|
+
'', `The prototype: ${file}. Read it, then overwrite it with the Write tool.`, '', 'The rules it breaks, each with the lines that broke it:'];
|
|
303
|
+
for (const f of failed || []) {
|
|
304
|
+
L.push(`- ${one(f.title, 80)}${f.words ? ' (the PM said: "' + one(f.words, 200) + '")' : ''}`);
|
|
305
|
+
for (const l of f.lines || []) L.push(` > ${one(l, 160)}`);
|
|
306
|
+
}
|
|
307
|
+
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">.',
|
|
308
|
+
`A line that is a note for the PM (a format or its size, that the data is sample data, how to use the prototype) moves to ${path.join(dir, 'notes.json')} as { "notes": [{ "text", "screen"? }] }, keeping the notes already there. Never just delete it.`,
|
|
309
|
+
'Sample or placeholder copy becomes real copy about the prototype\'s own subject. A frame (a device, a browser bar, a status bar) goes: the design is the page itself.',
|
|
310
|
+
'Write nothing else.');
|
|
311
|
+
return L.join('\n');
|
|
312
|
+
}
|
|
313
|
+
|
|
293
314
|
/* ── the companions as data (PARTS): each check is PURE and keeps only what is well formed ── */
|
|
294
315
|
const ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,59}$/;
|
|
295
316
|
const arr = (v, n) => (Array.isArray(v) ? v.slice(0, n) : []);
|
|
@@ -442,7 +463,12 @@ function saidOf(abs) {
|
|
|
442
463
|
function contextOf(cur, { ini, ws = '', rt = null, versions = [] } = {}) {
|
|
443
464
|
if (!ini) return '';
|
|
444
465
|
const wsf = ws ? ` --ws ${ws}` : '';
|
|
445
|
-
|
|
466
|
+
// every correction that is true of EVERY prototype becomes a check (initiative prototype-rules, lib/prototype-rules.js): the agent adds it
|
|
467
|
+
// itself, with no button, and PMOS keeps it only when it fails its bad example and passes its good one
|
|
468
|
+
const never = 'Never write the prototype yourself, never write an HTML file in the repository, a scratchpad or elsewhere, and never use `pmos lab file`: that is for the background lab only. '
|
|
469
|
+
+ 'When the PM\'s words are a rule for every prototype that a page can be checked for (e.g. "no device frame", "no instructions on the screen"), not a change to this version only and not a taste ("calmer"), '
|
|
470
|
+
+ 'also run `pmos lab rule add --json -` with { "title", "words": "<the PM\'s own words>", "tests": [{ "in": "text" | "attr" | "source", "re", "flags"? }], "bad": "<a small HTML page that breaks it>", "good": "<one that keeps it>" }. '
|
|
471
|
+
+ 'PMOS checks every version against it before it opens, and the PM sees it in Settings › PMOS › Prototype rules with Undo. Say so in one line.';
|
|
446
472
|
if (!cur || !cur.file) {
|
|
447
473
|
// no version is the prototype yet: list what exists, so "improve the prototype" continues the one the PM means, never a new file
|
|
448
474
|
const vs = (versions || []).filter((v) => v && v.file).slice(0, 6);
|
|
@@ -468,7 +494,8 @@ function contextOf(cur, { ini, ws = '', rt = null, versions = [] } = {}) {
|
|
|
468
494
|
const fin = (x) => x.state === 'ok' || x.state === 'not made' || x.state === 'none';
|
|
469
495
|
const partsLine = (s) => Object.fromEntries((s.parts || []).map((x) => [x.kind, x.state === 'not made' ? 'not made: ' + one(x.why, 120) : x.state]));
|
|
470
496
|
function roundLine(R, now) {
|
|
471
|
-
const slots = R.slots.map((s) => ({ key: s.key, title: s.title, state: s.state, ...(s.file && s.state === 'ok' ? { file: s.file } : {}), ...(s.why ? { why: one(s.why, 200) } : {}), ...(s.dims ? { dims: s.dims } : {}), ...(s.said ? { said: s.said } : {}), ...(s.progress && s.state === 'working' ? { progress: s.progress } : {}), ...((s.parts || []).length ? { parts: partsLine(s) } : {})
|
|
497
|
+
const slots = R.slots.map((s) => ({ key: s.key, title: s.title, state: s.state, ...(s.file && s.state === 'ok' ? { file: s.file } : {}), ...(s.why ? { why: one(s.why, 200) } : {}), ...(s.dims ? { dims: s.dims } : {}), ...(s.said ? { said: s.said } : {}), ...(s.progress && (s.state === 'working' || s.state === 'proving') ? { progress: s.progress } : {}), ...((s.parts || []).length ? { parts: partsLine(s) } : {}),
|
|
498
|
+
...(s.fixed ? { fixed: s.fixed } : {}), ...(s.missed && s.missed.length ? { missed: s.missed.slice(0, 6) } : {}) }));
|
|
472
499
|
const ok = R.slots.filter((s) => s.state === 'ok');
|
|
473
500
|
const done = R.slots.every((s) => fin(s) && (s.parts || []).every(fin));
|
|
474
501
|
const checked = ok.length ? (ok.length === 1 ? 'It opened and rendered' : `All ${ok.length} opened and rendered`) + ' in a headless browser (' + ok.map((s) => s.dims).join(', ') + ')' : '';
|
|
@@ -496,6 +523,8 @@ function create(deps) {
|
|
|
496
523
|
const warn = deps.warn || (() => {});
|
|
497
524
|
const now = () => (deps.now ? deps.now() : Date.now());
|
|
498
525
|
const render = deps.render || ((abs) => E.renderCheck(abs, { phone: true })); // proven at 390 px too: the viewport pin
|
|
526
|
+
// the PM's prototype rules (lib/prototype-rules.js), read for each version so an Undo in Settings counts at once
|
|
527
|
+
const rulesOf = deps.rules || (() => { try { return RULES.active(deps.runtimeDir ? deps.runtimeDir() : null); } catch (e) { warn('prototype rules', e); return []; } });
|
|
499
528
|
const pollMs = deps.pollMs || 1000;
|
|
500
529
|
const rounds = new Map(); // id → round
|
|
501
530
|
|
|
@@ -633,13 +662,37 @@ function create(deps) {
|
|
|
633
662
|
async function prove(R, s, cost = null) {
|
|
634
663
|
if (s.state !== 'working') return;
|
|
635
664
|
s.state = 'proving';
|
|
665
|
+
return verify(R, s, cost);
|
|
666
|
+
}
|
|
667
|
+
/** Render the version, then run the PM's rules on it. A first failure starts the one fix run; after it, the version opens either way. */
|
|
668
|
+
async function verify(R, s, cost = null) {
|
|
636
669
|
let st = null; try { st = fs.statSync(s.abs); } catch { st = null; }
|
|
637
670
|
let v;
|
|
638
671
|
if (!st || !st.isFile()) v = { ok: false, why: 'the run ended without writing its file' };
|
|
639
672
|
else if (st.size > 2e6) v = { ok: false, why: 'the file is over 2 MB' };
|
|
640
673
|
else { try { v = await render(s.abs); } catch (e) { v = { ok: false, why: 'it did not open: ' + one(e && e.message, 120) }; } }
|
|
641
674
|
if (s.state !== 'proving') return; // stopped while it rendered (Undo, the budget)
|
|
675
|
+
const fx = s.fixing || null;
|
|
676
|
+
if ((!v || !v.ok) && fx && fx.draft) {
|
|
677
|
+
// the fix broke the render: the draft that rendered comes back, and the version opens with the rules it breaks
|
|
678
|
+
try { fs.copyFileSync(fx.draft, s.abs); } catch (e) { warn('prototype rules draft', e); }
|
|
679
|
+
v = fx.v; fx.left = fx.failed;
|
|
680
|
+
}
|
|
642
681
|
if (!v || !v.ok) { s.state = 'working'; return notMade(R, s, 'not proven: ' + ((v && v.why) || 'it did not render')); }
|
|
682
|
+
if (!fx) {
|
|
683
|
+
let failed = []; try { failed = RULES.run(fs.readFileSync(s.abs, 'utf8'), rulesOf()); } catch (e) { warn('prototype rules', e); failed = []; }
|
|
684
|
+
if (failed.length && fix(R, s, failed, v, cost)) return;
|
|
685
|
+
} else if (!fx.left) {
|
|
686
|
+
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; }
|
|
687
|
+
}
|
|
688
|
+
const fd = s.fixing || null; // set by fix(), also when its run could not start
|
|
689
|
+
if (fd) {
|
|
690
|
+
const left = new Set((fd.left || []).map((f) => f.id));
|
|
691
|
+
s.fixed = fd.failed.filter((f) => !left.has(f.id)).length;
|
|
692
|
+
s.missed = (fd.left || []).map((f) => f.title);
|
|
693
|
+
s.progress = null;
|
|
694
|
+
if (fd.cost !== null) cost = cost === null ? fd.cost : Math.round((cost + fd.cost) * 10000) / 10000;
|
|
695
|
+
}
|
|
643
696
|
s.state = 'ok'; s.dims = `${v.w}×${v.h}`; s.said = saidOf(s.abs);
|
|
644
697
|
// copy.json is PMOS's, read from the prototype's own words, so the Page copy card can never disagree with the screen
|
|
645
698
|
try { fs.writeFileSync(path.join(path.dirname(s.abs), 'copy.json'), JSON.stringify(copyOf(fs.readFileSync(s.abs, 'utf8')), null, 1)); } catch (e) { warn('live round copy', e); }
|
|
@@ -650,6 +703,41 @@ function create(deps) {
|
|
|
650
703
|
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); }
|
|
651
704
|
write(R); settle(R);
|
|
652
705
|
}
|
|
706
|
+
/** 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. */
|
|
707
|
+
function fix(R, s, failed, v, cost) {
|
|
708
|
+
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 };
|
|
709
|
+
try { fs.copyFileSync(s.abs, fx.draft); } catch (e) { warn('prototype rules draft', e); fx.draft = ''; }
|
|
710
|
+
s.fixing = fx;
|
|
711
|
+
s.progress = { now: `Fixing ${failed.length === 1 ? '1 thing' : failed.length + ' things'} before you see it`, done: 0, total: 0 };
|
|
712
|
+
try { s.size = fs.statSync(s.abs).size; } catch { s.size = -1; }
|
|
713
|
+
E.appendRun(R.rt, { kind: 'start', run: fx.run, job: JOB, ws: R.ws, ini: R.ini, key: `live:${R.id}:${s.key}:fix`, budget: 0, step: R.step, from: R.from }, now());
|
|
714
|
+
let session = null;
|
|
715
|
+
try {
|
|
716
|
+
session = deps.spawn({ name: 'Fixing ' + s.key + ' · ' + one(failed.map((f) => f.title).join(', '), 50), agent: 'claude', ws: R.ws, origin: `${ORIGIN}:${R.ws}:${R.ini}:${fx.run}:${s.key}`,
|
|
717
|
+
initialInput: fixPromptOf({ file: s.abs, dir: path.dirname(s.abs), failed }) + '\r', initiative: R.ini, writePaths: [path.dirname(s.abs)], addDirs: [],
|
|
718
|
+
onDone: (res) => { fixEnded(R, s, res).catch((e) => warn('prototype rules fix end', e)); } });
|
|
719
|
+
} catch (e) { warn('prototype rules fix spawn', e); }
|
|
720
|
+
if (!session || session.state === 'exited' || session.headless !== JOB) {
|
|
721
|
+
if (session && session.state !== 'exited' && deps.stop) try { deps.stop(session); } catch { /* best effort */ }
|
|
722
|
+
s.fixing = null; s.progress = null;
|
|
723
|
+
try { E.appendRun(R.rt, { kind: 'end', run: fx.run, ok: false, cost: null, ms: 0, filed: 0, dropped: ['the fix run could not start'] }, now()); } catch { /* the version opens anyway */ }
|
|
724
|
+
s.fixing = { ...fx, left: failed, draft: '' }; // it opens with the rules it breaks, never hidden
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
fx.session = session;
|
|
728
|
+
write(R);
|
|
729
|
+
return true;
|
|
730
|
+
}
|
|
731
|
+
async function fixEnded(R, s, res = {}) {
|
|
732
|
+
const fx = s.fixing; if (!fx || fx.done) return;
|
|
733
|
+
fx.done = true;
|
|
734
|
+
const out = (res && res.result) || {};
|
|
735
|
+
const c = Number.isFinite(out.costUsd) ? Math.round(out.costUsd * 10000) / 10000 : null;
|
|
736
|
+
if (c !== null) fx.cost = fx.cost === null ? c : fx.cost + c;
|
|
737
|
+
try { E.appendRun(R.rt, { kind: 'end', run: fx.run, ok: true, cost: c, ms: Math.max(0, now() - R.start), filed: 0, dropped: [] }, now()); } catch { /* the card says it */ }
|
|
738
|
+
if (s.state !== 'proving') return;
|
|
739
|
+
return verify(R, s, null);
|
|
740
|
+
}
|
|
653
741
|
/** A companion lands: it must parse and be well formed (flowOf, lanesOf, tweaksOf, notesOf), else it is "not made" with the reason. */
|
|
654
742
|
function provePart(R, s, x) {
|
|
655
743
|
if (x.state !== 'working') return;
|
|
@@ -667,6 +755,8 @@ function create(deps) {
|
|
|
667
755
|
let pj = null; try { pj = progressOf(JSON.parse(fs.readFileSync(path.join(path.dirname(s.abs), 'progress.json'), 'utf8'))); } catch { pj = null; }
|
|
668
756
|
if (pj && JSON.stringify(pj) !== JSON.stringify(s.progress || null)) { s.progress = pj; R.seen = now(); write(R); }
|
|
669
757
|
}
|
|
758
|
+
// a fix run that writes is making progress
|
|
759
|
+
if (s.fixing && !s.fixing.done && s.abs) { let z = -1; try { z = fs.statSync(s.abs).size; } catch { z = -1; } if (z !== s.size) { s.size = z; R.seen = now(); } }
|
|
670
760
|
for (const x of s.state === 'not made' ? [] : [s, ...(s.parts || [])]) {
|
|
671
761
|
if (x.state !== 'working') continue;
|
|
672
762
|
let size = -1; try { size = fs.statSync(x.abs).size; } catch { size = -1; }
|
|
@@ -697,6 +787,8 @@ function create(deps) {
|
|
|
697
787
|
const busy = [s, ...(s.parts || [])].some((x) => x.state === 'working');
|
|
698
788
|
if (busy && s.session && s.session.state !== 'exited' && deps.stop) try { deps.stop(s.session); } catch { /* best effort */ }
|
|
699
789
|
if (s.state === 'working') notMade(R, s, why); // a file being proven finishes its proof
|
|
790
|
+
// a fix run that stalls ends: the version opens as the fix left it, or as the draft
|
|
791
|
+
if (s.fixing && !s.fixing.done) { if (s.fixing.session && s.fixing.session.state !== 'exited' && deps.stop) try { deps.stop(s.fixing.session); } catch { /* best effort */ } fixEnded(R, s, { stopped: true }).catch((e) => warn('prototype rules fix end', e)); }
|
|
700
792
|
for (const x of s.parts || []) partNotMade(R, s, x, why);
|
|
701
793
|
}
|
|
702
794
|
}
|
|
@@ -733,6 +825,7 @@ function create(deps) {
|
|
|
733
825
|
const R = rounds.get(id);
|
|
734
826
|
if (R) for (const s of R.slots) {
|
|
735
827
|
if (s.session && s.session.state !== 'exited' && deps.stop && [s, ...(s.parts || [])].some((x) => x.state === 'working' || x.state === 'proving')) try { deps.stop(s.session); } catch { /* best effort */ }
|
|
828
|
+
if (s.fixing && s.fixing.session && !s.fixing.done && s.fixing.session.state !== 'exited' && deps.stop) { s.fixing.done = true; try { deps.stop(s.fixing.session); } catch { /* best effort */ } }
|
|
736
829
|
if (s.state === 'working' || s.state === 'proving') { s.state = 'working'; notMade(R, s, why); }
|
|
737
830
|
for (const x of s.parts || []) partNotMade(R, s, x, why);
|
|
738
831
|
}
|
|
@@ -769,6 +862,6 @@ function running(ini) { return inst ? inst.running(ini) : false; }
|
|
|
769
862
|
function stopRound(id) { return inst ? inst.stop(id) : { ok: false, error: NOT_READY }; }
|
|
770
863
|
function status() { return inst ? inst.status() : []; }
|
|
771
864
|
|
|
772
|
-
module.exports = { DELETE_RE, JOB, ORIGIN, STALL_MS, progressOf, KEYS, DEFAULT_DIRECTIONS, ONE_DIRECTION, PARTS, FROM, marksOf, intentOf, parseDirs, askOf, waiting, baseOf, currentOf: PR.currentOf, contextOf, scaffoldOf, promptOf, saidOf, roundLine,
|
|
865
|
+
module.exports = { DELETE_RE, JOB, ORIGIN, STALL_MS, progressOf, KEYS, DEFAULT_DIRECTIONS, ONE_DIRECTION, PARTS, FROM, marksOf, intentOf, parseDirs, askOf, waiting, baseOf, currentOf: PR.currentOf, contextOf, scaffoldOf, promptOf, fixPromptOf, saidOf, roundLine,
|
|
773
866
|
flowOf, lanesOf, tweaksOf, notesOf, copyOf, changesOf, partsAt, editsOf, styleWords, STYLE_OK,
|
|
774
867
|
create, install, round, startNow, proposeNow, cancel, stopRound, dropCard, running, status };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* prototype-rules.js — the PM's prototype rules as checks (initiative prototype-rules, step 2 of the design "Prototypes right on the first
|
|
3
|
+
* try", agreed by Wawan 2026-11-18; Exploring 2 page pgFt, boards FtA and FtB). Each correction the PM makes that is true of EVERY prototype
|
|
4
|
+
* ("it should not have the desktop container") becomes a check. lib/live-round.js runs the list on each version after it renders
|
|
5
|
+
* (renderCheck) and before it opens; a version that fails gets ONE automatic fix run that quotes the failed lines.
|
|
6
|
+
*
|
|
7
|
+
* A CHECK EARNS ITS PLACE. A rule carries one bad and one good example. add() refuses a rule that does not fail its bad example AND pass its
|
|
8
|
+
* good one (the design's own first test called the button "See the week" an instruction and failed a clean version). Buttons and links are
|
|
9
|
+
* never read as instructions: their words are what the user taps.
|
|
10
|
+
*
|
|
11
|
+
* A RULE IS DATA, never code: each test is a regular expression over one part of the page:
|
|
12
|
+
* text the screen's visible words, one block per line, WITHOUT buttons, links, the head, scripts, styles and comments
|
|
13
|
+
* attr the class and id of every element in the body ("device-frame", "status-bar")
|
|
14
|
+
* source the whole file
|
|
15
|
+
* A rule fails when any of its tests matches; the matched line is quoted to the fix run and kept with the version.
|
|
16
|
+
*
|
|
17
|
+
* THE LEDGER. <runtime>/prototype-rules.jsonl, append-only: { at, by, kind: add | undo | restore, rule? | id }. The newest line for an id
|
|
18
|
+
* wins, so the PM's later words win. The three seed rules are today's corrections (2026-11-18) and are in effect unless the PM undoes them.
|
|
19
|
+
* An undone rule is not added again unless the PM says it again (add with again: true). Settings › PMOS › Prototype rules lists them with Undo.
|
|
20
|
+
*
|
|
21
|
+
* SEED · file(rt) · read(rt) → { rules: [rule + { on, seed, undoneAt? }] } · active(rt) → [rule]
|
|
22
|
+
* screenText(html) PURE → [line] · attrsOf(html) PURE → [quote] · run(html, rules) PURE → [{ id, title, words, lines }] (the failed ones)
|
|
23
|
+
* validate(rule) PURE → { rule } | { error } · earn(rule) PURE → { ok } | { ok: false, error }
|
|
24
|
+
* add(rt, rule, { by, again }) → { ok, rule } | { ok: false, error } · undo(rt, id, { by }) · restore(rt, id, { by }) */
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
|
|
28
|
+
const FILE = 'prototype-rules.jsonl';
|
|
29
|
+
const IN = Object.freeze(['text', 'attr', 'source']);
|
|
30
|
+
const MAX_TESTS = 6, MAX_RE = 300, MAX_EXAMPLE = 20000, MAX_QUOTES = 3;
|
|
31
|
+
const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
32
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
33
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]{1,59}$/;
|
|
34
|
+
|
|
35
|
+
/* ── today's corrections (Wawan 2026-11-18, batch 31 and the design's Weather strip): each proven on its bad and good example (tests) ── */
|
|
36
|
+
const WEATHER = (body) => `<!doctype html><html><head><title>Weather strip</title><meta name="pmos-changed" content="The forecast for planners"><style>body{margin:0}</style></head><body>${body}</body></html>`;
|
|
37
|
+
const GOOD = WEATHER('<section data-screen="today" data-label="Today"><h1 data-copy="title">Jurong West, 31°</h1><p data-copy="detail">Light rain from 2 pm. Standees stay indoors.</p><button data-go="week">See the week</button><a href="#alerts">Tap for alerts</a></section>');
|
|
38
|
+
const SEED = Object.freeze([
|
|
39
|
+
Object.freeze({ id: 'no-frame', title: 'No device or browser frame', words: 'should not have the desktop container', at: '2026-11-18T00:00:00.000Z', by: 'pm:wawan',
|
|
40
|
+
tests: [{ in: 'attr', re: '(^|[^a-z0-9])(device|bezel|notch|status-?bar|phone-?(frame|shell|case)|browser-?(bar|chrome|frame|window)|window-?chrome|traffic-?lights?|home-?indicator|dynamic-?island|desktop-?(frame|container|window))([^a-z0-9]|$)', flags: 'i' },
|
|
41
|
+
{ in: 'text', re: '^9:41( ?[ap]m)?$', flags: 'i' }],
|
|
42
|
+
bad: WEATHER('<div class="device-frame"><div class="status-bar"><span>9:41</span></div><section data-screen="today"><h1>Jurong West, 31°</h1></section></div>'), good: GOOD }),
|
|
43
|
+
Object.freeze({ id: 'no-instructions', title: 'No instructions on the screen', words: 'In case of instruction, it should be put as comment or annotation.', at: '2026-11-18T00:00:00.000Z', by: 'pm:wawan',
|
|
44
|
+
tests: [{ in: 'text', re: '^(tap|click|press|swipe|scroll|drag|hover|try)\\b', flags: 'i' }, { in: 'text', re: '\\b\\d{3,5} ?[×x] ?\\d{3,5}\\b', flags: 'i' },
|
|
45
|
+
{ in: 'text', re: '\\bformat \\d+\\b|^(note|annotation|instructions?)\\s*:|\\bthis (screen|page|prototype|mock ?up) (shows|is)\\b', flags: 'i' }],
|
|
46
|
+
bad: WEATHER('<section data-screen="today"><p>Format 1 · 7680 × 1550</p><h1>Jurong West, 31°</h1><p>Tap a day to see the hours</p></section>'), good: GOOD }),
|
|
47
|
+
Object.freeze({ id: 'no-sample-copy', title: 'No sample or placeholder copy', words: 'From the 18 Nov corrections: no "Sample data" or placeholder notes on a screen.', at: '2026-11-18T00:00:00.000Z', by: 'pm:wawan',
|
|
48
|
+
tests: [{ in: 'text', re: 'lorem ipsum|\\bsample (data|text|copy|content)\\b|\\bplaceholder\\b|\\bdummy (data|text|copy)\\b|\\b(tbd|todo)\\b|\\b(john|jane) doe\\b|\\bexample\\.com\\b', flags: 'i' }],
|
|
49
|
+
bad: WEATHER('<section data-screen="today"><h1>Jurong West, 31°</h1><p>Sample data</p><p>Lorem ipsum dolor sit amet</p></section>'), good: GOOD }),
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
/* ── a page, read the way the checks read it ── */
|
|
53
|
+
const ENT = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ', mdash: '—', ndash: '–', hellip: '…', times: '×', middot: '·', deg: '°', rsquo: '’', lsquo: '‘', rdquo: '”', ldquo: '“' };
|
|
54
|
+
function decode(s) {
|
|
55
|
+
return String(s).replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (m, e) => {
|
|
56
|
+
if (e[0] === '#') { const n = e[1] === 'x' || e[1] === 'X' ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10); try { return String.fromCodePoint(n); } catch { return ' '; } }
|
|
57
|
+
return ENT[e.toLowerCase()] !== undefined ? ENT[e.toLowerCase()] : m;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const bodyOf = (html) => { const h = String(html || ''); const m = /<body\b[^>]*>([\s\S]*)$/i.exec(h); return (m ? m[1] : h.replace(/<head\b[\s\S]*?<\/head>/i, '')).replace(/<!--[\s\S]*?-->/g, ' '); };
|
|
61
|
+
/** PURE. The screen's visible words, one block per line: no head, scripts, styles or comments, and no buttons or links (what the user taps
|
|
62
|
+
* is never an instruction to the PM: the design's "See the week" false alarm). */
|
|
63
|
+
function screenText(html) {
|
|
64
|
+
let h = bodyOf(html).replace(/<(script|style|noscript|template|svg|title|button|a|select|textarea)\b[\s\S]*?<\/\1\s*>/gi, '\n');
|
|
65
|
+
h = h.replace(/<(br|hr)\b[^>]*>/gi, '\n').replace(/<\/?(p|div|li|ul|ol|h[1-6]|tr|td|th|table|section|article|header|footer|nav|main|aside|blockquote|pre|dd|dt|dl|figure|figcaption)\b[^>]*>/gi, '\n');
|
|
66
|
+
h = decode(h.replace(/<[^>]+>/g, ' '));
|
|
67
|
+
return h.split('\n').map((l) => l.replace(/\s+/g, ' ').trim()).filter(Boolean);
|
|
68
|
+
}
|
|
69
|
+
/** PURE. The class and id of every element in the body, each quoted as its opening tag (cut at 120 characters). */
|
|
70
|
+
function attrsOf(html) {
|
|
71
|
+
const out = [], re = /<([a-z][a-z0-9-]*)\b([^>]*)>/gi, b = bodyOf(html);
|
|
72
|
+
let m;
|
|
73
|
+
while ((m = re.exec(b)) && out.length < 5000) {
|
|
74
|
+
const a = m[2], vals = [];
|
|
75
|
+
for (const k of ['class', 'id']) { const x = new RegExp('\\b' + k + '\\s*=\\s*("([^"]*)"|\'([^\']*)\'|([^\\s>]+))', 'i').exec(a); if (x) vals.push(x[2] != null ? x[2] : x[3] != null ? x[3] : x[4]); }
|
|
76
|
+
if (vals.length) out.push({ value: vals.join(' '), quote: one(m[0], 120) });
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
function regexOf(t) { try { return new RegExp(t.re, (t.flags || '').replace(/[^imsu]/g, '')); } catch { return null; } }
|
|
81
|
+
/** PURE. The rules a page breaks: [{ id, title, words, lines: [quoted line] }], in the rules' order; [] when it passes them all. */
|
|
82
|
+
function run(html, rules) {
|
|
83
|
+
const failed = [];
|
|
84
|
+
let text = null, attrs = null;
|
|
85
|
+
for (const r of rules || []) {
|
|
86
|
+
const lines = [];
|
|
87
|
+
for (const t of r.tests || []) {
|
|
88
|
+
const re = regexOf(t); if (!re) continue;
|
|
89
|
+
if (t.in === 'text') { text = text || screenText(html); for (const l of text) if (re.test(l) && !lines.includes(one(l, 160))) lines.push(one(l, 160)); }
|
|
90
|
+
else if (t.in === 'attr') { attrs = attrs || attrsOf(html); for (const a of attrs) if (re.test(a.value) && !lines.includes(a.quote)) lines.push(a.quote); }
|
|
91
|
+
else if (t.in === 'source') { const m = re.exec(String(html || '')); if (m) lines.push(one(m[0], 160)); }
|
|
92
|
+
if (lines.length >= MAX_QUOTES) break;
|
|
93
|
+
}
|
|
94
|
+
if (lines.length) failed.push({ id: r.id, title: r.title, words: r.words || '', lines: lines.slice(0, MAX_QUOTES) });
|
|
95
|
+
}
|
|
96
|
+
return failed;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* ── a rule ── */
|
|
100
|
+
/** PURE. A rule as the agent wrote it → { rule } | { error }: an id, a title, the PM's words, 1 to 6 tests that compile, both examples. */
|
|
101
|
+
function validate(r) {
|
|
102
|
+
if (!isObj(r)) return { error: 'a rule is a JSON object' };
|
|
103
|
+
const title = one(r.title, 80), words = one(r.words, 300);
|
|
104
|
+
const id = ID_RE.test(String(r.id || '')) ? r.id : one(title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, ''), 60);
|
|
105
|
+
if (!title) return { error: 'title names the rule in a few plain words, e.g. "No device or browser frame"' };
|
|
106
|
+
if (!words) return { error: 'words are the PM\'s own sentence the rule comes from' };
|
|
107
|
+
if (!ID_RE.test(id)) return { error: 'id is a short kebab-case name' };
|
|
108
|
+
const tests = Array.isArray(r.tests) ? r.tests.slice(0, MAX_TESTS + 1) : [];
|
|
109
|
+
if (!tests.length || tests.length > MAX_TESTS) return { error: `tests are 1 to ${MAX_TESTS} of { "in": "text" | "attr" | "source", "re": "<regular expression>", "flags"?: "i" }` };
|
|
110
|
+
const out = [];
|
|
111
|
+
for (const t of tests) {
|
|
112
|
+
if (!isObj(t) || !IN.includes(t.in)) return { error: 'each test reads "text" (the screen\'s words, no buttons or links), "attr" (class and id) or "source"' };
|
|
113
|
+
const re = String(t.re || ''); if (!re || re.length > MAX_RE) return { error: `each test has a regular expression under ${MAX_RE} characters` };
|
|
114
|
+
const flags = String(t.flags || '').replace(/[^imsu]/g, '');
|
|
115
|
+
if (!regexOf({ re, flags })) return { error: 'this is not a regular expression: ' + one(re, 80) };
|
|
116
|
+
out.push({ in: t.in, re, ...(flags ? { flags } : {}) });
|
|
117
|
+
}
|
|
118
|
+
const bad = String(r.bad || ''), good = String(r.good || '');
|
|
119
|
+
if (!bad || !good || bad.length > MAX_EXAMPLE || good.length > MAX_EXAMPLE) return { error: 'bad and good are two small HTML pages: one the rule must fail, one it must pass' };
|
|
120
|
+
return { rule: { id, title, words, tests: out, bad, good } };
|
|
121
|
+
}
|
|
122
|
+
/** PURE. A rule earns its place when it fails its bad example and passes its good one. */
|
|
123
|
+
function earn(rule) {
|
|
124
|
+
const bad = run(rule.bad, [rule]), good = run(rule.good, [rule]);
|
|
125
|
+
if (!bad.length) return { ok: false, error: 'the rule does not catch its bad example, so it would catch nothing' };
|
|
126
|
+
if (good.length) return { ok: false, error: 'the rule fails its good example (a false alarm on "' + one(good[0].lines[0], 80) + '"): narrow it' };
|
|
127
|
+
return { ok: true };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ── the ledger ── */
|
|
131
|
+
const file = (rt) => path.join(rt, FILE);
|
|
132
|
+
function lines(rt) {
|
|
133
|
+
if (!rt) return [];
|
|
134
|
+
let raw = ''; try { raw = fs.readFileSync(file(rt), 'utf8'); } catch { return []; }
|
|
135
|
+
const out = [];
|
|
136
|
+
for (const l of raw.split('\n')) { if (!l) continue; try { const j = JSON.parse(l); if (isObj(j)) out.push(j); } catch { /* a torn line */ } }
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
/** Every rule, seeds first, then the PM's own, with its state: on, seed, undoneAt. */
|
|
140
|
+
function read(rt) {
|
|
141
|
+
const m = new Map();
|
|
142
|
+
for (const s of SEED) m.set(s.id, { ...s, tests: s.tests.map((t) => ({ ...t })), on: true, seed: true });
|
|
143
|
+
for (const l of lines(rt)) {
|
|
144
|
+
if (l.kind === 'add' && isObj(l.rule)) { const v = validate(l.rule); if (v.rule) m.set(v.rule.id, { ...v.rule, at: l.at, by: l.by || null, on: true, seed: false }); }
|
|
145
|
+
else if ((l.kind === 'undo' || l.kind === 'restore') && m.has(l.id)) { const r = m.get(l.id); r.on = l.kind === 'restore'; if (l.kind === 'undo') r.undoneAt = l.at; else delete r.undoneAt; }
|
|
146
|
+
}
|
|
147
|
+
return { rules: [...m.values()] };
|
|
148
|
+
}
|
|
149
|
+
const active = (rt) => read(rt).rules.filter((r) => r.on);
|
|
150
|
+
function append(rt, line) { fs.mkdirSync(rt, { recursive: true }); fs.appendFileSync(file(rt), JSON.stringify(line) + '\n'); }
|
|
151
|
+
/** Add (or, with the same id, replace: the PM's later words win) a rule, once it earns its place. An undone rule needs again: true. */
|
|
152
|
+
function add(rt, raw, { by = 'agent:cli', again = false, now = Date.now() } = {}) {
|
|
153
|
+
if (!rt) return { ok: false, error: 'no runtime state folder' };
|
|
154
|
+
const v = validate(raw); if (v.error) return { ok: false, error: v.error };
|
|
155
|
+
const e = earn(v.rule); if (!e.ok) return e;
|
|
156
|
+
const cur = read(rt).rules.find((r) => r.id === v.rule.id);
|
|
157
|
+
if (cur && !cur.on && !again) return { ok: false, error: `the PM undid "${cur.title}". Add it again only when the PM says it again (again: true, --again)` };
|
|
158
|
+
append(rt, { at: new Date(now).toISOString(), by, kind: 'add', rule: v.rule });
|
|
159
|
+
if (cur && !cur.on) append(rt, { at: new Date(now).toISOString(), by, kind: 'restore', id: v.rule.id });
|
|
160
|
+
return { ok: true, rule: { id: v.rule.id, title: v.rule.title }, replaced: !!cur };
|
|
161
|
+
}
|
|
162
|
+
function turn(kind) {
|
|
163
|
+
return (rt, id, { by = 'pm:page', now = Date.now() } = {}) => {
|
|
164
|
+
if (!rt) return { ok: false, error: 'no runtime state folder' };
|
|
165
|
+
const cur = read(rt).rules.find((r) => r.id === id);
|
|
166
|
+
if (!cur) return { ok: false, error: 'there is no such prototype rule' };
|
|
167
|
+
if (cur.on === (kind === 'restore')) return { ok: true, rule: { id, title: cur.title }, same: true };
|
|
168
|
+
append(rt, { at: new Date(now).toISOString(), by, kind, id });
|
|
169
|
+
return { ok: true, rule: { id, title: cur.title } };
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const undo = turn('undo'), restore = turn('restore');
|
|
173
|
+
/** What the page shows: no tests or examples, only what the PM reads. */
|
|
174
|
+
const listOf = (rt) => read(rt).rules.map((r) => ({ id: r.id, title: r.title, words: r.words, at: r.at, on: r.on, seed: !!r.seed, ...(r.undoneAt ? { undoneAt: r.undoneAt } : {}) }));
|
|
175
|
+
|
|
176
|
+
module.exports = { FILE, SEED, file, read, active, listOf, screenText, attrsOf, run, validate, earn, add, undo, restore };
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
* POST /api/lab/delete { ws, ini, file? | n?, key? } → { ok, batch, said, deleted, next } delete one prototype version (no file and no n:
|
|
24
24
|
* the prototype now); next: what the Viewer opens instead, or null. `pmos lab delete` reaches it too
|
|
25
25
|
* POST /api/lab/restore { ws, batch } → { ok, said, back } Undo of that delete (`pmos lab undo <batch>`)
|
|
26
|
+
* GET /api/lab/rules → { ok, rules: [{ id, title, words, at, on, seed, undoneAt? }] } the PM's prototype rules (lib/prototype-rules.js)
|
|
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
|
+
* Origin, D98); undo and restore: Settings › PMOS › Prototype rules (a page press)
|
|
26
29
|
* POST /api/lab/comment { ws, ini, file, el?, label?, text, x?, y?, send? } → { ok, id } a comment pinned to an element (send: it was
|
|
27
30
|
* sent to PMOS as the next change; else it is kept for the team)
|
|
28
31
|
*
|
|
@@ -109,6 +112,7 @@ function others(ctx, w, dir, T, now) {
|
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
const READS = {
|
|
115
|
+
'/api/lab/rules': (ctx, res) => { ctx.json(res, { ok: true, rules: require('./prototype-rules.js').listOf(ctx.runtimeDir) }); return true; },
|
|
112
116
|
'/api/lab': (ctx, res, url) => {
|
|
113
117
|
const w = wsOf(ctx, url.searchParams.get('ws')); if (!w) return fail(ctx, res, 404, 'no such workspace');
|
|
114
118
|
const dir = dirOf(ctx, w); if (!dir) { ctx.json(res, { ok: true, lab: null }); return true; }
|
|
@@ -326,6 +330,17 @@ function liveRound(ctx, res, b) {
|
|
|
326
330
|
ctx.json(res, r);
|
|
327
331
|
return true;
|
|
328
332
|
}
|
|
333
|
+
/** POST /api/lab/rules: add (once it earns its place), undo or restore one of the PM's prototype rules. */
|
|
334
|
+
function protoRules(ctx, res, b, by) {
|
|
335
|
+
const RU = require('./prototype-rules.js'), rt = ctx.runtimeDir;
|
|
336
|
+
if (!rt) return fail(ctx, res, 409, 'no runtime state folder');
|
|
337
|
+
const op = String(b.op || '');
|
|
338
|
+
const r = op === 'add' ? RU.add(rt, b.rule, { by, again: b.again === true })
|
|
339
|
+
: op === 'undo' || op === 'restore' ? RU[op](rt, String(b.id || ''), { by }) : { ok: false, error: 'op is add, undo or restore' };
|
|
340
|
+
if (!r.ok) return fail(ctx, res, op === 'add' ? 422 : 404, r.error);
|
|
341
|
+
ctx.json(res, r);
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
329
344
|
const readsDrop = (dir, b) => LAB.readLines(LAB.ledgerFile(dir)).some((l) => l.kind === 'drop' && l.batch === b);
|
|
330
345
|
|
|
331
346
|
module.exports = {
|
|
@@ -335,12 +350,19 @@ module.exports = {
|
|
|
335
350
|
if (req.method === 'GET') { const fn = READS[p0]; if (!fn) return fail(ctx, res, 404, 'not found'); return fn(ctx, res, url); }
|
|
336
351
|
if (req.method !== 'POST') return fail(ctx, res, 405, 'GET or POST only');
|
|
337
352
|
const fn = WRITES[p0];
|
|
338
|
-
if (!fn && !['/api/lab/round', '/api/lab/delete', '/api/lab/restore'].includes(p0)) return fail(ctx, res, 404, 'not found');
|
|
353
|
+
if (!fn && !['/api/lab/round', '/api/lab/delete', '/api/lab/restore', '/api/lab/rules'].includes(p0)) return fail(ctx, res, 404, 'not found');
|
|
339
354
|
const got = await ctx.readJson(req);
|
|
340
355
|
if (!got.ok || !isObj(got.body)) return fail(ctx, res, 400, 'the body must be a JSON object');
|
|
341
356
|
// 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
|
|
342
357
|
// terminal too). It starts a round, or with propose: true only files the ✦ ask the PM's ✓ starts. Never a write of a record.
|
|
343
358
|
if (p0 === '/api/lab/round') return liveRound(ctx, res, got.body);
|
|
359
|
+
// 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
|
|
360
|
+
if (p0 === '/api/lab/rules') {
|
|
361
|
+
let by;
|
|
362
|
+
if (req.headers.origin) { const g = guard.requirePagePress(req, got.body); if (!g.ok) return fail(ctx, res, g.status, g.error); by = (g.actor && g.actor.by) || 'pm:page'; }
|
|
363
|
+
else by = /^(pm|agent):[\w.:-]{1,80}$/.test(String(got.body.by || '')) ? got.body.by : 'agent:cli';
|
|
364
|
+
return protoRules(ctx, res, got.body, by);
|
|
365
|
+
}
|
|
344
366
|
// delete and undo a prototype version: the trash in the Viewer (a page press), or `pmos lab delete|undo` from the chat's agent (D98,
|
|
345
367
|
// no Origin: the same door as the live round). A request from another site always carries its Origin, so it meets the page press.
|
|
346
368
|
if (p0 === '/api/lab/delete' || p0 === '/api/lab/restore') {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.608.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.608.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
.pc-prog small { color: var(--cz-ink3); font-variant-numeric: tabular-nums; }
|
|
75
75
|
.pc-bar2 { display: block; height: 4px; border-radius: 2px; background: var(--cz-well); overflow: hidden; }
|
|
76
76
|
.pc-bar2 i { display: block; height: 100%; background: var(--cz-blue); transition: width .4s ease; }
|
|
77
|
+
.pc-fixed { margin: 0 0 8px; font-size: var(--fs-meta); color: var(--cz-ink2); }
|
|
77
78
|
.pc-lost { display: block; color: var(--cz-ink2); padding: 8px 10px; border-radius: 8px; background: var(--cz-well); margin-bottom: 8px; }
|
|
78
79
|
@keyframes pcPulse { 50% { opacity: 1; } }
|
|
79
80
|
@media (prefers-reduced-motion: reduce) { .pc-making i { animation: none; opacity: .7; } }
|
|
@@ -221,6 +221,15 @@ function progressHtml(c) {
|
|
|
221
221
|
+ `${p && p.total ? `<span class="pc-bar2" aria-hidden="true"><i style="width:${pct}%"></i></span>` : ''}</div>`;
|
|
222
222
|
}
|
|
223
223
|
if (typeof document !== 'undefined' && typeof setInterval === 'function') setInterval(() => { for (const el of document.querySelectorAll('[data-pc-clock]')) el.textContent = clock(el.dataset.pcClock); }, 1000);
|
|
224
|
+
/** The PM's prototype rules (lib/prototype-rules.js): one quiet line, only when PMOS fixed something before the version opened, and the rule
|
|
225
|
+
* it still breaks when the one fix did not reach it (never hidden). Nothing at all when the first draft passed (zero is silence). */
|
|
226
|
+
export function checksHtml(c) {
|
|
227
|
+
const k = c && c.checks; if (!k) return '';
|
|
228
|
+
const n = k.fixed || 0, miss = (k.missed || []).filter(Boolean);
|
|
229
|
+
const fixed = n ? `PMOS fixed ${n === 1 ? '1 thing' : n + ' things'} before showing you this.` : '';
|
|
230
|
+
const left = miss.length ? ` It still breaks your ${miss.length === 1 ? 'rule' : 'rules'}: ${miss.map(esc).join('; ')}.` : '';
|
|
231
|
+
return `<p class="pc-fixed" role="status">${fixed}${left}</p>`;
|
|
232
|
+
}
|
|
224
233
|
function protoCard(c, v, making) {
|
|
225
234
|
const sel = V.sel && !(V.insp && !V.side) ? `<p class="pc-sel">${SVG(I.point, 14)}<b>${esc(V.sel.label || V.sel.el)}</b> is in the chat box: say the change.${ib('data-pc-unsel', 'Clear the element', I.x)}</p>` : '';
|
|
226
235
|
const cm = (c.comments || []).filter((x) => !x.send);
|
|
@@ -229,7 +238,7 @@ function protoCard(c, v, making) {
|
|
|
229
238
|
const sug = suggestion(c);
|
|
230
239
|
const draw = V.mode === 'draw' ? `<canvas class="pc-ink" aria-label="Sketch over the prototype"></canvas><span class="pc-inkacts">${ib('data-pc-ink="attach"', 'Attach the sketch to your next message', I.attach, 'blue')}${ib('data-pc-ink="clear"', 'Clear the sketch', I.x)}</span>` : '';
|
|
231
240
|
const lost = c.notMade ? `<p class="pc-making pc-lost">Version ${c.round} was not made: ${esc(c.notMade)}.${c.fallbackN ? ` This is version ${c.fallbackN}.` : ''} Ask in the chat for it in smaller steps, one screen or format at a time.</p>` : '';
|
|
232
|
-
return { pre: lost + (making ? progressHtml(c) :
|
|
241
|
+
return { pre: lost + (making ? progressHtml(c) : checksHtml(c)), dev: `<div class="pc-frame" data-pc-frame>${v.url ? '' : '<p class="pc-none">PMOS is making it.</p>'}</div>${draw}`, post: sel + draft + list + sug };
|
|
233
242
|
}
|
|
234
243
|
/** The notes beside the design (notes.json): what the run wants the PM to know, kept off the screens (Wawan 2026-11-18). Only the notes for
|
|
235
244
|
* the screen shown and the ones for the whole prototype; none at all is silence. A note on a layer flashes it on the design. */
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* (GET/POST /api/next-prompt/prefs; batch 26 item 2)
|
|
13
13
|
* › Checks (a heading inside Claude since U4; it was the section Claude’s checks) Grill by itself (Full, Only at stage exits, Off) and the monthly credit for checks with what this month used (grill.mode,
|
|
14
14
|
* grill.cap, POST /api/settings; GET /api/grill; canvas GrillEntry). At the cap Claude pauses and says so once here.
|
|
15
|
+
* › Prototype rules (after Checks; openSettings('rules')) the checks every prototype version meets before it opens, each from the PM's words,
|
|
16
|
+
* with Undo and Bring back (GET and POST /api/lab/rules, lib/prototype-rules.js)
|
|
15
17
|
* › Jev and Laya (a sub-panel of General › Extras since U4) the TypeSafe key, Laya on this computer and the per-repository switches (pm/cozy-jl.js; canvas JlA1Empty–JlA4Phone)
|
|
16
18
|
* › Adler (a sub-panel of General › Extras since U4) how much of Claude's face shows, Motion, Celebrations, Quiet after (adler.*, POST /api/settings; canvas AdM5, batch 16 item 2)
|
|
17
19
|
* › Dress for the day (adler.dress.*, canvas AsSet1, batch 18 item 8): the master switch, where you are, one switch per group,
|
|
@@ -425,7 +427,30 @@ function claudeSec() {
|
|
|
425
427
|
+ trow('API key', keySub, keyRight)
|
|
426
428
|
+ (k.present && C.off ? trow('Runs on the API', 'Off: PMOS_GRILL_API is off in the environment.', '<span class="ev-pill">Off</span>') : '')
|
|
427
429
|
+ sharpenRows()
|
|
428
|
-
+ '<h4 id="evChecks">Checks</h4>' + checksSec()
|
|
430
|
+
+ '<h4 id="evChecks">Checks</h4>' + checksSec() // U4: the section Claude’s checks folded in here
|
|
431
|
+
+ '<h4 id="evProtoRules">Prototype rules</h4>' + protoRulesSec();
|
|
432
|
+
}
|
|
433
|
+
/* Settings › PMOS › Prototype rules (initiative prototype-rules, design "Prototypes right on the first try", board FtB): each correction of
|
|
434
|
+
* the PM's that is true of every prototype, as a check PMOS runs on each version before it opens (lib/prototype-rules.js). Each row is the
|
|
435
|
+
* rule, the PM's own words and the date, and Undo. No run button and no picker: PMOS adds them from the chat. An undone rule waits below it
|
|
436
|
+
* with Bring back, and PMOS does not add it again unless the PM says it again. GET and POST /api/lab/rules. */
|
|
437
|
+
function protoRulesSec() {
|
|
438
|
+
const R = T.pru;
|
|
439
|
+
if (!R) return '<p class="ev-small ev-mut">Reading your prototype rules.</p>';
|
|
440
|
+
if (R.ok === false) return `<p class="ev-small ev-mut">Your prototype rules could not be read: ${esc(R.error || 'the server did not answer')}.</p>`;
|
|
441
|
+
const on = R.rules.filter((r) => r.on), off = R.rules.filter((r) => !r.on);
|
|
442
|
+
const sub = (r) => [r.words ? '“' + r.words + '”' : '', dayOf(r.at)].filter(Boolean).join(' · ');
|
|
443
|
+
return '<p class="ev-small ev-mut ev-lead">PMOS checks every prototype version against these before you see it, and fixes it once when one fails. Each comes from your own words in the chat.</p>'
|
|
444
|
+
+ (on.length ? on.map((r) => trow(r.title, sub(r), `<button type="button" class="ev-btn sm" data-ev-pru="undo" data-ev-pru-id="${esc(r.id)}" aria-label="${esc('Undo the rule ' + r.title)}">Undo</button>`)).join('')
|
|
445
|
+
: '<p class="ev-small ev-mut">No rules now. Each correction you make that is true of every prototype shows here.</p>')
|
|
446
|
+
+ off.map((r) => trow(r.title, 'You undid it' + (r.undoneAt ? ' on ' + dayOf(r.undoneAt) : '') + '. PMOS adds it again only when you say it again.', `<button type="button" class="ev-btn sm" data-ev-pru="restore" data-ev-pru-id="${esc(r.id)}" aria-label="${esc('Bring back the rule ' + r.title)}">Bring back</button>`)).join('');
|
|
447
|
+
}
|
|
448
|
+
async function saveProtoRule(op, id) {
|
|
449
|
+
const r = await pmPost('/api/lab/rules', { op, id });
|
|
450
|
+
if (r && r.ok && T.pru && T.pru.ok !== false) { const x = T.pru.rules.find((y) => y.id === id); if (x) { x.on = op === 'restore'; if (op === 'undo') x.undoneAt = new Date().toISOString(); else delete x.undoneAt; } }
|
|
451
|
+
const t = r && r.rule ? r.rule.title : 'the rule';
|
|
452
|
+
T.msg = r && r.ok ? (op === 'undo' ? 'Undone. PMOS no longer checks prototypes for: ' + t + '.' : 'Back. PMOS checks every prototype for: ' + t + ' again.') : (r && r.error) || 'Not saved.';
|
|
453
|
+
draw();
|
|
429
454
|
}
|
|
430
455
|
/* Settings › Claude › Sharpen prompts (batch 26 item 2; pm/next-prompt-ui.js, lib/routes-next-prompt.js): the suggestions after a reply, Sharpen as I
|
|
431
456
|
* type (on by default: both run as a background `claude -p` in the PM's own Claude session, Wawan 2026-11-04), the style, and Your own rules.
|
|
@@ -471,7 +496,7 @@ function checksSec() {
|
|
|
471
496
|
}
|
|
472
497
|
const BODY = { general, claude: claudeSec, connectors, workspaces, updates };
|
|
473
498
|
// the old section names (deep links, other pages' calls): where their controls are now (U4)
|
|
474
|
-
const MOVED = { scheduled: ['connectors', 'sw:list'], checks: ['claude', ''], adler: ['general', 'adler'], jl: ['general', 'jl'], dress: ['general', 'adler'], workflows: ['workspaces', 'workflows'] };
|
|
499
|
+
const MOVED = { scheduled: ['connectors', 'sw:list'], checks: ['claude', ''], rules: ['claude', ''], adler: ['general', 'adler'], jl: ['general', 'jl'], dress: ['general', 'adler'], workflows: ['workspaces', 'workflows'] };
|
|
475
500
|
let disposeClaudeSetup = null;
|
|
476
501
|
function draw() {
|
|
477
502
|
const el = T.el; if (!el || el.hidden) return;
|
|
@@ -553,6 +578,7 @@ function mount() {
|
|
|
553
578
|
async function press(e) {
|
|
554
579
|
const t = e.target.closest('a[data-ev-sec], a[data-ev-cadd], button'); if (!t) return;
|
|
555
580
|
if (t.dataset.evCadd) { startWait(t.dataset.evCadd); draw(); return; } // the link opens the Claude account's connector page; PMOS waits for it
|
|
581
|
+
if (t.dataset.evPru) { if (T.busy) return; T.busy = true; try { await saveProtoRule(t.dataset.evPru, t.dataset.evPruId); } finally { T.busy = false; } return; }
|
|
556
582
|
if (t.dataset.evCcat) { T.cat = t.dataset.evCcat; draw(); const f = T.el.querySelector(`[data-ev-ccat="${T.cat}"]`); if (f) f.focus(); return; }
|
|
557
583
|
if (t.dataset.evPok || t.dataset.evPno) { if (T.busy) return; T.busy = true; try { await decideProp(t.dataset.evPok || t.dataset.evPno, !!t.dataset.evPok); } finally { T.busy = false; } return; }
|
|
558
584
|
if (t.dataset.evSec) { e.preventDefault(); const m = MOVED[t.dataset.evSec]; T.sec = m ? m[0] : t.dataset.evSec; T.sub = m ? m[1] : ''; T.msg = ''; T.dress = false; draw(); const f = T.el.querySelector(`[data-ev-sec="${T.sec}"]`); if (f) f.focus(); openCheck(); return; }
|
|
@@ -700,6 +726,7 @@ async function load() {
|
|
|
700
726
|
SW.swLoad(draw);
|
|
701
727
|
pmGet('/api/autonomy/kinds').then((k) => { T.ck = k && k.ok ? k : { ok: false, error: (k && k.error) || '' }; draw(); }).catch(() => { T.ck = { ok: false }; draw(); });
|
|
702
728
|
pmGet('/api/artefacts/lessons').then((l) => { T.ls = l && l.ok ? l : null; draw(); }).catch(() => { T.ls = null; });
|
|
729
|
+
pmGet('/api/lab/rules').then((r) => { T.pru = r && r.ok ? { ok: true, rules: Array.isArray(r.rules) ? r.rules : [] } : { ok: false, error: (r && r.error) || '' }; draw(); }).catch(() => { T.pru = { ok: false }; draw(); });
|
|
703
730
|
pmGet('/api/grill').then((g) => { T.gr = g && g.ok ? g : { ok: false, error: (g && g.error) || '' }; draw(); }).catch(() => { T.gr = { ok: false }; draw(); });
|
|
704
731
|
pmGet('/api/next-prompt/prefs').then((n) => { T.np = n && n.ok ? n : null; draw(); }).catch(() => { T.np = null; });
|
|
705
732
|
pmGet('/api/profiles').then(async (pr) => { const k = await pmGet('/api/anthropic'); T.cl = { profiles: pr && Array.isArray(pr.profiles) ? pr.profiles : [], prefs: (pr && pr.prefs) || {}, perr: pr && pr.ok === false ? (pr.error || 'the server did not answer') : '', key: k && k.ok ? k.key : { present: false, source: null }, off: !!(k && k.off) }; draw(); }).catch(() => { T.cl = { profiles: [], prefs: {}, perr: 'the server did not answer', key: { present: false, source: null } }; draw(); });
|
|
@@ -727,11 +754,11 @@ export function openSettings(section, o = {}) {
|
|
|
727
754
|
const m = MOVED[section];
|
|
728
755
|
if (m) { T.sec = m[0]; T.sub = m[1]; T.dress = section === 'dress'; } else if (section && BODY[section]) { T.sec = section; T.sub = ''; T.dress = false; }
|
|
729
756
|
else if (el.hidden) { T.sec = 'general'; T.sub = ''; T.dress = false; } // a fresh open with no section opens on General (R2), not on the section of the last visit
|
|
730
|
-
if (el.hidden) { const ae = document.activeElement; T.back = ae && ae !== document.body ? ae : null; T.ws = null; T.src = null; T.msg = ''; T.phase = ''; T.auto = false; T.wkOpen = new Set(); T.wkMore = new Set(); T.arc = false; T.fresh = null; T.note = {}; T.info = false; T.fold = false; T.dir = null; T.q = ''; T.cat = 'all'; stopWait(); T.dset = {}; T.cl = null; T.gr = null; T.np = null; T.ck = null; T.ls = null; JL.reset(); SW.swReset(); }
|
|
757
|
+
if (el.hidden) { const ae = document.activeElement; T.back = ae && ae !== document.body ? ae : null; T.ws = null; T.src = null; T.msg = ''; T.phase = ''; T.auto = false; T.wkOpen = new Set(); T.wkMore = new Set(); T.arc = false; T.fresh = null; T.note = {}; T.info = false; T.fold = false; T.dir = null; T.q = ''; T.cat = 'all'; stopWait(); T.dset = {}; T.cl = null; T.gr = null; T.pru = null; T.np = null; T.ck = null; T.ls = null; JL.reset(); SW.swReset(); }
|
|
731
758
|
el.hidden = false; document.getElementById('evStScrim').hidden = false; el.setAttribute('data-esc-layer', '');
|
|
732
759
|
draw();
|
|
733
760
|
const f = el.querySelector('[aria-current="page"]'); if (f) f.focus();
|
|
734
|
-
if (section === 'checks') { const h = el.querySelector('#evChecks'); if (h && h.scrollIntoView) h.scrollIntoView({ block: 'start' }); }
|
|
761
|
+
if (section === 'checks' || section === 'rules') { const h = el.querySelector(section === 'rules' ? '#evProtoRules' : '#evChecks'); if (h && h.scrollIntoView) h.scrollIntoView({ block: 'start' }); }
|
|
735
762
|
load();
|
|
736
763
|
return el;
|
|
737
764
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Prototype rules (initiative prototype-rules, step 2 of \"Prototypes right on the first try\"): the PM's corrections as checks run after renderCheck and before a version opens, one fix run on a failure, a rule added only when it fails its bad example and passes its good one, Undo in Settings › PMOS (lib/prototype-rules.js, lib/live-round.js, lib/routes-lab.js /api/lab/rules, lib/lab-cli.js). Backend and source reads only.",
|
|
3
|
+
"modules": [
|
|
4
|
+
"prototype-rules.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": { "prototype-rules.test.js": 1 }
|
|
7
|
+
}
|