create-pmos 0.51.0 → 0.53.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 (212) hide show
  1. package/package.json +1 -1
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/mods/pmos-cockpit/README.md +13 -0
  4. package/payload/mods/pmos-cockpit/hooks/lib/commands.mjs +2 -1
  5. package/payload/mods/pmos-cockpit/hooks/lib/grants.mjs +41 -11
  6. package/payload/mods/pmos-cockpit/hooks/lib/guard.mjs +228 -8
  7. package/payload/mods/pmos-cockpit/hooks/register.tsx +11 -3
  8. package/payload/planning/evals/eval-calibration.md +1 -1
  9. package/payload/planning/okrs/health-budgets.md +1 -1
  10. package/payload/scripts/plan-items-stage.js +271 -0
  11. package/payload/scripts/pmos-log.sh +18 -7
  12. package/payload/scripts/workflow-state.js +28 -2
  13. package/payload/state/discoveries.md +1 -1
  14. package/payload/state/log.md +1 -1
  15. package/workspace/bin/pmos.js +15 -1
  16. package/workspace/cut-stub.js +40 -0
  17. package/workspace/first-paint-audit.js +145 -0
  18. package/workspace/fixtures/capture/requirements/capture-2026-10-04-1.md +10 -0
  19. package/workspace/fixtures/initiatives-api/list.json +176 -0
  20. package/workspace/fixtures/initiatives-api/post-403.json +5 -0
  21. package/workspace/fixtures/initiatives-api/post-ok.json +10 -0
  22. package/workspace/fixtures/initiatives-api/roadmap.json +208 -0
  23. package/workspace/fixtures/initiatives-api/sheet.json +112 -0
  24. package/workspace/fixtures/report-api/draft.json +177 -0
  25. package/workspace/fixtures/reports-page/draft-biweekly-2026-10-16.md +97 -0
  26. package/workspace/fixtures/today-api/provider-rows.json +204 -0
  27. package/workspace/fixtures/today-api/seam-probe-kinds.json +5 -0
  28. package/workspace/guide/board.md +81 -0
  29. package/workspace/guide/breakdown.md +154 -0
  30. package/workspace/guide/command-palette.md +75 -0
  31. package/workspace/guide/index.md +27 -17
  32. package/workspace/guide/initiatives-roadmap.md +130 -0
  33. package/workspace/guide/initiatives-screen.md +89 -0
  34. package/workspace/guide/initiatives-timeline.md +57 -0
  35. package/workspace/guide/integrated-work.md +94 -0
  36. package/workspace/guide/knowledge-graph.md +3 -68
  37. package/workspace/guide/layout.md +98 -32
  38. package/workspace/guide/live-notes.md +3 -3
  39. package/workspace/guide/pm-only-acts.md +89 -0
  40. package/workspace/guide/pm-only-lines.md +61 -0
  41. package/workspace/guide/reports-page.md +80 -0
  42. package/workspace/guide/reports.md +73 -0
  43. package/workspace/guide/timeline.md +70 -0
  44. package/workspace/guide/today.md +85 -0
  45. package/workspace/guide/validate-with-typesafe.md +1 -1
  46. package/workspace/lib/actor.js +91 -0
  47. package/workspace/lib/board-cache.js +32 -2
  48. package/workspace/lib/board-cli.js +108 -0
  49. package/workspace/lib/board-fold.js +232 -0
  50. package/workspace/lib/breakdown-export.js +80 -0
  51. package/workspace/lib/capture.js +98 -0
  52. package/workspace/lib/engine/plan-items-stage.js +271 -0
  53. package/workspace/lib/engine/workflow-state.js +28 -2
  54. package/workspace/lib/factory-join.js +158 -0
  55. package/workspace/lib/grant-mint.js +113 -0
  56. package/workspace/lib/health-rules-factory.js +92 -0
  57. package/workspace/lib/health-rules-plan.js +164 -0
  58. package/workspace/lib/health.js +79 -0
  59. package/workspace/lib/initiative-cli.js +222 -0
  60. package/workspace/lib/initiative-display.js +183 -0
  61. package/workspace/lib/initiative-needs.js +127 -0
  62. package/workspace/lib/initiative-rows.js +206 -0
  63. package/workspace/lib/initiative-writer.js +141 -0
  64. package/workspace/lib/issues.js +206 -0
  65. package/workspace/lib/item-cli.js +195 -0
  66. package/workspace/lib/item-spans.js +137 -0
  67. package/workspace/lib/measure-cli.js +100 -0
  68. package/workspace/lib/measurements.js +189 -0
  69. package/workspace/lib/mobile-nav.js +57 -53
  70. package/workspace/lib/needs-providers.js +120 -0
  71. package/workspace/lib/placements.js +440 -0
  72. package/workspace/lib/plan-items.js +922 -0
  73. package/workspace/lib/plan-ledgers.js +85 -0
  74. package/workspace/lib/plan-rules.js +72 -0
  75. package/workspace/lib/plan-tree.js +367 -0
  76. package/workspace/lib/pm-guard.js +174 -0
  77. package/workspace/lib/pm-lines-needs.js +331 -0
  78. package/workspace/lib/pmos-verbs.js +66 -0
  79. package/workspace/lib/proactive.js +7 -4
  80. package/workspace/lib/report-cli.js +152 -0
  81. package/workspace/lib/report-draft.js +579 -0
  82. package/workspace/lib/report-needs.js +213 -0
  83. package/workspace/lib/route-modules.js +128 -0
  84. package/workspace/lib/routes-board.js +91 -0
  85. package/workspace/lib/routes-capture.js +52 -0
  86. package/workspace/lib/routes-initiatives.js +371 -0
  87. package/workspace/lib/routes-reports.js +163 -0
  88. package/workspace/lib/routes-timeline.js +197 -0
  89. package/workspace/lib/routes-today.js +32 -0
  90. package/workspace/lib/today-cli.js +99 -0
  91. package/workspace/lib/today.js +333 -0
  92. package/workspace/lib/triage.js +163 -0
  93. package/workspace/lib/verify-work-cli.js +81 -0
  94. package/workspace/lib/work-check-needs.js +99 -0
  95. package/workspace/package-lock.json +1 -1
  96. package/workspace/package.json +5 -5
  97. package/workspace/public/index.html +29 -19
  98. package/workspace/public/pm/app.js +299 -30
  99. package/workspace/public/pm/bd-board.js +113 -0
  100. package/workspace/public/pm/bd-drag.js +59 -0
  101. package/workspace/public/pm/bd-model.js +152 -0
  102. package/workspace/public/pm/bd-timeline.js +233 -0
  103. package/workspace/public/pm/bd-tree.js +244 -0
  104. package/workspace/public/pm/board-copy.js +57 -0
  105. package/workspace/public/pm/breakdown-api.js +58 -0
  106. package/workspace/public/pm/breakdown-copy.js +138 -0
  107. package/workspace/public/pm/components.css +3054 -0
  108. package/workspace/public/pm/cycle-review.js +125 -0
  109. package/workspace/public/pm/data.js +40 -187
  110. package/workspace/public/pm/dest-board.js +438 -0
  111. package/workspace/public/pm/dest-initiatives.js +134 -0
  112. package/workspace/public/pm/dest-reports.js +270 -0
  113. package/workspace/public/pm/dest-settings.js +217 -0
  114. package/workspace/public/pm/dest-today.js +176 -0
  115. package/workspace/public/pm/dialogs.js +88 -0
  116. package/workspace/public/pm/display-word.js +56 -0
  117. package/workspace/public/pm/dock.js +105 -0
  118. package/workspace/public/pm/fixture.js +8 -227
  119. package/workspace/public/pm/frame-copy.js +94 -0
  120. package/workspace/public/pm/handoff-box.js +82 -0
  121. package/workspace/public/pm/http.js +88 -0
  122. package/workspace/public/pm/icons.js +53 -0
  123. package/workspace/public/pm/initiative-list.js +218 -0
  124. package/workspace/public/pm/initiative-sheet.js +261 -0
  125. package/workspace/public/pm/initiatives-api.js +59 -0
  126. package/workspace/public/pm/initiatives-copy.js +215 -0
  127. package/workspace/public/pm/initiatives-timeline-copy.js +59 -0
  128. package/workspace/public/pm/initiatives-timeline.js +410 -0
  129. package/workspace/public/pm/initiatives-ui.js +123 -0
  130. package/workspace/public/pm/item-sheet.js +251 -0
  131. package/workspace/public/pm/keep-card.js +204 -0
  132. package/workspace/public/pm/lifecycle.js +7 -1
  133. package/workspace/public/pm/mobile.css +49 -20
  134. package/workspace/public/pm/mobile.js +157 -29
  135. package/workspace/public/pm/modes-live.js +7 -883
  136. package/workspace/public/pm/modes.js +32 -1024
  137. package/workspace/public/pm/new-initiative-sheet.js +74 -0
  138. package/workspace/public/pm/next-step-ui.js +3 -2
  139. package/workspace/public/pm/palette-copy.js +51 -0
  140. package/workspace/public/pm/palette.js +312 -0
  141. package/workspace/public/pm/panel-breakdown.js +702 -0
  142. package/workspace/public/pm/panel-cockpit.js +63 -295
  143. package/workspace/public/pm/panel-detail.js +25 -172
  144. package/workspace/public/pm/panel-initiatives.js +1 -19
  145. package/workspace/public/pm/panel-repos.js +31 -81
  146. package/workspace/public/pm/panel-tabs.js +197 -110
  147. package/workspace/public/pm/panel-trees.js +5 -2
  148. package/workspace/public/pm/portfolio-report.js +61 -0
  149. package/workspace/public/pm/primitives.js +656 -0
  150. package/workspace/public/pm/print.css +33 -0
  151. package/workspace/public/pm/provider-cards.js +136 -0
  152. package/workspace/public/pm/registry.js +194 -0
  153. package/workspace/public/pm/release-card.js +110 -0
  154. package/workspace/public/pm/report-view.js +309 -0
  155. package/workspace/public/pm/reports-copy.js +114 -0
  156. package/workspace/public/pm/roadmap.js +271 -0
  157. package/workspace/public/pm/sig-watch.js +41 -0
  158. package/workspace/public/pm/state.js +8 -4
  159. package/workspace/public/pm/status-banner.js +13 -5
  160. package/workspace/public/pm/tab-doc.js +2 -4
  161. package/workspace/public/pm/tab-term.js +12 -2
  162. package/workspace/public/pm/tab-web.js +3 -2
  163. package/workspace/public/pm/timeline-copy.js +48 -0
  164. package/workspace/public/pm/today-cards.js +244 -0
  165. package/workspace/public/pm/today-copy.js +97 -0
  166. package/workspace/public/pm/tokens.css +16 -18
  167. package/workspace/public/pm/topbar.js +102 -0
  168. package/workspace/public/pm/triage-card.js +60 -0
  169. package/workspace/public/pm/undo-hold.js +103 -0
  170. package/workspace/public/pm/view-addrepo.js +2 -1
  171. package/workspace/public/pm/view-livenotes.js +3 -1
  172. package/workspace/public/pm/view-today.js +7 -162
  173. package/workspace/public/vendor/Sortable.min.js +2 -0
  174. package/workspace/public/vendor/lucide-sprite.js +79 -0
  175. package/workspace/replaced-tests.json +2864 -0
  176. package/workspace/run-tests.js +117 -6
  177. package/workspace/server.js +312 -36
  178. package/workspace/sheet-answer.js +61 -0
  179. package/workspace/skills/measure.skill +41 -0
  180. package/workspace/skills/report-biweekly.skill +23 -25
  181. package/workspace/skills/tracker-refresh.skill +50 -0
  182. package/workspace/test-files.json +20 -4
  183. package/workspace/test-lists/base.json +6 -0
  184. package/workspace/test-lists/run2-a.json +6 -0
  185. package/workspace/test-lists/run2-b.json +13 -0
  186. package/workspace/test-lists/run2-c.json +19 -0
  187. package/workspace/test-lists/run2-d.json +22 -0
  188. package/workspace/test-lists/run3-0.json +5 -0
  189. package/workspace/test-lists/run3-a.json +5 -0
  190. package/workspace/test-lists/run3-b.json +6 -0
  191. package/workspace/test-lists/run3-c.json +15 -0
  192. package/workspace/test-lists/run3-d.json +6 -0
  193. package/workspace/test-lists/run4-a.json +8 -0
  194. package/workspace/test-lists/run4-b.json +6 -0
  195. package/workspace/test-lists/run4-c.json +13 -0
  196. package/workspace/test-lists/run4-d.json +9 -0
  197. package/workspace/test-lists/run5-a.json +6 -0
  198. package/workspace/test-lists/run5-b.json +6 -0
  199. package/workspace/test-lists/run5-c.json +15 -0
  200. package/workspace/test-run.js +27 -1
  201. package/workspace/third-party/README.md +44 -0
  202. package/workspace/third-party/lucide-static-1.52.0.LICENSE +43 -0
  203. package/workspace/third-party/sortablejs-1.15.7.LICENSE +21 -0
  204. package/workspace/design-parity.js +0 -673
  205. package/workspace/public/pm/tab-task.js +0 -86
  206. package/workspace/public/pm/view-guide.js +0 -141
  207. package/workspace/public/pm/view-knowledge.js +0 -225
  208. package/workspace/public/pm/view-memory.js +0 -122
  209. package/workspace/public/pm/view-portfolio.js +0 -153
  210. package/workspace/public/pm/view-reports.js +0 -190
  211. package/workspace/public/pm/view-scheduled.js +0 -161
  212. package/workspace/public/pm/view-skills.js +0 -216
