create-pmos 0.841.0 → 0.843.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.
Files changed (34) hide show
  1. package/package.json +59 -54
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/changelog.json +58 -0
  7. package/workspace/guide/cli.md +24 -0
  8. package/workspace/guide/layout.md +3 -0
  9. package/workspace/guide/settings-and-switches.md +1 -0
  10. package/workspace/lib/build-engine.js +4 -1
  11. package/workspace/lib/copy-tests.js +281 -0
  12. package/workspace/lib/events-place.js +38 -2
  13. package/workspace/lib/factory-traces.js +2 -1
  14. package/workspace/lib/features.json +2 -0
  15. package/workspace/lib/initiative-cost.js +259 -0
  16. package/workspace/lib/pmos-verbs.js +6 -0
  17. package/workspace/lib/routes-artefacts.js +31 -1
  18. package/workspace/lib/routes-factory-metrics.js +54 -1
  19. package/workspace/lib/routes-proposals.js +7 -0
  20. package/workspace/package-lock.json +2 -2
  21. package/workspace/package.json +1 -1
  22. package/workspace/public/pm/bd-backlog.css +3 -0
  23. package/workspace/public/pm/bd-backlog.js +36 -7
  24. package/workspace/public/pm/bd-pop-ds.js +8 -4
  25. package/workspace/public/pm/copy-tests.js +95 -0
  26. package/workspace/public/pm/cozy-events-view.js +16 -2
  27. package/workspace/public/pm/cozy-events.css +5 -1
  28. package/workspace/public/pm/cozy-events.js +6 -1
  29. package/workspace/public/pm/cozy-pop-work.js +14 -1
  30. package/workspace/public/pm/initiative-cost.js +103 -0
  31. package/workspace/public/pm/pop-work-model.js +2 -1
  32. package/workspace/test-lists/copy-tests.json +9 -0
  33. package/workspace/test-lists/events-bring.json +9 -0
  34. package/workspace/test-lists/initiative-cost.json +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.841.0",
3
+ "version": "0.843.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,64 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.843.0",
38
+ "at": "2026-11-25T17:32:30.120Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1952,
43
+ "t": "Copy and layout tests on an initiative, drafted from plain words (job #1905, A351)",
44
+ "s": "Copy and layout tests on an initiative, drafted from plain words (job #1905, A351)",
45
+ "k": "new",
46
+ "h": "Copy and layout tests on an initiative, drafted from plain words (job #1905, A351)",
47
+ "try": {
48
+ "steps": [
49
+ "Open Work and open an initiative whose record names a rollout_flag (add rollout_flag: checkout-button to one if none does)",
50
+ "Under the Overview, read the ✦ line in the Copy test block, type \"Pay now\" in its field and press ✦",
51
+ "Press ▶ to start it, then ask the chat: copy test results A 10,000 people 410 converted, B 10,000 people 460 converted"
52
+ ],
53
+ "see": "With nothing typed in the chat, the Copy test block shows its ✦ offer; ✦ drafts A against B with Undo. Then a Copy test block with one table (Variant, Copy, the rate and how sure), one ✦ line such…",
54
+ "open": "/premium-board.html"
55
+ },
56
+ "i": "copy-tests"
57
+ },
58
+ {
59
+ "n": 2027,
60
+ "t": "Events says what to bring on each meeting (job #2012, TbEvents)",
61
+ "s": "Events says what to bring on each meeting (job #2012, TbEvents)",
62
+ "k": "new",
63
+ "h": "Events says what to bring on each meeting (job #2012, TbEvents)",
64
+ "try": {
65
+ "steps": [
66
+ "Open Events.",
67
+ "Look at a meeting under Coming up that is about one of your products or initiatives.",
68
+ "Read the ✦ line under it, then open one of the dates it names in the list."
69
+ ],
70
+ "see": "Each meeting tied to your work says what to bring, for example \"Bring two calls: …\", naming dates that Events lists; a meeting with nothing to decide says \"Nothing new for this one yet.\"; focus time…",
71
+ "open": "/premium-events.html"
72
+ },
73
+ "i": "tb-events-bring"
74
+ },
75
+ {
76
+ "n": 1958,
77
+ "t": "What each initiative and merged pull request cost, and a pause for a stall (job #1906)",
78
+ "s": "What each initiative and merged pull request cost, and a pause for a stall (job #1906)",
79
+ "k": "new",
80
+ "h": "What each initiative and merged pull request cost, and a pause for a stall (job #1906)",
81
+ "try": {
82
+ "steps": [
83
+ "Open Work and press the Cost tab: read each initiative's agent hours, spend and result",
84
+ "Open an initiative from Work, press ⋯ and pick Cost: one row per merged pull request with its own cost",
85
+ "Where a row says 0 merged in 7 days, press the pause button on its ✦, then Undo in the toast"
86
+ ],
87
+ "see": "One row per initiative the factory worked on: agent hours, spend in dollars and how many pull requests merged. An initiative that spent for 7 days with no merge shows one ✦ asking to pause its jobs.…",
88
+ "open": "/premium-board.html?work=cost"
89
+ },
90
+ "i": "initiative-cost"
91
+ }
92
+ ]
93
+ },
36
94
  {
37
95
  "v": "0.841.0",
38
96
  "at": "2026-11-25T17:17:15.241Z",
@@ -1033,59 +1091,6 @@
1033
1091
  }
1034
1092
  }
1035
1093
  ]
