create-pmos 0.828.0 → 0.830.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 +237 -35
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/board-deliveries-test.js +2 -2
- package/workspace/briefing-premium-board-test.js +1 -1
- package/workspace/briefing-premium-insights-test.js +1 -1
- package/workspace/changelog.json +236 -8
- package/workspace/guide/agent-capabilities.md +1 -1
- package/workspace/guide/backlog.md +12 -1
- package/workspace/guide/cli.md +46 -1
- package/workspace/guide/home.md +2 -1
- package/workspace/guide/layout.md +1 -0
- package/workspace/guide/settings-and-switches.md +1 -0
- package/workspace/lib/board-premium.js +1 -0
- package/workspace/lib/code-map.js +8 -2
- package/workspace/lib/critical-needs.js +162 -0
- package/workspace/lib/deps-cli.js +102 -0
- package/workspace/lib/engine/boards.js +13 -2
- package/workspace/lib/factory-floor.js +16 -8
- package/workspace/lib/features.json +17 -13
- package/workspace/lib/needs-providers.js +1 -0
- package/workspace/lib/page-one-answer.js +86 -0
- package/workspace/lib/pages-cli.js +6 -2
- package/workspace/lib/people-cli.js +9 -1
- package/workspace/lib/people-prep.js +140 -0
- package/workspace/lib/pmos-verbs.js +10 -0
- package/workspace/lib/print-cli.js +49 -0
- package/workspace/lib/print-pdf.js +96 -0
- package/workspace/lib/prototype-cli.js +86 -0
- package/workspace/lib/report-cli.js +12 -2
- package/workspace/lib/report-readers.js +5 -3
- package/workspace/lib/review-pack.js +348 -0
- package/workspace/lib/review-reasons.js +121 -9
- package/workspace/lib/route-modules.js +5 -0
- package/workspace/lib/routes-boards.js +25 -2
- package/workspace/lib/routes-report-design.js +3 -1
- package/workspace/lib/routes-review-pack.js +42 -0
- package/workspace/lib/routes-roadmap-ops.js +53 -1
- package/workspace/lib/routes-sim-users.js +66 -0
- package/workspace/lib/routes-skill-map.js +39 -0
- package/workspace/lib/routes-strategy-card.js +13 -6
- package/workspace/lib/routes-team-waits.js +24 -0
- package/workspace/lib/sim-users.js +329 -0
- package/workspace/lib/skill-map.js +199 -0
- package/workspace/lib/task-store.js +1 -1
- package/workspace/lib/team-cli.js +20 -1
- package/workspace/lib/team-waits.js +167 -0
- package/workspace/lib/tradeoff-cards.js +258 -0
- package/workspace/lib/tradeoff-cli.js +83 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/action-keys.js +1 -0
- package/workspace/public/pm/ask-here-ctx.js +25 -1
- package/workspace/public/pm/ask-here.css +7 -0
- package/workspace/public/pm/ask-here.js +15 -2
- package/workspace/public/pm/bd-backlog.css +61 -0
- package/workspace/public/pm/bd-backlog.js +99 -7
- package/workspace/public/pm/bd-work.js +12 -1
- package/workspace/public/pm/code-map.js +15 -4
- package/workspace/public/pm/cozy-board.css +5 -1
- package/workspace/public/pm/cozy-library.css +5 -0
- package/workspace/public/pm/cozy-pop-work.js +4 -1
- package/workspace/public/pm/cozy-proto.css +5 -0
- package/workspace/public/pm/cozy-proto.js +11 -3
- package/workspace/public/pm/cozy-search.js +2 -2
- package/workspace/public/pm/cozy-today-app.js +5 -2
- package/workspace/public/pm/day-time.js +8 -0
- package/workspace/public/pm/factory.js +199 -0
- package/workspace/public/pm/home-ini.js +3 -2
- package/workspace/public/pm/ini-links.js +2 -1
- package/workspace/public/pm/ini-tasks.js +5 -2
- package/workspace/public/pm/ini-view-model.js +14 -6
- package/workspace/public/pm/ini-view.js +12 -2
- package/workspace/public/pm/library-model.js +1 -1
- package/workspace/public/pm/page-one-answer.css +18 -0
- package/workspace/public/pm/page-one-answer.js +134 -0
- package/workspace/public/pm/pop-cap.js +5 -3
- package/workspace/public/pm/pop-work-model.js +8 -6
- package/workspace/public/pm/portfolio.js +1 -1
- package/workspace/public/pm/premium-board.js +23 -6
- package/workspace/public/pm/premium-library.js +27 -3
- package/workspace/public/pm/premium-report-read.js +11 -2
- package/workspace/public/pm/print-pdf.js +191 -0
- package/workspace/public/pm/range-pick.css +12 -0
- package/workspace/public/pm/range-pick.js +30 -6
- package/workspace/public/pm/review-pack.js +47 -0
- package/workspace/public/pm/review-reasons.js +19 -5
- package/workspace/public/pm/sim-users.js +34 -0
- package/workspace/public/pm/skill-map.js +57 -0
- package/workspace/public/pm/sort-order.js +3 -0
- package/workspace/public/pm/task-card.js +10 -7
- package/workspace/public/pm/team-waits.js +56 -0
- package/workspace/public/pm/tradeoff-cards.css +27 -0
- package/workspace/public/pm/tradeoff-cards.js +183 -0
- package/workspace/public/premium-board.html +3 -0
- package/workspace/public/today.html +1 -0
- package/workspace/run-tests.js +9 -1
- package/workspace/test-lists/critical-needs.json +9 -0
- package/workspace/test-lists/factory-page-ui.json +9 -0
- package/workspace/test-lists/page-one-answer.json +9 -0
- package/workspace/test-lists/people-prep.json +9 -0
- package/workspace/test-lists/print-pdf.json +9 -0
- package/workspace/test-lists/review-pack.json +9 -0
- package/workspace/test-lists/sim-users.json +9 -0
- package/workspace/test-lists/skill-map.json +9 -0
- package/workspace/test-lists/surface-ask-card.json +9 -0
- package/workspace/test-lists/task-time-optional.json +9 -0
- package/workspace/test-lists/team-waits.json +9 -0
- package/workspace/test-lists/tradeoff-cards.json +9 -0
- package/workspace/test-lists/voice-files.json +9 -0
- package/workspace/test-timings.json +25 -0
|
@@ -48,7 +48,7 @@ function blockOf(text) {
|
|
|
48
48
|
const titles = new Map();
|
|
49
49
|
let inInis = false, cur = null;
|
|
50
50
|
L.forEach((l, i) => {
|
|
51
|
-
if (/^##\s/.test(l)) { inInis = /^##\s+Initiatives\s*$/i.test(l); cur = null; return; }
|
|
51
|
+
if (/^##\s/.test(l)) { inInis = /^##\s+(Initiatives|Bets that failed)\s*$/i.test(l); cur = null; return; } // the review pack's failed bets are blocks too
|
|
52
52
|
const m = inInis && /^###\s+(.+?)\s+\(([A-Za-z0-9._-]{1,80})\)\s*$/.exec(l);
|
|
53
53
|
if (m) { cur = m[2]; titles.set(m[2], m[1].trim()); }
|
|
54
54
|
if (inInis) out[i] = cur;
|
|
@@ -185,7 +185,7 @@ let attached = false;
|
|
|
185
185
|
function attach(ctxFactory) {
|
|
186
186
|
if (attached || typeof ctxFactory !== 'function') return;
|
|
187
187
|
attached = true;
|
|
188
|
-
|
|
188
|
+
const heard = ({ root, cadence, path: rel }) => {
|
|
189
189
|
setImmediate(() => {
|
|
190
190
|
let ctx = null; try { ctx = ctxFactory(); } catch { ctx = null; }
|
|
191
191
|
if (!ctx) return;
|
|
@@ -199,7 +199,9 @@ function attach(ctxFactory) {
|
|
|
199
199
|
file({ root: abs, rel, cadence, dir, runtime: ctx.runtimeDir || null, ask: SC.askVia(spawn), ws: w.id || '', board })
|
|
200
200
|
.catch((e) => console.log(`[report-readers] ${rel}: not run (${one(e && e.message, 160)})`));
|
|
201
201
|
});
|
|
202
|
-
}
|
|
202
|
+
};
|
|
203
|
+
require('./report-draft.js').onDraftWritten(heard);
|
|
204
|
+
try { require('./review-pack.js').onWritten(heard); } catch { /* a checkout without the review pack still reads its reports */ } // the monthly review pack (job #1910)
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
/** Reader proposals filed in one state folder: the health number. */
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* review-pack.js — the monthly product review pack (initiative review-pack, job #1910, idea A343; board BatchMoreADS panel 25, agreed 2026-11-25).
|
|
3
|
+
*
|
|
4
|
+
* Before a monthly review with leadership the PM writes the same page from zero. PMOS already keeps each part of it as a record, so it drafts
|
|
5
|
+
* the page and the PM edits it. One pack per product per month. No model call: every line is read from a record, and every line names that
|
|
6
|
+
* record. A part with nothing to cite is left out (no source, no line; zero is silence).
|
|
7
|
+
*
|
|
8
|
+
* gather(root, { today, stateDir }) → { goals, failed, decision, asks } the product's records, each item with `source` { label, ref } or none
|
|
9
|
+
* goals the key results of the OKR files and the loose KR metric records (lib/goal-source.js), with the state of their newest reading
|
|
10
|
+
* (lib/goal-status.js readingOf). Source: the reading's own source, else the key result's line in the OKR file, else the record.
|
|
11
|
+
* failed each refuted outcome check of the last WINDOW_DAYS days (outcome_checks.jsonl, the live checks only), with the newest Lessons
|
|
12
|
+
* line of that experiment (artefacts.jsonl). Source: the check's path:line.
|
|
13
|
+
* decision a key result of the OKR files that is a decision (okr-goals `decision`: go/no-go, decided by) with a date today or later, the
|
|
14
|
+
* nearest first; else the decision journal's next look-again (state open or due), the nearest first. Source: its line.
|
|
15
|
+
* asks the Narrative artefact's `asks` lines of the product (scope portfolio or board:<id>), newest first. Source: the set's own sources.
|
|
16
|
+
* packOf({ product, today, goals, failed, decision, asks }) PURE → { title, month, slot, sections: [{ key, head, lines | bets }], dropped } | null
|
|
17
|
+
* null when no part has a line. `dropped` counts the items left out for having no source.
|
|
18
|
+
* markdown(pack) PURE → the file. readPack(text) PURE → { title, sections } read back from a file (the PM's edits show in Library)
|
|
19
|
+
* write(root, pack, { redraft }) → { ok, path, sha, written } | { ok: false, status, error }
|
|
20
|
+
* <state>/reports/review-pack/<YYYY-MM>-01.md (lib/report-draft.js draftPath, so the Issue press and the report readers know it).
|
|
21
|
+
* A pack that exists is left byte for byte as it is (the PM may have edited it) unless `redraft`; an issued pack is frozen (409).
|
|
22
|
+
* After a write, the report readers are told (onWritten: lib/report-readers.js attach listens here as it does to report drafts).
|
|
23
|
+
* onWritten(fn) → unsubscribe
|
|
24
|
+
* itemsOf({ ws, name, packs }) PURE → Library rows (the lib/library-items.js ITEM shape) in the Reports family, kind 'Review pack', with
|
|
25
|
+
* `pack` { sections, cadence, slot, sha, issued } for the preview and the share (Issue) press. lib/routes-review-pack.js serves them.
|
|
26
|
+
* due(today) PURE → true in the last DUE_DAYS days of the month: the pack is drafted before the review.
|
|
27
|
+
* tick(ctx, now) → [{ ws, ok, path? , why? }] drafts the month's pack of each product that has none, when due. Never shares.
|
|
28
|
+
* autoOn(env) → whether Library's open drafts due packs here (PMOS_REVIEW_PACK; off by default on a scratch server)
|
|
29
|
+
* list(root) → [{ path, slot, title, sections, sha, cadence }] the packs of one product, newest first (Library › Reports)
|
|
30
|
+
* cli(args, { root, now, say }) → exit code `pmos report pack [--redraft] [--json] [--now <time>]`
|
|
31
|
+
* The copy names PMOS only. Sharing is the PM's Issue press (POST /api/report/issue); nothing here issues or sends. */
|
|
32
|
+
const fs = require('fs');
|
|
33
|
+
const path = require('path');
|
|
34
|
+
|
|
35
|
+
const CADENCE = 'review-pack';
|
|
36
|
+
const WINDOW_DAYS = 30;
|
|
37
|
+
const DUE_DAYS = 7;
|
|
38
|
+
const MAX = { goals: 6, failed: 4, asks: 4 };
|
|
39
|
+
const DAY = 86400000;
|
|
40
|
+
const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
41
|
+
const MON = MONTHS.map((m) => m.slice(0, 3));
|
|
42
|
+
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
43
|
+
const one = (v, n = 240) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
44
|
+
const short = (d) => (DAY_RE.test(String(d || '')) ? (+d.slice(8, 10)) + ' ' + MON[+d.slice(5, 7) - 1] : String(d || ''));
|
|
45
|
+
const firstSentence = (s) => { const t = one(s, 600); const m = /^(.+?[.;])(\s|$)/.exec(t); return one(m ? m[1].replace(/[.;]$/, '') : t, 160); };
|
|
46
|
+
const relOf = (root, f) => path.relative(root, f).split(path.sep).join('/');
|
|
47
|
+
const SEVERITY = { broken: 0, behind: 1, close: 2, none: 3, on: 4 };
|
|
48
|
+
const STATE_WORD = { on: 'on track', behind: 'behind', close: 'near its limit', broken: 'over its limit', none: 'no reading yet' };
|
|
49
|
+
const HEAD = { goals: 'Goals', failed: 'Bets that failed', decision: 'Next big decision', asks: 'Asks' };
|
|
50
|
+
const SAID = 'Drafted by PMOS from goals, experiments and decisions. Edit, then share.';
|
|
51
|
+
|
|
52
|
+
/* ── reading the records ─────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
53
|
+
function linesOf(file) { try { return fs.readFileSync(file, 'utf8').split('\n'); } catch { return null; } }
|
|
54
|
+
function stateDirOf(root) {
|
|
55
|
+
for (const rel of [['pmos', 'state'], ['state'], ['.pmos']]) { const d = path.join(root, ...rel); try { if (fs.statSync(d).isDirectory()) return d; } catch { /* next */ } }
|
|
56
|
+
try { return require('./driver.js').stateDirOf(root); } catch { return null; }
|
|
57
|
+
}
|
|
58
|
+
function okrDirOf(root) {
|
|
59
|
+
for (const d of [path.join(root, 'pmos', 'planning', 'okrs'), path.join(root, 'planning', 'okrs')]) { try { if (fs.statSync(d).isDirectory()) return d; } catch { /* next */ } }
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/** The path:line of the first line of the OKR files that names a key result's token as a heading or a list item. */
|
|
63
|
+
const tokRe = (t) => new RegExp('(^|[^A-Za-z0-9.-])' + String(t).replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '([^A-Za-z0-9-]|$)');
|
|
64
|
+
const listy = (l) => /^\s*(#{1,6}\s|[-*]\s|\|)/.test(l);
|
|
65
|
+
/** The path:line of a key result in the OKR files: the first heading or list line naming its token after its objective's line (KR1 repeats per objective). */
|
|
66
|
+
function okrRef(root, files, token, objective) {
|
|
67
|
+
const dir = okrDirOf(root);
|
|
68
|
+
if (!dir || !token) return null;
|
|
69
|
+
const re = tokRe(token), ro = objective ? tokRe(objective) : null;
|
|
70
|
+
for (const f of files || []) {
|
|
71
|
+
const L = linesOf(path.join(dir, f));
|
|
72
|
+
if (!L) continue;
|
|
73
|
+
const o = ro ? L.findIndex((l) => listy(l) && ro.test(l)) : 0;
|
|
74
|
+
if (o < 0) continue;
|
|
75
|
+
const i = L.findIndex((l, n) => n >= o && listy(l) && re.test(l));
|
|
76
|
+
if (i >= 0) return relOf(root, path.join(dir, f)) + ':' + (i + 1);
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function titleOf(root, id) {
|
|
81
|
+
for (const d of [path.join(root, 'pmos', 'state', 'initiatives'), path.join(root, 'planning', 'initiatives')]) {
|
|
82
|
+
const L = linesOf(path.join(d, id + '.md'));
|
|
83
|
+
if (!L) continue;
|
|
84
|
+
const t = L.slice(0, 40).find((l) => /^title:\s*/.test(l));
|
|
85
|
+
if (t) return one(t.replace(/^title:\s*/, '').replace(/^["']|["']$/g, ''), 120);
|
|
86
|
+
}
|
|
87
|
+
return id;
|
|
88
|
+
}
|
|
89
|
+
function goalsOf(root, today) {
|
|
90
|
+
const GS = require('./goal-status.js');
|
|
91
|
+
let src; try { src = require('./goal-source.js').source({ root }); } catch { return []; }
|
|
92
|
+
const files = (src.okr && src.okr.files) || [];
|
|
93
|
+
let recRel = ''; try { recRel = relOf(root, require('./goal-source.js').recordsDirOf(root)) + '/kr-metrics.jsonl'; } catch { recRel = ''; }
|
|
94
|
+
const out = [];
|
|
95
|
+
const add = (title, rec, token, objective) => {
|
|
96
|
+
const r = rec ? GS.readingOf(rec, today) : { dot: 'none', txt: '', source: '' };
|
|
97
|
+
let ref = r.source ? one(r.source, 200) : '';
|
|
98
|
+
let label = ref ? 'reading' : '';
|
|
99
|
+
if (!ref && token) { ref = okrRef(root, files, token, objective) || ''; label = ref ? 'OKR file' : ''; }
|
|
100
|
+
if (!ref && rec && rec.rid && recRel) { ref = recRel + '#' + rec.rid; label = 'goal record'; }
|
|
101
|
+
const state = STATE_WORD[r.dot] || 'no reading yet';
|
|
102
|
+
const text = r.dot === 'none' ? `${title}: no reading yet` : `${title}: ${r.txt}${r.txt ? ' · ' : ''}${state}${r.stale && r.ageDays != null ? `, reading ${r.ageDays} days old` : ''}`;
|
|
103
|
+
out.push({ title, dot: r.dot, text: one(text, 200), source: ref ? { label, ref } : null });
|
|
104
|
+
};
|
|
105
|
+
for (const g of src.goals || []) if (!(g.k && g.k.decision && !g.record)) add(one(g.title, 110), g.record, g.token, g.o && g.o.token); // a decision key result is the Next big decision, not a goal
|
|
106
|
+
for (const rec of src.loose || []) add(one(rec.title || rec.rid, 110), rec, null);
|
|
107
|
+
return out.sort((a, b) => SEVERITY[a.dot] - SEVERITY[b.dot]);
|
|
108
|
+
}
|
|
109
|
+
function failedOf(root, today, stateDir) {
|
|
110
|
+
const O = require('./outcomes.js');
|
|
111
|
+
const files = [...new Set([stateDir && path.join(stateDir, 'outcome_checks.jsonl'), path.join(root, 'pmos', 'state', 'outcome_checks.jsonl'), path.join(root, 'planning', 'runs', 'outcome_checks.jsonl')].filter(Boolean))];
|
|
112
|
+
const rows = [], at = new Map();
|
|
113
|
+
for (const f of files) (linesOf(f) || []).forEach((l, i) => { let o = null; try { o = JSON.parse(l); } catch { return; } if (o && o.initiative_id) { rows.push(o); at.set(o, relOf(root, f) + ':' + (i + 1)); } });
|
|
114
|
+
const live = new Set(O.liveChecks(rows));
|
|
115
|
+
const from = Date.parse(today + 'T00:00:00Z') - WINDOW_DAYS * DAY, to = Date.parse(today + 'T23:59:59Z');
|
|
116
|
+
let lessons = new Map();
|
|
117
|
+
try {
|
|
118
|
+
const A = require('./artefacts.js');
|
|
119
|
+
const F = A.fold(A.readLines(A.file(stateDir)));
|
|
120
|
+
lessons = new Map([...F].map(([scope, m]) => [scope, ((m.get('lessons') || {}).sets || []).filter((s) => s.text)]));
|
|
121
|
+
} catch { lessons = new Map(); }
|
|
122
|
+
const out = [];
|
|
123
|
+
for (const r of rows) {
|
|
124
|
+
if (!live.has(r) || r.disposition !== 'refuted') continue;
|
|
125
|
+
const t = Date.parse(r.checked_at || r.at || r.date || '');
|
|
126
|
+
if (!(t >= from && t <= to)) continue;
|
|
127
|
+
const id = String(r.initiative_id);
|
|
128
|
+
const ls = lessons.get('experiment:' + id) || lessons.get('initiative:' + id) || [];
|
|
129
|
+
const lesson = ls.length ? one(ls[ls.length - 1].text, 160) : '';
|
|
130
|
+
const found = firstSentence(r.evidence);
|
|
131
|
+
const text = (found || 'The outcome check refuted it') + (lesson ? `; learned ${lesson.replace(/^learned\s+/i, '')}` : '');
|
|
132
|
+
out.push({ id, title: titleOf(root, id), at: t, text: one(text, 280), source: { label: 'outcome check', ref: at.get(r) } });
|
|
133
|
+
}
|
|
134
|
+
return out.sort((a, b) => b.at - a.at);
|
|
135
|
+
}
|
|
136
|
+
function decisionOf(root, today) {
|
|
137
|
+
try {
|
|
138
|
+
const OG = require('./okr-goals.js');
|
|
139
|
+
const okr = OG.read(root);
|
|
140
|
+
const ks = [];
|
|
141
|
+
for (const o of (okr.ok && okr.objectives) || []) for (const k of o.krs || []) if (k.decision && DAY_RE.test(String(k.due || '')) && k.due >= today) ks.push(Object.assign({ otoken: o.token }, k));
|
|
142
|
+
ks.sort((a, b) => a.due.localeCompare(b.due));
|
|
143
|
+
for (const k of ks) {
|
|
144
|
+
const ref = okrRef(root, okr.files, k.token, k.otoken);
|
|
145
|
+
if (ref) return { text: one(`${k.title}, by ${short(k.due)}`, 200), source: { label: 'OKR file', ref } };
|
|
146
|
+
}
|
|
147
|
+
} catch { /* no OKR file */ }
|
|
148
|
+
try {
|
|
149
|
+
const DJ = require('./decision-journal.js');
|
|
150
|
+
const J = DJ.read(root);
|
|
151
|
+
const es = DJ.fold(J.rows, { today }).filter((e) => (e.state === 'open' || e.state === 'due') && e.decided && DAY_RE.test(String(e.check || ''))).sort((a, b) => a.check.localeCompare(b.check));
|
|
152
|
+
for (const e of es) {
|
|
153
|
+
for (const f of (DJ.filesOf(root).all || [])) {
|
|
154
|
+
const L = linesOf(f) || [];
|
|
155
|
+
const i = L.findIndex((l) => l.includes(`"id":"${e.id}"`) && l.includes('"decision"'));
|
|
156
|
+
if (i >= 0) return { text: one(`Look again at "${one(e.decided, 120)}", by ${short(e.check)}`, 200), source: { label: 'decision journal', ref: relOf(root, f) + ':' + (i + 1) } };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} catch { /* no journal */ }
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
function asksOf(stateDir) {
|
|
163
|
+
try {
|
|
164
|
+
const A = require('./artefacts.js');
|
|
165
|
+
const F = A.fold(A.readLines(A.file(stateDir)));
|
|
166
|
+
const out = [];
|
|
167
|
+
for (const [scope, m] of F) {
|
|
168
|
+
if (scope !== 'portfolio' && !/^board:/.test(scope)) continue;
|
|
169
|
+
for (const s of ((m.get('narrative') || {}).sets || [])) {
|
|
170
|
+
if (s.field !== 'asks' || !one(s.text)) continue;
|
|
171
|
+
const src = (Array.isArray(s.sources) ? s.sources : []).find((x) => x && x.ref);
|
|
172
|
+
out.push({ at: String(s.at || ''), text: one(s.text, 200), source: src ? { label: one(src.label || 'source', 40), ref: one(src.ref, 200) } : null });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return out.sort((a, b) => b.at.localeCompare(a.at));
|
|
176
|
+
} catch { return []; }
|
|
177
|
+
}
|
|
178
|
+
function gather(root, { today, stateDir } = {}) {
|
|
179
|
+
const abs = path.resolve(String(root));
|
|
180
|
+
const dir = stateDir || stateDirOf(abs);
|
|
181
|
+
const t = DAY_RE.test(String(today || '')) ? today : new Date().toISOString().slice(0, 10);
|
|
182
|
+
return { goals: goalsOf(abs, t), failed: dir || abs ? failedOf(abs, t, dir) : [], decision: decisionOf(abs, t), asks: dir ? asksOf(dir) : [] };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* ── the pack ─────────────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
186
|
+
const cited = (x) => !!(x && one(x.text) && x.source && one(x.source.ref));
|
|
187
|
+
function packOf({ product, today, goals = [], failed = [], decision = null, asks = [] } = {}) {
|
|
188
|
+
if (!DAY_RE.test(String(today || ''))) return null;
|
|
189
|
+
let dropped = 0;
|
|
190
|
+
const keep = (xs, n) => { const all = (xs || []).filter((x) => x && one(x.text)); const ok = all.filter(cited); dropped += all.length - ok.length; return ok.slice(0, n); };
|
|
191
|
+
const sections = [];
|
|
192
|
+
const g = keep(goals, MAX.goals);
|
|
193
|
+
if (g.length) sections.push({ key: 'goals', head: HEAD.goals, lines: g.map((x) => ({ text: one(x.text, 200), source: x.source })) });
|
|
194
|
+
const f = keep(failed, MAX.failed);
|
|
195
|
+
if (f.length) sections.push({ key: 'failed', head: HEAD.failed, bets: f.map((x) => ({ id: x.id, title: one(x.title || x.id, 120), lines: [{ text: one(x.text, 280), source: x.source }] })) });
|
|
196
|
+
const d = keep(decision ? [decision] : [], 1);
|
|
197
|
+
if (d.length) sections.push({ key: 'decision', head: HEAD.decision, lines: [{ text: one(d[0].text, 200), source: d[0].source }] });
|
|
198
|
+
const a = keep(asks, MAX.asks);
|
|
199
|
+
if (a.length) sections.push({ key: 'asks', head: HEAD.asks, lines: a.map((x) => ({ text: one(x.text, 200), source: x.source })) });
|
|
200
|
+
if (!sections.length) return null;
|
|
201
|
+
const month = MONTHS[+today.slice(5, 7) - 1];
|
|
202
|
+
const name = one(product || 'Product', 80);
|
|
203
|
+
return { title: `${name} · ${month} review`, product: name, month, slot: today.slice(0, 7) + '-01', today, sections, dropped };
|
|
204
|
+
}
|
|
205
|
+
const srcText = (s) => (s && s.ref ? ` — source: \`${String(s.ref).replace(/`/g, "'")}\`` : '');
|
|
206
|
+
function markdown(pack) {
|
|
207
|
+
const out = ['---', 'type: Reference', `title: ${JSON.stringify(pack.title)}`, `timestamp: ${pack.today}`, 'kind: review-pack', 'status: draft', '---', '',
|
|
208
|
+
`# ${pack.title}`, '', `✦ ${SAID}`, ''];
|
|
209
|
+
for (const s of pack.sections) {
|
|
210
|
+
out.push(`## ${s.head}`, '');
|
|
211
|
+
if (s.bets) for (const b of s.bets) { out.push(`### ${b.title} (${b.id})`, ''); for (const l of b.lines) out.push(`- ${l.text}${srcText(l.source)}`); out.push(''); }
|
|
212
|
+
else { for (const l of s.lines) out.push(`- ${l.text}${srcText(l.source)}`); out.push(''); }
|
|
213
|
+
}
|
|
214
|
+
return out.join('\n');
|
|
215
|
+
}
|
|
216
|
+
const KEY_OF = Object.fromEntries(Object.entries(HEAD).map(([k, v]) => [v.toLowerCase(), k]));
|
|
217
|
+
function readPack(text) {
|
|
218
|
+
const body = String(text || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
|
|
219
|
+
const L = body.split(/\r?\n/);
|
|
220
|
+
const t = L.find((l) => /^#\s/.test(l));
|
|
221
|
+
const sections = [];
|
|
222
|
+
let cur = null, bet = null;
|
|
223
|
+
for (const l of L) {
|
|
224
|
+
const h = /^##\s+(.+?)\s*$/.exec(l);
|
|
225
|
+
if (h) { cur = { key: KEY_OF[h[1].toLowerCase()] || 'other', head: one(h[1], 80), lines: [] }; sections.push(cur); bet = null; continue; }
|
|
226
|
+
const b = cur && /^###\s+(.+?)(?:\s+\(([A-Za-z0-9._-]{1,80})\))?\s*$/.exec(l);
|
|
227
|
+
if (b) { bet = b[2] || ''; cur.lines.push({ text: one(b[1], 160), head: true, id: bet }); continue; }
|
|
228
|
+
const li = cur && /^\s*[-*]\s+(.+)$/.exec(l);
|
|
229
|
+
if (li) {
|
|
230
|
+
const m = /^(.*?)\s+—\s+source:\s+`([^`]+)`\s*$/.exec(li[1]);
|
|
231
|
+
cur.lines.push(m ? { text: one(m[1], 300), source: one(m[2], 200) } : { text: one(li[1], 300), source: '' });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return { title: t ? one(t.replace(/^#\s+/, ''), 160) : '', sections: sections.filter((s) => s.lines.length) };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* ── writing ── */
|
|
238
|
+
const heard = new Set(); // the report readers (lib/report-readers.js attach) hear each pack this process writes, as they hear a cadence draft
|
|
239
|
+
/** Call fn({ root, cadence, slot, path }) after each pack this process writes. → an unsubscribe function */
|
|
240
|
+
function onWritten(fn) { if (typeof fn === 'function') heard.add(fn); return () => heard.delete(fn); }
|
|
241
|
+
/* ──────────────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
242
|
+
function write(root, pack, { redraft = false } = {}) {
|
|
243
|
+
if (!pack || !pack.slot) return { ok: false, status: 400, error: 'there is no pack to write: no part has a line with a source' };
|
|
244
|
+
const RD = require('./report-draft.js'), IS = require('./issues.js');
|
|
245
|
+
const abs = path.resolve(String(root));
|
|
246
|
+
const rel = RD.draftPath(abs, CADENCE, pack.slot);
|
|
247
|
+
const file = path.join(abs, rel);
|
|
248
|
+
if (IS.isIssued(IS.readIssues(abs), CADENCE, pack.slot)) return { ok: false, status: 409, error: `the ${pack.month} pack is shared (issued) and frozen; nothing was written` };
|
|
249
|
+
let st = null; try { st = fs.lstatSync(file); } catch { st = null; }
|
|
250
|
+
if (st && !st.isFile()) return { ok: false, status: 403, error: `${rel} is not a regular file; nothing was written` };
|
|
251
|
+
if (st && !redraft) return { ok: true, path: rel, written: false, why: 'the pack exists; it is yours to edit (add --redraft to write it again)' };
|
|
252
|
+
const md = markdown(pack);
|
|
253
|
+
const tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
254
|
+
try { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(tmp, md, { flag: 'wx' }); fs.renameSync(tmp, file); } catch (e) {
|
|
255
|
+
try { fs.unlinkSync(tmp); } catch { /* not made */ }
|
|
256
|
+
return { ok: false, status: 500, error: 'could not write the pack: ' + one(e && e.message, 160) };
|
|
257
|
+
}
|
|
258
|
+
console.info(`[review-pack] wrote ${rel} sections=${pack.sections.length} dropped=${pack.dropped}`);
|
|
259
|
+
for (const fn of heard) { try { fn({ root: abs, cadence: CADENCE, slot: pack.slot, path: rel }); } catch { /* a listener never fails the write */ } }
|
|
260
|
+
return { ok: true, path: rel, written: true, sha: IS.blobSha(Buffer.from(md, 'utf8')) };
|
|
261
|
+
}
|
|
262
|
+
function due(today) {
|
|
263
|
+
if (!DAY_RE.test(String(today || ''))) return false;
|
|
264
|
+
const y = +today.slice(0, 4), m = +today.slice(5, 7), d = +today.slice(8, 10);
|
|
265
|
+
const last = new Date(Date.UTC(y, m, 0)).getUTCDate();
|
|
266
|
+
return d > last - DUE_DAYS;
|
|
267
|
+
}
|
|
268
|
+
/** Does Library draft due packs by itself here? PMOS_REVIEW_PACK=0 turns it off, =1 on; by default a scratch server (its own PMOS_STATE_DIR,
|
|
269
|
+
* which every suite sets) writes no pack into the repositories it hosts (the lib/profile-default.js rule). */
|
|
270
|
+
function autoOn(env = process.env) {
|
|
271
|
+
const v = String((env && env.PMOS_REVIEW_PACK) || '').trim();
|
|
272
|
+
if (v === '0') return false;
|
|
273
|
+
if (v === '1') return true;
|
|
274
|
+
return !String((env && env.PMOS_STATE_DIR) || '').trim();
|
|
275
|
+
}
|
|
276
|
+
function itemsOf({ ws, name, packs } = {}) {
|
|
277
|
+
const about = { ws: ws || null, product: one(name, 80), ini: null, title: '', program: null, programTitle: '' };
|
|
278
|
+
return (packs || []).filter((k) => k && k.path).map((k) => ({
|
|
279
|
+
id: 'pack:' + ws + ':' + k.path, kind: 'doc', name: k.title || 'Review pack', sub: '', kindText: 'Review pack', type: 'Review pack', family: 'reports',
|
|
280
|
+
state: k.issued ? 'Issued' : 'Draft', v: null, gate: false, came: '', by: 'PMOS', ed: null, about: { ...about }, product: about.product,
|
|
281
|
+
scope: ws ? ['p:' + ws] : [], updated: k.updated || k.slot || null, held: null, path: k.path, open: { doc: { ws, path: k.path } },
|
|
282
|
+
pack: { sections: k.sections || [], cadence: k.cadence, slot: k.slot, sha: k.sha, issued: !!k.issued },
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
function nameOf(w) { return one((w && (w.label || w.name || w.id)) || 'Product', 80); }
|
|
286
|
+
function draftFor(root, { product, today, stateDir, redraft = false } = {}) {
|
|
287
|
+
if (!redraft) {
|
|
288
|
+
// a pack that exists is the PM's to edit: say so before reading any record
|
|
289
|
+
try { const rel = require('./report-draft.js').draftPath(path.resolve(String(root)), CADENCE, String(today).slice(0, 7) + '-01'); if (fs.existsSync(path.join(path.resolve(String(root)), rel))) return { ok: true, path: rel, written: false, why: 'the pack exists; it is yours to edit (add --redraft to write it again)' }; } catch { /* write() says */ }
|
|
290
|
+
}
|
|
291
|
+
const pack = packOf({ product, today, ...gather(root, { today, stateDir }) });
|
|
292
|
+
if (!pack) return { ok: true, written: false, why: 'nothing to cite: no goal, failed bet, decision or ask has a record' };
|
|
293
|
+
return Object.assign(write(root, pack, { redraft }), { pack });
|
|
294
|
+
}
|
|
295
|
+
const tried = new Map(); // ws → the day it was last tried: one read a day per product, not one a minute
|
|
296
|
+
async function tick(ctx, now = new Date()) {
|
|
297
|
+
const today = new Date(now).toISOString().slice(0, 10);
|
|
298
|
+
if (!ctx || !due(today)) return [];
|
|
299
|
+
const out = [];
|
|
300
|
+
const list = typeof ctx.workspaceList === 'function' ? ctx.workspaceList() : [];
|
|
301
|
+
for (const w of list) {
|
|
302
|
+
if (!w || !w.root || tried.get(w.id || w.root) === today) continue;
|
|
303
|
+
tried.set(w.id || w.root, today);
|
|
304
|
+
try {
|
|
305
|
+
let dir = null; try { dir = ctx.stateDirFor ? ctx.stateDirFor(w) : null; } catch { dir = null; }
|
|
306
|
+
const r = draftFor(w.root, { product: nameOf(w), today, stateDir: dir || undefined });
|
|
307
|
+
out.push({ ws: w.id, ok: r.ok, path: r.path, written: !!r.written, why: r.why || r.error });
|
|
308
|
+
} catch (e) { out.push({ ws: w.id, ok: false, why: one(e && e.message, 160) }); }
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
312
|
+
function list(root) {
|
|
313
|
+
const RD = require('./report-draft.js'), IS = require('./issues.js');
|
|
314
|
+
const abs = path.resolve(String(root));
|
|
315
|
+
let dirRel; try { dirRel = path.posix.dirname(RD.draftPath(abs, CADENCE, '2000-01-01')); } catch { return []; }
|
|
316
|
+
let names = []; try { names = fs.readdirSync(path.join(abs, dirRel)).filter((n) => /^\d{4}-\d{2}-01\.md$/.test(n)); } catch { return []; }
|
|
317
|
+
let iss = null; try { iss = IS.readIssues(abs); } catch { iss = null; }
|
|
318
|
+
const out = [];
|
|
319
|
+
for (const n of names.sort().reverse()) {
|
|
320
|
+
let text = ''; try { text = fs.readFileSync(path.join(abs, dirRel, n), 'utf8'); } catch { continue; }
|
|
321
|
+
const slot = n.slice(0, 10), P = readPack(text);
|
|
322
|
+
let at = ''; try { at = fs.statSync(path.join(abs, dirRel, n)).mtime.toISOString(); } catch { at = ''; }
|
|
323
|
+
out.push({ path: dirRel + '/' + n, cadence: CADENCE, slot, title: P.title || slot, sections: P.sections, sha: IS.blobSha(Buffer.from(text, 'utf8')), issued: !!(iss && IS.isIssued(iss, CADENCE, slot)), updated: at });
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/* ── pmos report pack ─────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
329
|
+
function cli(args, { root, now = Date.now(), say = (s) => process.stdout.write(s + '\n'), product } = {}) {
|
|
330
|
+
const has = (f) => args.includes('--' + f);
|
|
331
|
+
const val = (f) => { const i = args.indexOf('--' + f); return i >= 0 ? args[i + 1] : undefined; };
|
|
332
|
+
const t = val('now') ? Date.parse(val('now')) : now;
|
|
333
|
+
if (!Number.isFinite(t)) { say('--now needs a time, for example 2026-11-25T09:00:00Z'); return 2; }
|
|
334
|
+
const today = new Date(t).toISOString().slice(0, 10);
|
|
335
|
+
const abs = path.resolve(String(root || process.cwd()));
|
|
336
|
+
const r = draftFor(abs, { product: product || val('product') || path.basename(abs), today, redraft: has('redraft') });
|
|
337
|
+
if (has('json')) { say(JSON.stringify({ ok: r.ok, path: r.path || null, written: !!r.written, why: r.why || r.error || null, pack: r.pack || null })); return r.ok ? 0 : 1; }
|
|
338
|
+
if (!r.ok) { say(r.error); return 1; }
|
|
339
|
+
if (!r.pack) { say(r.why); return 0; }
|
|
340
|
+
say(r.written ? `Wrote ${r.path}. Edit it in Library › Reports, then share it.` : `${r.path}: ${r.why}.`);
|
|
341
|
+
if (r.pack.dropped) say(`${r.pack.dropped} ${r.pack.dropped === 1 ? 'line was' : 'lines were'} left out: no record to cite.`);
|
|
342
|
+
return 0;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const resetTick = () => tried.clear();
|
|
346
|
+
module.exports = { resetTick, onWritten, itemsOf, autoOn, CADENCE, WINDOW_DAYS, DUE_DAYS, MAX, HEAD, SAID, gather, packOf, markdown, readPack, write, due, draftFor, tick, list, cli, stateDirOf };
|
|
347
|
+
|
|
348
|
+
if (require.main === module && process.argv[2] === 'count') console.log(list(process.argv[3] || process.cwd()).length);
|
|
@@ -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
|
-
/**
|
|
215
|
-
function
|
|
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
|
|
228
|
-
|
|
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));
|
|
@@ -104,6 +104,7 @@ const MODULES = Object.freeze([
|
|
|
104
104
|
'routes-tracker-sync', // tracker-sync-on-today: the sync with Jira of a product, the PM's ✓ that takes Jira's value, and its Undo (task ledger; page-press POST)
|
|
105
105
|
'routes-standing-rules', // standing-rules-list (A470): the standing rules PMOS keeps, with edit, retire and bring back (memory + standing-rules.jsonl)
|
|
106
106
|
'routes-lab', // idle lab (build U): Intelligence › Lab, the compare view, the specimen files and the Lab's own ✦ (idle-lab.jsonl; page-press POST)
|
|
107
|
+
'routes-sim-users', // simulated users try the prototype (sim-users, A20): Findings of a version, the personas that walk (sim-users.jsonl)
|
|
107
108
|
'routes-loose', // batch 13 item 3: Claude's clean-up of Home's "Not in an initiative" under the group's ✦ (loose-props/; page-press POST)
|
|
108
109
|
'routes-workflows', // workflows-per-initiative (D99): the workflow library, save, copy, archive and the chat's draft (workflows.jsonl; page-press POST)
|
|
109
110
|
'routes-settings', // console3 Settings: the settings store for settings with no home of their own (GET; page-press POST)
|
|
@@ -135,6 +136,7 @@ const MODULES = Object.freeze([
|
|
|
135
136
|
'routes-report-design', // report-design-studio: the design studio (describe, samples, turns, versions, This is it), cycle renders and decisions, speaker notes and pins
|
|
136
137
|
'routes-report-structure', // report-structure: the structure step (turns, versions, Use this structure, sources and their checks, dry run) and the chart store (GET /api/charts)
|
|
137
138
|
'routes-insight-moves', // batch 16 item 1: the ✓ and Undo of a drafted move on the Intelligence ✦ strip (insight-moves.jsonl; date, anchor, chase to the outbox)
|
|
139
|
+
'page-one-answer', // page-one-answer (A308): POST /api/page-calls, each page's first-view calls to act, local only (runtime page-calls.jsonl); pmos pages calls
|
|
138
140
|
'routes-page-opens', // batch 16 item 1: the pages the PM opens, by day, local only (runtime page-opens.jsonl); drives the weekly report proposal
|
|
139
141
|
'routes-ready-reports', // batch 17 item 1: the ready-made dashboard and reports of every program, product and initiative (ready-reports.jsonl; page-press POST)
|
|
140
142
|
'routes-metric-drafts', // batch 15 item 1: the metrics Claude drafts unasked for a product, a program or an initiative; ✓ keep writes kr-metrics (metric-drafts.jsonl; page-press POST)
|
|
@@ -151,11 +153,14 @@ const MODULES = Object.freeze([
|
|
|
151
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)
|
|
152
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)
|
|
153
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)
|
|
154
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)
|
|
155
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)
|
|
156
159
|
'routes-arch-warns', // idea A54: one warning when an initiative names a risky part of the code (reads code-map.json; read-only)
|
|
157
160
|
'routes-live-rows', // bet A458: chat-made task changes streamed to open pages (runtime live-events.jsonl; read-only event stream)
|
|
161
|
+
'routes-team-waits', // team-waits (A364): Work › Dependencies' waits on other teams (GET, read-only; team-waits.jsonl written by pmos deps)
|
|
158
162
|
'routes-connector-data', // connector-data (A150): what each connector reads and writes, from lib/connector-data.js (read only)
|
|
163
|
+
'routes-review-pack', // job #1910 (A343): the monthly review packs for Library › Reports, drafted when due (<state>/reports/review-pack/; page-press POST)
|
|
159
164
|
'routes-portfolio', // bet A56: the Portfolio, every product side by side, and the answer to its one recommendation (runtime portfolio.jsonl; page-press POST)
|
|
160
165
|
]);
|
|
161
166
|
const PM_DIR = path.join(__dirname, '..', 'public', 'pm');
|