create-pmos 0.829.0 → 0.831.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 (69) hide show
  1. package/package.json +149 -49
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-board-test.js +1 -1
  7. package/workspace/briefing-premium-insights-test.js +1 -1
  8. package/workspace/changelog.json +148 -22
  9. package/workspace/guide/agent-capabilities.md +1 -1
  10. package/workspace/guide/backlog.md +12 -1
  11. package/workspace/guide/cli.md +20 -1
  12. package/workspace/guide/home.md +1 -1
  13. package/workspace/guide/layout.md +3 -0
  14. package/workspace/lib/anchor-id.js +226 -0
  15. package/workspace/lib/artefacts-cli.js +25 -1
  16. package/workspace/lib/code-map.js +8 -2
  17. package/workspace/lib/factory-floor.js +16 -8
  18. package/workspace/lib/features.json +14 -13
  19. package/workspace/lib/initiative-cli.js +67 -2
  20. package/workspace/lib/lessons-draft.js +242 -0
  21. package/workspace/lib/people-cli.js +9 -1
  22. package/workspace/lib/people-prep.js +140 -0
  23. package/workspace/lib/pmos-verbs.js +2 -0
  24. package/workspace/lib/prefs-sync.js +1 -1
  25. package/workspace/lib/print-cli.js +49 -0
  26. package/workspace/lib/print-pdf.js +96 -0
  27. package/workspace/lib/review-reasons.js +121 -9
  28. package/workspace/lib/route-modules.js +1 -0
  29. package/workspace/lib/routes-c3-strategy.js +2 -1
  30. package/workspace/lib/routes-proposals.js +2 -2
  31. package/workspace/lib/routes-report-design.js +3 -1
  32. package/workspace/lib/routes-skill-map.js +39 -0
  33. package/workspace/lib/routes-strategy-card.js +13 -6
  34. package/workspace/lib/skill-map.js +199 -0
  35. package/workspace/lib/team-cli.js +20 -1
  36. package/workspace/package-lock.json +2 -2
  37. package/workspace/package.json +1 -1
  38. package/workspace/public/pm/action-keys.js +1 -0
  39. package/workspace/public/pm/ask-here-ctx.js +25 -1
  40. package/workspace/public/pm/ask-here.css +7 -0
  41. package/workspace/public/pm/ask-here.js +15 -2
  42. package/workspace/public/pm/bd-backlog.css +61 -0
  43. package/workspace/public/pm/bd-backlog.js +62 -8
  44. package/workspace/public/pm/bd-work.js +12 -1
  45. package/workspace/public/pm/card-fold.js +123 -0
  46. package/workspace/public/pm/code-map.js +15 -4
  47. package/workspace/public/pm/cozy-board.css +5 -1
  48. package/workspace/public/pm/cozy-ev.css +7 -0
  49. package/workspace/public/pm/cozy-nav.js +2 -0
  50. package/workspace/public/pm/cozy-pop-work.js +2 -0
  51. package/workspace/public/pm/cozy-search.js +2 -2
  52. package/workspace/public/pm/factory.js +199 -0
  53. package/workspace/public/pm/pop-cap.js +5 -3
  54. package/workspace/public/pm/premium-board.js +4 -0
  55. package/workspace/public/pm/premium-report-read.js +11 -2
  56. package/workspace/public/pm/print-pdf.js +191 -0
  57. package/workspace/public/pm/readonly.js +2 -0
  58. package/workspace/public/pm/review-reasons.js +19 -5
  59. package/workspace/public/pm/skill-map.js +57 -0
  60. package/workspace/public/premium-board.html +2 -0
  61. package/workspace/test-lists/anchor-id.json +9 -0
  62. package/workspace/test-lists/card-fold.json +9 -0
  63. package/workspace/test-lists/factory-page-ui.json +9 -0
  64. package/workspace/test-lists/lessons-on-close.json +9 -0
  65. package/workspace/test-lists/people-prep.json +9 -0
  66. package/workspace/test-lists/print-pdf.json +9 -0
  67. package/workspace/test-lists/skill-map.json +9 -0
  68. package/workspace/test-lists/surface-ask-card.json +9 -0
  69. package/workspace/test-lists/voice-files.json +9 -0