@@ -0,0 +1,271 @@
1
+ 'use strict';
2
+ /* plan-items-stage.js — the stage of each plan item, and the Build rule, for the workflow engine (pm-os-absorb Run 4,
3
+ * PRD R6, map-spec X29).
4
+ *
5
+ * foldStages(text) → { items: { [id]: { initiative, stage } }, withdrawn: [id…] }
6
+ * readFactory(text) → { items: { [workItemId]: { initiative, plan_item, integrated, withdrawn } } }
7
+ * mainTree(root) → the main working tree of root's repository (root itself when it is not linked)
8
+ * buildRule({ planText, workText, initiative })
9
+ * → { applies, materialized: [id…], integrated: [id…], pending: [id…] }
10
+ * buildRuleFor(root, id) → the same, read from the repository's two ledgers; { applies: false } when neither
11
+ * file is there
12
+ * planItemsPath(root) · workItemsPath(root)
13
+ *
14
+ * THE BUILD RULE (R6). Items never complete a stage, with one exception: a code initiative's Build stage is done when
15
+ * every MATERIALIZED item under it is integrated. A materialized item is a work item whose `declared` line names a
16
+ * plan item (`plan_item`, D86 point 1) that sits in the Build stage of the same initiative and is not withdrawn. A
17
+ * work item that is withdrawn in the factory ledger is not counted. When an initiative has no materialized item under
18
+ * Build, the rule does not apply and the engine decides the Build step from the commits, as before.
19
+ *
20
+ * WHY THIS FILE EXISTS (X29). The engine (scripts/workflow-state.js) is vendored into the workspace bundle and into
21
+ * the kit, so it cannot require workspace/lib/plan-items.js. This module reads the same ledger with a small pure fold
22
+ * of its own. workspace/plan-items-stage-parity.test.js holds it to plan-items.js's fold (stage, withdrawn) and to
23
+ * scripts/work-item.js's fold (integrated, withdrawn) on every fixture, so a rule added to one fold and not the
24
+ * other fails a test instead of making CI and the workspace disagree.
25
+ *
26
+ * DELIBERATELY FLAT in scripts/, not scripts/lib/ (read-jsonl.js has the same note): the kit and the workspace bundle
27
+ * vendor the engine's require closure by BASENAME into one directory, so a `./lib/` require from the engine would
28
+ * load in this checkout and break in every vendored copy.
29
+ *
30
+ * The factory half is D65's ORDER, restated small: lines sorted by instant (ledger order breaks a tie), the type's
31
+ * chain (scripts/work-item.js CHAIN, chainFor), and a two-outcome node satisfied by its LATEST outcome (failed revokes
32
+ * verified, released revokes claimed). A line that skips its predecessor is not counted, the same as deriveItems
33
+ * discards it, so a hand-appended `integrated` with no `verified` before it never makes the Build step done. It does
34
+ * not restate the per-field schema: scripts/check-work-items.js fails CI on a schema-invalid line. Restated, not
35
+ * required, because work-item.js cannot be vendored (its sink guard requires ./lib/sink.js); the parity test holds the
36
+ * two folds to one answer, on valid and on invalid ledgers.
37
+ *
38
+ * BOTH LEDGERS ARE READ FROM THE MAIN WORKING TREE, as lib/plan-items.js, lib/plan-ledgers.js and lib/factory-join.js
39
+ * read them. From a linked worktree (where every factory agent works) the engine, check-work-items and the workspace
40
+ * then read the same two files. mainTree is the filesystem-only walk of lib/plan-tree.js mainTree, restated here.
41
+ *
42
+ * Pure apart from the two file reads in buildRuleFor. No network, no git, no clock. Zero dependencies, stock Node.
43
+ */
44
+ const fs = require('fs');
45
+ const path = require('path');
46
+
47
+ // ── the plan-items schema, as workspace/lib/plan-items.js lineErr states it ──────────────────────────────────────
48
+ // Every line that lib/plan-items.js ignores must be ignored here too, or the two folds disagree about which line of
49
+ // a repeated event id wins. So the whole stored-line schema is restated, not only the stage fields.
50
+ const EVENTS = ['planned', 'set', 'moved', 'flagged', 'withdrawn', 'kept'];
51
+ const STATES = ['todo', 'doing', 'review', 'done'];
52
+ const SET_FIELDS = ['title', 'stage', 'order', 'owner', 'after', 'start', 'due', 'milestone', 'note'];
53
+ const EVIDENCE_KINDS = ['commit', 'pr', 'file', 'session', 'note'];
54
+ const ID_RE = /^(.+)\.([0-9a-z]{10})$/;
55
+ const INIT_RE = /^[A-Za-z0-9][\w.-]{0,119}$/;
56
+ const EID_RE = /^[0-9a-z]{12}$/;
57
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
58
+ const AT_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
59
+ const BY_RE = /^(?:pm:[a-z0-9_-]{1,40}|agent:unknown|agent:sess-\d+\.[0-9a-f]{8})$/;
60
+
61
+ const isStr = (v) => typeof v === 'string';
62
+ const oneLine = (v, max) => isStr(v) && v.trim().length >= 1 && v.length <= max && !/[\r\n]/.test(v);
63
+ const initiativeOf = (id) => { const m = ID_RE.exec(String(id || '')); return m ? m[1] : null; };
64
+ function ownerOk(v) {
65
+ if (v === 'you' || v === 'agent') return true;
66
+ const m = /^(person|tracker):(.+)$/s.exec(String(v));
67
+ return !!m && m[2].length >= 1 && m[2].length <= 60 && !/[\r\n]/.test(m[2]);
68
+ }
69
+ const dateOk = (v) => v === null || (isStr(v) && DATE_RE.test(v) && (() => {
70
+ const t = Date.parse(v + 'T00:00:00Z');
71
+ return Number.isFinite(t) && new Date(t).toISOString().slice(0, 10) === v;
72
+ })());
73
+ function evidenceBad(e) {
74
+ if (!e || typeof e !== 'object' || Array.isArray(e) || !EVIDENCE_KINDS.includes(e.kind) || !isStr(e.ref)) return true;
75
+ const ref = e.ref;
76
+ if (e.kind === 'commit') return !/^[0-9a-f]{7,40}$/i.test(ref);
77
+ if (e.kind === 'pr') return !/^#?\d+$/.test(ref);
78
+ if (e.kind === 'file') return !ref || ref.length > 300 || path.isAbsolute(ref) || ref.split(/[\\/]/).includes('..') || /[\r\n]/.test(ref);
79
+ if (e.kind === 'session') return !/^sess-\d+$/.test(ref);
80
+ return !oneLine(ref, 200);
81
+ }
82
+ function fieldBad(k, v) {
83
+ switch (k) {
84
+ case 'title': return !oneLine(v, 200);
85
+ case 'stage': return !(isStr(v) && v.trim());
86
+ case 'order': return !(typeof v === 'number' && Number.isFinite(v));
87
+ case 'owner': return !ownerOk(v);
88
+ case 'after': return !(Array.isArray(v) && v.every((x) => isStr(x) && ID_RE.test(x)));
89
+ case 'start': case 'due': return !dateOk(v);
90
+ case 'milestone': return typeof v !== 'boolean';
91
+ case 'note': return !(v === null || (isStr(v) && v.length <= 1000));
92
+ default: return true;
93
+ }
94
+ }
95
+ /** true when lib/plan-items.js would ignore this stored line as schema-invalid. */
96
+ function lineBad(r) {
97
+ if (!r || typeof r !== 'object' || Array.isArray(r)) return true;
98
+ if (r.v !== 1 || !isStr(r.eid) || !EID_RE.test(r.eid) || !EVENTS.includes(r.ev)) return true;
99
+ if (!isStr(r.by) || !BY_RE.test(r.by) || (r.via !== 'ui' && r.via !== 'cli')) return true;
100
+ if (!isStr(r.at) || !AT_RE.test(r.at) || Number.isNaN(Date.parse(r.at))) return true;
101
+ if (!isStr(r.initiative) || !INIT_RE.test(r.initiative)) return true;
102
+ if (r.ev !== 'kept' && (!isStr(r.item) || !ID_RE.test(r.item) || initiativeOf(r.item) !== r.initiative)) return true;
103
+ switch (r.ev) {
104
+ case 'planned': return SET_FIELDS.some((k) => fieldBad(k, r[k]));
105
+ case 'set': {
106
+ const f = r.fields;
107
+ if (!f || typeof f !== 'object' || Array.isArray(f) || !Object.keys(f).length) return true;
108
+ return Object.keys(f).some((k) => !SET_FIELDS.includes(k)
109
+ || (!((k === 'start' || k === 'due' || k === 'note') && f[k] === null) && fieldBad(k, f[k])));
110
+ }
111
+ case 'moved':
112
+ if (!STATES.includes(r.to)) return true;
113
+ if (r.evidence !== undefined && evidenceBad(r.evidence)) return true;
114
+ if (r.override !== undefined && (r.override !== true || !String(r.by).startsWith('pm:'))) return true;
115
+ return false;
116
+ case 'flagged': return r.blocked === true ? !oneLine(r.reason, 200) : r.blocked !== false;
117
+ case 'withdrawn': return false;
118
+ case 'kept':
119
+ return r.item !== undefined || !isStr(r.batch) || !/^agent:/.test(r.batch)
120
+ || !Array.isArray(r.items) || !r.items.length || !r.items.every((x) => isStr(x) && ID_RE.test(x));
121
+ default: return true;
122
+ }
123
+ }
124
+
125
+ /**
126
+ * The plan-items ledger text → each live item's initiative and stage, and the withdrawn ids. The same order-free
127
+ * fold as lib/plan-items.js: drop byte-identical duplicates, sort by (at, eid, line), keep the first line of an event
128
+ * id, ignore a second `planned` of one id and every line after a withdraw.
129
+ */
130
+ function foldStages(text) {
131
+ const seenRaw = new Set();
132
+ const lines = [];
133
+ for (const raw0 of String(text == null ? '' : text).split('\n')) {
134
+ const raw = raw0.replace(/\r$/, '').trim();
135
+ if (!raw || seenRaw.has(raw)) continue;
136
+ let rec;
137
+ try { rec = JSON.parse(raw); } catch { continue; }
138
+ if (lineBad(rec)) continue;
139
+ seenRaw.add(raw);
140
+ lines.push({ raw, rec });
141
+ }
142
+ lines.sort((a, b) => (Date.parse(a.rec.at) - Date.parse(b.rec.at))
143
+ || (a.rec.eid < b.rec.eid ? -1 : a.rec.eid > b.rec.eid ? 1 : 0)
144
+ || (a.raw < b.raw ? -1 : a.raw > b.raw ? 1 : 0));
145
+ const seenEid = new Set();
146
+ const items = {};
147
+ const withdrawn = new Set();
148
+ for (const { rec } of lines) {
149
+ if (seenEid.has(rec.eid)) continue;
150
+ seenEid.add(rec.eid);
151
+ if (rec.ev === 'kept') continue;
152
+ if (rec.ev === 'planned') {
153
+ if (items[rec.item] || withdrawn.has(rec.item)) continue;
154
+ items[rec.item] = { initiative: rec.initiative, stage: rec.stage };
155
+ continue;
156
+ }
157
+ const it = items[rec.item];
158
+ if (!it || withdrawn.has(rec.item)) continue;
159
+ if (rec.ev === 'set' && Object.prototype.hasOwnProperty.call(rec.fields, 'stage')) it.stage = rec.fields.stage;
160
+ if (rec.ev === 'withdrawn') { delete items[rec.item]; withdrawn.add(rec.item); }
161
+ }
162
+ return { items, withdrawn: [...withdrawn].sort() };
163
+ }
164
+
165
+ /* D65(d)'s chain per type (scripts/work-item.js CHAIN, chainFor, NEGATED_BY, standsSatisfied), restated. */
166
+ const FACTORY_EVENTS = ['declared', 'claimed', 'released', 'verified', 'failed', 'integrated', 'shipped', 'withdrawn'];
167
+ const CHAIN_DEFAULT = ['claimed', 'verified', 'integrated', 'shipped'];
168
+ const CHAIN_HOTFIX = ['claimed', 'verified', 'shipped', 'integrated'];
169
+ const chainFor = (type) => (type === 'spike-item' ? CHAIN_DEFAULT.filter((e) => e !== 'verified') : type === 'hotfix' ? CHAIN_HOTFIX : CHAIN_DEFAULT);
170
+ const NEGATED_BY = { verified: 'failed', claimed: 'released' };
171
+ function standsSatisfied(history, need) {
172
+ const negator = NEGATED_BY[need];
173
+ if (!negator) return history.includes(need);
174
+ for (let i = history.length - 1; i >= 0; i -= 1) {
175
+ if (history[i] === need) return true;
176
+ if (history[i] === negator) return false;
177
+ }
178
+ return false;
179
+ }
180
+
181
+ /** The factory ledger text → per work item: its initiative, its plan item, and whether it is integrated or withdrawn. */
182
+ function readFactory(text) {
183
+ const lines = [];
184
+ String(text == null ? '' : text).split('\n').forEach((raw, idx) => {
185
+ if (!raw.trim()) return;
186
+ let rec;
187
+ try { rec = JSON.parse(raw); } catch { return; }
188
+ if (!rec || typeof rec !== 'object' || !isStr(rec.item_id) || !isStr(rec.initiative_id) || !FACTORY_EVENTS.includes(rec.event)) return;
189
+ const t = typeof rec.at === 'string' ? Date.parse(rec.at) : NaN;
190
+ if (Number.isNaN(t)) return;
191
+ lines.push({ rec, idx, t });
192
+ });
193
+ lines.sort((a, b) => a.t - b.t || a.idx - b.idx);
194
+ const items = {}; const fold = {};
195
+ for (const { rec } of lines) {
196
+ const id = rec.item_id;
197
+ if (rec.event === 'declared') {
198
+ if (items[id]) continue; // declared twice: the fold keeps the first
199
+ items[id] = { initiative: rec.initiative_id, plan_item: isStr(rec.plan_item) ? rec.plan_item : null, integrated: false, withdrawn: false };
200
+ fold[id] = { type: rec.type, history: ['declared'] };
201
+ continue;
202
+ }
203
+ const it = items[id];
204
+ if (!it || it.withdrawn) continue;
205
+ const chain = chainFor(fold[id].type);
206
+ const pos = chain.indexOf(rec.event === 'failed' ? 'verified' : rec.event);
207
+ if (pos > 0 && !standsSatisfied(fold[id].history, chain[pos - 1])) continue; // out of order: deriveItems discards it
208
+ fold[id].history.push(rec.event);
209
+ if (rec.event === 'integrated') it.integrated = true;
210
+ if (rec.event === 'withdrawn') it.withdrawn = true;
211
+ }
212
+ return { items };
213
+ }
214
+
215
+ /** The Build rule over the two ledgers' text, for one initiative. */
216
+ function buildRule({ planText, workText, initiative }) {
217
+ const plan = foldStages(planText);
218
+ const work = readFactory(workText);
219
+ const materialized = []; const integrated = []; const pending = [];
220
+ for (const [wid, w] of Object.entries(work.items)) {
221
+ if (w.initiative !== initiative || w.withdrawn || !w.plan_item) continue;
222
+ const p = plan.items[w.plan_item];
223
+ if (!p || p.initiative !== initiative || p.stage !== 'build') continue;
224
+ materialized.push(wid);
225
+ (w.integrated ? integrated : pending).push(wid);
226
+ }
227
+ const sort = (a) => a.sort();
228
+ return { applies: materialized.length > 0, materialized: sort(materialized), integrated: sort(integrated), pending: sort(pending) };
229
+ }
230
+
231
+ /** The main working tree of root's repository: root itself, unless root is a linked worktree. Filesystem only. */
232
+ function mainTree(root) {
233
+ try {
234
+ const dotgit = path.join(root, '.git');
235
+ if (fs.statSync(dotgit).isDirectory()) return root;
236
+ const m = /^gitdir:\s*(.+)$/m.exec(fs.readFileSync(dotgit, 'utf8'));
237
+ if (!m) return root;
238
+ const gitdir = path.resolve(root, m[1].trim());
239
+ const common = path.resolve(gitdir, fs.readFileSync(path.join(gitdir, 'commondir'), 'utf8').trim());
240
+ if (path.basename(common) !== '.git') return root;
241
+ const main = path.dirname(common);
242
+ return fs.statSync(path.join(main, '.git')).isDirectory() ? main : root;
243
+ } catch { return root; }
244
+ }
245
+
246
+ /** The plan-items ledger of a repository: planning/runs/ for PMOS-self, pmos/state/ in a kit (workflow-state layout). */
247
+ function planItemsPath(root) {
248
+ const main = mainTree(path.resolve(String(root)));
249
+ const self = path.join(main, 'planning', 'initiatives');
250
+ const kit = path.join(main, 'pmos', 'state', 'initiatives');
251
+ const isKit = !fs.existsSync(self) && fs.existsSync(kit);
252
+ return isKit ? path.join(main, 'pmos', 'state', 'plan-items.jsonl') : path.join(main, 'planning', 'runs', 'plan-items.jsonl');
253
+ }
254
+ /** The D65 factory ledger of a repository (the one scripts/check-work-items.js reads), in the main working tree. */
255
+ const workItemsPath = (root) => path.join(mainTree(path.resolve(String(root))), 'planning', 'work-items.jsonl');
256
+
257
+ function readText(file) {
258
+ try { return { ok: true, text: fs.readFileSync(file, 'utf8') }; }
259
+ catch (e) { return { ok: e && e.code === 'ENOENT', text: '', missing: true, error: e && e.code !== 'ENOENT' ? String(e.message || e) : null }; }
260
+ }
261
+
262
+ function buildRuleFor(root, initiative) {
263
+ const work = readText(workItemsPath(root));
264
+ if (work.missing && work.ok) return { applies: false, materialized: [], integrated: [], pending: [] };
265
+ if (!work.ok) return { applies: false, unknown: true, reason: `the factory ledger could not be read: ${work.error}`, materialized: [], integrated: [], pending: [] };
266
+ const plan = readText(planItemsPath(root));
267
+ if (!plan.ok) return { applies: false, unknown: true, reason: `the plan-items ledger could not be read: ${plan.error}`, materialized: [], integrated: [], pending: [] };
268
+ return buildRule({ planText: plan.text, workText: work.text, initiative });
269
+ }
270
+
271
+ module.exports = { foldStages, readFactory, buildRule, buildRuleFor, mainTree, planItemsPath, workItemsPath, lineBad };
@@ -151,7 +151,7 @@ case "$cmd" in
151
151
  nonempty note "$4"
