create-pmos 0.428.0 → 0.429.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 +13 -13
- 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/briefing-premium-board-test.js +2 -2
- package/workspace/briefing-premium-insights-test.js +81 -60
- package/workspace/briefing-premium-metrics-test.js +5 -3
- package/workspace/briefing-premium-sources-test.js +5 -5
- package/workspace/briefing-premium-test.js +5 -4
- package/workspace/changelog.json +12 -0
- package/workspace/ev-everywhere-test.js +2 -2
- package/workspace/guide/home.md +2 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/metric-drafts.md +48 -0
- package/workspace/intel-report-ui-test.js +189 -0
- package/workspace/lib/board-metrics-premium.js +1 -1
- package/workspace/lib/headless.js +15 -2
- package/workspace/lib/insights-premium.js +5 -1
- package/workspace/lib/insights-records.js +14 -5
- package/workspace/lib/intel-report.js +419 -0
- package/workspace/lib/metric-draft-runs.js +193 -0
- package/workspace/lib/metric-drafts.js +231 -0
- package/workspace/lib/metrics-cli.js +104 -0
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/report-setups.js +29 -13
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-insights-premium.js +2 -2
- package/workspace/lib/routes-insights-records.js +13 -5
- package/workspace/lib/routes-metric-drafts.js +141 -0
- package/workspace/lib/routes-phone-day.js +13 -2
- package/workspace/lib/routes-report-setups.js +92 -3
- package/workspace/lib/routes-viewer.js +5 -2
- package/workspace/metric-drafts-ui-test.js +209 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-phone-card-test.js +8 -5
- package/workspace/public/pm/bd-acts.js +3 -3
- package/workspace/public/pm/bd-pin-card.css +4 -4
- package/workspace/public/pm/bd-prog-panel.js +9 -4
- package/workspace/public/pm/cozy-aud.css +1 -1
- package/workspace/public/pm/cozy-board.css +256 -256
- package/workspace/public/pm/cozy-ev.css +45 -45
- package/workspace/public/pm/cozy-evmodel.js +1 -1
- package/workspace/public/pm/cozy-home-rows.css +23 -23
- package/workspace/public/pm/cozy-home.css +207 -207
- package/workspace/public/pm/cozy-insights.css +207 -108
- package/workspace/public/pm/cozy-live-pill.css +5 -5
- package/workspace/public/pm/cozy-mtg-present.css +23 -23
- package/workspace/public/pm/cozy-nav.js +1 -1
- package/workspace/public/pm/cozy-news.js +2 -2
- package/workspace/public/pm/cozy-panel.css +29 -29
- package/workspace/public/pm/cozy-pick.css +5 -5
- package/workspace/public/pm/cozy-rec-now.css +20 -20
- package/workspace/public/pm/cozy-rec-present.css +11 -11
- package/workspace/public/pm/cozy-rec-tab.css +13 -13
- package/workspace/public/pm/cozy-settings.js +1 -1
- package/workspace/public/pm/cozy-steps.css +9 -9
- package/workspace/public/pm/cozy-today.css +107 -71
- package/workspace/public/pm/cozy-viewer.css +7 -7
- package/workspace/public/pm/cozy-viewer.js +1 -1
- package/workspace/public/pm/cozy-vw-mtg.css +81 -81
- package/workspace/public/pm/cozy-vw-rp.css +53 -53
- package/workspace/public/pm/cozy-vw-shell.css +23 -23
- package/workspace/public/pm/cozy-vw.css +117 -117
- package/workspace/public/pm/cozy-xv.css +11 -11
- package/workspace/public/pm/cozy.css +18 -15
- package/workspace/public/pm/hi-pop.css +19 -19
- package/workspace/public/pm/home-app.js +28 -2
- package/workspace/public/pm/home-day.js +131 -26
- package/workspace/public/pm/home-ini.css +32 -32
- package/workspace/public/pm/home-line.css +7 -7
- package/workspace/public/pm/home-list.js +12 -1
- package/workspace/public/pm/home-phone-card.js +18 -15
- package/workspace/public/pm/ini-view.css +102 -102
- package/workspace/public/pm/ini-view.js +9 -3
- package/workspace/public/pm/loose-props.css +13 -13
- package/workspace/public/pm/metric-drafts.css +82 -0
- package/workspace/public/pm/metric-drafts.js +165 -0
- package/workspace/public/pm/ms-suggest.css +8 -8
- package/workspace/public/pm/ov-view.css +12 -12
- package/workspace/public/pm/premium-chart-tab.js +6 -6
- package/workspace/public/pm/premium-insights.js +298 -107
- package/workspace/public/pm/premium-report-intel.css +56 -0
- package/workspace/public/pm/premium-report-intel.js +232 -0
- package/workspace/public/pm/premium-shell.js +2 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium.css +127 -128
- package/workspace/public/pm/prog-order.css +6 -6
- package/workspace/public/pm/program-charter.css +23 -23
- package/workspace/public/pm/rp-parts.js +2 -2
- package/workspace/public/pm/sort-order.css +1 -1
- package/workspace/public/pm/split-merge.css +15 -15
- package/workspace/public/pm/task-card.css +21 -21
- package/workspace/public/pm/tk-tasks.css +37 -37
- package/workspace/public/pm/tk-view.css +6 -6
- package/workspace/public/pm/wf-page.css +28 -28
- package/workspace/public/premium-intelligence.html +82 -0
- package/workspace/server.js +38 -3
- package/workspace/skills/metric-draft.skill +47 -0
- package/workspace/test-lists/intel-report-ui.json +5 -0
- package/workspace/test-lists/intel-report.json +9 -0
- package/workspace/test-lists/metric-drafts-ui.json +5 -0
- package/workspace/test-lists/metric-drafts.json +9 -0
- package/workspace/test-run.js +3 -0
- package/workspace/public/premium-insights.html +0 -81
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-metric-drafts.js — the metrics Claude drafts without being asked (batch 15 item 1; contract metric-drafts-contract.md). The fold is
|
|
3
|
+
* lib/metric-drafts.js; the runs are lib/metric-draft-runs.js (ctx.metricDraftRuns). Only the PM's ✓ keep writes: one kr-metrics record
|
|
4
|
+
* (planning/records/kr-metrics.jsonl through scripts/records, the workspace's folder from lib/records-dir.js).
|
|
5
|
+
*
|
|
6
|
+
* GET /api/metric-drafts?ws=&scope=&id= → { ok, scope, id, title, when, run: { state: idle|running|ready|failed|off, step, reads },
|
|
7
|
+
* rows, head, sub, src } rows [] and run.state idle when nothing is drafted
|
|
8
|
+
* POST /api/metric-drafts/keep { ws, scope, id, row } → { ok, rid } ✓ one row: the record and, when now is known, one reading
|
|
9
|
+
* POST /api/metric-drafts/keep-all { ws, scope, id } → { ok, kept: n, failed } ✓ every open row
|
|
10
|
+
* POST /api/metric-drafts/drop { ws, scope, id, row } → { ok } ✕
|
|
11
|
+
* POST /api/metric-drafts/undo { ws, scope, id, row } → { ok } kept → open (its record edited { retired: true }); dropped → open
|
|
12
|
+
* POST /api/metric-drafts/start { ws, scope, id } → { ok, run } Draft again
|
|
13
|
+
* POST /api/metric-drafts/stop { ws, scope, id } → { ok } ■ Stop: the run ends; what it filed stays a draft
|
|
14
|
+
*
|
|
15
|
+
* WHICH LEDGER. A product's and an initiative's drafts are in the state folder of `ws`. A program's are in its charter's workspace (its home,
|
|
16
|
+
* lib/routes-programs.js all), whatever `ws` says, so a program reads the same from every product.
|
|
17
|
+
*
|
|
18
|
+
* WHO WRITES. As routes-premium-dashboards.js: a POST that carries an agent session header is refused (403), and pm-guard requirePagePress
|
|
19
|
+
* checks the launch nonce and the page's origin. With no state folder the read answers nothing and every write answers 409.
|
|
20
|
+
*
|
|
21
|
+
* wsFor(ctx, ws, scope, id) → the workspace whose ledger holds the scope, or null */
|
|
22
|
+
const guard = require('./pm-guard.js');
|
|
23
|
+
const MD = require('./metric-drafts.js');
|
|
24
|
+
const Runs = require('./metric-draft-runs.js');
|
|
25
|
+
const { repoScript } = require('./repo-script.js');
|
|
26
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
27
|
+
|
|
28
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
29
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
30
|
+
const records = () => require(repoScript('records/index.js'));
|
|
31
|
+
const UI = () => require(repoScript('trust/ledger.js')).actorFrom({ ui: true });
|
|
32
|
+
const NO_STATE = 'This repository has no PMOS state folder (pmos/state, state or .pmos). Nothing is saved until the folder exists.';
|
|
33
|
+
const todayIso = () => { const d = new Date(); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
34
|
+
const dirOf = (ctx, w) => { try { return ctx.stateDirFor ? ctx.stateDirFor(w) : null; } catch { return null; } };
|
|
35
|
+
|
|
36
|
+
function wsFor(ctx, ws, scope, id) {
|
|
37
|
+
let w = null;
|
|
38
|
+
try { w = ctx.getWs(ws || null); } catch { w = null; }
|
|
39
|
+
if (ws && w && w.id !== ws) w = null;
|
|
40
|
+
if (scope === 'program') {
|
|
41
|
+
try {
|
|
42
|
+
const p = require('./routes-programs.js').all(ctx).find((x) => x.id === id);
|
|
43
|
+
const list = (ctx.workspaceList ? ctx.workspaceList() : []) || [];
|
|
44
|
+
const home = p && list.find((x) => x.id === p.home);
|
|
45
|
+
if (home) return home;
|
|
46
|
+
} catch { /* the programs could not be read: the ledger of `ws` */ }
|
|
47
|
+
}
|
|
48
|
+
return w;
|
|
49
|
+
}
|
|
50
|
+
const offNow = (ctx) => Runs.off(ctx.env || process.env);
|
|
51
|
+
const viewFor = (ctx, w, scope, id) => { const dir = dirOf(ctx, w); return MD.viewOf(dir ? MD.read(dir) : null, scope, id, { off: offNow(ctx) }); };
|
|
52
|
+
|
|
53
|
+
async function handle(req, res, url, ctx) {
|
|
54
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
55
|
+
const what = url.pathname.replace(/^\/api\/metric-drafts\/?/, '');
|
|
56
|
+
if (what === '') {
|
|
57
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
58
|
+
const scope = url.searchParams.get('scope') || '', id = url.searchParams.get('id') || '', ws = url.searchParams.get('ws') || '';
|
|
59
|
+
if (!MD.SCOPES.includes(scope)) return send(bad(400, 'scope is product, program or initiative'));
|
|
60
|
+
const w = wsFor(ctx, ws, scope, id || ws);
|
|
61
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
62
|
+
const sid = scope === 'product' ? (id || w.id) : id;
|
|
63
|
+
if (!sid) return send(bad(400, 'id names the program or the initiative'));
|
|
64
|
+
return send({ status: 200, body: { ok: true, ...viewFor(ctx, w, scope, sid) } });
|
|
65
|
+
}
|
|
66
|
+
if (!['keep', 'keep-all', 'drop', 'undo', 'start', 'stop'].includes(what)) return send(bad(404, 'no such metric-drafts route'));
|
|
67
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
68
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'Only the PM keeps, drops or starts a draft, from the page. A run files drafts with pmos metrics draft.'));
|
|
69
|
+
const read = await ctx.readJson(req);
|
|
70
|
+
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
71
|
+
const body = read.body || {};
|
|
72
|
+
const g = guard.requirePagePress(req, body);
|
|
73
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
74
|
+
const scope = text(body.scope);
|
|
75
|
+
if (!MD.SCOPES.includes(scope)) return send(bad(400, 'scope is product, program or initiative'));
|
|
76
|
+
const w = wsFor(ctx, text(body.ws), scope, text(body.id));
|
|
77
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
78
|
+
const id = scope === 'product' ? (text(body.id) || w.id) : text(body.id);
|
|
79
|
+
if (!id) return send(bad(400, 'id names the program or the initiative'));
|
|
80
|
+
if (scope === 'product' && id !== w.id) return send(bad(400, 'A product\'s id is its workspace id.'));
|
|
81
|
+
const dir = dirOf(ctx, w);
|
|
82
|
+
if (!dir) return send(bad(409, NO_STATE));
|
|
83
|
+
const at = () => new Date().toISOString();
|
|
84
|
+
const S = () => MD.read(dir).scopes.get(MD.keyOf(scope, id));
|
|
85
|
+
|
|
86
|
+
if (what === 'start') {
|
|
87
|
+
if (!ctx.metricDraftRuns) return send(bad(503, 'Claude\'s runs are off on this server.'));
|
|
88
|
+
const r = ctx.metricDraftRuns.start({ ws: w.id, scope, id, why: 'press' });
|
|
89
|
+
if (!r || !r.ok) return send(bad(409, (r && r.error) || 'Claude could not start drafting.'));
|
|
90
|
+
return send({ status: 200, body: { ok: true, run: r.run } });
|
|
91
|
+
}
|
|
92
|
+
if (what === 'stop') {
|
|
93
|
+
const s = S();
|
|
94
|
+
if (!s || !s.run || s.run.ended) return send(bad(409, 'Claude is not drafting now.'));
|
|
95
|
+
try { if (ctx.metricDraftRuns) ctx.metricDraftRuns.stop(s.run.run); } catch { /* the end line below says it stopped */ }
|
|
96
|
+
MD.append(dir, g.actor, { kind: 'end', scope, id, run: s.run.run, ok: true, stopped: true }, at());
|
|
97
|
+
return send({ status: 200, body: { ok: true } });
|
|
98
|
+
}
|
|
99
|
+
const s = S();
|
|
100
|
+
const root = recordsDirFor(ctx, w.id), today = todayIso();
|
|
101
|
+
const keepOne = (row) => {
|
|
102
|
+
const k = MD.keepFields(scope, id, row, { today });
|
|
103
|
+
if (k.error) return { error: k.error };
|
|
104
|
+
let r;
|
|
105
|
+
try { r = records().add(root, 'kr-metrics', k.fields, UI(), 'Kept a metric Claude drafted'); } catch (e) { return { error: 'The record could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
106
|
+
if (!r.ok) return { error: r.reasons.join('; ') };
|
|
107
|
+
if (k.reading) { try { records().addReading(root, r.rid, k.reading, UI(), 'The reading Claude drafted it from'); } catch { /* the record stands; the next reading fills it */ } }
|
|
108
|
+
MD.append(dir, g.actor, { kind: 'keep', scope, id, row: row.id, rid: r.rid }, at());
|
|
109
|
+
return { rid: r.rid };
|
|
110
|
+
};
|
|
111
|
+
if (what === 'keep-all') {
|
|
112
|
+
const open = s ? [...s.rows.values()].filter((r) => r.state === 'open') : [];
|
|
113
|
+
if (!open.length) return send(bad(409, 'There is nothing open to keep.'));
|
|
114
|
+
let kept = 0; const failed = [];
|
|
115
|
+
for (const row of open) { const r = keepOne(row); if (r.rid) kept++; else failed.push({ row: row.id, error: r.error }); }
|
|
116
|
+
return send(kept ? { status: 200, body: { ok: true, kept, failed } } : bad(400, failed[0].error));
|
|
117
|
+
}
|
|
118
|
+
const row = s && s.rows.get(text(body.row));
|
|
119
|
+
if (!row) return send(bad(404, 'There is no such draft.'));
|
|
120
|
+
if (what === 'keep') {
|
|
121
|
+
if (row.state !== 'open') return send(bad(409, row.state === 'kept' ? 'You kept it already.' : 'You dropped it. Undo first.'));
|
|
122
|
+
const r = keepOne(row);
|
|
123
|
+
return send(r.rid ? { status: 200, body: { ok: true, rid: r.rid } } : bad(400, r.error));
|
|
124
|
+
}
|
|
125
|
+
if (what === 'drop') {
|
|
126
|
+
if (row.state !== 'open') return send(bad(409, row.state === 'kept' ? 'You kept it. Undo it first.' : 'You dropped it already.'));
|
|
127
|
+
MD.append(dir, g.actor, { kind: 'drop', scope, id, row: row.id }, at());
|
|
128
|
+
return send({ status: 200, body: { ok: true } });
|
|
129
|
+
}
|
|
130
|
+
// undo: a kept row's record is retired (readers skip it), a dropped row comes back
|
|
131
|
+
if (row.state === 'open') return send(bad(409, 'There is nothing to undo.'));
|
|
132
|
+
if (row.state === 'kept' && row.rid) {
|
|
133
|
+
let e;
|
|
134
|
+
try { e = records().edit(root, 'kr-metrics', row.rid, { retired: true }, UI(), 'Undo of a kept draft'); } catch (x) { e = { ok: false, reasons: [String((x && x.message) || x).slice(0, 160)] }; }
|
|
135
|
+
if (!e.ok && !(e.reasons || []).some((m) => /no such record/.test(m))) return send(bad(400, 'The record could not be retired: ' + (e.reasons || []).join('; ')));
|
|
136
|
+
}
|
|
137
|
+
MD.append(dir, g.actor, { kind: 'undo', scope, id, row: row.id, ...(row.rid ? { rid: row.rid } : {}) }, at());
|
|
138
|
+
return send({ status: 200, body: { ok: true } });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
module.exports = { prefixes: ['/api/metric-drafts'], handle, wsFor };
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* text, sub }: the confirmed decisions first, then the items done, then the drafts.
|
|
15
15
|
* tomorrow end of the day: the next working day (Monday to Friday) and its meetings, in the shape of GET /api/brief-page today[] rows
|
|
16
16
|
* (routes-brief-page.js todayAgenda), so the companion opens their briefs the same way.
|
|
17
|
+
* run today's morning prep run (Prepare my day), or null when there is none: { started_at, working, failed: [{ id, title, error }] }.
|
|
18
|
+
* working counts the tasks still waiting, working or sending; failed are the tasks the agent could not finish (at most 3).
|
|
19
|
+
* Your day (batch 15 item 3) says "My part's done" only when working is 0, and names each failed task as Claude's own miss.
|
|
17
20
|
* A private note is never read. A file that is missing or unreadable counts as empty. */
|
|
18
21
|
const fs = require('fs');
|
|
19
22
|
const path = require('path');
|
|
@@ -46,6 +49,14 @@ function finishedOf(run) {
|
|
|
46
49
|
.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')));
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
/** Today's run as Your day reads it: what is still under way and what failed. Null when there is no run. */
|
|
53
|
+
function runOf(run) {
|
|
54
|
+
if (!run || !Array.isArray(run.tasks)) return null;
|
|
55
|
+
const T = run.tasks.filter(Boolean);
|
|
56
|
+
return { started_at: run.started_at || null, working: T.filter((t) => ['waiting', 'working', 'sending'].includes(t.status)).length,
|
|
57
|
+
failed: T.filter((t) => t.status === 'failed').slice(0, 3).map((t) => ({ id: t.id, title: clip(t.title, 200), error: clip(t.error, 200) })) };
|
|
58
|
+
}
|
|
59
|
+
|
|
49
60
|
/** deps: { events, items, run, notes: [note with final_notes], adapter, points: (noteId) → { [pointId]: 'confirmed' | 'wrong' } }
|
|
50
61
|
* notes are today's non-private notes, read in full. A decision's point id is the Replay's (lib/meeting-replay.js): d1, d2, … in caughtOf order. */
|
|
51
62
|
function build(query, deps = {}) {
|
|
@@ -71,7 +82,7 @@ function build(query, deps = {}) {
|
|
|
71
82
|
...finished.map((t) => ({ kind: 'agent', text: clip(t.title, 200), sub: t.status === 'review' ? 'Drafted by the agent; it waits for you' : 'Finished by the agent' }))].slice(0, 5);
|
|
72
83
|
const tm = nextWorkday(now);
|
|
73
84
|
return { status: 200, body: {
|
|
74
|
-
ok: true, date: today, finished,
|
|
85
|
+
ok: true, date: today, finished, run: runOf(deps.run),
|
|
75
86
|
recap: { meetings: agenda.filter((m) => Date.parse(m.end || m.start) <= now.getTime()).length, decided: decisions.length, to_confirm: toConfirm, done: done.length, finished: finished.length, moved },
|
|
76
87
|
tomorrow: { date: localDate(tm), label: WD[tm.getDay()] + ' ' + tm.getDate() + ' ' + MO[tm.getMonth()], meetings: todayAgenda(events, items, tm, deps.adapter || {}) },
|
|
77
88
|
} };
|
|
@@ -93,7 +104,7 @@ function readRun(dir, date) {
|
|
|
93
104
|
|
|
94
105
|
module.exports = {
|
|
95
106
|
prefixes: ['/api/phone-day'],
|
|
96
|
-
build, finishedOf, nextWorkday,
|
|
107
|
+
build, finishedOf, nextWorkday, runOf,
|
|
97
108
|
handle: async (req, res, url, ctx) => {
|
|
98
109
|
if (url.pathname !== '/api/phone-day') return false;
|
|
99
110
|
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
* POST /api/report-setups/remove { ws, id } → { ok } delete a TEMPLATE: its schedule stops; its drafts and issued reports stay (L2)
|
|
20
20
|
* POST /api/report-setups/from-dashboard { ws, key, name, output, schedule, audience } → { ok, setup }
|
|
21
21
|
* POST /api/report-setups/finder { ws, cadence?, sources? } → { ok, finder }
|
|
22
|
+
* GET /api/report-setups/storyline?ws&board&scope&story? → { ok, storyline, defaults, checks, proposals } a report from Intelligence (batch 15 item 4,
|
|
23
|
+
* lib/intel-report.js): the draft the side panel opens on, who reads it / how often / the format from history,
|
|
24
|
+
* the five checks on the draft as `story` (the PM's edits, JSON) leaves it, and the ✦ strip's proposals
|
|
25
|
+
* POST /api/report-setups/setup { ws, source: 'intelligence', scope, board?, name, audience, output, schedule, storyline } → as above: sets up a
|
|
26
|
+
* report from Intelligence and drafts issue 1 from the live model (source intelligence:<scope>)
|
|
27
|
+
* POST /api/report-setups/strip-dismiss { ws, id } → { ok } Not now on a report the ✦ strip proposed
|
|
22
28
|
* GET /api/report-documents?ws → { docs: [{ path, id, setup, name, slot, state: draft|issued, source, output, made_by: schedule|you|agent, v, copy }] }
|
|
23
29
|
* POST /api/report-documents/discard { ws, path } → { ok, doc } delete an UNISSUED draft; an issued report is 409 and untouched (L3)
|
|
24
30
|
* POST /api/report-documents/archive { ws, path, archived } → { ok, doc, archived } hide (or bring back) an ISSUED report; a draft is 409 (L4)
|
|
@@ -54,7 +60,8 @@ const headless = require('./headless.js');
|
|
|
54
60
|
|
|
55
61
|
const text = (v) => (typeof v === 'string' ? v : '');
|
|
56
62
|
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
57
|
-
const POSTS = ['ask', 'change', 'cancel', 'setup', 'draft', 'dismiss', 'pause', 'resume', 'from-dashboard', 'finder', 'edit', 'remove', 'documents/discard', 'documents/archive'];
|
|
63
|
+
const POSTS = ['ask', 'change', 'cancel', 'setup', 'draft', 'dismiss', 'pause', 'resume', 'from-dashboard', 'finder', 'edit', 'remove', 'documents/discard', 'documents/archive', 'strip-dismiss'];
|
|
64
|
+
const IR = require('./intel-report.js');
|
|
58
65
|
const MADE_BY = ['schedule', 'you', 'agent'];
|
|
59
66
|
|
|
60
67
|
const runs = new Map(); // ask id → session id, for the report-setup runs this server started
|
|
@@ -144,6 +151,7 @@ function setupOut(s, now, docsOf, idx, root, draft) {
|
|
|
144
151
|
if (s.status === 'active') { try { const n = RS.nextDraftAt(s.schedule, s.last_run, now); next = n ? n.toISOString() : null; } catch { next = null; } }
|
|
145
152
|
return {
|
|
146
153
|
id: s.id, name: s.name, purpose: s.purpose, audience: s.audience, source: s.source, output: s.output, schedule: s.schedule, label: RS.scheduleLabel(s.schedule),
|
|
154
|
+
...(IR.isIntelligence(s.source) ? { scope: IR.scopeOf(s.source), storyline: s.storyline || {} } : {}),
|
|
147
155
|
next_draft: next, last_issued: issued, status: s.status, cycles: mine.length,
|
|
148
156
|
copy: copyOf(latest ? linkFor(idx, latest.path, s.output) : null, docSync.copyKindOf(s.output)),
|
|
149
157
|
structure: structureOf(root, s.id),
|
|
@@ -231,7 +239,7 @@ async function tick(ctx, now = new Date()) {
|
|
|
231
239
|
let st;
|
|
232
240
|
try { st = RS.stateOf(w.root); } catch { continue; }
|
|
233
241
|
for (const s of st.setups.values()) {
|
|
234
|
-
if (s.status !== 'active' || !String(s.source).startsWith('dashboard:')) continue;
|
|
242
|
+
if (s.status !== 'active' || !(String(s.source).startsWith('dashboard:') || IR.isIntelligence(s.source))) continue;
|
|
235
243
|
const sched = RS.scheduleOf(s);
|
|
236
244
|
if (!logic.isDue(sched, now)) continue;
|
|
237
245
|
const slotAt = logic.lastSlot(sched, now);
|
|
@@ -239,6 +247,11 @@ async function tick(ctx, now = new Date()) {
|
|
|
239
247
|
const slot = RS.localDay(slotAt);
|
|
240
248
|
if (s.drafted.some((d) => d.slot === slot)) continue;
|
|
241
249
|
let out;
|
|
250
|
+
if (IR.isIntelligence(s.source)) {
|
|
251
|
+
try { out = await draftIntelligence({ ...ctx, getWs: (id) => (id === w.id || id == null ? w : ctx.getWs(id)) }, w, s, slot, { now }); } catch (e) { out = { ok: false, error: String((e && e.message) || e) }; }
|
|
252
|
+
done.push({ id: s.id, slot, ...out });
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
242
255
|
try {
|
|
243
256
|
const c3 = require('./routes-c3-reports.js');
|
|
244
257
|
const deps = await c3.depsFor({ ...ctx, getWs: (id) => (id === w.id || id == null ? w : ctx.getWs(id)) }, w.id);
|
|
@@ -285,6 +298,25 @@ async function handle(req, res, url, ctx) {
|
|
|
285
298
|
const docPost = p === '/api/report-documents/discard' || p === '/api/report-documents/archive';
|
|
286
299
|
const sub = docPost ? p.replace(/^\/api\/report-/, '') : isDocs ? 'documents' : isExport ? 'export' : p.replace(/^\/api\/report-setups\/?/, '');
|
|
287
300
|
|
|
301
|
+
if (sub === 'storyline') {
|
|
302
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
303
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
304
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
305
|
+
const scope = text(url.searchParams.get('scope')) || 'view';
|
|
306
|
+
if (!IR.SCOPE_RE.test(scope)) return send(bad(400, 'scope is view, dashboard:<id>, goal:<id> or outcome:<id>'));
|
|
307
|
+
const m = await intelModel(req, ctx, w.id, url.searchParams.get('board'));
|
|
308
|
+
if (!m) return send(bad(500, 'Intelligence could not be read, so there is no draft.'));
|
|
309
|
+
const st = RS.fold(RS.readLines(RS.ledgerFile(w.root)));
|
|
310
|
+
const findings = RS.openFindings(st);
|
|
311
|
+
// ?story= the PM's edits so far ({ answer, ask, items }): the draft is redrawn with them and the five checks run on that preview
|
|
312
|
+
let story = {};
|
|
313
|
+
if (url.searchParams.get('story')) { let raw = null; try { raw = JSON.parse(url.searchParams.get('story')); } catch { raw = null; } const c = IR.checkStoryline(raw); if (!c.ok) return send(bad(400, c.error)); story = c.storyline; }
|
|
314
|
+
const S = IR.storylineOf(m, { scope, ask: story.ask, items: story.items });
|
|
315
|
+
if (story.answer) S.answer = story.answer;
|
|
316
|
+
const defaults = IR.defaultsOf(findings, scope, S.name);
|
|
317
|
+
const preview = IR.documentOf(m, { id: 'preview', name: S.name, audience: defaults.audience, output: defaults.output, source: IR.sourceOf(scope), storyline: story }, { slot: m.today, issue: 1 });
|
|
318
|
+
return send({ status: 200, body: { ok: true, storyline: S, defaults, checks: IR.storyChecks(preview), proposals: IR.proposalsOf(m, { findings, dismissed: [...st.stripDismissed] }), as_of: m.today } });
|
|
319
|
+
}
|
|
288
320
|
if (!docPost && (isDocs || isExport || (sub === '' && req.method === 'GET'))) {
|
|
289
321
|
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
290
322
|
if ((isDocs && p !== '/api/report-documents') || (isExport && p !== '/api/report-export')) return send(bad(404, 'no such report route'));
|
|
@@ -346,6 +378,30 @@ async function handle(req, res, url, ctx) {
|
|
|
346
378
|
if (sid && typeof ctx.stopSession === 'function') { try { ctx.stopSession(sid); } catch { /* the run ends by itself */ } }
|
|
347
379
|
return send({ status: 200, body: { ok: true } });
|
|
348
380
|
}
|
|
381
|
+
if (sub === 'setup' && body.source === 'intelligence') {
|
|
382
|
+
const scope = text(body.scope) || 'view';
|
|
383
|
+
if (!IR.SCOPE_RE.test(scope)) return send(bad(400, 'scope is view, dashboard:<id>, goal:<id> or outcome:<id>'));
|
|
384
|
+
const m = await intelModel(req, ctx, w.id, text(body.board) || null);
|
|
385
|
+
if (!m) return send(bad(500, 'Intelligence could not be read, so nothing was set up.'));
|
|
386
|
+
const name = text(body.name).trim() || IR.scopeName(m, scope);
|
|
387
|
+
const audience = text(body.audience).trim();
|
|
388
|
+
if (!audience) return send(bad(400, 'say who reads it'));
|
|
389
|
+
const finding = text(body.finding) ? RS.lookupFinding(RS.fold(RS.readLines(file)), text(body.finding)) : null;
|
|
390
|
+
const proposal = { name, purpose: `${name} from Intelligence for ${audience}: the answer first, the scorecard, and what needs a decision.`, audience, source: IR.sourceOf(scope),
|
|
391
|
+
output: text(body.output) || 'pdf', schedule: body.schedule, sources: [`Intelligence · ${IR.scopeName(m, scope)}`], sections: RS.FRAME.slice(), learned_from: 'Set up from Intelligence.', fixes: [],
|
|
392
|
+
storyline: body.storyline || {}, ...(finding && finding.ok ? { from: { finding: finding.finding.id } } : {}) };
|
|
393
|
+
const r = RS.setUp(root, proposal, opts);
|
|
394
|
+
if (!r.ok) return fail(r);
|
|
395
|
+
let drafted = { error: 'no first draft day' };
|
|
396
|
+
if (r.first_draft) { try { drafted = await draftIntelligence(ctx, w, r.setup, r.first_draft.slot, { model: m, now: new Date() }); } catch (e) { drafted = { error: String((e && e.message) || e) }; } }
|
|
397
|
+
if (drafted.path && ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg();
|
|
398
|
+
return send({ status: 200, body: { ok: true, setup: setupOut(r.setup, new Date(), documentsOf(ctx, w), copyIndex(root), root), first_draft: r.first_draft, drafted } });
|
|
399
|
+
}
|
|
400
|
+
if (sub === 'strip-dismiss') {
|
|
401
|
+
const r = RS.stripDismiss(file, { id: text(body.id), by: g.actor });
|
|
402
|
+
if (!r.ok) return fail(r);
|
|
403
|
+
return send({ status: 200, body: { ok: true } });
|
|
404
|
+
}
|
|
349
405
|
if (sub === 'setup') {
|
|
350
406
|
const st = RS.fold(RS.readLines(file));
|
|
351
407
|
let from = null; let base = null;
|
|
@@ -371,6 +427,14 @@ async function handle(req, res, url, ctx) {
|
|
|
371
427
|
// Draft it now: the next cycle of a set-up report, written at the slot of its next scheduled draft. A page write, like Draft now on the report.
|
|
372
428
|
const s = RS.fold(RS.readLines(file)).setups.get(text(body.id));
|
|
373
429
|
if (!s || s.status === 'removed') return send(bad(404, 'no such report'));
|
|
430
|
+
if (IR.isIntelligence(s.source)) {
|
|
431
|
+
let next = null; try { next = RS.nextDraftAt(s.schedule, s.last_run, new Date()); } catch { next = null; }
|
|
432
|
+
if (!next) return send(bad(400, 'this report has no next draft day'));
|
|
433
|
+
const d = await draftIntelligence(ctx, w, s, RS.localDay(next), { now: new Date() });
|
|
434
|
+
if (!d.ok && !d.existing) return send(bad(d.status || 500, 'the draft was not written: ' + d.error));
|
|
435
|
+
if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg();
|
|
436
|
+
return send({ status: 200, body: { ok: true, drafted: { slot: d.slot, path: d.path, existing: !!d.existing }, id: s.id + '/' + d.slot } });
|
|
437
|
+
}
|
|
374
438
|
if (s.source !== 'work') return send(bad(400, 'a dashboard report is drafted from its dashboard on its day'));
|
|
375
439
|
let next = null; try { next = RS.nextDraftAt(s.schedule, s.last_run, new Date()); } catch { next = null; }
|
|
376
440
|
const day = next ? `${next.getFullYear()}-${String(next.getMonth() + 1).padStart(2, '0')}-${String(next.getDate()).padStart(2, '0')}` : null; // the local day, as setUp names a slot
|
|
@@ -435,6 +499,31 @@ async function handle(req, res, url, ctx) {
|
|
|
435
499
|
return send(bad(404, 'no such report route'));
|
|
436
500
|
}
|
|
437
501
|
|
|
502
|
+
/** The Intelligence model, through its page's own read (as lib/routes-insights-records.js does), so a report says what the page shows. null when it cannot be read. */
|
|
503
|
+
async function intelModel(req, ctx, ws, board) {
|
|
504
|
+
let out = null;
|
|
505
|
+
const c = Object.assign({}, ctx, { json: (res, obj) => { out = obj; } });
|
|
506
|
+
const u = new URL('http://local/api/insights-premium?' + new URLSearchParams(Object.entries({ ws, board }).filter(([, v]) => v)).toString());
|
|
507
|
+
try { await require('./routes-insights-premium.js').handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, u, c); } catch { return null; }
|
|
508
|
+
return out && out.ok ? out.model : null;
|
|
509
|
+
}
|
|
510
|
+
/** Draft one issue of a report from Intelligence at `slot` (lib/intel-report.js documentOf). The issue number counts the documents before it; the issue
|
|
511
|
+
* before it (the latest issued one) gives Actions from issue N and Since issue N. A document already at the slot is the answer and is not overwritten.
|
|
512
|
+
* → { ok, slot, path } | { ok: false, existing?, error } */
|
|
513
|
+
async function draftIntelligence(ctx, w, s, slot, { model, now = new Date() } = {}) {
|
|
514
|
+
const rel = RD.draftPath(path.resolve(w.root), s.id, slot);
|
|
515
|
+
try { if (fs.statSync(path.join(path.resolve(w.root), rel)).isFile()) return { ok: false, existing: true, slot, path: rel, error: 'drafted already' }; } catch { /* not there yet */ }
|
|
516
|
+
const m = model || await intelModel(null, ctx, w.id, null);
|
|
517
|
+
if (!m) return { ok: false, error: 'Intelligence could not be read' };
|
|
518
|
+
const mine = (RN.reportsOf(w.root).reports || []).filter((x) => x.cadence === s.id && x.slot < slot).sort((a, b) => (a.slot < b.slot ? -1 : 1));
|
|
519
|
+
const before = mine.filter((x) => x.issued).pop() || null;
|
|
520
|
+
let prior = null;
|
|
521
|
+
if (before) { try { prior = fs.readFileSync(path.join(path.resolve(w.root), before.path), 'utf8'); } catch { prior = null; } }
|
|
522
|
+
const md = IR.documentOf(m, s, { slot, now, issue: mine.length + 1, prior });
|
|
523
|
+
const r = RS.writeDocument(w.root, s, slot, md, { now });
|
|
524
|
+
return r.ok ? { ok: true, slot, path: r.path } : { ok: false, status: r.status, error: r.error };
|
|
525
|
+
}
|
|
526
|
+
|
|
438
527
|
/** Draft a report's cycle now through the one writer (report-draft.js writeDraft). → { slot, path } | { error } */
|
|
439
528
|
function draftCycle(root, cadence, slot, actor) {
|
|
440
529
|
const d = RD.draftOf(root, { cadence, slot: slot || undefined });
|
|
@@ -450,4 +539,4 @@ function firstDraft(root, r, actor) {
|
|
|
450
539
|
return draftCycle(root, r.setup.id, r.first_draft && r.first_draft.slot, actor);
|
|
451
540
|
}
|
|
452
541
|
|
|
453
|
-
module.exports = { prefixes: ['/api/report-setups', '/api/report-documents', '/api/report-export'], handle, tick, ensureMigrated, documentsOf, listAnswer, copyOf };
|
|
542
|
+
module.exports = { prefixes: ['/api/report-setups', '/api/report-documents', '/api/report-export'], handle, tick, ensureMigrated, documentsOf, listAnswer, copyOf, draftIntelligence, intelModel };
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* POST /api/viewer-meeting/work-item { note, step: { text, owner?, due? } } → { ok, ticket, created }
|
|
12
12
|
* A next step becomes a ticket Drafted in PMOS on the note's initiative (lib/jira-tickets.js's draft file). It is not approved and not pushed:
|
|
13
13
|
* only the Commit gate pushes a ticket to Jira.
|
|
14
|
-
* GET /api/viewer-report/checks?ws=&path=&slot= → { ok, checks: [{ id, ok, text }] } the three checks before Issue (lib/viewer-report.js)
|
|
14
|
+
* GET /api/viewer-report/checks?ws=&path=&slot= → { ok, checks: [{ id, ok, text }] } the three checks before Issue (lib/viewer-report.js); five for a
|
|
15
|
+
* report made from Intelligence (lib/intel-report.js storyChecks)
|
|
15
16
|
* Every POST is a page press (lib/pm-guard.js requirePagePress). Handlers are pure over (q | body, ctx) so a test needs no server. */
|
|
16
17
|
const fs = require('fs');
|
|
17
18
|
const path = require('path');
|
|
@@ -84,7 +85,9 @@ function checks(q, ctx) {
|
|
|
84
85
|
let text = '';
|
|
85
86
|
try { text = fs.readFileSync(full, 'utf8'); } catch { return fail(404, 'the report file could not be read'); }
|
|
86
87
|
const slot = str(q.slot, 10) || ((/(\d{4}-\d{2}-\d{2})\.md$/.exec(rel) || [])[1] || '');
|
|
87
|
-
|
|
88
|
+
// A report made from Intelligence (batch 15 item 4) is checked as a story: the five checks before it goes out (lib/intel-report.js storyChecks).
|
|
89
|
+
const IR = require('./intel-report.js'), src = (/^---\r?\n[\s\S]*?^source:\s*(\S+)/m.exec(text) || [])[1];
|
|
90
|
+
return okBody({ checks: IR.isIntelligence(src) ? IR.storyChecks(text) : VR.issueChecks(text, { slot }) });
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* metric-drafts-ui-test.js — the metrics Claude drafts, as the program panel and the initiative view show them (feedback batch 15 item 1;
|
|
4
|
+
* canvas Iq9Program, Iq9Initiative). Serves the real Board page from the real server; Project Ascent comes from fixtures/program-ascent.js, and
|
|
5
|
+
* GET /api/metric-drafts and its POSTs are stubbed here in the contract's shape (keep-all marks every open row kept, undo puts one back).
|
|
6
|
+
* P the program's proposed goal leads the panel: the goal line, checkpoint chips, Built from with the drafted ticket as a pill, one line of
|
|
7
|
+
* why; Discuss in Home, Edit and ✓ are icon-only with a label · K ✓ keeps all; the Goal row of chips with a dot (ok, off) and Undo ·
|
|
8
|
+
* U Undo makes it a proposal again · Z nothing drafted, nothing shown · I the initiative at Discover: the proposed success measure under
|
|
9
|
+
* the stage card, Proves it worked, Early signal and Guardrail as Now → Target; ✓ keeps all; the folded "Success measure · Set before the
|
|
10
|
+
* build · 3" with Undo · S the type scale only · H on a phone. PMOS_SHOTS=<dir> also saves the screenshots. */
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const { spawn } = require('child_process');
|
|
14
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
15
|
+
const T = require('./test-run').configure({ name: 'metric-drafts-ui' });
|
|
16
|
+
const BP = require('./lib/board-premium.js');
|
|
17
|
+
const F = require('./fixtures/board-premium-facts.js');
|
|
18
|
+
const A = require('./fixtures/program-ascent.js');
|
|
19
|
+
|
|
20
|
+
const BASE = T.BASE;
|
|
21
|
+
const SHOTS = process.env.PMOS_SHOTS || '';
|
|
22
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
23
|
+
const until = async (fn, ms = 10000, step = 100) => { const t0 = Date.now(); for (;;) { let v; try { v = await fn(); } catch { v = null; } if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
24
|
+
const results = [];
|
|
25
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 700) : ''}`); };
|
|
26
|
+
let srv = null; let browser = null;
|
|
27
|
+
const finish = async (code) => {
|
|
28
|
+
if (browser) await browser.close().catch(() => {});
|
|
29
|
+
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
30
|
+
T.killTmux();
|
|
31
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
32
|
+
console.log(`\n${results.length - bad}/${results.length} metric-drafts-ui assertions passed`);
|
|
33
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
34
|
+
};
|
|
35
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
36
|
+
|
|
37
|
+
/* the drafts, in the contract's row shape (metric-drafts-contract.md) */
|
|
38
|
+
const PROGRAM = () => ({
|
|
39
|
+
title: 'Project Ascent', src: 'from the charter and its 3 initiatives', sub: '',
|
|
40
|
+
rows: [
|
|
41
|
+
{ id: 'g', group: 'Program goal', name: 'Sign-ins on CIAM, all products', type: 'Percentage', now: 12, nowTxt: '12%', target: 100, targetTxt: '100%', by: '2028-06-30',
|
|
42
|
+
why: 'idpf is 80% of all sign-ins, so it carries the goal. I check it every morning once you keep it.', source: 'Amplitude', ticket: null,
|
|
43
|
+
checkpoints: [{ by: '2027-02-27', target: 40, label: 'Legacy IdP off' }, { by: '2027-03-20', target: 85, label: 'All microsites' }], state: 'open' },
|
|
44
|
+
{ id: 'r1', group: 'Rolls up from', name: 'idpf · sign-ins on CIAM', type: 'Percentage', now: 15, nowTxt: '15%', target: 100, targetTxt: '100%', by: '2027-02-27', why: '', source: 'Amplitude', ticket: null, state: 'open' },
|
|
45
|
+
{ id: 'r2', group: 'Rolls up from', name: 'Microsites · sign-ins on CIAM', type: 'Percentage', now: null, nowTxt: '', target: 100, targetTxt: '100%', by: '2027-03-20', why: 'No event counts it yet.', source: '', ticket: { key: 'MS-212', text: 'MS-212 drafted' }, state: 'open' },
|
|
46
|
+
{ id: 'gr', group: 'Guardrail', name: 'Sign-in success', type: 'Stay within', now: 99.6, nowTxt: '99.6%', target: 99, targetTxt: 'stays above 99%', by: null, why: '', source: 'Amplitude', ticket: null, state: 'open' },
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
const INITIATIVE = () => ({
|
|
50
|
+
title: 'Descope feature parity', src: 'from the PRD and the desktop launch', sub: 'Desktop fell 7 points after the same change. 10% of shoppers keep the old login, so the result is fair.',
|
|
51
|
+
rows: [
|
|
52
|
+
{ id: 'gd', group: 'Guardrail', name: 'Checkout conversion', type: 'Stay within', now: 3.1, nowTxt: '3.1%', target: 3.1, targetTxt: '≥ 3.1%', by: null, why: 'A faster login must not cost orders', source: 'Amplitude', ticket: null, state: 'open' },
|
|
53
|
+
{ id: 'pw', group: 'Proves it worked', name: 'Mobile checkout login drop-off', type: 'Percentage', now: 27, nowTxt: '27%', target: 19, targetTxt: '19%', by: '2027-01-15', why: 'Moves your key result “drop-off under 15%”', source: 'Amplitude', ticket: null, state: 'open' },
|
|
54
|
+
{ id: 'es', group: 'Early signal', name: 'Inline form completion', type: 'Percentage', now: null, nowTxt: '', target: 80, targetTxt: '80% week 1', by: null, why: '', source: '', ticket: { key: 'ESHOP-981', text: 'ESHOP-981 drafted' }, state: 'open' },
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
(async () => {
|
|
59
|
+
const exe = process.env.PMOS_CHROME || findBrowser();
|
|
60
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
61
|
+
let chromium;
|
|
62
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
63
|
+
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
|
|
64
|
+
await T.waitForServer(BASE);
|
|
65
|
+
browser = await chromium.launch({ executablePath: exe });
|
|
66
|
+
if (SHOTS) fs.mkdirSync(SHOTS, { recursive: true });
|
|
67
|
+
const shot = async (p, name) => { if (SHOTS) { await sleep(450); await p.screenshot({ path: path.join(SHOTS, name + '.png') }); } };
|
|
68
|
+
|
|
69
|
+
const open = async ({ w = 1440, h = 900, drafts = { program: PROGRAM(), initiative: INITIATIVE() }, dark = false } = {}) => {
|
|
70
|
+
const c = await browser.newContext({ viewport: { width: w, height: h }, colorScheme: dark ? 'dark' : 'light' });
|
|
71
|
+
const page = await c.newPage();
|
|
72
|
+
const errors = [], posts = [], gets = [];
|
|
73
|
+
page.on('pageerror', (e) => errors.push(String((e && e.stack) || e)));
|
|
74
|
+
const json = (r, b) => r.fulfill({ contentType: 'application/json', body: JSON.stringify(b) }), wsOf = (r) => new URL(r.request().url()).searchParams.get('ws') || 'idpf';
|
|
75
|
+
await page.route('**/api/board-premium*', (r) => json(r, { ok: true, state: 'ready', model: BP.build(F.programFacts(wsOf(r))), as_of: Date.now() }));
|
|
76
|
+
await page.route('**/api/programs', (r) => json(r, { ok: true, programs: F.programs() }));
|
|
77
|
+
await page.route('**/api/boards/anchors*', (r) => json(r, { ok: true, anchors: A.ANCHORS[wsOf(r)] || [] }));
|
|
78
|
+
await page.route('**/api/insights-premium*', (r) => json(r, { ok: true, model: { goals: A.GOALS[wsOf(r)] || [] } }));
|
|
79
|
+
await page.route('**/api/boards/items*', (r) => json(r, { ok: true, items: A.ITEMS[wsOf(r)] || [] }));
|
|
80
|
+
await page.route('**/api/programs/*', (r) => json(r, { ok: true }));
|
|
81
|
+
await page.route('**/api/board-trail*', (r) => r.fulfill({ status: 500, contentType: 'application/json', body: '{"ok":false,"error":"not in this check"}' }));
|
|
82
|
+
// the metric drafts, per scope: the GET answers the rows as they stand; keep-all and undo change them as the server would
|
|
83
|
+
const S = { program: drafts.program, initiative: drafts.initiative };
|
|
84
|
+
await page.route('**/api/metric-drafts**', (r) => {
|
|
85
|
+
const rq = r.request(), u = new URL(rq.url());
|
|
86
|
+
if (rq.method() === 'GET') {
|
|
87
|
+
const scope = u.searchParams.get('scope'), id = u.searchParams.get('id'), d = S[scope];
|
|
88
|
+
gets.push({ scope, id, ws: u.searchParams.get('ws') });
|
|
89
|
+
const rows = d && d.rows ? d.rows : [];
|
|
90
|
+
return json(r, { ok: true, scope, id, title: (d && d.title) || '', when: '2026-10-27', run: { state: rows.length ? 'ready' : 'idle', step: rows.length ? 4 : 0, reads: [] }, rows, head: '', sub: (d && d.sub) || '', src: (d && d.src) || '' });
|
|
91
|
+
}
|
|
92
|
+
const body = JSON.parse(rq.postData() || '{}'), d = S[body.scope];
|
|
93
|
+
posts.push({ path: u.pathname, body });
|
|
94
|
+
if (u.pathname.endsWith('/keep-all')) { const n = d.rows.filter((x) => x.state === 'open').length; d.rows.forEach((x) => { if (x.state === 'open') { x.state = 'kept'; x.rid = 'rid-' + x.id; } }); return json(r, { ok: true, kept: n }); }
|
|
95
|
+
if (u.pathname.endsWith('/undo')) { const x = d.rows.find((y) => y.id === body.row); if (x) { x.state = 'open'; delete x.rid; } return json(r, { ok: true }); }
|
|
96
|
+
return json(r, { ok: true });
|
|
97
|
+
});
|
|
98
|
+
await page.goto(BASE + '/premium-board.html?ws=idpf&program=project-ascent');
|
|
99
|
+
await until(() => page.evaluate(() => { const v = document.querySelector('#czViewer'); return !!v && !v.hidden && !!v.querySelector('.pp-vw .czs-sum'); }));
|
|
100
|
+
return { page, ctx: c, errors, posts, gets, S };
|
|
101
|
+
};
|
|
102
|
+
const card = (p) => p.evaluate(() => {
|
|
103
|
+
const c = document.querySelector('#czViewer .pp-vw .md-card'); if (!c) return null;
|
|
104
|
+
return { first: c === c.parentElement.firstElementChild, hd: c.querySelector('.md-hd b').textContent, src: (c.querySelector('.md-src') || {}).textContent || '', gl: c.querySelector('.md-gl').textContent,
|
|
105
|
+
cps: [...c.querySelectorAll('.md-cp')].map((x) => x.textContent), built: [...c.querySelectorAll('.md-ru:not(.q)')].map((x) => [...x.children].map((y) => y.textContent).join(' | ')),
|
|
106
|
+
why: c.querySelector('.md-why').textContent,
|
|
107
|
+
presses: [...c.querySelectorAll('.md-ft .md-ib')].map((b) => ({ label: b.getAttribute('aria-label'), title: b.getAttribute('title'), text: b.textContent.trim(), svg: !!b.querySelector('svg[aria-hidden="true"]'), solid: b.classList.contains('solid'), href: b.getAttribute('href') || '' })) };
|
|
108
|
+
});
|
|
109
|
+
// every font size the parts draw: the type scale only (11, 12, 14, 16, 20, 28 px)
|
|
110
|
+
const sizes = (p, sel) => p.evaluate((s) => [...new Set([...document.querySelectorAll(s + ', ' + s + ' *')].filter((e) => e.childNodes.length && [...e.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim())).map((e) => getComputedStyle(e).fontSize))], sel);
|
|
111
|
+
const SCALE = new Set(['11px', '12px', '14px', '16px', '20px', '28px']);
|
|
112
|
+
|
|
113
|
+
/* ── P: the program's proposed goal ── */
|
|
114
|
+
const D = await open();
|
|
115
|
+
const p = D.page;
|
|
116
|
+
const c = await until(() => card(p));
|
|
117
|
+
ok('P the proposed goal leads the panel body, with where it came from', !!c && c.first && c.hd === 'Proposed goal' && c.src === 'from the charter and its 3 initiatives', JSON.stringify(c));
|
|
118
|
+
ok('P the goal line', !!c && c.gl === 'Sign-ins on CIAM, all products: 12% → 100% by Jun 2028', c && c.gl);
|
|
119
|
+
ok('P checkpoint chips at its milestones, and the guardrail', !!c && c.cps.join(' / ') === '40% at Legacy IdP off · Feb 27 / 85% at All microsites · Mar 20 / Guardrail: Sign-in success · stays above 99%', c && c.cps.join(' / '));
|
|
120
|
+
ok('P Built from: Now and Target, a drafted ticket as a pill', !!c && c.built.join(' / ') === 'idpf · sign-ins on CIAM | 15% | 100% by Feb 27 / Microsites · sign-ins on CIAM | — | Ticket MS-212 drafted'
|
|
121
|
+
&& await p.evaluate(() => !!document.querySelector('#czViewer .md-card .md-ru .md-pill')), c && c.built.join(' / '));
|
|
122
|
+
ok('P one line of why, in Claude\'s words', !!c && c.why === 'idpf is 80% of all sign-ins, so it carries the goal. I check it every morning once you keep it.', c && c.why);
|
|
123
|
+
ok('P Discuss in Home, Edit and a solid ✓ Keep this goal: icon-only, each with a label and a title', !!c && c.presses.map((x) => x.label).join() === 'Discuss the proposed goal in Home,Edit the proposed goal in Home,Keep this goal'
|
|
124
|
+
&& c.presses.every((x) => x.title && !x.text && x.svg) && c.presses[2].solid && /ask=program%3Aproject-ascent/.test(c.presses[0].href) && /^\/premium\.html\?ws=idpf/.test(c.presses[1].href), JSON.stringify(c && c.presses));
|
|
125
|
+
ok('P the read names the program and its product', D.gets.some((g) => g.scope === 'program' && g.id === 'project-ascent' && g.ws === 'idpf'), JSON.stringify(D.gets));
|
|
126
|
+
const ps = await sizes(p, '#czViewer .md-card');
|
|
127
|
+
ok('S the card uses the type scale only', ps.length && ps.every((x) => SCALE.has(x)), ps.join());
|
|
128
|
+
ok('P the rest of the panel is as before: the summary, the goals and the folding rows follow', await p.evaluate(() => { const b = document.querySelector('#czViewer .pp-vw'); return !!b.querySelector('.md-card + .czs-sum') && !!b.querySelector('.czs-sum ~ .pp-goal') && !!b.querySelector('[data-czs-fold="tree"]'); }));
|
|
129
|
+
await shot(p, 'Iq9Program-proposed-built');
|
|
130
|
+
|
|
131
|
+
/* ── K: ✓ keeps all ── */
|
|
132
|
+
await p.click('#czViewer .md-card [data-md="keep"]');
|
|
133
|
+
const kp = await until(() => D.posts.find((x) => x.path === '/api/metric-drafts/keep-all'));
|
|
134
|
+
ok('K ✓ keeps all in one press (POST /api/metric-drafts/keep-all)', !!kp && kp.body.scope === 'program' && kp.body.id === 'project-ascent' && kp.body.ws === 'idpf', JSON.stringify(kp));
|
|
135
|
+
const kept = await until(() => p.evaluate(() => { const g = document.querySelector('#czViewer .pp-vw .md-kept'); if (!g) return null;
|
|
136
|
+
return { first: g === g.parentElement.firstElementChild, per: g.querySelector('.pp-per').textContent, chips: [...g.querySelectorAll('.md-kr')].map((x) => (x.querySelector('.pp-gd.off') ? 'off:' : x.querySelector('.pp-gd') ? 'ok:' : '') + x.textContent),
|
|
137
|
+
undo: (g.querySelector('[data-md="undo"]') || {}).title || '', card: !!document.querySelector('#czViewer .md-card') }; }));
|
|
138
|
+
ok('K the Goal row of chips, each with a dot: ok with a reading, off while it waits on a ticket', !!kept && kept.first && kept.per === 'Goal' && !kept.card
|
|
139
|
+
&& kept.chips.join(' / ') === 'ok:Sign-ins on CIAM, all products12% of 100% · Jun 2028 / ok:idpf · sign-ins on CIAM15% of 100% · Feb 27 / off:Microsites · sign-ins on CIAMwaits on MS-212 / ok:Sign-in successstays above 99%', JSON.stringify(kept));
|
|
140
|
+
ok('K Undo is beside it, icon-only', !!kept && kept.undo === 'Undo');
|
|
141
|
+
ok('K the toast says what happens next, in first person', /I check the goal every morning/.test(await p.evaluate(() => (document.querySelector('#bdToast') || {}).textContent || '')));
|
|
142
|
+
await shot(p, 'Iq9Program-kept-built');
|
|
143
|
+
|
|
144
|
+
/* ── U: Undo ── */
|
|
145
|
+
await p.click('#czViewer .md-kept [data-md="undo"]');
|
|
146
|
+
await until(() => D.posts.filter((x) => x.path === '/api/metric-drafts/undo').length === 4, 5000);
|
|
147
|
+
ok('U Undo puts each kept row back (POST /api/metric-drafts/undo, one per row)', D.posts.filter((x) => x.path === '/api/metric-drafts/undo').map((x) => x.body.row).join() === 'g,r1,r2,gr');
|
|
148
|
+
ok('U the proposal shows again', !!(await until(() => card(p))));
|
|
149
|
+
|
|
150
|
+
/* ── I: the initiative at Discover ── */
|
|
151
|
+
await until(() => p.evaluate(() => { const b = document.querySelector('#czViewer [data-czs-fold="tree"]'); if (b && b.getAttribute('aria-expanded') !== 'true') b.click(); return !!document.querySelector('#czViewer button.pp-open[data-ini="descope-parity"]'); }));
|
|
152
|
+
await p.click('#czViewer button.pp-open[data-ini="descope-parity"]');
|
|
153
|
+
const ic = await until(() => p.evaluate(() => { const c = document.querySelector('#czViewer .iv .md-card'); if (!c) return null;
|
|
154
|
+
return { after: !!(c.previousElementSibling && c.previousElementSibling.classList.contains('iv-sc')), hd: c.querySelector('.md-hd b').textContent, src: c.querySelector('.md-src').textContent,
|
|
155
|
+
rows: [...c.querySelectorAll('.md-mr')].map((r) => [r.querySelector('.md-role').textContent, r.querySelector('.md-nm b').textContent, (r.querySelector('small') || {}).textContent || '', r.querySelector('.md-now').textContent, r.querySelector('.md-to').textContent].join(' | ')),
|
|
156
|
+
why: c.querySelector('.md-why').textContent, presses: [...c.querySelectorAll('.md-ft .md-ib')].map((b) => ({ label: b.getAttribute('aria-label'), title: b.getAttribute('title'), text: b.textContent.trim(), solid: b.classList.contains('solid'), href: b.getAttribute('href') || '' })) }; }));
|
|
157
|
+
ok('I the proposed success measure sits under the stage card, with where it came from', !!ic && ic.after && ic.hd === 'Proposed success measure' && ic.src === 'from the PRD and the desktop launch', JSON.stringify(ic));
|
|
158
|
+
ok('I three groups in order, each Now → Target', !!ic && ic.rows.join(' / ') === 'Proves it worked · 4 weeks after release | Mobile checkout login drop-off | Moves your key result “drop-off under 15%” | 27% | 19% / Early signal · shows in days | Inline form completion | Ticket ESHOP-981 drafted | — | 80% week 1 / Guardrail | Checkout conversion | A faster login must not cost orders | 3.1% | ≥ 3.1%', ic && ic.rows.join(' / '));
|
|
159
|
+
ok('I one line of why', !!ic && /^Desktop fell 7 points/.test(ic.why));
|
|
160
|
+
ok('I Edit and a solid ✓ Keep this success measure: icon-only, each with a label and a title', !!ic && ic.presses.map((x) => x.label).join() === 'Edit the proposed success measure in Home,Keep this success measure'
|
|
161
|
+
&& ic.presses.every((x) => x.title && !x.text) && ic.presses[1].solid && /ask=descope-parity/.test(ic.presses[0].href), JSON.stringify(ic && ic.presses));
|
|
162
|
+
const is = await sizes(p, '#czViewer .iv .md-card');
|
|
163
|
+
ok('S the initiative card uses the type scale only', is.length && is.every((x) => SCALE.has(x)), is.join());
|
|
164
|
+
await shot(p, 'Iq9Initiative-proposed-built');
|
|
165
|
+
await p.click('#czViewer .iv .md-card [data-md="keep"]');
|
|
166
|
+
const ki = await until(() => D.posts.find((x) => x.path === '/api/metric-drafts/keep-all' && x.body.scope === 'initiative'));
|
|
167
|
+
ok('I ✓ keeps all (POST /api/metric-drafts/keep-all, scope initiative)', !!ki && ki.body.id === 'descope-parity', JSON.stringify(ki));
|
|
168
|
+
const kf = await until(() => p.evaluate(() => { const k = document.querySelector('#czViewer .iv .md-kept-i'); if (!k) return null; const f = k.querySelector('[data-md="fold"]');
|
|
169
|
+
return { b: f.querySelector('b').textContent, pill: f.querySelector('.md-ok').textContent, n: f.querySelector('.n').textContent, open: f.getAttribute('aria-expanded'), undo: (k.querySelector('[data-md="undo"]') || {}).title || '', card: !!document.querySelector('#czViewer .iv .md-card') }; }));
|
|
170
|
+
ok('I kept: the folded "Success measure · Set before the build · 3", with Undo', !!kf && kf.b === 'Success measure' && kf.pill === 'Set before the build' && kf.n === '3' && kf.open === 'false' && kf.undo === 'Undo' && !kf.card, JSON.stringify(kf));
|
|
171
|
+
await p.click('#czViewer .iv .md-kept-i [data-md="fold"]');
|
|
172
|
+
const lst = await until(() => p.evaluate(() => { const L = [...document.querySelectorAll('#czViewer .iv .md-kept-i .md-lr')]; return L.length ? L.map((x) => x.textContent) : null; }));
|
|
173
|
+
ok('I the fold opens on its rows', !!lst && lst.join(' / ') === 'Mobile checkout login drop-off27% → 19%, 4 weeks after release / Inline form completionWaits on ESHOP-981 / Checkout conversionStays at ≥ 3.1%', JSON.stringify(lst));
|
|
174
|
+
await shot(p, 'Iq9Initiative-kept-built');
|
|
175
|
+
await p.click('#czViewer .iv .md-kept-i [data-md="undo"]');
|
|
176
|
+
await until(() => D.posts.filter((x) => x.path === '/api/metric-drafts/undo' && x.body.scope === 'initiative').length === 3, 5000);
|
|
177
|
+
ok('I Undo makes it a proposal again', !!(await until(() => p.evaluate(() => !!document.querySelector('#czViewer .iv .md-card')))));
|
|
178
|
+
ok('0 no page error (desk)', D.errors.length === 0, D.errors.join(' | '));
|
|
179
|
+
await D.ctx.close();
|
|
180
|
+
|
|
181
|
+
/* ── Z: nothing drafted, nothing shown ── */
|
|
182
|
+
const Z = await open({ drafts: { program: { rows: [] }, initiative: { rows: [] } } });
|
|
183
|
+
await until(() => Z.gets.some((g) => g.scope === 'program'), 4000);
|
|
184
|
+
await sleep(400); // the answer has arrived and drawn: nothing may appear
|
|
185
|
+
ok('Z nothing drafted: no proposal and no Goal row on the program panel', await Z.page.evaluate(() => !document.querySelector('#czViewer .md-card, #czViewer .md-kept')));
|
|
186
|
+
await Z.page.evaluate(() => { const b = document.querySelector('#czViewer [data-czs-fold="tree"]'); if (b && b.getAttribute('aria-expanded') !== 'true') b.click(); });
|
|
187
|
+
await until(() => Z.page.evaluate(() => !!document.querySelector('#czViewer button.pp-open[data-ini="descope-parity"]')));
|
|
188
|
+
await Z.page.click('#czViewer button.pp-open[data-ini="descope-parity"]');
|
|
189
|
+
await until(() => Z.page.evaluate(() => !!document.querySelector('#czViewer .iv')) && Z.gets.some((g) => g.scope === 'initiative'), 6000);
|
|
190
|
+
await sleep(400);
|
|
191
|
+
ok('Z nothing drafted: no success measure on the initiative', await Z.page.evaluate(() => !document.querySelector('#czViewer .md-card, #czViewer .md-kept-i')));
|
|
192
|
+
ok('0 no page error (nothing drafted)', Z.errors.length === 0, Z.errors.join(' | '));
|
|
193
|
+
await Z.ctx.close();
|
|
194
|
+
|
|
195
|
+
/* ── H: a phone, and dark ── */
|
|
196
|
+
const H = await open({ w: 390, h: 844 });
|
|
197
|
+
const hc = await until(() => card(H.page));
|
|
198
|
+
ok('H on a phone: the card fits the width, and its presses are 44 px', !!hc && await H.page.evaluate(() => { const c = document.querySelector('#czViewer .md-card'), r = c.getBoundingClientRect(), b = c.querySelector('[data-md="keep"]').getBoundingClientRect(); return r.right <= innerWidth && c.scrollWidth <= c.clientWidth + 1 && b.width >= 44; }));
|
|
199
|
+
await shot(H.page, 'Iq9Program-phone-built');
|
|
200
|
+
ok('0 no page error (phone)', H.errors.length === 0, H.errors.join(' | '));
|
|
201
|
+
await H.ctx.close();
|
|
202
|
+
if (SHOTS) {
|
|
203
|
+
const K = await open({ dark: true });
|
|
204
|
+
await until(() => card(K.page));
|
|
205
|
+
await shot(K.page, 'Iq9Program-dark-built');
|
|
206
|
+
await K.ctx.close();
|
|
207
|
+
}
|
|
208
|
+
return finish();
|
|
209
|
+
})();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.429.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.429.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED