create-pmos 0.697.0 → 0.699.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 (118) hide show
  1. package/package.json +20 -20
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/design-system/ui/tokens.css +1 -1
  4. package/payload/planning/evals/eval-calibration.md +1 -1
  5. package/payload/planning/okrs/health-budgets.md +1 -1
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/changelog.json +19 -0
  8. package/workspace/design-system/ui/tokens.css +1 -1
  9. package/workspace/design-token-reach.js +64 -6
  10. package/workspace/guide/cli.md +8 -0
  11. package/workspace/guide/layout.md +9 -0
  12. package/workspace/lib/design-cli.js +14 -2
  13. package/workspace/lib/design-drift.js +2 -0
  14. package/workspace/lib/design-swap.js +146 -0
  15. package/workspace/lib/design-system.js +7 -4
  16. package/workspace/lib/route-modules.js +1 -0
  17. package/workspace/lib/routes-draft-keep.js +65 -0
  18. package/workspace/package-lock.json +2 -2
  19. package/workspace/package.json +1 -1
  20. package/workspace/public/pm/agenda-live.css +7 -7
  21. package/workspace/public/pm/bd-backlog.css +71 -71
  22. package/workspace/public/pm/bd-pin-card.css +2 -2
  23. package/workspace/public/pm/bd-pop-ds.css +1 -1
  24. package/workspace/public/pm/bd-publish.css +23 -23
  25. package/workspace/public/pm/bd-shared.css +22 -22
  26. package/workspace/public/pm/bd-work-ds.css +1 -1
  27. package/workspace/public/pm/bd-work.css +25 -25
  28. package/workspace/public/pm/c3-capture.css +3 -3
  29. package/workspace/public/pm/c3-initiatives.css +21 -21
  30. package/workspace/public/pm/components.css +585 -585
  31. package/workspace/public/pm/console3.css +304 -304
  32. package/workspace/public/pm/cozy-adler.css +6 -6
  33. package/workspace/public/pm/cozy-board.css +267 -267
  34. package/workspace/public/pm/cozy-buddy.css +1 -1
  35. package/workspace/public/pm/cozy-day-pick.css +7 -7
  36. package/workspace/public/pm/cozy-divider.css +2 -2
  37. package/workspace/public/pm/cozy-draft-keep.js +74 -0
  38. package/workspace/public/pm/cozy-ev.css +121 -121
  39. package/workspace/public/pm/cozy-events.css +22 -22
  40. package/workspace/public/pm/cozy-goals.css +3 -3
  41. package/workspace/public/pm/cozy-home-rows.css +50 -50
  42. package/workspace/public/pm/cozy-home.css +218 -218
  43. package/workspace/public/pm/cozy-insights.css +197 -197
  44. package/workspace/public/pm/cozy-lab.css +18 -18
  45. package/workspace/public/pm/cozy-library.css +1 -1
  46. package/workspace/public/pm/cozy-live-pill.css +4 -4
  47. package/workspace/public/pm/cozy-mtg-present.css +32 -32
  48. package/workspace/public/pm/cozy-nav.js +1 -0
  49. package/workspace/public/pm/cozy-onboard.css +22 -22
  50. package/workspace/public/pm/cozy-panel.css +24 -24
  51. package/workspace/public/pm/cozy-panels.css +4 -4
  52. package/workspace/public/pm/cozy-phone-rec.css +12 -12
  53. package/workspace/public/pm/cozy-phone-settings.css +4 -4
  54. package/workspace/public/pm/cozy-pick.css +7 -7
  55. package/workspace/public/pm/cozy-pop-work.css +56 -56
  56. package/workspace/public/pm/cozy-popup.css +25 -25
  57. package/workspace/public/pm/cozy-proto.css +44 -44
  58. package/workspace/public/pm/cozy-rec-now.css +23 -23
  59. package/workspace/public/pm/cozy-rec-present.css +18 -18
  60. package/workspace/public/pm/cozy-rec-tab.css +8 -8
  61. package/workspace/public/pm/cozy-reveal.css +14 -14
  62. package/workspace/public/pm/cozy-routine.css +29 -29
  63. package/workspace/public/pm/cozy-steps.css +10 -10
  64. package/workspace/public/pm/cozy-task-pop.css +8 -8
  65. package/workspace/public/pm/cozy-today-page.css +28 -28
  66. package/workspace/public/pm/cozy-today.css +165 -165
  67. package/workspace/public/pm/cozy-viewer.css +21 -21
  68. package/workspace/public/pm/cozy-vw-mtg.css +105 -105
  69. package/workspace/public/pm/cozy-vw-rp.css +66 -66
  70. package/workspace/public/pm/cozy-vw-shell.css +42 -42
  71. package/workspace/public/pm/cozy-vw.css +90 -90
  72. package/workspace/public/pm/cozy-xv.css +8 -8
  73. package/workspace/public/pm/cozy.css +24 -24
  74. package/workspace/public/pm/dash-view.css +23 -23
  75. package/workspace/public/pm/draft-keep.js +151 -0
  76. package/workspace/public/pm/hi-pop.css +29 -29
  77. package/workspace/public/pm/home-chat.js +1 -1
  78. package/workspace/public/pm/home-impact.css +10 -10
  79. package/workspace/public/pm/home-ini.css +34 -34
  80. package/workspace/public/pm/home-line.css +12 -12
  81. package/workspace/public/pm/impact.css +12 -12
  82. package/workspace/public/pm/ini-view.css +240 -240
  83. package/workspace/public/pm/intent.css +11 -11
  84. package/workspace/public/pm/komorebi.css +3 -3
  85. package/workspace/public/pm/load-shapes.css +10 -10
  86. package/workspace/public/pm/loose-props.css +17 -17
  87. package/workspace/public/pm/metric-drafts.css +10 -10
  88. package/workspace/public/pm/ms-suggest.css +12 -12
  89. package/workspace/public/pm/ov-view.css +10 -10
  90. package/workspace/public/pm/page-chat.css +1 -1
  91. package/workspace/public/pm/premium-vw-backlog.css +7 -7
  92. package/workspace/public/pm/premium-vw-cal.css +22 -22
  93. package/workspace/public/pm/premium-vw-copy.css +6 -6
  94. package/workspace/public/pm/premium-vw-doc.css +98 -98
  95. package/workspace/public/pm/premium-vw-guide.css +9 -9
  96. package/workspace/public/pm/premium-vw-item.css +7 -7
  97. package/workspace/public/pm/premium-vw-jira.css +28 -28
  98. package/workspace/public/pm/premium-vw-meet.css +26 -26
  99. package/workspace/public/pm/premium-vw-notepad.css +14 -14
  100. package/workspace/public/pm/premium-vw-notes.css +11 -11
  101. package/workspace/public/pm/premium-vw-page.js +1 -0
  102. package/workspace/public/pm/premium-vw-rec.css +22 -22
  103. package/workspace/public/pm/premium-vw-report.css +14 -14
  104. package/workspace/public/pm/premium-vw-slides.css +27 -27
  105. package/workspace/public/pm/premium.css +598 -598
  106. package/workspace/public/pm/prog-order.css +7 -7
  107. package/workspace/public/pm/prog-page.css +16 -16
  108. package/workspace/public/pm/program-charter.css +23 -23
  109. package/workspace/public/pm/ready-lib.css +4 -4
  110. package/workspace/public/pm/sort-order.css +3 -3
  111. package/workspace/public/pm/split-merge.css +21 -21
  112. package/workspace/public/pm/story.css +3 -3
  113. package/workspace/public/pm/task-card.css +21 -21
  114. package/workspace/public/pm/tk-tasks.css +32 -32
  115. package/workspace/public/pm/tk-view.css +7 -7
  116. package/workspace/public/pm/wf-page.css +46 -46
  117. package/workspace/test-lists/design-token-swap.json +9 -0
  118. package/workspace/test-lists/forms-keep-drafts.json +9 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.697.0",