152
152
  run_exists "$1" || fail "run_id '$1' is not in state/runs.jsonl — log the run first (pmos-log.sh run ...), then accept it."
153
153
  acc=true; [ "$3" = fail ] && acc=false
154
- append acceptances.jsonl "{\"run_id\":$(js "$1"),\"initiative_id\":$(js "$2"),\"accepted\":$acc,\"pm_label\":$(js "$3"),\"note\":$(js "${4:-}"),\"date\":\"$today\"}"
154
+ append acceptances.jsonl "{\"run_id\":$(js "$1"),\"initiative_id\":$(js "$2"),\"accepted\":$acc,\"pm_label\":$(js "$3"),\"note\":$(js "${4:-}"),\"date\":\"$today\",\"via\":\"cli\"}"
155
155
  ;;
156
156
  outcome)
157
157
  [ $# -ge 2 ] || fail "usage: outcome <initiative_id> <validated|refuted|inconclusive> [evidence]"
@@ -169,7 +169,7 @@ case "$cmd" in
169
169
  echo "✅ appended to state/discoveries.md: - $today $* #friction"
170
170
  ;;
171
171
  grant)
172
- [ $# -ge 3 ] || fail "usage: grant <merge:<PR or branch>|publish:<artifact>> <pm> <instruction> [ttl_minutes] [initiative_id]"
172
+ [ $# -ge 3 ] || fail "usage: grant <merge:<PR or branch>|publish:<artifact>|release:<initiative>:<batch-id>|lifecycle-bulk:<state>:<id>,…> <pm> <instruction> [ttl_minutes] [initiative_id]"
173
173
  nonempty pm "$2"; nonempty instruction "$3"
174
174
  row="$(python3 - "$1" "$2" "$3" "${4:-120}" "${5:-}" "$STATE" <<'PY'
175
175
  import datetime, json, os, re, secrets, sys
@@ -178,12 +178,23 @@ def die(m):
178
178
  sys.stderr.write("pmos-log: ERROR — %s\n" % m); sys.exit(1)
179
179
  if re.match(r"^(docs-sync|outward)(:|$)", scope):
180
180
  die('"%s" is a standing scope. Standing grants are not allowed in this release (D81). Mint one single-use grant per action.' % scope)
181
+ # The same scopes and target patterns as scripts/record-grant.js and the cockpit mod's grants.mjs (D81;
182
+ # D86 point 2 added release and lifecycle-bulk). scripts/tests/record-grant.test.js runs one table through all three.
183
+ SLUG = r"[a-z0-9][a-z0-9._-]{0,99}"
184
+ PATS = {
185
+ "merge": r"^(?:[0-9]{1,9}|[A-Za-z0-9][A-Za-z0-9._/-]{0,79})$",
186
+ "publish": r"^[A-Za-z0-9@][A-Za-z0-9@._/-]{0,99}$",
187
+ "release": r"^" + SLUG + r":[A-Za-z0-9][A-Za-z0-9._-]{0,63}$",
188
+ "lifecycle-bulk": r"^(?:active|closed|on-hold|cancelled):" + SLUG + r"(?:," + SLUG + r"){0,19}$",
189
+ }
190
+ WHAT = {"merge": "PR number or branch name", "publish": "artifact name", "release": "<initiative>:<batch-id>",
191
+ "lifecycle-bulk": "<state>:<id>,<id>,… (one of active, closed, on-hold, cancelled, then 1 to 20 initiative ids)"}
181
192
  kind, sep, target = scope.partition(":")
182
- if not sep or kind not in ("merge", "publish"):
183
- die('unknown scope "%s". Use merge:<PR number or branch> or publish:<artifact>.' % scope)
184
- pat = r"^(?:[0-9]{1,9}|[A-Za-z0-9][A-Za-z0-9._/-]{0,79})$" if kind == "merge" else r"^[A-Za-z0-9@][A-Za-z0-9@._/-]{0,99}$"
185
- if not re.match(pat, target) or "*" in target or ".." in target:
186
- die('"%s" is not a single %s. A grant names one target; a wildcard is refused.' % (target, "PR number or branch name" if kind == "merge" else "artifact name"))
193
+ if not sep or kind not in PATS:
194
+ die('unknown scope "%s". Use merge:<PR number or branch>, publish:<artifact>, release:<initiative>:<batch-id> or lifecycle-bulk:<state>:<id>,<id>,….' % scope)
195
+ ids = target.partition(":")[2].split(",") if kind == "lifecycle-bulk" else []
196
+ if not re.match(PATS[kind] + r"\Z", target) or "*" in target or ".." in target or len(set(ids)) != len(ids):
197
+ die('"%s" is not a single %s. A grant names one target; a wildcard is refused.' % (target, WHAT[kind]))
187
198
  if not re.match(r"^[0-9]{1,4}$", ttl) or not (1 <= int(ttl) <= 1440):
188
199
  die("ttl_minutes must be a whole number from 1 to 1440, got '%s'." % ttl)
189
200
  if initiative:
@@ -1067,8 +1067,24 @@ function computeWorkflowDerived(id, opts) {
1067
1067
  * commits in this range" is a statement about the RANGE, and on a branch level with `main` that
1068
1068
  * range is legitimately empty. A reader who cannot tell those apart calls the second one "never
1069
1069
  * built", which is the console's half of this defect.
1070
+ *
1071
+ * THE BUILD RULE (PRD R6, pm-os-absorb Run 4). Items never complete a stage, with one exception: when plan items
1072
+ * under Build were materialized (a D65 `declared` line names them as `plan_item`, D86 point 1), the step is done
1073
+ * when every one of those work items is integrated, and pending until then, whatever the commits say. With no
1074
+ * materialized item the commits decide, as above. The rule reads both ledgers through plan-items-stage.js, the
1075
+ * engine's own pure fold (X29: the engine cannot require workspace/lib). A broken delivered_by stays blocked first.
1070
1076
  */
1071
- steps.push(build.unknown
1077
+ const buildRule = require('./plan-items-stage').buildRuleFor(root, id);
1078
+ const ruleStep = build.failedDeclaration || !(buildRule.applies || buildRule.unknown) ? null
1079
+ : buildRule.unknown
1080
+ ? step('build', 'build', 'unknown', buildRule.reason)
1081
+ : buildRule.pending.length === 0
1082
+ ? step('build', 'build', 'done',
1083
+ `every materialized item under Build is integrated (${buildRule.integrated.length} of ${buildRule.materialized.length} in planning/work-items.jsonl)`)
1084
+ : step('build', 'build', 'pending',
1085
+ `${buildRule.integrated.length} of ${buildRule.materialized.length} materialized item(s) under Build integrated — waiting on ${buildRule.pending.join(', ')}`,
1086
+ 'merge each work item with a `Work-Item: <id>` trailer on the trunk, then run `pmos verify-work`');
1087
+ steps.push(ruleStep || (build.unknown
1072
1088
  ? step('build', 'build', 'unknown', build.reason || range.reason)
1073
1089
  : build.failedDeclaration
1074
1090
  // REPORTED, never CI-blocking — the same stance R1 takes on an unresolvable anchor. Making a
@@ -1087,7 +1103,7 @@ function computeWorkflowDerived(id, opts) {
1087
1103
  : 'no implementation commits in this range')
1088
1104
  : step('build', 'build', 'done', build.signal
1089
1105
  ? `${build.count} commit(s) on implementation paths — ${delivery.attributionEvidence(build.signal, id, build.declaredSha)}`
1090
- : `${build.count} commit(s) on implementation paths`));
1106
+ : `${build.count} commit(s) on implementation paths`)));
1091
1107
 
1092
1108
  // ── quality ─ CI's verdict, never this engine's ──────────────────────────────────────────────
1093
1109
  steps.push(step('quality', 'quality', 'unknown', 'CI decides on the PR — this engine never claims a test result it did not run'));
@@ -1325,9 +1341,19 @@ function pmLadder({ id, fm, lane, effLane, knownLane, legacy, steps, root, L, re
1325
1341
  const accepted = cachedJsonl(path.join(L.runsDir, 'acceptances.jsonl'))
1326
1342
  .filter((a) => a && a.initiative_id === id && a.accepted === true);
1327
1343
  const acceptedOn = accepted.length ? (accepted[accepted.length - 1].accepted_at || accepted[accepted.length - 1].at) : null;
1344
+ // D86 point 3 — a report is approved when the PM issues it: an `issued` line in issues.jsonl naming its doc_path.
1345
+ // Its own minimal parse (X29: the vendored engine never requires workspace/lib); a line counts only if the PM wrote it.
1346
+ const norm = (p) => String(p || '').trim().replace(/^\.\//, '');
1347
+ const issued = effLane !== 'report' || !docPath ? []
1348
+ : cachedJsonl(path.join(L.runsDir, 'issues.jsonl')).filter((r) => r && r.ev === 'issued' && norm(r.path) === norm(docPath)
1349
+ && /^pm:/.test(String(r.by || '')) && (r.via === 'ui' || r.via === 'cli') && /^[0-9a-f]{40}$/.test(String(r.sha || '')));
1328
1350
  steps.push(!flows('approved') ? skipped('approved', 'approved')
1351
+ : issued.length
1352
+ ? step('approved', 'approved', 'done', `issued by the PM on ${String(issued[0].at || '').slice(0, 10)} (issues.jsonl)`)
1329
1353
  : accepted.length
1330
1354
  ? step('approved', 'approved', 'done', `accepted by the PM${acceptedOn ? ' on ' + String(acceptedOn).slice(0, 10) : ''}`)
1355
+ : effLane === 'report'
1356
+ ? step('approved', 'approved', 'pending', 'awaiting the PM\'s Issue (D86 point 3)', 'the PM issues the report (pmos report issue, or Issue on Reports) — never automatic')
1331
1357
  : step('approved', 'approved', 'pending', 'awaiting the PM\'s acceptance (D12)', 'the PM accepts the document — never automatic'));
1332
1358
 
1333
1359
  if (!flows('handoff')) steps.push(step('handoff', 'handed off', 'na', `${effLane} — nothing to hand off`));
@@ -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-10-05T04:02:12Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-06T00:08:33Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  Newest first, ISO dates.
4
4
 
5
- ## 2026-10-05
5
+ ## 2026-10-06
6
6
 
7
7
  - Adopted OKF v0.2 (D73).
@@ -406,6 +406,18 @@ function doctor() {
406
406
  // Reads tracked .md files straight from disk (lib/kg-cli.js); needs no running server.
407
407
  code = require('../lib/kg-cli').run(process.argv.slice(2), { say });
408
408
  }
409
+ else if (cmd === 'item') {
410
+ // An initiative's breakdown items (pm-os-absorb Run 1): the same writer and fold as the workspace page,
411
+ // straight from disk, no running server. The write is attributed from this terminal, never from an argument.
412
+ code = await require('../lib/item-cli.js').run(process.argv.slice(2), { say });
413
+ await new Promise((r) => process.stdout.write('', r)); // drain a long --json before process.exit below
414
+ }
415
+ else if (require('../lib/pmos-verbs.js').has(cmd)) {
416
+ // pm-os-absorb Runs 2–5: one module per verb (lib/pmos-verbs.js). A verb whose run has not built it says so.
417
+ code = await require('../lib/pmos-verbs.js').run(cmd, process.argv.slice(2), {
418
+ say, call: async (m, p, b) => { const live = await discover(); return live.length ? api(live[0].port, m, p, b) : null; } });
419
+ await new Promise((r) => process.stdout.write('', r));
420
+ }
409
421
  else if (cmd === 'upgrade') {
410
422
  // Escape hatch: pull the latest bundled app and force-reinstall over this global copy. Delegates
411
423
  // to the scaffolder (which owns the install path) rather than reinstalling itself in place.
@@ -417,13 +429,15 @@ function doctor() {
417
429
  if (r.error) { say('✗ could not run ' + npx + ' — ' + r.error.message); code = 1; }
418
430
  else code = r.status === null ? 1 : r.status;
419
431
  } else if (cmd === 'help' || cmd === '--help' || cmd === '-h') {
420
- say('usage: pmos [<path>|status|ls|stop|doctor|upgrade|schedule|skill|proactive|kg]');
432
+ say('usage: pmos [<path>|status|ls|stop|doctor|upgrade|schedule|skill|proactive|kg|item|' + require('../lib/pmos-verbs.js').names().join('|') + ']');
421
433
  say(' pmos open the current repo as a workspace (starts the server if needed)');
422
434
  say(' pmos <path> open another repo as a workspace');
423
435
  say(' pmos schedule … create, edit and run scheduled tasks (pmos schedule --help)');
424
436
  say(' pmos skill … list, read, create and edit skills');
425
437
  say(' pmos proactive … what is waiting for you, feedback, settings (pmos proactive --help)');
426
438
  say(' pmos kg … find a card, a section or a decision\'s citers without reading whole files (pmos kg --help)');
439
+ say(' pmos item add|set|move|withdraw|list — an initiative\'s breakdown items (pmos item help)');
440
+ for (const line of require('../lib/pmos-verbs.js').helpLines()) say(line);
427
441
  say(' pmos upgrade reinstall the workspace app from the latest published create-pmos');
428
442
  code = 0;
429
443
  } else if (cmd === 'up' || cmd === 'start' || cmd === 'open') {
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+ /* PMOS workspace — the suites whose subject R29 cut (pm-os-absorb Run 3, slice 3D).
3
+ *
4
+ * The All repos, Knowledge, Memory, Skills and Scheduled views, and the Reports tab, are gone from the shell. The suites that
5
+ * drew them in a browser (pm-r29-portfolio, -knowledge, -memory, -skills-scheduled, -reports-addrepo) have nothing to draw.
6
+ * Each keeps its file and its name, and asserts what is left of its subject: the view is not in the table, its module is not
7
+ * on disk, and the thing that replaced it is still there. Every removed assertion is in workspace/replaced-tests.json
8
+ * (C03 to C11). No browser and no server: these are reads of the sources, so they run in milliseconds.
9
+ */
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ const PM = path.join(__dirname, 'public', 'pm');
14
+ const read = (f) => { try { return fs.readFileSync(path.join(PM, f), 'utf8'); } catch { return null; } };
15
+ const gone = (f) => !fs.existsSync(path.join(PM, f));
16
+ /** The keys of `export const VIEWS = { … }` in panel-cockpit.js, in order. */
17
+ const viewKeys = () => {
18
+ const m = /export const VIEWS = \{([\s\S]*?)\n\};/.exec(read('panel-cockpit.js') || '');
19
+ return m ? [...m[1].matchAll(/^ {2}(\w+):/gm)].map((x) => x[1]) : [];
20
+ };
21
+ /** The keys of `BOARD_MODULES = { … }` in panel-cockpit.js. */
22
+ const boardKeys = () => {
23
+ const m = /BOARD_MODULES = \{([\s\S]*?)\};/.exec(read('panel-cockpit.js') || '');
24
+ return m ? [...m[1].matchAll(/(\w+):\s*'\.\/view-/g)].map((x) => x[1]) : [];
25
+ };
26
+
27
+ function suite(label, cases) {
28
+ const results = [];
29
+ for (const [name, fn] of cases) {
30
+ let cond = false; let extra = '';
31
+ try { const r = fn(); cond = r === true || (r && r.cond === true); extra = r && r.extra ? r.extra : ''; } catch (e) { extra = String((e && e.message) || e); }
32
+ results.push(cond);
33
+ console.log(`${cond ? '✓' : '✗'} ${name}${extra ? ' — ' + extra : ''}`);
34
+ }
35
+ const bad = results.filter((x) => !x).length;
36
+ console.log(`\n${results.length - bad}/${results.length} ${label} assertions passed`);
37
+ process.exit(bad ? 1 : 0);
38
+ }
39
+
40
+ module.exports = { suite, read, gone, viewKeys, boardKeys, PM };
@@ -0,0 +1,145 @@
1
+ 'use strict';
2
+ /* first-paint-audit.js — the first-paint instrument, shared by every first-paint suite (pm-os-absorb seams).
3
+ *
4
+ * Not a suite: first-paint-count.test.js (the Breakdown, Run 1) and each destination's first-paint suite (Initiatives
5
+ * 2D, Today 3B, Board 4D, Reports 5C) require it, so every surface is counted with ONE instrument: shoot.js's audit(),
6
+ * the one the PM's numbers came from. A "control" is a visible button, link, input, select, textarea, [role=button] or
7
+ * [draggable=true] inside the viewport on first paint.
8
+ *
9
+ * EXPECT PRD Q5's budgets at 1280×800, counted outside the dock and the terminal
10
+ * audit(phone) shoot.js's audit, verbatim; runs in the page (page.evaluate(audit, false))
11
+ * countIn([scope, exclude]) the same selector and visibility test, inside `scope` and outside `exclude`; in the page
12
+ * stableCount([scope, exclude, minus]) countIn once the screen is still (two animation frames apart); in the page,
13
+ * after installCounter(page)
14
+ * installCounter(page) the init script stableCount needs (window.__countIn); call it before page.goto
15
+ *
16
+ * Do not tune the selector or the visibility test for one surface: change them here, for all, or not at all.
17
+ */
18
+
19
+ const EXPECT = Object.freeze({ today: 17, initiatives: 24, board: 33, reports: 14 });
20
+
21
+ /* ── shoot.js audit(), copied verbatim (scratchpad/specimens2/shoot.js, 2026-10-05) ─────────────────────────────── */
22
+ // runs in the page
23
+ function audit(phone) {
24
+ const SEL = 'button, a[href], a[role], input:not([type="hidden"]), select, textarea, [role="button"], [draggable="true"]';
25
+ const vw = window.innerWidth;
26
+ const vh = window.innerHeight;
27
+ const visible = (el) => {
28
+ if (el.closest("dialog:not([open])")) return false;
29
+ const pop = el.closest("[popover]");
30
+ if (pop && !pop.matches(":popover-open")) return false;
31
+ const r = el.getBoundingClientRect();
32
+ if (r.width < 1 || r.height < 1) return false;
33
+ for (let n = el; n && n.nodeType === 1; n = n.parentElement) {
34
+ const cs = getComputedStyle(n);
35
+ if (cs.display === "none" || cs.visibility === "hidden" || Number(cs.opacity) === 0) return false;
36
+ }
37
+ return r.bottom > 0 && r.right > 0 && r.top < vh && r.left < vw;
38
+ };
39
+ const describe = (el) => {
40
+ const t = (el.getAttribute("aria-label") || el.textContent || el.value || "").trim().replace(/\s+/g, " ");
41
+ const r = el.getBoundingClientRect();
42
+ return `${el.tagName.toLowerCase()}${el.className && typeof el.className === "string" ? "." + el.className.trim().split(/\s+/).slice(0, 2).join(".") : ""} "${t.slice(0, 28)}" ${Math.round(r.width)}x${Math.round(r.height)}`;
43
+ };
44
+ const all = [...document.querySelectorAll(SEL)].filter(visible);
45
+ const notBar = all.filter((el) => !el.closest(".specbar"));
46
+ const small = phone
47
+ ? notBar.filter((el) => {
48
+ const r = el.getBoundingClientRect();
49
+ // inline text links inside prose are exempt from the 44px rule
50
+ if (el.tagName === "A" && !el.className && getComputedStyle(el).display === "inline") return false;
51
+ return r.width < 43.5 || r.height < 43.5;
52
+ })
53
+ : [];
54
+ const sw = document.documentElement.scrollWidth;
55
+ const offenders = [];
56
+ if (sw > vw) {
57
+ for (const el of document.querySelectorAll("body *")) {
58
+ const r = el.getBoundingClientRect();
59
+ if (r.right > vw + 0.5 && r.width > 0) {
60
+ let clipped = false;
61
+ for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) {
62
+ const o = getComputedStyle(p).overflowX;
63
+ if (o === "auto" || o === "scroll" || o === "hidden" || o === "clip") {
64
+ clipped = true;
65
+ break;
66
+ }
67
+ }
68
+ if (!clipped) offenders.push({ el: describe(el), right: Math.round(r.right) });
69
+ }
70
+ }
71
+ offenders.sort((a, b) => b.right - a.right);
72
+ }
73
+ return {
74
+ title: document.title,
75
+ controlsInViewport: all.length,
76
+ controlsExcludingSpecbar: notBar.length,
77
+ smallTargets: small.length,
78
+ smallTargetExamples: small.slice(0, 8).map(describe),
79
+ scrollWidth: sw,
80
+ innerWidth: vw,
81
+ horizontalOverflow: sw > vw,
82
+ overflowOffenders: offenders.slice(0, 6),
83
+ pageHeight: document.documentElement.scrollHeight
84
+ };
85
+ }
86
+
87
+ /**
88
+ * The same selector and the same visibility test as audit(), counted inside `scope` and outside every `exclude`.
89
+ * Runs in the page. Returns { n, names }.
90
+ */
91
+ function countIn([scope, exclude]) {
92
+ const SEL = 'button, a[href], a[role], input:not([type="hidden"]), select, textarea, [role="button"], [draggable="true"]';
93
+ const vw = window.innerWidth;
94
+ const vh = window.innerHeight;
95
+ const visible = (el) => {
96
+ if (el.closest("dialog:not([open])")) return false;
97
+ const pop = el.closest("[popover]");
98
+ if (pop && !pop.matches(":popover-open")) return false;
99
+ const r = el.getBoundingClientRect();
100
+ if (r.width < 1 || r.height < 1) return false;
101
+ for (let n = el; n && n.nodeType === 1; n = n.parentElement) {
102
+ const cs = getComputedStyle(n);
103
+ if (cs.display === "none" || cs.visibility === "hidden" || Number(cs.opacity) === 0) return false;
104
+ }
105
+ return r.bottom > 0 && r.right > 0 && r.top < vh && r.left < vw;
106
+ };
107
+ const roots = scope ? [...document.querySelectorAll(scope)] : [document];
108
+ const seen = new Set();
109
+ for (const root of roots) for (const el of root.querySelectorAll(SEL)) {
110
+ if (seen.has(el) || !visible(el)) continue;
111
+ if (exclude && el.closest(exclude)) continue;
112
+ seen.add(el);
113
+ }
114
+ const names = [...seen].map((el) => `${el.tagName.toLowerCase()} "${(el.getAttribute('aria-label') || el.textContent || '').trim().replace(/\s+/g, ' ').slice(0, 24)}"`);
115
+ return { n: seen.size, names };
116
+ }
117
+
118
+ /**
119
+ * countIn, but only once the screen is still: the count of `scope` minus `exclude` must be the same two animation
120
+ * frames apart (up to 60 tries). With `minus`, the controls inside `minus` are counted out in the SAME task, so the two
121
+ * numbers of a difference come from one paint. Runs in the page; needs window.__countIn (an init script).
122
+ */
123
+ async function stableCount([scope, exclude, minus]) {
124
+ const frame = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
125
+ const both = () => {
126
+ const a = window.__countIn([scope, exclude]);
127
+ const b = minus ? window.__countIn([scope, exclude ? exclude + ', ' + minus : minus]) : null;
128
+ return { n: a.n, names: a.names, without: b ? b.n : null };
129
+ };
130
+ let prev = both();
131
+ for (let k = 0; k < 60; k++) {
132
+ await frame();
133
+ const cur = both();
134
+ if (cur.n === prev.n && cur.without === prev.without) return { ...cur, still: true, tries: k + 1 };
135
+ prev = cur;
136
+ }
137
+ return { ...prev, still: false, tries: 60 };
138
+ }
139
+
140
+ /** Add the init script that stableCount calls. Call it once per page, before the first goto. */
141
+ function installCounter(page) {
142
+ return page.addInitScript({ content: 'window.__countIn = ' + countIn.toString() + ';' });
143
+ }
144
+
145
+ module.exports = { EXPECT, audit, countIn, stableCount, installCounter };
@@ -0,0 +1,10 @@
1
+ ---
2
+ type: Reference
3
+ title: "Capture 2026-10-04 1"
4
+ timestamp: 2026-10-04T08:12:00Z
5
+ source: capture
6
+ by: pm:wawan
7
+ synthetic: true
8
+ ---
9
+
10
+ Partner admins want to export the audit log as CSV before the quarterly review.