create-pmos 0.799.0 → 0.801.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 +28 -37
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +27 -10
- package/workspace/guide/initiatives-and-next-steps.md +10 -1
- package/workspace/guide/settings-and-switches.md +1 -0
- package/workspace/lib/answer-cache.js +185 -0
- package/workspace/lib/console-state.js +24 -3
- package/workspace/lib/core-docs.js +39 -3
- package/workspace/lib/coredoc-cli.js +2 -1
- package/workspace/lib/initiative-chat.js +1 -1
- package/workspace/lib/page-warm.js +3 -0
- package/workspace/lib/route-modules.js +36 -0
- package/workspace/lib/routes-core-docs.js +11 -2
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/bd-ini-panel.js +2 -1
- package/workspace/public/pm/bd-pop-ds.js +3 -3
- package/workspace/public/pm/cozy-home.css +5 -0
- package/workspace/public/pm/cozy-pop-work.js +22 -0
- package/workspace/public/pm/home-app.js +4 -3
- package/workspace/public/pm/home-chat.js +4 -2
- package/workspace/public/pm/page-chat.js +2 -1
- package/workspace/public/pm/pop-work-model.js +14 -2
- package/workspace/public/pm/premium-board.js +13 -4
- package/workspace/public/pm/premium-vw-ctx.js +51 -5
- package/workspace/server.js +3 -0
- package/workspace/test-files.json +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.801.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,32 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.801.0",
|
|
38
|
+
"at": "2026-11-25T01:53:19.580Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1829,
|
|
43
|
+
"t": "Issue a drafted document from the initiative page and the chat chip",
|
|
44
|
+
"s": "Issue a drafted document from the initiative page and the chat chip",
|
|
45
|
+
"k": "new"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"v": "0.800.0",
|
|
51
|
+
"at": "2026-11-25T01:39:46.319Z",
|
|
52
|
+
"f": 4,
|
|
53
|
+
"prs": [
|
|
54
|
+
{
|
|
55
|
+
"n": 1825,
|
|
56
|
+
"t": "Today, Work and an initiative open within 200 ms",
|
|
57
|
+
"s": "Today, Work and an initiative open within 200 ms",
|
|
58
|
+
"k": "imp"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
36
62
|
{
|
|
37
63
|
"v": "0.799.0",
|
|
38
64
|
"at": "2026-11-25T00:01:31.314Z",
|
|
@@ -42,16 +68,7 @@
|
|
|
42
68
|
"n": 1824,
|
|
43
69
|
"t": "Drafting the goal keeps the initiative page; one toast for one draft press",
|
|
44
70
|
"s": "Drafting the goal keeps the initiative page; one toast for one draft press",
|
|
45
|
-
"k": "fix"
|
|
46
|
-
"try": {
|
|
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."
|
|
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…",
|
|
53
|
-
"open": "/premium-board.html"
|
|
54
|
-
}
|
|
71
|
+
"k": "fix"
|
|
55
72
|
}
|
|
56
73
|
]
|
|
57
74
|
},
|
|
@@ -438,32 +455,6 @@
|
|
|
438
455
|
"k": "new"
|
|
439
456
|
}
|
|
440
457
|
]
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
"v": "0.781.0",
|
|
444
|
-
"at": "2026-11-24T16:04:56.192Z",
|
|
445
|
-
"f": 4,
|
|
446
|
-
"prs": [
|
|
447
|
-
{
|
|
448
|
-
"n": 1756,
|
|
449
|
-
"t": "✦ buttons act directly; ✦ drafts run as a PMOS background job",
|
|
450
|
-
"s": "✦ buttons act directly; ✦ drafts run as a PMOS background job",
|
|
451
|
-
"k": "new"
|
|
452
|
-
}
|
|
453
|
-
]
|
|
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
458
|
}
|
|
468
459
|
]
|
|
469
460
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-25T01:53:16Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-25T01:53:16Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-25T01:53:16Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.801.0",
|
|
4
|
+
"at": "2026-11-25T01:53:19.580Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1829,
|
|
9
|
+
"t": "Issue a drafted document from the initiative page and the chat chip",
|
|
10
|
+
"s": "Issue a drafted document from the initiative page and the chat chip",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"v": "0.800.0",
|
|
17
|
+
"at": "2026-11-25T01:39:46.319Z",
|
|
18
|
+
"f": 4,
|
|
19
|
+
"prs": [
|
|
20
|
+
{
|
|
21
|
+
"n": 1825,
|
|
22
|
+
"t": "Today, Work and an initiative open within 200 ms",
|
|
23
|
+
"s": "Today, Work and an initiative open within 200 ms",
|
|
24
|
+
"k": "imp"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
2
28
|
{
|
|
3
29
|
"v": "0.799.0",
|
|
4
30
|
"at": "2026-11-25T00:01:31.314Z",
|
|
@@ -8,16 +34,7 @@
|
|
|
8
34
|
"n": 1824,
|
|
9
35
|
"t": "Drafting the goal keeps the initiative page; one toast for one draft press",
|
|
10
36
|
"s": "Drafting the goal keeps the initiative page; one toast for one draft press",
|
|
11
|
-
"k": "fix"
|
|
12
|
-
"try": {
|
|
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."
|
|
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…",
|
|
19
|
-
"open": "/premium-board.html"
|
|
20
|
-
}
|
|
37
|
+
"k": "fix"
|
|
21
38
|
}
|
|
22
39
|
]
|
|
23
40
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Initiatives: the Roadmap, next steps, the Driver and done"
|
|
4
4
|
description: "The ranked list of initiatives, how PMOS works out the next steps, the Initiative Driver, and integrated work."
|
|
5
|
-
timestamp: 2026-11-
|
|
5
|
+
timestamp: 2026-11-25
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Initiatives: the Roadmap, next steps, the Driver and done
|
|
@@ -132,6 +132,15 @@ Below the strategy, a Work that shows one product has a **Principles** block. Wh
|
|
|
132
132
|
|
|
133
133
|
You can also ask the chat to keep, drop or add a principle (`pmos principles`). Work shows the change. When there are no principles and no drafts, the block is not shown.
|
|
134
134
|
|
|
135
|
+
### Issue a document PMOS drafted
|
|
136
|
+
|
|
137
|
+
When PMOS drafts a document for an initiative, for example a stage's plan that you asked the chat to update, the draft waits for you. You issue it in one of two places:
|
|
138
|
+
|
|
139
|
+
- **The initiative page.** A ✦ row at the top of **Where it stands** says "Issue the Plan document, drafted 25 Nov?". Press ✓ to issue it. Press ✎ to read or edit it first. Press ✕ to hide the row.
|
|
140
|
+
- **The chat.** The file chip under the answer that saved the draft has a ✓ beside it. Press ✓ to issue it.
|
|
141
|
+
|
|
142
|
+
Each issue offers Undo. Issuing marks the draft as the current version. Nothing is sent to anyone. When there are several drafts of one document, only the newest can be issued: it replaces the older ones.
|
|
143
|
+
|
|
135
144
|
### Now, Next and Later are retired (D105)
|
|
136
145
|
|
|
137
146
|
Earlier versions put each initiative in one of three horizons: Now, Next and Later. They are retired. Nothing you placed is lost:
|
|
@@ -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
|
|
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
|
|
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 };
|
|
@@ -43,7 +43,7 @@ const RETIRED_LEVELS = Object.freeze(['portfolio', 'board']);
|
|
|
43
43
|
const RETIRED = 'PMOS no longer drafts portfolio or board documents. The product page\'s story, Intent and goals cover them, and the ones already written stay readable.';
|
|
44
44
|
const CATS = Object.freeze(['Discover', 'Plan', 'Do', 'Learn']);
|
|
45
45
|
const KINDS = Object.freeze(['doc', 'derived', 'report']);
|
|
46
|
-
const EVENTS = Object.freeze(['draft', 'issue', 'drop']);
|
|
46
|
+
const EVENTS = Object.freeze(['draft', 'issue', 'drop', 'unissue']); // unissue: the PM's Undo of an issue (issue-from-chat)
|
|
47
47
|
const BY = Object.freeze({ you: 'You write it', proposes: 'PMOS proposes', drafts: 'PMOS drafts it', files: 'PMOS files it', watches: 'PMOS watches it',
|
|
48
48
|
keeps: 'PMOS keeps it current', live: 'Live view', reviews: 'PMOS reviews, you accept' });
|
|
49
49
|
const LEVEL = Object.freeze({
|
|
@@ -253,10 +253,12 @@ function fold(lines) {
|
|
|
253
253
|
for (const l of lines || []) {
|
|
254
254
|
const x = get(l);
|
|
255
255
|
if (l.ev === 'draft') x.drafts.push(l);
|
|
256
|
-
else if (l.ev === 'issue')
|
|
256
|
+
else if (l.ev === 'issue') x.issues.push(l);
|
|
257
|
+
else if (l.ev === 'unissue') x.issues = x.issues.filter((i) => i.slot !== l.slot); // Undo: the issue before it no longer counts
|
|
257
258
|
else if (l.ev === 'drop') x.drops.add(l.slot);
|
|
258
259
|
}
|
|
259
260
|
for (const x of m.values()) {
|
|
261
|
+
for (const l of x.issues) if (!x.issued || msOf(l.at) >= msOf(x.issued.at)) x.issued = l;
|
|
260
262
|
const issuedSlots = new Set(x.issues.map((l) => l.slot));
|
|
261
263
|
const open = x.drafts.filter((d) => !issuedSlots.has(d.slot) && !x.drops.has(d.slot) && (!x.issued || msOf(d.at) > msOf(x.issued.at)));
|
|
262
264
|
x.draft = open.length ? open[open.length - 1] : null;
|
|
@@ -320,6 +322,8 @@ function openDraft(root, scope, key, slot) {
|
|
|
320
322
|
if (!d) return refuse(404, `no draft ${slot} of ${c.entry.title}`);
|
|
321
323
|
if (x.issues.some((l) => l.slot === slot)) return refuse(409, 'that draft is issued already');
|
|
322
324
|
if (x.drops.has(slot)) return refuse(409, 'that draft was dropped');
|
|
325
|
+
// a newer draft replaces an older one: only the open draft is issued, so an old version never becomes the record by mistake
|
|
326
|
+
if (x.draft && x.draft.slot !== slot) return refuse(409, `a newer draft (${x.draft.slot}) replaces that one; issue the newer one`);
|
|
323
327
|
return { ok: true, entry: c.entry, line: d };
|
|
324
328
|
}
|
|
325
329
|
|
|
@@ -339,6 +343,38 @@ function issue(root, { scope, key, slot } = {}, actor, { now } = {}) {
|
|
|
339
343
|
const line = append(ledgerFile(abs), { ev: 'issue', scope, key, slot, path: o.line.path, by: (actor && actor.by) || null }, { now: t });
|
|
340
344
|
return { ok: true, line };
|
|
341
345
|
}
|
|
346
|
+
/** The core-document draft a file path is (issue-from-chat: the chat's file chip and the initiative page offer ✓ Issue on it), or null when the
|
|
347
|
+
* path is no draft of the ledger. → { scope, key, slot, path, title, state: 'draft' | 'issued' | 'superseded' | 'dropped', newer? } */
|
|
348
|
+
function draftOfPath(root, p) {
|
|
349
|
+
const want = String(p || '').replace(/\\/g, '/').replace(/^\.?\//, '');
|
|
350
|
+
if (!/\/core-docs\/[^/]+\/[^/]+\/[^/]+\.md$/.test(want)) return null;
|
|
351
|
+
const lines = readLines(ledgerFile(root));
|
|
352
|
+
const d = lines.find((l) => l.ev === 'draft' && typeof l.path === 'string' && (want === l.path || want.endsWith('/' + l.path) || l.path.endsWith('/' + want)));
|
|
353
|
+
if (!d) return null;
|
|
354
|
+
const x = fold(lines).get(`${d.scope}|${d.key}`);
|
|
355
|
+
const c = checkEntry(d.scope, d.key);
|
|
356
|
+
const st = x.drops.has(d.slot) ? 'dropped' : x.issues.some((l) => l.slot === d.slot) ? 'issued' : x.draft && x.draft.slot === d.slot ? 'draft' : 'superseded';
|
|
357
|
+
return { scope: d.scope, key: d.key, slot: d.slot, path: d.path, title: c.ok ? c.entry.title : d.key, state: st, ...(st === 'superseded' && x.draft ? { newer: x.draft.slot } : {}) };
|
|
358
|
+
}
|
|
359
|
+
/** Undo an issue (issue-from-chat): one `unissue` line and `state: draft` back in the file, so the draft is open again. Only the slot that is
|
|
360
|
+
* issued now, and only while no newer draft replaced it. A PM press only, like issue. */
|
|
361
|
+
function unissue(root, { scope, key, slot } = {}, actor, { now } = {}) {
|
|
362
|
+
const c = checkEntry(scope, key);
|
|
363
|
+
if (!c.ok) return c;
|
|
364
|
+
if (!SLOT_RE.test(String(slot || ''))) return refuse(400, 'slot must be YYYY-MM-DD, with -2, -3 for a second draft on one day');
|
|
365
|
+
const x = storeOf(root).get(`${scope}|${key}`);
|
|
366
|
+
const is = x && x.issues.find((l) => l.slot === slot);
|
|
367
|
+
if (!is) return refuse(409, 'that draft is not issued');
|
|
368
|
+
if (x.drafts.some((d) => d.slot !== slot && msOf(d.at) > msOf(is.at))) return refuse(409, 'a newer draft came after it, so the issue stays');
|
|
369
|
+
const abs = path.resolve(String(root));
|
|
370
|
+
const file = path.join(abs, is.path);
|
|
371
|
+
try {
|
|
372
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
373
|
+
fs.writeFileSync(file, text.replace(/^(---\r?\n[\s\S]*?)^state:[^\n]*$/m, '$1state: draft'));
|
|
374
|
+
} catch { /* the file is gone: the ledger line still reopens the draft */ }
|
|
375
|
+
const line = append(ledgerFile(abs), { ev: 'unissue', scope, key, slot, path: is.path, by: (actor && actor.by) || null }, { now });
|
|
376
|
+
return { ok: true, line };
|
|
377
|
+
}
|
|
342
378
|
/** Drop a draft: one `drop` line. The file stays as it is; the fold no longer counts it. */
|
|
343
379
|
function drop(root, { scope, key, slot } = {}, actor, { now } = {}) {
|
|
344
380
|
const o = openDraft(root, scope, key, slot);
|
|
@@ -651,6 +687,6 @@ function batchPrompt(entries, scope, { today, label } = {}) {
|
|
|
651
687
|
module.exports = {
|
|
652
688
|
LEDGER, DIR, LEVELS, RETIRED_LEVELS, RETIRED, LEVEL, SETS, CATS, KINDS, EVENTS, BY, RESEARCH_KEEP, BUILD_ONLY_INI, STALE_ON_MOVE, ID_RE, SLOT_RE, GUIDE,
|
|
653
689
|
entryOf, parseScope, levelOfScope, scopeDir, scopeLabel, draftable, storable, actOf, setFor, stateOf, summaryOf, localDay, addDays,
|
|
654
|
-
ledgerFile, readLines, append, fold, storeOf, checkEntry, writeDraft, issue, drop, frontmatterOf,
|
|
690
|
+
ledgerFile, readLines, append, fold, storeOf, checkEntry, writeDraft, issue, unissue, drop, frontmatterOf, draftOfPath,
|
|
655
691
|
gather, answer, initiativeDocs, initiativeSet, workflowPlan, stageEntry, WF_KEY_RE, prdSection, driverLists, runPrompt, batchPrompt,
|
|
656
692
|
};
|
|
@@ -88,7 +88,8 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
88
88
|
try { r = CD.writeDraft(root, { scope: flags.scope, key: flags.key, markdown, by: actor.by, now }); } catch (err) { return fail(`the draft was not written: ${String((err && err.message) || err).slice(0, 160)}`); }
|
|
89
89
|
if (!r.ok) return fail(r.error);
|
|
90
90
|
if (json) say(JSON.stringify({ ok: true, scope: flags.scope, key: flags.key, slot: r.slot, path: r.path }));
|
|
91
|
-
|
|
91
|
+
// issue-from-chat: the words the agent passes on name the real presses, so it never invents a place (it once sent the PM to a stage card)
|
|
92
|
+
else say(`✓ drafted ${r.path}. It waits for the PM, who issues it: ✓ on the file chip under your answer, or ✓ on the ✦ row "Issue the … document" at the top of the initiative page. Say exactly that. Nothing was sent.`);
|
|
92
93
|
return 0;
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -60,7 +60,7 @@ function rule(info, id) {
|
|
|
60
60
|
'The "N days over" badge counts from the planned finish (the latest due of its tasks). While the initiative is open it counts to today. Once it is in its workflow\'s last stage (Closed, Done) it counts to when the work really finished: the end of its last Done task, else the day it moved into that stage. On time, the badge goes away and the card says Done with that date; late, it reads "Finished N days late" and that number never grows. '
|
|
61
61
|
+ 'Never change a date, a task or the stage to clear or shorten the badge: the dates are the record. When the PM asks why it shows, explain this rule.',
|
|
62
62
|
'The Work timeline draws one bar per initiative, from the earliest start to the latest due of its tasks. An initiative with no dated task has no bar. Every stage shows there, Monitor and Evaluate included. Use these rules when the PM asks why an initiative is not on the timeline.',
|
|
63
|
-
`A stage's document fills its card only through \`pmos coredoc write --scope initiative:${ini} --key wf-<stage key> --file <path>\` (the stage keys are in \`pmos workflow of ${ini}\`). It is a draft the PM issues on the
|
|
63
|
+
`A stage's document fills its card only through \`pmos coredoc write --scope initiative:${ini} --key wf-<stage key> --file <path>\` (the stage keys are in \`pmos workflow of ${ini}\`). It is a draft the PM issues. Where to issue it, in these words only: "Press ✓ on the file chip under this answer, or on the ✦ row 'Issue the … document' at the top of the initiative's Where it stands." Never name a stage card, an Issue button or any other place. A newer draft replaces the older ones, so only the newest can be issued. A file written under planning/ is not linked to a card.`,
|
|
64
64
|
);
|
|
65
65
|
out.push(/* card-catalog:begin, generated by bin/card-catalog-gen.js: edit lib/card-catalog.json, not this block */"The card buttons run these pmos commands (the card catalog; who acts: you = one press with Undo, agent = PMOS starts a run, waits = only after the PM says yes). Run the one that fits the PM's ask, and tell the PM the Undo line it prints: pmos task set <id> --due <date> [--start <date>] [--owner <who>] [--notes <text>] [--milestone] [--pin] [--no-milestone] (Move the date, Set start and due, Change owner, Add a note, Make it a milestone, Pin, Back to a task; you); pmos task state <id> --to <state> --why <text> (Change status, Mark done; you); pmos task comment <id> <text> (Comment; you); pmos task describe <id> (Write the description; agent); pmos task remove <id> --why <text> (Remove; you); pmos task add <initiative> \"<title>\" --parent <task> [--due <date>] [--owner <who>] (Add a subtask, Add a task; you); pmos rehearse move <id> --due <date> [--by <days>] (What slips if it moves, Move a task; you); pmos task link <from> <to> --type fs|ss|ff|sf --lag <days> (Link two tasks; you); pmos task unlink <from> <to> (Unlink; you); pmos item move <item> <todo|doing|review|done> --evidence <ref> (Move on the board; you); pmos item set <item> --due <date> --owner <who> (Change date or owner; you); pmos item withdraw <item> (Withdraw; you); pmos initiative up|down <id> (Move up / down; you); pmos initiative top|bottom <id> (Move to top / bottom; you); pmos initiative after <id> <other> (Rank after another; you); pmos initiative check-by <id> <date> (Set check date; you); pmos initiative kind <id> product|project|sdlc (Change kind; you); pmos workflow switch <id> --to <workflow> --stage <stage> --why <text> (Change workflow; you); pmos workflow move <id> --stage <stage> --why <text> (Move to stage; you); pmos initiative describe <id> (Write the description; agent); pmos parked hold <id> --why <text> (Park it, Change the reason; you); pmos initiative export <id> (Export the breakdown; you); pmos initiative adopt <proposal> (Keep; you); pmos initiative drop <proposal> (Drop; you); pmos parked back <id> (Bring back; you); pmos launch check <initiative> --date <date> (Check what is not ready; you); pmos launch tier <initiative> (Set the launch tier; you); pmos ready check <initiative> (Run the check; you); pmos artefacts set <scope> <artefact> --text <text> (Write it; you); pmos artefacts undo <a-id> (Undo; you); pmos signoff ask <initiative> --who <who> (Ask; waits); pmos signoff answer <id> --answer <text> (Record the answer; you); pmos signoff drop <id> --why <text> (Drop; you); pmos rehearse end <initiative> --to <date> (Move the end; you); pmos rehearse cut <task|initiative> (Cut it; you)."/* card-catalog:end */);
|
|
66
66
|
return out;
|
|
@@ -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; }
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* Every route answers 410 for a portfolio or board scope (retired, below).
|
|
9
9
|
* POST /api/core-docs/issue { ws, scope, key, slot } → { ok } `state: issued` in the file and one `issue` line
|
|
10
10
|
* POST /api/core-docs/drop { ws, scope, key, slot } → { ok } one `drop` line
|
|
11
|
+
* POST /api/core-docs/unissue { ws, scope, key, slot } → { ok } Undo of Issue: one `unissue` line, `state: draft` in the file again
|
|
12
|
+
* GET /api/core-docs/of?ws&path → { ok, doc: { scope, key, slot, title, state, newer? } | null } the draft a file is
|
|
13
|
+
* (issue-from-chat: a chat file chip shows ✓ Issue on a core-document draft). One ledger read, no gather, so it answers in a few ms.
|
|
11
14
|
*
|
|
12
15
|
* WHO WRITES. Every POST refuses a request that carries an agent session header (403), as routes-scan.js does. Draft it passes pm-guard
|
|
13
16
|
* requirePagePress; Issue it and Drop pass requirePmPress (act `issue`): only the PM issues or drops a core document. A draft is never sent.
|
|
@@ -34,7 +37,7 @@ const headless = require('./headless.js');
|
|
|
34
37
|
|
|
35
38
|
const text = (v) => (typeof v === 'string' ? v : '');
|
|
36
39
|
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
37
|
-
const POSTS = ['draft', 'issue', 'drop'];
|
|
40
|
+
const POSTS = ['draft', 'issue', 'unissue', 'drop'];
|
|
38
41
|
|
|
39
42
|
const runs = new Map(); // `${ws}|${scope}|${key}` → session id, for the core-doc runs this server started
|
|
40
43
|
|
|
@@ -109,6 +112,12 @@ async function handle(req, res, url, ctx) {
|
|
|
109
112
|
if (!g.ok) return send(bad(g.status || 400, g.error));
|
|
110
113
|
return send({ status: 200, body: CD.answer(g.facts, { running: isRunning(w.id) }) });
|
|
111
114
|
}
|
|
115
|
+
if (sub === 'of') {
|
|
116
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
117
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
118
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
119
|
+
return send({ status: 200, body: { ok: true, doc: CD.draftOfPath(w.root, url.searchParams.get('path') || '') } });
|
|
120
|
+
}
|
|
112
121
|
if (!POSTS.includes(sub)) return send(bad(404, 'no such core-docs route'));
|
|
113
122
|
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
114
123
|
const read = await ctx.readJson(req);
|
|
@@ -135,7 +144,7 @@ async function handle(req, res, url, ctx) {
|
|
|
135
144
|
}
|
|
136
145
|
const c = CD.checkEntry(scope, key);
|
|
137
146
|
if (!c.ok) return send(bad(c.status, c.error));
|
|
138
|
-
const fn = sub === 'issue' ? CD.issue : CD.drop;
|
|
147
|
+
const fn = sub === 'issue' ? CD.issue : sub === 'unissue' ? CD.unissue : CD.drop;
|
|
139
148
|
const r = fn(w.root, { scope, key, slot: text(body.slot) }, g.actor, { now });
|
|
140
149
|
if (!r.ok) return send(bad(r.status, r.error));
|
|
141
150
|
refresh();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.801.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.801.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -263,7 +263,8 @@ function wire(body, key) {
|
|
|
263
263
|
const H = {
|
|
264
264
|
// planned versus actual (batch 11 item 8, pm/ini-versions.js): where a draft's writes go, the read after Make live, the toast with Undo
|
|
265
265
|
where: () => { const r = O.rowOf(key), M = O.M() || {}; return { ws: (r && r.ws) || (M.board && M.board.ws), board: (r && r.boardId) || (M.board && M.board.id) }; },
|
|
266
|
-
|
|
266
|
+
// the core documents are read again too, so an issued draft's ✦ goes away (issue-from-chat)
|
|
267
|
+
reload: () => { const r = O.rowOf(key); if (r && r.id) readPage(r, true); return O.reload ? O.reload() : null; },
|
|
267
268
|
toast: (m, undo) => (O.toast ? O.toast(m, undo) : null),
|
|
268
269
|
check: (uid, b) => { const r = O.rowOf(key), k = r && (r.tasks || []).find((x) => x.uid === uid); if (r && O.setTask) O.setTask(r, uid, k && k.status === 'Done' ? 'To do' : 'Done'); },
|
|
269
270
|
// the quick changes (batch 9 item 5b): the status caret, the date press and a Timeline or Kanban drag, each with Undo in the toast
|
|
@@ -75,9 +75,9 @@ export function sugHtml(s) {
|
|
|
75
75
|
const will = sugWill(s), src = (s.sources || []).map((x) => x && x.label).filter(Boolean).join(', ');
|
|
76
76
|
const ans = s.choices
|
|
77
77
|
? s.choices.map((c, i) => `<button type="button" class="pm-btn outline" data-pw-choice="${esc(s.id + '|' + i)}">${esc(c.label)}</button>`).join('') + `<button type="button" class="pm-btn outline" data-pw-drop="${esc(s.id)}" aria-label="Not now" title="Not now">${SV(I.x)}</button>`
|
|
78
|
-
: `<button type="button" class="pm-btn" data-pw-sug="${esc(s.id)}" aria-label="Change it first" title="Change it first">${SV(I.pen)}</button>`
|
|
79
|
-
+ `<button type="button" class="pm-btn primary" data-pw-keep="${esc(s.id)}" aria-label="Yes, do it" title="Yes, do it">${SV(I.ok)}</button>`
|
|
80
|
-
+ `<button type="button" class="pm-btn outline" data-pw-drop="${esc(s.id)}" aria-label="No" title="No">${SV(I.x)}</button>`;
|
|
78
|
+
: `<button type="button" class="pm-btn" data-pw-sug="${esc(s.id)}" aria-label="${s.issue ? 'Read it first' : 'Change it first'}" title="${s.issue ? 'Read it first' : 'Change it first'}">${SV(I.pen)}</button>`
|
|
79
|
+
+ `<button type="button" class="pm-btn primary" data-pw-keep="${esc(s.id)}" aria-label="${s.issue ? 'Issue it' : 'Yes, do it'}" title="${s.issue ? 'Issue it' : 'Yes, do it'}">${SV(I.ok)}</button>`
|
|
80
|
+
+ `<button type="button" class="pm-btn outline" data-pw-drop="${esc(s.id)}" aria-label="${s.issue ? 'Not now' : 'No'}" title="${s.issue ? 'Not now' : 'No'}">${SV(I.x)}</button>`;
|
|
81
81
|
return `<div class="pm-sug x" role="group" aria-label="PMOS suggests"><div class="ttl">${SV(I.star)}<b class="say">${esc(s.say)}</b></div>`
|
|
82
82
|
+ `<dl>${row('Why', esc(s.why))}${row('PMOS will', will.length && !(will.length === 1 && will[0] === s.say) ? `<ul>${will.map((w) => `<li>${esc(w)}</li>`).join('')}</ul>` : '')}${row('Based on', esc(src), 'src')}</dl>`
|
|
83
83
|
+ `<div class="ans">${ans}</div></div>`;
|
|
@@ -551,6 +551,11 @@ form.hm-box textarea { min-height: 48px; border: 0; background: none; resize: no
|
|
|
551
551
|
.hm-chat .ctxchip b { font-size: var(--fs-meta); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: var(--lh-meta); }
|
|
552
552
|
.hm-chat .ctxchip em { font-style: normal; font-size: var(--fs-meta); color: var(--cz-ink3); line-height: var(--lh-meta); }
|
|
553
553
|
.hm-chat .ctxchip.lead { box-shadow: inset 0 0 0 1.5px var(--cz-blue); }
|
|
554
|
+
/* a core-document draft's chip and its ✓ Issue (issue-from-chat): one icon button beside the chip, primary while the draft waits */
|
|
555
|
+
.hm-chat .ctxdoc { display: inline-flex; align-items: stretch; gap: var(--space-4, 4px); max-width: 100%; }
|
|
556
|
+
.hm-chat .ctxiss { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; padding: 0; border-radius: var(--radius-md, 12px); border: 0; background: var(--cz-blue); color: var(--cz-card); cursor: pointer; }
|
|
557
|
+
.hm-chat .ctxiss .i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
|
558
|
+
.hm-chat .ctxiss:disabled { opacity: .5; cursor: default; }
|
|
554
559
|
.hm-chat .ctxchip svg, .hm-chat .i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; flex: none; }
|
|
555
560
|
.hm-chat .tc, .hm-chat .gcard { margin-top: var(--space-8); padding: var(--space-12) 14px; border-radius: var(--radius-card, 16px); background: var(--cz-card); box-shadow: inset 0 0 0 1.5px var(--cz-blue); font-size: var(--fs-body); line-height: var(--lh-body); }
|
|
556
561
|
.hm-chat .agtag, .hm-chat .askh { margin: 0 0 var(--space-4); font-size: var(--fs-badge); font-weight: var(--fw-strong); color: var(--cz-ink3); line-height: var(--lh-badge); }
|
|
@@ -741,7 +741,28 @@ async function direct(d, ask, x, h) {
|
|
|
741
741
|
if (h.reload) await h.reload();
|
|
742
742
|
});
|
|
743
743
|
}
|
|
744
|
+
/* a drafted document's ✓ (issue-from-chat): POST /api/core-docs/issue marks the draft issued; Undo posts /api/core-docs/unissue. Nothing is sent. */
|
|
745
|
+
async function issueDoc(s, x, h) {
|
|
746
|
+
const w = h.where ? h.where() : {}, o = x.o(), ws = w.ws || o.ws, body = { ws, scope: 'initiative:' + o.id, key: s.issue.key, slot: s.issue.slot };
|
|
747
|
+
const res = await pmPost('/api/core-docs/issue', body).catch(() => null);
|
|
748
|
+
if (!res || res.ok === false) { if (h.toast) h.toast((res && res.error) || 'The draft was not issued.'); if (h.reload) await h.reload(); return; }
|
|
749
|
+
if (h.reload) await h.reload();
|
|
750
|
+
undoToast(s.issue.title + ' issued. Nothing was sent to anyone.', async () => {
|
|
751
|
+
const u = await pmPost('/api/core-docs/unissue', body).catch(() => null);
|
|
752
|
+
if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
|
|
753
|
+
if (h.reload) await h.reload();
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
/* ✎ on a drafted document's ✦: the draft opens to read or edit, with Issue it on top (pm/home-draft.js) */
|
|
757
|
+
async function readDraft(s, x, h) {
|
|
758
|
+
const w = h.where ? h.where() : {}, o = x.o(), A = await import('./home-draft.js');
|
|
759
|
+
VW.drill();
|
|
760
|
+
A.openDraftVw({ VW, pmGet, pmPost, toast: h.toast || (() => {}), ws: w.ws || o.ws, scope: 'initiative:' + o.id,
|
|
761
|
+
doc: { key: s.issue.key, title: s.issue.title, path: s.issue.path, slot: s.issue.slot, st: 'draft', state: 'Draft' }, iniTitle: (x.v() || {}).title || '',
|
|
762
|
+
onIssued: async () => { if (h.reload) await h.reload(); } });
|
|
763
|
+
}
|
|
744
764
|
async function keepSug(s, x, h) {
|
|
765
|
+
if (s.issue) { await issueDoc(s, x, h); return; }
|
|
745
766
|
if (s.derived) {
|
|
746
767
|
if (s.move && h.move) { await h.move(s.move.uid, { to: s.move.to, from: '', name: s.move.name }); return; }
|
|
747
768
|
if (s.moveAll) { await moveAll(s.moveAll, h); return; }
|
|
@@ -1010,6 +1031,7 @@ function big(c, x, h) {
|
|
|
1010
1031
|
void title;
|
|
1011
1032
|
}
|
|
1012
1033
|
function openSug(s, c, x, h) {
|
|
1034
|
+
if (s.issue) { readDraft(s, x, h); return; }
|
|
1013
1035
|
VW.drill();
|
|
1014
1036
|
VW.open({ kind: 'Suggestion', title: 'Suggestion', icon: 'spark', id: 'sug:' + s.id, back: true,
|
|
1015
1037
|
render: (b) => {
|
|
@@ -1067,9 +1067,10 @@ const chat = mountChat($('#hmChat'), {
|
|
|
1067
1067
|
let turnT = null;
|
|
1068
1068
|
function turnEnded() {
|
|
1069
1069
|
clearTimeout(turnT);
|
|
1070
|
-
|
|
1071
|
-
|
|
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
|
|
@@ -477,8 +477,9 @@ export function mountChat(el, host) {
|
|
|
477
477
|
function askOf(id) { const m = ((C.conv && C.conv.messages) || []).find((x) => x.role === 'tool' && x.ask && askId(x) === id); return m ? m.ask : null; }
|
|
478
478
|
/* the context chips under an answer (the files, tickets, pages and links it worked with), drawn as premium-vw-ctx draws them */
|
|
479
479
|
let chipsHtmlFn = null;
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
// a core-document draft's chip carries ✓ Issue (issue-from-chat): the module reads its state and draws again when it knows it
|
|
481
|
+
views.ctx().then((M) => { chipsHtmlFn = M.chipsHtml; if (M.configure) M.configure({ pmGet: (u) => host.pmGet(u), pmPost: (u, b) => host.pmPost(u, b), toast: (t) => host.toast(t), redraw: () => { if (C.t) draw(); } }); if (C.t) draw(); }).catch(() => {});
|
|
482
|
+
const chipsOf = (items) => (chipsHtmlFn ? chipsHtmlFn(items, { ws: (C.t && C.t.ws) || new URLSearchParams(location.search).get('ws') || '' }) : '');
|
|
482
483
|
function drawFoot(R) {
|
|
483
484
|
const t = C.t, goal = C.th && C.th.goal;
|
|
484
485
|
const also = t.also && !(C.conv && C.conv.ask) ? `<button type="button" class="hm-also" data-hm-also><i aria-hidden="true"></i><span><b>Also waiting on you:</b> ${esc(t.also.text)}</span><em>${esc(t.also.verb || 'Answer')}</em></button>` : '';
|
|
@@ -638,6 +639,7 @@ export function mountChat(el, host) {
|
|
|
638
639
|
if ('hmSignin' in d) { import('./cozy-settings.js').then((S) => S.openSettings('connectors')); return; } // a reach ask: Sign in to Jira opens Settings › Connectors
|
|
639
640
|
if ('hmFile' in d) { const i = foot.querySelector('#hmFile'); if (i) i.click(); return; }
|
|
640
641
|
if (d.reportOpen != null && d.reportOpen !== '') { e.preventDefault(); const m = ((C.conv && C.conv.messages) || [])[+d.reportOpen]; const bl = m ? splitReport(splitGoal(m.text).text).block : null; if (bl) views.block(bl, { chat: C.t.key || null }); return; }
|
|
642
|
+
if (d.ctxIssue != null) { e.preventDefault(); views.ctx().then((M) => M.issuePress(b)); return; }
|
|
641
643
|
if (d.ctx != null) { e.preventDefault(); views.ctx().then((M) => M.openCtx(M.itemOf(b), where())); return; }
|
|
642
644
|
if (d.file) { e.preventDefault(); views.file().then((M) => M.openChatFile(d.file, where())); return; }
|
|
643
645
|
if (d.att) { e.preventDefault(); if (/\/notes\/n[0-9a-z]{6,16}\.md$/.test(d.att)) openNotesHere(d.att.split('/').pop().replace(/\.md$/, '')); else views.attach().then((M) => M.openAttachment(d.att)); return; }
|
|
@@ -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
|
-
|
|
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() {
|
|
@@ -507,7 +507,8 @@ const andList = (a) => (a.length <= 1 ? a.join('') : a.slice(0, -1).join(', ') +
|
|
|
507
507
|
* place, so a draft could land where nothing looks. */
|
|
508
508
|
const docSave = (id) => (id ? ' When I say yes, save each one where the Artefacts list reads it: a PRD as a file the record names in `prd_path:`, a rubric in `rubric_path:`, the done test with `pmos artefacts set experiment:' + id + ' done-test check --text "<one check>"` once for each check, and any other document with `pmos coredoc write --scope initiative:' + id + ' --key <key> --file <path>`.' : '');
|
|
509
509
|
/** derivedOf(r, v, o, bd, arts) → { top: [s], rows: Map(uid → s) }. Each s: { id, derived: true, say, why, ask?, move?, direct? }. ask: the words ✓
|
|
510
|
-
* sends to Ask PMOS, which does it in a real session; move: { uid, to, name } ✓ puts a task in a stage
|
|
510
|
+
* sends to Ask PMOS, which does it in a real session; move: { uid, to, name } ✓ puts a task in a stage; issue: { key, slot, path, title } ✓ issues a
|
|
511
|
+
* drafted core document (POST /api/core-docs/issue) with Undo. direct: { act, to? } ✓ (or a choice)
|
|
511
512
|
* writes at once through POST /api/boards/ini-<act>, with Undo, and sends `ask` only when the route answers ask: true (bet 1f). o.dropped: the
|
|
512
513
|
* ids the PM said No to. */
|
|
513
514
|
export function derivedOf(r, v, o, bd, arts) {
|
|
@@ -530,6 +531,16 @@ export function derivedOf(r, v, o, bd, arts) {
|
|
|
530
531
|
why: 'The gate to the next stage needs ' + what + ', and ' + (miss.length === 1 ? 'it is' : 'they are') + ' not written.',
|
|
531
532
|
ask: 'Draft ' + what + ' for ' + title + (n ? ' from its ' + plural(n, 'document', 'documents') : '') + ', for me to read.' + docSave(o.id || v.id || v.key || r.id) });
|
|
532
533
|
}
|
|
534
|
+
// a document PMOS drafted waits to be issued (issue-from-chat): one ✦ per draft, ✓ issues it with Undo, ✎ opens it to read or edit, ✕ hides it.
|
|
535
|
+
// Before, a draft the chat saved had no Issue anywhere on this page, and the chat sent the PM to a card that did not exist.
|
|
536
|
+
for (const d of o.docs || []) {
|
|
537
|
+
if (!d || d.st !== 'draft' || !d.slot || !d.path || !d.key || d.running) continue;
|
|
538
|
+
const name = /\bdocument\b/i.test(d.title || '') ? d.title : (d.title || 'stage') + ' document';
|
|
539
|
+
const on = dayText(String(d.slot).slice(0, 10), t);
|
|
540
|
+
top.push({ id: 'd:issue:' + d.key + ':' + d.slot, derived: true, say: 'Issue the ' + name + (on ? ', drafted ' + on : '') + '?',
|
|
541
|
+
why: 'PMOS drafted it and it waits for you. Issuing marks it as the current version. Nothing is sent to anyone.',
|
|
542
|
+
issue: { key: d.key, slot: d.slot, path: d.path, title: d.title || name } });
|
|
543
|
+
}
|
|
533
544
|
// honest state (round 3 point 13): closed or done, with open tasks, is a contradiction PMOS asks about
|
|
534
545
|
const nOpen = (v.tasks || {}).open || 0;
|
|
535
546
|
if ((r.closed || r.ended || r.status === 'done') && nOpen > 0) {
|
|
@@ -549,7 +560,8 @@ export function workOf(r, v, o = {}) {
|
|
|
549
560
|
const t = todayOf(o);
|
|
550
561
|
const sum = summaryOf(r, v, o), sug = suggestsOf(v), bd = breakdownOf(r, v, o), arts = artefactsOf(v, o);
|
|
551
562
|
const dv = derivedOf(r, v, o, bd, arts);
|
|
552
|
-
|
|
563
|
+
// a draft that waits to be issued comes first: the PM asked for it, and it is the one thing on the page only they can finish
|
|
564
|
+
const all = dv.top.filter((s) => s.issue).concat(sug.top, dv.top.filter((s) => !s.issue)), rowS = new Map(sug.rows);
|
|
553
565
|
for (const [k, s] of dv.rows) if (!rowS.has(k)) rowS.set(k, s);
|
|
554
566
|
const dates = [r.start, r.end].concat(bd.rows.flatMap((x) => [x.start, x.end])).filter(Boolean);
|
|
555
567
|
const tk = trackOf(dates, o.mode || 'full', t), span = tk.span;
|
|
@@ -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
|
-
|
|
266
|
-
|
|
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
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* web → premium-vw-file.js openWebLink (a Google Doc or Confluence copy, or a Claude artifact's Open in Claude)
|
|
5
5
|
* jira → a ticket tab from the stored Jira readings (GET /api/jira/ticket); PMOS never reads Jira from here
|
|
6
6
|
* slack → a Slack tab with Open in Slack; PMOS stores no Slack message to show
|
|
7
|
-
*
|
|
7
|
+
* A file chip that is a core-document draft PMOS wrote or named (issue-from-chat) carries ✓ Issue beside it while the draft waits: the chip reads
|
|
8
|
+
* its state once (GET /api/core-docs/of), ✓ posts /api/core-docs/issue, and the toast's Undo posts /api/core-docs/unissue. Nothing is sent to
|
|
9
|
+
* anyone. That is the only write here. */
|
|
8
10
|
import { vwOpen, vwStyle } from './premium-viewer.js';
|
|
9
11
|
import { openChatFile, openWebLink } from './premium-vw-file.js';
|
|
10
12
|
import { slackUrl } from './chat-context.js';
|
|
@@ -21,10 +23,54 @@ const ref = (it) => (it.kind === 'file' ? it.path : it.kind === 'jira' ? it.key
|
|
|
21
23
|
|
|
22
24
|
/** The chip row under an answer. Pure. The first item is the main one: it is what opened by itself.
|
|
23
25
|
* Two or more things Claude only read fold into one "+N read" (batch 17 item 5): what it wrote or named stays in sight. */
|
|
24
|
-
const
|
|
26
|
+
const chip0 = (it, lead, sub, role = ' role="listitem"') => `<button type="button" class="ctxchip${lead ? ' lead' : ''}"${role} data-ctx="${esc(it.kind)}" data-ctx-ref="${esc(ref(it))}"${it.ts ? ` data-ctx-ts="${esc(it.ts)}"` : ''}${it.web ? ` data-ctx-web="${esc(it.web)}"` : ''} title="${esc(ref(it))}">${icon(it.kind)}<span><b>${esc(it.title)}</b><em>${esc(sub)}</em></span></button>`;
|
|
27
|
+
const OK = '<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>';
|
|
28
|
+
|
|
29
|
+
/* ── a core-document draft on a chip (issue-from-chat) ── */
|
|
30
|
+
const DOC_RE = /(?:^|\/)core-docs\/initiative-([A-Za-z0-9][A-Za-z0-9._-]{0,79})\/([A-Za-z0-9][A-Za-z0-9_-]{0,79})\/(\d{4}-\d{2}-\d{2}(?:-\d{1,2})?)\.md$/;
|
|
31
|
+
/** The draft a path names: { scope, key, slot }, or null. Pure. */
|
|
32
|
+
export function draftOf(p) { const m = DOC_RE.exec(String(p || '')); return m ? { scope: 'initiative:' + m[1], key: m[2], slot: m[3] } : null; }
|
|
33
|
+
const DST = new Map(); // ws|path → 'reading' | 'draft' | 'issued' | 'superseded' | 'dropped' | 'none'
|
|
34
|
+
const IO = { pmGet: null, pmPost: null, toast: null, redraw: null };
|
|
35
|
+
/** The page's reads and toast; home-chat.js sets them once. */
|
|
36
|
+
export function configure(o = {}) { Object.assign(IO, o); }
|
|
37
|
+
const SUB = { draft: 'Draft · waits for you to issue', issued: 'Issued', superseded: 'Older draft · a newer one replaces it', dropped: 'Dropped' };
|
|
38
|
+
function stateOf(it, ws) {
|
|
39
|
+
const k = (ws || '') + '|' + it.path;
|
|
40
|
+
if (!DST.has(k) && IO.pmGet) {
|
|
41
|
+
DST.set(k, 'reading');
|
|
42
|
+
IO.pmGet('/api/core-docs/of?path=' + encodeURIComponent(it.path) + (ws ? '&ws=' + encodeURIComponent(ws) : ''))
|
|
43
|
+
.then((r) => { DST.set(k, r && r.ok && r.doc ? r.doc.state : 'none'); if (IO.redraw && DST.get(k) !== 'none') IO.redraw(); })
|
|
44
|
+
.catch(() => DST.set(k, 'none'));
|
|
45
|
+
}
|
|
46
|
+
return DST.get(k) || '';
|
|
47
|
+
}
|
|
48
|
+
/** A chip; a draft PMOS wrote or named gets ✓ Issue beside it while it waits. Pure but for the one state read. */
|
|
49
|
+
export function chipHtml(it, lead, o = {}) {
|
|
50
|
+
const d = it.kind === 'file' && it.how !== 'read' && draftOf(it.path);
|
|
51
|
+
if (!d) return chip0(it, lead, it.sub);
|
|
52
|
+
const st = stateOf(it, o.ws);
|
|
53
|
+
if (st !== 'draft') return chip0(it, lead, SUB[st] || it.sub);
|
|
54
|
+
return `<span class="ctxdoc" role="listitem">${chip0(it, lead, SUB.draft, '')}<button type="button" class="ctxiss" data-ctx-issue="${esc(it.path)}" data-ctx-ws="${esc(o.ws || '')}" aria-label="Issue this draft. Nothing is sent to anyone" title="Issue it">${OK}</button></span>`;
|
|
55
|
+
}
|
|
56
|
+
/** ✓ on a draft's chip: issue it, then Undo in the toast. b: the ✓ button. */
|
|
57
|
+
export async function issuePress(b) {
|
|
58
|
+
const p = b.dataset.ctxIssue, ws = b.dataset.ctxWs || '', d = draftOf(p); if (!d || !IO.pmPost) return;
|
|
59
|
+
b.disabled = true;
|
|
60
|
+
const body = { ...(ws ? { ws } : {}), ...d }, k = ws + '|' + p;
|
|
61
|
+
const r = await IO.pmPost('/api/core-docs/issue', body).catch(() => null);
|
|
62
|
+
if (!r || r.ok === false) { b.disabled = false; DST.delete(k); if (IO.toast) IO.toast((r && r.error) || 'The draft was not issued.'); if (IO.redraw) IO.redraw(); return; }
|
|
63
|
+
DST.set(k, 'issued'); if (IO.redraw) IO.redraw();
|
|
64
|
+
const undo = async () => {
|
|
65
|
+
const u = await IO.pmPost('/api/core-docs/unissue', body).catch(() => null);
|
|
66
|
+
if (!u || u.ok === false) { if (IO.toast) IO.toast((u && u.error) || 'The undo did not land.'); return; }
|
|
67
|
+
DST.set(k, 'draft'); if (IO.redraw) IO.redraw();
|
|
68
|
+
};
|
|
69
|
+
try { const H = await import('./hi-pop.js'); H.undoToast('Issued. Nothing was sent to anyone.', undo); } catch { if (IO.toast) IO.toast('Issued. Nothing was sent to anyone.'); }
|
|
70
|
+
}
|
|
25
71
|
const OPEN = new Set(); // the folds the PM opened stay open when the conversation redraws
|
|
26
72
|
const foldId = (items) => items.map((it) => it.id || ref(it)).join('|');
|
|
27
|
-
export function chipsHtml(items) {
|
|
73
|
+
export function chipsHtml(items, o = {}) {
|
|
28
74
|
if (!items || !items.length) return '';
|
|
29
75
|
const read = items.filter((it) => it.how === 'read');
|
|
30
76
|
let shown = items, fold = [];
|
|
@@ -34,8 +80,8 @@ export function chipsHtml(items) {
|
|
|
34
80
|
fold = items.filter((it) => !shown.includes(it));
|
|
35
81
|
}
|
|
36
82
|
const id = fold.length ? foldId(fold) : '';
|
|
37
|
-
const more = fold.length ? `<details class="ctxmore" role="listitem" data-ctx-fold="${esc(id)}"${OPEN.has(id) ? ' open' : ''}><summary aria-label="${fold.length} more files and pages PMOS read">+${fold.length} read</summary><div class="ctxc">${fold.map((it) => chipHtml(it, false)).join('')}</div></details>` : '';
|
|
38
|
-
return `<div class="ctxc" role="list" aria-label="What PMOS worked with">${shown.map((it, i) => chipHtml(it, i === 0)).join('')}${more}</div>`;
|
|
83
|
+
const more = fold.length ? `<details class="ctxmore" role="listitem" data-ctx-fold="${esc(id)}"${OPEN.has(id) ? ' open' : ''}><summary aria-label="${fold.length} more files and pages PMOS read">+${fold.length} read</summary><div class="ctxc">${fold.map((it) => chipHtml(it, false, o)).join('')}</div></details>` : '';
|
|
84
|
+
return `<div class="ctxc" role="list" aria-label="What PMOS worked with">${shown.map((it, i) => chipHtml(it, i === 0, o)).join('')}${more}</div>`;
|
|
39
85
|
}
|
|
40
86
|
if (typeof document !== 'undefined') document.addEventListener('toggle', (e) => { const d = e.target; if (!d || !d.dataset || d.dataset.ctxFold == null) return; if (d.open) OPEN.add(d.dataset.ctxFold); else OPEN.delete(d.dataset.ctxFold); }, true);
|
|
41
87
|
/** An item from a chip's data attributes. */
|
package/workspace/server.js
CHANGED
|
@@ -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;
|