@@ -0,0 +1,140 @@
1
+ 'use strict';
2
+ /* people-prep.js — a 1:1 brief for one person, from the tasks they own (idea A85, factory job #1997, initiative people-prep).
3
+ *
4
+ * prepOf(tasks, who, { today, days }) PURE → { who, owners, shipped, stuck, recognise, days }
5
+ * linesOf(p) PURE → the brief as lines, each with its source
6
+ * matchOf(owners, who) PURE → the owner names that are this person
7
+ * tasksAll(root, stateDir) → every task of the repository: the Board's tasks and the breakdown items, read the way
8
+ * `pmos task list` reads them (lib/routes-boards.js foldOf, lib/task-items.js rowsOf)
9
+ * run(argv, o) → `pmos people prep <person> [--days N] [--json]` (lib/people-cli.js routes it here)
10
+ *
11
+ * THE THREE PARTS. Shipped: their tasks that went to Done in the last `days` days, by the day the state changed, newest first. Stuck:
12
+ * their open tasks (To do, In progress) past the due day, or marked blocked; each says which. Recognise: one Done task of those days,
13
+ * the newest that landed on or before its due day, else the newest Done. Nothing Done, no recognition: nothing is made up.
14
+ * Every line names its source: the task id and its initiative.
15
+ *
16
+ * WHO. An owner matches when its name, with case and a `person:` prefix ignored, is the name asked for. A one-word name also matches a
17
+ * first name, but only when exactly one owner has that first name, so "Dan" never picks up Dana's tasks and "Sam" asks which Sam.
18
+ *
19
+ * READS ONLY. The task ledger and the plan items are read, never written. The one write is a local use-log line (control peoplePrep, the
20
+ * health number), in the runtime folder outside every repository. */
21
+ const path = require('path');
22
+
23
+ const TAG = '[people-prep]';
24
+ const DAYS = 14;
25
+ const DONE = 'Done';
26
+ const OPEN = new Set(['To do', 'In progress']);
27
+ const DAY = 86400000;
28
+
29
+ const nameOf = (o) => String(o == null ? '' : o).replace(/^person:/i, '').replace(/\s+/g, ' ').trim();
30
+ const low = (s) => nameOf(s).toLowerCase().replace(/[-_]+/g, ' '); // a People id (dana-lee) reads as the name
31
+ const dayOf = (v) => { const s = String(v || '').slice(0, 10); return /^\d{4}-\d{2}-\d{2}$/.test(s) ? s : ''; };
32
+ const daysBetween = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(a + 'T00:00:00Z')) / DAY);
33
+
34
+ /** The owner names that are this person. PURE. */
35
+ function matchOf(owners, who) {
36
+ const q = low(who);
37
+ if (!q) return [];
38
+ const all = [...new Set((owners || []).map(nameOf).filter(Boolean))];
39
+ const exact = all.filter((o) => low(o) === q);
40
+ if (exact.length || q.includes(' ')) return exact;
41
+ const first = all.filter((o) => low(o).split(' ')[0] === q);
42
+ const people = new Set(first.map(low));
43
+ return people.size === 1 ? first : [];
44
+ }
45
+ /** Several owners share that first name: who they are, so the brief can ask which one. PURE. */
46
+ function ambiguousOf(owners, who) {
47
+ const q = low(who);
48
+ if (!q || q.includes(' ')) return [];
49
+ const first = [...new Set((owners || []).map(nameOf).filter((o) => low(o).split(' ')[0] === q && low(o) !== q))];
50
+ return first.length > 1 ? first.sort() : [];
51
+ }
52
+
53
+ const src = (t) => 'task ' + t.id + (t.initiative ? ' on ' + t.initiative : '');
54
+
55
+ /** The brief. tasks: [{ id, title, state, owner, due, since, blocked, initiative }]. PURE. */
56
+ function prepOf(tasks, who, { today, days = DAYS } = {}) {
57
+ const t0 = dayOf(today) || new Date().toISOString().slice(0, 10);
58
+ const list = Array.isArray(tasks) ? tasks.filter((t) => t && t.id && t.title) : [];
59
+ const owners = matchOf(list.map((t) => t.owner), who);
60
+ const mine = new Set(owners.map(low));
61
+ const own = list.filter((t) => mine.has(low(t.owner)));
62
+ const from = new Date(Date.parse(t0 + 'T00:00:00Z') - days * DAY).toISOString().slice(0, 10);
63
+ const shipped = own.filter((t) => t.state === DONE && dayOf(t.since) && dayOf(t.since) >= from && dayOf(t.since) <= t0)
64
+ .sort((a, b) => dayOf(b.since).localeCompare(dayOf(a.since)) || String(a.id).localeCompare(String(b.id)))
65
+ .map((t) => ({ id: t.id, title: t.title, initiative: t.initiative || '', on: dayOf(t.since), due: dayOf(t.due), source: src(t) }));
66
+ const stuck = own.filter((t) => OPEN.has(t.state) && (t.blocked || (dayOf(t.due) && dayOf(t.due) < t0)))
67
+ .map((t) => {
68
+ const late = dayOf(t.due) && dayOf(t.due) < t0 ? daysBetween(dayOf(t.due), t0) : 0;
69
+ const why = [late ? late + (late === 1 ? ' day late' : ' days late') : '', t.blocked ? 'blocked' + (t.reason ? ': ' + String(t.reason).slice(0, 120) : '') : ''].filter(Boolean).join(', ');
70
+ return { id: t.id, title: t.title, initiative: t.initiative || '', state: t.state, late, blocked: !!t.blocked, why, source: src(t) };
71
+ })
72
+ .sort((a, b) => b.late - a.late || String(a.id).localeCompare(String(b.id)));
73
+ const onTime = shipped.filter((s) => s.due && s.on <= s.due);
74
+ const pick = onTime[0] || shipped[0] || null;
75
+ const recognise = pick ? { ...pick, why: pick.due && pick.on <= pick.due ? (pick.on < pick.due ? 'landed ' + daysBetween(pick.on, pick.due) + (daysBetween(pick.on, pick.due) === 1 ? ' day' : ' days') + ' before its due day' : 'landed on its due day') : 'the newest one Done' } : null;
76
+ return { who: nameOf(who), owners, ambiguous: owners.length ? [] : ambiguousOf(list.map((t) => t.owner), who), days, today: t0, shipped, stuck, recognise };
77
+ }
78
+
79
+ /** The brief as lines. PURE. */
80
+ function linesOf(p) {
81
+ const name = p.owners[0] || p.who;
82
+ if (!p.owners.length) {
83
+ if (p.ambiguous && p.ambiguous.length) return [`More than one person is called ${p.who}: ${p.ambiguous.join(', ')}. Name one in full.`];
84
+ return [`No task names ${p.who} as its owner, so there is nothing to prepare from the tasks. pmos people show ${p.who} lists what else PMOS knows.`];
85
+ }
86
+ const out = [`1:1 with ${name} · the last ${p.days} days`];
87
+ out.push(p.shipped.length ? `Shipped (${p.shipped.length}):` : `Shipped: nothing Done in the last ${p.days} days.`);
88
+ for (const s of p.shipped) out.push(` ${s.on} ${s.title} — ${s.source}`);
89
+ out.push(p.stuck.length ? `Stuck (${p.stuck.length}):` : 'Stuck: no open task is late or blocked.');
90
+ for (const s of p.stuck) out.push(` ${s.title} · ${s.why} — ${s.source}`);
91
+ if (p.recognise) out.push(`Recognise: ${p.recognise.title}, ${p.recognise.why} — ${p.recognise.source}`);
92
+ return out;
93
+ }
94
+
95
+ /** Every task of the repository, read the way `pmos task list` reads them. */
96
+ function tasksAll(root, stateDir) {
97
+ const SR = require('./stage-read.js');
98
+ const { w, ctx } = SR.cliCtx(root, stateDir);
99
+ const out = [];
100
+ try {
101
+ const F = require('./routes-boards.js').foldOf(ctx, w);
102
+ for (const t of (F.tasks || new Map()).values()) {
103
+ if (!t || t.kind === 'Epic') continue;
104
+ out.push({ id: t.id, title: t.title, state: t.state, owner: t.owner || '', due: t.due || '', since: t.since || '', blocked: false, initiative: t.initiative || '' });
105
+ }
106
+ } catch { /* no board ledger: the breakdown items alone */ }
107
+ try {
108
+ for (const x of require('./task-items.js').rowsOf(root, { has: () => true }, null)) {
109
+ out.push({ id: x.uid, title: x.title, state: x.status, owner: x.owner || '', due: x.end || '', since: x.since || '', blocked: !!x.blocked, reason: x.reason || '', initiative: x.ini || '' });
110
+ }
111
+ } catch { /* no plan items */ }
112
+ return out;
113
+ }
114
+
115
+ const USAGE = 'usage: pmos people prep <person> [--days N] [--json] a 1:1 brief: what they shipped, where they are stuck, one thing to recognise';
116
+
117
+ /** `pmos people prep <person> [--days N] [--json]`. argv: the words after `prep`. → exit code */
118
+ function run(argv, { say = console.log, root, stateDir, today, env = process.env, now = Date.now(), useDir } = {}) {
119
+ const pos = [], flags = {};
120
+ for (let i = 0; i < argv.length; i++) {
121
+ const a = argv[i];
122
+ if (a === '--json') flags.json = true;
123
+ else if (a === '--days') flags.days = argv[++i];
124
+ else if (a.startsWith('--')) { say(`✗ --${a.slice(2)} is not an option of pmos people prep`); return 2; }
125
+ else pos.push(a);
126
+ }
127
+ const who = pos.join(' ').trim();
128
+ if (!who) { say(USAGE); return 2; }
129
+ const days = flags.days === undefined ? DAYS : Number(flags.days);
130
+ if (!Number.isInteger(days) || days < 1 || days > 90) { say('✗ --days is a whole number from 1 to 90'); return 2; }
131
+ const dir = stateDir === undefined ? require('./driver.js').stateDirOf(root) : stateDir;
132
+ const p = prepOf(tasksAll(root, dir), who, { today: today || new Date(now).toISOString().slice(0, 10), days });
133
+ try { console.error(`${TAG} ${p.owners.length ? 'prepared' : 'no owner'}: ${p.shipped.length} shipped, ${p.stuck.length} stuck`); } catch { /* no console */ }
134
+ try { require('./use-log.js').record(useDir || require('./state-root.js').defaultRoot({ env }), [{ kind: 'use', page: 'people', control: 'peoplePrep', device: 'desk' }], now); } catch { /* a count, never a reason to fail */ }
135
+ if (flags.json) { say(JSON.stringify({ ok: true, ...p })); return 0; }
136
+ for (const l of linesOf(p)) say(l);
137
+ return 0;
138
+ }
139
+
140
+ module.exports = { TAG, DAYS, prepOf, linesOf, matchOf, ambiguousOf, tasksAll, run, USAGE };
@@ -171,6 +171,8 @@ const VERBS = Object.freeze({
171
171
  // Not a pm-os-absorb verb (run: null): initiative connector-data (job #1920, A150) added it through the same table.
172
172
  connectors: Object.freeze({ module: 'connectors-cli.js', run: null, guide: 'cli.md',
173
173
  help: 'pmos connectors data [<connector>] — what PMOS reads and writes through each connector, and what leaves this computer (pmos connectors help)' }),
174
+ print: Object.freeze({ module: 'print-cli.js', run: null, guide: 'cli.md',
175
+ help: 'pmos print <file.md|initiative id> [--out file.html] — one clean page to print or save as PDF (pmos print help)' }),
174
176
  // Not a pm-os-absorb verb (run: null): initiative press-release-faq (bet A362) added it through the same table.
175
177
  'press-release': Object.freeze({ module: 'press-release-cli.js', run: null, guide: 'cli.md',
176
178
  help: 'pmos press-release <initiative> | count — a one-page press release and FAQ for a bet, drafted from its record, for you to edit (pmos press-release help)' }),
@@ -49,7 +49,7 @@ const KEYS = Object.freeze({
49
49
  'pmos.home.cardfold', 'pmos-report-orders-hidden', 'cz-live-side',
50
50
  'pmos.pop.five', // the work popup's four toolbar actions, worked out weekly from use (idea A498, pm/pop-cap.js)
51
51
  ]),
52
- prefix: Object.freeze(['pmos.board.', 'pmos.pv.tab:', 'pmos.dash.view:', 'cz-vw-fold:']),
52
+ prefix: Object.freeze(['pmos.board.', 'pmos.pv.tab:', 'pmos.dash.view:', 'cz-vw-fold:', 'pmos.fold:']),
53
53
  });