1036
- },
1037
- {
1038
- "v": "0.819.0",
1039
- "at": "2026-11-25T08:28:20.856Z",
1040
- "f": 4,
1041
- "prs": [
1042
- {
1043
- "n": 1878,
1044
- "t": "Pmos approver shows what each approver asked before",
1045
- "s": "Pmos approver shows what each approver asked before",
1046
- "k": "new",
1047
- "i": "approver-memory",
1048
- "h": "Pmos approver shows what each approver asked before",
1049
- "try": {
1050
- "steps": [
1051
- "In the chat on Today, ask: what did Ana ask on earlier sign-offs?",
1052
- "Open an initiative in Work that waits on a sign-off and ask the chat: what did its approvers ask before?"
1053
- ],
1054
- "see": "The chat lists what that person had to sign off, what they answered and what they objected to, newest first, each with its source. A person with nothing recorded is left out.",
1055
- "open": "/premium-board.html"
1056
- }
1057
- },
1058
- {
1059
- "n": 1867,
1060
- "t": "Each report draft in each reader's language",
1061
- "s": "Each report draft in each reader's language",
1062
- "k": "new",
1063
- "i": "report-reader-language"
1064
- },
1065
- {
1066
- "n": 1868,
1067
- "t": "The factory numbers snapshot per station (job #1862)",
1068
- "s": "The factory numbers snapshot per station (job #1862)",
1069
- "k": "new",
1070
- "i": "factory-floor-snapshot",
1071
- "h": "The factory numbers snapshot per station (job #1862)",
1072
- "try": {
1073
- "steps": [
1074
- "On Today, open Ask PMOS and ask: what did each factory station make this week?",
1075
- "Open Work and compare the initiatives it names as waiting with their rows."
1076
- ],
1077
- "see": "PMOS answers per station (Intake, Shape, Plan, Track, Evaluate, Check, You) with what waits, what it made this week, its PMOS time and what you undid; tokens and money say not recorded yet.",
1078
- "open": "/today.html"
1079
- }
1080
- },
1081
- {
1082
- "n": 1875,
1083
- "t": "I have N minutes — one pick in Ctrl K, the chat and pmos pick (job #1873)",
1084
- "s": "I have N minutes — one pick in Ctrl K, the chat and pmos pick (job #1873)",
1085
- "k": "new",
1086
- "i": "time-box-pick-chat"
1087
- }
1088
- ]
1089
1094
  }
1090
1095
  ]