3
+ "version": "0.699.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,25 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.699.0",
38
+ "at": "2026-11-22T10:23:23.766Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1517,
43
+ "t": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
44
+ "s": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
45
+ "k": "x"
46
+ },
47
+ {
48
+ "n": 1518,
49
+ "t": "Forms keep drafts when panels close",
50
+ "s": "Forms keep drafts when panels close",
51
+ "k": "new"
52
+ }
53
+ ]
54
+ },
36
55
  {
37
56
  "v": "0.697.0",
38
57
  "at": "2026-11-22T09:56:23.025Z",
@@ -417,25 +436,6 @@
417
436
  "k": "new"
418
437
  }
419
438
  ]
420
- },
421
- {
422
- "v": "0.654.0",
423
- "at": "2026-11-22T01:23:23.116Z",
424
- "f": 4,
425
- "prs": [
426
- {
427
- "n": 1436,
428
- "t": "The Initiatives | Backlog switch is a tablist with its label again",
429
- "s": "The Initiatives | Backlog switch is a tablist with its label again",
430
- "k": "fix"
431
- },
432
- {
433
- "n": 1437,
434
- "t": "Publish to beta first; promote to GA only on evidence",
435
- "s": "Publish to beta first; promote to GA only on evidence",
436
- "k": "x"
437
- }
438
- ]
439
439
  }
440
440
  ]
441
441
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@1add3b6d
1
+ kernel-source: pmos@dc606942
2
2
  assembled: 2026-11-22
3
3
  mode: vendor
@@ -1,7 +1,7 @@
1
1
  /* PMOS Komorebi tokens. GENERATED from tokens.json by lib/design-system.js: do not edit; run `node lib/design-system.js --write`. */
