create-pmos 0.799.0 → 0.800.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.799.0",
3
+ "version": "0.800.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -34,27 +34,40 @@
34
34
  ],
35
35
  "pmosChanges": [
36
36
  {
37
- "v": "0.799.0",
38
- "at": "2026-11-25T00:01:31.314Z",
37
+ "v": "0.800.0",
38
+ "at": "2026-11-25T01:39:46.319Z",
39
39
  "f": 4,
40
40
  "prs": [
41
41
  {
42
- "n": 1824,
43
- "t": "Drafting the goal keeps the initiative page; one toast for one draft press",
44
- "s": "Drafting the goal keeps the initiative page; one toast for one draft press",
45
- "k": "fix",
42
+ "n": 1825,
43
+ "t": "Today, Work and an initiative open within 200 ms",
44
+ "s": "Today, Work and an initiative open within 200 ms",
45
+ "k": "imp",
46
46
  "try": {
47
47
  "steps": [
48
- "On a phone, open Work and tap an initiative whose Problem or Goal is not written.",
49
- "In Where it stands, tap the ✦ Draft the Problem and Goal line.",
50
- "Wait for the drafts, then press Undo on the toast."
48
+ "Open Today, then Work, then an initiative from Work.",
49
+ "Change something on the initiative (a task title), wait a second, then open Work again.",
50
+ "Open the same initiative again."
51
51
  ],
52
- "see": "the page stays on the initiative's work while PMOS drafts; one toast says 'Problem and Goal drafted.' and Undo takes both lines back. If the Dashboard is your chosen view, its list icon in the…",
52
+ "see": "each page shows its rows at once, in about the blink of an eye; the change you made shows on Work and on the initiative.",
53
53
  "open": "/premium-board.html"
54
54
  }
55
55
  }
56
56
  ]
57
57
  },
58
+ {
59
+ "v": "0.799.0",
60
+ "at": "2026-11-25T00:01:31.314Z",
61
+ "f": 4,
62
+ "prs": [
63
+ {
64
+ "n": 1824,
65
+ "t": "Drafting the goal keeps the initiative page; one toast for one draft press",
66
+ "s": "Drafting the goal keeps the initiative page; one toast for one draft press",
67
+ "k": "fix"
68
+ }
69
+ ]
70
+ },
58
71
  {
59
72
  "v": "0.798.0",
60
73
  "at": "2026-11-24T23:17:36.353Z",
@@ -451,19 +464,6 @@
451
464
  "k": "new"
452
465
  }
453
466
  ]
454
- },
455
- {
456
- "v": "0.780.0",
457
- "at": "2026-11-24T15:38:49.543Z",
458
- "f": 4,
459
- "prs": [
460
- {
461
- "n": 1754,
462
- "t": "The strategy draft speaks for the whole product; Positioning folds to one line",
463
- "s": "The strategy draft speaks for the whole product; Positioning folds to one line",
464
- "k": "new"
465
- }
466
- ]
467
467
  }
468
468
  ]