1091
1096
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@3b5deb6e9
1
+ kernel-source: pmos@b534252a3
2
2
  assembled: 2026-11-25
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-25T17:17:11Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T17:32:26Z"}
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-25T17:17:11Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T17:32:26Z"}
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-25T17:17:11Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T17:32:26Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,62 @@
1
1
  [
2
+ {
3
+ "v": "0.843.0",
4
+ "at": "2026-11-25T17:32:30.120Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1952,
9
+ "t": "Copy and layout tests on an initiative, drafted from plain words (job #1905, A351)",
10
+ "s": "Copy and layout tests on an initiative, drafted from plain words (job #1905, A351)",
11
+ "k": "new",
12
+ "h": "Copy and layout tests on an initiative, drafted from plain words (job #1905, A351)",
13
+ "try": {
14
+ "steps": [
15
+ "Open Work and open an initiative whose record names a rollout_flag (add rollout_flag: checkout-button to one if none does)",
16
+ "Under the Overview, read the ✦ line in the Copy test block, type \"Pay now\" in its field and press ✦",
17
+ "Press ▶ to start it, then ask the chat: copy test results A 10,000 people 410 converted, B 10,000 people 460 converted"
18
+ ],
19
+ "see": "With nothing typed in the chat, the Copy test block shows its ✦ offer; ✦ drafts A against B with Undo. Then a Copy test block with one table (Variant, Copy, the rate and how sure), one ✦ line such…",
20
+ "open": "/premium-board.html"
21
+ },
22
+ "i": "copy-tests"
23
+ },
24
+ {
25
+ "n": 2027,
26
+ "t": "Events says what to bring on each meeting (job #2012, TbEvents)",
27
+ "s": "Events says what to bring on each meeting (job #2012, TbEvents)",
28
+ "k": "new",
29
+ "h": "Events says what to bring on each meeting (job #2012, TbEvents)",
30
+ "try": {
31
+ "steps": [
32
+ "Open Events.",
33
+ "Look at a meeting under Coming up that is about one of your products or initiatives.",
34
+ "Read the ✦ line under it, then open one of the dates it names in the list."
35
+ ],
36
+ "see": "Each meeting tied to your work says what to bring, for example \"Bring two calls: …\", naming dates that Events lists; a meeting with nothing to decide says \"Nothing new for this one yet.\"; focus time…",
37
+ "open": "/premium-events.html"
38
+ },
39
+ "i": "tb-events-bring"
40
+ },
41
+ {
42
+ "n": 1958,
43
+ "t": "What each initiative and merged pull request cost, and a pause for a stall (job #1906)",
44
+ "s": "What each initiative and merged pull request cost, and a pause for a stall (job #1906)",
45
+ "k": "new",
46
+ "h": "What each initiative and merged pull request cost, and a pause for a stall (job #1906)",
47
+ "try": {
48
+ "steps": [
49
+ "Open Work and press the Cost tab: read each initiative's agent hours, spend and result",
50
+ "Open an initiative from Work, press ⋯ and pick Cost: one row per merged pull request with its own cost",
51
+ "Where a row says 0 merged in 7 days, press the pause button on its ✦, then Undo in the toast"
52
+ ],
53
+ "see": "One row per initiative the factory worked on: agent hours, spend in dollars and how many pull requests merged. An initiative that spent for 7 days with no merge shows one ✦ asking to pause its jobs.…",
54
+ "open": "/premium-board.html?work=cost"
55
+ },
56
+ "i": "initiative-cost"
57
+ }
58
+ ]
59
+ },
2
60
  {
3
61
  "v": "0.841.0",
4
62
  "at": "2026-11-25T17:17:15.241Z",
@@ -791,6 +791,19 @@ Every command takes `--json` and `--root <dir>`. The command does not accept `--
791
791
 
792
792
  The command exits 0 when it is done, 1 when it refuses, and 2 for a usage error.
793
793
 
794
+ ### pmos experiment: copy and layout tests
795
+
796
+ Try new words or a new layout on an initiative and see which does better. Run it in the product's repository, or pass `--root <dir>`, or ask the chat, for example "draft a copy test here: try "Pay now" or "Pay $42.00", behind the flag checkout-button". No running workspace is needed.
797
+
798
+ - `pmos experiment draft <initiative> "<ask>"` drafts a test of two variants. Two quoted texts are A and B. One quoted text is B, and A is "As it is now". With no quotes, B is the ask itself. A screen, layout or order in the ask makes it a layout test. `--flag <flag>` names the product's rollout flag (else the record's `rollout_flag`), `--metric <name>` names the column (default Converted), and `--a` and `--b` set the texts. The draft does not start.
799
+ - `pmos experiment start <id>` starts it behind its flag. Only you start a test. A test with no flag is refused: name it with `pmos experiment flag <id> <flag>`.
800
+ - `pmos experiment result <id> <A|B> --people <n> --converted <n>` records the counts of one variant. The last counts of a variant replace the earlier ones.
801
+ - `pmos experiment show <id>` prints the table and the ✦ line. PMOS works out how sure it is that the leader is better (a one-sided test of two proportions). At 80 % sure or more, the line says, for example, "B wins by 0.5 points (96 % sure). Keep B for everyone?". Under 80 %, it says "Not sure yet".
802
+ - `pmos experiment keep <id>` keeps the winner. It is refused under 80 % sure. PMOS records it and names the flag change, for example "Set checkout-button to B for everyone."; it does not change your flag service. `pmos experiment undo <id>` takes back the test's last step.
803
+ - `pmos experiment list [<initiative>]` lists the tests and their lines. `pmos experiment count [--days 7]` prints how many were drafted; its last line is the number.
804
+ - On Work, the initiative's popup shows each test under the Overview: one table, one ✦ line, ▶ to start a draft and ✓ to keep a winner, each with Undo.
805
+ - The tests are in `planning/copy-tests.jsonl` (`pmos/planning/copy-tests.jsonl` in a kit). PMOS calls no model and sends nothing.
806
+
794
807
  ### pmos measure
795
808
 
796
809
  | Command | What it does |
@@ -1134,6 +1147,17 @@ PMOS never pushes to the default branch and never merges. Every command takes `-
1134
1147
 
1135
1148
  The benchmark needs a signed-in agent CLI. It never pushes and never opens a pull request. A role run cannot start it.
1136
1149
 
1150
+ ### pmos cost: what the factory spent per initiative and pull request
1151
+
1152
+ Where PMOS's factory builds a product's work items, each run leaves its tokens, its cost and its time. These commands add them up per initiative and per merged pull request. Work › Cost shows the same rows.
1153
+
1154
+ - `pmos cost` (or `pmos cost show`) prints one line per initiative the factory worked on: its agent hours, its spend in dollars and how many pull requests merged. An initiative that spent in the last 7 days and has had no merge for 7 days says "0 merged in 7 days", with the `pmos cost pause` that would pause it. `--json` prints the rows.
1155
+ - `pmos cost <initiative>` prints one line per merged pull request of that initiative, each with its own agent hours, spend and tokens, and its link when PMOS opened it.
1156
+ - `pmos cost pause <initiative>` pauses the initiative's new factory jobs: the Builder takes no new work item of it. Work a Builder holds now finishes. PMOS also files one ✦ for a stalled initiative, and its ✓ does the same, with Undo.
1157
+ - `pmos cost resume <initiative>` lets the factory take its jobs again.
1158
+
1159
+ Money shows only in these commands, on Work › Cost and in the initiative's ⋯ › Cost. `PMOS_INITIATIVE_COST=off` stops the ✦.
1160
+
1137
1161
  ### pmos jira
1138
1162
 
1139
1163
  [Jira tickets](jira.md) explains each step with its examples.
@@ -117,6 +117,8 @@ On a computer, Work is built from the parts of the PMOS design system. The top l
117
117
  - **Add to the backlog.** Type a line and press Enter. Name the initiative ("for Migration from Okta") or PMOS puts it in the closest one; when none is close, it asks.
118
118
  - **Items.** A table grouped by initiative, each group with "n items · r ready". The tabs show **All**, **Ready**, **Needs detail** or **Untouched 60 days**. Drag a row by its grip to change the rank (with Undo); the number is its place in the one rank. **Last change** shows when the item last changed; an item untouched for 30 days or more has a badge, for example "79 days untouched". **Group** also groups the rows by what PMOS can do, with its ✓ buttons. Tick rows to change them together. The tune icon filters the rows.
119
119
 
120
+ **Cost** shows on a computer when PMOS's factory has built work items for the product. One row per initiative it worked on: **Agent hours**, **Spend** in dollars and **Result**, for example "3 PRs merged". Press a name to open the initiative. An initiative that spent in the last 7 days and has had no merge for 7 days says "0 merged in 7 days" in red, and one ✦ under the table asks to pause its jobs. The pause button stops new jobs: the factory takes no new work item of it, and the work it holds now finishes. The toast has **Undo**. ✕ keeps it going, and PMOS does not ask again until it stalls again. A paused initiative has a play button that starts its jobs again. Money shows only here and in the initiative's ⋯ › **Cost**, which lists each merged pull request with its own cost. `pmos cost` reads the same rows.
121
+
120
122
  **This sprint** shows all work in the sprint's dates, in Jira and outside it. It holds every ticket of the active Jira sprint, done ones too, and every PMOS task whose dates meet the sprint's dates. A task under way with no date is in it too. Early stages often have no tickets, so their work still shows here.
121
123
 
122
124
  - **The sprint card.** The sprint's name, its end date and what it holds, for example "21 Jira tickets and 7 tasks outside Jira". Under it, "11 of 28 done" with a bar. Then four columns: **Sprint goal**, **In progress**, **To do** and **Done**, each with its count and its first tasks. PMOS drafts the goal from the sprint's work. Press the pencil to write your own; it can name work outside Jira, and PMOS does not write over it. When PMOS has a newer draft, ✓ uses it and ✕ keeps yours. Press the sprint's name to open a past sprint. The arrow icon reads Jira again; a red dot on it means the last read is old. Under the columns, PMOS shows one suggestion, for example to place tickets in an initiative, with **Why**, **PMOS will**, **What changes** and **Based on**. The pencil picks another initiative first, ✓ does it (with Undo) and ✕ says not now.
@@ -255,6 +257,7 @@ Events is one page for everything with a date, from every source PMOS reads: you
255
257
  - Late shows the newest five dates first. One line under them, such as "16 more late, the oldest 350 days", opens the rest.
256
258
  - **Today** is a timeline: the dates with no time first, then each one by its time, with a red **now** line between the past and the next ones. Past ones are dashed. Each has one press to the act itself: read the draft of a report, mark a task done, or open the work a meeting is about. A report shows by its name and the day in words ("IDPF sprint biweekly update · 28 Oct"). Report drafts more than 14 days old are one row, "9 old report drafts", where PMOS suggests **Drop them** with ✓ and ✕. ✓ takes them off Events, with **Undo**, and the drafts stay in the Library.
257
259
  - **Coming up** holds the next 30 days (meetings: the next 7). A day with three meetings or more is one line, such as "Fri 20 Nov · 5 meetings". Press it to see them. Milestones, tasks, deadlines and reports on that day keep their own rows. Only a date at risk carries a suggestion, in a blue box under its row. A date that needs nothing shows nothing.
260
+ - **What to bring.** Each meeting today or in the next 7 days that is about one of your initiatives or products has a line under it, after ✦, that says what to bring, for example "Bring two calls: API ready is 8 days late; Beta out is due 20 Nov." PMOS writes it by itself from that work's or product's own dates on this page: the late ones, the ones at risk, and the ones due on or before the meeting's day, up to three. A meeting with none says "Nothing new for this one yet." Focus time and a meeting about no work or product have no line. The line has no buttons: open the date it names to act on it.
258
261
  - Every late or at-risk date has a suggestion. A late task of yours with no later day in any record gets "Move to today". A late Jira ticket gets "Set a new date in Jira", which ✓ adds to your tasks. A late deadline from a source gets "Ask Ang where it stands".
259
262
  - The delivery milestones after that are one line at the bottom of Coming up, for example "Delivery milestones later 6, until 20 Feb". Press it to see them.
260
263
  - A milestone is a diamond. A task is a round dot, a report a small square, and a deadline a purple dot. A meeting is a ring, and focus time is a green ring. Orange is late, amber is at risk.
@@ -173,6 +173,7 @@ An "off" switch accepts `off`, `0`, `false` or `no` unless the row says a differ
173
173
  | `PMOS_CORRECTION_MEMORY` | `off` stops your ✕ reasons from becoming memory. By default a reason of 12 characters or more is remembered as one unconfirmed entry for 30 days, at most 6 at once. | on | — |
174
174
  | `PMOS_CORRECTION_RULES` | `off` stops PMOS from recording each ✕ reason with a kind and offering a kind that repeats 3 times in 30 days as a standing rule in the Lab. | on | — |
175
175
  | `PMOS_FACTORY_LESSONS` | `off` stops factory lessons. By default each factory setback (a failed check, a revert or rollback, a pull request the guardrail sent to a person, your Undo of one, a reviewer FAIL) becomes one Lessons line on its initiative and one line in the Builder's notebook. The Builder prompt carries the last 5. The same setback 3 times in 14 days files one proposal, "Change the factory harness", for your ✓. | on | — |
176
+ | `PMOS_INITIATIVE_COST` | `off` stops the pause proposal of the factory's cost. By default, when the factory has spent on an initiative for 7 days with no merge, PMOS files one ✦ to pause its new jobs, for your ✓. Work › Cost and `pmos cost` still show the cost. | on | — |
176
177
  | `PMOS_CLAUDE_HOME` | The one folder where PMOS looks for PMOS transcripts. | the PMOS config folders | — |
177
178
  | `PMOS_HEADLESS_TIMEOUT_MS` | The longest time a background run may take. | 20 minutes | — |
178
179
 
@@ -134,7 +134,9 @@ function itemsOf(root) {
134
134
  }
135
135
  const itemOf = (root, item) => itemsOf(root).find((x) => x.item_id === item) || null;
136
136
  // factory-fleet-scale: an item whose dependencies are not integrated yet is not offered (lib/factory-fleet.js waitingOn)
137
- const next = (root, ini) => { const all = itemsOf(root); return all.filter((x) => x.state === 'declared' && (!ini || x.initiative_id === ini) && !require('./factory-fleet.js').waitingOn(x, all).length); };
137
+ // initiative-cost (A17): a paused initiative's declared items are not offered; an item already claimed is not touched, so running work finishes
138
+ const pausedOf = (root) => { try { return require('./initiative-cost.js').pausedOf(require('./driver.js').stateDirOf(root, { create: false })); } catch { return new Set(); } };
139
+ const next = (root, ini) => { const all = itemsOf(root), off = pausedOf(root); return all.filter((x) => x.state === 'declared' && (!ini || x.initiative_id === ini) && !off.has(x.initiative_id) && !require('./factory-fleet.js').waitingOn(x, all).length); };
138
140
 
139
141
  function claim(root, item, { agent = 'pmos:builder' } = {}) {
140
142
  if (!ITEM_RE.test(String(item || ''))) return { ok: false, error: 'name a work item, <initiative>.<n>' };
@@ -143,6 +145,7 @@ function claim(root, item, { agent = 'pmos:builder' } = {}) {
143
145
  const it = all.find((x) => x.item_id === item) || null;
144
146
  if (!it) return { ok: false, error: `${item} is not a declared work item` };
145
147
  if (it.state !== 'declared') return { ok: false, error: `${item} is ${it.state}, not waiting for a Builder` };
148
+ if (pausedOf(root).has(it.initiative_id)) return { ok: false, error: `${it.initiative_id} is paused, so the factory takes no new job of it. pmos cost resume ${it.initiative_id} starts its jobs again` };
146
149
  const FL = require('./factory-fleet.js');
147
150
  const wait = FL.waitingOn(it, all);
148
151
  if (wait.length) return { ok: false, error: `${item} waits for ${wait.join(', ')}. It can be claimed once ${wait.length === 1 ? 'that item is' : 'those items are'} integrated` };
@@ -0,0 +1,281 @@
1
+ 'use strict';
2
+ /* copy-tests.js — copy and layout tests on an initiative, drafted from plain words (initiative copy-tests, job #1905, idea A351;
3
+ * board BatchDesignDS panel 20). `pmos experiment …`.
4
+ *
5
+ * The PM asks in plain words ("try the price on the button", or `"Pay now" or "Pay $42.00"`) and PMOS drafts a test of two variants on the
6
+ * initiative, behind the product's rollout flag. Nothing runs until the PM starts it. The result is one table and one ✦ line with how sure
7
+ * PMOS is; Keep records the winner with Undo. A test under 80 % sure says "Not sure yet" and cannot be kept.
8
+ *
9
+ * The store is one append-only ledger per product: planning/copy-tests.jsonl (a kit: pmos/planning/copy-tests.jsonl). The workspace and
10
+ * the CLI read and write the same file. Lines:
11
+ * { at, op: 'draft', id, initiative, ask, kind: 'copy'|'layout', metric, flag, variants: [{ v, text }] }
12
+ * { at, op: 'flag', id, flag } the rollout flag, named later
13
+ * { at, op: 'start', id } the PM's press: never written by a draft
14
+ * { at, op: 'result', id, v, people, converted } the counts of one variant; the last line per variant wins
15
+ * { at, op: 'keep', id, v, sure } the PM keeps the winner; refused under KEEP_MIN
16
+ * { at, op: 'undo', id } takes back the test's last line (a keep, a result, a start, a flag or the draft)
17
+ *
18
+ * draftOf(ask, o) PURE → { kind, variants } the plain words to A and B
19
+ * resultOf(variants) PURE → { leader, other, lead (points), sure (0..1) } | null one-sided two-proportion z test
20
+ * foldOf(lines) PURE → [test] every test's state, oldest first
21
+ * lineOf(test) PURE → the ✦ line
22
+ * read(root) · forInitiative(root, id) · act(root, op, args) the ledger
23
+ * CLI: pmos experiment draft|list|show|flag|start|result|keep|undo|count
24
+ * No model call, no network, no git. Every log line carries [copy-tests]; a draft and a keep record use-log controls copyTestDraft and
25
+ * copyTestKeep. The copy says PMOS, never Claude. */
26
+ const fs = require('fs');
27
+ const path = require('path');
28
+
29
+ const TAG = '[copy-tests]';
30
+ const KEEP_MIN = 0.8;
31
+ const one = (s, n = 200) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
32
+ const pct = (x) => (Math.round(x * 1000) / 10).toFixed(1).replace(/\.0$/, '') + ' %';
33
+ const pts = (x) => { const p = Math.round(x * 1000) / 10; return (Number.isInteger(p) ? p.toFixed(0) : p.toFixed(1)) + (p === 1 ? ' point' : ' points'); };
34
+ const fmtN = (n) => String(Math.round(n)).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
35
+ const num = (s) => { const n = Number(String(s == null ? '' : s).replace(/[,_\s]/g, '')); return Number.isFinite(n) ? n : NaN; };
36
+
37
+ /* ── the plain words ── */
38
+ /** PURE. Two quoted texts are A and B; one is B against "As it is now"; none: B is the ask itself. */
39
+ function draftOf(ask, o = {}) {
40
+ const a = one(ask, 300);
41
+ const q = [...a.matchAll(/["“”]([^"“”]{1,120})["“”]/g)].map((m) => one(m[1], 120)).filter(Boolean);
42
+ const kind = /\blayouts?\b|\bscreen\b|\bplacement\b|\border\b/i.test(a) ? 'layout' : 'copy';
43
+ let A = o.a ? one(o.a, 120) : '', B = o.b ? one(o.b, 120) : '';
44
+ if (!A && !B) {
45
+ if (q.length >= 2) { A = q[0]; B = q[1]; }
46
+ else if (q.length === 1) { A = 'As it is now'; B = q[0]; }
47
+ else { A = 'As it is now'; B = one(a.replace(/^(please\s+)?(try|test)\s+/i, ''), 120); B = B ? B[0].toUpperCase() + B.slice(1) : ''; }
48
+ }
49
+ if (!A) A = 'As it is now';
50
+ return { kind, variants: B ? [{ v: 'A', text: A }, { v: 'B', text: B }] : [] };
51
+ }
52
+
53
+ /* ── how sure ── */
54
+ function phi(z) { // the standard normal CDF (Abramowitz and Stegun 7.1.26, error under 1.5e-7)
55
+ const t = 1 / (1 + 0.3275911 * Math.abs(z) / Math.SQRT2);
56
+ const e = 1 - (((((1.061405429 * t - 1.453152027) * t) + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-(z * z) / 2);
57
+ return z >= 0 ? (1 + e) / 2 : (1 - e) / 2;
58
+ }
59
+ /** PURE. variants [{ v, people, converted }] → the leader, its lead in points and how sure PMOS is that the leader is better (one side). */
60
+ function resultOf(variants) {
61
+ const vs = (variants || []).filter((x) => x && x.people > 0 && x.converted >= 0 && x.converted <= x.people);
62
+ if (vs.length < 2) return null;
63
+ const [p, q] = vs.slice(0, 2).map((x) => ({ ...x, rate: x.converted / x.people }));
64
+ const lead = Math.abs(p.rate - q.rate);
65
+ const [hi, lo] = p.rate >= q.rate ? [p, q] : [q, p];
66
+ const se = Math.sqrt((p.rate * (1 - p.rate)) / p.people + (q.rate * (1 - q.rate)) / q.people);
67
+ const sure = lead === 0 ? 0.5 : se > 0 ? phi(lead / se) : 1;
68
+ return { leader: lead === 0 ? null : hi.v, other: lead === 0 ? null : lo.v, lead, sure };
69
+ }
70
+
71
+ /* ── the ledger ── */
72
+ function fileOf(root) {
73
+ const kit = fs.existsSync(path.join(root, 'pmos', 'state'));
74
+ return path.join(root, ...(kit ? ['pmos', 'planning'] : ['planning']), 'copy-tests.jsonl');
75
+ }
76
+ function readLines(root) {
77
+ let t = ''; try { t = fs.readFileSync(fileOf(root), 'utf8'); } catch { return []; }
78
+ const out = [];
79
+ for (const s of t.split('\n')) { if (!s.trim()) continue; try { const x = JSON.parse(s); if (x && x.op && x.id) out.push(x); } catch { /* a torn line is skipped */ } }
80
+ return out;
81
+ }
82
+ function append(root, line) {
83
+ const f = fileOf(root);
84
+ fs.mkdirSync(path.dirname(f), { recursive: true });
85
+ fs.appendFileSync(f, JSON.stringify(line) + '\n');
86
+ }
87
+
88
+ /** PURE. The ledger lines → every test's state. An undo takes back the test's last line that is still standing. */
89
+ function foldOf(lines) {
90
+ const by = new Map();
91
+ for (const x of lines || []) {
92
+ if (!x || !x.id) continue;
93
+ if (!by.has(x.id)) by.set(x.id, []);
94
+ const L = by.get(x.id);
95
+ if (x.op === 'undo') { L.pop(); continue; }
96
+ L.push(x);
97
+ }
98
+ const out = [];
99
+ for (const [id, L] of by) {
100
+ const d = L.find((x) => x.op === 'draft');
101
+ if (!d) continue;
102
+ const t = { id, initiative: d.initiative, ask: d.ask || '', kind: d.kind || 'copy', metric: d.metric || 'Converted', flag: d.flag || '', at: d.at,
103
+ variants: (d.variants || []).map((v) => ({ v: v.v, text: v.text, people: 0, converted: 0, rate: null })), status: 'draft', kept: null };
104
+ for (const x of L) {
105
+ if (x.op === 'flag') t.flag = one(x.flag, 80);
106
+ else if (x.op === 'start') t.status = 'running';
107
+ else if (x.op === 'result') { const v = t.variants.find((y) => y.v === x.v); if (v) { v.people = x.people; v.converted = x.converted; v.rate = x.people > 0 ? x.converted / x.people : null; } }
108
+ else if (x.op === 'keep') { t.status = 'kept'; t.kept = x.v; }
109
+ }
110
+ t.result = resultOf(t.variants);
111
+ t.canKeep = t.status === 'running' && !!(t.result && t.result.leader && t.result.sure >= KEEP_MIN);
112
+ t.line = lineOf(t);
113
+ out.push(t);
114
+ }
115
+ return out;
116
+ }
117
+ /** PURE. The one ✦ line of a test. */
118
+ function lineOf(t) {
119
+ if (t.status === 'kept') return `Kept ${t.kept}. ${t.flag ? `Set ${t.flag} to ${t.kept} for everyone.` : `Roll ${t.kept} out to everyone.`}`;
120
+ if (t.status === 'draft') return t.flag ? 'Drafted. Starting it waits for you.' : 'Drafted. Name the rollout flag before it starts.';
121
+ const r = t.result;
122
+ if (!r) return `Running behind ${t.flag}. No results yet.`;
123
+ const sure = Math.round(r.sure * 100);
124
+ if (!r.leader) return 'Not sure yet: A and B are level. Let it run.';
125
+ if (r.sure < KEEP_MIN) return `Not sure yet: ${r.leader} leads by ${pts(r.lead)} (${sure} % sure). Let it run.`;
126
+ return `${r.leader} wins by ${pts(r.lead)} (${sure} % sure). Keep ${r.leader} for everyone?`;
127
+ }
128
+
129
+ const read = (root) => foldOf(readLines(root));
130
+ const forInitiative = (root, id) => read(root).filter((t) => t.initiative === id);
131
+ const find = (root, id) => read(root).find((t) => t.id === id) || null;
132
+ function nextId(root) {
133
+ let n = 0;
134
+ for (const x of readLines(root)) { const m = /^ct(\d+)$/.exec(x.id); if (m) n = Math.max(n, +m[1]); }
135
+ return 'ct' + (n + 1);
136
+ }
137
+ function flagOfRecord(root, ini) {
138
+ try { const I = require('./item-why.js'), f = I.recordPathOf(root, ini); return f ? one(I.frontOf(fs.readFileSync(f, 'utf8')).rollout_flag, 80) : ''; } catch { return ''; }
139
+ }
140
+
141
+ /** The offer on the work popup (LINE Rule 12): an initiative whose record names its rollout_flag and has no test yet → { initiative, flag }.
142
+ * No flag, or a test already: null (zero is silence). */
143
+ function offerOf(root, ini) {
144
+ const id = one(ini, 120);
145
+ if (!id || forInitiative(root, id).length) return null;
146
+ const flag = flagOfRecord(root, id);
147
+ return flag ? { initiative: id, flag } : null;
148
+ }
149
+
150
+ /** The ledger's writes. op: draft | flag | start | result | keep | undo. → { ok, test, said } | { ok: false, error } */
151
+ function act(root, op, a = {}, now = Date.now()) {
152
+ const at = new Date(now).toISOString();
153
+ if (op === 'draft') {
154
+ const ini = one(a.initiative, 120);
155
+ if (!ini) return { ok: false, error: 'Name the initiative the test belongs to.' };
156
+ const D = draftOf(a.ask, a);
157
+ if (D.variants.length < 2) return { ok: false, error: 'Say what to try, for example: "Pay now" or "Pay $42.00".' };
158
+ const id = nextId(root), flag = one(a.flag, 80) || flagOfRecord(root, ini);
159
+ append(root, { at, op: 'draft', id, initiative: ini, ask: one(a.ask, 300), kind: D.kind, metric: one(a.metric, 40) || 'Converted', flag, variants: D.variants });
160
+ console.log(`${TAG} drafted ${id} initiative=${ini} kind=${D.kind} flag=${flag || '-'}`);
161
+ const t = find(root, id);
162
+ return { ok: true, test: t, said: `Drafted ${id}: A "${D.variants[0].text}", B "${D.variants[1].text}". ${t.line}` };
163
+ }
164
+ const t = find(root, one(a.id, 40));
165
+ if (!t) return { ok: false, error: `There is no copy test ${one(a.id, 40) || '(no id)'}.` };
166
+ if (op === 'flag') {
167
+ const flag = one(a.flag, 80);
168
+ if (!flag) return { ok: false, error: 'Name the flag.' };
169
+ if (t.status !== 'draft') return { ok: false, error: `${t.id} has started; its flag stays ${t.flag}.` };
170
+ append(root, { at, op: 'flag', id: t.id, flag });
171
+ return { ok: true, test: find(root, t.id), said: `${t.id} runs behind ${flag}.` };
172
+ }
173
+ if (op === 'start') {
174
+ if (t.status !== 'draft') return { ok: false, error: `${t.id} has already started.` };
175
+ if (!t.flag) return { ok: false, error: `${t.id} has no rollout flag yet. Name it first: pmos experiment flag ${t.id} <flag>.` };
176
+ append(root, { at, op: 'start', id: t.id });
177
+ console.log(`${TAG} started ${t.id} flag=${t.flag}`);
178
+ return { ok: true, test: find(root, t.id), said: `${t.id} started behind ${t.flag}.` };
179
+ }
180
+ if (op === 'result') {
181
+ if (t.status !== 'running') return { ok: false, error: t.status === 'draft' ? `${t.id} has not started. Start it first.` : `${t.id} is kept; it takes no more results.` };
182
+ const v = one(a.v, 4).toUpperCase(), people = num(a.people), converted = num(a.converted);
183
+ if (!t.variants.some((x) => x.v === v)) return { ok: false, error: `${t.id} has variants ${t.variants.map((x) => x.v).join(' and ')}.` };
184
+ if (!(people > 0) || !(converted >= 0) || converted > people || !Number.isInteger(people) || !Number.isInteger(converted)) return { ok: false, error: 'Give whole numbers: the people who saw it, and how many of them converted (no more than the people).' };
185
+ append(root, { at, op: 'result', id: t.id, v, people, converted });
186
+ const u = find(root, t.id);
187
+ return { ok: true, test: u, said: `${t.id} ${v}: ${fmtN(converted)} of ${fmtN(people)}. ${u.line}` };
188
+ }
189
+ if (op === 'keep') {
190
+ if (!t.canKeep) return { ok: false, error: t.status === 'kept' ? `${t.id} already kept ${t.kept}.` : `Not sure yet: ${t.id} is under ${Math.round(KEEP_MIN * 100)} % sure, so it cannot be kept.` };
191
+ append(root, { at, op: 'keep', id: t.id, v: t.result.leader, sure: Math.round(t.result.sure * 1000) / 1000 });
192
+ console.log(`${TAG} kept ${t.id} v=${t.result.leader}`);
193
+ const u = find(root, t.id);
194
+ return { ok: true, test: u, said: u.line };
195
+ }
196
+ if (op === 'undo') {
197
+ append(root, { at, op: 'undo', id: t.id });
198
+ const u = find(root, t.id);
199
+ return { ok: true, test: u, said: u ? `Undone. ${u.line}` : `Undone: ${t.id} is no longer drafted.` };
200
+ }
201
+ return { ok: false, error: `${op} is not a copy test action.` };
202
+ }
203
+ function count(root, { days = 7, now = Date.now() } = {}) {
204
+ const from = new Date(now - days * 864e5).toISOString();
205
+ return readLines(root).filter((x) => x.op === 'draft' && String(x.at) >= from).length;
206
+ }
207
+
208
+ /* ── pmos experiment ── */
209
+ const COMMANDS = { experiment: ['draft', 'list', 'show', 'flag', 'start', 'result', 'keep', 'undo', 'count'] };
210
+ const USAGE = [
211
+ 'usage: pmos experiment <command> — copy and layout tests on an initiative, drafted from plain words',
212
+ ' pmos experiment draft <initiative> "<ask>" [--flag <f>] [--metric <m>] [--a <text>] [--b <text>] draft a test (it does not start)',
213
+ ' pmos experiment list [<initiative>] the tests and their ✦ lines',
214
+ ' pmos experiment show <id> one test as a table',
215
+ ' pmos experiment flag <id> <flag> name the rollout flag of a draft',
216
+ ' pmos experiment start <id> start it behind its flag (your press; a draft never starts by itself)',
217
+ ' pmos experiment result <id> <A|B> --people <n> --converted <n> record one variant\'s counts',
218
+ ' pmos experiment keep <id> keep the winner (refused under 80 % sure)',
219
+ ' pmos experiment undo <id> take back the test\'s last step',
220
+ ' pmos experiment count [--days 7] tests drafted in the last days; the number is the last line',
221
+ 'PMOS calls no model and changes no flag service: Keep names the flag change for you to make.',
222
+ ];
223
+ function repoOf(cwd) {
224
+ let d = path.resolve(cwd);
225
+ for (;;) { try { if (fs.existsSync(path.join(d, '.git'))) return d; } catch { /* look further up */ } const up = path.dirname(d); if (up === d) return path.resolve(cwd); d = up; }
226
+ }
227
+ function used(o, control, now) {
228
+ try { const dir = o.stateDir || require('./state-root.js').defaultRoot({ env: o.env || process.env }); require('./use-log.js').record(dir, [{ kind: 'use', page: 'work', control, device: 'desk' }], now); } catch { /* a count, never a reason to fail */ }
229
+ }
230
+ function tableOf(t) {
231
+ const rows = [`| Variant | ${t.kind === 'layout' ? 'Layout' : 'Copy'} | ${t.metric} | Sure |`, '|---|---|---|---|'];
232
+ const r = t.result, sure = r && r.leader ? Math.round(r.sure * 100) + ' %' : '';
233
+ for (const v of t.variants) rows.push(`| ${v.v} | ${v.text} | ${v.rate == null ? '' : pct(v.rate) + ` (${fmtN(v.converted)} of ${fmtN(v.people)})`} | ${r && r.leader === v.v ? sure : ''} |`);
234
+ return rows;
235
+ }
236
+ function run(argv, o = {}) {
237
+ const say = o.say || ((s) => console.log(s)), now = o.now || Date.now();
238
+ const args = argv[0] === 'experiment' ? argv.slice(1) : argv.slice();
239
+ const pos = [], fl = {};
240
+ for (let i = 0; i < args.length; i++) { const a = args[i]; if (/^--(root|days|flag|metric|a|b|people|converted)$/.test(a)) fl[a.slice(2)] = args[++i]; else if (a === '--json') fl.json = true; else pos.push(a); }
241
+ const cmd = pos[0] || 'list';
242
+ if (cmd === 'help' || cmd === '--help') { USAGE.forEach((l) => say(l)); return 0; }
243
+ const root = path.resolve(fl.root || o.root || repoOf(o.cwd || process.cwd()));
244
+ const out = (r) => {
245
+ if (fl.json) { say(JSON.stringify(r)); return r.ok ? 0 : 1; }
246
+ if (!r.ok) { say('✗ ' + r.error); return 1; }
247
+ say('✓ ' + r.said); return 0;
248
+ };
249
+ if (cmd === 'count') {
250
+ const days = Math.max(1, Math.min(365, parseInt(fl.days, 10) || 7)), n = count(root, { days, now });
251
+ say(`${TAG} ${n} ${n === 1 ? 'copy test' : 'copy tests'} drafted in the last ${days} days.`); say(String(n)); return 0;
252
+ }
253
+ if (cmd === 'list') {
254
+ const T = pos[1] ? forInitiative(root, pos[1]) : read(root);
255
+ if (fl.json) { say(JSON.stringify({ ok: true, tests: T })); return 0; }
256
+ if (!T.length) { say('No copy test yet. pmos experiment draft <initiative> "<what to try>" drafts one.'); return 0; }
257
+ for (const t of T) say(`- ${t.id} (${t.initiative}): ${t.line}`);
258
+ return 0;
259
+ }
260
+ if (cmd === 'show') {
261
+ const t = find(root, pos[1] || '');
262
+ if (fl.json) { say(JSON.stringify(t ? { ok: true, test: t } : { ok: false, error: 'not found' })); return t ? 0 : 1; }
263
+ if (!t) { say(`✗ There is no copy test ${pos[1] || '(no id)'}.`); return 1; }
264
+ say(`${t.id} on ${t.initiative}${t.flag ? ', behind ' + t.flag : ''}: ${t.ask}`);
265
+ tableOf(t).forEach((l) => say(l));
266
+ say('✦ ' + t.line);
267
+ return 0;
268
+ }
269
+ if (cmd === 'draft') {
270
+ const r = act(root, 'draft', { initiative: pos[1], ask: pos.slice(2).join(' '), flag: fl.flag, metric: fl.metric, a: fl.a, b: fl.b }, now);
271
+ if (r.ok) used(o, 'copyTestDraft', now);
272
+ return out(r);
273
+ }
274
+ if (cmd === 'flag') return out(act(root, 'flag', { id: pos[1], flag: pos[2] || fl.flag }, now));
275
+ if (cmd === 'start' || cmd === 'undo') return out(act(root, cmd, { id: pos[1] }, now));
276
+ if (cmd === 'result') return out(act(root, 'result', { id: pos[1], v: pos[2], people: fl.people, converted: fl.converted }, now));
277
+ if (cmd === 'keep') { const r = act(root, 'keep', { id: pos[1] }, now); if (r.ok) used(o, 'copyTestKeep', now); return out(r); }
278
+ say(`✗ ${cmd} is not a command of pmos experiment`); USAGE.forEach((l) => say(l)); return 2;
279
+ }
280
+
281
+ module.exports = { offerOf, COMMANDS, TAG, KEEP_MIN, draftOf, resultOf, foldOf, lineOf, read, forInitiative, find, act, count, fileOf, run, USAGE };