create-pmos 0.827.0 → 0.828.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 +86 -32
- 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/changelog.json +85 -12
- package/workspace/guide/cli.md +29 -0
- package/workspace/lib/board-cli.js +5 -1
- package/workspace/lib/features.json +2 -0
- package/workspace/lib/five-action-cap.js +84 -0
- package/workspace/lib/people-cli.js +43 -2
- package/workspace/lib/pmos-verbs.js +7 -1
- package/workspace/lib/portfolio-cli.js +64 -0
- package/workspace/lib/portfolio.js +168 -0
- package/workspace/lib/review-reasons.js +357 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-portfolio.js +50 -0
- package/workspace/lib/routes-stakeholders.js +42 -0
- package/workspace/lib/routes-strategy-card.js +29 -1
- package/workspace/lib/routes-use-log.js +6 -1
- package/workspace/lib/stakeholder-map.js +232 -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-principles.js +12 -1
- package/workspace/public/pm/cozy-pick.css +1 -0
- package/workspace/public/pm/cozy-pop-work.js +6 -1
- package/workspace/public/pm/cozy-today-app.js +48 -1
- package/workspace/public/pm/cozy-today-view.js +12 -4
- package/workspace/public/pm/five-action-cap.js +104 -0
- package/workspace/public/pm/portfolio.js +67 -0
- package/workspace/public/pm/product-switcher.js +7 -1
- package/workspace/public/pm/review-reasons.js +75 -0
- package/workspace/public/pm/stakeholder-map.js +125 -0
- package/workspace/public/premium-portfolio.html +48 -0
- package/workspace/server.js +1 -1
- package/workspace/stage-card-tasks-test.js +11 -5
- package/workspace/test-lists/five-action-cap.json +9 -0
- package/workspace/test-lists/portfolio.json +9 -0
- package/workspace/test-lists/review-reasons.json +9 -0
- package/workspace/test-lists/stakeholder-map.json +9 -0
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* pmos people show <person> [--json] one person's page: interactions, tone, shared work, notes, handles
|
|
7
7
|
* pmos people record --file <sightings.json> (agent session) append what the session saw
|
|
8
8
|
* pmos people settings [--json] whether calendar attendee names are kept
|
|
9
|
+
* pmos people map <initiative> [--json] who decides, must agree, needs to know, and when each last heard (A371)
|
|
10
|
+
* pmos people keep|drop|told|undo <initiative> <person> [--group decides|agree|know] the PM's word on one name (lib/stakeholder-map.js)
|
|
9
11
|
*
|
|
10
12
|
* The same module the People place reads (lib/people-store.js), so a terminal line and the page cannot disagree.
|
|
11
13
|
* `list` and `show` first record the names this repository's records hold (plan item owners, Live notes speakers), as
|
|
@@ -20,14 +22,17 @@ const path = require('path');
|
|
|
20
22
|
const store = require('./people-store');
|
|
21
23
|
const { parseArgs } = require('./schedule-cli');
|
|
22
24
|
|
|
23
|
-
const COMMANDS = { people: ['list', 'show', 'record', 'settings'] };
|
|
25
|
+
const COMMANDS = { people: ['list', 'show', 'record', 'settings', 'map', 'keep', 'drop', 'told', 'undo'] };
|
|
24
26
|
const USAGE = [
|
|
25
27
|
'usage: pmos people [list|show|record|settings] — the people you work with in this repository',
|
|
26
28
|
' pmos people [list] [--json] each person, and what waits for you in the review list',
|
|
27
29
|
' pmos people show <person> [--json] one person: interactions, tone, shared work, notes and handles',
|
|
28
30
|
' pmos people record --file <sightings.json> (agent session) record the people a session saw',
|
|
29
31
|
' pmos people settings [--json] whether calendar attendee names are kept (calendar names: on|off)',
|
|
30
|
-
'
|
|
32
|
+
' pmos people map <initiative> [--json] who decides, who must agree, who needs to know, and when each last heard from you',
|
|
33
|
+
' pmos people keep <initiative> <person> [--group decides|agree|know] keep a name on the map (in that group)',
|
|
34
|
+
' pmos people drop|told|undo <initiative> <person> take a name off, mark that you sent them an update, or take back the last of these',
|
|
35
|
+
'Nothing here removes a person, merges, sets a tone or writes a note. Do that in People. PMOS never sends an update: you do.',
|
|
31
36
|
];
|
|
32
37
|
const BOOL = new Set(['json', 'help']);
|
|
33
38
|
|
|
@@ -128,7 +133,43 @@ async function run(argv, { say = console.log, cwd = process.cwd(), env = process
|
|
|
128
133
|
if (!r.ok) say(`✗ ${r.error}`);
|
|
129
134
|
return r.ok ? 0 : 1;
|
|
130
135
|
}
|
|
136
|
+
if (sub === 'map' || SM_ACTS.includes(sub)) return mapCmd(sub, pos, flags, { say, root, json, fail, now });
|
|
131
137
|
return fail(`pmos people ${sub} is not a command. ${USAGE[0]}`, 2);
|
|
132
138
|
}
|
|
133
139
|
|
|
140
|
+
const SM_ACTS = ['keep', 'drop', 'told', 'undo'];
|
|
141
|
+
/** `pmos people map` and the four presses on one name (initiative stakeholder-map): the store the Work popup's People block reads. */
|
|
142
|
+
function mapCmd(sub, pos, flags, { say, root, json, fail, now }) {
|
|
143
|
+
const SM = require('./stakeholder-map.js');
|
|
144
|
+
const ini = String(pos[1] || '');
|
|
145
|
+
if (!ini) return fail(`usage: pmos people ${sub} <initiative>${sub === 'map' ? '' : ' <person>'}`, 2);
|
|
146
|
+
if (sub === 'map') {
|
|
147
|
+
const m = SM.read(root, ini, { now });
|
|
148
|
+
if (json) { say(JSON.stringify({ ok: true, ...m })); return 0; }
|
|
149
|
+
say(`People · ${m.title} · ${m.rows.length} ${m.rows.length === 1 ? 'name' : 'names'}${m.drafts ? ` · ${m.drafts} draft${m.drafts === 1 ? '' : 's'} to keep or drop` : ''}`);
|
|
150
|
+
if (!m.rows.length) { say('No names yet. PMOS lists the record\'s decider, the sign-offs and the people whose Jira, notes or mail name this initiative.'); return 0; }
|
|
151
|
+
for (const g of SM.GROUPS) {
|
|
152
|
+
const rows = m.rows.filter((r) => r.group === g);
|
|
153
|
+
if (!rows.length) continue;
|
|
154
|
+
say(SM.GROUP_WORD[g][0].toUpperCase() + SM.GROUP_WORD[g].slice(1) + ':');
|
|
155
|
+
for (const r of rows) {
|
|
156
|
+
const heard = r.days == null ? 'no update on record' : r.days === 0 ? 'last heard today' : `last heard ${r.days} day${r.days === 1 ? '' : 's'} ago`;
|
|
157
|
+
say(` ${r.name} (${r.id}) · ${heard}${r.kept ? '' : ' · draft: ' + r.why}`);
|
|
158
|
+
if (r.update) say(` ✦ draft update, for you to send: ${r.update}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
const who = String(pos.slice(2).join(' ') || '');
|
|
164
|
+
if (!who) return fail(`usage: pmos people ${sub} <initiative> <person>`, 2);
|
|
165
|
+
const m = SM.read(root, ini, { now });
|
|
166
|
+
const row = m.rows.find((r) => r.id === who.toLowerCase()) || m.rows.find((r) => SM.same(r.name, who));
|
|
167
|
+
const r = SM.act(SM.recordsDirOf(root), { ini, person: row ? row.id : null, name: row ? row.name : who, kind: sub, group: flags.group != null ? flags.group : sub === 'keep' && row ? row.group : undefined }, { by: 'pm', now });
|
|
168
|
+
if (json) { say(JSON.stringify(r)); return r.ok ? 0 : 1; }
|
|
169
|
+
if (!r.ok) return fail(r.error);
|
|
170
|
+
const word = { keep: `kept${r.line.group ? ' · ' + SM.GROUP_WORD[r.line.group] : ''}`, drop: 'taken off the map', told: 'marked: you sent them an update today', undo: 'your last press taken back' }[sub];
|
|
171
|
+
say(`✓ ${r.line.name || r.line.person} ${word}`);
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
134
175
|
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -50,7 +50,7 @@ const VERBS = Object.freeze({
|
|
|
50
50
|
help: 'pmos docs [list|link|unlink|find] … — is each linked document the same as, ahead of or behind its Google Docs and Confluence copy, and record a sync (pmos docs help)' }),
|
|
51
51
|
// Not a pm-os-absorb verb (run: null): people-directory added it through the same table.
|
|
52
52
|
people: Object.freeze({ module: 'people-cli.js', run: null, guide: 'cli.md',
|
|
53
|
-
help: 'pmos people list|show|record|settings … — the people you work with in this repository (pmos people help)' }),
|
|
53
|
+
help: 'pmos people list|show|record|settings|map|keep|drop|told|undo … — the people you work with in this repository, and who decides on each initiative (pmos people help)' }),
|
|
54
54
|
// Not a pm-os-absorb verb (run: null): initiative dry-run-tickets-before-build added it through the same table.
|
|
55
55
|
signoff: Object.freeze({ module: 'signoff-cli.js', run: null, guide: 'cli.md',
|
|
56
56
|
help: 'pmos signoff ask|answer|drop|evidence|list … — the sign-offs an initiative waits on; a stage\'s sign-offs are Your move rows on Today (pmos signoff help)' }),
|
|
@@ -213,6 +213,9 @@ const VERBS = Object.freeze({
|
|
|
213
213
|
driver: Object.freeze({ module: 'driver-cli.js', run: null, guide: 'cli.md',
|
|
214
214
|
help: 'pmos driver propose|status|exits|keep|return|drop|undo|pause|resume|mode … — the Initiative Driver: class A and B changes apply with Undo, the rest wait for you (pmos driver help)' }),
|
|
215
215
|
// one-change-record-no-source-no-auto: everything PMOS changed by itself, in one record (lib/change-record.js)
|
|
216
|
+
// Not a pm-os-absorb verb (run: null): initiative portfolio (bet A56) added it through the same table.
|
|
217
|
+
portfolio: Object.freeze({ module: 'portfolio-cli.js', run: null, guide: 'cli.md',
|
|
218
|
+
help: 'pmos portfolio [--json] | keep|not-now|undo <key> — every product side by side: bets, odds, spend, outcome so far, and one recommendation (pmos portfolio help)' }),
|
|
216
219
|
health: Object.freeze({ module: 'product-health-cli.js', run: null, guide: 'cli.md',
|
|
217
220
|
help: 'pmos health [score|trend|drops] — this product\'s health score (0 to 100), its trend this month and its past drops (pmos health help)' }),
|
|
218
221
|
// Not a pm-os-absorb verb (run: null): initiative setup-station (product line slice 5) added it through the same table.
|
|
@@ -243,6 +246,9 @@ const VERBS = Object.freeze({
|
|
|
243
246
|
// Not a pm-os-absorb verb (run: null): feedback batch 25 item 1 added it through the same table.
|
|
244
247
|
'git-identity': Object.freeze({ module: 'git-identity-cli.js', run: null, guide: 'cli.md',
|
|
245
248
|
help: 'pmos git-identity [set --name <n> --email <e> --login <gh>] — which git identity and GitHub login this repository uses; save your choice for it' }),
|
|
249
|
+
// Not a pm-os-absorb verb (run: null): initiative review-reasons (job #1913, A427) added it through the same table.
|
|
250
|
+
voice: Object.freeze({ module: 'voice-cli.js', run: null, guide: 'cli.md',
|
|
251
|
+
help: 'pmos voice add|import|reason|list|file|undo|count — survey comments and app-store reviews grouped by reason; Work shows them as Customer voice (pmos voice help)' }),
|
|
246
252
|
// Not a pm-os-absorb verb (run: null): roadmap-signal-verb (bet A157) added it through the same table.
|
|
247
253
|
signal: Object.freeze({ module: 'signal-cli.js', run: null, guide: 'cli.md',
|
|
248
254
|
help: 'pmos signal add|remove|list|count — the customer signals behind each roadmap item; Work shows the count (pmos signal help)' }),
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* portfolio-cli.js — `pmos portfolio`: every registered product side by side, and the answer to its one recommendation (initiative portfolio).
|
|
3
|
+
* The work is in lib/portfolio.js; the page (/premium-portfolio.html) reads the same rows and writes the same store.
|
|
4
|
+
*
|
|
5
|
+
* pmos portfolio [--json] one line per product (bets, odds, spend, outcome) and the ✦ recommendation, if any
|
|
6
|
+
* pmos portfolio keep|not-now <key> answer the recommendation: Keep hides it while its facts hold, Not now for 7 days
|
|
7
|
+
* pmos portfolio undo <key> take the last answer back
|
|
8
|
+
*
|
|
9
|
+
* The products are the workspace's registered ones (workspaces.json in the state folder), and this repository when it has a PMOS state
|
|
10
|
+
* folder. Reading changes no product's files. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const PF = require('./portfolio.js');
|
|
14
|
+
|
|
15
|
+
const COMMANDS = { portfolio: ['keep', 'not-now', 'undo'] };
|
|
16
|
+
const USAGE = [
|
|
17
|
+
'usage: pmos portfolio [--json] | keep|not-now|undo <key> — every product side by side: bets, odds, spend, outcome so far',
|
|
18
|
+
' pmos portfolio [--json] one line per product and PMOS\'s one recommendation',
|
|
19
|
+
' pmos portfolio keep <key> keep the recommendation (it stays hidden while its facts hold)',
|
|
20
|
+
' pmos portfolio not-now <key> not now: hidden for 7 days',
|
|
21
|
+
' pmos portfolio undo <key> take the last answer back',
|
|
22
|
+
].join('\n');
|
|
23
|
+
|
|
24
|
+
const stateOf = (env) => require('./state-root.js').defaultRoot({ env });
|
|
25
|
+
|
|
26
|
+
/** The registered products, and this repository when it has a PMOS state folder and is not registered. */
|
|
27
|
+
function productsOf(dir, cwd) {
|
|
28
|
+
const driver = require('./driver.js');
|
|
29
|
+
let reg = [];
|
|
30
|
+
try { reg = JSON.parse(fs.readFileSync(path.join(dir, 'workspaces.json'), 'utf8')); } catch { reg = []; }
|
|
31
|
+
const out = [], seen = new Set();
|
|
32
|
+
const add = (root, ws, name) => {
|
|
33
|
+
const r = path.resolve(root);
|
|
34
|
+
if (seen.has(r) || !driver.stateDirOf(r)) return;
|
|
35
|
+
seen.add(r);
|
|
36
|
+
out.push({ ws: ws || driver.wsIdOf(r), name: name || path.basename(r), root: r });
|
|
37
|
+
};
|
|
38
|
+
for (const x of Array.isArray(reg) ? reg : []) if (x && typeof x.root === 'string') { try { if (fs.statSync(x.root).isDirectory()) add(x.root, x.id, x.name); } catch { /* gone */ } }
|
|
39
|
+
if (cwd) add(cwd);
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function run(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd(), now = Date.now() } = {}) {
|
|
44
|
+
const args = argv[0] === 'portfolio' ? argv.slice(1) : argv.slice();
|
|
45
|
+
const dir = stateOf(env);
|
|
46
|
+
const sub = args[0] && !args[0].startsWith('--') ? args[0] : null;
|
|
47
|
+
if (sub === 'help') { say(USAGE); return 0; }
|
|
48
|
+
if (sub) {
|
|
49
|
+
if (!PF.KINDS.includes(sub) || !args[1]) { say(USAGE); return 2; }
|
|
50
|
+
const r = PF.decide(dir, { key: args[1], kind: sub, by: 'cli' }, { now });
|
|
51
|
+
if (!r.ok) { say(r.error); return 1; }
|
|
52
|
+
console.info(`${PF.TAG} ${sub} key=${args[1]}`);
|
|
53
|
+
say(sub === 'undo' ? 'Taken back: the recommendation shows again.' : sub === 'keep' ? `Kept. To take it back: pmos portfolio undo ${args[1]}` : `Not now: hidden for ${PF.NOT_NOW_DAYS} days. To take it back: pmos portfolio undo ${args[1]}`);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
const v = PF.view(productsOf(dir, cwd), dir, { now });
|
|
57
|
+
try { require('./use-log.js').record(dir, [{ kind: 'use', page: 'premium-portfolio', control: 'portfolio', device: 'desk' }], now); } catch { /* a count, never a reason to fail */ }
|
|
58
|
+
console.info(`${PF.TAG} products=${v.rows.length} show=${v.show} rec=${v.rec ? 1 : 0}`);
|
|
59
|
+
if (args.includes('--json')) { say(JSON.stringify(v, null, 2)); return 0; }
|
|
60
|
+
for (const l of PF.lines(v)) say(l);
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { COMMANDS, USAGE, run, productsOf };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* portfolio.js — the Portfolio: every product side by side for a head of product (bet A56, initiative portfolio, board BatchPlanDS panel 7).
|
|
3
|
+
*
|
|
4
|
+
* rowsOf(facts, { now }) PURE → [{ ws, name, bets, odds, judged, spend, outcome, due }] one row per product, in the given order
|
|
5
|
+
* recommend(rows) PURE → { key, to, from, n, text, why } | null at most one recommendation
|
|
6
|
+
* fold(lines, now) PURE → { [key]: { kind, until } } the decisions that stand (Undo takes the last back)
|
|
7
|
+
* hidden(rec, lines, now) PURE → bool Keep hides it while its facts hold; Not now for 7 days
|
|
8
|
+
* factsOf(root, { now }) → one product's facts, read from its own records (never written)
|
|
9
|
+
* read(products, { now }) → { show, rows, rec } products: [{ ws, name, root }]. rec is the recommendation before decisions
|
|
10
|
+
* view(products, dir, { now }) → { ok, show, rows, rec, as_of } read() with the decisions of <dir>/portfolio.jsonl applied
|
|
11
|
+
* decide(dir, { key, kind, by }, { now }) → { ok, line } | { ok: false, error } THE ONE WRITER of <dir>/portfolio.jsonl
|
|
12
|
+
*
|
|
13
|
+
* THE NUMBERS come from records every PMOS product keeps, so the page works on any user's products:
|
|
14
|
+
* bets the product's work initiatives that are not stopped and whose outcome is not judged yet (lib/outcomes.js scan: subjects less disposed)
|
|
15
|
+
* odds validated of validated plus refuted outcome checks, in percent. Under MIN_JUDGED judged it is null: not known, never a guess
|
|
16
|
+
* spend the cost of the product's agent runs in the last SPEND_DAYS days (factory-traces.jsonl in its state folder). No cost: null
|
|
17
|
+
* outcome the evidence of the product's latest check that held (validated). None: null
|
|
18
|
+
* due its bets whose outcome check is due: they wait on review
|
|
19
|
+
* THE RECOMMENDATION. The product with the most due checks, MIN_DUE or more, is the one to help. When another product has more open bets
|
|
20
|
+
* and none due, PMOS says to move one person from it; otherwise to look at the product first. The reason is the due count.
|
|
21
|
+
*
|
|
22
|
+
* THE STORE. <runtime>/portfolio.jsonl, append-only, one line { at, kind: 'keep'|'not-now'|'undo', key, by, until? }. The key holds the
|
|
23
|
+
* facts (to, from, due count), so a kept recommendation comes back only when they change. Nothing here writes a product's files.
|
|
24
|
+
* The Portfolio shows only with MIN_PRODUCTS products or more (`show`). */
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
|
|
28
|
+
const FILE = 'portfolio.jsonl';
|
|
29
|
+
const TAG = '[portfolio]';
|
|
30
|
+
const DAY = 86400000;
|
|
31
|
+
const SPEND_DAYS = 30;
|
|
32
|
+
const MIN_JUDGED = 3;
|
|
33
|
+
const MIN_DUE = 2;
|
|
34
|
+
const MIN_PRODUCTS = 2;
|
|
35
|
+
const NOT_NOW_DAYS = 7;
|
|
36
|
+
const KINDS = Object.freeze(['keep', 'not-now', 'undo']);
|
|
37
|
+
const KEY_RE = /^[A-Za-z0-9._:-]{1,200}$/;
|
|
38
|
+
|
|
39
|
+
const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); if (t.length <= n) return t; const c = t.slice(0, n - 1); return (c.slice(0, c.lastIndexOf(' ')) || c).replace(/[,;:\s]+$/, '') + '…'; };
|
|
40
|
+
const timeOf = (c) => { const t = Date.parse(c && (c.at || c.date) || ''); return Number.isFinite(t) ? t : 0; };
|
|
41
|
+
|
|
42
|
+
function rowsOf(facts, { now = Date.now() } = {}) {
|
|
43
|
+
const since = now - SPEND_DAYS * DAY;
|
|
44
|
+
return (facts || []).map((f) => {
|
|
45
|
+
const judgedIds = new Set((f.disposed || []).map((d) => d.id));
|
|
46
|
+
const bets = (f.subjects || []).filter((s) => !judgedIds.has(s.id)).length;
|
|
47
|
+
const held = (f.disposed || []).filter((d) => d.disposition === 'validated').length;
|
|
48
|
+
const refuted = (f.disposed || []).filter((d) => d.disposition === 'refuted').length;
|
|
49
|
+
const judged = held + refuted;
|
|
50
|
+
const odds = judged >= MIN_JUDGED ? Math.round((held / judged) * 100) : null;
|
|
51
|
+
let spend = null;
|
|
52
|
+
for (const r of f.runs || []) {
|
|
53
|
+
const t = Date.parse(r && r.at || '');
|
|
54
|
+
if (!Number.isFinite(t) || t < since || t > now || !Number.isFinite(r.costUsd) || r.costUsd <= 0) continue;
|
|
55
|
+
spend = (spend || 0) + r.costUsd;
|
|
56
|
+
}
|
|
57
|
+
if (spend != null) spend = Math.round(spend * 100) / 100;
|
|
58
|
+
const last = (f.checks || []).filter((c) => c && c.disposition === 'validated' && c.evidence).sort((a, b) => timeOf(b) - timeOf(a))[0];
|
|
59
|
+
return { ws: f.ws, name: f.name || f.ws, bets, odds, judged, spend, outcome: last ? clip(last.evidence, 60) : null, due: (f.due || []).length };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function recommend(rows) {
|
|
64
|
+
const R = (rows || []).filter(Boolean);
|
|
65
|
+
const to = R.filter((r) => r.due >= MIN_DUE).sort((a, b) => b.due - a.due || b.bets - a.bets || String(a.name).localeCompare(String(b.name)))[0];
|
|
66
|
+
if (!to) return null;
|
|
67
|
+
const from = R.filter((r) => r !== to && r.due === 0 && r.bets > to.bets).sort((a, b) => b.bets - a.bets || String(a.name).localeCompare(String(b.name)))[0] || null;
|
|
68
|
+
const n = to.due;
|
|
69
|
+
return {
|
|
70
|
+
key: `${to.ws}:${from ? from.ws : '-'}:${n}`,
|
|
71
|
+
to: to.ws, from: from ? from.ws : null, n,
|
|
72
|
+
text: from ? `Move one person from ${from.name} to ${to.name}` : `Look at ${to.name} first`,
|
|
73
|
+
why: `${n} bets there wait on their outcome check.`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function fold(lines, now = Date.now()) {
|
|
78
|
+
const stack = {};
|
|
79
|
+
for (const l of lines || []) {
|
|
80
|
+
if (!l || !KEY_RE.test(String(l.key || '')) || !KINDS.includes(l.kind)) continue;
|
|
81
|
+
const s = (stack[l.key] = stack[l.key] || []);
|
|
82
|
+
if (l.kind === 'undo') s.pop(); else s.push(l);
|
|
83
|
+
}
|
|
84
|
+
const out = {};
|
|
85
|
+
for (const [k, s] of Object.entries(stack)) if (s.length) { const l = s[s.length - 1]; out[k] = { kind: l.kind, until: l.until || null, at: l.at || null }; }
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function hidden(rec, lines, now = Date.now()) {
|
|
90
|
+
if (!rec) return false;
|
|
91
|
+
const d = fold(lines, now)[rec.key];
|
|
92
|
+
if (!d) return false;
|
|
93
|
+
if (d.kind === 'keep') return true;
|
|
94
|
+
return d.kind === 'not-now' && !!d.until && Date.parse(d.until) > now;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Every outcome check line the product holds, in the places lib/outcomes.js reads them, each file once. */
|
|
98
|
+
function checksOf(root, runsDir) {
|
|
99
|
+
const OC = require('./outcomes.js');
|
|
100
|
+
const files = [...new Set([runsDir, path.join(root, 'pmos', 'state'), path.join(root, 'planning', 'runs')].filter(Boolean).map((d) => path.join(d, 'outcome_checks.jsonl')))];
|
|
101
|
+
const rows = [];
|
|
102
|
+
for (const f of files) {
|
|
103
|
+
let text = ''; try { text = fs.readFileSync(f, 'utf8'); } catch { continue; }
|
|
104
|
+
for (const s of text.split('\n')) { if (!s.trim()) continue; try { const o = JSON.parse(s); if (o && typeof o === 'object') rows.push(o); } catch { /* a torn line */ } }
|
|
105
|
+
}
|
|
106
|
+
return OC.liveChecks(rows);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function factsOf(root, { now = Date.now() } = {}) {
|
|
110
|
+
const OC = require('./outcomes.js');
|
|
111
|
+
const S = OC.scan(root, { today: OC.todayOf(now) });
|
|
112
|
+
let runs = [];
|
|
113
|
+
try { const dir = require('./driver.js').stateDirOf(root); runs = require('./factory-traces.js').read(dir, { sinceMs: now - SPEND_DAYS * DAY }); } catch { runs = []; }
|
|
114
|
+
return {
|
|
115
|
+
subjects: S.subjects.map((s) => ({ id: s.id })),
|
|
116
|
+
disposed: S.disposed.map((d) => ({ id: d.id, disposition: d.disposition })),
|
|
117
|
+
due: S.due.map((d) => ({ id: d.id })),
|
|
118
|
+
checks: checksOf(path.resolve(root), S.layout && S.layout.runsDir),
|
|
119
|
+
runs: runs.map((r) => ({ at: r.at, costUsd: r.costUsd })),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function read(products, { now = Date.now(), factsOf: F = factsOf } = {}) {
|
|
124
|
+
const list = (products || []).filter((p) => p && p.root);
|
|
125
|
+
const facts = list.map((p) => { let f; try { f = F(p.root, { now }); } catch { f = {}; } return { ...f, ws: p.ws, name: p.name || path.basename(p.root) }; });
|
|
126
|
+
const rows = rowsOf(facts, { now });
|
|
127
|
+
return { show: rows.length >= MIN_PRODUCTS, rows, rec: recommend(rows) };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function linesOf(dir) {
|
|
131
|
+
let text = ''; try { text = fs.readFileSync(path.join(dir, FILE), 'utf8'); } catch { return []; }
|
|
132
|
+
const out = [];
|
|
133
|
+
for (const s of text.split('\n')) { if (!s.trim()) continue; try { out.push(JSON.parse(s)); } catch { /* a torn line */ } }
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function view(products, dir, o = {}) {
|
|
138
|
+
const now = o.now || Date.now();
|
|
139
|
+
const r = read(products, o);
|
|
140
|
+
if (!r.show) return { ok: true, show: false, rows: [], rec: null, as_of: new Date(now).toISOString() };
|
|
141
|
+
const rec = r.rec && !hidden(r.rec, dir ? linesOf(dir) : [], now) ? r.rec : null;
|
|
142
|
+
return { ok: true, show: true, rows: r.rows, rec, as_of: new Date(now).toISOString() };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function decide(dir, { key, kind, by } = {}, { now = Date.now() } = {}) {
|
|
146
|
+
if (!dir) return { ok: false, error: 'no state folder to keep the decision in' };
|
|
147
|
+
if (!KINDS.includes(kind)) return { ok: false, error: `the answer is one of ${KINDS.join(', ')}` };
|
|
148
|
+
if (!KEY_RE.test(String(key || ''))) return { ok: false, error: 'name the recommendation by its key' };
|
|
149
|
+
if (kind === 'undo' && !fold(linesOf(dir), now)[key]) return { ok: false, error: 'there is no answer to this recommendation to undo' };
|
|
150
|
+
const line = { at: new Date(now).toISOString(), kind, key: String(key), by: String(by || 'pm').slice(0, 40) };
|
|
151
|
+
if (kind === 'not-now') line.until = new Date(now + NOT_NOW_DAYS * DAY).toISOString();
|
|
152
|
+
try {
|
|
153
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
154
|
+
fs.appendFileSync(path.join(dir, FILE), JSON.stringify(line) + '\n', { mode: 0o600 });
|
|
155
|
+
} catch (e) { return { ok: false, error: 'the decision could not be saved: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
156
|
+
return { ok: true, line };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** One printed line per product, then the recommendation. PURE. */
|
|
160
|
+
function lines(v) {
|
|
161
|
+
if (!v || !v.show) return ['Nothing to compare: the Portfolio needs two or more products.'];
|
|
162
|
+
const money = (n) => (n == null ? '' : '$' + (n >= 100 ? Math.round(n) : n.toFixed(2)));
|
|
163
|
+
const out = v.rows.map((r) => r.name + ': ' + [`${r.bets} bet${r.bets === 1 ? '' : 's'}`, r.odds == null ? '' : `odds ${r.odds}%`, r.spend == null ? '' : `spend ${money(r.spend)} (30 days)`, r.outcome ? `outcome: ${r.outcome}` : ''].filter(Boolean).join(' · '));
|
|
164
|
+
if (v.rec) out.push(`✦ ${v.rec.text}: ${v.rec.why} (pmos portfolio keep|not-now ${v.rec.key})`);
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = { FILE, TAG, SPEND_DAYS, MIN_JUDGED, MIN_DUE, MIN_PRODUCTS, NOT_NOW_DAYS, KINDS, rowsOf, recommend, fold, hidden, factsOf, read, view, decide, linesOf, lines };
|