54
54
  const EXACT = new Set(KEYS.exact);
55
55
 
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+ /* print-cli.js — `pmos print` (initiative print-pdf, job #1911, idea A379). The page comes from lib/print-pdf.js printFile: the same layout
3
+ * as Print or PDF in the workspace. One .html file is written; the PM opens it and chooses Save as PDF. Nothing is sent. */
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { TAG, brandOf, fileOf, printFile } = require('./print-pdf.js');
7
+
8
+ const COMMANDS = { print: ['brand'] };
9
+ const USAGE = [
10
+ 'usage: pmos print <file.md | initiative id> [--out <file.html>] — one clean page to print or save as PDF',
11
+ ' pmos print <initiative id> the initiative\'s record as a print page: title, date and page N of M on every page',
12
+ ' pmos print <file.md> --out x.html any report or document of the product; default <name>.print.html here',
13
+ ' pmos print brand the brand printed at the top right (the product\'s own design system), or none',
14
+ 'Open the page and choose Save as PDF. Nothing is sent.',
15
+ ];
16
+ function repoOf(cwd) {
17
+ let d = path.resolve(cwd);
18
+ 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; }
19
+ }
20
+ function used(o) {
21
+ try { const dir = o.stateDir || require('./state-root.js').defaultRoot({ env: o.env || process.env }); require('./use-log.js').record(dir, [{ kind: 'use', page: 'today', control: 'print-pdf', device: 'desk' }], o.now || Date.now()); } catch { /* a count, never a reason to fail */ }
22
+ }
23
+ async function run(argv, o = {}) {
24
+ const say = o.say || ((s) => console.log(s));
25
+ const args = argv[0] === 'print' ? argv.slice(1) : argv.slice();
26
+ const pos = [], flags = {};
27
+ for (let i = 0; i < args.length; i++) { const a = args[i]; if (a === '--root' || a === '--out' || a === '--date') flags[a.slice(2)] = args[++i]; else if (a === '--json') flags.json = true; else pos.push(a); }
28
+ const cmd = pos[0] || 'help';
29
+ if (cmd === 'help' || cmd === '--help') { USAGE.forEach((l) => say(l)); return pos[0] ? 0 : 2; }
30
+ const root = path.resolve(flags.root || o.root || repoOf(o.cwd || process.cwd()));
31
+ if (cmd === 'brand') {
32
+ const b = brandOf(root);
33
+ if (flags.json) { say(JSON.stringify({ ok: true, brand: b })); return 0; }
34
+ say(b ? `Printed pages show the brand ${b}.` : 'No brand: this product has no design system of its own, so printed pages show none.');
35
+ return 0;
36
+ }
37
+ const file = fileOf(root, cmd);
38
+ const r = await printFile(root, file, { date: flags.date });
39
+ if (!r.ok) { say('✗ ' + r.error); return 1; }
40
+ const out = path.resolve(o.cwd || process.cwd(), flags.out || path.basename(file).replace(/\.md$/i, '') + '.print.html');
41
+ fs.writeFileSync(out, r.html);
42
+ used(o);
43
+ console.log(`${TAG} printed ${path.relative(root, file)} out=${path.basename(out)}`);
44
+ if (flags.json) { say(JSON.stringify({ ok: true, title: r.title, out })); return 0; }
45
+ say(`✓ Wrote ${out}: "${r.title}". Open it and choose Save as PDF.`);
46
+ return 0;
47
+ }
48
+
49
+ module.exports = { run, COMMANDS, USAGE };
@@ -0,0 +1,96 @@
1
+ 'use strict';
2
+ /* print-pdf.js — Print or PDF, the Node side (initiative print-pdf, job #1911, idea A379; board BatchMoreADS panel 26). The layout itself is
3
+ * public/pm/print-pdf.js (layoutHtml, cleanHtml), loaded here with import(), so the terminal, the page and a report sent as a copy print
4
+ * the same page.
5
+ *
6
+ * brandOf(root) → the product's own design system brand name (its design-system/brand/tokens.json `name`, idea A1), or '' when
7
+ * the product has none or only PMOS's own. Read only.
8
+ * sectionsHtml(md) PURE → { title, sections: [{ h, html }] } from a markdown file (lib/report-export.js parseReport, sectionsOf)
9
+ * printFile(root, rel, { date }) → Promise { ok, title, html } | { ok: false, error } a file inside the product only
10
+ * fileOf(root, what) → the file `pmos print` prints: a path, or an initiative id (planning/initiatives/<id>.md, a kit's
11
+ * pmos/planning/initiatives or pmos/state/initiatives)
12
+ *
13
+ * THE ROUTE (lib/routes-report-design.js owns the prefix and hands it here): GET /api/print?ws=<id> → { ok, brand }. Read only; nothing is written or sent.
14
+ *
15
+ * THE COMMAND (lib/print-cli.js): pmos print <file.md | initiative id> [--out <file.html>] [--json] · pmos print brand. It writes one .html file (default
16
+ * <name>.print.html in the current folder); the PM opens it and chooses Save as PDF. A file outside the product is refused (exit 1) and
17
+ * nothing is written. Each print logs one `[print-pdf]` line and one use-log line (control print-pdf), the count the kill reads. */
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const { pathToFileURL } = require('url');
21
+
22
+ const TAG = '[print-pdf]';
23
+ const PAGE_JS = path.join(__dirname, '..', 'public', 'pm', 'print-pdf.js');
24
+ let page = null;
25
+ const layout = () => (page = page || import(pathToFileURL(PAGE_JS).href));
26
+
27
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
28
+ const inline = (s) => esc(s).replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>');
29
+
30
+ /* ── the brand ── */
31
+ function brandOf(root) {
32
+ if (!root) return '';
33
+ let DS; try { DS = require('./design-system.js'); } catch { return ''; }
34
+ const own = path.resolve(DS.OWN);
35
+ for (const p of DS.PLACES || []) {
36
+ const d = path.join(root, p);
37
+ if (path.resolve(d) === own) continue;
38
+ try { const j = JSON.parse(fs.readFileSync(path.join(d, 'brand', 'tokens.json'), 'utf8')); const n = String((j && j.name) || '').trim(); if (n && n !== 'PMOS Brand') return n.slice(0, 80); } catch { /* no brand there */ }
39
+ }
40
+ return '';
41
+ }
42
+
43
+ /* ── markdown to sections ── */
44
+ function blockHtml(blocks) {
45
+ let out = '', list = false;
46
+ for (const b of blocks) {
47
+ if (b.t !== 'li' && list) { out += '</ul>'; list = false; }
48
+ if (b.t === 'li') { if (!list) { out += '<ul>'; list = true; } out += `<li>${inline(b.text)}</li>`; }
49
+ else if (b.t === 'h') out += `<h3>${inline(b.text)}</h3>`;
50
+ else if (b.t === 'p') out += `<p>${inline(b.text)}</p>`;
51
+ else if (b.t === 'table') out += `<table>${b.rows.map((r, i) => `<tr>${r.map((c) => (i ? `<td>${inline(c)}</td>` : `<th>${inline(c)}</th>`)).join('')}</tr>`).join('')}</table>`;
52
+ }
53
+ return out + (list ? '</ul>' : '');
54
+ }
55
+ function sectionsHtml(md) {
56
+ const RE = require('./report-export.js');
57
+ const rep = RE.parseReport(md);
58
+ return { title: rep.title, sections: RE.sectionsOf(rep).map((s) => ({ h: s.heading === rep.title ? '' : s.heading, html: blockHtml(s.blocks) })) };
59
+ }
60
+
61
+ const inside = (root, abs) => { const r = path.relative(path.resolve(root), abs); return !!r && !r.startsWith('..') && !path.isAbsolute(r); };
62
+
63
+ function fileOf(root, what) {
64
+ const w = String(what || '').trim();
65
+ if (!w) return null;
66
+ if (/^[a-z0-9][a-z0-9-]{0,80}$/.test(w) && !/\.md$/.test(w)) {
67
+ for (const d of ['planning/initiatives', 'pmos/planning/initiatives', 'pmos/state/initiatives']) {
68
+ const f = path.join(root, d, w + '.md');
69
+ if (fs.existsSync(f)) return f;
70
+ }
71
+ }
72
+ return path.resolve(root, w);
73
+ }
74
+
75
+ async function printFile(root, file, { date = '' } = {}) {
76
+ const abs = path.resolve(root, file);
77
+ if (!inside(root, abs)) return { ok: false, error: 'That file is outside this product. PMOS prints only the product\'s own files.' };
78
+ let md;
79
+ try { md = fs.readFileSync(abs, 'utf8'); } catch { return { ok: false, error: 'No such file: ' + path.relative(root, abs) }; }
80
+ const { title, sections } = sectionsHtml(md);
81
+ const L = await layout();
82
+ return { ok: true, title, html: L.layoutHtml({ title, date: date || L.dateLine(), brand: brandOf(root), sections }) };
83
+ }
84
+
85
+ /* ── the route ── */
86
+ const prefixes = ['/api/print'];
87
+ async function handle(req, res, url, ctx) {
88
+ if (url.pathname !== '/api/print') return false;
89
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
90
+ let w = null;
91
+ try { w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null; } catch { w = null; }
92
+ ctx.json(res, { ok: true, brand: w && w.root ? brandOf(w.root) : '' });
93
+ return true;
94
+ }
95
+
96
+ module.exports = { TAG, brandOf, sectionsHtml, fileOf, printFile, prefixes, handle };
@@ -13,8 +13,11 @@
13
13
  * { v: 1, ev: 'reason', cid, reason, at, via } names (or renames) a comment's reason