469
469
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@5ab2efffc
1
+ kernel-source: pmos@6cd2bca37
2
2
  assembled: 2026-11-25
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-25T00:01:27Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T01:39:43Z"}
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-25T00:01:27Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T01:39:43Z"}
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-25T00:01:27Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-25T01:39:43Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,26 +1,39 @@
1
1
  [
2
2
  {
3
- "v": "0.799.0",
4
- "at": "2026-11-25T00:01:31.314Z",
3
+ "v": "0.800.0",
4
+ "at": "2026-11-25T01:39:46.319Z",
5
5
  "f": 4,
6
6
  "prs": [
7
7
  {
8
- "n": 1824,
9
- "t": "Drafting the goal keeps the initiative page; one toast for one draft press",
10
- "s": "Drafting the goal keeps the initiative page; one toast for one draft press",
11
- "k": "fix",
8
+ "n": 1825,
9
+ "t": "Today, Work and an initiative open within 200 ms",
10
+ "s": "Today, Work and an initiative open within 200 ms",
11
+ "k": "imp",
12
12
  "try": {
13
13
  "steps": [
14
- "On a phone, open Work and tap an initiative whose Problem or Goal is not written.",
15
- "In Where it stands, tap the ✦ Draft the Problem and Goal line.",
16
- "Wait for the drafts, then press Undo on the toast."
14
+ "Open Today, then Work, then an initiative from Work.",
15
+ "Change something on the initiative (a task title), wait a second, then open Work again.",
16
+ "Open the same initiative again."
17
17
  ],
18
- "see": "the page stays on the initiative's work while PMOS drafts; one toast says 'Problem and Goal drafted.' and Undo takes both lines back. If the Dashboard is your chosen view, its list icon in the…",
18
+ "see": "each page shows its rows at once, in about the blink of an eye; the change you made shows on Work and on the initiative.",
19
19
  "open": "/premium-board.html"
20
20
  }
21
21
  }
22
22
  ]
23
23
  },
24
+ {
25
+ "v": "0.799.0",
26
+ "at": "2026-11-25T00:01:31.314Z",
27
+ "f": 4,
28
+ "prs": [
29
+ {
30
+ "n": 1824,
31
+ "t": "Drafting the goal keeps the initiative page; one toast for one draft press",
32
+ "s": "Drafting the goal keeps the initiative page; one toast for one draft press",
33
+ "k": "fix"
34
+ }
35
+ ]
36
+ },
24
37
  {
25
38
  "v": "0.798.0",
26
39
  "at": "2026-11-24T23:17:36.353Z",
@@ -503,6 +503,7 @@ A refresh waits for the sources it uses. The briefing waits for work assigned to
503
503
  - **One server runs the schedules.** When several PMOS servers run on one computer (for example an npm install and a checkout), only one of them runs the schedules and starts background runs; the others serve pages only. If that server stops, another one takes over within 3 minutes. A refresh you press runs on the server where you press it.
504
504
  - **Quiet start**: a server starts no background run in its first 5 minutes, so the first pages load quickly. A missed refresh catches up after that.
505
505
  - **Warm start**: 5 seconds after PMOS starts, it reads what Today and Work show once, so your first page opens as fast as later ones. This read writes nothing you would see as read or seen. `PMOS_WARM=off` turns it off.
506
+ - **Pages open from their last answer**: Today, Work and an initiative show the answer PMOS read last, while nothing changed since, and PMOS reads them again quietly when it is not busy. A change you, the chat or an agent make shows on the next open, also when it is written outside PMOS (PMOS watches the planning and pmos folders): the change makes every kept answer too old, and PMOS reads the newest pages again about a second later. Work also reads its first twelve initiatives ahead, so opening one from Work is fast too. A restart starts empty.
506
507
  - **Fresh answers, asked once**: when two parts of a page ask for the same thing at the same moment, the server is asked once and both get the same answer. Nothing is kept after it arrives, so the next look always reads again.
507
508
  - **Last view while Today reads**: Today shows the list from your last visit at once, with a hollow ring next to "Good morning". You can read that list, but you cannot use it until the new read is in. Then the ring goes away. Before a section has data, it shows grey shapes with no names and no counts. Each section fills in when its own data arrives. If the Viewer was open on your last visit, its space stays empty, so the chat does not change width. Adler's face next to the greeting thinks while Today reads, and changes to handled when the read is in. If the read fails, it changes to honest.
508
509
  - **Work while it reads**: the toolbar and the tabs show at once, with grey rows below them. If the read takes more than 2 seconds, the line "Still reading the board." shows. There is no progress bar and no percent.
@@ -0,0 +1,185 @@
1
+ 'use strict';
2
+ /* answer-cache.js — the slow reads a page opens on answer at once from their last answer, and are read again in the background
3
+ * (page-open-200ms, Wawan 2026-11-25: "Benchmark is to not exceed 200ms").
4
+ *
5
+ * The server answers one request at a time. On the PM's data a few reads took most of a second each (an initiative's page 1.4 s, its
6
+ * dashboard 0.9 s, Today's events 0.9 s) and every other read of the page queued behind them, so Today showed its first rows after
7
+ * 1.2 to 3.3 s. Each of these reads is the same answer for the same question until something is written.
8
+ *
9
+ * cacheable(pathname) → true for the routes on SLOW
10
+ * serve(req, res, url, ctx, run) → Promise<boolean> run(ctx2, res2) is the route's own handler; ctx2.json is watched for the answer
11
+ * bump(method, pathname) a write: every kept answer is too old to show from now on (the next read waits for a fresh one)
12
+ * idle() a request came in: the background reads wait until the server has had IDLE_MS with no request
13
+ * warm(url, run, ctx) read this answer in the background, once the server is idle, so its first open is fast too
14
+ * onKept(fn) fn(url, body, ctx) after each fresh answer is kept: route-modules warms what the page opens next from it
15
+ * watch(roots) watch each workspace's records for a write made outside the server (an agent's `pmos` command, an editor)
16
+ * stats() · reset() for the tests
17
+ *
18
+ * THE RULES
19
+ * - A kept answer is shown only when nothing was written since it was read (GEN). A write the PM makes (any POST, PUT, PATCH or
20
+ * DELETE but the few on QUIET that change no record), and the end of a chat turn (the page posts /api/answer-cache/drop), make
21
+ * every kept answer too old: the next read waits for a fresh one, as before. So an edit shows at once, and a chat write lands.
22
+ * The AGAIN_MAX answers kept last are then read again in the background once the server is idle, so the next open after a
23
+ * write is fast again within about a second.
24
+ * - A kept answer older than FRESH_MS is shown, and the route is read again in the background once the server is idle, so a change
25
+ * made outside the server (a Jira read, a file) shows on the next open. One background read at a time; the newest ask wins.
26
+ * - A write made outside the server counts as a write too: each workspace's planning/ and pmos/ folders are watched (watch), and
27
+ * any change in them makes every kept answer too old. A workspace whose folders cannot be watched keeps nothing at all.
28
+ * - A kept answer older than MAX_AGE_MS, or kept on another day, is not shown: the read waits, as before.
29
+ * - Only a 200 answer that is ready is kept: a "reading" (202), stale or pending answer, and an error, are never kept.
30
+ * Nothing is written to disk; a restart starts empty (lib/page-warm.js fills the common ones). */
31
+
32
+ const SLOW = new Set([
33
+ '/api/initiative-premium',
34
+ '/api/board-premium',
35
+ '/api/ready-reports/dashboard',
36
+ '/api/events-place',
37
+ '/api/board-trail',
38
+ '/api/onboard/state',
39
+ '/api/news-for-you',
40
+ ]);
41
+ // writes that change no record a SLOW route reads: the use log, a session's heartbeat, view preferences
42
+ const fs = require('fs');
43
+ const path = require('path');
44
+ const QUIET = [/^\/api\/use-log(\/|$)/, /^\/api\/card-log(\/|$)/, /^\/api\/session\/touch$/, /^\/api\/view-prefs$/, /^\/api\/next-prompt\/prefs$/, /^\/api\/draft-keep\/mark$/];
45
+ const FRESH_MS = 3000;
46
+ const MAX_AGE_MS = 30 * 60 * 1000;
47
+ const IDLE_MS = 600;
48
+ const AHEAD_IDLE_MS = 2000; // a read nobody asked for yet waits for a longer quiet: it may hold the next press for up to its own length
49
+ const MAX_KEYS = 200;
50
+ const AGAIN_MAX = 12; // kept answers read again after a write, newest first
51
+ const QUEUE_MAX = 40;
52
+
53
+ let GEN = 0;
54
+ // the background read answers nobody: a route that touches `res` itself finds a response that takes nothing
55
+ const DUMMY = { headersSent: false, setHeader() {}, getHeader() {}, writeHead() { return this; }, write() { return true; }, end() {}, on() {} };
56
+ const kept = new Map(); // key → { gen, day, at, body, again } again(): the background read of the same question
57
+ const queue = new Map(); // key → run(ctx2) for the background read
58
+ const ahead = new Map(); // key → run(ctx2) for a read ahead (warm): only when queue is empty and the server was quiet AHEAD_IDLE_MS
59
+ let lastReq = 0, timer = null, busy = false, follower = null;
60
+ const n = { hit: 0, miss: 0, kept: 0, again: 0, bumped: 0, warmed: 0, outside: 0 };
61
+
62
+ const dayOf = () => new Date().toDateString(); // an answer kept yesterday is never shown today (Today, Events)
63
+ const keyOf = (url) => {
64
+ const q = [...url.searchParams.entries()].filter(([k]) => k !== '_' && k !== 't').sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
65
+ return url.pathname + '?' + q.map(([k, v]) => k + '=' + v).join('&');
66
+ };
67
+ const ready = (code, body) => (code || 200) === 200 && body && typeof body === 'object' && body.ok !== false
68
+ && body.state !== 'reading' && body.state !== 'error' && !body.stale && !body.pending;
69
+
70
+ function cacheable(pathname) { return SLOW.has(pathname); }
71
+ function bump(method, pathname) {
72
+ const m = String(method || 'GET').toUpperCase();
73
+ if (m === 'GET' || m === 'HEAD' || m === 'OPTIONS') return false;
74
+ if (!String(pathname || '').startsWith('/api/')) return false;
75
+ if (QUIET.some((re) => re.test(pathname))) return false;
76
+ return drop();
77
+ }
78
+ /** Every kept answer is too old from now on; the newest are read again once the server is idle. */
79
+ function drop() {
80
+ GEN++; n.bumped++; queue.clear(); ahead.clear();
81
+ // the newest kept answers are read again once the server is idle; until then a read waits for its own fresh answer
82
+ const last = [...kept.entries()].slice(-AGAIN_MAX).reverse();
83
+ for (const [key, e] of last) if (e.again) queue.set(key, e.again);
84
+ schedule();
85
+ return true;
86
+ }
87
+ function idle() { lastReq = Date.now(); }
88
+
89
+ /* ── writes made outside the server ── an agent's `pmos` command, a git checkout or an editor writes the records with no request to
90
+ * the server. The folders the records live in are watched: planning/ and pmos/ of each workspace, each with every folder under it, and
91
+ * the workspace folder itself (so a planning/ or pmos/ made later is watched from then on). .git and node_modules are never watched. */
92
+ const SKIP = /(^|[\\/])(\.git|node_modules)([\\/]|$)/;
93
+ const watched = new Map(); // folder → FSWatcher | 'none' (not there) | 'blind' (there, but it cannot be watched)
94
+ let blind = false;
95
+ function watchDir(dir, recursive) {
96
+ if (watched.has(dir) && watched.get(dir) !== 'none') return;
97
+ let there = false; try { there = fs.statSync(dir).isDirectory(); } catch { there = false; }
98
+ if (!there) { watched.set(dir, 'none'); return; }
99
+ try {
100
+ const w = fs.watch(dir, { recursive, persistent: false }, (ev, f) => {
101
+ if (f && SKIP.test(String(f))) return;
102
+ n.outside++; drop();
103
+ if (!recursive && (f === 'planning' || f === 'pmos')) watchDir(path.join(dir, f), true);
104
+ });
105
+ w.on('error', () => { try { w.close(); } catch { /* closed */ } watched.set(dir, 'blind'); blind = true; drop(); });
106
+ watched.set(dir, w);
107
+ } catch { watched.set(dir, 'blind'); blind = true; }
108
+ }
109
+ function watch(roots) {
110
+ for (const root of roots || []) {
111
+ if (!root || typeof root !== 'string') continue;
112
+ watchDir(root, false);
113
+ watchDir(path.join(root, 'planning'), true);
114
+ watchDir(path.join(root, 'pmos'), true);
115
+ }
116
+ return !blind;
117
+ }
118
+
119
+ function keep(key, gen, body, again, url, ctx) {
120
+ if (gen !== GEN) return; // a write landed while it was read: this answer may already be old
121
+ kept.delete(key); kept.set(key, { gen, day: dayOf(), at: Date.now(), body, again }); n.kept++;
122
+ while (kept.size > MAX_KEYS) kept.delete(kept.keys().next().value);
123
+ if (follower && url) { try { follower(url, body, ctx); } catch { /* a warm-up is never needed for the answer */ } }
124
+ }
125
+ const fresh = (e) => !!e && e.gen === GEN && e.day === dayOf() && Date.now() - e.at < MAX_AGE_MS;
126
+ function warm(url, run, ctx) {
127
+ const key = keyOf(url);
128
+ if (fresh(kept.get(key)) || queue.has(key) || ahead.has(key) || ahead.size >= QUEUE_MAX) return false;
129
+ ahead.set(key, () => capture(run, ctx, null).catch(() => null));
130
+ n.warmed++;
131
+ schedule();
132
+ return true;
133
+ }
134
+ function onKept(fn) { follower = typeof fn === 'function' ? fn : null; }
135
+
136
+ /** Runs the route with ctx.json watched; the answer still goes to `res` when `res` is given. → { handled, code?, body? } */
137
+ async function capture(run, ctx, res, url) {
138
+ let got = null;
139
+ const ctx2 = Object.assign({}, ctx, { json: (r, obj, code) => { got = { code: code || 200, body: obj }; if (res) return ctx.json(res, obj, code); return undefined; } });
140
+ const handled = (await run(ctx2, res || DUMMY)) === true;
141
+ return { handled, url, ctx, ...(got || {}) };
142
+ }
143
+
144
+ function schedule() {
145
+ if (timer || busy || (!queue.size && !ahead.size)) return;
146
+ const need = queue.size ? IDLE_MS : AHEAD_IDLE_MS;
147
+ const wait = Math.max(0, need - (Date.now() - lastReq));
148
+ timer = setTimeout(async () => {
149
+ timer = null;
150
+ if (Date.now() - lastReq < (queue.size ? IDLE_MS : AHEAD_IDLE_MS)) { schedule(); return; }
151
+ const from = queue.size ? queue : ahead;
152
+ const [key, job] = from.entries().next().value; from.delete(key);
153
+ busy = true;
154
+ try { const gen = GEN, a = await job(); if (a && a.handled && ready(a.code, a.body)) { keep(key, gen, a.body, job, a.url, a.ctx); n.again++; } }
155
+ catch { /* the next open reads it in the foreground */ }
156
+ busy = false;
157
+ schedule();
158
+ }, wait);
159
+ if (timer.unref) timer.unref();
160
+ }
161
+
162
+ async function serve(req, res, url, ctx, run) {
163
+ if (blind) return (await capture(run, ctx, res, url)).handled; // a write outside the server could not be seen: keep nothing
164
+ // a write that landed just before this request is seen first: the watchers' events of this turn of the loop run before the check
165
+ if (kept.size) await new Promise((r) => setImmediate(r));
166
+ const key = keyOf(url), e = kept.get(key), now = Date.now();
167
+ const again = () => capture(run, ctx, null, url).catch(() => null);
168
+ if (fresh(e)) {
169
+ n.hit++;
170
+ ctx.json(res, e.body, 200);
171
+ if (now - e.at >= FRESH_MS) { queue.delete(key); queue.set(key, again); schedule(); }
172
+ return true;
173
+ }
174
+ n.miss++;
175
+ const gen = GEN;
176
+ const a = await capture(run, ctx, res, url);
177
+ if (!a.handled) return false;
178
+ if (a.body !== undefined && ready(a.code, a.body)) keep(key, gen, a.body, again, url, ctx);
179
+ return true;
180
+ }
181
+
182
+ function stats() { return { ...n, size: kept.size, gen: GEN, queued: queue.size, ahead: ahead.size }; }
183
+ function reset() { for (const w of watched.values()) if (w && typeof w === 'object') { try { w.close(); } catch { /* closed */ } } watched.clear(); blind = false; kept.clear(); queue.clear(); ahead.clear(); GEN = 0; if (timer) clearTimeout(timer); timer = null; busy = false; lastReq = 0; follower = null; for (const k of Object.keys(n)) n[k] = 0; }
184
+
185
+ module.exports = { SLOW, QUIET, FRESH_MS, MAX_AGE_MS, IDLE_MS, AHEAD_IDLE_MS, AGAIN_MAX, cacheable, serve, bump, drop, idle, warm, onKept, watch, stats, reset, keyOf };
@@ -190,7 +190,7 @@ function workflow({ root }) {
190
190
  * split, same reasons, stated in `historyRange`'s own header. The `build` rung is attributed per
191
191
  * initiative now (R-2), so a trunk-wide range no longer means a trunk-wide answer.
192
192
  */
193
- const range = engine.historyRange(root);
193
+ const range = historyRangeOf(engine, root);
194
194
  const changeRange = engine.commitRange(root);
195
195
  // ONE delivery index for the board, built once and shared, exactly as the CLI board does.
196
196
  let deliveryIndex = null;
@@ -243,6 +243,27 @@ function workflow({ root }) {
243
243
 
244
244
  // ENGINE_PATHS/loadEngine are exported for the packaging guard in workspace/test.js: the incident
245
245
  // that made them a list was invisible to every unit test precisely because resolution was inline.
246
+ /* The trunk's whole history, kept per repository until a trunk ref moves (page-open-200ms). `historyRange` reads every commit of the
247
+ * trunk with one `git log` (about 1 s on this repository), and the board, every initiative page and the initiative's sheet each asked
248
+ * for it again. The trunk refs' own ids (one `git for-each-ref`, a few ms) say whether it moved: a commit, a pull or a fetch gives a
249
+ * new key and the next read reads the history again. A range that could not be read is never kept. */
250
+ const RANGES = new Map(); // root → { key, range }
251
+ const TRUNK_REFS = ['refs/remotes/origin/main', 'refs/heads/main', 'refs/remotes/origin/master', 'refs/heads/master'];
252
+ function trunkKey(root) {
253
+ try {
254
+ const out = require('child_process').execFileSync('git', ['for-each-ref', '--format=%(refname) %(objectname)', ...TRUNK_REFS], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 5000 });
255
+ const head = require('child_process').execFileSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 5000 });
256
+ return out.trim() + '|' + head.trim();
257
+ } catch { return null; }
258
+ }
259
+ function historyRangeOf(engine, root) {
260
+ const key = trunkKey(root), got = RANGES.get(root);
261
+ if (key && got && got.key === key) return got.range;
262
+ const range = engine.historyRange(root);
263
+ if (key && range && range.ok) { RANGES.set(root, { key, range }); if (RANGES.size > 16) RANGES.delete(RANGES.keys().next().value); }
264
+ return range;
265
+ }
266
+
246
267
  /* ONE initiative's ladder, derived on demand.
247
268
  *
248
269
  * WHY THIS IS SEPARATE FROM `workflow`. The board caps what it returns (`inFlight`) and reports the
@@ -274,7 +295,7 @@ function ladder({ root, id }) {
274
295
  // the PM named, and "where does it stand" is a question the pull-request range cannot answer — on
275
296
  // main it is empty, so the panel reported `BUILD 0/3` on delivered work (R-3).
276
297
  let range, changeRange, row;
277
- try { range = engine.historyRange(root); }
298
+ try { range = historyRangeOf(engine, root); }
278
299
  catch (e) { return { ok: false, error: 'could not resolve the commit range: ' + String((e && e.message) || 'error').slice(0, 120) }; }
279
300
  try { changeRange = engine.commitRange(root); } catch { changeRange = { ok: false }; }
280
301
  try { row = engine.computeWorkflow(id, { root, range, changeRange }); }
@@ -296,4 +317,4 @@ function ladder({ root, id }) {
296
317
  };
297
318
  }
298
319
 
299
- module.exports = { metrics, radar, workflow, ladder, computeMetricsFromRuns, loadJson, loadJsonl, ENGINE_PATHS, loadEngine };
320
+ module.exports = { metrics, radar, workflow, ladder, historyRangeOf, computeMetricsFromRuns, loadJson, loadJsonl, ENGINE_PATHS, loadEngine };
@@ -18,6 +18,9 @@ const PATHS = [
18
18
  '/api/notes',
19
19
  '/api/live',
20
20
  '/api/insights-premium',
21
+ // Today's events and the onboarding check, kept by lib/answer-cache.js once read (page-open-200ms)
22
+ '/api/events-place',
23
+ '/api/onboard/state',
21
24
  ];
22
25
 
23
26
  function httpGet(host, port, p) {
@@ -29,6 +29,8 @@
29
29
  */
30
30
  const fs = require('fs');
31
31
  const path = require('path');
32
+ // a copy of this loader without answer-cache.js beside it (package-closure.test.js) still routes, with nothing kept
33
+ let answerCache; try { answerCache = require('./answer-cache.js'); } catch { answerCache = { cacheable: () => false, onKept() {}, warm() { return false; }, watch() { return false; } }; }
32
34
 
33
35
  const MODULES = Object.freeze([
34
36
  'routes-setup', // Claude-ready onboarding, explicit profile checks and real first work
@@ -218,9 +220,31 @@ function pmModules(url) {
218
220
  return { ok: true, present, grantScopes };
219
221
  }
220
222
 
223
+ /* What a page opens next, read in the background once the server is idle (lib/answer-cache.js warm, page-open-200ms): Work's answer names
224
+ * its initiatives, so the first WARM_INI of them open from a kept answer too. The warm read asks exactly as the initiative page does
225
+ * (id, ws, board) and holds no request of its own: no header is passed on. */
226
+ const WARM_INI = 12;
227
+ // a suite's server (a state folder under the system temp folder) reads nothing ahead, as it does not warm at start (lib/page-warm.js)
228
+ let aheadOn = null;
229
+ const readsAhead = () => { if (aheadOn === null) { try { aheadOn = require('./page-warm.js').shouldWarm(process.env, process.env.PMOS_STATE_DIR || null); } catch { aheadOn = false; } } return aheadOn; };
230
+ answerCache.onKept((url, body, ctx) => {
231
+ if (url.pathname !== '/api/board-premium' || !readsAhead()) return;
232
+ const m = body && body.model, b = m && m.board;
233
+ if (!b || b.all) return;
234
+ const owner = ownerOf('/api/initiative-premium'), t = load();
235
+ if (!owner || !t.mods[owner.name]) return;
236
+ const rows = (m.initiatives && m.initiatives.list && m.initiatives.list.rows) || [];
237
+ for (const r of rows.slice(0, WARM_INI)) {
238
+ if (!r || !r.id) continue;
239
+ const u = new URL('http://local/api/initiative-premium?id=' + encodeURIComponent(r.id) + (b.ws ? '&ws=' + encodeURIComponent(b.ws) : '') + (b.id ? '&board=' + encodeURIComponent(b.id) : ''));
240
+ answerCache.warm(u, (c, r2) => t.mods[owner.name].handle({ method: 'GET', headers: {} }, r2, u, c), ctx);
241
+ }
242
+ });
221
243
  async function dispatch(req, res, url, ctx) {
222
244
  const p = url.pathname;
223
245
  if (!p.startsWith('/api/')) return false;
246
+ // the end of a chat turn: the page says so, and the write it makes drops every kept answer (server.js bumps on every write)
247
+ if (p === '/api/answer-cache/drop') { ctx.json(res, req.method === 'POST' ? { ok: true } : { ok: false, error: 'POST only' }, req.method === 'POST' ? 200 : 405); return true; }
224
248
  const owner = ownerOf(p);
225
249
  if (!owner) return false;
226
250
  const t = load();
@@ -233,6 +257,18 @@ async function dispatch(req, res, url, ctx) {
233
257
  const readJson = async (r) => {
234
258
  try { return { ok: true, body: JSON.parse((await ctx.readBody(r)) || '{}') }; } catch { return { ok: false }; }
235
259
  };
260
+ // the slow reads a page opens on answer from their last answer while nothing was written (lib/answer-cache.js, page-open-200ms)
261
+ if (req.method === 'GET' && answerCache.cacheable(p)) {
262
+ try {
263
+ answerCache.watch((ctx.workspaceList ? ctx.workspaceList() : []).map((w) => w && w.root));
264
+ return await answerCache.serve(req, res, url, { ...ctx, readJson }, (c, r) => t.mods[owner.name].handle(req, r, url, c));
265
+ }
266
+ catch (e) {
267
+ if (res.headersSent) { try { res.end(); } catch { /* already closed */ } return true; }
268
+ ctx.json(res, { ok: false, error: `${owner.name} failed: ${String((e && e.message) || e).slice(0, 200)}` }, 500);
269
+ return true;
270
+ }
271
+ }
236
272
  try { return (await t.mods[owner.name].handle(req, res, url, { ...ctx, readJson })) === true; }
237
273
  catch (e) {
238
274
  if (res.headersSent) { try { res.end(); } catch { /* already closed */ } return true; }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.799.0",
3
+ "version": "0.800.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.799.0",
9
+ "version": "0.800.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.799.0",
3
+ "version": "0.800.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -1067,9 +1067,10 @@ const chat = mountChat($('#hmChat'), {
1067
1067
  let turnT = null;
1068
1068
  function turnEnded() {
1069
1069
  clearTimeout(turnT);
1070
- turnT = setTimeout(async () => { await load(); iniFresh(); if (progPanel) progPanel.then((PP) => PP.refresh()); }, 400); // two chats that finish together read once
1071
- // the popup's own reads (the case card, the Library's rows) are read again too, as on every other page (initiative chat-saves-to-cards)
1072
- document.dispatchEvent(new CustomEvent('cz:chat-turn'));
1070
+ const drop = pmPost('/api/answer-cache/drop', {}).catch(() => null); // kept answers go first (page-open-200ms)
1071
+ turnT = setTimeout(async () => { await drop; await load(); iniFresh(); if (progPanel) progPanel.then((PP) => PP.refresh()); }, 400); // two chats read once
1072
+ drop.then(() => document.dispatchEvent(new CustomEvent('cz:chat-turn')));
1073
+ // ↑ the popup's own reads (the case card, the Library's rows) are read again too, as on every other page (initiative chat-saves-to-cards)
1073
1074
  }
1074
1075
  /* claude-onboarding-build: set up a project as a conversation in this chat's place (cozy-onboard.js). It opens on ?onboard=1, shows the
1075
1076
  * finished project's next steps on ?onboarded=1, and opens by itself on a first run: setup not finished and no registered folder holds an
@@ -96,7 +96,8 @@ function host() {
96
96
  workItem: () => toast('Make it a task from Today, in the initiative’s own chat.'),
97
97
  viewerClosed: () => false, reopenViewer: () => {}, desk: () => true, head: () => '',
98
98
  // a finished turn: the page reads its records again, so what Claude changed shows with no refresh (as Home, batch 25 item 3)
99
- turnEnded: () => document.dispatchEvent(new CustomEvent('cz:chat-turn')),
99
+ // the server's kept answers are dropped first, so the reads see what the chat wrote (lib/answer-cache.js, page-open-200ms)
100
+ turnEnded: () => { Promise.resolve(pmPost('/api/answer-cache/drop', {})).catch(() => null).then(() => document.dispatchEvent(new CustomEvent('cz:chat-turn'))); },
100
101
  };
101
102
  }
102
103
  async function mod() {
@@ -256,16 +256,23 @@ function drawPick() {
256
256
  }
257
257
  // a saved pick (this chip, or Settings): the Board opens on the ticked products, without a one-off link's ws or board
258
258
  addEventListener('pp:changed', () => { const q = new URLSearchParams(location.search); ['ws', 'board', 'all', 'pick'].forEach((k) => q.delete(k)); const s = q.toString(); location.assign(location.pathname + (s ? '?' + s : '')); });
259
+ const SW_KEY = 'pmos.board.switcher';
260
+ function keptSwitcher() { try { const a = JSON.parse(store.get(SW_KEY) || 'null'); return Array.isArray(a) && a.length && a.every((b) => b && b.id) ? a : null; } catch { return null; } }
259
261
  /** Turn the saved pick into the boards to read: every product's board (All), several (PICK), one (ONE) or the default board. false while the
260
262
  * default board is still being read (its switcher lists the boards). A one-off link keeps its own. */
261
263
  async function resolvePick() {
262
264
  if (picked) return true;
263
265
  if (!PKP) PKP = await PK.readPick();
264
266
  if (DEEP || !PKP) { picked = true; return true; }
265
- const h = await readBoard('');
266
- if (h.r && h.r.state === 'reading') return false;
267
+ // the boards to pick between, as the last read of any board listed them (page-open-200ms): the default board is read only when no
268
+ // board was read on this browser before, so Work reads the picked boards once instead of the default board first
269
+ let sw = keptSwitcher();
270
+ if (!sw) {
271
+ const h = await readBoard('');
272
+ if (h.r && h.r.state === 'reading') return false;
273
+ sw = (h.r && h.r.ok && h.r.model && h.r.model.board.switcher) || null;
274
+ }
267
275
  picked = true;
268
- const sw = (h.r && h.r.ok && h.r.model && h.r.model.board.switcher) || null;
269
276
  if (!sw) return true; // one board: nothing to pick between
270
277
  const on = new Set(PKP.products.filter((p) => p.on).map((p) => p.ws)), keys = sw.filter((b) => on.has(b.ws)).map((b) => b.ws + '|' + b.id);
271
278
  if (!keys.length) return true;
@@ -1444,10 +1451,12 @@ function newOnce() {
1444
1451
  history.replaceState(history.state, '', location.pathname + (s ? '?' + s : ''));
1445
1452
  Acts.open.new($('#newIni'));
1446
1453
  }
1447
- /** One board's model (GET /api/board-premium); { r, status }. */
1454
+ /** One board's model (GET /api/board-premium); { r, status }. Its switcher is kept for the next open's pick (resolvePick). */
1448
1455
  async function readBoard(q) {
1449
1456
  let r = null, status = 0;
1450
1457
  try { const res = await fetch('/api/board-premium' + (q ? '?' + q : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
1458
+ const sw = r && r.ok && r.model && r.model.board && r.model.board.switcher;
1459
+ if (Array.isArray(sw) && sw.length) store.set(SW_KEY, JSON.stringify(sw.map((b) => ({ ws: b.ws || '', id: b.id, name: b.name }))));
1451
1460
  return { r, status };
1452
1461
  }
1453
1462
  /** All products: this board first, then every other product's board, merged into one model (pm/bd-prog.js mergeBoards). While any board
@@ -179,6 +179,7 @@ const jiraMoveSessions = new Map();
179
179
  const jiraMoves = require('./lib/jira-moves.js');
180
180
  const planItems = require('./lib/plan-items.js'); // pm-os-absorb Run 1 — the ONE writer and fold of plan-items.jsonl (control graph)
181
181
  const planTree = require('./lib/plan-tree.js'); // …and the Breakdown layout: derived stages, owed rows, the Board columns
182
+ const answerCache = require('./lib/answer-cache.js'); // page-open-200ms: the slow reads a page opens on, kept until a write
182
183
  const routeModules = require('./lib/route-modules.js'); // pm-os-absorb Runs 2–5 — each run's routes in its own lib/routes-<name>.js
183
184
  const needsProviders = require('./lib/needs-providers.js'); // …and each run's needs-you rows, folded into deriveNeeds
184
185
  const pmGuard = require('./lib/pm-guard.js'); // pm-os-absorb Run 2 (R25) — Origin, nonce and writer fields on every PM press
@@ -7358,6 +7359,8 @@ function json(res, obj, code = 200) {
7358
7359
 
7359
7360
  async function handleRequest(req, res) {
7360
7361
  const url = new URL(req.url, 'http://localhost');
7362
+ // page-open-200ms: a write makes every kept answer too old to show; any request holds the background reads back (lib/answer-cache.js)
7363
+ if (url.pathname.startsWith('/api/')) { answerCache.idle(); answerCache.bump(req.method, url.pathname); }
7361
7364
  // A page file under this or an earlier launch's build prefix is the same file without it (see BUILD above).
7362
7365
  const built = BUILD_RE.exec(url.pathname);
7363
7366
  const p = built ? built[2] : url.pathname;
@@ -133,7 +133,8 @@
133
133
  "loop-telemetry.test.js",
134
134
  "signals.test.js",
135
135
  "task-jira-sync.test.js",
136
- "correction-kinds.test.js"
136
+ "correction-kinds.test.js",
137
+ "answer-cache.test.js"
137
138
  ],
138
139
  "panels": [
139
140
  "pm-r7-test.js",