create-pmos 0.851.0 → 0.852.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/package.json +79 -105
  2. package/payload/AGENTS.md +63 -0
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/planning/evals/eval-calibration.md +1 -1
  5. package/payload/planning/okrs/health-budgets.md +1 -1
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/changelog.json +78 -22
  8. package/workspace/guide/cli.md +20 -0
  9. package/workspace/guide/initiatives-and-next-steps.md +11 -0
  10. package/workspace/guide/programs.md +1 -0
  11. package/workspace/lib/features.json +2 -0
  12. package/workspace/lib/knowledge-cli.js +6 -0
  13. package/workspace/lib/on-item-routes.js +68 -0
  14. package/workspace/lib/on-item.js +272 -0
  15. package/workspace/lib/one-person-knows.js +403 -0
  16. package/workspace/lib/pmos-verbs.js +6 -0
  17. package/workspace/lib/route-modules.js +2 -0
  18. package/workspace/lib/routes-capture.js +1 -1
  19. package/workspace/lib/routes-one-person-knows.js +40 -0
  20. package/workspace/lib/routes-screen-map.js +47 -0
  21. package/workspace/lib/routes-stage-signoffs.js +4 -1
  22. package/workspace/lib/screen-map.js +381 -0
  23. package/workspace/lib/signoffs.js +4 -1
  24. package/workspace/package-lock.json +2 -2
  25. package/workspace/package.json +1 -1
  26. package/workspace/public/pm/bd-prog-panel.js +25 -1
  27. package/workspace/public/pm/cozy-board.css +3 -0
  28. package/workspace/public/pm/cozy-pop-work.js +5 -2
  29. package/workspace/public/pm/home-app.js +5 -0
  30. package/workspace/public/pm/on-item.js +155 -0
  31. package/workspace/public/pm/one-person-knows.js +66 -0
  32. package/workspace/public/pm/premium-board.js +2 -0
  33. package/workspace/public/pm/screen-map.css +23 -0
  34. package/workspace/public/pm/screen-map.js +187 -0
  35. package/workspace/public/premium-board.html +2 -0
  36. package/workspace/test-lists/kit-agents-verbs.json +9 -0
  37. package/workspace/test-lists/one-person-knows.json +9 -0
  38. package/workspace/test-lists/screen-map.json +9 -0
  39. package/workspace/test-lists/surface-on-item.json +9 -0
