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.
Files changed (37) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-insights-test.js +16 -21
  7. package/workspace/changelog.json +24 -0
  8. package/workspace/guide/briefing-premium.md +19 -9
  9. package/workspace/lib/briefing-premium-agent.js +3 -0
  10. package/workspace/lib/report-chat.js +37 -0
  11. package/workspace/lib/report-setups.js +49 -7
  12. package/workspace/lib/routes-report-setups.js +38 -7
  13. package/workspace/package-lock.json +2 -2
  14. package/workspace/package.json +1 -1
  15. package/workspace/premium-chat-chart-tab-test.js +150 -0
  16. package/workspace/premium-chat-report-tab-test.js +127 -0
  17. package/workspace/public/pm/goal-chat.js +2 -1
  18. package/workspace/public/pm/premium-chart-draw.js +58 -0
  19. package/workspace/public/pm/premium-chart-tab.js +157 -0
  20. package/workspace/public/pm/premium-chat.js +8 -2
  21. package/workspace/public/pm/premium-insights.js +17 -79
  22. package/workspace/public/pm/premium-report-tab.js +233 -0
  23. package/workspace/public/pm/premium-shell.js +35 -3
  24. package/workspace/public/pm/premium-vw-report.css +60 -0
  25. package/workspace/public/pm/premium.css +1 -120
  26. package/workspace/public/pm/report-chat.js +89 -0
  27. package/workspace/test-lists/premium-chat-chart-tab.json +12 -0
  28. package/workspace/test-lists/premium-chat-report-tab.json +12 -0
  29. package/workspace/premium-studio-chart-test.js +0 -193
  30. package/workspace/premium-studio-report-test.js +0 -277
  31. package/workspace/premium-studio-test.js +0 -185
  32. package/workspace/public/pm/premium-studio-design.js +0 -298
  33. package/workspace/public/pm/premium-studio-report.js +0 -291
  34. package/workspace/public/pm/premium-studio.js +0 -453
  35. package/workspace/test-lists/premium-studio-chart.json +0 -13
  36. package/workspace/test-lists/premium-studio-report.json +0 -9
  37. package/workspace/test-lists/premium-studio.json +0 -9