2
2
  :root, [data-theme="light"] {--raise:0 1px 2px rgba(42,46,53,.08), 0 4px 14px -6px rgba(70,80,50,.14);--lift:0 10px 28px -10px rgba(42,46,53,.28);--glow:0 0 0 2px #5F7A45, 0 0 0 5px rgba(95,122,69,.10)}
3
3
  [data-theme="dark"] {--raise:0 1px 2px rgba(0,0,0,.4), 0 4px 14px -6px rgba(169,196,140,.08);--lift:0 10px 28px -10px rgba(0,0,0,.6);--glow:0 0 0 2px #A9C48C, 0 0 0 5px rgba(169,196,140,.12)}
4
- :root {--space-4:4px;--space-8:8px;--space-12:12px;--space-16:16px;--space-24:24px;--space-32:32px;--space-48:48px;--space-64:64px;--radius-sm:6px;--radius-md:10px;--radius-card:16px;--radius-panel:24px;--radius-pill:999px}
4
+ :root:where(*) {--space-4:4px;--space-8:8px;--space-12:12px;--space-16:16px;--space-24:24px;--space-32:32px;--space-48:48px;--space-64:64px;--radius-sm:6px;--radius-md:10px;--radius-card:16px;--radius-panel:24px;--radius-pill:999px}
5
5
  :root:where(*) {--type-title:26px;--leading-title:32px;--weight-title:600;--type-heading:18px;--leading-heading:24px;--weight-heading:600;--type-body:15px;--leading-body:24px;--weight-body:400;--type-small:13px;--leading-small:20px;--weight-small:400;--type-code:13px;--leading-code:20px;--weight-code:400}
6
6
  .title{font-family:var(--font-sans);font-size:var(--type-title);line-height:var(--leading-title);font-weight:var(--weight-title)}
7
7
  .heading{font-family:var(--font-sans);font-size:var(--type-heading);line-height:var(--leading-heading);font-weight:var(--weight-heading)}
@@ -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-22T09:56:19Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T10:23:20Z"}
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-22T09:56:19Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T10:23:20Z"}
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-22T09:56:19Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T10:23:20Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,23 @@
1
1
  [
2
+ {
3
+ "v": "0.699.0",
4
+ "at": "2026-11-22T10:23:23.766Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1517,
9
+ "t": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
10
+ "s": "Fixed spacing and corner values read the same-value Komorebi token (token-first step 2)",
11
+ "k": "x"
12
+ },
13
+ {
14
+ "n": 1518,
15
+ "t": "Forms keep drafts when panels close",
16
+ "s": "Forms keep drafts when panels close",
17
+ "k": "new"
18
+ }
19
+ ]
20
+ },
2
21
  {
3
22
  "v": "0.697.0",
4
23
  "at": "2026-11-22T09:56:23.025Z",
@@ -1,7 +1,7 @@
1
1
  /* PMOS Komorebi tokens. GENERATED from tokens.json by lib/design-system.js: do not edit; run `node lib/design-system.js --write`. */
2
2
  :root, [data-theme="light"] {--raise:0 1px 2px rgba(42,46,53,.08), 0 4px 14px -6px rgba(70,80,50,.14);--lift:0 10px 28px -10px rgba(42,46,53,.28);--glow:0 0 0 2px #5F7A45, 0 0 0 5px rgba(95,122,69,.10)}
3
3
  [data-theme="dark"] {--raise:0 1px 2px rgba(0,0,0,.4), 0 4px 14px -6px rgba(169,196,140,.08);--lift:0 10px 28px -10px rgba(0,0,0,.6);--glow:0 0 0 2px #A9C48C, 0 0 0 5px rgba(169,196,140,.12)}
4
- :root {--space-4:4px;--space-8:8px;--space-12:12px;--space-16:16px;--space-24:24px;--space-32:32px;--space-48:48px;--space-64:64px;--radius-sm:6px;--radius-md:10px;--radius-card:16px;--radius-panel:24px;--radius-pill:999px}
4
+ :root:where(*) {--space-4:4px;--space-8:8px;--space-12:12px;--space-16:16px;--space-24:24px;--space-32:32px;--space-48:48px;--space-64:64px;--radius-sm:6px;--radius-md:10px;--radius-card:16px;--radius-panel:24px;--radius-pill:999px}
5
5
  :root:where(*) {--type-title:26px;--leading-title:32px;--weight-title:600;--type-heading:18px;--leading-heading:24px;--weight-heading:600;--type-body:15px;--leading-body:24px;--weight-body:400;--type-small:13px;--leading-small:20px;--weight-small:400;--type-code:13px;--leading-code:20px;--weight-code:400}
6
6
  .title{font-family:var(--font-sans);font-size:var(--type-title);line-height:var(--leading-title);font-weight:var(--weight-title)}
7
7
  .heading{font-family:var(--font-sans);font-size:var(--type-heading);line-height:var(--leading-heading);font-weight:var(--weight-heading)}
@@ -8,7 +8,10 @@
8
8
  * colour brand.css with the light --ink → a red must change every page whose body carries pm-ds (the colour tokens are scoped to it)
9
9
  * A page that did not change fails the run (exit 1). Each page prints one "[token-reach]" line, and the run prints the computed type roles
10
10
  * (--fs-body, --fs-meta, --fs-panel, --fs-display) of the unchanged page, which must still read 15, 13, 18 and 26 px.
11
- * OUT=<dir> where the before/after PNGs go (default: this run's state folder). PAGES=a.html,b.html only these pages. */
11
+ * Changes also checked: --type-small, --muted (light and dark) and, since step 2 (token-swap-same-value), --space-8 must reach every page.
12
+ * OUT=<dir> where the before/after PNGs go (default: this run's state folder). PAGES=a.html,b.html only these pages.
13
+ * --same the other check: every page with each stylesheet in public/pm as on BASE_REF (default origin/main) against the files on
14
+ * disk, light and dark. A change that swaps a fixed value for a same-value token must show no difference. */
12
15
  const fs = require('fs');
13
16
  const path = require('path');
14
17
  const { spawn } = require('child_process');
@@ -26,7 +29,15 @@ const CHANGES = [
26
29
  { key: 'type-small', sheet: 'komorebi.css', pairs: [['--type-small:13px', '--type-small:15px']], kind: 'type' },
27
30
  { key: 'ink', sheet: 'brand.css', pairs: [['--ink:#2A2E35', '--ink:#B03020'], ['--ink:#ECEEF1', '--ink:#FF8A80']], kind: 'colour' },
28
31
  { key: 'muted', sheet: 'brand.css', pairs: [['--muted:#646A74', '--muted:#B03020'], ['--muted:#9EA4AD', '--muted:#FF8A80']], kind: 'colour' },
32
+ { key: 'space-8', sheet: 'komorebi.css', pairs: [['--space-8:8px', '--space-8:14px']], kind: 'space' },
33
+ { key: 'space-4', sheet: 'komorebi.css', pairs: [['--space-4:4px', '--space-4:10px']], kind: 'space' },
34
+ { key: 'space-12', sheet: 'komorebi.css', pairs: [['--space-12:12px', '--space-12:20px']], kind: 'space' },
35
+ { key: 'radius-sm', sheet: 'komorebi.css', pairs: [['--radius-sm:6px', '--radius-sm:0px']], kind: 'corner' },
29
36
  ];
37
+ const KINDS = [...new Set(CHANGES.map((c) => c.kind))];
38
+ // the kinds a page must show to pass; spacing and corners are measured and printed (step 2 moved part of them onto tokens; the values
39
+ // between two tokens still bypass them, so a page can show neither yet)
40
+ const REQUIRED = new Set((process.env.REQUIRE || 'type,colour').split(','));
30
41
  // a page the server serves at another address
31
42
  const URLS = { 'capture.html': '/console.html?capture=1', 'premium-present.html': '/pm/present' };
32
43
  const log = (s) => console.log('[token-reach] ' + s);
@@ -38,13 +49,17 @@ const sample = () => {
38
49
  const r = el.getBoundingClientRect();
39
50
  if (!r.width || !r.height) continue;
40
51
  const s = getComputedStyle(el);
41
- out.push(s.fontSize + '|' + s.color);
52
+ out.push([s.fontSize, s.color, s.padding, s.margin, s.gap, s.borderRadius].join('|'));
42
53
  }
43
54
  const b = getComputedStyle(document.body);
44
55
  return { els: out, pmds: document.body.classList.contains('pm-ds'), roles: ['--fs-body', '--fs-meta', '--fs-panel', '--fs-display'].map((n) => b.getPropertyValue(n).trim()) };
45
56
  };
46
57
 
58
+ const SAME = process.argv.includes('--same');
59
+ const BASE_REF = process.env.BASE_REF || 'origin/main';
60
+
47
61
  (async () => {
62
+ if (SAME) return same();
48
63
  for (const c of CHANGES) for (const [from] of c.pairs) if (!read(path.join(PUB, 'pm', c.sheet)).includes(from)) { log(`${c.sheet} no longer holds "${from}": update CHANGES`); process.exit(2); }
49
64
  const { chromium } = require('playwright-core');
50
65
  const srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
@@ -62,7 +77,7 @@ const sample = () => {
62
77
  await ctx.close();
63
78
  return { ...s, png };
64
79
  };
65
- const misses = [];
80
+ const misses = [], unreached = [];
66
81
  const roleLines = [];
67
82
  for (const page of PAGES) {
68
83
  const base = await shoot(page, null);
@@ -70,7 +85,7 @@ const sample = () => {
70
85
  const steady = Buffer.compare(base.png, again.png) === 0;
71
86
  fs.writeFileSync(path.join(OUT, page.replace('.html', '') + '-before.png'), base.png);
72
87
  roleLines.push(`${page}: ${base.roles.join(' / ')}`);
73
- const parts = [], hit = { type: false, colour: false };
88
+ const parts = [], hit = Object.fromEntries(KINDS.map((k) => [k, false]));
74
89
  for (const c of CHANGES) {
75
90
  const after = await shoot(page, c);
76
91
  fs.writeFileSync(path.join(OUT, page.replace('.html', '') + '-' + c.key + '.png'), after.png);
@@ -80,14 +95,57 @@ const sample = () => {
80
95
  if (reached) hit[c.kind] = true;
81
96
  parts.push(`${c.key} ${reached ? 'yes' : 'no'} (${n})`);
82
97
  }
83
- for (const k of ['type', 'colour']) if (!hit[k]) misses.push(`${page} ${k}`);
84
- log(`${page}${steady ? '' : ' (moves by itself)'} · type ${hit.type ? 'reached' : 'NOT reached'} · colour ${hit.colour ? 'reached' : 'NOT reached'} · ${parts.join(', ')}`);
98
+ for (const k of KINDS) if (!hit[k] && REQUIRED.has(k)) misses.push(`${page} ${k}`);
99
+ for (const k of KINDS) if (!hit[k] && !REQUIRED.has(k)) unreached.push(`${page} ${k}`);
100
+ log(`${page}${steady ? '' : ' (moves by itself)'} · ${KINDS.map((k) => `${k} ${hit[k] ? 'reached' : 'NOT reached'}`).join(' · ')} · ${parts.join(', ')}`);
85
101
  }
86
102
  console.log('\ntype roles on each page before the change (--fs-body / --fs-meta / --fs-panel / --fs-display):\n ' + roleLines.join('\n '));
87
103
  const wrongRoles = roleLines.filter((l) => !l.endsWith('15px / 13px / 18px / 26px'));
88
104
  if (wrongRoles.length) misses.push('type roles not 15/13/18/26 px on ' + wrongRoles.length + ' page(s)');
89
105
  log(`${PAGES.length - new Set(misses.map((m) => m.split(' ')[0])).size} of ${PAGES.length} pages reached · screenshots in ${OUT}`);
90
106
  if (misses.length) log('NOT reached: ' + misses.join(', '));
107
+ if (unreached.length) log('measured, not required (REQUIRE=…): not reached on ' + unreached.join(', '));
91
108
  await browser.close(); srv.kill('SIGKILL'); T.killTmux && T.killTmux();
92
109
  process.exit(misses.length ? 1 : 0);
93
110
  })().catch((e) => { console.error(e); process.exit(2); });
111
+
112
+ /* --same: every page with each stylesheet in public/pm as on BASE_REF, against the files on disk, in light and dark. A change that only swaps
113
+ * a fixed value for a token of the same value must show no difference: not in the screenshot, not in any element's size, colour, spacing
114
+ * or corners. (token-swap-same-value, done test W6) */
115
+ async function same() {
116
+ const { execFileSync } = require('child_process');
117
+ const old = (f) => { try { return execFileSync('git', ['show', `${BASE_REF}:workspace/public/pm/${f}`], { cwd: __dirname, encoding: 'utf8', maxBuffer: 1 << 26, stdio: ['ignore', 'pipe', 'ignore'] }); } catch { return null; } };
118
+ const { chromium } = require('playwright-core');
119
+ const srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
120
+ await T.waitForServer(T.BASE);
121
+ const browser = await chromium.launch({ executablePath: findBrowser() });
122
+ fs.mkdirSync(OUT, { recursive: true });
123
+ const shoot = async (page, scheme, base) => {
124
+ const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 }, colorScheme: scheme, reducedMotion: 'reduce' });
125
+ if (base) await ctx.route(/\/pm\/[^/?]+\.css(\?.*)?$/, (r) => { const f = new URL(r.request().url()).pathname.split('/').pop(); const t = old(f); return t == null ? r.continue() : r.fulfill({ contentType: 'text/css', body: t }); });
126
+ const p = await ctx.newPage();
127
+ await p.goto(T.BASE + (URLS[page] || '/' + page), { waitUntil: 'load' }).catch(() => {});
128
+ await p.waitForTimeout(1500);
129
+ const s = await p.evaluate(sample);
130
+ const png = await p.screenshot({ fullPage: true });
131
+ await ctx.close();
132
+ return { ...s, png };
133
+ };
134
+ const diff = [];
135
+ for (const page of PAGES) for (const scheme of ['light', 'dark']) for (let attempt = 1; attempt <= 2; attempt++) {
136
+ // a difference must show twice: a page that drew while its data was still arriving differs once by timing, not by the change
137
+ const a = await shoot(page, scheme, true), b = await shoot(page, scheme, false);
138
+ const n = a.els.filter((v, i) => b.els[i] !== v).length + Math.abs(a.els.length - b.els.length);
139
+ const shot = Buffer.compare(a.png, b.png) !== 0;
140
+ let moves = false;
141
+ if (shot && !n) { const a2 = await shoot(page, scheme, true); moves = Buffer.compare(a.png, a2.png) !== 0; } // a page that moves by itself
142
+ const differs = n > 0 || (shot && !moves);
143
+ if (differs && attempt === 1) continue;
144
+ if (differs) { diff.push(`${page} ${scheme}`); fs.writeFileSync(path.join(OUT, `${page.replace('.html', '')}-${scheme}-base.png`), a.png); fs.writeFileSync(path.join(OUT, `${page.replace('.html', '')}-${scheme}-now.png`), b.png); }
145
+ log(`${page} ${scheme} · ${differs ? `DIFFERS (${n} elements${shot ? ', screenshot' : ''})` : `same${moves ? ' (moves by itself; every element the same)' : ''}${attempt > 1 ? ' (second try)' : ''}`}`);
146
+ break;
147
+ }
148
+ log(`${diff.length} of ${PAGES.length * 2} page views differ from ${BASE_REF}${diff.length ? ': ' + diff.join(', ') : ''}`);
149
+ await browser.close(); srv.kill('SIGKILL'); T.killTmux && T.killTmux();
150
+ process.exit(diff.length ? 1 : 0);
151
+ }
@@ -356,6 +356,14 @@ The design system's own sheet (Komorebi, `komorebi.css`) is the only place the t
356
356
 
357
357
  To change a text size on every page, change the style in `workspace/design-system/ui/tokens.json` and run `node lib/design-system.js --write`. Do not write a `--fs-*` value in a page's stylesheet.
358
358
 
359
+ ### pmos design swap: a fixed value becomes the token with the same value
360
+
361
+ - `pmos design swap` counts, for each stylesheet, the fixed spacing (padding, margin, gap) and corner values that equal a design token. It also counts the values that sit between two tokens. It changes no file.
362
+ - `pmos design swap --write` replaces each of those values with its token, for example `padding: 8px 12px` with `padding: var(--space-8) var(--space-12)`. Nothing on screen moves, because the token has the same value. After that, a change to the token reaches every place that reads it.
363
+ - It does not change a value between two tokens. That is a decision for a person. It does not change the system's own sheets, scripts, HTML, a custom property, a `var()` fallback, `@keyframes` or the scaled slide and report canvases.
364
+ - When two system sheets have a token with the same value, a token at `:root` wins, then the later sheet. So the UI system's own token wins over a chart token.
365
+ - A product sets its files in `design-drift.json`. `swapIgnore` names sheets that draw in a frame without the system's sheets.
366
+
359
367
  To see that a change reaches every page, run `node design-token-reach.js` in `workspace/`. It changes one token in a test copy of the system's sheets, takes a screenshot of each page before and after, and names each page the change did not reach. It changes no file.
360
368
 
361
369
  ### pmos pages: fix a page before you add to it
@@ -116,6 +116,15 @@ The Viewer shows one item: an initiative, a program, a task, a document, a meeti
116
116
  - On a page drawn from the PMOS design system (Today, Home, an item on its own page), the parts inside the Viewer card follow the system too: a meeting, the calendar and a report use its corners, its buttons and its switches. A word button has a small corner, a switch looks like tabs, and a chip or a tag stays round.
117
117
  - One item shows in one Viewer only. If an item is already open, opening it again (a row, a ⌘-click, Open beside) shows it in the Viewer it is in. It never opens a second copy.
118
118
 
119
+ ### What you type is kept
120
+
121
+ Text you type in a PMOS box (a chat message, a Why, notes, a routine's instructions) is kept on this computer until you send it, save it or clear it.
122
+
123
+ - If a panel closes or the page reloads before you send, open the same box again: the text is back, and a short note at the bottom of the page says **Draft kept**. On a phone the note shows under the top bar.
124
+ - Press the Undo icon on that note to start empty instead.
125
+ - A message typed in one chat stays with that chat.
126
+ - PMOS keeps nothing from password, key, token or search boxes. A kept draft goes after 14 days.
127
+
119
128
  ### A task opened from a place
120
129
 
121
130
  On a computer, a PMOS task you open from Events, Today, Goals or Search opens as one full popup, in the middle of the page. Home keeps its Viewer until Home is rebuilt, and a Jira ticket keeps the ticket Viewer.
@@ -14,13 +14,16 @@
14
14
  * --github print each new bypass as a GitHub warning on its file and line (the CI step uses it)
15
15
  * --pages the older view instead: each page's share of system classes and its own CSS (a measure only)
16
16
  *
17
- * Run it in the product's repository. It reads git only and changes nothing else. Exit codes: 0 done, 1 a count rose (only with --gate) or
17
+ * pmos design swap [--write] (initiative token-swap-same-value, lib/design-swap.js) each fixed spacing or corner value in a scanned
18
+ * stylesheet that equals a design token: counted per file, or with --write replaced by that token. Nothing on screen moves.
19
+ *
20
+ * Run it in the product's repository. drift reads git only and changes nothing else. Exit codes: 0 done, 1 a count rose (only with --gate) or
18
21
  * the refs cannot be read, 2 usage. */
19
22
  const fs = require('fs');
20
23
  const path = require('path');
21
24
  const D = require('./design-drift.js');
22
25
 
23
- const COMMANDS = { design: ['drift'] };
26
+ const COMMANDS = { design: ['drift', 'swap'] };
24
27
  const USAGE = [
25
28
  'usage: pmos design drift — every place your styles and scripts do not read a design token, and which ones a change adds',
26
29
  ' pmos design drift [--ref <ref>] [--base <ref>|week] [--weeks <n>] [--json] [--write] [--gate] [--github] [--pages]',
@@ -32,6 +35,7 @@ const USAGE = [
32
35
  ' --github print each new bypass as a GitHub warning on its line',
33
36
  ' --pages each page\'s share of system classes instead (a measure only)',
34
37
  'It reads git only. A product sets its files and system sheets in design-drift.json in its design-system folder.',
38
+ ' pmos design swap [--write] each fixed spacing or corner value that equals a design token: counted, or with --write replaced by the token',
35
39
  ];
36
40
  const FLAGS = new Set(['ref', 'base', 'weeks', 'json', 'write', 'gate', 'repo', 'github', 'pages']);
37
41
  const BOOL = new Set(['json', 'write', 'gate', 'github', 'pages']);
@@ -60,6 +64,14 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), now
60
64
  if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 2; }
61
65
  if (!COMMANDS.design.includes(sub)) { say(`unknown design command "${sub}". Use one of: ${COMMANDS.design.join(', ')}`); return 2; }
62
66
  const { pos, flags } = parse(args.slice(1));
67
+ if (sub === 'swap') {
68
+ const bad = Object.keys(flags).filter((k) => k !== 'write' && k !== 'repo');
69
+ if (pos.length || bad.length) { say('✗ usage: pmos design swap [--write]'); return 2; }
70
+ const root = repoRoot(flags.repo ? path.resolve(cwd, flags.repo) : cwd);
71
+ if (!root) { say('✗ this is not a git repository. Run pmos design swap in your product\'s repository.'); return 1; }
72
+ require('./design-swap.js').run({ root, write: !!flags.write, say });
73
+ return 0;
74
+ }
63
75
  if (pos.length) { say(`✗ pmos design ${sub} takes no argument`); return 2; }
64
76
  for (const k of Object.keys(flags)) if (!FLAGS.has(k)) { say(`✗ --${k} is not an option of pmos design drift`); return 2; }
65
77
  for (const k of ['ref', 'base', 'weeks', 'repo']) if (k in flags && !flags[k]) { say(`✗ --${k} needs a value`); return 2; }
@@ -47,6 +47,8 @@ const DEFAULTS = Object.freeze({
47
47
  scan: ['workspace/public/**/*.css', 'workspace/public/**/*.js', 'workspace/public/**/*.html'],
48
48
  ignore: ['workspace/public/vendor/**'],
49
49
  systemScripts: ['komorebi.js'],
50
+ // `pmos design swap` (token-swap-same-value) leaves these sheets alone: they draw in a frame that does not load the system's sheets
51
+ swapIgnore: ['workspace/public/pm/tokens.css', 'workspace/public/pm/premium-report-*.css'],
50
52
  });
51
53
  const CONFIG_PLACES = ['pmos/design-system/design-drift.json', 'design-system/design-drift.json', 'workspace/design-system/design-drift.json'];
52
54
  const REBUILT_SHARE = 0.10;
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+ /* design-swap.js — swap a fixed spacing or corner value for the design token with the same value (initiative token-swap-same-value,
3
+ * token-first design system step 2). Wawan, 2026-11-22: every part of every page reads the design system's tokens, so that changing one
4
+ * token changes every page. The token guard (lib/design-drift.js, `pmos design drift`) counts the places that skip a token; this rewrites
5
+ * the ones where a token has EXACTLY the value written, so nothing on screen moves.
6
+ *
7
+ * What it swaps: lengths in padding, margin, gap and border-radius declarations (each length of a shorthand on its own; px, and rem at
8
+ * 16 px). A length with no same-value token stays and is listed (`left`): a value between two tokens is a decision, never a guess.
9
+ * What it never touches: custom property definitions, a value inside var(--x, fallback), @keyframes, the scaled canvases (slides, report
10
+ * cards, the presented page, the diagram labels: their sizes follow the canvas, not the UI), the system's own sheets, scripts and HTML.
11
+ * Which token: from the system sheets (the product's design-drift config). A token declared at :root wins over a scoped one (it works on
12
+ * every page); then the later sheet wins, so the UI system's own sheet beats brand and charts (10px → --radius-md, not --radius-lane).
13
+ *
14
+ * swap(css, tokens) PURE → { css, n, left: [{ line, prop, value }] } · tokensFrom(sheetTexts) PURE → Map value(px) → { spacing, corner }
15
+ * run({ root, write, say }) → { files: [{ file, n, left }], total } — `pmos design swap [--write]` (lib/design-cli.js)
16
+ */
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+ const DD = require('./design-drift.js');
20
+
21
+ const SPACE_PROP = /^(?:(?:padding|margin)(?:-(?:top|right|bottom|left|inline|block)(?:-(?:start|end))?)?|(?:row-|column-)?gap)$/;
22
+ const RADIUS_PROP = /^border(?:-[a-z]+)*-radius$/;
23
+ const FAMILY = { spacing: /^--space-/, corner: /^--radius-/ };
24
+ // the scaled canvases (conformance-gate.js SCALED_CANVAS, and the report slide): their lengths are canvas units
25
+ const CANVAS = /(?:^|[\s>+~,(])\.(?:sl-(?:cv|tx|it|lab|axl|ph)|r-(?:title|heading|small|kicker|big|quote)|vzx-page|vz-(?:words|tfig|th)|rds|rsm|rp-slide|tg-clu|tg-tmc|iv-tlm|pc-(?:flow|lanes|sn|dn|e|ln|bx))\b/;
26
+ const LENGTH = /(?<![\w.#/-])(-?\d*\.?\d+)(px|rem)\b/g;
27
+ const log = (s) => `[token-swap] ${s}`;
28
+
29
+ /** PURE. The system's spacing and corner tokens: px value → { spacing: name, corner: name }. */
30
+ function tokensFrom(sheets) {
31
+ const best = { spacing: new Map(), corner: new Map() }; // px → { name, root, order }
32
+ sheets.forEach((css, order) => {
33
+ const src = String(css || '').replace(/\/\*[\s\S]*?\*\//g, '');
34
+ for (const m of src.matchAll(/([^{}]*)\{([^{}]*)\}/g)) {
35
+ const root = m[1].split(',').some((x) => /^:root\b/.test(x.trim()));
36
+ for (const d of m[2].matchAll(/(--[a-z0-9-]+)\s*:\s*([^;]+)/g)) {
37
+ const v = /^(\d*\.?\d+)(px|rem)$/.exec(d[2].trim()); if (!v) continue;
38
+ const px = v[2] === 'px' ? Number(v[1]) : Number(v[1]) * 16;
39
+ for (const k of Object.keys(FAMILY)) {
40
+ if (!FAMILY[k].test(d[1])) continue;
41
+ const cur = best[k].get(px), cand = { name: d[1], root, order };
42
+ if (!cur || (cand.root && !cur.root) || (cand.root === cur.root && cand.order >= cur.order)) best[k].set(px, cand);
43
+ }
44
+ }
45
+ }
46
+ });
47
+ return { spacing: new Map([...best.spacing].map(([px, t]) => [px, t.name])), corner: new Map([...best.corner].map(([px, t]) => [px, t.name])) };
48
+ }
49
+
50
+ /** One declaration value with each same-value length swapped. → { value, n, left: [length] } */
51
+ function swapValue(value, map) {
52
+ let n = 0; const left = [];
53
+ // a var(…) call is a token already: keep it whole (its fallback included)
54
+ const parts = []; let rest = value;
55
+ while (rest.length) {
56
+ const i = rest.indexOf('var(');
57
+ if (i < 0) { parts.push([rest, false]); break; }
58
+ parts.push([rest.slice(0, i), false]);
59
+ let depth = 0, j = i + 3;
60
+ for (; j < rest.length; j++) { if (rest[j] === '(') depth++; else if (rest[j] === ')' && --depth === 0) break; }
61
+ parts.push([rest.slice(i, j + 1), true]); rest = rest.slice(j + 1);
62
+ }
63
+ const out = parts.map(([t, keep]) => (keep ? t : t.replace(LENGTH, (m, num, unit) => {
64
+ const px = unit === 'px' ? Number(num) : Number(num) * 16;
65
+ if (px === 0) return m;
66
+ const name = map.get(Math.abs(px));
67
+ if (!name) { left.push(m); return m; }
68
+ n++;
69
+ return px < 0 ? `calc(-1 * var(${name}))` : `var(${name})`;
70
+ }))).join('');
71
+ return { value: out, n, left };
72
+ }
73
+
74
+ /** PURE. Swap a stylesheet. Comments, @keyframes, custom properties and canvas rules stay as written. */
75
+ function swap(css, tokens) {
76
+ const src = String(css || '');
77
+ let out = '', n = 0, i = 0, line = 1;
78
+ const left = [];
79
+ const stack = []; // selector or at-rule prelude of each open block
80
+ let buf = '';
81
+ const skipBlock = () => stack.some((s) => /^@keyframes|^@-webkit-keyframes/.test(s) || CANVAS.test(' ' + s));
82
+ const flushDecl = (text) => {
83
+ // text: one declaration with its leading whitespace, no ';' or '}'
84
+ const m = /^(\s*)([a-z-]+)(\s*:\s*)([\s\S]*?)(\s*)$/.exec(text);
85
+ if (!m || skipBlock() || !stack.length) return text;
86
+ const prop = m[2];
87
+ const kind = SPACE_PROP.test(prop) ? 'spacing' : RADIUS_PROP.test(prop) ? 'corner' : null;
88
+ if (!kind) return text;
89
+ const r = swapValue(m[4], tokens[kind]);
90
+ n += r.n;
91
+ for (const v of r.left) left.push({ line, prop, value: v });
92
+ return m[1] + prop + m[3] + r.value + m[5];
93
+ };
94
+ while (i < src.length) {
95
+ const ch = src[i];
96
+ if (ch === '/' && src[i + 1] === '*') { const e = src.indexOf('*/', i + 2); const end = e < 0 ? src.length : e + 2; const c = src.slice(i, end); buf += c; line += (c.match(/\n/g) || []).length; i = end; continue; }
97
+ if (ch === '"' || ch === "'") { const e = src.indexOf(ch, i + 1); const end = e < 0 ? src.length : e + 1; buf += src.slice(i, end); i = end; continue; }
98
+ if (ch === '{') { stack.push(buf.replace(/\/\*[\s\S]*?\*\//g, '').trim()); out += buf + ch; buf = ''; i++; continue; }
99
+ if (ch === ';' || ch === '}') {
100
+ out += flushDecl(buf) + ch; buf = '';
101
+ if (ch === '}') stack.pop();
102
+ i++; continue;
103
+ }
104
+ if (ch === '\n') line++;
105
+ buf += ch; i++;
106
+ }
107
+ out += buf;
108
+ return { css: out, n, left };
109
+ }
110
+
111
+ /** Walk a folder for files (skips node_modules and .git). */
112
+ function walk(root, rel = '', acc = []) {
113
+ for (const e of fs.readdirSync(path.join(root, rel), { withFileTypes: true })) {
114
+ if (e.name === 'node_modules' || e.name === '.git') continue;
115
+ const p = rel ? rel + '/' + e.name : e.name;
116
+ if (e.isDirectory()) walk(root, p, acc); else acc.push(p);
117
+ }
118
+ return acc;
119
+ }
120
+
121
+ /** `pmos design swap [--write]`: every scanned stylesheet of the product at root, from its design-drift config. */
122
+ function run({ root = process.cwd(), write = false, say = (s) => console.log(s) } = {}) {
123
+ const read = (p) => { try { return fs.readFileSync(path.join(root, p), 'utf8'); } catch { return null; } };
124
+ const cfg = DD.configAt(read);
125
+ const files = walk(root).filter((p) => /\.css$/i.test(p));
126
+ const isSystem = (p) => (cfg.systemSheets || []).some((n) => p === n || p.endsWith('/' + n));
127
+ const sysSheets = files.filter(isSystem).sort((a, b) => cfg.systemSheets.findIndex((n) => a.endsWith(n)) - cfg.systemSheets.findIndex((n) => b.endsWith(n)));
128
+ const tokens = tokensFrom(sysSheets.map(read));
129
+ const scan = (cfg.scan || []).map(DD.globRe), ignore = [...(cfg.ignore || []), ...(cfg.swapIgnore || [])].map(DD.globRe);
130
+ const targets = files.filter((p) => !isSystem(p) && scan.some((re) => re.test(p)) && !ignore.some((re) => re.test(p))).sort();
131
+ const out = []; let total = 0, leftTotal = 0;
132
+ for (const f of targets) {
133
+ const text = read(f);
134
+ const r = swap(text, tokens);
135
+ if (!r.n && !r.left.length) continue;
136
+ out.push({ file: f, n: r.n, left: r.left });
137
+ total += r.n; leftTotal += r.left.length;
138
+ if (r.n) say(log(`${f}: ${r.n} ${write ? 'swapped' : 'to swap'}${r.left.length ? `, ${r.left.length} between two tokens` : ''}`));
139
+ if (write && r.n) fs.writeFileSync(path.join(root, f), r.css);
140
+ }
141
+ say(log(`${write ? 'swapped' : 'same-value swaps'} ${total} in ${out.filter((x) => x.n).length} stylesheets; ${leftTotal} lengths sit between two tokens and stay`));
142
+ say(String(total));
143
+ return { files: out, total, left: leftTotal };
144
+ }
145
+
146
+ module.exports = { swap, swapValue, tokensFrom, run, CANVAS };
@@ -100,8 +100,9 @@ function tokensOf(json) {
100
100
  }
101
101
 
102
102
  // a token can name another one: "{blue}" is the brand's blue, so the chart role follows the brand in both themes
103
- // the type tokens' block: written at :root in the workspace sheet too (not scoped to .pm-ds), so a page without pm-ds and the older
104
- // names that alias them (LEGACY_TYPE) resolve them everywhere. The names are new, so declaring them on every page changes no rule.
103
+ // the UI system's unscoped token blocks (type, spacing, corners): written at :root in the workspace sheet too (not scoped to .pm-ds), so a
104
+ // page without pm-ds and the older names that alias them (LEGACY_TYPE) resolve them everywhere. No other sheet declares these names, so
105
+ // declaring them on every page changes no rule.
105
106
  const TYPE_ROOT = ':root:where(*)';
106
107
  const valueOf = (v) => String(v).replace(/\{([a-z0-9-]+)\}/g, 'var(--$1)');
107
108
  /** PURE. A system's tokens.json → its tokens.css: the themed tokens (light, then dark), the rest, and (ui only) the type classes. */
@@ -120,7 +121,9 @@ function tokensCss(json, name) {
120
121
  const L = [`/* ${(SYSTEMS[name] || {}).title || name} tokens. GENERATED from tokens.json by lib/design-system.js: do not edit; run \`node lib/design-system.js --write\`. */`];
121
122
  if (light.length) L.push(`:root, [data-theme="light"] {${light.join(';')}}`);
122
123
  if (dark.length) L.push(`[data-theme="dark"] {${dark.join(';')}}`);
123
- if (rest.length) L.push(`:root {${rest.join(';')}}`);
124
+ // the UI system's spacing and corners sit at :root in the workspace sheet too (token-swap-same-value): a page sheet that reads them works
125
+ // on every page, with or without pm-ds
126
+ if (rest.length) L.push(`${(SYSTEMS[name] || {}).types ? TYPE_ROOT : ':root'} {${rest.join(';')}}`);
124
127
  if ((SYSTEMS[name] || {}).types) {
125
128
  // the type styles are tokens (--type-, --leading-, --weight-<style>), and the type classes read them: a change to one style's size in
126
129
  // tokens.json reaches every class and part that names it (initiative token-first-design-system)
@@ -199,7 +202,7 @@ function sheetOf(name, tokens, bundle) {
199
202
  ` * lib/design-system.js: do not edit; change the system's files and run \`node lib/design-system.js --write\`. Every rule is scoped to ${sys.scope},`,
200
203
  ' * so the sheet changes nothing until a page puts the class on its root. Load brand.css, then charts.css, then the system\'s own sheet. */',
201
204
  ];
202
- if (sys.types) L.push('/* Except the type tokens (--type-, --leading-, --weight-<style>) and the workspace\'s older type names that point at them (--fs-*, --fw-*,\n * --lh-*): those sit at :root, so a change to one Komorebi type token reaches every page, with or without the class. */');
205
+ if (sys.types) L.push('/* Except the type, spacing and corner tokens (--type-, --leading-, --weight-, --space-, --radius-) and the workspace\'s older type names that\n * point at them (--fs-*, --fw-*, --lh-*): those sit at :root, so a change to one Komorebi token reaches every page, with or without the class. */');
203
206
  if (name === 'brand') L.push(...FONTS);
204
207
  // brand and charts sit inside another system's page: their own page-level rules (body, the preview root) are that system's job
205
208
  const shared = sys.scope === FAMILY;
@@ -45,6 +45,7 @@ const MODULES = Object.freeze([
45
45
  'routes-my-work', // initiative my-work: the ranked list of work assigned to the PM, the brief, Read again
46
46
  'routes-intake', // planning-flows run 4: one-line intake draft (drafts only)
47
47
  'routes-pm-items', // planning-flows runs 1-2: the PM's own items and jobs to be done (add, edit, remove, undo)
48
+ 'routes-draft-keep', // forms-keep-drafts: counts of returned and undone drafts, never the text (draft-keep/marks.jsonl; page-press POST)
48
49
  'routes-today-log', // six-place navigation slice 5: Today's log, the PM's own entries and marks (today-log/log.jsonl; page-press POST)
49
50
  'routes-runs', // console3 agent surfaces: runs grouped for the sessions panel, PM answers, corrections
50
51
  'routes-doc-health', // console3 B2: the six document health checks, recomputed from text
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+ /* routes-draft-keep.js — the health number of forms that keep drafts (initiative forms-keep-drafts; pm/draft-keep.js is the page side).
3
+ *
4
+ * POST /api/draft-keep/mark { ev: "restored" | "undone", n } → { ok } a page press; appends { at, ev, n } and nothing else
5
+ *
6
+ * The drafts themselves stay in the browser's local storage: this route never receives or keeps any typed text, only counts.
7
+ * STATE: <runtime>/draft-keep/marks.jsonl, append-only.
8
+ * HEALTH (record health_read): `node workspace/lib/routes-draft-keep.js --kept-percent` prints the percent of returned drafts kept, not
9
+ * undone, over the last 14 days; -1 when no draft came back in that time. Every line it logs starts with [draft-keep]. */
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const guard = require('./pm-guard.js');
13
+
14
+ const EVENTS = new Set(['restored', 'undone']);
15
+ const WINDOW = 14 * 864e5;
16
+ const fileOf = (runtimeDir) => path.join(runtimeDir, 'draft-keep', 'marks.jsonl');
17
+
18
+ function readLines(file) {
19
+ let raw = '';
20
+ try { raw = fs.readFileSync(file, 'utf8'); } catch { return []; }
21
+ return raw.split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
22
+ }
23
+
24
+ /** Percent of returned drafts kept (not undone) in the 14 days before `now`; -1 when none came back. */
25
+ function keptPercent(lines, now) {
26
+ let back = 0, undone = 0;
27
+ for (const l of lines) {
28
+ const t = Date.parse(l.at);
29
+ if (!(now - t <= WINDOW)) continue;
30
+ const n = Number.isInteger(l.n) && l.n > 0 ? l.n : 1;
31
+ if (l.ev === 'restored') back += n; else if (l.ev === 'undone') undone += n;
32
+ }
33
+ if (!back) return -1;
34
+ return Math.round(100 * Math.max(0, back - undone) / back);
35
+ }
36
+
37
+ module.exports = {
38
+ prefixes: ['/api/draft-keep'],
39
+ fileOf,
40
+ keptPercent,
41
+ handle: async (req, res, url, ctx) => {
42
+ if (url.pathname !== '/api/draft-keep/mark' || req.method !== 'POST') return false;
43
+ if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'PMOS has no state folder here, so it cannot count returned drafts' }, 503); return true; }
44
+ const got = await ctx.readJson(req);
45
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
46
+ const body = got.body || {};
47
+ const g = guard.requirePagePress(req, body);
48
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
49
+ if (!EVENTS.has(body.ev)) { ctx.json(res, { ok: false, error: 'ev is restored or undone' }, 400); return true; }
50
+ const n = Number.isInteger(body.n) && body.n > 0 && body.n < 1000 ? body.n : 1;
51
+ const file = fileOf(ctx.runtimeDir);
52
+ fs.mkdirSync(path.dirname(file), { recursive: true });
53
+ fs.appendFileSync(file, JSON.stringify({ at: new Date().toISOString(), ev: body.ev, n }) + '\n');
54
+ console.log(`[draft-keep] ${body.ev} ${n}`);
55
+ ctx.json(res, { ok: true });
56
+ return true;
57
+ },
58
+ };
59
+
60
+ if (require.main === module && process.argv.includes('--kept-percent')) {
61
+ const root = require('./state-root.js').resolveStateRoot({ env: process.env, legacy: null }).root;
62
+ const lines = readLines(fileOf(root));
63
+ console.log(`[draft-keep] ${lines.length} marks in ${fileOf(root)}`);
64
+ console.log(String(keptPercent(lines, Date.now())));
65
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.697.0",
3
+ "version": "0.699.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.697.0",
9
+ "version": "0.699.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",