create-pmos 0.387.0 → 0.389.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 +25 -25
- 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-insights-test.js +16 -21
- package/workspace/changelog.json +24 -0
- package/workspace/guide/briefing-premium.md +19 -9
- package/workspace/lib/briefing-premium-agent.js +3 -0
- package/workspace/lib/report-chat.js +37 -0
- package/workspace/lib/report-setups.js +49 -7
- package/workspace/lib/routes-report-setups.js +38 -7
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-chat-chart-tab-test.js +150 -0
- package/workspace/premium-chat-report-tab-test.js +127 -0
- package/workspace/public/pm/goal-chat.js +2 -1
- package/workspace/public/pm/premium-chart-draw.js +58 -0
- package/workspace/public/pm/premium-chart-tab.js +157 -0
- package/workspace/public/pm/premium-chat.js +8 -2
- package/workspace/public/pm/premium-insights.js +17 -79
- package/workspace/public/pm/premium-report-tab.js +233 -0
- package/workspace/public/pm/premium-shell.js +35 -3
- package/workspace/public/pm/premium-vw-report.css +60 -0
- package/workspace/public/pm/premium.css +1 -120
- package/workspace/public/pm/report-chat.js +89 -0
- package/workspace/test-lists/premium-chat-chart-tab.json +12 -0
- package/workspace/test-lists/premium-chat-report-tab.json +12 -0
- package/workspace/premium-studio-chart-test.js +0 -193
- package/workspace/premium-studio-report-test.js +0 -277
- package/workspace/premium-studio-test.js +0 -185
- package/workspace/public/pm/premium-studio-design.js +0 -298
- package/workspace/public/pm/premium-studio-report.js +0 -291
- package/workspace/public/pm/premium-studio.js +0 -453
- package/workspace/test-lists/premium-studio-chart.json +0 -13
- package/workspace/test-lists/premium-studio-report.json +0 -9
- package/workspace/test-lists/premium-studio.json +0 -9
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
* line, what stands out), the Reports card, the dock and the standard dialog.
|
|
4
4
|
* briefing-premium-reports adds the PM's presses, each through pmPost and so behind the launch nonce: a saved dashboard (POST /api/premium-dashboards/save,
|
|
5
5
|
* PRD D2 to D6) and the report presses of the console's Reports workspace (POST /api/report-setups/ask | change | cancel | setup | dismiss | pause | resume |
|
|
6
|
-
* draft, PRD R2 to R4). premium-studio-chart
|
|
7
|
-
*
|
|
8
|
-
* revert | accept (PRD R5 to R8). insights-one-list puts the insight first, the pinned dashboard on top and one paged list of dashboards and reports below
|
|
6
|
+
* draft, PRD R2 to R4). premium-studio-chart's saved charts are drawn in their four forms (premium-chart-draw.js). premium-reports-from-chat removed the
|
|
7
|
+
* Insight Studio: New, Edit and Shape it open the Chat page, where Claude proposes and the PM saves in the tab beside the chat. insights-one-list puts the insight first, the pinned dashboard on top and one paged list of dashboards and reports below
|
|
9
8
|
* (PRD L1 to L6); its one new press is Pin, POST /api/premium-dashboards/pin. Nothing else posts, and nothing is sent outward. */
|
|
10
9
|
import { $, $$, esc, openDlg, popKey, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, crumbHtml, wireCrumb, kv, setPageGaps, infoBtn, growAsk } from './premium-shell.js';
|
|
11
|
-
import { pmPost
|
|
12
|
-
import { openStudio } from './premium-studio.js';
|
|
10
|
+
import { pmPost } from './http.js';
|
|
13
11
|
import { openReport } from './premium-report-read.js';
|
|
14
12
|
import * as MT from './premium-metric-tiles.js';
|
|
13
|
+
import { W, P, X, Y, tileHtml } from './premium-chart-draw.js';
|
|
15
14
|
|
|
16
15
|
let M = null; // the model
|
|
17
16
|
let dash = null; // the dashboard in the top card: the pinned one until a list row opens another
|
|
@@ -63,62 +62,6 @@ $('#insHero').addEventListener('click', (e) => {
|
|
|
63
62
|
});
|
|
64
63
|
|
|
65
64
|
/* ── charts ───────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
66
|
-
const W = 220, H = 60, P = 5;
|
|
67
|
-
const X = (fx) => P + fx * (W - 2 * P), Y = (fy) => P + (1 - fy) * (H - 2 * P);
|
|
68
|
-
/* A chart is drawn in one of four forms (initiative premium-studio-chart C3). The page and the Insight Studio share this drawing. A KR metric's own chart
|
|
69
|
-
* is a line; a chart the PM saved carries its form. Bars and a meter start at zero, so a series with a value below zero is drawn as a line and says so. */
|
|
70
|
-
const unitTxt = (c, v) => { const u = c.unit || '', s = String(Math.round(v * 100) / 100); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
|
|
71
|
-
function chgHtml(c) {
|
|
72
|
-
return c.step === 0 ? '' : `<span class="mchg ${c.good === null ? '' : c.good ? 'good' : 'bad'}">${c.step > 0 ? '▲ ' : '▼ '}${esc(Math.abs(c.step) + (c.unit && /^[%°]/.test(c.unit) ? c.unit : c.unit ? ' ' + c.unit : ''))} since the last reading</span>`;
|
|
73
|
-
}
|
|
74
|
-
const chipOf = (c) => `<i class="mchip ${c.chipKind === 'bad' ? 'warn' : c.chipKind}">${esc(c.chip)}</i>`;
|
|
75
|
-
const capOf = (c) => 'on ' + c.at + (c.targetTxt ? ' · ' + c.targetTxt : '');
|
|
76
|
-
function tileHtml(c) {
|
|
77
|
-
const f = c.form || 'line', neg = c.pts.some((p) => p.v < 0) || (c.target !== null && c.target < 0);
|
|
78
|
-
const h = f === 'number' ? numTile(c) : f === 'bars' && !neg ? barsTile(c) : f === 'meter' && !neg && c.target !== null ? meterTile(c) : lineTile(c, f !== 'line' && f !== 'number' ? (neg ? 'A value is below zero, so it is drawn as a line.' : 'No target is set, so it is drawn as a line.') : '');
|
|
79
|
-
return h + (c.note ? `<p class="mnote">${esc(c.note)}</p>` : '');
|
|
80
|
-
}
|
|
81
|
-
function lineTile(c, why) {
|
|
82
|
-
const d = c.pts.map((p, i) => (i ? 'L' : 'M') + X(p.fx).toFixed(1) + ',' + Y(p.fy).toFixed(1)).join('');
|
|
83
|
-
const last = c.pts[c.pts.length - 1];
|
|
84
|
-
return `<div class="mt1 mch ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" tabindex="0" role="img" aria-label="${esc(c.title)}, ${c.pts.length} readings, now ${esc(c.v)}${c.targetTxt ? ', ' + esc(c.targetTxt) : ''}. Use the arrow keys to read each reading."><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval">${esc(c.v)}</b><em class="mwk">${esc(capOf(c))}</em>${chgHtml(c)}`
|
|
85
|
-
+ `<svg viewBox="0 0 ${W} ${H}"><path class="ar" d="${d}L${X(1)},${H}L${X(0)},${H}Z"/>${c.ty !== null ? `<line class="tg" x1="${P}" x2="${W - P}" y1="${Y(c.ty)}" y2="${Y(c.ty)}"/>` : ''}<path class="ln2" d="${d}"/><line class="cx" x1="0" x2="0" y1="0" y2="${H}"/><circle class="dt" cx="${X(last.fx)}" cy="${Y(last.fy)}" r="3.5"/></svg>`
|
|
86
|
-
+ `<span class="mfoot"><i>${esc(c.ticks[0])}</i>${c.target !== null ? '<i class="tgl">dashed line is the target</i>' : ''}<i>${esc(c.ticks[1])}</i></span>${why ? `<span class="mwhy">${esc(why)}</span>` : ''}</div>`;
|
|
87
|
-
}
|
|
88
|
-
function barsTile(c) {
|
|
89
|
-
const n = c.pts.length, hi = Math.max(...c.pts.map((p) => p.v), c.target !== null ? c.target : 0) || 1, pc = (v) => (v / hi * 84).toFixed(1);
|
|
90
|
-
const cols = c.pts.map((p, i) => `<span class="bw" title="${esc(p.d + ': ' + p.txt)}">${i === n - 1 ? `<b class="bl">${esc(p.txt)}</b>` : ''}<i class="${i === n - 1 ? 'bk' : 'bg'}" style="height:${pc(p.v)}%"></i></span>`).join('');
|
|
91
|
-
return `<div class="mt1 mfm bars ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" role="img" aria-label="${esc(c.title)}, ${n} readings as bars from zero, now ${esc(c.v)}${c.targetTxt ? ', ' + esc(c.targetTxt) : ''}"><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval">${esc(c.v)}</b><em class="mwk">${esc(capOf(c))}</em>${chgHtml(c)}`
|
|
92
|
-
+ `<div class="bplot">${cols}${c.target !== null ? `<i class="btg" style="bottom:${pc(c.target)}%"></i>` : ''}</div>`
|
|
93
|
-
+ `<span class="mfoot"><i>${esc(c.ticks[0])}</i><i class="tgl">${c.target !== null ? 'dashed line is the target' : 'bars start at zero'}</i><i>${esc(c.ticks[1])}</i></span></div>`;
|
|
94
|
-
}
|
|
95
|
-
function numTile(c) {
|
|
96
|
-
const d = c.pts.map((p, i) => (i ? 'L' : 'M') + X(p.fx).toFixed(1) + ',' + (2 + (1 - p.fy) * 26).toFixed(1)).join('');
|
|
97
|
-
return `<div class="mt1 mfm num ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" role="img" aria-label="${esc(c.title)}, now ${esc(c.v)}${c.targetTxt ? ', ' + esc(c.targetTxt) : ''}"><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval mhero">${esc(c.v)}</b><em class="mwk">${esc(capOf(c))}</em>${chgHtml(c)}`
|
|
98
|
-
+ `<svg class="nspk" viewBox="0 0 ${W} 30" aria-hidden="true"><path d="${d}"/></svg></div>`;
|
|
99
|
-
}
|
|
100
|
-
function meterTile(c) {
|
|
101
|
-
const v = c.pts[c.pts.length - 1].v, tg = c.target, hi = Math.max(v, tg) * 1.15 || 1, lower = c.dir < 0, ok = lower ? v <= tg : v >= tg;
|
|
102
|
-
return `<div class="mt1 mfm prg ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" role="img" aria-label="${esc(c.title)} is ${esc(c.v)} against ${lower ? 'a limit' : 'a target'} of ${esc(unitTxt(c, tg))}. ${ok ? 'It is on the right side of it.' : 'It is not there yet.'}"><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval">${esc(c.v)}</b><em class="mwk">${esc(ok ? (lower ? 'Within the limit' : 'At or past the target') : (lower ? 'Over the limit' : 'Short of the target'))}</em>`
|
|
103
|
-
+ `<div class="mtrk"><i class="mfil ${ok ? 'ok' : 'warn'}" style="width:${(v / hi * 100).toFixed(1)}%"></i><i class="mtgt" style="left:${(tg / hi * 100).toFixed(1)}%"></i></div>`
|
|
104
|
-
+ `<span class="mfoot"><i>0</i><i class="tgl">${lower ? 'limit' : 'target'} ${esc(unitTxt(c, tg))}</i><i>${esc(unitTxt(c, hi))}</i></span></div>`;
|
|
105
|
-
}
|
|
106
|
-
/* The Studio's draft drawn from a measure's chart (premium-studio-chart C2, C7): the latest `range` readings, against the draft's target, as the server's
|
|
107
|
-
* lib/insights-premium.js mineOf draws a saved chart. Every point is a reading of the record. */
|
|
108
|
-
function deriveChart(base, d) {
|
|
109
|
-
const all = base.pts, pts0 = d.range ? all.slice(-d.range) : all.slice();
|
|
110
|
-
if (pts0.length < 2) return null;
|
|
111
|
-
const tg = d.target === null || d.target === undefined || d.target === '' ? null : +d.target;
|
|
112
|
-
const day = (p) => Date.parse(String(p.at).slice(0, 10) + 'T00:00:00Z');
|
|
113
|
-
const t0 = day(pts0[0]), span = day(pts0[pts0.length - 1]) - t0 || 1;
|
|
114
|
-
const ys = pts0.map((p) => p.v).concat(tg !== null ? [tg] : []), lo = Math.min(...ys), hi = Math.max(...ys), range = hi - lo || 1;
|
|
115
|
-
const pts = pts0.map((p) => Object.assign({}, p, { fx: (day(p) - t0) / span, fy: (p.v - lo) / range }));
|
|
116
|
-
const now = pts[pts.length - 1], prev = pts[pts.length - 2], step = Math.round((now.v - prev.v) * 100) / 100, dir = d.better === 'lower' ? -1 : 1;
|
|
117
|
-
return Object.assign({}, base, {
|
|
118
|
-
key: 'draft', title: d.title || base.title, form: d.form, note: d.note || '', pts, v: now.txt, at: now.d, target: tg, targetTxt: tg !== null ? 'target ' + unitTxt(base, tg) : '',
|
|
119
|
-
ty: tg !== null ? (tg - lo) / range : null, step, dir, good: step ? step * dir > 0 : null, ticks: [pts[0].d, now.d],
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
65
|
/* Point at reading j: the cursor line, the dot, the value and the date move to it. Without j the tile returns to the latest reading. */
|
|
123
66
|
function chartAt(t, j) {
|
|
124
67
|
const c = byKey(t.dataset.key); if (!c) return;
|
|
@@ -220,24 +163,19 @@ $('#dashBar').addEventListener('click', (e) => {
|
|
|
220
163
|
if (e.target.closest('#pdEdit')) openDashEdit(curDash()); else if (e.target.closest('#pcNew')) openChartEdit(null);
|
|
221
164
|
});
|
|
222
165
|
|
|
223
|
-
/* ──
|
|
166
|
+
/* ── dashboards, charts and reports are made and changed in a chat (initiative premium-reports-from-chat, slice C; the Insight Studio is removed).
|
|
167
|
+
* Edit, New chart, the + menu and Shape it open the Chat page: with ?open= it opens that one in the tab beside the chat, with ?say= it puts a first
|
|
168
|
+
* message in the box for the PM to send. Every save is still the PM's press in that tab. ── */
|
|
169
|
+
/* the switches under On your dashboards in a measure's dialog still save a dashboard here (POST /api/premium-dashboards/save) */
|
|
224
170
|
async function saveDash(body) { return pmPost('/api/premium-dashboards/save', Object.assign({ ws: M.board.ws, board: M.board.id }, body)); }
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
};
|
|
234
|
-
const studioOf = (o) => openStudio(Object.assign({ M, tile: tileHtml, derive: deriveChart, save: saveDash, saveChart, setup: (sub, body) => repPost(sub, body), structure, design, reportsChanged: () => load(),
|
|
235
|
-
done: async (id) => { dash = id || dash; await load(); } }, o));
|
|
236
|
-
function openDashEdit(D) { studioOf({ mode: 'dash', D, done: async (id) => { dash = id || null; await load(); } }); }
|
|
237
|
-
/* A chart is made and edited in the Studio's Chart mode (initiative premium-studio-chart). Save posts POST /api/premium-charts/save. */
|
|
238
|
-
function openChartEdit(id) { studioOf({ mode: 'chart', C: id ? (M.mineSaved || []).find((x) => x.id === id) || null : null }); }
|
|
239
|
-
/* A report is set up and shaped in the Studio's Report mode (initiative premium-studio-report). */
|
|
240
|
-
function openReportEdit(s) { studioOf({ mode: 'rep', R: s || null }); }
|
|
171
|
+
function toChat(o) {
|
|
172
|
+
const q = new URLSearchParams(); if (M.board.ws) q.set('ws', M.board.ws);
|
|
173
|
+
if (o.open) q.set('open', o.open); if (o.say) q.set('say', o.say);
|
|
174
|
+
location.href = '/premium-chat.html?' + q.toString();
|
|
175
|
+
}
|
|
176
|
+
const openDashEdit = (D) => toChat(D ? { open: 'dashboard:' + D.id } : { say: 'Make a dashboard of ' });
|
|
177
|
+
const openChartEdit = (id) => toChat(id ? { open: 'chart:' + id } : { say: 'Make a chart of ' });
|
|
178
|
+
const openReportEdit = (s) => toChat(s ? { open: 'report:' + s.id } : { say: 'Make a report of ' });
|
|
241
179
|
$('#dashBody').addEventListener('click', (e) => { const o = e.target.closest('[data-open]'); if (o) { openChart(byKey(o.dataset.open)); return; } const ed = e.target.closest('[data-ced]'); if (ed) openChartEdit(ed.dataset.ced); });
|
|
242
180
|
$('#dashBody').addEventListener('keydown', (e) => {
|
|
243
181
|
const t = e.target.closest && e.target.closest('.mch'); if (!t || !/^Arrow(Left|Right)$/.test(e.key)) return;
|
|
@@ -409,7 +347,7 @@ function openSetup(s) {
|
|
|
409
347
|
const rows = [['Schedule', s.label], ['Status', s.paused ? 'Paused' : 'Active'], ['Next draft', s.paused ? '' : s.next], ['Last issued cycle', s.lastIssued], ['Audience', s.audience], ['Output', s.output], ['Documents', String(s.cycles)], ['Purpose', s.purpose]];
|
|
410
348
|
const acts = [s.paused ? ['resume', 'Resume'] : ['pause', 'Pause', 1]];
|
|
411
349
|
if (s.fromWork && !s.paused) acts.unshift(['draft', 'Draft it now']);
|
|
412
|
-
if (s.fromWork) acts.push(['studio', 'Shape it in
|
|
350
|
+
if (s.fromWork) acts.push(['studio', 'Shape it in a chat', 1]);
|
|
413
351
|
repDlg({ eye: 'Set-up report', title: s.name, facts: rows, say: s.paused ? 'This report is paused. Resume it to draft it on its schedule again.' : 'This report is drafted on its schedule. You can draft the next cycle now or pause it.',
|
|
414
352
|
html: kv(rows) + `<p class="note">${s.fromWork ? (s.structured ? 'Draft it now starts a background run that follows the saved structure.' : 'Draft it now writes the next cycle as a file at once.') : 'This report is drafted from its dashboard on its day.'} Pause and Resume record a line in the report ledger. Nothing is sent.</p>`,
|
|
415
353
|
acts, on: {
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/* pm/premium-report-tab.js — the Report tab beside a chat (initiative premium-reports-from-chat, slice B; PRD R1–R4). It replaces the Insight Studio's
|
|
2
|
+
* Report mode: the PM asks in the chat, Claude ends its answer with a `pmos-report` block (public/pm/report-chat.js), and this tab shows it.
|
|
3
|
+
*
|
|
4
|
+
* A NEW REPORT (block.proposal): its name, what it answers, audience, format, the seven sections every new report has, and the Schedule chip.
|
|
5
|
+
* Set it up posts POST /api/report-setups/setup. A report with Schedule Off (none said) is then paused at once with POST /api/report-setups/edit,
|
|
6
|
+
* so it runs once (PM, 2026-10-21).
|
|
7
|
+
* A SET-UP REPORT (block.id): the Schedule chip (POST .../edit), Structure | Design with their versions, the cycles (drafts and issued reports) and
|
|
8
|
+
* Delete template (POST .../remove). A change Claude proposes in words (block.structure, block.design, block.schedule) shows as one press.
|
|
9
|
+
* Structure: GET /api/report-structure; turn, accept (Use this) and revert (Undo). Design: GET /api/report-design and its version renders;
|
|
10
|
+
* turn, accept (This is it) and revert. A draft is discarded (POST /api/report-documents/discard); an issued report is kept for good and can
|
|
11
|
+
* only be archived (POST /api/report-documents/archive).
|
|
12
|
+
*
|
|
13
|
+
* Every write is a press here, behind the launch nonce (http.js pmPost). Claude writes nothing: the routes refuse an agent session. A render is
|
|
14
|
+
* HTML the server sanitized, shown in a frame with an empty sandbox, so nothing in it runs. Nothing is sent outward. */
|
|
15
|
+
import { pmGet, pmPost } from './http.js';
|
|
16
|
+
import { vwOpen, vwStyle, vwConfirm } from './premium-viewer.js';
|
|
17
|
+
|
|
18
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
19
|
+
const OUT = { 'google-slides': 'Google Slides', 'google-doc': 'Google Doc', 'google-sheets': 'Google Sheets', confluence: 'Confluence page', pdf: 'PDF' };
|
|
20
|
+
const FRAME = [['Headline', 'The one thing the readers must know this cycle.'], ['Timeline', 'The dated items, written in full.'], ['Initiatives', 'Done, in progress, next and the key open item.'],
|
|
21
|
+
['New since last report', 'What is new in the window, each with its date.'], ['Decided this cycle', 'The decisions, marked Decided or Acknowledged.'], ['Needs your call', 'The asks to the readers: what, who, by when.'], ['Sources', 'The sources reached and not reached.']];
|
|
22
|
+
const DAYN = { Mon: 'Mondays', Tue: 'Tuesdays', Wed: 'Wednesdays', Thu: 'Thursdays', Fri: 'Fridays', Sat: 'Saturdays', Sun: 'Sundays' };
|
|
23
|
+
const POLL_MS = 1200, POLL_MAX = 240000;
|
|
24
|
+
const ws = () => new URLSearchParams(location.search).get('ws') || '';
|
|
25
|
+
const qs = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
26
|
+
const post = (p, body) => pmPost(p, Object.assign(ws() ? { ws: ws() } : {}, body)).catch(() => null);
|
|
27
|
+
const get = (p, o) => pmGet(p + '?' + qs(Object.assign({ ws: ws() }, o))).catch(() => null);
|
|
28
|
+
|
|
29
|
+
/** The schedule in words: 'off' or null is Off. */
|
|
30
|
+
export function schedWords(s) {
|
|
31
|
+
if (!s || s === 'off') return 'Off · runs once';
|
|
32
|
+
const t = s.time || '09:00';
|
|
33
|
+
if (s.cadence === 'daily') return 'Daily at ' + t;
|
|
34
|
+
if (s.cadence === 'monthly') return 'Monthly on day ' + (s.dayOfMonth || 1) + ' at ' + t;
|
|
35
|
+
return (s.cadence === 'weekly' ? 'Weekly, ' : 'Every two weeks, ') + (DAYN[s.day] || 'Mondays') + ' at ' + t;
|
|
36
|
+
}
|
|
37
|
+
const sameSched = (a, b) => schedWords(a) === schedWords(b);
|
|
38
|
+
/** The choices of the Schedule chip, the current day kept for weekly ones. */
|
|
39
|
+
export function schedChoices(cur) {
|
|
40
|
+
const day = cur && cur !== 'off' && cur.day ? cur.day : 'Mon';
|
|
41
|
+
return ['off', { cadence: 'daily', time: '09:00' }, { cadence: 'weekly', day, time: '09:00' }, { cadence: 'bi-weekly', day, time: '09:00' }, { cadence: 'monthly', dayOfMonth: 1, time: '09:00' }];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const T = new Map(); // tab id → its state
|
|
45
|
+
/** Open (or refresh) the Report tab for a checked block (report-chat.js cleanBlock). */
|
|
46
|
+
export function openReportTab(block) {
|
|
47
|
+
if (!block) return null;
|
|
48
|
+
vwStyle('report');
|
|
49
|
+
const id = 'report:' + (block.id || block.proposal.name).toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 60);
|
|
50
|
+
let t = T.get(id);
|
|
51
|
+
if (!t || JSON.stringify(t.block) !== JSON.stringify(block)) {
|
|
52
|
+
t = { id, block, sched: block.proposal ? (block.proposal.schedule || 'off') : null, open: false, view: 'structure', busy: false, msg: '', setup: null, docs: [], S: null, Z: null, sv: null, dv: null, render: new Map(), gone: false, loaded: false };
|
|
53
|
+
T.set(id, t);
|
|
54
|
+
if (block.id) load(t);
|
|
55
|
+
}
|
|
56
|
+
return vwOpen({ id, title: 'Report', icon: 'doc', render: (el) => draw(t, el), wire: (el) => { el.onclick = (e) => press(t, e); } });
|
|
57
|
+
}
|
|
58
|
+
const paneOf = (t) => document.querySelector(`#dOut .obody.vw[data-vw="${CSS.escape(t.id)}"]`);
|
|
59
|
+
const redraw = (t) => { const el = paneOf(t); if (el) draw(t, el); };
|
|
60
|
+
|
|
61
|
+
async function load(t) {
|
|
62
|
+
const rid = t.block.id;
|
|
63
|
+
const [L, D, S] = await Promise.all([get('/api/report-setups'), get('/api/report-documents'), get('/api/report-structure', { id: rid })]);
|
|
64
|
+
t.setup = L && Array.isArray(L.setups) ? L.setups.find((s) => s.id === rid) || null : null;
|
|
65
|
+
t.gone = !!L && !t.setup;
|
|
66
|
+
t.docs = D && Array.isArray(D.docs) ? D.docs.filter((d) => d.id.startsWith(rid + '/')).sort((a, b) => (a.slot < b.slot ? 1 : -1)) : [];
|
|
67
|
+
if (S && S.ok) { t.S = S.structure; if (t.sv == null) t.sv = t.S.current; }
|
|
68
|
+
t.loaded = true;
|
|
69
|
+
if (t.view === 'design') await loadDesign(t);
|
|
70
|
+
redraw(t);
|
|
71
|
+
if (t.S && t.S.running) poll(t, 'structure');
|
|
72
|
+
}
|
|
73
|
+
async function loadDesign(t) {
|
|
74
|
+
const r = await get('/api/report-design', { id: t.block.id });
|
|
75
|
+
if (!r || !r.ok) { t.Z = { err: (r && r.error) || 'The design of this report could not be read.' }; return; }
|
|
76
|
+
t.Z = r.design;
|
|
77
|
+
if (t.dv == null) t.dv = t.Z.current != null ? t.Z.current : (t.Z.saved ? t.Z.saved.version : null);
|
|
78
|
+
await renderOf(t, t.dv);
|
|
79
|
+
if (t.Z.running) poll(t, 'design');
|
|
80
|
+
}
|
|
81
|
+
async function renderOf(t, n) {
|
|
82
|
+
if (n == null || t.render.has(n)) return;
|
|
83
|
+
try { const r = await fetch('/api/report-design/version?' + qs({ ws: ws(), id: t.block.id, n }), { credentials: 'same-origin' }); if (r.ok) t.render.set(n, await r.text()); } catch { /* shown as unread */ }
|
|
84
|
+
}
|
|
85
|
+
/* One structure or design job runs at a time; wait for it, then show its newest version. */
|
|
86
|
+
async function poll(t, kind) {
|
|
87
|
+
const end = Date.now() + POLL_MAX;
|
|
88
|
+
while (Date.now() < end && paneOf(t)) {
|
|
89
|
+
await new Promise((ok) => setTimeout(ok, POLL_MS));
|
|
90
|
+
if (kind === 'structure') {
|
|
91
|
+
const S = await get('/api/report-structure', { id: t.block.id });
|
|
92
|
+
if (S && S.ok && !S.structure.running) { t.S = S.structure; t.sv = t.S.current; t.busy = false; t.msg = lastSaid(t.S.log); redraw(t); return; }
|
|
93
|
+
} else {
|
|
94
|
+
const r = await get('/api/report-design', { id: t.block.id });
|
|
95
|
+
if (r && r.ok && !r.design.running) { t.Z = r.design; t.dv = t.Z.current; await renderOf(t, t.dv); t.busy = false; t.msg = lastSaid(t.Z.log); redraw(t); return; }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
t.busy = false; t.msg = 'PMOS has not answered yet. The new version shows when you open this report again.'; redraw(t);
|
|
99
|
+
}
|
|
100
|
+
const lastSaid = (log) => { const l = (log || []).filter((x) => x.who === 'pmos').pop(); return l ? l.text : ''; };
|
|
101
|
+
|
|
102
|
+
/* ── drawing ── */
|
|
103
|
+
const btn = (a, label, o = {}) => `<button type="button" class="btn${o.sec ? ' sec' : ''}${o.cls ? ' ' + o.cls : ''}" data-rt="${esc(a)}"${o.off ? ' disabled' : ''}${o.pressed != null ? ` aria-pressed="${o.pressed}"` : ''}>${esc(label)}</button>`;
|
|
104
|
+
function schedHtml(t, cur) {
|
|
105
|
+
const chip = `<button type="button" class="rt-chip" data-rt="sched" aria-expanded="${t.open}"><em>Schedule</em><b>${esc(schedWords(cur))}</b></button>`;
|
|
106
|
+
if (!t.open) return chip;
|
|
107
|
+
const opts = schedChoices(cur).map((s, i) => `<button type="button" role="menuitemradio" aria-checked="${sameSched(s, cur)}" data-rt="pick|${i}">${esc(schedWords(s))}</button>`).join('');
|
|
108
|
+
const days = cur && cur !== 'off' && (cur.cadence === 'weekly' || cur.cadence === 'bi-weekly')
|
|
109
|
+
? `<div class="rt-days" role="group" aria-label="Day">${Object.keys(DAYN).slice(0, 5).map((d) => btn('day|' + d, d, { sec: cur.day !== d, pressed: cur.day === d })).join('')}</div>` : '';
|
|
110
|
+
return chip + `<div class="rt-menu" role="menu" aria-label="Schedule">${opts}${days}<p class="rt-note">Or say it in the chat: “make it every two weeks”.</p></div>`;
|
|
111
|
+
}
|
|
112
|
+
const sectionsHtml = (L) => `<ol class="rt-secs">${L.map(([h, d]) => `<li><b>${esc(h)}</b>${d ? `<span>${esc(d)}</span>` : ''}</li>`).join('')}</ol>`;
|
|
113
|
+
|
|
114
|
+
function draw(t, el) {
|
|
115
|
+
const ask = el.querySelector(':scope > .vcf'); // an open confirm card outlives a redraw (a poll or a load), so its answer still lands
|
|
116
|
+
el.innerHTML = `<div class="rt">${t.block.proposal ? newHtml(t) : setupHtml(t)}${t.msg ? `<p class="rt-msg" role="status">${esc(t.msg)}</p>` : ''}</div>`;
|
|
117
|
+
if (ask) el.prepend(ask);
|
|
118
|
+
el.querySelectorAll('iframe[data-rt-frame]').forEach((f) => { f.srcdoc = t.render.get(+f.dataset.rtFrame) || ''; });
|
|
119
|
+
}
|
|
120
|
+
function newHtml(t) {
|
|
121
|
+
const p = t.block.proposal;
|
|
122
|
+
return `<p class="rt-eye">New report · from this chat</p><h3 class="rt-h">${esc(p.name)}</h3>${p.purpose ? `<p class="rt-sub">${esc(p.purpose)}</p>` : ''}`
|
|
123
|
+
+ `<p class="rt-meta">For ${esc(p.audience)} · ${esc(OUT[p.output] || p.output)}</p><div class="rt-row">${schedHtml(t, t.sched)}</div>`
|
|
124
|
+
+ `<p class="rt-label">Sections</p>${sectionsHtml(FRAME)}<p class="rt-note">Every new report has these sections. Once it is set up, ask in the chat to shape them.</p>`
|
|
125
|
+
+ `<div class="rt-foot">${btn('setup', t.busy ? 'Setting it up' : 'Set it up', { off: t.busy })}</div>`;
|
|
126
|
+
}
|
|
127
|
+
function setupHtml(t) {
|
|
128
|
+
const s = t.setup;
|
|
129
|
+
if (!t.loaded) return '<p class="rt-note" role="status">Reading the report.</p>';
|
|
130
|
+
if (t.gone) return `<p class="rt-eye">Report</p><h3 class="rt-h">${esc(t.block.id)}</h3><p class="rt-note">This template is deleted, or it is not set up in this workspace. Its issued reports are kept.</p>${cyclesHtml(t)}`;
|
|
131
|
+
const cur = s.status === 'paused' ? 'off' : s.schedule;
|
|
132
|
+
const want = t.block.schedule && !sameSched(t.block.schedule, cur) ? `<div class="rt-ask"><p>Claude proposes: <b>${esc(schedWords(t.block.schedule))}</b></p>${btn('sched-use', 'Change the schedule', { off: t.busy })}</div>` : '';
|
|
133
|
+
return `<p class="rt-eye">Report template</p><h3 class="rt-h">${esc(s.name)}</h3><p class="rt-meta">For ${esc(s.audience || 'no one named')} · ${esc(OUT[s.output] || s.output)}${s.next_draft ? ' · next draft ' + esc(s.next_draft.slice(0, 10)) : ''}</p>`
|
|
134
|
+
+ `<div class="rt-row">${schedHtml(t, cur)}</div>${want}`
|
|
135
|
+
+ `<div class="rt-seg" role="group" aria-label="Step">${btn('view|structure', 'Structure', { sec: t.view !== 'structure', pressed: t.view === 'structure' })}${btn('view|design', 'Design', { sec: t.view !== 'design', pressed: t.view === 'design' })}</div>`
|
|
136
|
+
+ (t.view === 'design' ? designHtml(t) : structureHtml(t)) + cyclesHtml(t)
|
|
137
|
+
+ `<div class="rt-foot rt-end">${btn('remove', 'Delete template', { sec: true, cls: 'rt-del', off: t.busy })}</div>`;
|
|
138
|
+
}
|
|
139
|
+
function stepper(kind, n, list, saved) {
|
|
140
|
+
if (n == null || !list.length) return '';
|
|
141
|
+
const i = list.findIndex((v) => v.n === n);
|
|
142
|
+
return `<div class="rt-ver"><button type="button" class="rt-arrow" data-rt="${kind}|${list[i - 1] ? list[i - 1].n : n}" aria-label="Earlier version"${i <= 0 ? ' disabled' : ''}>‹</button>`
|
|
143
|
+
+ `<span>${kind === 'sv' ? 'S' : 'D'}${n}${n === saved ? ' · saved' : ' · not saved'}</span><button type="button" class="rt-arrow" data-rt="${kind}|${list[i + 1] ? list[i + 1].n : n}" aria-label="Later version"${i >= list.length - 1 ? ' disabled' : ''}>›</button></div>`;
|
|
144
|
+
}
|
|
145
|
+
function structureHtml(t) {
|
|
146
|
+
const S = t.S, V = (S && S.versions) || [];
|
|
147
|
+
const plan = S && S.plan, shown = t.sv;
|
|
148
|
+
const L = plan && plan.outline ? plan.outline.map((x) => [x.title, x.notes || '']) : FRAME;
|
|
149
|
+
const ask = t.block.structure && !(S && S.running) ? `<div class="rt-ask"><p>Your change: <b>“${esc(t.block.structure)}”</b></p>${btn('s-turn', 'Make the next version', { off: t.busy })}</div>` : '';
|
|
150
|
+
const working = S && S.running ? '<p class="rt-note" role="status">PMOS is making the next version.</p>' : '';
|
|
151
|
+
const save = shown != null && S && shown !== S.saved ? btn('s-accept', 'Use this', { off: t.busy }) : '';
|
|
152
|
+
const undo = V.some((v) => v.n < (S ? S.current : 0)) ? btn('s-undo', 'Undo', { sec: true, off: t.busy }) : '';
|
|
153
|
+
return `${stepper('sv', shown, V, S && S.saved)}${ask}${working}${sectionsHtml(L)}${!V.length ? '<p class="rt-note">No structure version yet: each cycle uses these sections. Say in the chat how to shape them.</p>' : ''}${save || undo ? `<div class="rt-foot">${undo}${save}</div>` : ''}`;
|
|
154
|
+
}
|
|
155
|
+
function designHtml(t) {
|
|
156
|
+
const Z = t.Z;
|
|
157
|
+
if (!Z) return '<p class="rt-note" role="status">Reading the design.</p>';
|
|
158
|
+
if (Z.err) return `<p class="rt-note">${esc(Z.err)}</p>`;
|
|
159
|
+
const V = Z.versions || [], saved = Z.saved ? Z.saved.version : null;
|
|
160
|
+
const ask = t.block.design && !Z.running ? `<div class="rt-ask"><p>Your change: <b>“${esc(t.block.design)}”</b></p>${btn('d-turn', 'Make the next version', { off: t.busy })}</div>` : '';
|
|
161
|
+
const working = Z.running ? '<p class="rt-note" role="status">PMOS is making the next version.</p>' : '';
|
|
162
|
+
const frame = t.dv != null ? (t.render.has(t.dv) ? `<iframe class="rt-frame" sandbox="" title="Design version D${t.dv}" data-rt-frame="${t.dv}"></iframe>` : '<p class="rt-note">This version could not be read.</p>')
|
|
163
|
+
: '<p class="rt-note">No design version yet. Say in the chat how it should look, or attach a sample. Each cycle uses the standard look until then.</p>';
|
|
164
|
+
const save = t.dv != null && t.dv !== saved ? btn('d-accept', 'This is it', { off: t.busy }) : '';
|
|
165
|
+
const undo = V.some((v) => v.n < (Z.current || 0)) ? btn('d-undo', 'Undo', { sec: true, off: t.busy }) : '';
|
|
166
|
+
return `${stepper('dv', t.dv, V, saved)}${ask}${working}${frame}${save || undo ? `<div class="rt-foot">${undo}${save}</div>` : ''}`;
|
|
167
|
+
}
|
|
168
|
+
function cyclesHtml(t) {
|
|
169
|
+
if (!t.docs.length) return '';
|
|
170
|
+
const row = (d) => `<li><span class="rt-tag ${d.state}">${d.state === 'issued' ? 'Issued' : 'Draft'}</span><span class="rt-slot">${esc(d.slot)}${d.archived ? ' · archived' : ''}</span>`
|
|
171
|
+
+ (d.state === 'issued' ? btn((d.archived ? 'unarchive|' : 'archive|') + d.path, d.archived ? 'Bring back' : 'Archive', { sec: true, off: t.busy }) : btn('discard|' + d.path, 'Discard', { sec: true, off: t.busy })) + '</li>';
|
|
172
|
+
return `<p class="rt-label">Reports</p><ul class="rt-cyc">${t.docs.map(row).join('')}</ul><p class="rt-note">An issued report is kept for good. A draft can be discarded until it is issued.</p>`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* ── pressing ── */
|
|
176
|
+
async function act(t, fn) { t.busy = true; t.msg = ''; redraw(t); const m = await fn(); t.busy = false; if (m != null) t.msg = m; redraw(t); }
|
|
177
|
+
const why = (r, d) => (r && r.error) || d;
|
|
178
|
+
async function setSchedule(t, s) {
|
|
179
|
+
if (t.block.proposal) { t.sched = s; t.open = false; redraw(t); return; }
|
|
180
|
+
t.open = false;
|
|
181
|
+
await act(t, async () => {
|
|
182
|
+
const r = await post('/api/report-setups/edit', { id: t.block.id, schedule: s === 'off' ? { cadence: 'off' } : s });
|
|
183
|
+
if (!r || !r.ok) return 'The schedule did not change: ' + why(r, 'the page could not reach PMOS') + '.';
|
|
184
|
+
t.setup = r.setup; return 'Schedule: ' + schedWords(r.setup.status === 'paused' ? 'off' : r.setup.schedule) + '.';
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async function press(t, e) {
|
|
188
|
+
const b = e.target.closest('[data-rt]'); if (!b || b.disabled) return;
|
|
189
|
+
const [a, v] = [b.dataset.rt.split('|')[0], b.dataset.rt.slice(b.dataset.rt.indexOf('|') + 1)];
|
|
190
|
+
const cur = t.block.proposal ? t.sched : t.setup && (t.setup.status === 'paused' ? 'off' : t.setup.schedule);
|
|
191
|
+
if (a === 'sched') { t.open = !t.open; redraw(t); return; }
|
|
192
|
+
if (a === 'pick') { await setSchedule(t, schedChoices(cur)[+v]); return; }
|
|
193
|
+
if (a === 'day') { await setSchedule(t, Object.assign({}, cur, { day: v })); return; }
|
|
194
|
+
if (a === 'sched-use') { await setSchedule(t, t.block.schedule); return; }
|
|
195
|
+
if (a === 'view') { t.view = v; redraw(t); if (v === 'design' && !t.Z) { await loadDesign(t); redraw(t); } return; }
|
|
196
|
+
if (a === 'sv') { t.sv = +v; redraw(t); return; }
|
|
197
|
+
if (a === 'dv') { t.dv = +v; await renderOf(t, t.dv); redraw(t); return; }
|
|
198
|
+
if (a === 'setup') { await setUp(t); return; }
|
|
199
|
+
const id = t.block.id;
|
|
200
|
+
if (a === 's-turn') { t.busy = true; t.msg = ''; redraw(t); const r = await post('/api/report-structure/turn', { id, text: t.block.structure }); if (!r || !r.ok) { t.busy = false; t.msg = 'That did not start: ' + why(r, 'no answer') + '.'; redraw(t); return; } t.S = Object.assign({}, t.S, { running: true }); t.block = Object.assign({}, t.block, { structure: undefined }); redraw(t); poll(t, 'structure'); return; }
|
|
201
|
+
if (a === 'd-turn') { t.busy = true; t.msg = ''; redraw(t); const r = await post('/api/report-design/turn', { id, text: t.block.design, points: [] }); if (!r || !r.ok) { t.busy = false; t.msg = 'That did not start: ' + why(r, 'no answer') + '.'; redraw(t); return; } t.Z = Object.assign({}, t.Z, { running: true }); t.block = Object.assign({}, t.block, { design: undefined }); redraw(t); poll(t, 'design'); return; }
|
|
202
|
+
if (a === 's-accept') { await act(t, async () => { const r = await post('/api/report-structure/accept', { id, n: t.sv }); if (!r || !r.ok) return why(r, 'The structure was not saved.'); t.S = r.structure; return 'S' + t.sv + ' is saved. The next cycle follows it.'; }); return; }
|
|
203
|
+
if (a === 's-undo') { const V = t.S.versions.filter((x) => x.n < t.S.current); const to = V[V.length - 1].n; await act(t, async () => { const r = await post('/api/report-structure/revert', { id, n: to }); if (!r || !r.ok) return why(r, 'Undo did not go through.'); t.S = r.structure; t.sv = t.S.current; return 'Back to S' + to + '.'; }); return; }
|
|
204
|
+
if (a === 'd-accept') { await act(t, async () => { const r = await post('/api/report-design/accept', { id, n: t.dv }); if (!r || !r.ok) return why(r, 'The design was not saved.'); t.Z = r.design; return 'D' + t.dv + ' is the saved design. The next cycle follows it.'; }); return; }
|
|
205
|
+
if (a === 'd-undo') { const V = t.Z.versions.filter((x) => x.n < t.Z.current); const to = V[V.length - 1].n; await act(t, async () => { const r = await post('/api/report-design/revert', { id, n: to }); if (!r || !r.ok) return why(r, 'Undo did not go through.'); t.Z = r.design; t.dv = t.Z.current; await renderOf(t, t.dv); return 'Back to D' + to + '.'; }); return; }
|
|
206
|
+
if (a === 'discard' || a === 'archive' || a === 'unarchive') {
|
|
207
|
+
if (a === 'discard' && !(await vwConfirm(paneOf(t), { text: 'Discard this draft? It is deleted. Issued reports are not touched.', yes: 'Discard', no: 'Keep it' }))) return;
|
|
208
|
+
await act(t, async () => {
|
|
209
|
+
const r = await post('/api/report-documents/' + (a === 'discard' ? 'discard' : 'archive'), a === 'discard' ? { path: v } : { path: v, archived: a === 'archive' });
|
|
210
|
+
if (!r || !r.ok) return why(r, 'That did not go through.');
|
|
211
|
+
await load(t); return a === 'discard' ? 'The draft is discarded.' : a === 'archive' ? 'Archived. It is kept, and hidden from the list.' : 'It is back in the list.';
|
|
212
|
+
});
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (a === 'remove') {
|
|
216
|
+
if (!(await vwConfirm(paneOf(t), { text: 'Delete this template? Its schedule stops now. Its issued reports and its open draft stay.', yes: 'Delete template', no: 'Keep it' }))) return;
|
|
217
|
+
await act(t, async () => { const r = await post('/api/report-setups/remove', { id }); if (!r || !r.ok) return why(r, 'The template was not deleted.'); await load(t); return 'Template deleted. Its schedule stopped; its reports are kept.'; });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function setUp(t) {
|
|
221
|
+
const p = t.block.proposal;
|
|
222
|
+
const schedule = t.sched === 'off' ? { cadence: 'weekly', day: 'Mon', time: '09:00' } : t.sched;
|
|
223
|
+
await act(t, async () => {
|
|
224
|
+
const r = await post('/api/report-setups/setup', { proposal: { name: p.name, purpose: p.purpose || p.name, audience: p.audience, source: 'work', output: p.output, schedule,
|
|
225
|
+
sources: p.sources.length ? p.sources : ['The records of this workspace'], learned_from: 'Set up from a chat.' } });
|
|
226
|
+
if (!r || !r.ok) return 'It was not set up: ' + why(r, 'the page could not reach PMOS') + '.';
|
|
227
|
+
if (t.sched === 'off') await post('/api/report-setups/edit', { id: r.setup.id, schedule: { cadence: 'off' } });
|
|
228
|
+
// the tab now shows the set-up report
|
|
229
|
+
t.block = { kind: 'report', id: r.setup.id }; t.loaded = false; await load(t);
|
|
230
|
+
const d = r.drafted || {};
|
|
231
|
+
return 'Set up. ' + (d.path ? 'The first draft is written.' : 'The first draft was not written' + (d.error ? ': ' + d.error : '') + '.') + (t.sched === 'off' ? ' Schedule is Off, so it runs once.' : '');
|
|
232
|
+
});
|
|
233
|
+
}
|
|
@@ -9,6 +9,11 @@ import { chipActs, openLive, openFocus, mountRecord, HL_LINE } from './premium-v
|
|
|
9
9
|
import { lineItems, behindOf, whenRead } from './freshness-words.js';
|
|
10
10
|
import { splitGoal, shownUser, goalBlockHtml, goalProgressHtml, goalChipHtml, goalViewHtml, goalNow, slashMatches } from './goal-chat.js';
|
|
11
11
|
import { mdHtml, userHtml, toolLine, webKind } from './chat-md.js';
|
|
12
|
+
import { splitReport, reportChipHtml, blockSig } from './report-chat.js';
|
|
13
|
+
import { openReportTab } from './premium-report-tab.js';
|
|
14
|
+
import { openChartTab } from './premium-chart-tab.js';
|
|
15
|
+
/** A pmos-report block opens the Report tab, or the Chart tab for a chart or a dashboard (premium-reports-from-chat, slice C). */
|
|
16
|
+
export const openBlockTab = (b) => (b && b.kind === 'report' ? openReportTab(b) : openChartTab(b));
|
|
12
17
|
import { mountNotes, openNotes, flushNotes, syncNotes } from './premium-notes.js';
|
|
13
18
|
import { attachMarkup, attachRowMarkup, mountAttach, attachNames, clearAttach, syncAttach, dropFiles, splitFiles, filesHtml, openAttachment } from './premium-attach.js';
|
|
14
19
|
import { railModel, railHtml, teaser, menuCount, loudestRow, factsOf, titleOf, endAsks, DOT, WORD } from './session-rail.js';
|
|
@@ -428,9 +433,9 @@ export function sessionHtml(c, goal = null) {
|
|
|
428
433
|
const out = msgs.map((m, i) => {
|
|
429
434
|
if (m.role === 'user') return turnUser(shownUser(m.text));
|
|
430
435
|
if (m.role !== 'assistant') return `<p class="toolline" title="${esc((m.calls || []).map((x) => x.tool + (x.target ? ' ' + x.target : '')).join('\n'))}">${esc(toolLine(m.tools))}</p>`;
|
|
431
|
-
const g = splitGoal(m.text);
|
|
436
|
+
const g = splitGoal(m.text), rp = splitReport(g.text); // premium-reports-from-chat: a pmos-report block becomes a chip that opens the Report tab
|
|
432
437
|
const live = i === last && waiting && !!goal && goal.state === 'grilling';
|
|
433
|
-
return turnAgent(`<p class="agtag">Claude</p>${
|
|
438
|
+
return turnAgent(`<p class="agtag">Claude</p>${rp.text ? mdHtml(rp.text) : ''}${goalBlockHtml(g.block, { live, state: goal && goal.state })}${reportChipHtml(rp.block, i)}${chipsHtml(ctx.get(i))}`);
|
|
434
439
|
});
|
|
435
440
|
if (goalProgressHtml(goal)) out.push(goalChipHtml(goal)); // the goal itself is in the viewer's Goal tab (goalView below)
|
|
436
441
|
// item-chat-history: an ended session keeps its conversation on the item; the next message picks it up
|
|
@@ -478,6 +483,7 @@ export function drawThread(th, key, conv) {
|
|
|
478
483
|
ctxAuto(key, conv);
|
|
479
484
|
S.goal = th.goal || null; S.draft = readyDraft(conv); S.session = th.session || null;
|
|
480
485
|
goalView(key, conv);
|
|
486
|
+
reportAuto(key, conv);
|
|
481
487
|
const go = $('#askGo'); if (go) go.disabled = !!th.working; // an earlier read-only run still answering
|
|
482
488
|
const n = $('#askNote'); if (n) n.textContent = th.working ? 'The agent is answering. You can write again when it has.' : conv && conv.ask ? 'Claude is waiting for your answer above.' : CHAT_NOTE;
|
|
483
489
|
if (atEnd) b.scrollTop = b.scrollHeight;
|
|
@@ -518,7 +524,7 @@ function ctxPeek(it) {
|
|
|
518
524
|
const f = $('#askF'); if (!f) return;
|
|
519
525
|
if (!b) { f.insertAdjacentHTML('beforebegin', '<button type="button" class="ctxpeek" id="ctxPeek" hidden></button>'); b = $('#ctxPeek'); }
|
|
520
526
|
b.innerHTML = `<span>${esc(it.sub)} · <b>${esc(it.title)}</b></span><em>View</em>`; b.hidden = false;
|
|
521
|
-
b.onclick = () => { ctxPeek(null); if (it.kind === 'goal') openGoal(); else openCtx(it, ctxWhere()); };
|
|
527
|
+
b.onclick = () => { ctxPeek(null); if (it.kind === 'goal') openGoal(); else if (it.kind === 'report') openBlockTab(it.block); else openCtx(it, ctxWhere()); };
|
|
522
528
|
CTX.peekTimer = setTimeout(() => ctxPeek(null), 15000);
|
|
523
529
|
}
|
|
524
530
|
$('#dBody').addEventListener('click', (e) => {
|
|
@@ -552,6 +558,32 @@ $('#dBody').addEventListener('click', (e) => {
|
|
|
552
558
|
e.preventDefault(); openGoal();
|
|
553
559
|
if (innerWidth < 1000 && !chatPage()) setTab('out');
|
|
554
560
|
});
|
|
561
|
+
/* premium-reports-from-chat (R1): the newest pmos-report block in a finished answer opens the Report tab by itself, once, on a desktop, and is
|
|
562
|
+
* offered in the bar over the box on a phone. A block that was already there when the chat opened opens nothing; its chip opens it. */
|
|
563
|
+
const RV = { key: null, sig: null };
|
|
564
|
+
function newestReport(conv) {
|
|
565
|
+
const ms = (conv && conv.messages) || [];
|
|
566
|
+
for (let i = ms.length - 1; i >= 0; i--) { if (ms[i].role !== 'assistant') continue; const b = splitReport(splitGoal(ms[i].text).text).block; if (b) return b; }
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
function reportAuto(key, conv) {
|
|
570
|
+
const busy = !conv || conv.ask || conv.turn === 'agent' || conv.turn === 'tool';
|
|
571
|
+
if (busy && RV.key === key) return;
|
|
572
|
+
const b = newestReport(conv), sig = blockSig(b);
|
|
573
|
+
const first = RV.key !== key; RV.key = key;
|
|
574
|
+
const was = RV.sig; RV.sig = sig;
|
|
575
|
+
if (first || !b || sig === was) return;
|
|
576
|
+
const P = b.proposal, name = P ? (b.kind === 'chart' ? P.title || P.measure : P.name) : b.id;
|
|
577
|
+
if (desk()) openBlockTab(b); else ctxPeek({ kind: 'report', block: b, title: name, sub: b.kind === 'report' ? 'Report' : b.kind === 'chart' ? 'Chart' : 'Dashboard' });
|
|
578
|
+
}
|
|
579
|
+
$('#dBody').addEventListener('click', (e) => {
|
|
580
|
+
const c = e.target.closest('[data-report-open]'); if (!c) return;
|
|
581
|
+
e.preventDefault();
|
|
582
|
+
const m = ((S.conv && S.conv.messages) || [])[+c.dataset.reportOpen];
|
|
583
|
+
const b = m ? splitReport(splitGoal(m.text).text).block : null;
|
|
584
|
+
if (b) openBlockTab(b);
|
|
585
|
+
if (innerWidth < 1000 && !chatPage()) setTab('out');
|
|
586
|
+
});
|
|
555
587
|
/** The draft of the newest ready goal block in the conversation, which Start sends as the confirmed goal. */
|
|
556
588
|
function readyDraft(conv) {
|
|
557
589
|
const ms = (conv && conv.messages) || [];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
@font-face{font-family:"Space Grotesk";src:url(/vendor/space-grotesk-var.woff2) format("woff2");font-weight:300 700;font-display:swap}
|
|
2
|
+
@font-face{font-family:"IBM Plex Mono";src:url(/vendor/ibm-plex-mono-400.woff2) format("woff2");font-weight:400;font-display:swap}
|
|
3
|
+
@font-face{font-family:"IBM Plex Mono";src:url(/vendor/ibm-plex-mono-500.woff2) format("woff2");font-weight:500;font-display:swap}
|
|
4
|
+
@font-face{font-family:"IBM Plex Mono";src:url(/vendor/ibm-plex-mono-700.woff2) format("woff2");font-weight:600 700;font-display:swap}
|
|
5
|
+
:root{--fs-1:11px;--fs-2:12px;--fs-3:14px;--fs-4:16px;--fs-5:20px;--fs-6:28px}
|
|
6
|
+
/* pm/premium-vw-report.css — the Report tab beside a chat (initiative premium-reports-from-chat, slice B; premium-report-tab.js).
|
|
7
|
+
* Loaded once by vwStyle('report'). Sizes are only var(--fs-1..6), weights 400/500/600 (premium-console-type.test.js). */
|
|
8
|
+
.rt{max-width:760px;margin:0 auto;padding:4px 2px 24px;display:flex;flex-direction:column;align-items:stretch;gap:12px;text-align:left}
|
|
9
|
+
.rt>*{align-self:stretch}
|
|
10
|
+
.rt .btn,.obody:has(>.rt)>.vcf .btn{display:inline-flex;align-items:center;justify-content:center;min-height:40px;padding:0 16px;border:1px solid var(--solid);border-radius:6px;background:var(--solid);color:var(--on-solid);font-size:var(--fs-2);font-weight:600;white-space:nowrap}
|
|
11
|
+
.rt .btn.sec,.obody:has(>.rt)>.vcf .btn.sec{background:transparent;border-color:var(--hair);color:var(--ink)}
|
|
12
|
+
.rt .btn:disabled{opacity:.5;cursor:default}
|
|
13
|
+
.rt-eye{margin:0;font:500 var(--fs-1) var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3)}
|
|
14
|
+
.rt-h{margin:0;font-size:var(--fs-5);font-weight:600;color:var(--ink);overflow-wrap:anywhere}
|
|
15
|
+
.rt-sub{margin:0;font-size:var(--fs-3);color:var(--ink-2)}
|
|
16
|
+
.rt-meta,.rt-note{margin:0;font-size:var(--fs-2);color:var(--ink-3)}
|
|
17
|
+
.rt-label{margin:6px 0 0;font-size:var(--fs-2);font-weight:600;color:var(--ink-2)}
|
|
18
|
+
.rt-msg{margin:0;padding:10px 12px;border-radius:8px;background:var(--well);font-size:var(--fs-3);color:var(--ink)}
|
|
19
|
+
.rt-row{display:flex;flex-direction:column;gap:8px;align-items:flex-start}
|
|
20
|
+
.rt-chip{align-self:flex-start;display:inline-flex;flex-direction:column;align-items:flex-start;gap:1px;min-height:44px;padding:6px 14px;border:1px solid var(--hair);border-radius:6px;background:var(--card-solid,var(--card));color:var(--ink);text-align:left;cursor:pointer}
|
|
21
|
+
.rt-chip em{font-style:normal;font-size:var(--fs-1);color:var(--ink-3)}
|
|
22
|
+
.rt-chip b{font-size:var(--fs-3);font-weight:600}
|
|
23
|
+
.rt-menu{display:flex;flex-direction:column;gap:2px;width:100%;max-width:360px;padding:6px;border:1px solid var(--hair);border-radius:8px;background:var(--card-solid,var(--card));box-shadow:var(--card-shadow)}
|
|
24
|
+
.rt-menu>button{min-height:44px;padding:0 12px;border-radius:6px;text-align:left;font-size:var(--fs-3);color:var(--ink);background:none}
|
|
25
|
+
.rt-menu>button[aria-checked="true"]{background:var(--well);font-weight:600}
|
|
26
|
+
@media (hover:hover){.rt-menu>button:hover{background:var(--well)}}
|
|
27
|
+
.rt-menu .rt-note{padding:6px 12px}
|
|
28
|
+
.rt-days{display:flex;flex-wrap:wrap;gap:6px;padding:6px 6px 2px}
|
|
29
|
+
.rt-days .btn{min-height:44px;min-width:52px;padding:0 10px}
|
|
30
|
+
.rt-ask{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:10px;padding:10px 12px;border-radius:8px;background:var(--well)}
|
|
31
|
+
.rt-ask p{margin:0;font-size:var(--fs-3);color:var(--ink-2);flex:1 1 200px;min-width:0;overflow-wrap:anywhere}
|
|
32
|
+
.rt-ask b{color:var(--ink);font-weight:600}
|
|
33
|
+
.rt .rt-seg{display:inline-flex;gap:4px;padding:3px;border-radius:6px;background:var(--well);align-self:flex-start}
|
|
34
|
+
.rt-seg .btn.sec{border-color:transparent}
|
|
35
|
+
.rt-seg .btn{min-height:40px;border-radius:6px}
|
|
36
|
+
.rt-ver{display:flex;align-items:center;gap:6px;font:500 var(--fs-2) var(--mono);color:var(--ink-2)}
|
|
37
|
+
.rt-arrow{width:44px;height:44px;border:1px solid var(--hair);border-radius:6px;background:var(--card-solid,var(--card));color:var(--ink);font-size:var(--fs-4);cursor:pointer}
|
|
38
|
+
.rt-arrow:disabled{opacity:.4;cursor:default}
|
|
39
|
+
.rt-secs{margin:0;padding:0;list-style:none;border:1px solid var(--hair);border-radius:8px;background:var(--card-solid,var(--card))}
|
|
40
|
+
.rt-secs li{display:flex;flex-direction:column;gap:2px;padding:10px 14px;border-top:1px solid var(--hair)}
|
|
41
|
+
.rt-secs li:first-child{border-top:0}
|
|
42
|
+
.rt-secs b{font-size:var(--fs-3);font-weight:600;color:var(--ink)}
|
|
43
|
+
.rt-secs span{font-size:var(--fs-2);color:var(--ink-3)}
|
|
44
|
+
.rt-frame{width:100%;aspect-ratio:16/10;border:1px solid var(--hair);border-radius:8px;background:var(--card-solid,var(--card))}
|
|
45
|
+
.rt-cyc{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:6px}
|
|
46
|
+
.rt-cyc li{display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-height:44px;padding:4px 4px 4px 10px;border:1px solid var(--hair);border-radius:8px}
|
|
47
|
+
.rt-slot{flex:1;min-width:0;font-size:var(--fs-3);color:var(--ink)}
|
|
48
|
+
.rt-tag{padding:2px 8px;border-radius:6px;font:500 var(--fs-1) var(--mono);text-transform:uppercase}
|
|
49
|
+
.rt-tag.draft{background:var(--well);color:var(--ink-2)}
|
|
50
|
+
.rt-tag.issued{background:color-mix(in srgb,var(--good) 16%,transparent);color:var(--ink)}
|
|
51
|
+
.rt-foot{display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end}
|
|
52
|
+
.rt-foot .btn{min-height:44px}
|
|
53
|
+
.rt-end{margin-top:6px;padding-top:12px;border-top:1px solid var(--hair)}
|
|
54
|
+
.rt-del{color:var(--bad)}
|
|
55
|
+
.rt button:focus-visible{outline:2px solid var(--ember);outline-offset:2px}
|
|
56
|
+
/* the Chart tab (premium-chart-tab.js, slice C): a chart at a readable size, a dashboard's charts side by side where they fit */
|
|
57
|
+
.rt .ct-tile{max-width:460px}
|
|
58
|
+
.rt .ct-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px;margin:0}
|
|
59
|
+
.rt .ct-grid .nempty{align-self:start;padding:12px 14px;border-radius:8px;background:var(--well)}
|
|
60
|
+
.rt .ct-grid .nempty p{margin:0;font-size:var(--fs-2);color:var(--ink-2)}
|