@@ -1,291 +0,0 @@
1
- /* pm/premium-studio-report.js — the Insight Studio's Report mode on the premium Insights page (initiative premium-studio-report). premium-studio.js hands
2
- * Report mode to this module: the brief, its tray, the library rows, the preview, the checks, the footer and the conversation.
3
- *
4
- * Two drafts. A NEW report is a brief in the page (title, what it answers, audience, format, schedule, draw from). A turn changes it and writes nothing.
5
- * Set it up posts POST /api/report-setups/setup with the proposal, or POST /api/report-setups/from-dashboard for the board's dashboard.
6
- * A SET-UP report is read from GET /api/report-structure. Its sections change through its structure: Leave out posts POST /api/report-structure/remove,
7
- * a turn posts POST /api/report-structure/turn (one headless job that proposes the next version), Undo posts .../revert to the version before, and
8
- * Use this structure posts .../accept. Every POST goes through the page's hand (P.setup, P.structure), behind the launch nonce. The frame of a new report
9
- * is frozen (D78 as amended by D86), so its sections are shown, not edited. Nothing is sent outward. */
10
- import { $, esc } from './premium-shell.js';
11
- import * as DES from './premium-studio-design.js';
12
-
13
- const OUT = { 'google-slides': ['Google Slides', 'A deck. Leadership usually reads one.'], 'google-doc': ['Google Doc', 'A document to read through.'], 'google-sheets': ['Google Sheets', 'A spreadsheet of the numbers.'], confluence: ['Confluence page', 'A page in your wiki.'], pdf: ['PDF', 'A file to keep or attach.'] };
14
- const CAD = { daily: 'Daily', weekly: 'Weekly', 'bi-weekly': 'Every two weeks', monthly: 'Monthly' };
15
- const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
16
- const DAYN = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
17
- /* The frame every instant draft writes, in its frozen order (lib/report-draft.js FRAME), and what each section holds (lib/report-setups.js SECTION_NOTES). */
18
- const FRAME = [['headline', 'Headline', 'The one thing the readers must know this cycle.'], ['timeline', 'Timeline', 'The dated items, written in full.'],
19
- ['initiatives', 'Initiatives', 'One block for each initiative: done, in progress, next and the key open item.'], ['new', 'New since last report', 'What is new in the window, each with its date.'],
20
- ['decided', 'Decided this cycle', 'The decisions, marked Decided or Acknowledged.'], ['needs', 'Needs your call', 'The asks to the readers: what, who, by when.'], ['sources', 'Sources', 'The sources reached and not reached.']];
21
- const FIXED = { headline: 'Every report leads with its answer.', needs: 'Every report names what it needs from its readers.', sources: 'Every report lists its sources, so each number can be checked.' };
22
- const DOCI = '<svg class="i" viewBox="0 0 24 24"><path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/></svg>';
23
- const SECW = /\b(sections?|headline|timeline|initiatives|decided|decisions?|needs your call|sources|new since)\b/;
24
- const LEAD = /\b(lead(ership)?|exec(utive)?s?|the board|directors?|vps?|heads? of|c-?level|cxo|ceo|cto|cpo)\b/i;
25
- const HELP = 'I understand: call it something, it answers something (or a question), for an audience, a format (slides, a doc, sheets, Confluence, a PDF), daily, weekly on a day, every two weeks, monthly, from my work or from the dashboard, undo, and start a new one.';
26
- const HELPS = 'Tell me how to shape the sections in your own words, for example: leave out the timeline, or put the decisions first. PMOS proposes the next version; nothing is saved until you press Use this structure. Undo goes back one version.';
27
-
28
- let X = null; // the Studio's hand: { st, P, chip, opt, field, draw, plural }
29
- export function useStudio(x) { X = x; DES.useStudio({ get st() { return x.st; }, get P() { return x.P; }, chip: x.chip, draw: x.draw, say: x.say, restream: x.restream, converse: x.converse, r: () => (x.st ? x.st.r : null) }); }
30
- const design = (d) => d.kind === 'setup' && d.tab === 'design';
31
- const st = () => X.st;
32
- const r = () => X.st.r;
33
- const board = () => X.P.M.board || {};
34
- const setups = () => ((X.P.M.reports || {}).setups || []);
35
- const clean = (s) => s.trim().replace(/^["'“]|["'”]$/g, '').replace(/[.\s]+$/, '').trim();
36
- const outName = (o) => (OUT[o] ? OUT[o][0] : o || 'Not set');
37
- const lead = (aud) => LEAD.test(aud || '');
38
- function schedLabel(d) {
39
- if (d.cadence === 'daily') return 'Daily at 09:00';
40
- if (d.cadence === 'monthly') return 'Monthly on the 1st at 09:00';
41
- return (d.cadence === 'weekly' ? 'Weekly, ' : 'Every other ') + DAYN[d.day] + (d.cadence === 'weekly' ? 's' : '') + ' at 09:00';
42
- }
43
-
44
- /* ── the drafts ── */
45
- export function blankReport() {
46
- return { kind: 'new', title: ((board().name || 'Board') + ' weekly report').slice(0, 80), purpose: '', audience: 'The team', output: 'google-doc', cadence: 'weekly', day: 'Mon', from: 'work' };
47
- }
48
- export function setupReport(s) {
49
- const d = { kind: 'setup', id: s.id, name: s.name, audience: s.audience, output: s.output, label: s.label, S: null, loading: true, working: false, err: '', tab: 'structure', Z: DES.fresh() };
50
- load(d);
51
- return d;
52
- }
53
- async function load(d) {
54
- const res = await X.P.structure.get(d.id);
55
- if (r() !== d) return;
56
- d.loading = false;
57
- if (!res || res.ok !== true) { d.err = (res && res.error) || 'The structure of this report could not be read.'; X.draw(); return; }
58
- d.S = res.structure; d.err = '';
59
- // The conversation is kept in the structure log: show what was said before, failed runs included, and pick up a run that is still going.
60
- X.replay((d.S.log || []).map((l) => ({ who: l.who === 'pmos' ? 'a' : 'u', text: l.text })));
61
- if (d.S.running) { d.working = true; X.draw(); waitFor(d, (d.S.log || []).length).then((a) => { if (r() === d) X.say(a); }); return; }
62
- X.draw();
63
- }
64
- const plan = (d) => (d.S && d.S.plan) || null;
65
- const shownN = (d) => (d.S ? d.S.current : null);
66
- const savedN = (d) => (d.S ? d.S.saved : null);
67
- const outline = (d) => (plan(d) ? plan(d).outline : FRAME.map(([id, title]) => ({ id, title, fixed: !!FIXED[id], charts: [], notes: '', show: '' })));
68
-
69
- /* ── the brief ── */
70
- export function brief() {
71
- const d = r(), c = X.chip;
72
- if (design(d)) return DES.brief(d);
73
- if (d.kind === 'new') {
74
- return `<div class="stbr" role="group" aria-label="Brief">${c('title', 'Title', d.title || 'Not set')}${c('purpose', 'What it answers', d.purpose || 'Not set')}${c('aud', 'Audience', d.audience || 'Not set')}${c('out', 'Format', outName(d.output))}${c('sched', 'Schedule', schedLabel(d))}${c('from', 'Draw from', d.from === 'dash' ? 'The board\'s dashboard' : 'Your work')}${d.from === 'work' ? c('secs', 'Sections', String(FRAME.length)) : ''}</div>`;
75
- }
76
- const n = shownN(d), s = savedN(d);
77
- return `<div class="stbr" role="group" aria-label="Brief">${DES.tabs(d)}${c('facts', 'Report', d.name)}${c('secs', 'Sections', d.loading ? 'Reading' : String(outline(d).length))}${c('ver', 'Version', d.loading ? 'Reading' : n == null ? 'None yet' : 'S' + n + (s === n ? ', saved' : s != null ? ', saved is S' + s : ', not saved'))}</div>`;
78
- }
79
- export function tray(p) {
80
- const d = r(), o = X.opt, f = X.field;
81
- if (design(d)) return DES.tray(d, p);
82
- if (d.kind === 'new') {
83
- if (p === 'title') return f('title', d.title, 'The name of the report', 80);
84
- if (p === 'purpose') return f('purpose', d.purpose, 'For example: Are partners activating, and what do we decide?', 400) + '<p class="note">One line: what the report answers for its readers. The headline leads with it.</p>';
85
- if (p === 'aud') return f('audience', d.audience, 'Who reads it', 120) + `<div class="sor"><button type="button" class="dmcta alt" data-st="set|audience|The team">The team</button><button type="button" class="dmcta alt" data-st="set|audience|Leadership">Leadership</button></div>`;
86
- if (p === 'out') return `<div class="sol">${Object.keys(OUT).map((k) => o('set|output|' + k, OUT[k][0], OUT[k][1], d.output === k)).join('')}</div><p class="note">PMOS drafts the report as a file in the repository. The format names the copy you keep in step with it. Nothing is sent from here.</p>`;
87
- if (p === 'sched') {
88
- return `<div class="sol">${Object.keys(CAD).map((k) => o('set|cadence|' + k, CAD[k], k === 'monthly' ? 'On the 1st' : k === 'daily' ? 'Every day' : 'On ' + DAYN[d.day], d.cadence === k)).join('')}</div>`
89
- + (d.cadence === 'weekly' || d.cadence === 'bi-weekly' ? `<div class="sor">${DAYS.map((k) => `<button type="button" class="dmcta${d.day === k ? '' : ' alt'}" data-st="set|day|${k}" aria-pressed="${d.day === k}">${DAYN[k]}</button>`).join('')}</div>` : '') + '<p class="note">PMOS drafts it at 09:00 on its day. A draft is only a draft until you issue it.</p>';
90
- }
91
- if (p === 'from') return `<div class="sol">${o('set|from|work', 'Your work', 'The records of this workspace: initiatives, decisions, releases and asks.', d.from === 'work')}${board().id ? o('set|from|dash', 'The board\'s dashboard', 'The charts of ' + (board().name || 'this board') + '\'s dashboard, in its order, drafted on its day.', d.from === 'dash') : ''}</div>`;
92
- if (p === 'secs') return `<ul class="sul">${FRAME.map(([, t, w]) => `<li><span>${esc(t)}<small>${esc(w)}</small></span></li>`).join('')}</ul><p class="note">A new report always has these sections, in this order. Once it is set up, you can shape them here in words.</p>`;
93
- return '';
94
- }
95
- if (p === 'facts') return `<ul class="sul"><li><span>Audience<small>${esc(d.audience || 'Not named')}</small></span></li><li><span>Format<small>${esc(outName(d.output))}</small></span></li><li><span>Schedule<small>${esc(d.label || 'Not set')}</small></span></li></ul><p class="note">These are set when the report is set up. This page does not change them.</p>`;
96
- if (p === 'secs') {
97
- if (d.loading) return '<p class="note">Reading the structure.</p>';
98
- const L = outline(d);
99
- return `<ul class="sul">${L.map((x) => `<li><span>${esc(x.title)}${FIXED[x.id] ? `<small>${esc(FIXED[x.id])}</small>` : x.notes ? `<small>${esc(x.notes)}</small>` : ''}</span><span class="stlc">${FIXED[x.id] ? '<small>Always in</small>' : plan(d) ? `<button type="button" data-st="rsec|${esc(x.id)}" aria-label="Leave out ${esc(x.title)}"${d.working ? ' disabled' : ''}>Leave out</button>` : ''}</span></li>`).join('')}</ul>`
100
- + (plan(d) ? '<p class="note">Leave out makes the next version without that section. To add or move one, say it.</p>' : '<p class="note">This report has no structure yet, so each cycle uses this frame. Say how to shape it, and PMOS proposes the first version.</p>');
101
- }
102
- if (p === 'ver') {
103
- const V = (d.S && d.S.versions) || [];
104
- return V.length ? `<ul class="sul">${V.slice().reverse().map((v) => `<li><span>S${v.n}${v.n === savedN(d) ? ' · saved' : ''}${v.n === shownN(d) ? ' · shown' : ''}<small>${esc(v.turn || '')}</small></span></li>`).join('')}</ul><p class="note">Undo goes back one version. Use this structure saves the version shown.</p>` : '<p class="note">No version yet. Say how to shape the report.</p>';
105
- }
106
- return '';
107
- }
108
-
109
- /* ── the library: the board's set-up reports ── */
110
- export function libRows() {
111
- const L = setups(), d = r();
112
- const rows = L.map((s) => `<button type="button" class="stli" data-st="libr|${esc(s.id)}"${!s.fromWork || (d.kind === 'setup' && d.id === s.id) ? ' disabled' : ''}><span class="stlic" aria-hidden="true">${DOCI}</span><span><b>${esc(s.name)}</b><small>${esc([s.label, s.audience ? 'for ' + s.audience : ''].filter(Boolean).join(' · '))}</small></span><em>${!s.fromWork ? 'Follows its dashboard' : d.kind === 'setup' && d.id === s.id ? 'Open' : 'Shape it'}</em></button>`).join('');
113
- return `<p class="label">Set-up reports · ${L.length}</p>${L.length ? `<div class="stlg">${rows}</div>` : '<p class="note">No report is set up yet. Fill the brief and press Set it up.</p>'}`;
114
- }
115
-
116
- /* ── the preview ── */
117
- export function preview() {
118
- const d = r();
119
- if (design(d)) return DES.preview(d);
120
- if (d.kind === 'new') {
121
- const secs = d.from === 'work' ? FRAME.map(([, t, w]) => `<section class="stsec"><h4>${esc(t)}</h4><p class="mut">${esc(w)}</p></section>`).join('')
122
- : `<p class="note">Drawn from ${esc(board().name || 'the board')}'s dashboard: each of its charts, in its order, as the dashboard reads them on the report's day.</p>`;
123
- return `<div class="stpvw"><h3 class="ndt">${esc(d.title || 'Untitled report')}</h3><p class="mut stuse">${esc(d.purpose || 'It does not say what it answers yet.')}</p><p class="stsrc">For ${esc(d.audience || 'no one yet')} · ${esc(outName(d.output))} · ${esc(schedLabel(d))}</p>${secs}<p class="note">Nothing is drafted until you press Set it up. The first draft is written then, as a file.</p></div>`;
124
- }
125
- if (d.loading) return '<div class="stpvw"><p class="note">Reading the structure of this report.</p></div>';
126
- if (d.err) return `<div class="stpvw"><p class="note">${esc(d.err)}</p></div>`;
127
- const P = plan(d), names = new Map((P ? P.charts : []).map((c) => [c.id, c.name || c.id]));
128
- const secs = outline(d).map((x) => `<section class="stsec"><h4>${esc(x.title)}${FIXED[x.id] ? '<span class="npin2">Always in</span>' : ''}</h4>${x.charts && x.charts.length ? `<p class="mut">Charts: ${esc(x.charts.map((c) => names.get(c) || c).join(', '))}</p>` : ''}${x.notes ? `<p class="mut">${esc(x.notes)}</p>` : ''}${!P ? `<p class="mut">${esc((FRAME.find((f) => f[0] === x.id) || ['', '', ''])[2])}</p>` : ''}</section>`).join('');
129
- const pu = P && P.purpose;
130
- return `<div class="stpvw"><h3 class="ndt">${esc(d.name)}${d.S && d.S.current != null ? `<span class="npin2">S${d.S.current}</span>` : ''}</h3>${pu && pu.decision ? `<p class="mut stuse">${esc(pu.decision)}</p>` : ''}<p class="stsrc">For ${esc(d.audience || 'no one named')} · ${esc(outName(d.output))} · ${esc(d.label || '')}</p>${secs}${d.working ? '<p class="note" role="status">PMOS is working on the next version.</p>' : ''}</div>`;
131
- }
132
-
133
- /* ── the checks ── */
134
- export function checks() {
135
- const d = r();
136
- if (design(d)) return DES.checks(d);
137
- if (d.kind === 'new') {
138
- const dup = setups().some((s) => s.name.toLowerCase() === d.title.trim().toLowerCase());
139
- return [
140
- { ok: !!d.purpose.trim(), l: 'It says what it answers', d: d.purpose.trim() ? '"' + d.purpose.trim() + '"' : 'There is nothing for the headline to answer.', fix: ['Say what it answers', 'chip|purpose'] },
141
- { ok: !!d.audience.trim(), l: 'It names its audience', d: d.audience.trim() ? 'For ' + d.audience.trim() + '.' : 'Without an audience, Needs your call stays empty.', fix: ['Name the audience', 'chip|aud'] },
142
- { ok: !(lead(d.audience) && d.output !== 'google-slides'), l: 'The format fits the audience', d: lead(d.audience) && d.output !== 'google-slides' ? 'Leadership usually reads a deck.' : 'The format suits the audience.', fix: ['Make it slides', 'set|output|google-slides'] },
143
- { ok: !!d.title.trim() && !dup, l: 'The title is new', d: !d.title.trim() ? 'Give it a title.' : dup ? 'A report called "' + d.title.trim() + '" is set up already.' : 'No set-up report has this title.', fix: ['Change the title', 'chip|title'] },
144
- { ok: true, l: 'It leads with the answer', d: d.from === 'work' ? 'The frame starts with the headline.' : 'It follows the dashboard. Put the chart that answers first on the dashboard.' },
145
- ];
146
- }
147
- const L = outline(d), n = shownN(d), s = savedN(d);
148
- return [
149
- { ok: true, l: 'It leads with the answer', d: 'The headline is first and always in.' },
150
- { ok: true, l: 'It names the decision', d: 'Needs your call is always in, so the readers see what is asked of them.' },
151
- { ok: true, l: 'It shows its sources', d: 'Sources is always in, so each number can be checked.' },
152
- { ok: !(lead(d.audience) && L.length > 5), l: 'The length fits the audience', d: lead(d.audience) ? L.length + ' sections. Leadership reads five or fewer.' : L.length + ' sections for ' + (d.audience || 'its readers') + '.', fix: ['Ask to shorten it', 'say|Keep it to five sections or fewer.'] },
153
- { ok: n != null && n === s, l: 'The version shown is saved', d: n == null ? 'There is no structure yet. Say how to shape it.' : n === s ? 'S' + n + ' is the saved structure. The next cycle follows it.' : 'S' + n + ' is not saved. The next cycle follows ' + (s != null ? 'S' + s : 'the frame') + '.', fix: n != null ? ['Use this structure', 'save'] : null },
154
- ];
155
- }
156
- export function guide() {
157
- const d = r();
158
- if (design(d)) return DES.guide(d);
159
- return d.kind === 'new' ? 'A report leads with the answer, then the evidence, then what it needs from the reader.'
160
- : 'Shape the sections of ' + esc(d.name) + ' in words. PMOS proposes each version. <button type="button" class="lk" data-st="new">Start a new report instead</button>';
161
- }
162
- export function footer() {
163
- const d = r(), s = st();
164
- if (design(d)) { const f = DES.footer(d); return { undo: f.undo, cta: f.cta, off: f.off || s.busy }; }
165
- if (d.kind === 'new') return { undo: s.h.rep.length > 0, cta: 'Set it up', off: s.busy };
166
- const n = shownN(d);
167
- return { undo: !d.working && !!(d.S && d.S.versions.some((v) => v.n < n)), cta: 'Use this structure', off: s.busy || d.working || n == null || n === savedN(d) };
168
- }
169
-
170
- /* ── doing things ── */
171
- export function set(f, v) {
172
- const d = r(); if (d.kind !== 'new') return;
173
- if (f === 'cadence' && CAD[v]) d.cadence = v;
174
- else if (f === 'day' && DAYS.includes(v)) { d.day = v; if (d.cadence !== 'weekly' && d.cadence !== 'bi-weekly') d.cadence = 'weekly'; }
175
- else if (f === 'output' && OUT[v]) d.output = v;
176
- else if (f === 'from') d.from = v === 'dash' && board().id ? 'dash' : 'work';
177
- else if (f === 'audience') d.audience = v;
178
- }
179
- /* Undo on a set-up report goes back to the version before the one shown (POST .../revert). → a promise of the answer, or null when there is none. */
180
- export function undoSetup() {
181
- if (design(r())) return DES.undo(r()).then((a) => a || 'I changed nothing. There is no earlier version to go back to.');
182
- const d = r(), n = shownN(d), V = ((d.S && d.S.versions) || []).filter((v) => v.n < n);
183
- if (!V.length || d.working) return null;
184
- const to = V[V.length - 1].n;
185
- return X.P.structure.post('revert', d.id, { n: to }).then((res) => {
186
- if (!res || res.ok !== true) return 'That did not go through: ' + ((res && res.error) || 'the structure could not be changed') + '.';
187
- d.S = res.structure; return 'Done: back to S' + to + '. The next turn builds on it.';
188
- });
189
- }
190
- export async function leaveOut(id) {
191
- const d = r(), x = outline(d).find((o) => o.id === id); if (!x || d.working) return;
192
- st().busy = true; st().msg = 'Leaving out ' + x.title + '.'; X.draw(['ft']);
193
- const res = await X.P.structure.post('remove', d.id, { kind: 'section', ref: id });
194
- st().busy = false;
195
- if (!res || res.ok !== true) { st().msg = (res && res.error) || 'That section could not be left out.'; X.draw(); return; }
196
- d.S = res.structure; st().msg = 'Made S' + d.S.current + ' without ' + x.title + '. It is not saved yet.'; X.draw();
197
- }
198
- export async function save() {
199
- const d = r(), s = st();
200
- if (design(d)) return DES.keep(d);
201
- if (d.kind === 'setup') {
202
- const n = shownN(d); if (n == null || n === savedN(d)) return;
203
- s.busy = true; s.msg = 'Saving the structure.'; X.draw(['ft']);
204
- const res = await X.P.structure.post('accept', d.id, { n });
205
- s.busy = false;
206
- if (!res || res.ok !== true) { s.msg = (res && res.error) || 'The structure could not be saved.'; X.draw(); return; }
207
- d.S = res.structure; s.msg = 'S' + n + ' is saved as the structure. The next cycle follows it.'; X.draw(); X.P.reportsChanged();
208
- return;
209
- }
210
- const title = d.title.trim(), purpose = d.purpose.trim(), audience = d.audience.trim();
211
- if (!title) { s.msg = 'Give the report a title.'; X.draw(['ft']); return; }
212
- if (!purpose && d.from === 'work') { s.msg = 'Say what the report answers, in one line.'; X.draw(['ft']); return; }
213
- if (!audience) { s.msg = 'Name the audience.'; X.draw(['ft']); return; }
214
- const schedule = { cadence: d.cadence, time: '09:00', ...(d.cadence === 'weekly' || d.cadence === 'bi-weekly' ? { day: d.day } : {}), ...(d.cadence === 'monthly' ? { dayOfMonth: 1 } : {}) };
215
- s.busy = true; s.msg = 'Setting it up.'; X.draw(['ft']);
216
- const res = d.from === 'dash'
217
- ? await X.P.setup('from-dashboard', { key: 'board:' + board().id, name: title, output: d.output, schedule, audience })
218
- : await X.P.setup('setup', { proposal: { name: title, purpose, audience, source: 'work', output: d.output, schedule, sources: ['The records of this workspace'], learned_from: 'Set up in the Insight Studio.' } });
219
- s.busy = false;
220
- if (!res || res.ok !== true) { s.msg = (res && res.error) || 'The report could not be set up.'; X.draw(['ft']); return; }
221
- const dr = res.drafted || {};
222
- X.done('Set up "' + title + '". ' + (d.from === 'dash' ? 'It is drafted from the dashboard on its day.' : dr.path ? 'The first draft is ' + dr.path + '.' : 'The first draft was not written' + (dr.error ? ': ' + dr.error : '') + '. Draft it now on the report tries again.'));
223
- }
224
-
225
- /* ── the conversation ── */
226
- export const help = () => (r().kind === 'new' ? HELP : design(r()) ? DES.help() : HELPS);
227
- export function command(t, low) {
228
- const d = r();
229
- if (design(d)) return DES.turn(d, t, low);
230
- if (d.kind === 'setup') return turn(t, low);
231
- if (/\b(start (a )?new|new report|start over)\b/.test(low)) { X.snap(); st().r = blankReport(); return 'Done: a new report. Say what it answers and who reads it.'; }
232
- const before = JSON.stringify(d), said = []; X.snap();
233
- const nm = t.match(/(?:call it|name it|title it|rename it to|called|named)\s+["“]?(.+?)(?=["”]|,|;|\s+and\s+(?:it|make|for)\b|$)/i);
234
- if (nm && clean(nm[1])) { d.title = clean(nm[1]).slice(0, 80); said.push('title "' + d.title + '"'); }
235
- const pu = t.match(/(?:it answers|answers|purpose[:\s]|it is about|it's about)\s*[:-]?\s*(.+?)(?=;|$)/i);
236
- if (pu && clean(pu[1])) { d.purpose = clean(pu[1]).slice(0, 400); said.push('it answers "' + d.purpose + '"'); }
237
- else if (/\?\s*$/.test(t) && t.split(/\s+/).length >= 3) { d.purpose = t.slice(0, 400); said.push('it answers "' + d.purpose + '"'); }
238
- const au = t.match(/\baudience[:\s]+(.+?)(?=[,;]|$)/i) || t.match(/\b(?:it is |it's |write it |make it )?for\s+(leadership|the leadership|the team|my team|our team|the board|executives|the execs|stakeholders|investors)\b/i);
239
- if (au && clean(au[1])) { const a = clean(au[1]); d.audience = (/^leadership$/i.test(a) ? 'Leadership' : a.charAt(0).toUpperCase() + a.slice(1)).slice(0, 120); said.push('for ' + d.audience); }
240
- const rest = low.replace(/(?:it answers|answers|purpose[:\s]|it is about|it's about).*$/i, ' ').replace(/(?:call it|name it|title it|called|named)\s+.+?(?=,|;|$)/i, ' ');
241
- const out = /\b(slides?|deck|presentation)\b/.test(rest) ? 'google-slides' : /\b(sheets?|spreadsheet)\b/.test(rest) ? 'google-sheets' : /\bconfluence\b/.test(rest) ? 'confluence' : /\bpdf\b/.test(rest) ? 'pdf' : /\b(google doc|doc|document)\b/.test(rest) ? 'google-doc' : null;
242
- if (out && out !== d.output) { d.output = out; said.push('format: ' + OUT[out][0]); }
243
- const cad = /\b(daily|every day)\b/.test(rest) ? 'daily' : /\b(every (two|2|other) weeks?|bi-?weekly|fortnightly)\b/.test(rest) ? 'bi-weekly' : /\b(weekly|every week)\b/.test(rest) ? 'weekly' : /\b(monthly|every month)\b/.test(rest) ? 'monthly' : null;
244
- if (cad && cad !== d.cadence) { d.cadence = cad; said.push(CAD[cad].toLowerCase()); }
245
- const dy = rest.match(/\b(mon|tue|wed|thu|fri)[a-z]*days?\b/);
246
- if (dy) { const k = dy[1].charAt(0).toUpperCase() + dy[1].slice(1); if (k !== d.day || (d.cadence !== 'weekly' && d.cadence !== 'bi-weekly')) { set('day', k); said.push('on ' + DAYN[k] + 's'); } }
247
- if (/\bfrom (the |this )?(board'?s? )?dashboard\b/.test(rest)) { if (d.from !== 'dash') { set('from', 'dash'); if (d.from === 'dash') said.push('drawn from the board\'s dashboard'); else said.push('this board has no dashboard to draw from'); } }
248
- else if (/\bfrom (my|our|the) (work|records)\b/.test(rest) && d.from !== 'work') { set('from', 'work'); said.push('drawn from your work'); }
249
- if (JSON.stringify(d) === before) {
250
- st().h.rep.pop();
251
- if (SECW.test(low) && /\b(leave out|drop|remove|without|skip|move|put|first|last|add)\b/.test(low)) return 'I changed nothing: a new report always has the same sections, in the same order. Set it up, then tell me here how to shape them.';
252
- return said.length ? 'I changed nothing: ' + said.join('; ') + '.' : 'I changed nothing. ' + HELP;
253
- }
254
- st().pop = null;
255
- return 'Done: ' + said.join('; ') + '. Nothing is set up until you press Set it up.';
256
- }
257
- /* A turn on a set-up report: one structure job. Its answer is PMOS's own words from the structure log. */
258
- async function turn(t, low) {
259
- const d = r();
260
- if (/^(use this|save (it|this)|use this structure)\b/.test(low)) { await save(); return st().msg; }
261
- if (d.working) return 'PMOS is still working on the last turn. Wait for its answer.';
262
- d.working = true; X.draw();
263
- const before = d.S ? d.S.log.length : 0;
264
- const res = await X.P.structure.post('turn', d.id, { text: t });
265
- if (!res || res.ok !== true) { d.working = false; X.draw(); return 'That did not go through: ' + ((res && res.error) || 'the turn could not start') + '.'; }
266
- return waitFor(d, before);
267
- }
268
- /* Wait for the one structure job of this report, then give PMOS's own words from the log. A run that ended without a version says so. */
269
- async function waitFor(d, before) {
270
- const end = Date.now() + 240000;
271
- for (;;) {
272
- await new Promise((ok) => setTimeout(ok, 800));
273
- if (r() !== d) return 'The Studio moved on. The answer is in the report\'s structure.';
274
- const g = await X.P.structure.get(d.id);
275
- if (g && g.ok === true && !g.structure.running) {
276
- d.working = false; d.S = g.structure; X.draw();
277
- const said = g.structure.log.slice(before).filter((l) => l.who === 'pmos').pop();
278
- return said ? said.text + (said.n ? ' Shown: S' + said.n + ', not saved yet.' : '') : 'PMOS ended without an answer. Say it again, or in other words.';
279
- }
280
- if (Date.now() > end) { d.working = false; X.draw(); return 'PMOS has not answered yet. The answer will show when you open this report again.'; }
281
- }
282
- }
283
- /* The presses of a set-up report's tabs: the tab switch and the Design step (premium-studio-design.js). */
284
- export function press(a) {
285
- const d = r(); if (d.kind !== 'setup') return;
286
- if (a[0] === 'rtab') { if (a[1] === 'design' || a[1] === 'structure') DES.openTab(d, a[1]); return; }
287
- if (design(d)) DES.press(d, a);
288
- }
289
- export const afterDraw = () => { if (design(r())) DES.afterDraw(); };
290
- export const addFile = (f) => { const d = r(); if (design(d)) DES.addFile(d, f); };
291
- export const focusInput = (v) => { const i = $('#stIn'); if (i) { i.value = v; i.focus(); } };