@@ -0,0 +1,403 @@
1
+ 'use strict';
2
+ /* one-person-knows.js — the areas of a product that only one person knows (initiative one-person-knows, job #1899, idea A391). `pmos knowledge …`.
3
+ *
4
+ * A part of a product that one person alone has touched for months is a risk the PM sees only when that person is away. The git history
5
+ * and the task records already say who touched what; this adds it up. No model call; every row comes from a record. Nothing is sent.
6
+ *
7
+ * areasOf({ commits, tasks, titles, now, months }) PURE → { areas: [area], total, people: { git, jira } }
8
+ * commits [{ at (ms), name, email, files: [path] }] git log of the last `months` (bots and PMOS's own agent commits are left out)
9
+ * tasks [{ id, initiative, owner, at (ms) }] one row per task, `at` its last change (Jira-synced tasks included)
10
+ * An area is a folder (up to two levels, a leading src/lib/app/packages… skipped) or an initiative. It counts once it has MIN_TOUCH
11
+ * touches in the window; it is a one-person area when exactly one person made all of them. A source whose window holds fewer than
12
+ * two people flags nothing: a product one person builds alone has no "only one person" to point at.
13
+ * area = { key, label, source: 'git'|'jira', person, months, touches, group }
14
+ * suggestOf(area, { areas, commits, tasks, leaves, today }) PURE → { plan: 'pairing'|'writeup', partner, before } | null
15
+ * Only while the area's person has leave starting in the next LEAVE_DAYS. Pairing: the other person with the most touches in the same
16
+ * group (the folder's first part, or the git/Jira source); none: a short write-up.
17
+ * leavesOfEvents(events) PURE → leave read from the calendar by itself (an event titled leave, OOO, vacation…), so no typed ask is needed.
18
+ * fold(lines) PURE → { leaves: [{ person, from, until }], plans: Map(area key → plan) }
19
+ * view(root, { now, stateDir, git, tasks, leaves }) → { ok, areas: [area + suggest + plan], total }
20
+ * plan(root, key, { now, stateDir }) · undo(root, key, { now, stateDir }) · leave(stateDir, { person, from, until }, { now })
21
+ * CLI: pmos knowledge [list] | leave <person> <YYYY-MM-DD> [<YYYY-MM-DD>] | leave <person> --drop | plan <n> | undo <n> | count [--days N]
22
+ *
23
+ * THE LEDGER is knowledge.jsonl in the product's LOCAL state folder (lib/driver.js stateDirOf: pmos/state, gitignored), never in git:
24
+ * leave dates are about people. Lines: { at, kind: 'leave', person, from, until } · { at, kind: 'leave-drop', person }
25
+ * · { at, kind: 'plan', area, person, plan, partner, before, file? } · { at, kind: 'undo', area }.
26
+ * A write-up is a plain draft file under planning/knowledge/ (a kit: pmos/planning/knowledge/); PMOS runs no git command for it.
27
+ * Each plan logs [one-person-knows] and records the use-log control knowledgePlan, the count the kill reads. */
28
+ const fs = require('fs');
29
+ const path = require('path');
30
+
31
+ const TAG = '[one-person-knows]';
32
+ const MONTHS = 6;
33
+ const MIN_TOUCH = 3;
34
+ const LEAVE_DAYS = 14;
35
+ const LEDGER = 'knowledge.jsonl';
36
+ const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
37
+ const MONTH_MS = 30.44 * 864e5;
38
+ const CONTAINERS = new Set(['src', 'lib', 'app', 'apps', 'packages', 'services', 'modules', 'source', 'pkg', 'internal']);
39
+ const BOT = /\[bot\]|^claude$|noreply@anthropic\.com|github-actions|dependabot|renovate|^pmos$/i;
40
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
41
+ const short = (d) => (DAY_RE.test(String(d || '')) ? (+d.slice(8, 10)) + ' ' + MON[+d.slice(5, 7) - 1] : '');
42
+ const one = (s, n = 200) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
43
+ const key = (s) => one(s, 120).toLowerCase();
44
+ const localDay = (t = Date.now()) => { const d = new Date(t); return new Date(d.getTime() - d.getTimezoneOffset() * 60000).toISOString().slice(0, 10); };
45
+ const addDays = (day, n) => new Date(Date.parse(day + 'T00:00:00Z') + n * 864e5).toISOString().slice(0, 10);
46
+ const slug = (s) => key(s).replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 50) || 'area';
47
+ const isBot = (name, email) => BOT.test(one(name)) || BOT.test(one(email));
48
+
49
+ /** The folder area of a file path: up to two folders, a leading container (src, lib, …) skipped. null for a file at the top. */
50
+ function areaOfFile(file) {
51
+ const parts = String(file || '').split('/').filter(Boolean);
52
+ parts.pop(); // the file itself
53
+ while (parts.length > 1 && CONTAINERS.has(parts[0].toLowerCase())) parts.shift();
54
+ if (!parts.length || parts[0].startsWith('.')) return null;
55
+ return parts.slice(0, 2).join('/');
56
+ }
57
+
58
+ /** PURE. */
59
+ function areasOf({ commits = [], tasks = [], titles = {}, now = Date.now(), months = MONTHS } = {}) {
60
+ const from = now - months * MONTH_MS;
61
+ const A = new Map(); // key → { key, label, source, group, by: Map(person → { n, first }) }
62
+ const names = new Map(); // git email → { name → n }
63
+ const touch = (k, label, source, group, person, at) => {
64
+ if (!A.has(k)) A.set(k, { key: k, label, source, group, by: new Map() });
65
+ const a = A.get(k), b = a.by.get(person) || { n: 0, first: at };
66
+ b.n += 1; b.first = Math.min(b.first, at); a.by.set(person, b);
67
+ };
68
+ const gitPeople = new Set(), jiraPeople = new Set();
69
+ for (const c of commits || []) {
70
+ if (!c || !Number.isFinite(c.at) || c.at < from || c.at > now + 864e5) continue;
71
+ if (isBot(c.name, c.email)) continue;
72
+ const who = key(c.email) || key(c.name);
73
+ if (!who) continue;
74
+ const m = names.get(who) || {}; m[one(c.name, 80)] = (m[one(c.name, 80)] || 0) + 1; names.set(who, m);
75
+ gitPeople.add(who);
76
+ const seen = new Set();
77
+ for (const f of c.files || []) { const k = areaOfFile(f); if (k && !seen.has(k)) { seen.add(k); touch('git:' + k, k, 'git', 'git:' + k.split('/')[0], who, c.at); } }
78
+ }
79
+ for (const t of tasks || []) {
80
+ if (!t || !Number.isFinite(t.at) || t.at < from || t.at > now + 864e5) continue;
81
+ const who = key(t.owner);
82
+ if (!who || !t.initiative || isBot(t.owner, '')) continue;
83
+ jiraPeople.add(who);
84
+ touch('ini:' + t.initiative, one(titles[t.initiative] || t.initiative, 80), 'jira', 'jira', who, t.at);
85
+ }
86
+ const nameOf = (who, source) => {
87
+ if (source !== 'git') return who;
88
+ const m = names.get(who) || {};
89
+ return Object.keys(m).sort((a, b) => m[b] - m[a] || b.length - a.length)[0] || who;
90
+ };
91
+ const counted = [...A.values()].filter((a) => [...a.by.values()].reduce((s, b) => s + b.n, 0) >= MIN_TOUCH);
92
+ const many = { git: gitPeople.size >= 2, jira: jiraPeople.size >= 2 };
93
+ const areas = counted.filter((a) => a.by.size === 1 && many[a.source]).map((a) => {
94
+ const [who, b] = [...a.by.entries()][0];
95
+ const person = a.source === 'git' ? nameOf(who, 'git') : one([...(tasks || [])].find((t) => key(t.owner) === who).owner, 80);
96
+ return { key: a.key, label: a.label, source: a.source, group: a.group, who, person, touches: b.n,
97
+ months: Math.max(1, Math.min(months, Math.round((now - b.first) / MONTH_MS) || 1)) };
98
+ }).sort((x, y) => y.months - x.months || y.touches - x.touches || x.label.localeCompare(y.label));
99
+ // the touches each person made per group, for the pairing partner
100
+ const byGroup = {};
101
+ for (const a of counted) for (const [who, b] of a.by) { const g = (byGroup[a.group] = byGroup[a.group] || {}); g[who] = (g[who] || 0) + b.n; }
102
+ return { areas, total: counted.length, people: { git: gitPeople.size, jira: jiraPeople.size }, byGroup, names: Object.fromEntries([...names.keys()].map((w) => [w, nameOf(w, 'git')])) };
103
+ }
104
+
105
+ /** Does a leave line name this person? By full name, git email, or the first name alone. */
106
+ function leaveMatches(leavePerson, area) {
107
+ const l = key(leavePerson);
108
+ if (!l) return false;
109
+ const p = key(area.person), w = key(area.who);
110
+ return l === p || l === w || (w.includes('@') && l === w.split('@')[0]) || (!l.includes(' ') && l === p.split(' ')[0]);
111
+ }
112
+
113
+ /** PURE. The ✦ for an area before its person's leave, or null. */
114
+ function suggestOf(area, { byGroup = {}, names = {}, leaves = [], today } = {}) {
115
+ if (!area || !DAY_RE.test(String(today || ''))) return null;
116
+ const last = addDays(today, LEAVE_DAYS);
117
+ const l = (leaves || []).filter((x) => x && DAY_RE.test(String(x.from || '')) && x.from >= today && x.from <= last && leaveMatches(x.person, area))
118
+ .sort((a, b) => a.from.localeCompare(b.from))[0];
119
+ if (!l) return null;
120
+ const g = byGroup[area.group] || {};
121
+ const partner = Object.keys(g).filter((w) => w !== area.who).sort((a, b) => g[b] - g[a] || a.localeCompare(b))[0] || null;
122
+ return partner ? { plan: 'pairing', partner: area.source === 'git' ? (names[partner] || partner) : partner, before: l.from } : { plan: 'writeup', partner: null, before: l.from };
123
+ }
124
+
125
+ /* ── the ledger ─────────────────────────────────────────────────────────────────────────────────────────── */
126
+ function readLines(dir) {
127
+ try { return fs.readFileSync(path.join(String(dir || ''), LEDGER), 'utf8').split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean); }
128
+ catch { return []; }
129
+ }
130
+ function append(dir, line) { fs.mkdirSync(dir, { recursive: true }); fs.appendFileSync(path.join(dir, LEDGER), JSON.stringify(line) + '\n'); }
131
+
132
+ /** PURE. The latest leave per person, and the plan per area that no undo took back. */
133
+ function fold(lines) {
134
+ const leaves = new Map(), plans = new Map();
135
+ for (const l of lines || []) {
136
+ if (!l || typeof l !== 'object') continue;
137
+ if (l.kind === 'leave' && one(l.person) && DAY_RE.test(String(l.from || ''))) leaves.set(key(l.person), { person: one(l.person, 80), from: l.from, until: DAY_RE.test(String(l.until || '')) ? l.until : l.from });
138
+ else if (l.kind === 'leave-drop') leaves.delete(key(l.person));
139
+ else if (l.kind === 'plan' && l.area) plans.set(l.area, { plan: l.plan, partner: l.partner || null, before: l.before || '', person: l.person || '', file: l.file || null, text: l.text || null, at: l.at });
140
+ else if (l.kind === 'undo' && l.area) plans.delete(l.area);
141
+ }
142
+ return { leaves: [...leaves.values()], plans };
143
+ }
144
+
145
+ /* ── the sources ────────────────────────────────────────────────────────────────────────────────────────── */
146
+ const RS = '\x1e', US = '\x1f';
147
+ const gitArgs = (since) => ['log', '--no-merges', `--since=${since}`, `--format=${RS}%at${US}%an${US}%ae`, '--name-only'];
148
+ function parseGit(out) {
149
+ const commits = [];
150
+ for (const chunk of String(out || '').split(RS)) {
151
+ const lines = chunk.split('\n');
152
+ const [at, name, email] = (lines.shift() || '').split(US);
153
+ if (!at) continue;
154
+ commits.push({ at: Number(at) * 1000, name, email, files: lines.map((s) => s.trim()).filter(Boolean) });
155
+ }
156
+ return commits;
157
+ }
158
+ const gitCache = new Map(); // root → { head, day, commits }
159
+ /** The commits of the last MONTHS, async (never blocks the server), kept per root until HEAD or the day changes. */
160
+ function readGit(root, { now = Date.now() } = {}) {
161
+ const cp = require('child_process');
162
+ const run = (args) => new Promise((ok) => cp.execFile('git', args, { cwd: root, maxBuffer: 256 * 1024 * 1024, encoding: 'utf8' }, (e, out) => ok(e ? null : out)));
163
+ return run(['rev-parse', 'HEAD']).then((h) => {
164
+ const head = String(h || '').trim(), day = localDay(now), c = gitCache.get(root);
165
+ if (!head) return [];
166
+ if (c && c.head === head && c.day === day) return c.commits;
167
+ return run(gitArgs(new Date(now - MONTHS * MONTH_MS).toISOString())).then((out) => {
168
+ const commits = parseGit(out);
169
+ gitCache.set(root, { head, day, commits });
170
+ return commits;
171
+ });
172
+ });
173
+ }
174
+ function readGitSync(root, { now = Date.now() } = {}) {
175
+ try { return parseGit(require('child_process').execFileSync('git', gitArgs(new Date(now - MONTHS * MONTH_MS).toISOString()), { cwd: root, maxBuffer: 256 * 1024 * 1024, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })); }
176
+ catch { return []; }
177
+ }
178
+ /** One row per task: its initiative, its owner now, and when it last changed. */
179
+ function readTasks(root) {
180
+ try {
181
+ const Facts = require('./drift-facts.js');
182
+ const stateDir = require('./driver.js').stateDirOf(root);
183
+ let storeFile = null; try { const s = require('./task-store.js').storeFor(root); storeFile = s && s.file; } catch { storeFile = null; }
184
+ const out = [];
185
+ for (const t of Facts.tasksOf(root, stateDir ? path.join(stateDir, 'boards.jsonl') : null, storeFile, []).tasks || []) {
186
+ let owner = '', at = null, gone = false;
187
+ for (const l of t.lines || []) {
188
+ if (l.kind === 'task-remove') gone = true; else if (l.kind === 'task-restore') gone = false;
189
+ if (l.owner !== undefined) owner = l.owner;
190
+ const ms = typeof l.at === 'number' ? l.at : Date.parse(l.at);
191
+ if (Number.isFinite(ms)) at = Math.max(at || 0, ms);
192
+ }
193
+ if (!gone && owner && at) out.push({ id: t.id, initiative: t.initiative, owner: String(owner).replace(/^person:/, ''), at });
194
+ }
195
+ return out;
196
+ } catch { return []; }
197
+ }
198
+ function titlesOf(root) { const o = {}; try { for (const i of require('./live-notes.js').loadInitiatives(root).open) o[i.id] = i.title; } catch { /* ids stand in */ } return o; }
199
+ /** The PM's own away days (`pmos away`), as a leave of the git user of this checkout. */
200
+ function pmAway(root, { awayDir, now = Date.now() } = {}) {
201
+ try {
202
+ const AW = require('./away-handover.js');
203
+ const dir = awayDir || require('./state-root.js').defaultRoot({ env: process.env });
204
+ const s = AW.stateOf(AW.readLines(dir), localDay(now));
205
+ const lines = AW.readLines(dir).filter((l) => l.kind === 'away' && DAY_RE.test(String(l.from || '')));
206
+ const last = s && s.away ? s.away : lines[lines.length - 1];
207
+ if (!last) return [];
208
+ let who = ''; try { who = require('child_process').execFileSync('git', ['config', 'user.name'], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim(); } catch { who = ''; }
209
+ return who ? [{ person: who, from: last.from, until: last.until || last.from }] : [];
210
+ } catch { return []; }
211
+ }
212
+ /** PURE. Leave read from the calendar by itself, so nobody has to type it: an event whose title says leave, OOO, out of office, vacation,
213
+ * holiday, PTO or cuti. The person is its one attendee, or the name left in the title ("Sam OOO", "Leave: Sam Ito"). Events that name
214
+ * nobody are skipped (the PM's own days come from `pmos away`). → [{ person, from, until }] */
215
+ const LEAVE_WORD = /\b(annual leave|on leave|leave|ooo|out[ -]of[ -]office|vacation|holiday|holidays|pto|cuti)\b/i;
216
+ function leavesOfEvents(events) {
217
+ const out = [];
218
+ for (const e of events || []) {
219
+ const title = one(e && e.title, 120);
220
+ if (!title || !LEAVE_WORD.test(title)) continue;
221
+ const from = String(e.at || e.start || '').slice(0, 10);
222
+ if (!DAY_RE.test(from)) continue;
223
+ let end = String(e.end || '').slice(0, 10);
224
+ if (!DAY_RE.test(end) || end < from) end = from;
225
+ const people = [].concat(e.attendees || []).map((x) => one(x && typeof x === 'object' ? x.name || x.email : x, 80)).filter(Boolean);
226
+ let person = people.length === 1 ? people[0] : '';
227
+ if (!person) {
228
+ const rest = title.replace(new RegExp(LEAVE_WORD.source, 'gi'), ' ').replace(/[^\p{L}\p{M}' .-]+/gu, ' ').replace(/\s+/g, ' ').trim().replace(/^[.\- ]+|[.\- ]+$/g, '');
229
+ const words = rest.split(' ').filter((w) => w && !/^(is|on|for|day|days|the|of|annual|sick|public)$/i.test(w));
230
+ if (words.length >= 1 && words.length <= 3) person = words.join(' ');
231
+ }
232
+ if (person) out.push({ person, from, until: end, source: 'calendar' });
233
+ }
234
+ return out;
235
+ }
236
+ /** Leave on the workspace's calendar (lib/calendar-events.js readAll). A calendar that cannot be read gives nothing. */
237
+ function calendarLeaves({ calDir, now = Date.now() } = {}) {
238
+ try {
239
+ const dir = calDir || require('./state-root.js').defaultRoot({ env: process.env });
240
+ return leavesOfEvents(require('./calendar-events.js').readAll(dir, { now }));
241
+ } catch { return []; }
242
+ }
243
+ const leavesOf = (root, o, now) => o.leaves || [...pmAway(root, { now, awayDir: o.awayDir }), ...calendarLeaves({ calDir: o.calDir || o.useDir, now })];
244
+ function stateDirOf(root, o = {}) { return o.stateDir || require('./driver.js').stateDirOf(root, { create: true }); }
245
+
246
+ /** The block's rows: the one-person areas, each with its ✦ (before a leave) or its plan. */
247
+ function viewOf({ commits, tasks, titles, leaves, lines, now = Date.now() }) {
248
+ const A = areasOf({ commits, tasks, titles, now });
249
+ const F = fold(lines);
250
+ const all = [...F.leaves, ...(leaves || [])];
251
+ const today = localDay(now);
252
+ const areas = A.areas.map((a) => {
253
+ const plan = F.plans.get(a.key) || null;
254
+ return { ...a, plan, suggest: plan ? null : suggestOf(a, { byGroup: A.byGroup, names: A.names, leaves: all, today }) };
255
+ });
256
+ return { ok: true, areas, total: A.total };
257
+ }
258
+ async function view(root, o = {}) {
259
+ const now = o.now || Date.now();
260
+ const commits = o.commits || await readGit(root, { now });
261
+ return viewOf({ commits, tasks: o.tasks || readTasks(root), titles: o.titles || titlesOf(root), leaves: leavesOf(root, o, now),
262
+ lines: readLines(stateDirOf(root, o)), now });
263
+ }
264
+ function viewSync(root, o = {}) {
265
+ const now = o.now || Date.now();
266
+ return viewOf({ commits: o.commits || readGitSync(root, { now }), tasks: o.tasks || readTasks(root), titles: o.titles || titlesOf(root),
267
+ leaves: leavesOf(root, o, now), lines: readLines(stateDirOf(root, o)), now });
268
+ }
269
+
270
+ /* ── the writes ─────────────────────────────────────────────────────────────────────────────────────────── */
271
+ function knowledgeDir(root) { const kit = fs.existsSync(path.join(root, 'pmos', 'state')); return path.join(root, ...(kit ? ['pmos', 'planning'] : ['planning']), 'knowledge'); }
272
+ function writeupOf(area, { day, commits = [] }) {
273
+ const files = new Map();
274
+ if (area.source === 'git') for (const c of commits) for (const f of c.files || []) if (areaOfFile(f) === area.label) files.set(f, (files.get(f) || 0) + 1);
275
+ const top = [...files.entries()].sort((a, b) => b[1] - a[1]).slice(0, 12).map(([f, n]) => `- \`${f}\` (${n} ${n === 1 ? 'change' : 'changes'})`);
276
+ return ['---', 'type: Reference', `title: "Write-up: ${area.label.replace(/"/g, "'")}"`, `timestamp: ${day}`, '---', '',
277
+ `# Write-up: ${area.label}`, '',
278
+ `Only ${area.person} touched this in the last ${area.months} ${area.months === 1 ? 'month' : 'months'}. PMOS drafted this page on ${short(day)} so the knowledge stays when ${area.person} is away. It is a draft: ${area.person} fills it in. PMOS sends nothing.`, '',
279
+ '## What it does', '', '(to write)', '',
280
+ '## How it works', '', '(to write)', '',
281
+ '## Where it breaks', '', '(to write)', '',
282
+ ...(top.length ? ['## The files touched most', '', ...top, ''] : []),
283
+ '## Who else to ask', '', '(to write)', ''].join('\n');
284
+ }
285
+ function used(o, now) {
286
+ try { const dir = o.useDir || require('./state-root.js').defaultRoot({ env: o.env || process.env }); require('./use-log.js').record(dir, [{ kind: 'use', page: 'board', control: 'knowledgePlan', device: 'desk' }], now); } catch { /* a count, never a reason to fail */ }
287
+ }
288
+ /** Plan the ✦ of one area: a pairing (recorded) or a write-up (a draft file too). */
289
+ async function plan(root, areaKey, o = {}) {
290
+ const now = o.now || Date.now();
291
+ const v = o.view || await view(root, o);
292
+ const a = (v.areas || []).find((x) => x.key === areaKey);
293
+ if (!a) return { ok: false, error: 'no one-person area with that name' };
294
+ if (a.plan) return { ok: false, error: 'already planned' };
295
+ const s = a.suggest || { plan: 'writeup', partner: null, before: '' }; // no leave: the PM may still ask for a write-up
296
+ const day = localDay(now);
297
+ let file = null, text = null;
298
+ if (s.plan === 'writeup') {
299
+ const f = path.join(knowledgeDir(root), `${slug(a.label)}-${slug(a.person)}.md`);
300
+ if (!fs.existsSync(f)) {
301
+ text = writeupOf(a, { day, commits: a.source === 'git' ? (o.commits || await readGit(root, { now })) : [] });
302
+ fs.mkdirSync(path.dirname(f), { recursive: true }); fs.writeFileSync(f, text);
303
+ }
304
+ file = path.relative(root, f);
305
+ }
306
+ const line = { at: new Date(now).toISOString(), kind: 'plan', area: a.key, person: a.person, plan: s.plan, partner: s.partner, before: s.before, file, text: text ? require('crypto').createHash('sha1').update(text).digest('hex') : null };
307
+ append(stateDirOf(root, o), line);
308
+ console.log(`${TAG} planned ${s.plan} area=${a.key}${s.partner ? ' partner=' + s.partner : ''}`);
309
+ used(o, now);
310
+ return { ok: true, area: a, plan: { plan: s.plan, partner: s.partner, before: s.before, file } };
311
+ }
312
+ /** Take a plan back: an unedited write-up draft is removed too. */
313
+ function undo(root, areaKey, o = {}) {
314
+ const now = o.now || Date.now();
315
+ const dir = stateDirOf(root, o);
316
+ const p = fold(readLines(dir)).plans.get(areaKey);
317
+ if (!p) return { ok: false, error: 'nothing planned for that area' };
318
+ if (p.file && p.text) {
319
+ const f = path.join(root, p.file);
320
+ try { if (require('crypto').createHash('sha1').update(fs.readFileSync(f, 'utf8')).digest('hex') === p.text) fs.unlinkSync(f); } catch { /* gone or edited: kept */ }
321
+ }
322
+ append(dir, { at: new Date(now).toISOString(), kind: 'undo', area: areaKey });
323
+ return { ok: true };
324
+ }
325
+ function leave(dir, { person, from, until, drop = false } = {}, { now = Date.now() } = {}) {
326
+ const p = one(person, 80);
327
+ if (!p) return { ok: false, error: 'name the person' };
328
+ if (drop) { append(dir, { at: new Date(now).toISOString(), kind: 'leave-drop', person: p }); return { ok: true }; }
329
+ if (!DAY_RE.test(String(from || ''))) return { ok: false, error: 'the first day of leave is a date like 2026-12-03' };
330
+ if (until && (!DAY_RE.test(String(until)) || until < from)) return { ok: false, error: 'the last day is a date on or after the first' };
331
+ append(dir, { at: new Date(now).toISOString(), kind: 'leave', person: p, from, until: until || from });
332
+ return { ok: true };
333
+ }
334
+ function count(o = {}, { days = 7, now = Date.now() } = {}) {
335
+ const from = now - days * 864e5;
336
+ return readLines(o.stateDir).filter((l) => l.kind === 'plan' && Date.parse(l.at) >= from).length;
337
+ }
338
+
339
+ /** "only Sam, 6 months" */
340
+ const whoLine = (a) => `only ${a.person}, ${a.months} ${a.months === 1 ? 'month' : 'months'}`;
341
+ const planLine = (p) => (p.plan === 'pairing' ? `pairing with ${p.partner} planned` : 'write-up drafted') + (p.before ? ` before ${short(p.before)}` : '');
342
+ const suggestLine = (s) => (s.plan === 'pairing' ? `✦ pair with ${s.partner}` : '✦ a short write-up') + ` before leave on ${short(s.before)}`;
343
+
344
+ /* ── pmos knowledge ─────────────────────────────────────────────────────────────────────────────────────── */
345
+ const COMMANDS = { knowledge: ['list', 'leave', 'plan', 'undo', 'count'] };
346
+ const USAGE = [
347
+ 'usage: pmos knowledge [list|leave|plan|undo|count] — the areas only one person knows, and a pairing or write-up before their leave',
348
+ ' pmos knowledge [list] [--json] the one-person areas of the last 6 months, numbered, with the person and how long',
349
+ ' pmos knowledge leave <person> <from> [<until>] record a person\'s leave (dates YYYY-MM-DD; kept on this computer, not in git)',
350
+ ' pmos knowledge leave <person> --drop forget that leave',
351
+ ' pmos knowledge plan <n> plan area n: a pairing with the nearest teammate, or a short write-up draft',
352
+ ' pmos knowledge undo <n> take that plan back (an unedited write-up draft is removed)',
353
+ ' pmos knowledge count [--days 7] plans made in the last days; the number is the last line',
354
+ 'Nothing is sent and nothing is written to Jira.',
355
+ ];
356
+ function repoOf(cwd) {
357
+ let d = path.resolve(cwd);
358
+ for (;;) { try { if (fs.existsSync(path.join(d, '.git'))) return d; } catch { /* look further up */ } const up = path.dirname(d); if (up === d) return path.resolve(cwd); d = up; }
359
+ }
360
+ async function run(argv, o = {}) {
361
+ const say = o.say || ((s) => console.log(s)), now = o.now || Date.now();
362
+ const args = argv[0] === 'knowledge' ? argv.slice(1) : argv.slice();
363
+ const pos = [], flags = {};
364
+ for (let i = 0; i < args.length; i++) { const a = args[i]; if (a === '--root' || a === '--days') flags[a.slice(2)] = args[++i]; else if (a === '--json' || a === '--drop') flags[a.slice(2)] = true; else pos.push(a); }
365
+ const sub = pos.shift() || 'list';
366
+ if (['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return 0; }
367
+ if (!COMMANDS.knowledge.includes(sub)) { say(`unknown knowledge command "${sub}". Use one of: ${COMMANDS.knowledge.join(', ')}`); return 2; }
368
+ const root = path.resolve(flags.root || o.root || repoOf(o.cwd || process.cwd()));
369
+ const opts = { ...o, now, stateDir: stateDirOf(root, o) };
370
+ if (sub === 'count') { say(String(count(opts, { days: Number(flags.days) || 7, now }))); return 0; }
371
+ if (sub === 'leave') {
372
+ const r = leave(opts.stateDir, { person: pos[0], from: pos[1], until: pos[2], drop: !!flags.drop }, { now });
373
+ if (!r.ok) { say('✗ ' + r.error); return 1; }
374
+ say(flags.drop ? `Forgot ${one(pos[0], 80)}'s leave.` : `Recorded: ${one(pos[0], 80)} is on leave from ${short(pos[1])}${pos[2] && pos[2] !== pos[1] ? ' to ' + short(pos[2]) : ''}. It stays on this computer.`);
375
+ return 0;
376
+ }
377
+ const v = await view(root, opts);
378
+ if (sub === 'list') {
379
+ if (flags.json) { say(JSON.stringify(v)); return 0; }
380
+ if (!v.areas.length) { say(v.total ? `Every one of the ${v.total} areas has two or more people.` : 'No area has 3 or more changes in the last 6 months yet.'); return 0; }
381
+ say(`${v.areas.length} of ${v.total} areas are known by one person:`);
382
+ v.areas.forEach((a, i) => say(` ${i + 1}. ${a.label} — ${whoLine(a)}${a.plan ? ' · ' + planLine(a.plan) : a.suggest ? ' · ' + suggestLine(a.suggest) : ''}`));
383
+ return 0;
384
+ }
385
+ const n = Number(pos[0]);
386
+ const a = Number.isInteger(n) && n >= 1 ? v.areas[n - 1] : null;
387
+ if (!a) { say(`✗ name an area by its number in pmos knowledge (1 to ${v.areas.length || 0})`); return 2; }
388
+ if (sub === 'plan') {
389
+ const r = await plan(root, a.key, { ...opts, view: v });
390
+ if (!r.ok) { say('✗ ' + r.error); return 1; }
391
+ say(`${a.label}: ${planLine(r.plan)}.${r.plan.file ? ' Draft: ' + r.plan.file : ''} Undo: pmos knowledge undo ${n}`);
392
+ return 0;
393
+ }
394
+ const r = undo(root, a.key, opts);
395
+ if (!r.ok) { say('✗ ' + r.error); return 1; }
396
+ say(`${a.label}: the plan is taken back.`);
397
+ return 0;
398
+ }
399
+
400
+ module.exports = { leavesOfEvents, calendarLeaves, areasOf, areaOfFile, suggestOf, fold, viewOf, view, viewSync, plan, undo, leave, count, readLines, parseGit, readGit, readTasks, writeupOf,
401
+ whoLine, planLine, suggestLine, run, COMMANDS, USAGE, TAG, LEDGER, MONTHS, MIN_TOUCH, LEAVE_DAYS };
402
+
403
+ if (require.main === module) Promise.resolve(run(process.argv.slice(2))).then((c) => process.exit(c || 0));
@@ -159,6 +159,9 @@ const VERBS = Object.freeze({
159
159
  // Not a pm-os-absorb verb (run: null): initiative three-line-why (bet A86) added it through the same table.
160
160
  why: Object.freeze({ module: 'why-cli.js', run: null, guide: 'cli.md',
161
161
  help: 'pmos why <initiative or task> | coverage — why the work exists in three lines: goal, problem, evidence, read from its records (pmos why help)' }),
162
+ // Not a pm-os-absorb verb (run: null): initiative screen-map (job #1895, A318) added it through the same table.
163
+ screens: Object.freeze({ module: 'screen-map.js', run: null, guide: 'cli.md',
164
+ help: "pmos screens [show|note] — the product's screens from its merged code, the flows between them and their marks; a note on a screen starts work (pmos screens help)" }),
162
165
  // Not a pm-os-absorb verb (run: null): initiative compare-items (job #1919, A421) added it through the same table.
163
166
  compare: Object.freeze({ module: 'compare-cli.js', run: null, guide: 'cli.md',
164
167
  help: 'pmos compare <a> <b> — two initiatives, or two versions of a document (<file>@<revision>), side by side with the differences marked (pmos compare help)' }),
@@ -183,6 +186,9 @@ const VERBS = Object.freeze({
183
186
  help: 'pmos raid show|count — one RAID list per initiative: risks, assumptions, late tasks and dependencies, read from its own records (pmos raid help)' }),
184
187
  hire: Object.freeze({ module: 'hire-draft.js', run: null, guide: 'cli.md',
185
188
  help: 'pmos hire [draft|show|count] — the role your open work most needs, per person, and a one-page role brief PMOS drafts for you to edit (pmos hire help)' }),
189
+ // Not a pm-os-absorb verb (run: null): initiative one-person-knows (job #1899, A391) added it through the same table.
190
+ knowledge: Object.freeze({ module: 'knowledge-cli.js', run: null, guide: 'cli.md',
191
+ help: 'pmos knowledge [list|leave|plan|undo|count] — the areas only one person touched in 6 months, and a pairing or write-up before their leave (pmos knowledge help)' }),
186
192
  // Not a pm-os-absorb verb (run: null): initiative built-vs-design (job #1903, A380) added it through the same table.
187
193
  review: Object.freeze({ module: 'review-cli.js', run: null, guide: 'cli.md',
188
194
  help: 'pmos review shots|list|note|accept|fix|count — a built screen beside the design it came from, each difference circled and numbered (pmos review help)' }),
@@ -154,6 +154,7 @@ const MODULES = Object.freeze([
154
154
  '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)
155
155
  'routes-segments', // idea A327: a product's user groups and the roadmap items that serve each, kept or renamed on Work (records segments.jsonl; page-press POST)
156
156
  'routes-principles', // bet A352: a product's principles drafted from its decisions, kept or dropped on the Board (records principles.jsonl; page-press POST)
157
+ 'routes-one-person-knows', // job #1899 (A391): the areas only one person touched in 6 months, and the ✦ before their leave (runtime knowledge.jsonl; page-press POST)
157
158
  'routes-app-versions', // idea A211: a product's app versions in use, the open bugs their users hit, one ✦ force proposal the PM decides (records app-versions.jsonl; page-press POST)
158
159
  'routes-switches', // idea A263: who has which switch, per customer, on Work; turning one waits for the PM's own press (records switches.jsonl; page-press POST)
159
160
  'routes-prefs', // bet A461: view preferences that follow the person to the phone and other browsers (runtime view-prefs.json; page-press POST)
@@ -165,6 +166,7 @@ const MODULES = Object.freeze([
165
166
  'routes-code-map', // idea A176: the product's code map on Work, redrawn when the default branch moves (records code-map.json; read-only)
166
167
  'routes-arch-warns', // idea A54: one warning when an initiative names a risky part of the code (reads code-map.json; read-only)
167
168
  'routes-live-rows', // bet A458: chat-made task changes streamed to open pages (runtime live-events.jsonl; read-only event stream)
169
+ 'routes-screen-map', // screen-map (job #1895, A318): the product page's Screens tab, read from the default branch; a note on a screen is a capture (page-press POST)
168
170
  'routes-story-map', // idea A419: a new bet's story map with the Release 1 line on the initiative popup (state story-maps.json; page-press POST)
169
171
  'routes-screen-layouts', // three-layouts (A317): a new screen's three layouts, the ✦ pick and its Undo (product state layouts.jsonl; page-press POST)
170
172
  'routes-team-waits', // team-waits (A364): Work › Dependencies' waits on other teams (GET, read-only; team-waits.jsonl written by pmos deps)
@@ -49,4 +49,4 @@ async function handle(req, res, url, ctx) {
49
49
  return true;
50
50
  }
51
51
 
52
- module.exports = { prefixes, handle };
52
+ module.exports = { prefixes, handle, captureStateDir };
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+ /* routes-one-person-knows.js — the areas only one person knows, over HTTP (initiative one-person-knows, job #1899, idea A391).
3
+ * The rules and the ledger are lib/one-person-knows.js (knowledge.jsonl in the product's local state folder); the verb is `pmos knowledge`.
4
+ *
5
+ * GET /api/one-person-knows?ws=<id> → { ok, areas, total } areas: [{ key, label, source, person, months, touches, suggest, plan }]
6
+ * POST /api/one-person-knows { ws, act, area } → { ok, plan? } | 400 act ∈ plan · undo
7
+ *
8
+ * WHO WRITES. A page press: pm-guard requirePagePress checks the page's Origin and launch nonce. The chat writes with `pmos knowledge`.
9
+ * Nothing here is sent anywhere, and nothing is written to Jira. */
10
+ const path = require('path');
11
+ const guard = require('./pm-guard.js');
12
+ const K = require('./one-person-knows.js');
13
+
14
+ const CHECKOUT = path.join(__dirname, '..', '..');
15
+ function wsOf(ctx, ws) { try { return ctx && typeof ctx.getWs === 'function' ? ctx.getWs(ws || null) : null; } catch { return null; } }
16
+ const rootFor = (ctx, ws) => { const w = wsOf(ctx, ws); return (ctx && ctx.repoRoot) || (w && w.root) || CHECKOUT; };
17
+ const optsOf = (ctx) => ({ stateDir: (ctx && ctx.knowledgeStateDir) || undefined, awayDir: (ctx && ctx.awayDir) || undefined, useDir: (ctx && ctx.runtimeDir) || undefined,
18
+ commits: (ctx && ctx.knowledgeCommits) || undefined, tasks: (ctx && ctx.knowledgeTasks) || undefined, now: (ctx && ctx.now) || undefined });
19
+
20
+ async function handle(req, res, url, ctx) {
21
+ if (url.pathname !== '/api/one-person-knows') return false;
22
+ const send = (status, body) => { ctx.json(res, body, status); return true; };
23
+ if (req.method === 'GET') {
24
+ const root = rootFor(ctx, url.searchParams.get('ws'));
25
+ try { const v = await K.view(root, optsOf(ctx)); return send(200, { ok: true, areas: v.areas, total: v.total }); }
26
+ catch (e) { return send(200, { ok: true, areas: [], total: 0, error: String(e && e.message || e) }); }
27
+ }
28
+ if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
29
+ const rd = await ctx.readJson(req);
30
+ if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
31
+ const body = rd.body || {};
32
+ const g = guard.requirePagePress(req, body);
33
+ if (!g.ok) return send(g.status, { ok: false, error: g.error });
34
+ const root = rootFor(ctx, body.ws || null), area = String(body.area || '');
35
+ if (body.act === 'plan') { const r = await K.plan(root, area, optsOf(ctx)); return r.ok ? send(200, { ok: true, plan: r.plan }) : send(400, { ok: false, error: r.error }); }
36
+ if (body.act === 'undo') { const r = K.undo(root, area, optsOf(ctx)); return r.ok ? send(200, { ok: true }) : send(400, { ok: false, error: r.error }); }
37
+ return send(400, { ok: false, error: 'act is plan or undo' });
38
+ }
39
+
40
+ module.exports = { prefixes: ['/api/one-person-knows'], handle };
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+ /* routes-screen-map.js — the product page's Screens tab over HTTP (initiative screen-map, job #1895, idea A318; lib/route-modules.js).
3
+ *
4
+ * GET /api/screen-map?ws=<id> → lib/screen-map.js read(root): { ok, ref, commit, updated, screens, flows, counts }
5
+ * POST /api/screen-map/note { ws, screen, text } → { ok: true, id, file, screen } one capture that names the screen (page press)
6
+ *
7
+ * The map is read from the workspace's default branch, so it follows each merge; nothing here writes the product's files. The note goes
8
+ * through pm-guard requirePagePress and lib/capture.js into the folder Today's capture card and triage read (routes-capture.js
9
+ * captureStateDir), with the actor that call returns. `pmos screens show` and `pmos screens note` read and write the same.
10
+ */
11
+ const guard = require('./pm-guard.js');
12
+ const SM = require('./screen-map.js');
13
+ const { captureStateDir } = require('./routes-capture.js');
14
+
15
+ const prefixes = ['/api/screen-map'];
16
+
17
+ function wsOf(ctx, id) { try { return ctx && typeof ctx.getWs === 'function' ? ctx.getWs(id || null) : null; } catch { return null; } }
18
+
19
+ async function handle(req, res, url, ctx) {
20
+ if (url.pathname === '/api/screen-map') {
21
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
22
+ const w = wsOf(ctx, url.searchParams.get('ws'));
23
+ if (!w || !w.root) { ctx.json(res, { ok: false, error: 'This repository is not registered.' }, 404); return true; }
24
+ const m = SM.read(w.root);
25
+ ctx.json(res, m, m.ok ? 200 : 409);
26
+ return true;
27
+ }
28
+ if (url.pathname === '/api/screen-map/note') {
29
+ if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
30
+ const parsed = await ctx.readJson(req);
31
+ if (!parsed.ok) { ctx.json(res, { ok: false, error: 'The body is not valid JSON.' }, 400); return true; }
32
+ const body = parsed.body;
33
+ const g = guard.requirePagePress(req, body);
34
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
35
+ const id = body && typeof body.ws === 'string' ? body.ws : '';
36
+ if (!id) { ctx.json(res, { ok: false, error: 'Select a repository first. A note is kept in one repository.' }, 400); return true; }
37
+ const w = wsOf(ctx, id);
38
+ if (!w || w.id !== id) { ctx.json(res, { ok: false, error: 'This repository is not registered.' }, 404); return true; }
39
+ const r = SM.note(w.root, { screen: body.screen, text: body.text, actor: g.actor, stateDir: captureStateDir(ctx, w.root) });
40
+ if (!r.ok) { ctx.json(res, { ok: false, error: r.error }, r.status || 400); return true; }
41
+ ctx.json(res, { ok: true, id: r.id, file: r.file, screen: r.screen, written: 1 });
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+
47
+ module.exports = { prefixes, handle };
@@ -40,8 +40,11 @@ function lineRowOf(root, ini) {
40
40
  }
41
41
 
42
42
  module.exports = {
43
- prefixes: ['/api/stage-signoffs'],
43
+ // '/api/on-item': the open initiative's sign-offs, numbers and press release (job #1986, lib/on-item-routes.js), a second prefix here so
44
+ // route-modules.js is not touched
45
+ prefixes: ['/api/stage-signoffs', '/api/on-item'],
44
46
  handle: async (req, res, url, ctx) => {
47
+ if (url.pathname === '/api/on-item' || url.pathname.startsWith('/api/on-item/')) return require('./on-item-routes.js').handle(req, res, url, ctx);
45
48
  const YM = require('./routes-your-move.js');
46
49
  if (url.pathname === '/api/stage-signoffs') {
47
50
  const r = await read(req, res, url, ctx, 'GET'); if (!r) return true;