create-pmos 0.711.0 → 0.713.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 +88 -40
- package/payload/KIT-VERSION +1 -1
- package/payload/design-system/ui/README.md +1 -1
- package/payload/design-system/ui/components/State/README.md +21 -0
- package/payload/design-system/ui/components/State/preview.html +8 -0
- package/payload/design-system/ui/components/bundle.css +12 -0
- package/payload/design-system/ui/interactions.md +2 -0
- 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/bin/back-place-health.js +70 -0
- package/workspace/changelog.json +87 -2
- package/workspace/design-system/ui/README.md +1 -1
- package/workspace/design-system/ui/components/State/README.md +21 -0
- package/workspace/design-system/ui/components/State/preview.html +8 -0
- package/workspace/design-system/ui/components/bundle.css +12 -0
- package/workspace/design-system/ui/interactions.md +2 -0
- package/workspace/guide/breakdown.md +20 -1
- package/workspace/guide/claude-proposes.md +5 -1
- package/workspace/guide/cli.md +10 -1
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/initiatives-and-next-steps.md +13 -0
- package/workspace/guide/layout.md +10 -3
- package/workspace/guide/routine.md +10 -2
- package/workspace/guide/settings-and-switches.md +4 -0
- package/workspace/lib/briefing-premium-products.js +16 -2
- package/workspace/lib/changed-mark.js +34 -0
- package/workspace/lib/launch-cli.js +43 -5
- package/workspace/lib/launch-tiers.js +143 -0
- package/workspace/lib/needs-providers.js +1 -0
- package/workspace/lib/parked-cli.js +105 -0
- package/workspace/lib/parked-reasons.js +245 -0
- package/workspace/lib/pmos-verbs.js +4 -1
- package/workspace/lib/prefs-sync.js +138 -0
- package/workspace/lib/product-dots.js +60 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-briefing-premium.js +11 -1
- package/workspace/lib/routes-prefs.js +56 -0
- package/workspace/lib/routes-strategy-card.js +53 -0
- package/workspace/lib/routes-use-log.js +24 -3
- package/workspace/lib/routine-sentence.js +250 -0
- package/workspace/lib/strategy-card.js +133 -0
- package/workspace/lib/unused-controls.js +178 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/back-place.js +87 -0
- package/workspace/public/pm/bd-backlog.css +1 -1
- package/workspace/public/pm/bd-backlog.js +9 -3
- package/workspace/public/pm/bd-pop-ds.css +10 -0
- package/workspace/public/pm/bd-pop-ds.js +27 -3
- package/workspace/public/pm/bd-strategy.js +85 -0
- package/workspace/public/pm/bd-views.js +2 -1
- package/workspace/public/pm/changed-mark.css +7 -0
- package/workspace/public/pm/changed-mark.js +117 -0
- package/workspace/public/pm/cozy-home.css +7 -0
- package/workspace/public/pm/cozy-pick.css +12 -0
- package/workspace/public/pm/cozy-pop-work.css +10 -1
- package/workspace/public/pm/cozy-pop-work.js +201 -17
- package/workspace/public/pm/cozy-routine-job.js +50 -7
- package/workspace/public/pm/cozy-routine.css +2 -0
- package/workspace/public/pm/cozy-settings.js +21 -3
- package/workspace/public/pm/cozy-task-pop.css +7 -0
- package/workspace/public/pm/cozy-today-page.css +1 -0
- package/workspace/public/pm/cozy-viewer.css +1 -1
- package/workspace/public/pm/cozy-viewer.js +14 -2
- package/workspace/public/pm/cozy-vw-mtg.css +0 -2
- package/workspace/public/pm/cozy-vw.css +0 -1
- package/workspace/public/pm/home-app.js +21 -1
- package/workspace/public/pm/home-ask.js +19 -1
- package/workspace/public/pm/home-chat.js +16 -3
- package/workspace/public/pm/home-today.js +2 -0
- package/workspace/public/pm/ini-tasks.js +4 -1
- package/workspace/public/pm/komorebi.css +11 -0
- package/workspace/public/pm/prefs-sync.js +111 -0
- package/workspace/public/pm/premium-board.js +20 -2
- package/workspace/public/pm/premium-chart-tab.js +2 -1
- package/workspace/public/pm/premium-mtg-replay.js +4 -3
- package/workspace/public/pm/premium-report-read.js +5 -4
- package/workspace/public/pm/premium-report-tab.js +4 -3
- package/workspace/public/pm/premium-vw-backlog.css +2 -1
- package/workspace/public/pm/premium-vw-backlog.js +4 -3
- package/workspace/public/pm/premium-vw-cal.css +1 -2
- package/workspace/public/pm/premium-vw-cal.js +14 -13
- package/workspace/public/pm/premium-vw-copies.js +3 -2
- package/workspace/public/pm/premium-vw-copy.css +0 -3
- package/workspace/public/pm/premium-vw-mtg.js +12 -11
- package/workspace/public/pm/product-switcher.js +41 -0
- package/workspace/public/pm/report-orders-ui.js +2 -1
- package/workspace/public/pm/rp-parts.js +3 -2
- package/workspace/public/pm/state-blocks.js +36 -0
- package/workspace/public/pm/use-log.js +118 -1
- package/workspace/public/pm/work-select.js +92 -2
- package/workspace/public/pm/work-tree.js +70 -0
- package/workspace/public/premium-aud.html +1 -0
- package/workspace/public/premium-board.html +5 -0
- package/workspace/public/premium-buddy.html +1 -0
- package/workspace/public/premium-events.html +1 -0
- package/workspace/public/premium-goals.html +1 -0
- package/workspace/public/premium-intelligence.html +1 -0
- package/workspace/public/premium-library.html +1 -0
- package/workspace/public/premium-present.html +1 -0
- package/workspace/public/premium-rec.html +1 -0
- package/workspace/public/premium-routine.html +1 -0
- package/workspace/public/premium-viewer.html +1 -0
- package/workspace/public/premium-workflows.html +1 -0
- package/workspace/public/today.html +1 -0
- package/workspace/server.js +20 -0
- package/workspace/test-lists/back-place.json +9 -0
- package/workspace/test-lists/changed-mark.json +9 -0
- package/workspace/test-lists/launch-tiers.json +9 -0
- package/workspace/test-lists/parked-reasons.json +9 -0
- package/workspace/test-lists/prefs-follow-person.json +9 -0
- package/workspace/test-lists/product-switcher-dots.json +9 -0
- package/workspace/test-lists/routine-sentence.json +9 -0
- package/workspace/test-lists/shared-empty-states.json +9 -0
- package/workspace/test-lists/strategy-card.json +9 -0
- package/workspace/test-lists/unused-controls.json +9 -0
- package/workspace/test-lists/work-subtasks-followups.json +9 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* parked-reasons.js — parked work keeps a reason and a way back (bet A446, initiative parked-reason-way-back).
|
|
4
|
+
*
|
|
5
|
+
* A parked initiative is one whose LATEST lifecycle line (D70, lifecycle.jsonl) is `on-hold`. This module reads why it is parked, what
|
|
6
|
+
* brings it back, and whether that has happened; it writes the hold and the return; and it is the needs provider that puts one Today card
|
|
7
|
+
* per parked initiative whose way back is met (lib/needs-providers.js). Works on any product built with PMOS, in either layout.
|
|
8
|
+
*
|
|
9
|
+
* reasonKind(text) → 'waiting' | 'evidence' | 'crowded' | 'other' | 'none'
|
|
10
|
+
* parkedOf(root, { today }) → { file, parked: [{ id, title, reason, kind, at, back, after, afterTitle, met }] }
|
|
11
|
+
* met = { why } | null
|
|
12
|
+
* hold(root, { id, why, back, after }, { now, by, via }) → { ok, file, line } | { ok: false, error }
|
|
13
|
+
* bringBack(root, { id }, { now, by, via }) → { ok, file, line } | { ok: false, error }
|
|
14
|
+
* coverage(root) → { parked, explained, pct }
|
|
15
|
+
* broughtBack(root, { days, now }) → number of `active` lines with way_back: true in the last `days` days
|
|
16
|
+
* needs provider: kinds ['parked-back'] · rowsFor(w, { lead }) · sig(w)
|
|
17
|
+
* CLI: node lib/parked-reasons.js coverage <root> the health number, on its last line
|
|
18
|
+
* node lib/parked-reasons.js brought <root> [--days N] the outcome number, on its last line
|
|
19
|
+
*
|
|
20
|
+
* THE WAY BACK. A hold names it in one of three ways, read in this order:
|
|
21
|
+
* back a day (YYYY-MM-DD): met when today is that day or later (the field the Board's hold already writes)
|
|
22
|
+
* after an initiative id: met when that initiative's latest lifecycle line is closed or cancelled, or it has an acceptance line
|
|
23
|
+
* the reason itself: an initiative id of this repository named after "waiting on", "after", "until", "blocked by" or "depends on"
|
|
24
|
+
* reads as `after`, so an older hold that says "waiting on checkout-v2" gets its way back with no new field.
|
|
25
|
+
* A hold with none of these has no way back; `pmos parked list` says so, and it never makes a card.
|
|
26
|
+
*
|
|
27
|
+
* Every line this module writes carries `[parked]` in what the CLI prints (the health log text). Nothing is sent. */
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
const path = require('path');
|
|
30
|
+
|
|
31
|
+
const NAME = 'parked-reasons';
|
|
32
|
+
const FILE = 'lifecycle.jsonl';
|
|
33
|
+
const DAY = 864e5;
|
|
34
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
35
|
+
const ID_RE = /^[a-z0-9][a-z0-9._-]*$/i;
|
|
36
|
+
const STOPPED = new Set(['closed', 'on-hold', 'cancelled']);
|
|
37
|
+
const DONE = new Set(['closed', 'cancelled']);
|
|
38
|
+
const TAG = '[parked]';
|
|
39
|
+
|
|
40
|
+
const todayOf = (now = Date.now()) => new Date(now).toISOString().slice(0, 10);
|
|
41
|
+
const clip = (s, n) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
|
|
42
|
+
const rel = (root, f) => path.relative(root, f).split(path.sep).join('/');
|
|
43
|
+
const isDir = (p) => { try { return fs.statSync(p).isDirectory(); } catch { return false; } };
|
|
44
|
+
|
|
45
|
+
/** Where this repository keeps its initiatives and ledgers (the layout scripts/workflow-state.js and POST /api/lifecycle use). */
|
|
46
|
+
function layoutOf(root) {
|
|
47
|
+
root = path.resolve(root);
|
|
48
|
+
if (isDir(path.join(root, 'planning', 'initiatives'))) return { initiatives: path.join(root, 'planning', 'initiatives'), runs: path.join(root, 'planning', 'runs') };
|
|
49
|
+
if (isDir(path.join(root, 'pmos', 'state', 'initiatives'))) return { initiatives: path.join(root, 'pmos', 'state', 'initiatives'), runs: path.join(root, 'pmos', 'state') };
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function jsonl(file) {
|
|
54
|
+
let text = '';
|
|
55
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
56
|
+
const out = [];
|
|
57
|
+
for (const l of text.split('\n')) { if (!l.trim()) continue; try { const r = JSON.parse(l); if (r && typeof r === 'object') out.push(r); } catch { /* a torn line */ } }
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The initiatives of this repository: Map id → title (the file name is the id; `id:` in the frontmatter wins). */
|
|
62
|
+
function initiativesOf(L) {
|
|
63
|
+
const out = new Map();
|
|
64
|
+
let files = [];
|
|
65
|
+
try { files = fs.readdirSync(L.initiatives).filter((f) => f.endsWith('.md')); } catch { return out; }
|
|
66
|
+
for (const f of files) {
|
|
67
|
+
let head = '';
|
|
68
|
+
try { head = fs.readFileSync(path.join(L.initiatives, f), 'utf8').slice(0, 4000); } catch { continue; }
|
|
69
|
+
const fm = /^---\n([\s\S]*?)\n---/.exec(head);
|
|
70
|
+
const get = (k) => { const m = fm && new RegExp('^' + k + ':\\s*(.*)$', 'm').exec(fm[1]); return m ? m[1].trim().replace(/^["']|["']$/g, '') : ''; };
|
|
71
|
+
const id = get('id') || f.slice(0, -3);
|
|
72
|
+
out.set(id, get('title') || id);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Why it is parked, as one of five kinds. Order matters: "waiting on more data" is waiting, not evidence. */
|
|
78
|
+
function reasonKind(text) {
|
|
79
|
+
const t = String(text || '').toLowerCase().trim();
|
|
80
|
+
if (!t) return 'none';
|
|
81
|
+
if (/\b(waiting (on|for)|blocked (by|on)|depends on|dependent on|after|until|once)\b/.test(t)) return 'waiting';
|
|
82
|
+
if (/\b(low evidence|no evidence|not enough evidence|no data|not enough data|unproven|not proven|no signal|weak signal|needs? proof)\b/.test(t)) return 'evidence';
|
|
83
|
+
if (/\b(no capacity|capacity|bandwidth|other priorities|priorit\w*|crowded|not now|too many|focus|no time|no one|nobody)\b/.test(t)) return 'crowded';
|
|
84
|
+
return 'other';
|
|
85
|
+
}
|
|
86
|
+
const KIND_WORDS = { waiting: 'waiting on something', evidence: 'low evidence', crowded: 'crowded out', other: 'other', none: 'no reason given' };
|
|
87
|
+
|
|
88
|
+
/** An initiative id of this repository named in the reason after a waiting word. */
|
|
89
|
+
function afterFromReason(reason, ids, self) {
|
|
90
|
+
const t = String(reason || '');
|
|
91
|
+
const re = /\b(?:waiting (?:on|for)|blocked (?:by|on)|depends on|dependent on|after|until|once)\s+(?:the\s+)?([a-z0-9][a-z0-9._-]*)/gi;
|
|
92
|
+
let m;
|
|
93
|
+
while ((m = re.exec(t))) { const id = m[1].replace(/[.]+$/, ''); if (id !== self && ids.has(id)) return id; }
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Latest lifecycle line per id, and the ids with an acceptance line. */
|
|
98
|
+
function foldOf(L) {
|
|
99
|
+
const latest = new Map();
|
|
100
|
+
for (const r of jsonl(path.join(L.runs, FILE))) {
|
|
101
|
+
if (typeof r.initiative_id !== 'string') continue;
|
|
102
|
+
if (r.state !== 'active' && !STOPPED.has(r.state)) continue;
|
|
103
|
+
latest.set(r.initiative_id, r);
|
|
104
|
+
}
|
|
105
|
+
const accepted = new Set();
|
|
106
|
+
for (const a of jsonl(path.join(L.runs, 'acceptances.jsonl'))) if (typeof a.initiative_id === 'string' && a.accepted !== false) accepted.add(a.initiative_id);
|
|
107
|
+
return { latest, accepted };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function parkedOf(root, { today = todayOf() } = {}) {
|
|
111
|
+
root = path.resolve(root);
|
|
112
|
+
const L = layoutOf(root);
|
|
113
|
+
if (!L) return { file: null, parked: [] };
|
|
114
|
+
const titles = initiativesOf(L);
|
|
115
|
+
const { latest, accepted } = foldOf(L);
|
|
116
|
+
const parked = [];
|
|
117
|
+
for (const [id, r] of latest) {
|
|
118
|
+
if (r.state !== 'on-hold') continue;
|
|
119
|
+
const reason = String(r.reason || '').trim();
|
|
120
|
+
const back = DATE.test(r.back || '') ? r.back : null;
|
|
121
|
+
const after = (typeof r.after === 'string' && r.after && r.after !== id ? r.after : null) || afterFromReason(reason, titles, id);
|
|
122
|
+
let met = null;
|
|
123
|
+
if (back && back <= today) met = { why: `its return day ${back} came` };
|
|
124
|
+
else if (after) {
|
|
125
|
+
const a = latest.get(after);
|
|
126
|
+
const afterTitle = titles.get(after) || after;
|
|
127
|
+
if (accepted.has(after)) met = { why: `${afterTitle} is done` };
|
|
128
|
+
else if (a && DONE.has(a.state)) met = { why: `${afterTitle} was ${a.state}` };
|
|
129
|
+
}
|
|
130
|
+
parked.push({ id, title: titles.get(id) || id, reason, kind: reasonKind(reason), at: r.at || null, back, after,
|
|
131
|
+
afterTitle: after ? titles.get(after) || after : null, met });
|
|
132
|
+
}
|
|
133
|
+
parked.sort((x, y) => (!!y.met - !!x.met) || String(x.at || '').localeCompare(String(y.at || '')) || x.id.localeCompare(y.id));
|
|
134
|
+
return { file: rel(root, path.join(L.runs, FILE)), parked };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The way back in words, or '' when the hold names none. */
|
|
138
|
+
function wayBackWords(p) {
|
|
139
|
+
const parts = [];
|
|
140
|
+
if (p.back) parts.push(`on ${p.back}`);
|
|
141
|
+
if (p.after) parts.push(`when ${p.afterTitle && p.afterTitle !== p.after ? `${p.afterTitle} (${p.after})` : p.after} is done`);
|
|
142
|
+
return parts.join(', or ');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function append(root, L, line) {
|
|
146
|
+
const file = path.join(L.runs, FILE);
|
|
147
|
+
try {
|
|
148
|
+
fs.mkdirSync(L.runs, { recursive: true });
|
|
149
|
+
const st = (() => { try { return fs.lstatSync(file); } catch { return null; } })();
|
|
150
|
+
if (st && !st.isFile()) return { ok: false, error: 'the lifecycle ledger is not a plain file — nothing was saved' };
|
|
151
|
+
fs.appendFileSync(file, JSON.stringify(line) + '\n');
|
|
152
|
+
return { ok: true, file: rel(root, file), line };
|
|
153
|
+
} catch (e) { return { ok: false, error: 'the lifecycle ledger could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
154
|
+
}
|
|
155
|
+
function pmSlug() { try { return require('./actor.js').PM_SLUG || 'pm'; } catch { return 'pm'; } }
|
|
156
|
+
|
|
157
|
+
/** Park an initiative with its reason and its way back. One `on-hold` line. */
|
|
158
|
+
function hold(root, { id, why, back, after } = {}, { now = Date.now(), by, via } = {}) {
|
|
159
|
+
root = path.resolve(root);
|
|
160
|
+
const L = layoutOf(root);
|
|
161
|
+
if (!L) return { ok: false, error: 'this folder has no initiatives (planning/initiatives or pmos/state/initiatives)' };
|
|
162
|
+
if (!ID_RE.test(String(id || ''))) return { ok: false, error: 'name the initiative by its id' };
|
|
163
|
+
const ids = initiativesOf(L);
|
|
164
|
+
if (!ids.has(id)) return { ok: false, error: `no initiative ${id} here` };
|
|
165
|
+
const reason = String(why || '').replace(/\s+/g, ' ').trim();
|
|
166
|
+
if (!reason) return { ok: false, error: 'say why it is parked (--why "<reason>")' };
|
|
167
|
+
if (reason.length > 500) return { ok: false, error: 'keep the reason under 500 characters' };
|
|
168
|
+
if (back != null && back !== '' && !DATE.test(String(back))) return { ok: false, error: 'the return day is YYYY-MM-DD' };
|
|
169
|
+
if (after != null && after !== '') {
|
|
170
|
+
if (after === id) return { ok: false, error: 'an initiative cannot wait on itself' };
|
|
171
|
+
if (!ids.has(after)) return { ok: false, error: `no initiative ${after} here to wait on` };
|
|
172
|
+
}
|
|
173
|
+
return append(root, L, { initiative_id: id, state: 'on-hold', reason, ...(back ? { back: String(back) } : {}), ...(after ? { after } : {}),
|
|
174
|
+
pm: pmSlug(), by: by || 'agent:unknown', via: via || 'cli', at: new Date(now).toISOString() });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Bring a parked initiative back. One `active` line marked as brought back through its way back. */
|
|
178
|
+
function bringBack(root, { id } = {}, { now = Date.now(), by, via } = {}) {
|
|
179
|
+
root = path.resolve(root);
|
|
180
|
+
const L = layoutOf(root);
|
|
181
|
+
if (!L) return { ok: false, error: 'this folder has no initiatives (planning/initiatives or pmos/state/initiatives)' };
|
|
182
|
+
const p = parkedOf(root, { today: todayOf(now) }).parked.find((x) => x.id === id);
|
|
183
|
+
if (!p) return { ok: false, error: `${id} is not on hold (pmos parked list shows what is)` };
|
|
184
|
+
const reason = p.met ? `Brought back: ${p.met.why}` : 'Brought back before its way back was met';
|
|
185
|
+
return append(root, L, { initiative_id: id, state: 'active', reason, way_back: !!p.met, pm: pmSlug(), by: by || 'agent:unknown', via: via || 'cli',
|
|
186
|
+
at: new Date(now).toISOString() });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The health number: how many parked initiatives say why AND name a way back. */
|
|
190
|
+
function coverage(root) {
|
|
191
|
+
const { parked } = parkedOf(root);
|
|
192
|
+
const explained = parked.filter((p) => p.reason && (p.back || p.after)).length;
|
|
193
|
+
return { parked: parked.length, explained, pct: parked.length ? Math.round((explained / parked.length) * 100) : 100 };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The outcome number: initiatives brought back through their way back in the last `days` days. */
|
|
197
|
+
function broughtBack(root, { days = 7, now = Date.now() } = {}) {
|
|
198
|
+
const L = layoutOf(root);
|
|
199
|
+
if (!L) return 0;
|
|
200
|
+
const since = now - days * DAY;
|
|
201
|
+
return jsonl(path.join(L.runs, FILE)).filter((r) => r.state === 'active' && r.way_back === true && Date.parse(r.at) >= since).length;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/* ── the needs provider (lib/needs-providers.js): one Today card per parked initiative whose way back is met ─────────────── */
|
|
205
|
+
function rowsFor(w, { lead } = {}) {
|
|
206
|
+
if (!lead || !w || !w.root) return [];
|
|
207
|
+
const { file, parked } = parkedOf(w.root);
|
|
208
|
+
return parked.filter((p) => p.met).map((p) => {
|
|
209
|
+
const cause = `Bring back ${clip(p.title, 80)}? ${p.met.why[0].toUpperCase() + p.met.why.slice(1)}. Parked because: ${p.reason ? clip(p.reason, 160) : 'no reason given'}.`;
|
|
210
|
+
return {
|
|
211
|
+
run_id: `${NAME}:${w.id}:${p.id}`, kind: 'parked-back', initiative_id: p.id, question: cause, doc: file, ws: w.id,
|
|
212
|
+
today: { kind: 7, source: NAME, cause, evidence: `${file} · on hold since ${String(p.at || '').slice(0, 10) || 'an unknown day'}`,
|
|
213
|
+
act: { label: 'Bring back', cli: `pmos parked back ${p.id}` } },
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// the date is in the signature: a return day comes at midnight with no change to the ledger
|
|
218
|
+
function sig(w) {
|
|
219
|
+
if (!w || !w.root) return '';
|
|
220
|
+
const L = layoutOf(w.root);
|
|
221
|
+
if (!L) return 'none';
|
|
222
|
+
const parts = [FILE, 'acceptances.jsonl'].map((f) => { try { const st = fs.statSync(path.join(L.runs, f)); return st.size + ':' + st.mtimeMs; } catch { return '-'; } });
|
|
223
|
+
return parts.join('|') + '@' + todayOf();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
module.exports = { kinds: ['parked-back'], rowsFor, sig, NAME, TAG, KIND_WORDS, reasonKind, parkedOf, wayBackWords, hold, bringBack, coverage, broughtBack, layoutOf, todayOf };
|
|
227
|
+
|
|
228
|
+
if (require.main === module) {
|
|
229
|
+
const [cmd, rootArg, ...rest] = process.argv.slice(2);
|
|
230
|
+
const root = path.resolve(rootArg || '.');
|
|
231
|
+
if (cmd === 'coverage') {
|
|
232
|
+
const c = coverage(root);
|
|
233
|
+
console.log(`${TAG} ${c.explained} of ${c.parked} parked initiatives say why and what brings them back`);
|
|
234
|
+
console.log(String(c.pct));
|
|
235
|
+
} else if (cmd === 'brought') {
|
|
236
|
+
const i = rest.indexOf('--days');
|
|
237
|
+
const days = i >= 0 ? Math.max(1, parseInt(rest[i + 1], 10) || 7) : 7;
|
|
238
|
+
const n = broughtBack(root, { days });
|
|
239
|
+
console.log(`${TAG} ${n} parked initiatives brought back through their way back in the last ${days} days`);
|
|
240
|
+
console.log(String(n));
|
|
241
|
+
} else {
|
|
242
|
+
console.log('usage: node lib/parked-reasons.js coverage <root> | brought <root> [--days N]');
|
|
243
|
+
process.exitCode = 2;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -59,7 +59,7 @@ const VERBS = Object.freeze({
|
|
|
59
59
|
help: 'pmos calendar import|status — the calendar events an agent session read, saved for Briefing and Calendar (pmos calendar help)' }),
|
|
60
60
|
// Not a pm-os-absorb verb (run: null): launch-readiness-check added it through the same table.
|
|
61
61
|
launch: Object.freeze({ module: 'launch-cli.js', run: null, guide: 'cli.md',
|
|
62
|
-
help: 'pmos launch check|list — what is not ready before a launch date
|
|
62
|
+
help: 'pmos launch check|list|tier — what is not ready before a launch date, and the launch tier with its steps (pmos launch help)' }),
|
|
63
63
|
// Not a pm-os-absorb verb (run: null): ready-for-engineering-check added it through the same table.
|
|
64
64
|
ready: Object.freeze({ module: 'ready-cli.js', run: null, guide: 'cli.md',
|
|
65
65
|
help: 'pmos ready check|list — is an initiative ready for engineering: problem, done test, design for every state, open questions, sign-offs (pmos ready help)' }),
|
|
@@ -139,6 +139,9 @@ const VERBS = Object.freeze({
|
|
|
139
139
|
// Not a pm-os-absorb verb (run: null): initiative decision-journal-outcome-checks added it through the same table.
|
|
140
140
|
decisions: Object.freeze({ module: 'decisions-cli.js', run: null, guide: 'cli.md',
|
|
141
141
|
help: 'pmos decisions add|list|show|check|record — a decision journal: what you decided, what you expect, a date to check, and how your calls turned out (pmos decisions help)' }),
|
|
142
|
+
// Not a pm-os-absorb verb (run: null): initiative parked-reason-way-back (bet A446) added it through the same table.
|
|
143
|
+
parked: Object.freeze({ module: 'parked-cli.js', run: null, guide: 'cli.md',
|
|
144
|
+
help: 'pmos parked list|hold|back|coverage — parked initiatives: why each is parked, what brings it back, and bringing it back (pmos parked help)' }),
|
|
142
145
|
// Not a pm-os-absorb verb (run: null): chief-unit-owners (Wawan 2026-11-18) added both through the same table.
|
|
143
146
|
units: Object.freeze({ module: 'units-cli.js', run: null, guide: 'cli.md',
|
|
144
147
|
help: 'pmos units [list|show <unit>] — the programs, products and projects, who owns each initiative, and each owner\'s brief (pmos units help)' }),
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* prefs-sync.js — view preferences that follow the person, not the browser (bet A461, initiative prefs-follow-person).
|
|
4
|
+
* THE ONE WRITER of <runtime>/view-prefs.json. lib/routes-prefs.js does the HTTP; public/pm/prefs-sync.js is the page side.
|
|
5
|
+
*
|
|
6
|
+
* WHY. About 40 view choices (theme, the Work and Board views, columns, folds, filters, scopes) were kept in one browser's localStorage
|
|
7
|
+
* only, so the phone and a second browser started from scratch. The workspace server runs on the user's own computer and the phone
|
|
8
|
+
* reaches that same server, so the person's copy lives in the server's runtime folder. NOTHING LEAVES THE COMPUTER.
|
|
9
|
+
*
|
|
10
|
+
* WHAT FOLLOWS. Only the keys in KEYS: view choices. Drafts, caches, "seen" markers and panel sizes stay in each browser (a panel
|
|
11
|
+
* width that fits a desk does not fit a phone). A key is allowed when it is in KEYS.exact or starts with one of KEYS.prefix.
|
|
12
|
+
*
|
|
13
|
+
* THE FILE. { v: 1, prefs: { <key>: { v: <string> | null, at: <ms> } }, followed: [{ at, device, n }] }, mode 0600, written through a
|
|
14
|
+
* temporary file and a rename. The later `at` wins, so two devices never fight; `v: null` means the person removed the value.
|
|
15
|
+
* `followed` notes each page open that took at least one value from here (the health number); it keeps KEEP_DAYS days.
|
|
16
|
+
*
|
|
17
|
+
* allowed(key) → boolean PURE
|
|
18
|
+
* off(env) → boolean PMOS_PREFS_SYNC=off (or 0, false, no) turns the whole thing off
|
|
19
|
+
* read(dir) → { prefs, followed } a file that cannot be read counts as empty
|
|
20
|
+
* values(dir) → { <key>: { v, at } }
|
|
21
|
+
* apply(dir, body, now) → { ok, wrote, refused } | { ok: false, error }
|
|
22
|
+
* body = { set: { <key>: { v, at } }, followed?: <n>, device?: phone|tablet|desk }
|
|
23
|
+
* count(dir, now) → the page opens in the last KEEP_DAYS days that took a value from the store
|
|
24
|
+
* CLI: node lib/prefs-sync.js count [--root <runtime>] → the count on its last line (the health number) */
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
|
|
28
|
+
const FILE = 'view-prefs.json';
|
|
29
|
+
const MAX_VALUE = 8192;
|
|
30
|
+
const MAX_KEYS = 300;
|
|
31
|
+
const MAX_FOLLOWED = 500;
|
|
32
|
+
const KEEP_DAYS = 30;
|
|
33
|
+
const DAY = 864e5;
|
|
34
|
+
const SKEW = 60e3; // a device clock a minute ahead is still believed; further ahead is cut to now
|
|
35
|
+
const DEVICES = ['phone', 'tablet', 'desk'];
|
|
36
|
+
|
|
37
|
+
/* View choices only. A new view choice that should follow the person is added here; nothing else needs to change. */
|
|
38
|
+
const KEYS = Object.freeze({
|
|
39
|
+
exact: Object.freeze([
|
|
40
|
+
'pmos.c3.theme', 'pmos.adler',
|
|
41
|
+
'pmos.work.view.3', 'pmos.work.sprint', 'pmos.work.classic', 'pmos.work.backlog',
|
|
42
|
+
'pmos.backlog.view', 'pmos.backlog.prefs',
|
|
43
|
+
'pmos.tasks.view', 'pmos.tasks.zoom', 'pmos.tasks.cols.timeline',
|
|
44
|
+
'pmos.goals.filt', 'pmos.goals.cols',
|
|
45
|
+
'pmos.lib.view', 'pmos.srl.view',
|
|
46
|
+
'pmos.events.scope.v1', 'pmos.events.hide.v2', 'pmos.events.show',
|
|
47
|
+
'pmos.routine.kind', 'pmos.routine.scope.v1',
|
|
48
|
+
'pmos.intel.tiles.off', 'pmos.guide.folded', 'pmos.order.notnow', 'pmos.listen.where',
|
|
49
|
+
'pmos.home.cardfold', 'pmos-report-orders-hidden', 'cz-live-side',
|
|
50
|
+
]),
|
|
51
|
+
prefix: Object.freeze(['pmos.board.', 'pmos.pv.tab:', 'pmos.dash.view:', 'cz-vw-fold:']),
|
|
52
|
+
});
|
|
53
|
+
const EXACT = new Set(KEYS.exact);
|
|
54
|
+
|
|
55
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
56
|
+
const say = (s) => { try { console.log('[prefs-follow-person] ' + s); } catch { /* no console */ } };
|
|
57
|
+
|
|
58
|
+
function allowed(key) {
|
|
59
|
+
if (typeof key !== 'string' || !key || key.length > 120) return false;
|
|
60
|
+
if (EXACT.has(key)) return true;
|
|
61
|
+
return KEYS.prefix.some((p) => key.length > p.length && key.startsWith(p));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function off(env = process.env) { return ['off', '0', 'false', 'no'].includes(String((env && env.PMOS_PREFS_SYNC) || '').trim().toLowerCase()); }
|
|
65
|
+
|
|
66
|
+
function file(dir) { return dir ? path.join(dir, FILE) : null; }
|
|
67
|
+
|
|
68
|
+
function read(dir) {
|
|
69
|
+
const f = file(dir);
|
|
70
|
+
let j = null;
|
|
71
|
+
try { j = f ? JSON.parse(fs.readFileSync(f, 'utf8')) : null; } catch { j = null; }
|
|
72
|
+
const prefs = {};
|
|
73
|
+
if (isObj(j) && isObj(j.prefs)) {
|
|
74
|
+
for (const [k, e] of Object.entries(j.prefs)) {
|
|
75
|
+
if (allowed(k) && isObj(e) && Number.isFinite(e.at) && (e.v === null || typeof e.v === 'string')) prefs[k] = { v: e.v, at: e.at };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const followed = isObj(j) && Array.isArray(j.followed) ? j.followed.filter((x) => isObj(x) && typeof x.at === 'string' && Number.isFinite(x.n)) : [];
|
|
79
|
+
return { prefs, followed };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function values(dir) { return read(dir).prefs; }
|
|
83
|
+
|
|
84
|
+
function write(dir, data) {
|
|
85
|
+
const f = file(dir);
|
|
86
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
87
|
+
const tmp = f + '.' + process.pid + '.' + Date.now() + '.tmp';
|
|
88
|
+
fs.writeFileSync(tmp, JSON.stringify({ v: 1, prefs: data.prefs, followed: data.followed }), { mode: 0o600 });
|
|
89
|
+
fs.renameSync(tmp, f);
|
|
90
|
+
try { fs.chmodSync(f, 0o600); } catch { /* a file system without modes */ }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function apply(dir, body, now = Date.now()) {
|
|
94
|
+
if (!dir) return { ok: false, error: 'This workspace has no runtime folder, so preferences are not kept.' };
|
|
95
|
+
if (!isObj(body)) return { ok: false, error: 'the body must be an object' };
|
|
96
|
+
const set = body.set == null ? {} : body.set;
|
|
97
|
+
if (!isObj(set)) return { ok: false, error: 'set must be an object of key → { v, at }' };
|
|
98
|
+
const n = body.followed == null ? 0 : Number(body.followed);
|
|
99
|
+
if (!Number.isInteger(n) || n < 0 || n > MAX_KEYS) return { ok: false, error: 'followed must be a whole number' };
|
|
100
|
+
const cur = read(dir);
|
|
101
|
+
const refused = [];
|
|
102
|
+
let wrote = 0;
|
|
103
|
+
for (const [k, e] of Object.entries(set)) {
|
|
104
|
+
if (!allowed(k)) { refused.push({ key: String(k).slice(0, 120), why: 'not a view preference' }); continue; }
|
|
105
|
+
if (!isObj(e) || !(e.v === null || typeof e.v === 'string') || !Number.isFinite(e.at)) { refused.push({ key: k, why: 'needs { v: text or null, at: time }' }); continue; }
|
|
106
|
+
if (typeof e.v === 'string' && e.v.length > MAX_VALUE) { refused.push({ key: k, why: `longer than ${MAX_VALUE} characters` }); continue; }
|
|
107
|
+
const at = Math.min(e.at, now + SKEW);
|
|
108
|
+
const had = cur.prefs[k];
|
|
109
|
+
if (had && had.at >= at) continue; // an older or equal write: the person's later choice stands
|
|
110
|
+
if (!had && Object.keys(cur.prefs).length >= MAX_KEYS) { refused.push({ key: k, why: `the store already keeps ${MAX_KEYS} preferences` }); continue; }
|
|
111
|
+
cur.prefs[k] = { v: e.v, at };
|
|
112
|
+
wrote++;
|
|
113
|
+
}
|
|
114
|
+
let followed = cur.followed.filter((x) => Date.parse(x.at) > now - KEEP_DAYS * DAY);
|
|
115
|
+
const pruned = followed.length !== cur.followed.length;
|
|
116
|
+
if (n > 0) followed.push({ at: new Date(now).toISOString(), device: DEVICES.includes(body.device) ? body.device : 'desk', n });
|
|
117
|
+
if (followed.length > MAX_FOLLOWED) followed = followed.slice(-MAX_FOLLOWED);
|
|
118
|
+
if (wrote || n > 0 || pruned) {
|
|
119
|
+
try { write(dir, { prefs: cur.prefs, followed }); } catch (e) { return { ok: false, error: 'could not save: ' + (e && e.message) }; }
|
|
120
|
+
say(`wrote ${wrote}, followed ${n}${n ? ' on ' + (DEVICES.includes(body.device) ? body.device : 'desk') : ''}, keeps ${Object.keys(cur.prefs).length}`);
|
|
121
|
+
}
|
|
122
|
+
return { ok: true, wrote, refused };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function count(dir, now = Date.now()) {
|
|
126
|
+
return read(dir).followed.filter((x) => Date.parse(x.at) > now - KEEP_DAYS * DAY && x.n > 0).length;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = { FILE, KEYS, MAX_VALUE, MAX_KEYS, KEEP_DAYS, allowed, off, file, read, values, apply, count };
|
|
130
|
+
|
|
131
|
+
if (require.main === module) {
|
|
132
|
+
const argv = process.argv.slice(2);
|
|
133
|
+
const i = argv.indexOf('--root');
|
|
134
|
+
const dir = i >= 0 ? argv[i + 1] : require('./state-root.js').defaultRoot({ env: process.env });
|
|
135
|
+
if (argv[0] === 'count') { console.log(count(dir)); process.exit(0); }
|
|
136
|
+
console.error('usage: node lib/prefs-sync.js count [--root <runtime folder>]');
|
|
137
|
+
process.exit(2);
|
|
138
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* product-dots.js — the product switcher's dots (bet A381, initiative product-switcher-dots). For each registered product: how many rows
|
|
4
|
+
* need the PM now, from the same rows that make Today's "needs you" count (lib/briefing-premium.js allRowsOf). The row that shows them is
|
|
5
|
+
* public/pm/product-switcher.js; the route is GET /api/briefing-premium/products?needs=1.
|
|
6
|
+
*
|
|
7
|
+
* needsIn(f, now, defers, product?) → n | null PURE. One product's read: its rows that need the PM, less those put off. null while pending.
|
|
8
|
+
* dotsOf({ available, now, factsOf, defers, log? }) → { [ws]: n | null } every registered product, ticked or not. null: not read yet.
|
|
9
|
+
* presses(lines, now) → n PURE. Presses of the switcher (control data-psw) in the use log, last 7 days.
|
|
10
|
+
* CLI: node lib/product-dots.js count → presses of the last 7 days on its last line (the health number)
|
|
11
|
+
*
|
|
12
|
+
* WHAT IS READ. A product that is on Home is asked with the Briefing's own age (5 minutes), so it costs nothing new. A product that is not
|
|
13
|
+
* on Home is read only for its dot, at most every 30 minutes, through the same one-read-at-a-time state (lib/briefing-premium-products.js
|
|
14
|
+
* factsOf). Nothing here writes a record or sends anything. A change in the dots writes one `[product-dots]` server log line. */
|
|
15
|
+
const BP = require('./briefing-premium.js');
|
|
16
|
+
const Prod = require('./briefing-premium-products.js');
|
|
17
|
+
|
|
18
|
+
const ON_MAX_AGE = Prod.STALE_MS;
|
|
19
|
+
const OFF_MAX_AGE = 30 * 60 * 1000;
|
|
20
|
+
const PRESS_DAYS = 7;
|
|
21
|
+
const CONTROL = 'data-psw';
|
|
22
|
+
const say = (line) => { try { console.log(line); } catch { /* no console */ } };
|
|
23
|
+
|
|
24
|
+
function needsIn(f, now, defers, product) {
|
|
25
|
+
if (!f || f.pending) return null;
|
|
26
|
+
const g = Object.assign({ initiatives: [], runs: [], merges: [], evals: [], tripwires: null, missing: [], protoDecided: [] }, f, { now, asOf: now, meetings: null, defers: defers || {} });
|
|
27
|
+
if (product) g.product = product;
|
|
28
|
+
return BP.allRowsOf(g).all.length;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let lastSig = null;
|
|
32
|
+
async function dotsOf({ available, now = Date.now(), factsOf, defers = {}, log = say }) {
|
|
33
|
+
const out = {};
|
|
34
|
+
for (const p of available || []) {
|
|
35
|
+
let f = null;
|
|
36
|
+
try { f = await factsOf(p, { maxAge: p.on ? ON_MAX_AGE : OFF_MAX_AGE }); } catch { f = null; }
|
|
37
|
+
out[p.ws] = needsIn(f, now, defers, { ws: p.ws, name: p.name });
|
|
38
|
+
}
|
|
39
|
+
const v = Object.values(out), sig = JSON.stringify(out);
|
|
40
|
+
if (sig !== lastSig) {
|
|
41
|
+
lastSig = sig;
|
|
42
|
+
log('[product-dots] ' + v.length + ' products, ' + v.filter((x) => x > 0).length + ' with a dot, ' + v.filter((x) => x === null).length + ' not read yet');
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
const forget = () => { lastSig = null; };
|
|
47
|
+
|
|
48
|
+
function presses(lines, now = Date.now()) {
|
|
49
|
+
const cut = now - PRESS_DAYS * 864e5;
|
|
50
|
+
return (lines || []).filter((l) => l && l.kind === 'use' && l.control === CONTROL && Date.parse(l.at) >= cut && Date.parse(l.at) <= now + 864e5).length;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { ON_MAX_AGE, OFF_MAX_AGE, CONTROL, needsIn, dotsOf, presses, forget };
|
|
54
|
+
|
|
55
|
+
if (require.main === module) {
|
|
56
|
+
if (process.argv[2] !== 'count') { console.error('usage: node lib/product-dots.js count (presses of the product switcher in the last ' + PRESS_DAYS + ' days)'); process.exit(2); }
|
|
57
|
+
const UL = require('./use-log.js');
|
|
58
|
+
const dir = require('./state-root.js').defaultRoot({ env: process.env });
|
|
59
|
+
console.log(String(presses(UL.readLines(dir))));
|
|
60
|
+
}
|
|
@@ -138,6 +138,8 @@ const MODULES = Object.freeze([
|
|
|
138
138
|
'routes-spec-critic', // spec-critic: the sceptical reviewer's hardest questions on a document before it is shared (runtime spec-critic.jsonl)
|
|
139
139
|
'routes-jira-epics', // work-subtasks: the epic check's fix, direct on tickets assigned to the PM, the day's draft for the rest (tracker/jira/epics.jsonl; page-press POST)
|
|
140
140
|
'routes-use-log', // bet A466: the local use log, page opens and controls pressed, on this computer only (runtime use-log.jsonl; page-press POST)
|
|
141
|
+
'routes-strategy-card', // bet A458: a product's five-line strategy above its Board, and the gentle "doesn't fit" note on new work (records strategy-card.jsonl; page-press POST)
|
|
142
|
+
'routes-prefs', // bet A461: view preferences that follow the person to the phone and other browsers (runtime view-prefs.json; page-press POST)
|
|
141
143
|
]);
|
|
142
144
|
const PM_DIR = path.join(__dirname, '..', 'public', 'pm');
|
|
143
145
|
const MODULE_NAME = /^[a-z0-9][a-z0-9-]*\.js$/;
|
|
@@ -27,6 +27,7 @@ const { correctionEvent } = require(repoScript('card-state.js'));
|
|
|
27
27
|
const { appendOutbox } = require(repoScript('outbox.js'));
|
|
28
28
|
|
|
29
29
|
const Prod = require('./briefing-premium-products.js');
|
|
30
|
+
const Dots = require('./product-dots.js');
|
|
30
31
|
const Src = require('./briefing-premium-sources.js');
|
|
31
32
|
const Drafts = require('./briefing-premium-drafts.js');
|
|
32
33
|
const settings = require('./settings-store.js');
|
|
@@ -327,7 +328,16 @@ module.exports = { grillAsk, liveAsk,
|
|
|
327
328
|
let def = null; try { def = ctx.getWs ? ctx.getWs(null) : null; } catch { def = null; }
|
|
328
329
|
// with no pick saved (the default), the workspace a page opens with stays ticked, as every page showed it before the pick
|
|
329
330
|
const pub = (sel) => { const chosen = Array.isArray(settings.get(ctx.runtimeDir, 'ws.briefing.include', null)); return { ok: true, all: !!sel.all, chosen, products: sel.available.map((a) => { const primary = !!def && def.id === a.ws; return { ws: a.ws, name: a.name, home: a.home, primary, initials: a.initials || null, on: a.on || (!chosen && primary) }; }) }; };
|
|
330
|
-
if (req.method === 'GET') {
|
|
331
|
+
if (req.method === 'GET') {
|
|
332
|
+
const sel = products(ctx), body = pub(sel);
|
|
333
|
+
// ?needs=1 (bet A381): each product's count of rows that need the PM, for the product switcher's dot (lib/product-dots.js); null: not read yet
|
|
334
|
+
if (url.searchParams.get('needs') === '1') {
|
|
335
|
+
const now = Date.now();
|
|
336
|
+
const d = await Dots.dotsOf({ available: sel.available.map((a, i) => ({ ...a, on: body.products[i].on })), now, defers: Object.fromEntries(Wr.readDefers(ctx.runtimeDir, now)), factsOf: (p, o) => Prod.factsOf(p, { engine: enginePath(), runtimeDir: ctx.runtimeDir, maxAge: o.maxAge }) });
|
|
337
|
+
body.products.forEach((p) => { p.needs = p.ws in d ? d[p.ws] : null; });
|
|
338
|
+
}
|
|
339
|
+
ctx.json(res, body); return true;
|
|
340
|
+
}
|
|
331
341
|
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'GET or POST only' }, 405); return true; }
|
|
332
342
|
const got = await ctx.readJson(req);
|
|
333
343
|
if (!got.ok || !got.body || typeof got.body !== 'object' || !Array.isArray(got.body.on)) { ctx.json(res, { ok: false, error: 'body must be JSON with on, the ticked workspace ids' }, 400); return true; }
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-prefs.js — view preferences that follow the person, over HTTP (bet A461, initiative prefs-follow-person). The store and its rules
|
|
3
|
+
* are lib/prefs-sync.js (<runtime>/view-prefs.json on this computer); the page side is public/pm/prefs-sync.js.
|
|
4
|
+
*
|
|
5
|
+
* GET /api/view-prefs/boot.js → text/javascript: the person's values, the allowlist, then public/pm/prefs-sync.js. Every page loads it
|
|
6
|
+
* first, right after the nonce meta, so the values are in this browser's storage before page code reads it.
|
|
7
|
+
* GET /api/view-prefs → { ok, on, keeps, followed }
|
|
8
|
+
* POST /api/view-prefs { set, followed, device } → { ok, wrote, refused } the page side, in batches
|
|
9
|
+
*
|
|
10
|
+
* NOTHING IS SENT ANYWHERE. A script load from another site (Sec-Fetch-Site cross-site or same-site) gets the script with no values, so
|
|
11
|
+
* another page cannot read the person's choices by including it. WHO WRITES: the person's own pages only (pm-guard requirePagePress: the
|
|
12
|
+
* page's Origin and launch nonce); a POST with an agent session header is refused. PMOS_PREFS_SYNC=off: no values, and a POST is refused. */
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const guard = require('./pm-guard.js');
|
|
16
|
+
const PS = require('./prefs-sync.js');
|
|
17
|
+
|
|
18
|
+
const PAGE_JS = path.join(__dirname, '..', 'public', 'pm', 'prefs-sync.js');
|
|
19
|
+
// JSON in a script: every `<` and line separator is written as a unicode escape, so no value can close the script element or open a comment.
|
|
20
|
+
const safe = (v) => JSON.stringify(v).replace(/</g, '\\u003c').replace(/[\u2028\u2029]/g, (c) => '\\u' + c.charCodeAt(0).toString(16));
|
|
21
|
+
|
|
22
|
+
function crossSite(req) {
|
|
23
|
+
const s = String((req.headers && req.headers['sec-fetch-site']) || '').toLowerCase();
|
|
24
|
+
return s === 'cross-site' || s === 'same-site';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function handle(req, res, url, ctx) {
|
|
28
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
29
|
+
const what = url.pathname.replace(/^\/api\/view-prefs\/?/, '');
|
|
30
|
+
const dir = ctx.runtimeDir || null;
|
|
31
|
+
const isOff = PS.off(process.env);
|
|
32
|
+
if (what === 'boot.js') {
|
|
33
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
|
|
34
|
+
let code = '';
|
|
35
|
+
try { code = fs.readFileSync(PAGE_JS, 'utf8'); } catch { code = ''; }
|
|
36
|
+
const vals = isOff || crossSite(req) ? {} : PS.values(dir);
|
|
37
|
+
const body = `window.__pmosViewPrefs=${safe(vals)};window.__pmosViewPrefsKeys=${safe(PS.KEYS)};window.__pmosViewPrefsOn=${isOff ? 'false' : 'true'};\n${code}`;
|
|
38
|
+
res.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' });
|
|
39
|
+
res.end(body);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (what !== '') return send(404, { ok: false, error: 'no such view-prefs route' });
|
|
43
|
+
if (req.method === 'GET') return send(200, { ok: true, on: !isOff, keeps: Object.keys(PS.values(dir)).length, followed: PS.count(dir) });
|
|
44
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
|
|
45
|
+
if (req.headers && req.headers['x-pmos-session']) return send(403, { ok: false, error: 'An agent session does not change view preferences. Only your own pages do.' });
|
|
46
|
+
if (isOff) return send(409, { ok: false, error: 'Preferences that follow you are off on this computer (PMOS_PREFS_SYNC=off).' });
|
|
47
|
+
const rd = await ctx.readJson(req);
|
|
48
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
49
|
+
const body = rd.body || {};
|
|
50
|
+
const g = guard.requirePagePress(req, body);
|
|
51
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
52
|
+
const r = PS.apply(dir, body);
|
|
53
|
+
return r.ok ? send(200, r) : send(r.error.startsWith('This workspace') ? 409 : 400, r);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { prefixes: ['/api/view-prefs'], handle };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-strategy-card.js — a product's five-line strategy over HTTP (bet A458, initiative strategy-five-lines). The card and its fit rule are
|
|
3
|
+
* lib/strategy-card.js; the file is strategy-card.jsonl in the product's records folder (lib/records-dir.js).
|
|
4
|
+
*
|
|
5
|
+
* GET /api/strategy-card?ws=<id>[&board=<id>] → { ok, card, labels, complete, notes } notes: null while the Board is still being read
|
|
6
|
+
* POST /api/strategy-card { ws, fields } → { ok, card, complete } | 400 when no known line is named
|
|
7
|
+
*
|
|
8
|
+
* The notes come from the Board's own backlog route (GET /api/boards/backlog, every view, the new-work stages), so they read the rows the Board draws.
|
|
9
|
+
* WHO WRITES. A page press: pm-guard requirePagePress checks the page's Origin and launch nonce. Nothing here is sent anywhere. */
|
|
10
|
+
const guard = require('./pm-guard.js');
|
|
11
|
+
const SC = require('./strategy-card.js');
|
|
12
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
13
|
+
|
|
14
|
+
/** GET a route module's own handler, as routes-board-premium.js does, and return { status, body }. */
|
|
15
|
+
async function via(mod, pathAndQuery, req, ctx) {
|
|
16
|
+
let out = { status: 500, body: null };
|
|
17
|
+
const c = Object.assign({}, ctx, { json: (res, obj, code) => { out = { status: code || 200, body: obj }; } });
|
|
18
|
+
const handled = await mod.handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, new URL('http://local' + pathAndQuery), c);
|
|
19
|
+
return handled === false ? { status: 404, body: null } : out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function rowsOf(req, ctx, ws, board) {
|
|
23
|
+
try {
|
|
24
|
+
// only the stages new work stands in (the old names too), so the 100-row page of the backlog route holds them all
|
|
25
|
+
const q = '?view=all&limit=100&stage=' + encodeURIComponent('Triage,Discover,Plan,Prioritize,Intake,Ideate,Strategize') + (ws ? '&ws=' + encodeURIComponent(ws) : '') + (board ? '&board=' + encodeURIComponent(board) : '');
|
|
26
|
+
const r = await via(require('./routes-boards.js'), '/api/boards/backlog' + q, req, ctx);
|
|
27
|
+
if (r.status !== 200 || !r.body || r.body.ok === false || r.body.pending) return null;
|
|
28
|
+
return Array.isArray(r.body.rows) ? r.body.rows : null;
|
|
29
|
+
} catch { return null; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function handle(req, res, url, ctx) {
|
|
33
|
+
if (url.pathname !== '/api/strategy-card') return false;
|
|
34
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
35
|
+
if (req.method === 'GET') {
|
|
36
|
+
const ws = url.searchParams.get('ws') || null;
|
|
37
|
+
const card = SC.read(recordsDirFor(ctx, ws));
|
|
38
|
+
const complete = SC.complete(card);
|
|
39
|
+
let notes = [];
|
|
40
|
+
if (complete) { const rows = ctx.strategyRows ? ctx.strategyRows : await rowsOf(req, ctx, ws, url.searchParams.get('board') || null); notes = rows ? SC.notes(card, rows) : null; }
|
|
41
|
+
return send(200, { ok: true, card, labels: SC.LABELS, complete, notes });
|
|
42
|
+
}
|
|
43
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
|
|
44
|
+
const rd = await ctx.readJson(req);
|
|
45
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
46
|
+
const body = rd.body || {};
|
|
47
|
+
const g = guard.requirePagePress(req, body);
|
|
48
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
49
|
+
const r = SC.save(recordsDirFor(ctx, body.ws || null), body.fields);
|
|
50
|
+
return r.ok ? send(200, { ok: true, card: r.card, complete: SC.complete(r.card) }) : send(400, { ok: false, error: r.error });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { prefixes: ['/api/strategy-card'], handle };
|