create-pmos 0.827.0 → 0.829.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 +217 -45
- 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/bin/pmos.js +19 -9
- package/workspace/board-deliveries-test.js +2 -2
- package/workspace/changelog.json +216 -12
- package/workspace/guide/cli.md +62 -0
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/settings-and-switches.md +1 -0
- package/workspace/lib/board-cli.js +5 -1
- package/workspace/lib/board-premium.js +1 -0
- 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/features.json +5 -0
- package/workspace/lib/five-action-cap.js +84 -0
- 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 +43 -2
- package/workspace/lib/pmos-verbs.js +15 -1
- package/workspace/lib/portfolio-cli.js +64 -0
- package/workspace/lib/portfolio.js +168 -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 +357 -0
- package/workspace/lib/route-modules.js +6 -0
- package/workspace/lib/routes-boards.js +25 -2
- package/workspace/lib/routes-portfolio.js +50 -0
- 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-stakeholders.js +42 -0
- package/workspace/lib/routes-strategy-card.js +29 -1
- package/workspace/lib/routes-team-waits.js +24 -0
- package/workspace/lib/routes-use-log.js +6 -1
- package/workspace/lib/sim-users.js +329 -0
- package/workspace/lib/stakeholder-map.js +232 -0
- package/workspace/lib/task-store.js +1 -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/lib/voice-cli.js +7 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-vw-jira-test.js +6 -2
- package/workspace/public/pm/bd-backlog.js +44 -6
- package/workspace/public/pm/bd-principles.js +12 -1
- package/workspace/public/pm/cozy-library.css +5 -0
- package/workspace/public/pm/cozy-pick.css +1 -0
- package/workspace/public/pm/cozy-pop-work.js +8 -2
- package/workspace/public/pm/cozy-proto.css +5 -0
- package/workspace/public/pm/cozy-proto.js +11 -3
- package/workspace/public/pm/cozy-today-app.js +53 -3
- package/workspace/public/pm/cozy-today-view.js +12 -4
- package/workspace/public/pm/day-time.js +8 -0
- package/workspace/public/pm/five-action-cap.js +104 -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-work-model.js +8 -6
- package/workspace/public/pm/portfolio.js +67 -0
- package/workspace/public/pm/premium-board.js +19 -6
- package/workspace/public/pm/premium-library.js +27 -3
- package/workspace/public/pm/product-switcher.js +7 -1
- 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 +75 -0
- package/workspace/public/pm/sim-users.js +34 -0
- package/workspace/public/pm/sort-order.js +3 -0
- package/workspace/public/pm/stakeholder-map.js +125 -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 +1 -0
- package/workspace/public/premium-portfolio.html +48 -0
- package/workspace/public/today.html +1 -0
- package/workspace/run-tests.js +9 -1
- package/workspace/server.js +1 -1
- package/workspace/stage-card-tasks-test.js +11 -5
- package/workspace/test-lists/critical-needs.json +9 -0
- package/workspace/test-lists/five-action-cap.json +9 -0
- package/workspace/test-lists/page-one-answer.json +9 -0
- package/workspace/test-lists/portfolio.json +9 -0
- package/workspace/test-lists/review-pack.json +9 -0
- package/workspace/test-lists/review-reasons.json +9 -0
- package/workspace/test-lists/sim-users.json +9 -0
- package/workspace/test-lists/stakeholder-map.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-timings.json +25 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* review-reasons.js — reviews grouped by reason, not by score (idea A427, initiative review-reasons; done test
|
|
4
|
+
* planning/done-tests/review-reasons.md; board BatchMoreADS panel 28).
|
|
5
|
+
*
|
|
6
|
+
* Survey comments and app-store reviews, grouped by the reason behind them. Rows sort by how fast each reason grows. One ✦
|
|
7
|
+
* names the fastest-growing complaint; accepting it files a triage item (a capture note, lib/capture.js, which the needs
|
|
8
|
+
* queue proposes through lib/triage.js) with Undo. The score stays, as one line under the reasons.
|
|
9
|
+
*
|
|
10
|
+
* THE LEDGER: customer-voice.jsonl in the product's runs folder (planning/runs/ for PMOS itself, pmos/state/ in a kit
|
|
11
|
+
* repository; lib/plan-ledgers.js runsDir). Append-only JSON lines:
|
|
12
|
+
* { v: 1, ev: 'comment', cid, at, source, score, scale, reason, text, via } one comment as the customer wrote it
|
|
13
|
+
* { v: 1, ev: 'reason', cid, reason, at, via } names (or renames) a comment's reason
|
|
14
|
+
* { v: 1, ev: 'filed', reason, capture, at, by } the ✦ was accepted: a triage item was filed
|
|
15
|
+
* { v: 1, ev: 'unfiled', capture, at, by } its Undo
|
|
16
|
+
* cid 'vc_' + 10 hex of sha1(source, at, text): the same comment imported twice is one comment
|
|
17
|
+
* source survey | review | other
|
|
18
|
+
* score a number on `scale` (5 for a store's stars, 10 for an NPS survey), or null
|
|
19
|
+
*
|
|
20
|
+
* WHO NAMES A REASON (spec question 2, default kept): whoever adds the comment (the import's reason column, or the chat).
|
|
21
|
+
* A comment with no reason joins the one named reason it shares at least 2 words with, more than any other; otherwise it
|
|
22
|
+
* stays unsorted, and the block says how many. No model runs here.
|
|
23
|
+
*
|
|
24
|
+
* group(lines, now) → { rows, unsorted, loose, score, suggest, filed } PURE
|
|
25
|
+
* growthWord(last, prev) → 'up 3×' | 'up' | 'new' | 'flat' | 'down' PURE
|
|
26
|
+
* parseComment(o, now) → { ok, line } | { ok: false, error } PURE
|
|
27
|
+
* parseCsv(text) → [row objects] PURE
|
|
28
|
+
* ledgerFile(root) · read(root) · add(root, o) · importFile(root, file) · nameReason(root, cid, reason)
|
|
29
|
+
* file(root, reason, { actor, now }) · undo(root, capture, { actor, now }) · count(root, now)
|
|
30
|
+
*
|
|
31
|
+
* CLI (`pmos voice`, lib/voice-cli.js through lib/pmos-verbs.js; what chat and agents run; nothing else writes the ledger):
|
|
32
|
+
* pmos voice add --text "<comment>" [--reason "<reason>"] [--score 2] [--scale 5|10] [--source review] [--at <iso>]
|
|
33
|
+
* pmos voice import <file.csv|file.json> columns: text, reason, score, scale, source, at (a header row in a CSV)
|
|
34
|
+
* pmos voice reason <cid> "<reason>"
|
|
35
|
+
* pmos voice list [--json]
|
|
36
|
+
* pmos voice file "<reason>" files the reason as a triage item; prints the Undo line
|
|
37
|
+
* pmos voice undo <capture id>
|
|
38
|
+
* pmos voice count last line: reasons with a comment in the last 30 days
|
|
39
|
+
* Every option takes --root <checkout>; without it, the git root of the current folder. Every log line carries [voice].
|
|
40
|
+
* Nothing here calls a model or sends anything. Exit codes: 0 done, 1 refused, 2 usage.
|
|
41
|
+
*/
|
|
42
|
+
const fs = require('fs');
|
|
43
|
+
const path = require('path');
|
|
44
|
+
const crypto = require('crypto');
|
|
45
|
+
|
|
46
|
+
const TAG = '[voice]';
|
|
47
|
+
const FILE = 'customer-voice.jsonl';
|
|
48
|
+
const SOURCES = Object.freeze(['survey', 'review', 'other']);
|
|
49
|
+
const MAX_TEXT = 500;
|
|
50
|
+
const MAX_REASON = 80;
|
|
51
|
+
const MAX_SHOWN = 20;
|
|
52
|
+
const DAY = 86400000;
|
|
53
|
+
const WINDOW_DAYS = 90;
|
|
54
|
+
const TREND_DAYS = 30;
|
|
55
|
+
const MIN_SUGGEST = 2; // a complaint needs at least this many comments in the last 30 days before PMOS names it
|
|
56
|
+
const CID_RE = /^vc_[0-9a-f]{10}$/;
|
|
57
|
+
const CAPTURE_RE = /^capture-\d{4}-\d{2}-\d{2}-\d+$/;
|
|
58
|
+
const LINE_BREAK = /[\r\n\x00-\x08\x0b-\x1f]/;
|
|
59
|
+
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
|
+
|
|
61
|
+
const str = (v) => (v == null ? '' : String(v)).trim();
|
|
62
|
+
const oneLine = (s) => str(s).replace(/\s+/g, ' ');
|
|
63
|
+
const words = (s) => [...new Set(String(s || '').toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length >= 3 && !STOP.has(w)))];
|
|
64
|
+
const cidOf = (source, at, text) => 'vc_' + crypto.createHash('sha1').update([source, at, text].join('\0')).digest('hex').slice(0, 10);
|
|
65
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
66
|
+
|
|
67
|
+
/** One `comment` line from what a caller gives, or the reason it is refused. PURE. */
|
|
68
|
+
function parseComment(o = {}, now = new Date()) {
|
|
69
|
+
const text = oneLine(o.text), reason = oneLine(o.reason), source = str(o.source || 'other').toLowerCase();
|
|
70
|
+
if (!text) return { ok: false, error: 'the comment has no text: --text "<what the customer wrote>"' };
|
|
71
|
+
if (!SOURCES.includes(source)) return { ok: false, error: `the source is one of: ${SOURCES.join(', ')}` };
|
|
72
|
+
if (reason.length > MAX_REASON) return { ok: false, error: `the reason is at most ${MAX_REASON} characters` };
|
|
73
|
+
const scale = o.scale == null || o.scale === '' ? (o.score != null && Number(o.score) > 5 ? 10 : 5) : Number(o.scale);
|
|
74
|
+
if (scale !== 5 && scale !== 10) return { ok: false, error: 'the scale is 5 (stars) or 10 (an NPS survey)' };
|
|
75
|
+
let score = null;
|
|
76
|
+
if (o.score != null && o.score !== '') {
|
|
77
|
+
score = Number(o.score);
|
|
78
|
+
if (!Number.isFinite(score) || score < 0 || score > scale) return { ok: false, error: `the score is a number from 0 to ${scale}` };
|
|
79
|
+
}
|
|
80
|
+
const atMs = o.at ? Date.parse(o.at) : new Date(now).getTime();
|
|
81
|
+
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
|
+
const at = new Date(atMs).toISOString();
|
|
83
|
+
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' } };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 'up 3×' from twice or more, 'up' from a quarter more, 'new' when the 30 days before had none, 'down' below three
|
|
88
|
+
* quarters, else 'flat'. PURE. */
|
|
89
|
+
function growthWord(last, prev) {
|
|
90
|
+
if (!prev) return last ? 'new' : 'flat';
|
|
91
|
+
const r = last / prev;
|
|
92
|
+
if (r >= 2) return `up ${Math.round(r)}×`;
|
|
93
|
+
if (r >= 1.25) return 'up';
|
|
94
|
+
if (r < 0.75) return 'down';
|
|
95
|
+
return 'flat';
|
|
96
|
+
}
|
|
97
|
+
const growing = (w) => w === 'new' || /^up/.test(w);
|
|
98
|
+
const lowScore = (c) => c.score != null && (c.scale === 10 ? c.score <= 6 : c.score <= 3);
|
|
99
|
+
|
|
100
|
+
/** The live comments (a reason line renames one), and the filed triage items still standing. PURE. */
|
|
101
|
+
function fold(lines) {
|
|
102
|
+
const comments = new Map(), filed = new Map();
|
|
103
|
+
for (const l of lines || []) {
|
|
104
|
+
if (!l || typeof l !== 'object') continue;
|
|
105
|
+
if (l.ev === 'comment' && CID_RE.test(String(l.cid || '')) && str(l.text) && !comments.has(l.cid)) {
|
|
106
|
+
const scale = l.scale === 10 ? 10 : 5, score = Number.isFinite(Number(l.score)) && l.score !== null ? Number(l.score) : null;
|
|
107
|
+
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;
|
|
110
|
+
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
|
+
else if (l.ev === 'unfiled') filed.delete(l.capture);
|
|
112
|
+
}
|
|
113
|
+
return { comments: [...comments.values()], filed };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A comment with no reason joins the ONE named reason it shares at least 2 words with, more than any other. PURE. */
|
|
117
|
+
function placeUnnamed(text, reasons) {
|
|
118
|
+
const have = new Set(words(text));
|
|
119
|
+
let best = null, bestN = 0, tie = false;
|
|
120
|
+
for (const r of reasons) {
|
|
121
|
+
const n = words(r).filter((w) => have.has(w)).length;
|
|
122
|
+
if (n > bestN) { best = r; bestN = n; tie = false; } else if (n === bestN && n > 0) tie = true;
|
|
123
|
+
}
|
|
124
|
+
return bestN >= 2 && !tie ? best : null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The score line: the mean of a 5 scale, the NPS of a 10 scale, and how many comments each counts. '' when none is scored. PURE. */
|
|
128
|
+
function scoreLine(list) {
|
|
129
|
+
const five = list.filter((c) => c.score != null && c.scale === 5), ten = list.filter((c) => c.score != null && c.scale === 10);
|
|
130
|
+
const parts = [];
|
|
131
|
+
if (five.length) parts.push(`Score ${(five.reduce((s, c) => s + c.score, 0) / five.length).toFixed(1)} of 5 from ${plural(five.length, 'comment', 'comments')}`);
|
|
132
|
+
if (ten.length) {
|
|
133
|
+
const pro = ten.filter((c) => c.score >= 9).length, det = ten.filter((c) => c.score <= 6).length;
|
|
134
|
+
parts.push(`NPS ${Math.round((pro - det) * 100 / ten.length)} from ${plural(ten.length, 'answer', 'answers')}`);
|
|
135
|
+
}
|
|
136
|
+
return parts.join(' · ');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Lines → { rows, unsorted, score, suggest, filed }. PURE.
|
|
140
|
+
* rows: one per reason with a comment in the last 90 days, { reason, n, last, prev, growth, complaint, filed, comments },
|
|
141
|
+
* sorted by growth ((last + 1) / (prev + 1)), then by count. suggest: the fastest-growing complaint not filed yet, or null. */
|
|
142
|
+
function group(lines, now = Date.now()) {
|
|
143
|
+
const t = new Date(now).getTime();
|
|
144
|
+
const { comments, filed } = fold(lines);
|
|
145
|
+
const recent = comments.filter((c) => { const a = Date.parse(c.at); return Number.isFinite(a) && a <= t + DAY && t - a <= WINDOW_DAYS * DAY; });
|
|
146
|
+
const named = [...new Set(recent.map((c) => c.reason).filter(Boolean))];
|
|
147
|
+
const by = new Map();
|
|
148
|
+
const loose = [];
|
|
149
|
+
for (const c of recent) {
|
|
150
|
+
const reason = c.reason || placeUnnamed(c.text, named);
|
|
151
|
+
if (!reason) { loose.push(c); continue; }
|
|
152
|
+
if (!by.has(reason)) by.set(reason, []);
|
|
153
|
+
by.get(reason).push(c);
|
|
154
|
+
}
|
|
155
|
+
const filedBy = new Map([...filed.values()].map((f) => [f.reason, f.capture]));
|
|
156
|
+
const rows = [...by.entries()].map(([reason, list]) => {
|
|
157
|
+
const age = (c) => (t - Date.parse(c.at)) / DAY;
|
|
158
|
+
const last = list.filter((c) => age(c) <= TREND_DAYS).length, prev = list.filter((c) => age(c) > TREND_DAYS && age(c) <= 2 * TREND_DAYS).length;
|
|
159
|
+
const scored = list.filter((c) => c.score != null);
|
|
160
|
+
const complaint = scored.length > 0 && scored.filter(lowScore).length * 2 > scored.length;
|
|
161
|
+
const sorted = list.slice().sort((a, b) => b.at.localeCompare(a.at));
|
|
162
|
+
return { reason, n: list.length, last, prev, growth: growthWord(last, prev), rate: (last + 1) / (prev + 1), complaint, filed: filedBy.get(reason) || null,
|
|
163
|
+
comments: sorted.slice(0, MAX_SHOWN).map((c) => ({ cid: c.cid, at: c.at, source: c.source, score: c.score, scale: c.scale, text: c.text })) };
|
|
164
|
+
}).sort((a, b) => b.rate - a.rate || b.n - a.n || a.reason.localeCompare(b.reason));
|
|
165
|
+
const pick = rows.find((r) => r.complaint && growing(r.growth) && r.last >= MIN_SUGGEST && !r.filed) || null;
|
|
166
|
+
const suggest = pick ? { reason: pick.reason, line: `${pick.reason} is the fastest-growing complaint. Make it a work item?` } : null;
|
|
167
|
+
return { rows, unsorted: loose.length, loose: loose.slice(0, MAX_SHOWN).map((c) => ({ cid: c.cid, text: c.text })), score: scoreLine(recent), suggest, filed: [...filed.values()] };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A small CSV reader: a header row, commas, double quotes around a field that holds a comma or a quote. PURE. */
|
|
171
|
+
function parseCsv(text) {
|
|
172
|
+
const rows = [];
|
|
173
|
+
let row = [], f = '', q = false;
|
|
174
|
+
const s = String(text || '').replace(/^/, '');
|
|
175
|
+
for (let i = 0; i < s.length; i++) {
|
|
176
|
+
const ch = s[i];
|
|
177
|
+
if (q) { if (ch === '"') { if (s[i + 1] === '"') { f += '"'; i++; } else q = false; } else f += ch; continue; }
|
|
178
|
+
if (ch === '"') q = true;
|
|
179
|
+
else if (ch === ',') { row.push(f); f = ''; }
|
|
180
|
+
else if (ch === '\n' || ch === '\r') { if (ch === '\r' && s[i + 1] === '\n') i++; row.push(f); f = ''; if (row.some((x) => x.trim())) rows.push(row); row = []; }
|
|
181
|
+
else f += ch;
|
|
182
|
+
}
|
|
183
|
+
row.push(f); if (row.some((x) => x.trim())) rows.push(row);
|
|
184
|
+
if (!rows.length) return [];
|
|
185
|
+
const head = rows[0].map((h) => h.trim().toLowerCase());
|
|
186
|
+
return rows.slice(1).map((r) => Object.fromEntries(head.map((h, i) => [h, r[i] == null ? '' : r[i]])));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* ── the ledger ── */
|
|
190
|
+
function ledgerFile(root) { return path.join(require('./plan-ledgers.js').runsDir(root), FILE); }
|
|
191
|
+
function read(root) {
|
|
192
|
+
let raw = '';
|
|
193
|
+
try { raw = fs.readFileSync(ledgerFile(root), 'utf8'); } catch { return []; }
|
|
194
|
+
const out = [];
|
|
195
|
+
for (const l of raw.split('\n')) { if (!l.trim()) continue; try { out.push(JSON.parse(l)); } catch { /* a line it cannot read is skipped */ } }
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
function append(root, lines) {
|
|
199
|
+
const file = ledgerFile(root);
|
|
200
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
201
|
+
fs.appendFileSync(file, lines.map((l) => JSON.stringify(l)).join('\n') + '\n');
|
|
202
|
+
}
|
|
203
|
+
function sig(root) { try { const s = fs.statSync(ledgerFile(root)); return `${s.size}:${s.mtimeMs}`; } catch { return '0'; } }
|
|
204
|
+
|
|
205
|
+
function add(root, o, now = new Date()) {
|
|
206
|
+
const p = parseComment(o, now);
|
|
207
|
+
if (!p.ok) return p;
|
|
208
|
+
const known = new Set(fold(read(root)).comments.map((c) => c.cid));
|
|
209
|
+
if (known.has(p.line.cid)) return { ok: true, cid: p.line.cid, already: true };
|
|
210
|
+
append(root, [p.line]);
|
|
211
|
+
return { ok: true, cid: p.line.cid, already: false };
|
|
212
|
+
}
|
|
213
|
+
|
|
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()) {
|
|
216
|
+
let raw = '';
|
|
217
|
+
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
|
+
let items = null;
|
|
219
|
+
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
|
+
else items = parseCsv(raw);
|
|
221
|
+
if (!Array.isArray(items)) return { ok: false, error: 'the file holds no list of comments' };
|
|
222
|
+
const known = new Set(fold(read(root)).comments.map((c) => c.cid));
|
|
223
|
+
const fresh = [], refused = [];
|
|
224
|
+
let already = 0;
|
|
225
|
+
items.forEach((it, i) => {
|
|
226
|
+
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);
|
|
229
|
+
if (!p.ok) { refused.push({ row: i + 1, error: p.error }); return; }
|
|
230
|
+
if (known.has(p.line.cid)) { already++; return; }
|
|
231
|
+
known.add(p.line.cid); fresh.push(p.line);
|
|
232
|
+
});
|
|
233
|
+
if (fresh.length) append(root, fresh);
|
|
234
|
+
return { ok: true, added: fresh.length, already, refused };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function nameReason(root, cid, reason, now = new Date()) {
|
|
238
|
+
const r = oneLine(reason);
|
|
239
|
+
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)' };
|
|
240
|
+
if (!r || r.length > MAX_REASON) return { ok: false, error: `the reason is one line of 1 to ${MAX_REASON} characters` };
|
|
241
|
+
if (!fold(read(root)).comments.some((c) => c.cid === cid)) return { ok: false, error: `no comment ${cid} in this product's customer voice` };
|
|
242
|
+
append(root, [{ v: 1, ev: 'reason', cid, reason: r, at: new Date(now).toISOString(), via: 'cli' }]);
|
|
243
|
+
return { ok: true };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The ✦ accepted: file `reason` as a triage item (a capture note). → { ok, capture, text } | { ok: false, status, error } */
|
|
247
|
+
function file(root, reason, { actor = null, now = new Date() } = {}) {
|
|
248
|
+
const G = group(read(root), new Date(now).getTime());
|
|
249
|
+
const row = G.rows.find((r) => r.reason === str(reason));
|
|
250
|
+
if (!row) return { ok: false, status: 404, error: `no reason "${str(reason).slice(0, MAX_REASON)}" in the last ${WINDOW_DAYS} days` };
|
|
251
|
+
if (row.filed) return { ok: false, status: 409, error: `already filed as ${row.filed}` };
|
|
252
|
+
const text = `Customer voice: ${row.reason}. ${plural(row.last, 'comment', 'comments')} in the last ${TREND_DAYS} days (${row.growth}), ${row.n} in ${WINDOW_DAYS} days.\n\n`
|
|
253
|
+
+ row.comments.slice(0, 3).map((c) => `> ${c.text}`).join('\n') + '\n\nFiled by PMOS from the product\'s customer voice (pmos voice).';
|
|
254
|
+
const stateDir = require('./triage.js').stateDir(root);
|
|
255
|
+
const w = require('./capture.js').write(stateDir, { text, actor: actor && actor.by ? actor : { by: 'agent:unknown' }, now: new Date(now) });
|
|
256
|
+
if (!w.ok) return w;
|
|
257
|
+
append(root, [{ v: 1, ev: 'filed', reason: row.reason, capture: w.id, at: new Date(now).toISOString(), by: (actor && actor.by) || 'agent:unknown' }]);
|
|
258
|
+
console.error(`${TAG} filed "${row.reason}" as ${w.id}`);
|
|
259
|
+
return { ok: true, capture: w.id, text };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Undo a filing: remove the capture note PMOS filed, unless an initiative was already made from it. */
|
|
263
|
+
function undo(root, capture, { actor = null, now = new Date() } = {}) {
|
|
264
|
+
const id = str(capture);
|
|
265
|
+
if (!CAPTURE_RE.test(id)) return { ok: false, status: 400, error: 'name the triage item by its capture id (capture-YYYY-MM-DD-n)' };
|
|
266
|
+
const { filed } = fold(read(root));
|
|
267
|
+
if (!filed.has(id)) return { ok: false, status: 404, error: `${id} was not filed from customer voice, so PMOS leaves it alone` };
|
|
268
|
+
let made = {};
|
|
269
|
+
try { made = require('./placements.js').createdFrom(root) || {}; } catch { made = {}; }
|
|
270
|
+
if (made[id]) return { ok: false, status: 409, error: `an initiative was already made from ${id}; PMOS leaves it alone` };
|
|
271
|
+
const stateDir = require('./triage.js').stateDir(root);
|
|
272
|
+
try { fs.unlinkSync(path.join(stateDir, require('./capture.js').DIR, id + '.md')); } catch (e) { if (!e || e.code !== 'ENOENT') return { ok: false, status: 500, error: 'the triage item could not be removed' }; }
|
|
273
|
+
append(root, [{ v: 1, ev: 'unfiled', capture: id, at: new Date(now).toISOString(), by: (actor && actor.by) || 'agent:unknown' }]);
|
|
274
|
+
console.error(`${TAG} undid ${id}`);
|
|
275
|
+
return { ok: true };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** The health number: reasons with a comment in the last 30 days. */
|
|
279
|
+
function count(root, now = Date.now()) { return group(read(root), now).rows.filter((r) => r.last > 0).length; }
|
|
280
|
+
|
|
281
|
+
/* ── the CLI ── */
|
|
282
|
+
const COMMANDS = { voice: ['add', 'import', 'reason', 'list', 'file', 'undo', 'count'] };
|
|
283
|
+
const USAGE = [
|
|
284
|
+
'usage: pmos voice add --text "<comment>" [--reason "<reason>"] [--score <n>] [--scale 5|10] [--source survey|review|other] [--at <date>]',
|
|
285
|
+
' pmos voice import <file.csv|file.json> (columns: text, reason, score, scale, source, at)',
|
|
286
|
+
' pmos voice reason <comment id> "<reason>"',
|
|
287
|
+
' pmos voice list [--json]',
|
|
288
|
+
' pmos voice file "<reason>" · pmos voice undo <capture id>',
|
|
289
|
+
' pmos voice count',
|
|
290
|
+
'Each takes --root <checkout>. Work shows the reasons as Customer voice, under the strategy. PMOS sends nothing.',
|
|
291
|
+
];
|
|
292
|
+
function repoOf(cwd) {
|
|
293
|
+
let d = path.resolve(cwd);
|
|
294
|
+
for (;;) { if (fs.existsSync(path.join(d, '.git'))) return d; const up = path.dirname(d); if (up === d) return path.resolve(cwd); d = up; }
|
|
295
|
+
}
|
|
296
|
+
function run(argv, o = {}) {
|
|
297
|
+
const say = o.say || ((s) => console.log(s)), now = o.now || new Date();
|
|
298
|
+
const args = argv[0] === 'voice' ? argv.slice(1) : argv.slice();
|
|
299
|
+
const pos = [], flags = {};
|
|
300
|
+
const VAL = new Set(['root', 'text', 'reason', 'score', 'scale', 'source', 'at']);
|
|
301
|
+
for (let i = 0; i < args.length; i++) {
|
|
302
|
+
const a = args[i];
|
|
303
|
+
if (a.startsWith('--') && VAL.has(a.slice(2))) flags[a.slice(2)] = args[++i];
|
|
304
|
+
else if (a === '--json') flags.json = true;
|
|
305
|
+
else pos.push(a);
|
|
306
|
+
}
|
|
307
|
+
const cmd = pos[0];
|
|
308
|
+
if (!cmd || cmd === 'help' || cmd === '--help') { USAGE.forEach((l) => say(l)); return cmd ? 0 : 2; }
|
|
309
|
+
if (!COMMANDS.voice.includes(cmd)) { say(`✗ ${cmd} is not a command of pmos voice`); USAGE.forEach((l) => say(l)); return 2; }
|
|
310
|
+
const root = path.resolve(flags.root || o.root || repoOf(o.cwd || process.cwd()));
|
|
311
|
+
const actorOf = () => { try { return require('./actor.js').fromCli({ isTTY: !!process.stdin.isTTY, env: process.env }); } catch { return null; } };
|
|
312
|
+
if (cmd === 'add') {
|
|
313
|
+
const r = add(root, { text: flags.text, reason: flags.reason, score: flags.score, scale: flags.scale, source: flags.source, at: flags.at }, now);
|
|
314
|
+
if (!r.ok) { say(`${TAG} refused: ${r.error}`); return 1; }
|
|
315
|
+
say(r.already ? `${TAG} ${r.cid} is already there.` : `${TAG} added ${r.cid}. Work shows it under Customer voice.`);
|
|
316
|
+
return 0;
|
|
317
|
+
}
|
|
318
|
+
if (cmd === 'import') {
|
|
319
|
+
if (!pos[1]) { USAGE.forEach((l) => say(l)); return 2; }
|
|
320
|
+
const r = importFile(root, path.resolve(o.cwd || process.cwd(), pos[1]), now);
|
|
321
|
+
if (!r.ok) { say(`${TAG} refused: ${r.error}`); return 1; }
|
|
322
|
+
say(`${TAG} added ${plural(r.added, 'comment', 'comments')}${r.already ? `; ${r.already} already there` : ''}${r.refused.length ? `; ${r.refused.length} refused (row ${r.refused[0].row}: ${r.refused[0].error})` : ''}.`);
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
325
|
+
if (cmd === 'reason') {
|
|
326
|
+
const r = nameReason(root, pos[1], pos.slice(2).join(' ') || flags.reason, now);
|
|
327
|
+
if (!r.ok) { say(`${TAG} refused: ${r.error}`); return 1; }
|
|
328
|
+
say(`${TAG} ${pos[1]} now sits under "${oneLine(pos.slice(2).join(' ') || flags.reason)}".`);
|
|
329
|
+
return 0;
|
|
330
|
+
}
|
|
331
|
+
if (cmd === 'file') {
|
|
332
|
+
const r = file(root, pos.slice(1).join(' ') || flags.reason, { actor: actorOf(), now });
|
|
333
|
+
if (!r.ok) { say(`${TAG} refused: ${r.error}`); return 1; }
|
|
334
|
+
say(`${TAG} filed as triage item ${r.capture}. Undo: pmos voice undo ${r.capture}`);
|
|
335
|
+
return 0;
|
|
336
|
+
}
|
|
337
|
+
if (cmd === 'undo') {
|
|
338
|
+
const r = undo(root, pos[1], { actor: actorOf(), now });
|
|
339
|
+
if (!r.ok) { say(`${TAG} refused: ${r.error}`); return 1; }
|
|
340
|
+
say(`${TAG} took ${pos[1]} back.`);
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
343
|
+
const G = group(read(root), new Date(now).getTime());
|
|
344
|
+
if (cmd === 'count') { const n = G.rows.filter((r) => r.last > 0).length; say(`${TAG} ${plural(n, 'reason', 'reasons')} with a comment in the last ${TREND_DAYS} days.`); say(String(n)); return 0; }
|
|
345
|
+
if (flags.json) { say(JSON.stringify({ ok: true, ...G })); return 0; }
|
|
346
|
+
if (!G.rows.length && !G.unsorted) { say('No customer comments yet. pmos voice import reads an export from your survey tool or app store.'); return 0; }
|
|
347
|
+
for (const r of G.rows) say(`- ${r.reason}: ${r.n} (30 days: ${r.growth})${r.complaint ? ' · complaint' : ''}${r.filed ? ` · filed ${r.filed}` : ''}`);
|
|
348
|
+
if (G.unsorted) { say(`${plural(G.unsorted, 'comment has', 'comments have')} no reason yet; pmos voice reason <id> "<reason>" names one:`); for (const c of G.loose) say(` ${c.cid} ${c.text.slice(0, 100)}`); }
|
|
349
|
+
if (G.score) say(G.score);
|
|
350
|
+
if (G.suggest) say(`✦ ${G.suggest.line} pmos voice file "${G.suggest.reason}"`);
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
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 };
|
|
356
|
+
|
|
357
|
+
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,10 +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-stakeholders', // bet A371: an initiative's stakeholder map, decides / must agree / needs to know, in the Work popup (records stakeholders.jsonl; page-press POST)
|
|
154
157
|
'routes-code-map', // idea A176: the product's code map on Work, redrawn when the default branch moves (records code-map.json; read-only)
|
|
155
158
|
'routes-arch-warns', // idea A54: one warning when an initiative names a risky part of the code (reads code-map.json; read-only)
|
|
156
159
|
'routes-live-rows', // bet A458: chat-made task changes streamed to open pages (runtime live-events.jsonl; read-only event stream)
|
|
160
|
+
'routes-team-waits', // team-waits (A364): Work › Dependencies' waits on other teams (GET, read-only; team-waits.jsonl written by pmos deps)
|
|
157
161
|
'routes-connector-data', // connector-data (A150): what each connector reads and writes, from lib/connector-data.js (read only)
|
|
162
|
+
'routes-review-pack', // job #1910 (A343): the monthly review packs for Library › Reports, drafted when due (<state>/reports/review-pack/; page-press POST)
|
|
163
|
+
'routes-portfolio', // bet A56: the Portfolio, every product side by side, and the answer to its one recommendation (runtime portfolio.jsonl; page-press POST)
|
|
158
164
|
]);
|
|
159
165
|
const PM_DIR = path.join(__dirname, '..', 'public', 'pm');
|
|
160
166
|
const MODULE_NAME = /^[a-z0-9][a-z0-9-]*\.js$/;
|
|
@@ -962,6 +962,9 @@ function itemsOf(w, fr, board, rows) {
|
|
|
962
962
|
// the PM's priority (inline-sprint-priority): carried only when set
|
|
963
963
|
const PR = fr.folded.priorities || new Map();
|
|
964
964
|
if (PR.size) for (const x of out) if (x.kind !== 'Epic' && x.src !== 'jira' && PR.has(x.uid)) x.priority = PR.get(x.uid);
|
|
965
|
+
// the PM's optional times (task-time-optional): carried only when set, so a task with no time reads exactly as before
|
|
966
|
+
const TMS = fr.folded.times || new Map();
|
|
967
|
+
if (TMS.size) for (const x of out) if (x.kind !== 'Epic' && x.src !== 'jira' && TMS.has(x.uid)) Object.assign(x, timeFields(TMS, x.uid));
|
|
965
968
|
// the task's description (task-descriptions): carried only when set; descBy 'pmos' when PMOS wrote the last one, with its sources
|
|
966
969
|
const DS = fr.folded.descriptions || new Map();
|
|
967
970
|
if (DS.size) for (const x of out) if (x.src !== 'jira' && DS.has(x.uid)) Object.assign(x, descFields(DS.get(x.uid)));
|
|
@@ -971,6 +974,9 @@ function itemsOf(w, fr, board, rows) {
|
|
|
971
974
|
return B.rollupItems(out);
|
|
972
975
|
}
|
|
973
976
|
|
|
977
|
+
/** A task's times as item fields (task-time-optional): start_time and due_time, each only when set. */
|
|
978
|
+
function timeFields(TM, id) { const v = TM && TM.get(id); const o = {}; if (v && v.start_time) o.start_time = v.start_time; if (v && v.due_time) o.due_time = v.due_time; return o; }
|
|
979
|
+
|
|
974
980
|
/** tracker-daily: a PMOS task that names a Jira key carries `tracker` { key, status, readAt, stale }: Jira's status at the last read, and
|
|
975
981
|
* stale when that read is older than a day or did not return the ticket (lib/task-jira.js staleOf). Its state is already the read's
|
|
976
982
|
* (readLedger). A page or a forecast says "not read since" instead of trusting a stale state. */
|
|
@@ -1758,6 +1764,8 @@ const WRITES = {
|
|
|
1758
1764
|
if (body.milestone != null && typeof body.milestone !== 'boolean') return fail(ctx, res, 400, 'milestone is true or false');
|
|
1759
1765
|
// the priority and the sprint, set in the row (initiative inline-sprint-priority): sprint is the sprint's name, only to word the line's why
|
|
1760
1766
|
if (body.priority != null && (typeof body.priority !== 'string' || !/^(P[1-3])?$/.test(body.priority))) return fail(ctx, res, 400, "priority is P1, P2, P3, or '' for none");
|
|
1767
|
+
// an optional time of day on the start and due (task-time-optional): "HH:MM", or '' to take it out; the day stays in start and due
|
|
1768
|
+
for (const k of ['start_time', 'due_time']) if (body[k] != null && body[k] !== '' && !(typeof body[k] === 'string' && B.TIME_RE.test(body[k]))) return fail(ctx, res, 400, `${k} is a time of day, HH:MM (00:00 to 23:59), or '' for none`);
|
|
1761
1769
|
if (body.sprint != null && body.sprint !== '' && !ONE_LINE(body.sprint, 80)) return fail(ctx, res, 400, 'sprint is the sprint\'s name, one line of at most 80 characters');
|
|
1762
1770
|
if (body.pinned !== undefined && body.pinned !== null && typeof body.pinned !== 'boolean') return fail(ctx, res, 400, 'pinned is true, false, or null for the rule (the last milestone only)');
|
|
1763
1771
|
const pinWas = (id) => { const PN = p.fr.folded.pins || new Map(); return PN.has(id) ? PN.get(id) : null; };
|
|
@@ -1765,7 +1773,7 @@ const WRITES = {
|
|
|
1765
1773
|
// a Jira ticket takes the milestone flag (feedback batch 11 item 3) and the PM's own start and due days, kept in PMOS only (item 23):
|
|
1766
1774
|
// Jira keeps its title, status and assignee, and nothing is written to Jira
|
|
1767
1775
|
if (typeof body.task === 'string' && B.JIRA_KEY_RE.test(body.task) && !B.taskOf(p.fr.folded, body.task)) {
|
|
1768
|
-
if (['owner', 'notes', 'initiative', 'section', 'priority', 'description'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates, its milestone flag and its pin change here');
|
|
1776
|
+
if (['owner', 'notes', 'initiative', 'section', 'priority', 'description', 'start_time', 'due_time'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates, its milestone flag and its pin change here');
|
|
1769
1777
|
if (body.milestone == null && body.start == null && body.due == null && body.pinned === undefined && body.parent == null) return fail(ctx, res, 400, 'nothing to change: send start, due, milestone, pinned or parent');
|
|
1770
1778
|
if (body.parent != null) { const pe = parentError(p, body.task, body.parent, null); if (pe) return fail(ctx, res, 400, pe); }
|
|
1771
1779
|
for (const k of ['start', 'due']) if (body[k] != null && body[k] !== '' && !/^\d{4}-\d{2}-\d{2}$/.test(String(body[k]))) return fail(ctx, res, 400, `${k} is a day, YYYY-MM-DD, or '' for none`);
|
|
@@ -1857,12 +1865,26 @@ const WRITES = {
|
|
|
1857
1865
|
const d0 = (p.fr.folded.descriptions || new Map()).get(t.id);
|
|
1858
1866
|
desc = body.description.replace(/\s+$/, ''); from.description = d0 ? d0.text : '';
|
|
1859
1867
|
}
|
|
1860
|
-
|
|
1868
|
+
// the times (task-time-optional): a board-ledger line for every kind of PMOS task, like the priority. A day cleared to '' takes its time
|
|
1869
|
+
// with it, so a task never keeps a time on a day it no longer has
|
|
1870
|
+
let tm = null;
|
|
1871
|
+
{
|
|
1872
|
+
const T0 = (p.fr.folded.times || new Map()).get(t.id) || { start_time: '', due_time: '' }, next = {};
|
|
1873
|
+
for (const k of ['start_time', 'due_time']) if (body[k] != null) next[k] = String(body[k]);
|
|
1874
|
+
if (ev.start === '' && T0.start_time && next.start_time == null) next.start_time = '';
|
|
1875
|
+
if (ev.due === '' && T0.due_time && next.due_time == null) next.due_time = '';
|
|
1876
|
+
if (Object.keys(next).length) {
|
|
1877
|
+
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
1878
|
+
tm = next; for (const k of Object.keys(next)) if (body[k] != null) from[k] = T0[k] || '';
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
if (!Object.keys(ev).length && sec == null && ms == null && !pin && !prio && par == null && desc == null && tm == null) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, start_time, due_time, initiative, section, milestone, pinned, priority, parent or description');
|
|
1861
1882
|
if (sec != null) append(p.file, g.actor, { kind: 'task-section', board: p.board.id, task: t.id, section: sec, why: sec ? 'placed under ' + sec : 'placed under no stage' });
|
|
1862
1883
|
if (ms != null) append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: t.id, milestone: ms, why: ms ? 'made a milestone' : 'no longer a milestone' });
|
|
1863
1884
|
if (pin) append(p.file, g.actor, pinLine(t.id));
|
|
1864
1885
|
if (prio) { append(p.file, g.actor, { kind: 'task-priority', board: p.board.id, task: t.id, priority: body.priority, why: body.priority ? 'priority ' + body.priority : 'no priority' }); console.info('[inline-field] priority'); }
|
|
1865
1886
|
if (par != null) append(p.file, g.actor, parentLine(p, t.id, par));
|
|
1887
|
+
if (tm) append(p.file, g.actor, { kind: 'task-time', board: p.board.id, task: t.id, ...tm, why: Object.values(tm).some(Boolean) ? 'time set' : 'time taken out' });
|
|
1866
1888
|
if (desc != null) append(p.file, g.actor, { kind: 'task-description', board: p.board.id, task: t.id, description: desc, ...(Array.isArray(g.sources) && desc ? { sources: g.sources } : {}), why: desc ? (g.sources ? 'written from ' + g.sources.length + (g.sources.length === 1 ? ' source' : ' sources') : 'description edited') : 'description cleared' });
|
|
1867
1889
|
if (!Object.keys(ev).length) {
|
|
1868
1890
|
const items = itemsOf(p.w, { ...p.fr, folded: B.fold(readLedger(ctx, p.w)) }, p.board, (needRows(ctx, res, p.w) || []).filter((r) => r.id === t.initiative));
|
|
@@ -1876,6 +1898,7 @@ const WRITES = {
|
|
|
1876
1898
|
if (intoSprint) console.info('[inline-field] sprint');
|
|
1877
1899
|
const F2 = B.fold(readLedger(ctx, p.w)), t2 = B.taskOf(F2, t.id), it2 = B.rollupItems([B.taskItem(t2)])[0];
|
|
1878
1900
|
if (F2.priorities && F2.priorities.has(t.id)) it2.priority = F2.priorities.get(t.id);
|
|
1901
|
+
Object.assign(it2, timeFields(F2.times, t.id));
|
|
1879
1902
|
ctx.json(res, { ok: true, from, item: it2 });
|
|
1880
1903
|
},
|
|
1881
1904
|
'/api/boards/tasks/describe-draft': async (ctx, res, body, g) => {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-portfolio.js — the Portfolio: every product side by side for a head of product (initiative portfolio, bet A56).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/product-portfolio → { ok, show, rows, rec, as_of } lib/portfolio.js view over every registered product
|
|
5
|
+
* except the embedded PMOS checkout (PMOS itself is not a product). show is false
|
|
6
|
+
* under two products. Reads only; one use-log line (control portfolio)
|
|
7
|
+
* POST /api/product-portfolio/decide { key, kind } kind keep | not-now | undo: the answer to the one recommendation (page press),
|
|
8
|
+
* in <runtime>/portfolio.jsonl, the store `pmos portfolio keep|not-now|undo` writes too
|
|
9
|
+
* Nothing here writes a product's files or sends anything. (/api/portfolio is the older OKR hub of server.js, a different thing.) */
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const guard = require('./pm-guard.js');
|
|
12
|
+
const PF = require('./portfolio.js');
|
|
13
|
+
|
|
14
|
+
/** The products the Portfolio compares: every registered workspace except the embedded PMOS checkout. */
|
|
15
|
+
function productsOf(ctx) {
|
|
16
|
+
const list = (ctx.workspaceList ? ctx.workspaceList() : []) || [];
|
|
17
|
+
const self = ctx.selfRoot ? path.resolve(ctx.selfRoot) : null;
|
|
18
|
+
return list.filter((w) => w && w.root && path.resolve(w.root) !== self).map((w) => ({ ws: w.id, name: w.name || path.basename(w.root), root: w.root }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
prefixes: ['/api/product-portfolio'],
|
|
23
|
+
productsOf,
|
|
24
|
+
handle: async (req, res, url, ctx) => {
|
|
25
|
+
const p = url.pathname;
|
|
26
|
+
const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
|
|
27
|
+
if (p === '/api/product-portfolio') {
|
|
28
|
+
if (req.method !== 'GET') return bad('GET only', 405);
|
|
29
|
+
const v = PF.view(productsOf(ctx), ctx.runtimeDir || null);
|
|
30
|
+
if (ctx.runtimeDir) { try { require('./use-log.js').record(ctx.runtimeDir, [{ kind: 'use', page: 'premium-portfolio', control: 'portfolio', device: 'desk' }], Date.now()); } catch { /* a count only */ } }
|
|
31
|
+
console.log(`${PF.TAG} read products=${v.rows.length} show=${v.show} rec=${v.rec ? 1 : 0}`);
|
|
32
|
+
ctx.json(res, v);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (p === '/api/product-portfolio/decide') {
|
|
36
|
+
if (req.method !== 'POST') return bad('POST only', 405);
|
|
37
|
+
const got = await ctx.readJson(req);
|
|
38
|
+
if (!got.ok) return bad('invalid JSON body');
|
|
39
|
+
const b = got.body || {};
|
|
40
|
+
const g = guard.requirePagePress(req, b);
|
|
41
|
+
if (!g.ok) return bad(g.error, g.status);
|
|
42
|
+
const r = PF.decide(ctx.runtimeDir || null, { key: b.key, kind: b.kind, by: 'page' });
|
|
43
|
+
if (!r.ok) return bad(r.error);
|
|
44
|
+
console.log(`${PF.TAG} ${r.line.kind} key=${r.line.key}`);
|
|
45
|
+
ctx.json(res, { ok: true, line: r.line });
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return bad('no such route', 404);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-review-pack.js — the monthly review packs of every product, for Library › Reports (initiative review-pack, job #1910; lib/review-pack.js).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/review-packs → { ok, items } each product's packs as Library rows (lib/review-pack.js itemsOf), newest first. Read only.
|
|
5
|
+
* POST /api/review-packs/due {} → { ok, written, items } Library calls it when it opens: in the last 7 days of the month, PMOS drafts the month's
|
|
6
|
+
* pack of each product that has none (lib/review-pack.js tick). A pack that exists is
|
|
7
|
+
* never written over, and nothing is shared: Share is the PM's Issue press.
|
|
8
|
+
* PMOS_REVIEW_PACK=0 turns the drafting off (=1 on); a scratch server (its own PMOS_STATE_DIR) drafts none by default (lib/review-pack.js autoOn).
|
|
9
|
+
* The POST comes from the page only (pm-guard requirePagePress); an agent session is refused (403). */
|
|
10
|
+
const guard = require('./pm-guard.js');
|
|
11
|
+
const RP = require('./review-pack.js');
|
|
12
|
+
|
|
13
|
+
function itemsAll(ctx) {
|
|
14
|
+
const list = typeof ctx.workspaceList === 'function' ? ctx.workspaceList() : [];
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const w of list) {
|
|
17
|
+
if (!w || !w.root) continue;
|
|
18
|
+
try { out.push(...RP.itemsOf({ ws: w.id, name: w.label || w.name || w.id, packs: RP.list(w.root) })); } catch { /* an unreadable product shows no pack */ }
|
|
19
|
+
}
|
|
20
|
+
return out.sort((a, b) => String(b.updated || '').localeCompare(String(a.updated || '')));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function handle(req, res, url, ctx) {
|
|
24
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
25
|
+
const what = url.pathname.replace(/^\/api\/review-packs\/?/, '');
|
|
26
|
+
if (what === '') {
|
|
27
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'GET only' });
|
|
28
|
+
return send(200, { ok: true, items: itemsAll(ctx) });
|
|
29
|
+
}
|
|
30
|
+
if (what !== 'due') return send(404, { ok: false, error: 'no such review-pack route' });
|
|
31
|
+
if (req.method !== 'POST') return send(405, { ok: false, error: 'POST only' });
|
|
32
|
+
if (req.headers && req.headers['x-pmos-session']) return send(403, { ok: false, error: 'An agent session does not open Library. Draft a pack with pmos report pack.' });
|
|
33
|
+
const rd = await ctx.readJson(req);
|
|
34
|
+
if (!rd.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
35
|
+
const g = guard.requirePagePress(req, rd.body || {});
|
|
36
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
37
|
+
let written = [];
|
|
38
|
+
if (RP.autoOn(process.env)) try { written = (await RP.tick({ workspaceList: ctx.workspaceList, stateDirFor: ctx.stateDirFor })).filter((r) => r.written).map((r) => ({ ws: r.ws, path: r.path })); } catch { written = []; }
|
|
39
|
+
return send(200, { ok: true, written, items: itemsAll(ctx) });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { prefixes: ['/api/review-packs'], handle, itemsAll };
|