14
14
  * { v: 1, ev: 'filed', reason, capture, at, by } the ✦ was accepted: a triage item was filed
15
15
  * { v: 1, ev: 'unfiled', capture, at, by } its Undo
16
+ * { v: 1, ev: 'read', from, fsig, n, at } PMOS read an export in the product's files by itself
17
+ * { v: 1, ev: 'unread', from, fsig, at, by } its Undo: the file's comments go, the file waits until it changes
16
18
  * cid 'vc_' + 10 hex of sha1(source, at, text): the same comment imported twice is one comment
17
19
  * source survey | review | other
20
+ * from the export a comment came from, relative to the product's folder (a comment PMOS read by itself), or absent
18
21
  * score a number on `scale` (5 for a store's stars, 10 for an NPS survey), or null
19
22
  *
20
23
  * WHO NAMES A REASON (spec question 2, default kept): whoever adds the comment (the import's reason column, or the chat).
@@ -28,6 +31,13 @@
28
31
  * ledgerFile(root) · read(root) · add(root, o) · importFile(root, file) · nameReason(root, cid, reason)
29
32
  * file(root, reason, { actor, now }) · undo(root, capture, { actor, now }) · count(root, now)
30
33
  *
34
+ * EXPORTS IN THE PRODUCT'S FILES (initiative review-reasons-files; LINE.md Rule 12, no chat-only features): `GET /api/voice` runs
35
+ * readExports first, so an app-store or survey export put in the product's folder shows on Work with no typed ask. findExports looks
36
+ * for CSV or JSON files whose name says review, survey, nps, csat, feedback or rating, at most MAX_DEPTH folders deep, outside dot
37
+ * folders, node_modules and build folders, at most MAX_BYTES. A file with no text column is left alone. One `read` line per file
38
+ * version (fsig = size:mtime); `unread` takes its comments back and the file waits until it changes. The scan is kept SCAN_MS per product.
39
+ * findExports(root) · readExports(root, { now, fresh }) · unread(root, from, { actor, now }) · readsOf(lines, now)
40
+ *
31
41
  * CLI (`pmos voice`, lib/voice-cli.js through lib/pmos-verbs.js; what chat and agents run; nothing else writes the ledger):
32
42
  * pmos voice add --text "<comment>" [--reason "<reason>"] [--score 2] [--scale 5|10] [--source review] [--at <iso>]
33
43
  * pmos voice import <file.csv|file.json> columns: text, reason, score, scale, source, at (a header row in a CSV)
@@ -56,6 +66,17 @@ const MIN_SUGGEST = 2; // a complaint needs at least this many comments in the
56
66
  const CID_RE = /^vc_[0-9a-f]{10}$/;
57
67
  const CAPTURE_RE = /^capture-\d{4}-\d{2}-\d{2}-\d+$/;
58
68
  const LINE_BREAK = /[\r\n\x00-\x08\x0b-\x1f]/;
69
+ const EXPORT_NAME = /(review|survey|nps|csat|feedback|rating)/i;
70
+ const EXPORT_EXT = /\.(csv|json)$/i;
71
+ const SKIP_DIR = /^(\..*|node_modules|dist|build|out|coverage|vendor|target)$/;
72
+ const MAX_DEPTH = 3;
73
+ const MAX_BYTES = 5 * 1024 * 1024;
74
+ const MAX_ENTRIES = 4000; // a folder walk stops after this many entries, so a huge checkout cannot slow Work down
75
+ const SCAN_MS = 60000;
76
+ const READ_DAYS = 7;
77
+ const TEXT_KEYS = ['text', 'comment', 'comments', 'review', 'review text', 'body', 'feedback', 'answer', 'content'];
78
+ const SCORE_KEYS = ['score', 'rating', 'star rating', 'stars'];
79
+ const DATE_KEYS = ['at', 'date', 'created', 'created at', 'review date', 'submitted at'];
59
80
  const STOP = new Set(['the', 'and', 'for', 'with', 'from', 'that', 'this', 'are', 'was', 'not', 'but', 'too', 'very', 'than', 'when', 'have', 'has', 'its', 'our', 'your', 'you', 'all', 'any', 'can']);
60
81
 
61
82
  const str = (v) => (v == null ? '' : String(v)).trim();
@@ -81,7 +102,7 @@ function parseComment(o = {}, now = new Date()) {
81
102
  if (!Number.isFinite(atMs)) return { ok: false, error: 'the date is not one PMOS can read; use 2026-11-20 or an ISO time' };
82
103
  const at = new Date(atMs).toISOString();
83
104
  const t = text.slice(0, MAX_TEXT);
84
- return { ok: true, line: { v: 1, ev: 'comment', cid: cidOf(source, at, t), at, source, score, scale, reason: reason || null, text: t, via: o.via || 'cli' } };
105
+ return { ok: true, line: { v: 1, ev: 'comment', cid: cidOf(source, at, t), at, source, score, scale, reason: reason || null, text: t, via: o.via || 'cli', ...(o.from ? { from: String(o.from) } : {}) } };
85
106
  }
86
107
 
87
108
  /** 'up 3×' from twice or more, 'up' from a quarter more, 'new' when the 30 days before had none, 'down' below three
@@ -105,8 +126,8 @@ function fold(lines) {
105
126
  if (l.ev === 'comment' && CID_RE.test(String(l.cid || '')) && str(l.text) && !comments.has(l.cid)) {
106
127
  const scale = l.scale === 10 ? 10 : 5, score = Number.isFinite(Number(l.score)) && l.score !== null ? Number(l.score) : null;
107
128
  comments.set(l.cid, { cid: l.cid, at: String(l.at || ''), source: SOURCES.includes(l.source) ? l.source : 'other', score, scale,
108
- reason: oneLine(l.reason).slice(0, MAX_REASON) || null, text: str(l.text).slice(0, MAX_TEXT) });
109
- } else if (l.ev === 'reason' && comments.has(l.cid)) comments.get(l.cid).reason = oneLine(l.reason).slice(0, MAX_REASON) || null;
129
+ reason: oneLine(l.reason).slice(0, MAX_REASON) || null, text: str(l.text).slice(0, MAX_TEXT), from: l.from ? String(l.from) : null });
130
+ } else if (l.ev === 'unread' && str(l.from)) { for (const [cid, c] of comments) if (c.from === l.from) comments.delete(cid); } else if (l.ev === 'reason' && comments.has(l.cid)) comments.get(l.cid).reason = oneLine(l.reason).slice(0, MAX_REASON) || null;
110
131
  else if (l.ev === 'filed' && CAPTURE_RE.test(String(l.capture || '')) && str(l.reason)) filed.set(l.capture, { reason: str(l.reason), capture: l.capture, at: l.at || null });
111
132
  else if (l.ev === 'unfiled') filed.delete(l.capture);
112
133
  }
@@ -211,21 +232,37 @@ function add(root, o, now = new Date()) {
211
232
  return { ok: true, cid: p.line.cid, already: false };
212
233
  }
213
234
 
214
- /** Comments from an export file (CSV with a header row, or a JSON array). → { ok, added, already, refused: [{ row, error }] } */
215
- function importFile(root, file, now = new Date()) {
235
+ /** The first non-empty value under one of `keys`, matching a column name in any case. */
236
+ function pick(o, keys) {
237
+ const low = new Map(Object.keys(o).map((k) => [k.trim().toLowerCase(), k]));
238
+ for (const k of keys) { const real = low.get(k); if (real != null && o[real] != null && String(o[real]).trim() !== '') return o[real]; }
239
+ return null;
240
+ }
241
+
242
+ /** The rows of an export (CSV with a header row, or a JSON array), or the reason it cannot be read. */
243
+ function rowsOf(file) {
216
244
  let raw = '';
217
245
  try { raw = fs.readFileSync(file, 'utf8'); } catch (e) { return { ok: false, error: `the file cannot be read: ${String((e && e.message) || e).slice(0, 160)}` }; }
218
246
  let items = null;
219
247
  if (/\.json$/i.test(file) || /^\s*\[/.test(raw)) { try { items = JSON.parse(raw); } catch { return { ok: false, error: 'the file is not JSON PMOS can read' }; } }
220
248
  else items = parseCsv(raw);
221
249
  if (!Array.isArray(items)) return { ok: false, error: 'the file holds no list of comments' };
250
+ return { ok: true, items };
251
+ }
252
+ const hasText = (items) => items.some((it) => it && typeof it === 'object' && Object.keys(it).some((k) => TEXT_KEYS.includes(k.trim().toLowerCase())));
253
+
254
+ /** Comments from an export file (CSV with a header row, or a JSON array). → { ok, added, already, refused: [{ row, error }] }
255
+ * opts.from: the file's path in the product (PMOS read it by itself); opts.source: the source when a row names none. */
256
+ function importFile(root, file, now = new Date(), opts = {}) {
257
+ const got = opts.items ? { ok: true, items: opts.items } : rowsOf(file);
258
+ if (!got.ok) return got;
222
259
  const known = new Set(fold(read(root)).comments.map((c) => c.cid));
223
260
  const fresh = [], refused = [];
224
261
  let already = 0;
225
- items.forEach((it, i) => {
262
+ got.items.forEach((it, i) => {
226
263
  const o = it && typeof it === 'object' ? it : {};
227
- const p = parseComment({ text: o.text || o.comment || o.review || o.body, reason: o.reason, score: o.score != null && o.score !== '' ? o.score : (o.rating != null && o.rating !== '' ? o.rating : null),
228
- scale: o.scale, source: o.source || 'other', at: o.at || o.date, via: 'import' }, now);
264
+ const p = parseComment({ text: pick(o, TEXT_KEYS), reason: pick(o, ['reason']), score: pick(o, SCORE_KEYS), scale: pick(o, ['scale']),
265
+ source: pick(o, ['source']) || opts.source || 'other', at: pick(o, DATE_KEYS), via: opts.from ? 'files' : 'import', from: opts.from }, now);
229
266
  if (!p.ok) { refused.push({ row: i + 1, error: p.error }); return; }
230
267
  if (known.has(p.line.cid)) { already++; return; }
231
268
  known.add(p.line.cid); fresh.push(p.line);
@@ -234,6 +271,80 @@ function importFile(root, file, now = new Date()) {
234
271
  return { ok: true, added: fresh.length, already, refused };
235
272
  }
236
273
 
274
+ /* ── exports in the product's files (review-reasons-files) ── */
275
+ const sourceOfName = (name) => (/survey|nps|csat/i.test(name) ? 'survey' : /review|rating/i.test(name) ? 'review' : 'other');
276
+
277
+ /** CSV or JSON files whose name says review, survey, nps, csat, feedback or rating, at most MAX_DEPTH folders deep.
278
+ * → [{ rel, abs, size, fsig, source }], sorted by path. */
279
+ function findExports(root) {
280
+ const out = [];
281
+ let seen = 0;
282
+ const walk = (dir, depth) => {
283
+ let ents = [];
284
+ try { ents = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
285
+ for (const e of ents) {
286
+ if (++seen > MAX_ENTRIES) return;
287
+ const abs = path.join(dir, e.name);
288
+ if (e.isDirectory()) { if (depth < MAX_DEPTH && !SKIP_DIR.test(e.name)) walk(abs, depth + 1); continue; }
289
+ if (!e.isFile() || !EXPORT_EXT.test(e.name) || !EXPORT_NAME.test(e.name)) continue;
290
+ let st = null;
291
+ try { st = fs.statSync(abs); } catch { continue; }
292
+ if (st.size > MAX_BYTES || !st.size) continue;
293
+ out.push({ rel: path.relative(root, abs).split(path.sep).join('/'), abs, size: st.size, fsig: `${st.size}:${Math.round(st.mtimeMs)}`, source: sourceOfName(e.name) });
294
+ }
295
+ };
296
+ walk(root, 0);
297
+ return out.sort((a, b) => a.rel.localeCompare(b.rel));
298
+ }
299
+
300
+ /** Per file, the last read or unread line. PURE. */
301
+ function filesOf(lines) {
302
+ const m = new Map();
303
+ for (const l of lines || []) if (l && (l.ev === 'read' || l.ev === 'unread') && str(l.from)) m.set(l.from, l);
304
+ return m;
305
+ }
306
+ /** The files read in the last READ_DAYS days that added comments and were not undone: [{ file, n, at }]. PURE. */
307
+ function readsOf(lines, now = Date.now()) {
308
+ const t = new Date(now).getTime();
309
+ return [...filesOf(lines).values()].filter((l) => l.ev === 'read' && l.n > 0 && t - Date.parse(l.at) <= READ_DAYS * DAY)
310
+ .map((l) => ({ file: l.from, n: l.n, at: l.at })).sort((a, b) => b.at.localeCompare(a.at));
311
+ }
312
+
313
+ const lastScan = new Map();
314
+ /** Read each new or changed export of the product's files. → { ok, read: [{ file, n }] }. At most once per SCAN_MS per product
315
+ * unless `fresh`. Nothing is written when no export is found. */
316
+ function readExports(root, { now = new Date(), fresh = false } = {}) {
317
+ const t = Date.now();
318
+ if (!fresh && lastScan.has(root) && t - lastScan.get(root) < SCAN_MS) return { ok: true, read: [], kept: true };
319
+ lastScan.set(root, t);
320
+ const found = findExports(root);
321
+ if (!found.length) return { ok: true, read: [] };
322
+ const state = filesOf(read(root));
323
+ const done = [];
324
+ for (const f of found) {
325
+ const was = state.get(f.rel);
326
+ if (was && was.fsig === f.fsig) continue;
327
+ const got = rowsOf(f.abs);
328
+ if (!got.ok || !hasText(got.items)) continue;
329
+ const r = importFile(root, f.abs, now, { from: f.rel, source: f.source, items: got.items });
330
+ if (!r.ok) continue;
331
+ append(root, [{ v: 1, ev: 'read', from: f.rel, fsig: f.fsig, n: r.added, at: new Date(now).toISOString() }]);
332
+ console.error(`${TAG} read ${r.added} from ${f.rel}`);
333
+ done.push({ file: f.rel, n: r.added });
334
+ }
335
+ return { ok: true, read: done };
336
+ }
337
+
338
+ /** Undo a read: the file's comments go, and the file waits until it changes. */
339
+ function unread(root, from, { actor = null, now = new Date() } = {}) {
340
+ const rel = str(from);
341
+ const was = filesOf(read(root)).get(rel);
342
+ if (!was || was.ev !== 'read') return { ok: false, status: 404, error: `PMOS did not read ${rel.slice(0, 200) || 'that file'} by itself` };
343
+ append(root, [{ v: 1, ev: 'unread', from: rel, fsig: was.fsig, at: new Date(now).toISOString(), by: (actor && actor.by) || 'agent:unknown' }]);
344
+ console.error(`${TAG} unread ${rel}`);
345
+ return { ok: true };
346
+ }
347
+
237
348
  function nameReason(root, cid, reason, now = new Date()) {
238
349
  const r = oneLine(reason);
239
350
  if (!CID_RE.test(String(cid || ''))) return { ok: false, error: 'name the comment by its id (vc_ and 10 letters or digits; pmos voice list shows them)' };
@@ -352,6 +463,7 @@ function run(argv, o = {}) {
352
463
  }
353
464
 
354
465
  module.exports = { TAG, FILE, SOURCES, WINDOW_DAYS, TREND_DAYS, parseComment, growthWord, fold, placeUnnamed, scoreLine, group, parseCsv,
355
- ledgerFile, read, sig, add, importFile, nameReason, file, undo, count, run, COMMANDS, USAGE };
466
+ ledgerFile, read, sig, add, importFile, nameReason, file, undo, count, run, COMMANDS, USAGE,
467
+ findExports, readExports, unread, readsOf, forgetScan: (root) => lastScan.delete(root) };
356
468
 
357
469
  if (require.main === module) process.exitCode = run(process.argv.slice(2));
@@ -153,6 +153,7 @@ const MODULES = Object.freeze([
153
153
  '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)
154
154
  'routes-principles', // bet A352: a product's principles drafted from its decisions, kept or dropped on the Board (records principles.jsonl; page-press POST)
155
155
  'routes-prefs', // bet A461: view preferences that follow the person to the phone and other browsers (runtime view-prefs.json; page-press POST)
156
+ 'routes-skill-map', // bet A208: the team skill map on Work, for the person and their lead only (records skill-map.jsonl; page-press POST)
156
157
  'routes-stakeholders', // bet A371: an initiative's stakeholder map, decides / must agree / needs to know, in the Work popup (records stakeholders.jsonl; page-press POST)
157
158
  'routes-code-map', // idea A176: the product's code map on Work, redrawn when the default branch moves (records code-map.json; read-only)
158
159
  'routes-arch-warns', // idea A54: one warning when an initiative names a risky part of the code (reads code-map.json; read-only)
@@ -15,6 +15,7 @@
15
15
  *
16
16
  * Sources: planning/records/{kr-metrics,bets,hypotheses}.jsonl through scripts/records, and <runtime>/signals/signals.jsonl. No facts
17
17
  * reader is used, so the route never starts a cold repository read. A number that no record holds is null, never invented. */
18
+ const { anchorId } = require('./anchor-id.js');
18
19
  const path = require('path');
19
20
  const fs = require('fs');
20
21
  const { repoScript } = require('./repo-script.js');
@@ -111,7 +112,7 @@ function signalsOf(outcomes, sig, readingsByMetric) {
111
112
  function synergyOf(krs, bets) {
112
113
  if (!bets.length) return null;
113
114
  const cols = krs.map((k) => ({ id: k.rid, n: String(k.metric || k.rid), icon: 'target' }));
114
- const hit = (b, c) => !!b.parent_kr && (String(b.parent_kr) === c.id || String(b.parent_kr) === c.n);
115
+ const hit = (b, c) => { const a = anchorId(b.parent_kr); return !!a && (a === c.id || a === c.n || String(b.parent_kr) === c.n); }; // the id, not its note (A547)
115
116
  const rows = bets.slice().sort((a, b) => a.rank - b.rank).map((b) => ({ id: b.rid, title: String(b.title), parked: b.horizon === 'later', weights: cols.map((c) => (hit(b, c) ? 1 : 0)), initiative: b.initiative || null }));
116
117
  const notes = [];
117
118
  cols.forEach((c, j) => { if (!rows.some((r) => !r.parked && r.weights[j] > 0)) notes.push({ icon: 'alert', tone: 'bad', text: c.n + ' has no active bet.' }); });
@@ -399,7 +399,7 @@ function applyOne(ctx, p, g, f, ini, x, choices, outbox) {
399
399
  else {
400
400
  const by = g.actor && g.actor.by && g.actor.by !== 'agent:auto' ? g.actor.by : 'agent:outcomes';
401
401
  const r = O.recordCheck(p.w.root, { initiative: ini, disposition: d.disposition, evidence: d.evidence, by, via: 'pmos', sources: x.sources || [] });
402
- if (r.ok) add({ op: 'verdict', at: r.line.at, disposition: d.disposition, horizon: d.horizon });
402
+ if (r.ok) { add({ op: 'verdict', at: r.line.at, disposition: d.disposition, horizon: d.horizon }); require('./lessons-draft.js').onClose(ctx, { root: p.w.root, id: ini }); } // lessons-on-close (A542)
403
403
  else x.failed = r.error;
404
404
  }
405
405
  } else if (x.group === 'outcome' && x.type === 'test') {
@@ -428,7 +428,7 @@ function applyOne(ctx, p, g, f, ini, x, choices, outbox) {
428
428
  // a met kill line (lib/kill-check.js, its ref is the record's kill line) says so, not "the outcome check said"
429
429
  const reason = (require('./kill-check.js').isKillRef(d.ref) ? `${String(d.evidence || '').replace(/[.\s]+$/, '')} (read ${d.check}).`
430
430
  : `The outcome check on ${d.check} said it did not work: ${String(d.evidence || '').replace(/[.\s]+$/, '')}.`).slice(0, 440);
431
- const stop = (why) => { const r = O.setLife(p.w.root, ini, 'cancelled', why, g.actor); if (r.ok) add({ op: 'life', from: r.from || 'active', to: 'cancelled' }); };
431
+ const stop = (why) => { const r = O.setLife(p.w.root, ini, 'cancelled', why, g.actor); if (r.ok) { add({ op: 'life', from: r.from || 'active', to: 'cancelled' }); require('./lessons-draft.js').onClose(ctx, { root: p.w.root, id: ini }); } }; // lessons-on-close (A542)
432
432
  if (d.next === 'kill') stop(reason);
433
433
  else if (d.next === 'iterate') {
434
434
  const t = RB.taskAdd(ctx, { ws: p.w.id, board: p.board.id, initiative: ini, title: 'Change what the outcome check showed, then check again', notes: [reason, source ? 'From ' + source : ''].filter(Boolean).join('\n').slice(0, 1900) }, g);
@@ -19,6 +19,7 @@
19
19
  * GET /api/report-notes?ws&path → { ok, speaker, suggestions, pins }
20
20
  * POST /api/report-notes/speaker { ws, path, slide, text } | { ws, path, slide, keep: true }
21
21
  * POST /api/report-notes/pin { ws, path, op, id?, slide, x, y, text, section? }
22
+ * GET /api/print?ws → { ok, brand } Print or PDF's brand, the product's own design system (lib/print-pdf.js handle, job #1911)
22
23
  *
23
24
  * WHO WRITES. Every POST passes pm-guard requirePagePress, and a request with an agent session header is refused first (403), as
24
25
  * routes-report-setups.js does. A job's render is data: the server sanitizes it (lib/report-design.js sanitize) before it is written or served.
@@ -455,6 +456,7 @@ function cycleAnswer(w, c) {
455
456
  }
456
457
 
457
458
  async function handle(req, res, url, ctx) {
459
+ if (url.pathname === '/api/print') return require('./print-pdf.js').handle(req, res, url, ctx); // Print or PDF's brand (job #1911): the product's own design system
458
460
  lastCtx = ctx;
459
461
  const p = url.pathname;
460
462
  const send = (r) => { ctx.json(res, r.body, r.status); return true; };
@@ -637,4 +639,4 @@ async function handle(req, res, url, ctx) {
637
639
  return send(bad(404, 'no such route'));
638
640
  }
639
641
 
640
- module.exports = { prefixes: ['/api/report-design', '/api/report-notes'], handle, attach, sweep, startCycle, resultJson, _promptFor: promptFor, _jobs: jobs, _fetches: fetches, startFetch };
642
+ module.exports = { prefixes: ['/api/report-design', '/api/report-notes', '/api/print'], handle, attach, sweep, startCycle, resultJson, _promptFor: promptFor, _jobs: jobs, _fetches: fetches, startFetch };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ /* routes-skill-map.js — the team skill map over HTTP (bet A208, initiative skill-map). The core is lib/skill-map.js; the verb is `pmos team skills`.
3
+ *
4
+ * GET /api/team/skills?ws=<id>[&as=<name>] → { ok, people, pair, window_days, for_reports: false }
5
+ * POST /api/team/skills { ws, act, key } → { ok, line } | 400 act ∈ skip · undo (a page press only)
6
+ *
7
+ * WHO SEES IT. The person and their lead, never a report or a published page: a GET that carries `pack=` (the read of a published
8
+ * page, public/pm/readonly.js) is refused with 403 and no rows. `as` gives a person's own view (only their row).
9
+ * Nothing here is sent anywhere.
10
+ */
11
+ const guard = require('./pm-guard.js');
12
+ const SM = require('./skill-map.js');
13
+ const { recordsDirFor } = require('./records-dir.js');
14
+
15
+ const CHECKOUT = require('path').join(__dirname, '..', '..');
16
+ function wsOf(ctx, ws) { try { return ctx && typeof ctx.getWs === 'function' ? ctx.getWs(ws || null) : null; } catch { return null; } }
17
+ const rootFor = (ctx, w) => (ctx && ctx.repoRoot) || (w && w.root) || CHECKOUT;
18
+
19
+ async function handle(req, res, url, ctx) {
20
+ if (url.pathname !== '/api/team/skills') return false;
21
+ const send = (status, body) => { ctx.json(res, body, status); return true; };
22
+ if (req.method === 'GET') {
23
+ if (url.searchParams.has('pack')) return send(403, { ok: false, error: 'the team skill map is only for the person and their lead; it is never on a published page' });
24
+ const wsId = url.searchParams.get('ws') || null;
25
+ const w = wsOf(ctx, wsId);
26
+ const v = SM.view(rootFor(ctx, w), { as: url.searchParams.get('as') || null, dir: recordsDirFor(ctx, wsId), now: ctx.now ? ctx.now() : Date.now(), log: ctx.log || ((s) => console.log(s)) });
27
+ return send(200, v);
28
+ }
29
+ if (req.method !== 'POST') return send(405, { ok: false, error: 'GET or POST' });
30
+ const rd = await ctx.readJson(req);
31
+ if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
32
+ const body = rd.body || {};
33
+ const g = guard.requirePagePress(req, body);
34
+ if (!g.ok) return send(g.status, { ok: false, error: g.error });
35
+ const r = SM.act(recordsDirFor(ctx, body.ws || null), String(body.act || ''), body.key, { by: (g.actor && g.actor.by) || 'pm' });
36
+ return r.ok ? send(200, { ok: true, line: r.line }) : send(400, { ok: false, error: r.error });
37
+ }
38
+
39
+ module.exports = { prefixes: ['/api/team/skills'], handle };