create-pmos 0.328.0 → 0.330.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 +227 -1
- 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 +56 -25
- package/workspace/briefing-premium-test.js +3 -1
- package/workspace/changelog.json +672 -0
- package/workspace/guide/briefing-premium.md +10 -8
- package/workspace/lib/insights-premium.js +111 -26
- package/workspace/lib/kit-update.js +57 -8
- package/workspace/lib/premium-dashboards.js +25 -5
- package/workspace/lib/routes-insights-premium.js +19 -4
- package/workspace/lib/routes-premium-dashboards.js +12 -1
- package/workspace/lib/settings-store.js +3 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-report-read-test.js +4 -2
- package/workspace/premium-studio-chart-test.js +3 -3
- package/workspace/premium-studio-report-test.js +1 -1
- package/workspace/premium-studio-test.js +4 -4
- package/workspace/premium-vw-cal-test.js +3 -1
- package/workspace/premium-vw-slides-test.js +8 -4
- package/workspace/public/pm/c3-settings.js +1 -1
- package/workspace/public/pm/premium-insights.css +52 -0
- package/workspace/public/pm/premium-insights.js +129 -50
- package/workspace/public/pm/premium-shell.js +137 -3
- package/workspace/public/pm/premium-vw-cal.css +66 -42
- package/workspace/public/pm/premium-vw-cal.js +38 -17
- package/workspace/public/pm/premium.css +22 -0
- package/workspace/public/pm/premium.js +1 -1
- package/workspace/public/premium-insights.html +29 -19
- package/workspace/server.js +7 -2
- package/workspace/test-run.js +2 -0
|
@@ -18,10 +18,10 @@ Every premium page has the same top bar. On the left is where you are, then a ro
|
|
|
18
18
|
- **Chat** opens the read-only agent about the page you are on: the Briefing, My work, the board, or the initiative. On Insights, Chat opens the Insight Studio, because the Studio is that page's chat.
|
|
19
19
|
- **Sources** has a green dot when every source was read recently, and an orange dot when a source is old, was never read, failed, or the page could not read it. Hover to see which. A press opens the Sources dialog (see "Sources" below).
|
|
20
20
|
- **The bell** counts the same things the Briefing lists under what you need to do, and a press opens the Briefing.
|
|
21
|
-
- **The ⋯ menu** holds **Search** (Ctrl K), **Agent sessions** with a count, **Console**, **Theme** (Light, Dark or Auto) and **Settings**. On the Board it also holds **Open initiatives** as Page or Popup. An orange dot on ⋯ means
|
|
21
|
+
- **The ⋯ menu** holds **Search** (Ctrl K), **Agent sessions** with a count, **Console**, **Theme** (Light, Dark or Auto) and **Settings**. On the Board it also holds **Open initiatives** as Page or Popup. An orange dot on ⋯ means a newer PMOS is ready, and **Settings** then shows the version.
|
|
22
22
|
- **On a phone** the bar is one row: the page name, Chat, the bell and ⋯. Sources moves into the ⋯ menu.
|
|
23
23
|
|
|
24
|
-
**Search** (Ctrl K, or `/`) opens the search over places, initiatives, documents and your running sessions; Enter opens the result. Search and the bell only read; neither changes a record. **Console** opens the console at `/console.html`, for the places premium does not have yet. In the console, the More menu has **Open premium**, which opens this page. **Settings** opens one dialog with two
|
|
24
|
+
**Search** (Ctrl K, or `/`) opens the search over places, initiatives, documents and your running sessions; Enter opens the result. Search and the bell only read; neither changes a record. **Console** opens the console at `/console.html`, for the places premium does not have yet. In the console, the More menu has **Open premium**, which opens this page. **Settings** opens one dialog. **Updates** comes first: the PMOS version you have, the newest published version, **Check now** and, when a newer one is ready, **Update**. Update does what the console's Settings › Updates does: it updates the kit in each workspace that is behind, then PMOS itself, which stops for about a minute and reloads the page. PMOS that runs from a checkout says to use `git pull` instead. Each workspace is a row with its kit version. PMOS checks once a day while a page is open (the console's **Check for updates** setting turns this off). **What's new** lists each published kit, newest first and grouped by day: its version, when it published, and one line per pull request it carries. Each line is copied from the pull request's "After:" paragraph, or its title when it has none, when the kit is published. Kits newer than yours are tinted, and yours is marked. Five show per day; **Show more** opens the rest. Then come two choices. **Workspaces** lists the repositories PMOS works in, with Add (a folder path) and Remove; Remove forgets the address and never deletes the folder, and a refusal shows the server's reason. **Connectors** has an On/Off switch for each source the Briefing reads. Each press saves that one record. Every other setting runs on a default and stays in the console; the dialog links to it. Remove needs the page's launch nonce, so an agent session cannot call it.
|
|
25
25
|
|
|
26
26
|
**Sources** is a dialog that lists each tracked source (Repository, Initiatives, Calendar, Jira status, My work and Tracker items) with its own state and the time it was last read. Each source except the repository has **Refresh**, and **Refresh all** reads them all again. Slack and email are read as part of My work, so they have no row of their own. A source PMOS does not track has no row: the dialog shows only what PMOS can say it read.
|
|
27
27
|
|
|
@@ -119,7 +119,7 @@ Above the list, with today picked, a ring shows how many of the meetings still a
|
|
|
119
119
|
|
|
120
120
|
With another day picked, the card lists that day's meetings from the calendar PMOS holds, and the items due that day. It reads the week once when the page opens. If the calendar cannot be read, the card says "Calendar not read" and gives the reason, and does not guess. A meeting in the past is shown dimmer. Picking a day changes only what the card shows and records nothing.
|
|
121
121
|
|
|
122
|
-
**The full calendar.** The button beside the filter in the card's title row opens the calendar in a dialog. **Day**, **Week** and **Month** each read the calendar PMOS holds for that range; the arrows move one day, week or month, and **Today** comes back. Week is a timeline from Monday to
|
|
122
|
+
**The full calendar.** The button beside the filter in the card's title row opens the calendar in a dialog. **Day**, **Week** and **Month** each read the calendar PMOS holds for that range; the arrows move one day, week or month, and **Today** comes back. The calendar fills the dialog; the dialog's conversation button brings the conversation back beside it. Day and Week are drawn the way the console's Calendar draws them. Week is a timeline from Monday to Sunday, with the weekend shaded and today tinted. Each day's head shows the day (press it to open that day), its meeting hours and a load bar. The **dates** row shows all-day meetings and the dated marks the Calendar reads (a promised date, a plan item, a release, a report, your own due items): four a day in a week, and a **+N** that opens the day. Every hour from 08:00 to 18:00 (wider when a meeting is earlier or later) has its label. Meetings at the same time sit side by side. A routine meeting (a stand-up, a 1:1, or one tied to no initiative, prep or record) is grey. In a narrow dialog, such as on a phone, Week is a list of days and Day stays a timeline. In Month, press a day to open it. Press a meeting to open its meeting dialog; the calendar stays as a **Calendar** tab beside it, at the same view. An empty range says "No meetings in this week" (or day, or month), and a calendar that cannot be read says "Calendar not read" with the reason.
|
|
123
123
|
|
|
124
124
|
Press a meeting, from today or from another day, to open the meeting dialog. It shows the time, the people, and what the meeting is about. It also shows the notes (decisions, next steps and open questions), the material, and, when a recording was kept, its length and the key points. Each part appears only when a record holds it.
|
|
125
125
|
|
|
@@ -309,23 +309,25 @@ Not drawn, because PMOS holds no record for them: the mockup's demo tasks, its J
|
|
|
309
309
|
Insights is the fourth place on the rail, at `/premium-insights.html`. It reads the KR metric records of the board's workspace, your saved dashboards, and the report files and report setups the console's Reports tab lists. It writes only when you press a button: a dashboard goes to the workspace's state folder (`premium-dashboards.jsonl`), and a report press goes to the report ledger through the console's own report routes. An agent session cannot make either write.
|
|
310
310
|
|
|
311
311
|
- **Charts.** One chart for each KR metric that holds at least two readings. The line runs through the readings at their dates, so a month with no reading is a gap and not a zero. The dashed line is the metric's target. The chip is the record's own line status: on its line, behind it, or well behind it. Pressing a chart, or its Details link, opens the metric's record in the dialog with the read-only agent beside it.
|
|
312
|
-
- **
|
|
312
|
+
- **The insight.** The page opens with one finding across the board's measures, in a large line, with the reason and its numbers under it, up to two more findings, **Ask PMOS why** (opens the measure's dialog on the Conversation tab) and **See the chart**. A measure that is short of its target, with a target date after its last reading, gets a projection: a straight line through its last four readings (all, when fewer), carried to the target date. When the line lands short, the finding says the measure will miss its target on that date at this pace, where it lands, how far short, and when it would get there. When the line lands on or past the target, it says the measure is on course. The page says how the projection is made, and no forecast line is drawn on a chart. With no KR metric, or none with two readings, the page says there is no insight yet and why.
|
|
313
|
+
- **The pinned dashboard.** The card under the insight shows the pinned dashboard: its insight band (the next findings on it, past the one the page leads with), its charts and **Unpin**. When nothing is pinned, it shows All measures, marked **Not pinned**, with **Pin**. Pressing a dashboard in the list shows it in this card, with **Pin** and **Back to** the pinned one. One dashboard per board is pinned, All measures included; pillar groups cannot be pinned. The pin is a line in `premium-dashboards.jsonl` and shows on Insights only.
|
|
314
|
+
- **Dashboards and reports.** One list holds the dashboards (All measures, your saved ones, then the pillars the metrics name) and then the reports (your set-up reports, then the report files). **All**, **Dashboards** and **Reports** filter it; it shows six rows to a page, with page numbers. A dashboard row shows its top finding and a pin. A report row quotes the opening sentence of its latest file; a set-up report with no file says no draft is written yet. **New** offers **Dashboard** or **Report**. Your requests and what PMOS found in your work stay at the top of the list. A saved dashboard draws its charts in the order you saved them. A chart whose record is gone, or that has fewer than two readings, is listed in its place with the reason and is not drawn.
|
|
313
315
|
- **Open the Studio from the top.** **Chat** beside the board name opens the Insight Studio: on the saved dashboard you are looking at, otherwise on a new dashboard, or in Report mode when no measure has a series yet.
|
|
314
|
-
- **Make or edit a dashboard.** **New
|
|
316
|
+
- **Make or edit a dashboard.** **New**, then **Dashboard**, or **Edit** on a saved one, opens the **Insight Studio**, a wide dialog. On the right, the brief shows the Name, Purpose, Charts and Main dashboard; press a chip to change it. **Library** lists the board's measures and saved dashboards to add. The preview draws the dashboard as the page will, and lists a measure with no series as not drawn. The checks (a name, a purpose, a chart, six or fewer, no repeat, a main dashboard on the board) say what fails, with a one-press fix. On the left you can say it instead: "add Partner activation", "remove …", "move … first", "call it …", "it is for …", "make it the main dashboard", "undo" or "start a new one". A turn changes the draft only. **Undo** steps back one change. **Save the dashboard** records it; **Remove the dashboard** asks once more and then removes it. In a chart's dialog, **On your dashboards** has a switch for each saved dashboard, which adds the chart to it or takes it off.
|
|
315
317
|
- **Make your own chart.** **New chart**, or **Edit** on one of your charts, opens the Insight Studio in **Chart** mode; the switch at the top moves between Chart and Dashboard, and each keeps its own draft. The brief shows the Question, Measure, Form (line, bars, number or meter), Range (all readings or the last few) and Target; **More** adds the Title, Better when, Note and Add to (a dashboard). The Studio suggests a form from the question and says why. The checks (a question, a target, enough readings, a form that fits the question, one scale) say what fails, with a one-press fix. You can say it instead: "show it as bars", "last 4 readings", "target 35", "lower is better", "call it …", "note: …", "add it to Weekly", or a question. A pie is declined, with the reason. **Save the chart** records it in the workspace's state folder, and adds it to the dashboard you named. Your charts are listed under **All measures**, and a dashboard can hold them beside the measures. **Remove the chart** asks once more; a dashboard that held it then says it was removed.
|
|
316
|
-
- **Set up a report in the Studio.** **New
|
|
318
|
+
- **Set up a report in the Studio.** **New**, then **Report**, on the list opens the Insight Studio in **Report** mode. The brief shows the Title, What it answers, Audience, Format, Schedule, Draw from (your work, or the board's dashboard) and the Sections. A new report always has the same sections, in the same order, so they are listed, not edited. The checks (what it answers, an audience, a format that fits the audience, a new title, the answer first) say what fails, with a one-press fix. You can say it instead: "it answers: …", "for leadership", "slides", "monthly", "every two weeks on Thursday", "call it …". **Set it up** records the report and writes its first draft as a file.
|
|
317
319
|
- **Change the size of the Studio.** On a wide window, **Normal**, **Half**, **3/4** and **Whole** sit beside **Library**. Whole is the full screen. At Half, the conversation and the Studio are two tabs. The Studio opens on Whole, and PMOS remembers your choice on this browser.
|
|
318
320
|
- **Shape a report's sections.** On a report drawn from your work, **Shape it in the Studio** opens Report mode on it. Tell PMOS how to shape the sections in your own words; PMOS proposes the next version and says what it changed. **Leave out** on a section makes the next version without it; the headline, Needs your call and Sources are always in. **Undo** goes back one version. **Use this structure** saves the version shown, and the next cycle follows it.
|
|
319
321
|
- **Design how a report looks.** A set-up report in the Studio has two tabs: **1 Structure** (what it says) and **2 Design** (how it looks). The Design tab shows the versions D1 to Dn, the slides of the one shown (a large preview, previous and next, and thumbnails), and the samples the look follows. **Add a file** (PDF, PowerPoint, Word or an image) or **Add the link** (Google or Confluence) adds a sample, and PMOS says what it took from it. Say how it should look, for example "use the theme of my picture", and PMOS makes the next version. Pick a version to look at it. **Undo** goes back one version. **This is it** saves the version shown as the design, and each new cycle is drawn to it. When you open a report again, both tabs show what was said before.
|
|
320
322
|
- **Choose a deck or a document, and read the design brief.** On the Design tab, the **Format** chip offers **Deck** and **Document** for the next version. Versions you already made keep their form. Once a design is saved, a **Design brief** chip shows what PMOS reads each cycle: your description, your samples, the reference version, and what stays the same, what changes and what PMOS learned. The cycles drafted to match it are checked on the report itself.
|
|
321
323
|
- **Point, make the next version, compare.** On the Design tab, click any part of a slide to attach a request to that spot: a numbered pin appears, and you type the request under the preview (**Point and say**; the switch turns pointing off). **Make the next version** sends the typed line and every pinned request to PMOS, which makes the next version; the pins are cleared once it starts. **Compare two** shows the same slide of two versions side by side; pick the version on each side.
|
|
322
|
-
- **
|
|
324
|
+
- **The findings.** Each finding is one sentence with its reason, taken from the series: will miss its target at this pace, on course, behind its line for three readings in a row, behind and still moving away from the target, closing in, slipped, reached its target, or a large one-step move. No cause is given.
|
|
323
325
|
- **Board measures.** The same four tiles as the Board's Metrics card, counted from the board's repository and drawn the same way. Choose **8 weeks**, **26 weeks** or **52 weeks**; the page keeps your choice. Press a measure to read its definition and values and to set its target: type a number and press **Save target**, or press **Clear target**. For Corrections, Blocked and Idle, lower is better, so the target is the most you accept; for Merged a week it is the least. The target goes to the workspace's state folder (`board-metric-targets.jsonl`) and the Board draws it too. An agent session cannot set one.
|
|
324
326
|
- **No series recorded.** A KR metric with one reading or none is listed with the reason and is not drawn.
|
|
325
327
|
- **Ask PMOS to set up a report.** Type what the report is for and press **Ask**. A background run proposes a report and does nothing else. The request is listed as Working, then Ready to review. A ready request opens with its proposal: **Set it up**, **Change it** (say what to change; the run revises it), or **Cancel**.
|
|
326
328
|
- **Found in your work.** Up to three reports PMOS found in your calendar, mail or documents, each with why and what it saw. **Set it up** records the report and drafts its first cycle as a file. **Not a report** hides it and records it after 5 seconds, unless you press **Undo**. If the finding changed while the window was open, the window says what happened. It was already set up, it was marked not a report, or a new scan replaced it. The list is read again. Close the window and open the report from the list. If PMOS does not hear back, the window says nothing was recorded. Press the button to try again.
|
|
327
329
|
- **Set up.** Your recurring reports, with their schedule and next draft. A report opens with **Draft it now** (for a report drawn from your work) and **Pause** or **Resume**.
|
|
328
|
-
- **
|
|
330
|
+
- **Report files.** The report files of the workspace, in the list, with cadence, slot and whether each is a draft or issued. Pressing one opens it on the page at the normal dialog size, with a status line (Draft or Issued, the saved design version, the file). The **slide deck / Document** menu picks the view: a deck is a title slide, then one slide for each section, with the arrow keys and a strip of slides; a document is a page. The **Read** menu holds **Present**, which shows the slide on the whole screen (the arrow keys move and Escape stops), and **Print or save as PDF**, which prints one slide to a page. **Download** gives PowerPoint, Word, Excel, CSV or the Markdown file; the files carry the words, not the look. **Open in the console** is where a document is edited or issued. Nothing is sent from this page.
|
|
329
331
|
- **Edit the slides.** In the **Read** menu of a draft, **Edit the slides** opens the same file as a **Slides** tab beside the report. The rail on the left lists the slides. Drag a slide to move it, or use the up and down buttons on it; the buttons also duplicate and delete a slide, and **+ Slide** adds one from a layout. On the slide, click an item to select it, drag it to move it (a line shows when it is centred), and drag a corner to resize it. Double-click text to type. The toolbar adds text, an image, a chart, a table or a shape, and changes the layout of the slide or the theme of the deck. The bar under it changes the selected item: text style, alignment and colour; bars or a line and **Edit data** for a chart; rows and columns for a table. An image is a file that is already in the workspace: type its path, such as `planning/design/screen.png`. Speaker notes go in the box under the slide. **Undo** and **Redo** cover every change. **Present** opens the presenter view: the slide, the next slide, your speaker notes (you can type in them) and a timer. The arrow keys move, and Escape stops. **Slides only** hides the notes. **Audience window** opens a second window with the slide alone, for the screen you share; it follows your slide and closes when you stop. **Save** asks why the slides change, then writes the file; the reason goes in the Edit log. The file stays markdown: each slide is a heading with its text under it, and a hidden comment keeps the layout and the notes. If someone changed the text of a slide in the file, the editor shows the file's text and says so. If the file changed while the slides were open, Save stops and tells you to open the slides again. An issued report opens its slides read-only, with **Open the slides**.
|
|
330
332
|
- **Shape a report's look.** On a draft, **Add a sample** takes a PDF, PowerPoint, Word, PNG or JPG file to follow. Say how it should look in the conversation; PMOS draws the next design version (D1, D2, …) and says what it changed. Press a version to go back to it. **This is it** saves the version shown as the report's design, and PMOS draws the cycle to match. An issued cycle is frozen with its look.
|
|
331
333
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* lib/insights-premium.js — the premium Insights page's model, built from the KR metric records and the report files the console's Reports tab reads
|
|
3
3
|
* (initiative briefing-premium-insights).
|
|
4
4
|
*
|
|
5
|
-
* build(facts) → model PURE. facts = { now, board, boards, outcomes, reports, reportsOk, missing[], saved, setups }
|
|
5
|
+
* build(facts) → model PURE. facts = { now, board, boards, outcomes, reports, reportsOk, missing[], saved, setups, pinned, leads }
|
|
6
6
|
* peekModel() → the last model built, for the agent to find a chart in (null before the first)
|
|
7
7
|
*
|
|
8
8
|
* facts come from the routes of lib/routes-c3-strategy.js and lib/routes-reports.js:
|
|
@@ -11,10 +11,13 @@
|
|
|
11
11
|
* reports GET /api/report → .reports [{ cadence, slot, path, status, issued: { at, by } | null, edited }]
|
|
12
12
|
* saved lib/premium-dashboards.js list(root, board.id) → [{ id, name, purpose, charts: [KR metric id], main, at }] (briefing-premium-reports D1)
|
|
13
13
|
* setups GET /api/report-setups → { setups, findings, asks } | null when it could not be read (briefing-premium-reports R1)
|
|
14
|
+
* pinned lib/premium-dashboards.js pinned(root, board.id) → 'all' | a saved id | null (insights-one-list L4)
|
|
15
|
+
* leads { [report path]: the opening sentence of that file } — read by the route; a path left out has none (insights-one-list L6)
|
|
14
16
|
*
|
|
15
17
|
* THE RULE THE FILE FOLLOWS (as the other premium models): a number, chip, line or date is made only from a field of a record. A measure with fewer than two
|
|
16
18
|
* readings gets no chart and says why. The time between two readings is drawn as the time it is, so a gap in a series shows as a gap and never as a zero. No
|
|
17
|
-
* forecast is drawn and no cause is given.
|
|
19
|
+
* forecast is drawn and no cause is given. One projection is said in words (initiative insights-one-list L2, amending briefing-premium-insights I6): for a
|
|
20
|
+
* measure short of its target with a target date ahead, a straight line through its last four readings carried to that date. Its method is stated. Run-based series (corrections per 100 runs, merges a week) belong to the Board's Metrics card and are not built here (PRD decision 4). */
|
|
18
21
|
|
|
19
22
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
20
23
|
const isoDay = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
@@ -22,9 +25,12 @@ const shortDate = (v) => { const t = isoDay(v); if (t === null) return ''; const
|
|
|
22
25
|
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
23
26
|
const fin = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
24
27
|
const r2 = (v) => Math.round(v * 100) / 100;
|
|
28
|
+
const r1 = (v) => Math.round(v * 10) / 10;
|
|
25
29
|
const num = (v, unit) => { const u = String(unit || '').trim(), s = String(r2(v)); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
|
|
26
30
|
const CHIP = { ok: ['On its line', 'ok'], drift: ['Behind its line', 'warn'], off: ['Well behind its line', 'bad'] };
|
|
27
31
|
const MAX_FINDINGS = 3;
|
|
32
|
+
const DAY = 864e5, WEEK = 7 * DAY;
|
|
33
|
+
const PROJ_N = 4; // the projection's line runs through the last four readings (insights-one-list L2)
|
|
28
34
|
const KR_FILE = 'planning/records/kr-metrics.jsonl';
|
|
29
35
|
|
|
30
36
|
let last = null;
|
|
@@ -56,7 +62,7 @@ function chartOf(o) {
|
|
|
56
62
|
const rid = clip(o.id, 100);
|
|
57
63
|
return {
|
|
58
64
|
key: 'ins:' + rid, id: o.id, title: clip(o.name, 120), sub: [o.pillar, rs.length + ' readings'].filter(Boolean).join(' · '), pillar: o.pillar || '',
|
|
59
|
-
unit: u, v: num(now, u), at: shortDate(rs[rs.length - 1].at), target: tgt, targetTxt: tgt !== null ? 'target ' + num(tgt, u) : '', by: o.by ? shortDate(o.by) : '',
|
|
65
|
+
unit: u, v: num(now, u), at: shortDate(rs[rs.length - 1].at), target: tgt, targetTxt: tgt !== null ? 'target ' + num(tgt, u) : '', by: o.by ? shortDate(o.by) : '', byAt: isoDay(o.by) !== null ? String(o.by).slice(0, 10) : null,
|
|
60
66
|
ty: tgt !== null ? (tgt - lo) / range : null, state: o.status || 'unscored', chip: chip[0], chipKind: chip[1], off: o.status === 'drift' || o.status === 'off', pivot: !!o.pivot,
|
|
61
67
|
step: r2(step), good, dir, first: rs[0].at, lastAt: rs[rs.length - 1].at, pts, range: [lo, hi],
|
|
62
68
|
ticks: [shortDate(rs[0].at), shortDate(rs[rs.length - 1].at)],
|
|
@@ -85,34 +91,73 @@ function mineOf(m, outcomes) {
|
|
|
85
91
|
});
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
/**
|
|
89
|
-
|
|
94
|
+
/** The projection of one chart (insights-one-list L2): a straight line through its last four readings (all, when fewer), at the dates they were taken,
|
|
95
|
+
* carried to the record's target date. null when the chart has no target, no target date after its last reading, or has reached its target. */
|
|
96
|
+
function projectionOf(c) {
|
|
97
|
+
if (c.target === null || !c.dir || !c.byAt) return null;
|
|
98
|
+
const P = c.pts.slice(-PROJ_N), a = P[0], z = P[P.length - 1], t0 = isoDay(a.at), t1 = isoDay(z.at), due = isoDay(c.byAt);
|
|
99
|
+
if (due === null || due <= t1 || t1 <= t0) return null;
|
|
100
|
+
if (c.dir > 0 ? z.v >= c.target : z.v <= c.target) return null;
|
|
101
|
+
const perDay = (z.v - a.v) / (t1 - t0) * DAY, atDue = z.v + perDay * (due - t1) / DAY;
|
|
102
|
+
const reaches = c.dir > 0 ? atDue >= c.target : atDue <= c.target, toward = perDay * c.dir > 0;
|
|
103
|
+
const when = toward ? t1 + (c.target - z.v) / perDay * DAY : null;
|
|
104
|
+
return { n: P.length, from: a, now: z.v, perWeek: perDay * 7, atDue, reaches, toward, when, short: Math.abs(c.target - atDue) };
|
|
105
|
+
}
|
|
106
|
+
const amount = (v, u) => String(u).trim() === '%' ? r2(v) + (r2(v) === 1 ? ' point' : ' points') : num(v, u);
|
|
107
|
+
const dayTxt = (t) => { const d = new Date(t); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()] + ' ' + d.getUTCFullYear(); };
|
|
108
|
+
|
|
109
|
+
/** Every finding of one chart, the strongest first. Each is { kind, score, text, why, key, chart }: `text` the headline, `why` one sentence with its numbers.
|
|
110
|
+
* Every number is a reading, the record's target or target date, or the projection said in words. No cause is given. */
|
|
111
|
+
function findingsOfChart(c) {
|
|
112
|
+
const u = c.unit, f = [];
|
|
113
|
+
const move = (a, b) => 'from ' + num(a, u) + ' to ' + num(b, u);
|
|
114
|
+
const prev = c.pts[c.pts.length - 2].v, now = c.pts[c.pts.length - 1].v, at = c.pts[c.pts.length - 1].d;
|
|
115
|
+
const spread = (c.range[1] - c.range[0]) || 1, tg = c.target !== null ? num(c.target, u) : '', by = c.by ? ' by ' + c.by : '';
|
|
116
|
+
const p = projectionOf(c);
|
|
117
|
+
if (c.pivot) f.push({ kind: 'stuck', score: 100, text: c.title + ' has been behind its line at three readings in a row, and the gap is not closing.', why: 'It is at ' + num(now, u) + ' on ' + at + (tg ? ', against a target of ' + tg + by : '') + '.' });
|
|
118
|
+
else if (c.off && c.good === false && c.step !== 0) f.push({ kind: 'worse', score: 90, text: c.title + ' is behind its line, and its last reading moved away from the target (' + move(prev, now) + ').', why: 'Its latest reading is ' + num(now, u) + ' on ' + at + (tg ? ', against a target of ' + tg + by : '') + '.' });
|
|
119
|
+
else if (c.off && c.good) f.push({ kind: 'closing', score: 60, text: c.title + ' is behind its line, and its last reading moved toward the target (' + move(prev, now) + ').', why: 'Its latest reading is ' + num(now, u) + ' on ' + at + (tg ? ', against a target of ' + tg + by : '') + '.' });
|
|
120
|
+
else if (c.off) f.push({ kind: 'off', score: 55, text: c.title + ' is behind its line at ' + num(now, u) + '.', why: tg ? 'The target is ' + tg + by + '.' : 'The record holds no target for it.' });
|
|
121
|
+
else if (c.state === 'ok' && c.good === false && c.step !== 0) f.push({ kind: 'slip', score: 50, text: c.title + ' is on its line, but its last reading moved away from the target (' + move(prev, now) + ').', why: 'The reading was taken on ' + at + (tg ? '. The target is ' + tg + by : '') + '.' });
|
|
122
|
+
if (c.target !== null && c.dir && (c.dir > 0 ? now >= c.target : now <= c.target)) f.push({ kind: 'reached', score: 58, text: c.title + ' has reached its target of ' + tg + '.', why: 'It read ' + num(now, u) + ' on ' + at + '.' });
|
|
123
|
+
if (p && !p.toward) f.push({ kind: 'stall', score: c.pivot ? 101 : 96, text: c.title + ' will miss its ' + tg + ' target on ' + c.by + ' unless it turns.', proj: true,
|
|
124
|
+
why: (c.pivot ? 'It has been behind its line at three readings in a row. ' : '') + 'Over its last ' + p.n + ' readings it went ' + move(p.from.v, p.now) + ', which is ' + (p.perWeek === 0 ? 'no move' : 'away from the target') + '. A straight line through them never reaches ' + tg + '.' });
|
|
125
|
+
else if (p && !p.reaches) f.push({ kind: 'miss', score: 95, text: c.title + ' will miss its ' + tg + ' target on ' + c.by + ' at this pace.', proj: true,
|
|
126
|
+
why: 'It is at ' + num(now, u) + ' and moving ' + amount(Math.abs(p.perWeek), u) + ' a week toward it, so it reaches about ' + num(r1(p.atDue), u) + ' by ' + c.by + ', ' + amount(r1(p.short), u) + ' short.'
|
|
127
|
+
+ (p.when && p.when - isoDay(c.lastAt) < 5 * 365 * DAY ? ' At this pace it gets there around ' + dayTxt(p.when) + '.' : '') });
|
|
128
|
+
else if (p) f.push({ kind: 'course', score: 62, text: c.title + ' is short of its target but on course to reach ' + tg + by + '.', proj: true,
|
|
129
|
+
why: 'It is at ' + num(now, u) + ' and moving ' + amount(Math.abs(p.perWeek), u) + ' a week toward it.' });
|
|
130
|
+
if (Math.abs(now - prev) / spread >= 0.4 && !f.some((x) => x.score >= 90)) f.push({ kind: 'move', score: 70, text: c.title + ' moved ' + move(prev, now) + ' in one reading.', why: 'That is ' + Math.round(Math.abs(now - prev) / spread * 100) + '% of the range its readings span. The reading was taken on ' + at + '.' });
|
|
131
|
+
f.sort((a, b) => b.score - a.score);
|
|
132
|
+
return f.map((x) => Object.assign(x, { key: c.key, chart: c.key }));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The strongest finding of each chart, strongest first. `max` caps the list (three on the page). */
|
|
136
|
+
function findingsOf(charts, max = MAX_FINDINGS) {
|
|
90
137
|
const out = [];
|
|
91
|
-
for (const c of charts) {
|
|
92
|
-
const u = c.unit, f = [];
|
|
93
|
-
const move = (a, b) => 'from ' + num(a, u) + ' to ' + num(b, u);
|
|
94
|
-
const prev = c.pts[c.pts.length - 2].v, now = c.pts[c.pts.length - 1].v;
|
|
95
|
-
const spread = (c.range[1] - c.range[0]) || 1;
|
|
96
|
-
if (c.pivot) f.push({ kind: 'stuck', score: 100, text: c.title + ' has been behind its line at three readings in a row, and the gap is not closing.' });
|
|
97
|
-
else if (c.off && c.good === false && c.step !== 0) f.push({ kind: 'worse', score: 90, text: c.title + ' is behind its line, and its last reading moved away from the target (' + move(prev, now) + ').' });
|
|
98
|
-
else if (c.off && c.good) f.push({ kind: 'closing', score: 60, text: c.title + ' is behind its line, and its last reading moved toward the target (' + move(prev, now) + ').' });
|
|
99
|
-
else if (c.off) f.push({ kind: 'off', score: 55, text: c.title + ' is behind its line at ' + num(now, u) + '.' });
|
|
100
|
-
else if (c.state === 'ok' && c.good === false && c.step !== 0) f.push({ kind: 'slip', score: 50, text: c.title + ' is on its line, but its last reading moved away from the target (' + move(prev, now) + ').' });
|
|
101
|
-
if (c.target !== null && c.dir && (c.dir > 0 ? now >= c.target : now <= c.target)) f.push({ kind: 'reached', score: 58, text: c.title + ' has reached its target of ' + num(c.target, u) + '.' });
|
|
102
|
-
if (Math.abs(now - prev) / spread >= 0.4 && !(f[0] && f[0].score >= 90)) f.push({ kind: 'move', score: 70, text: c.title + ' moved ' + move(prev, now) + ' in one reading.' });
|
|
103
|
-
f.sort((a, b) => b.score - a.score);
|
|
104
|
-
if (f[0]) out.push(Object.assign(f[0], { key: c.key, chart: c.key }));
|
|
105
|
-
}
|
|
138
|
+
for (const c of charts) { const f = findingsOfChart(c); if (f[0]) out.push(f[0]); }
|
|
106
139
|
out.sort((a, b) => b.score - a.score);
|
|
107
|
-
return out.slice(0,
|
|
140
|
+
return out.slice(0, max);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** A dashboard's insight (insights-one-list L4, L6): its charts' findings, strongest first, at most three. The page shows the first; the pinned card skips
|
|
144
|
+
* the one the page already leads with. `calm` when no chart has a finding. */
|
|
145
|
+
function dashInsightOf(L) {
|
|
146
|
+
if (!L.length) return { finds: [], calm: false, none: true };
|
|
147
|
+
const finds = findingsOf(L, 3).map(({ kind, text, why, chart, proj }) => ({ kind, text, why, chart, proj: !!proj }));
|
|
148
|
+
return { finds, calm: !finds.length, none: false, calmText: L.some((c) => c.target !== null) ? 'Nothing stands out here. No measure moved much, and none is far behind its line.' : 'Nothing stands out here. No measure on it has a target.' };
|
|
108
149
|
}
|
|
109
150
|
|
|
110
|
-
|
|
111
|
-
|
|
151
|
+
const REPORTS_MAX = 60;
|
|
152
|
+
/** The report files, newest first. `lead` is the opening sentence of the file as the route read it (insights-one-list L6), '' when it has none. */
|
|
153
|
+
function reportRows(reports, leads) {
|
|
154
|
+
const L = leads || {};
|
|
155
|
+
return (reports || []).slice().sort((a, b) => String(b.slot).localeCompare(String(a.slot)) || String(a.cadence).localeCompare(String(b.cadence))).slice(0, REPORTS_MAX).map((r) => {
|
|
112
156
|
const issued = !!r.issued;
|
|
113
157
|
return {
|
|
114
158
|
key: 'rep:' + r.cadence + ':' + r.slot, cadence: r.cadence, slot: r.slot, date: shortDate(r.slot), state: issued ? 'issued' : r.status === 'draft' ? 'draft' : 'file',
|
|
115
159
|
stateLabel: issued ? 'Issued' + (r.issued.at ? ' ' + shortDate(r.issued.at) : '') : r.status === 'draft' ? 'Draft' : 'Report file', path: r.path || '',
|
|
160
|
+
lead: typeof L[r.path] === 'string' ? clip(L[r.path], 240) : '',
|
|
116
161
|
};
|
|
117
162
|
});
|
|
118
163
|
}
|
|
@@ -169,6 +214,42 @@ function proposalOf(p) {
|
|
|
169
214
|
return { name: p.name ? clip(p.name, 120) : '', rows };
|
|
170
215
|
}
|
|
171
216
|
|
|
217
|
+
/** Each setup's latest report file (a row whose cadence is the setup's id; the rows are newest first), so its row can quote that file's opening sentence. */
|
|
218
|
+
function latestOf(su, rows) {
|
|
219
|
+
for (const s of su.setups) { const r = rows.find((x) => x.cadence === s.id); s.latest = r ? { key: r.key, date: r.date, path: r.path, lead: r.lead } : null; }
|
|
220
|
+
return su;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The page's insight (insights-one-list L1): the strongest finding across the board's measures with its reason, up to two more, and the counts it rests on.
|
|
224
|
+
* With no chart it says why there is no insight, and makes no number. */
|
|
225
|
+
function insightOf(charts, findings, total) {
|
|
226
|
+
if (!charts.length) return { none: true, text: total ? 'There is no insight yet. No KR metric holds two readings.' : 'There is no insight yet. No KR metric is recorded for this workspace.',
|
|
227
|
+
why: total ? 'PMOS draws an insight from the readings of your KR metrics. A measure needs two readings before it has a series.' : 'PMOS draws an insight from the readings of your KR metrics. Add one where the KR metrics are kept, and it shows here after two readings.' };
|
|
228
|
+
const last = charts.map((c) => c.lastAt).sort().pop(), off = charts.filter((c) => c.off).length;
|
|
229
|
+
const head = findings[0] || null;
|
|
230
|
+
return { none: false, off, total: charts.length, asOf: shortDate(last), calm: !head,
|
|
231
|
+
text: head ? head.text : charts.some((c) => c.target !== null) ? 'Nothing stands out. No measure moved much, and none is far behind its line.' : 'Nothing stands out. No measure here has a target, so the series can only be described.',
|
|
232
|
+
why: head ? head.why : '', chart: head ? head.chart : null, kind: head ? head.kind : 'calm', proj: !!(head && head.proj),
|
|
233
|
+
more: findings.slice(1, 3).map((x) => ({ text: x.text, chart: x.chart })) };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The opening sentence of a report file (insights-one-list L6): the first prose paragraph after the frontmatter, past headings, lists, tables, quotes, code
|
|
237
|
+
* and comments, cut at its first sentence end and clipped. '' when the file holds no prose. PURE. The page marks it as quoted from the file. */
|
|
238
|
+
function leadOf(text) {
|
|
239
|
+
let t = String(text || '').replace(/\r/g, '');
|
|
240
|
+
if (/^---\n/.test(t)) { const e = t.indexOf('\n---', 4); t = e < 0 ? '' : t.slice(e + 4); }
|
|
241
|
+
t = t.replace(/<!--[\s\S]*?-->/g, '').replace(/```[\s\S]*?```/g, '');
|
|
242
|
+
for (const para of t.split(/\n\s*\n/)) {
|
|
243
|
+
const lines = para.split('\n').map((x) => x.trim()).filter(Boolean);
|
|
244
|
+
if (!lines.length || lines.some((x) => /^(#|[-*+] |\d+[.)] |\||>|<|!\[)/.test(x))) continue;
|
|
245
|
+
const prose = lines.join(' ').replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/[*_`]{1,3}([^*_`]+)[*_`]{1,3}/g, '$1').replace(/\s+/g, ' ').trim();
|
|
246
|
+
if (prose.length < 12) continue;
|
|
247
|
+
const m = /^(.+?[.!?])(\s+(?=[A-Z0-9"“(])|$)/.exec(prose);
|
|
248
|
+
return clip(m ? m[1] : prose, 220);
|
|
249
|
+
}
|
|
250
|
+
return '';
|
|
251
|
+
}
|
|
252
|
+
|
|
172
253
|
function build(facts) {
|
|
173
254
|
const f = facts || {};
|
|
174
255
|
const outcomes = f.outcomes || [], missing = (f.missing || []).slice();
|
|
@@ -185,7 +266,9 @@ function build(facts) {
|
|
|
185
266
|
const dash = (id, name, L) => ({ id, name, keys: L.map((c) => c.key), total: L.length, off: offOf(L), chip: !L.length ? '' : offOf(L) ? offOf(L) + ' off its line' : 'On their lines' });
|
|
186
267
|
const dashboards = [dash('all', 'All measures', charts)].concat(savedOf(f.saved, outcomes, charts.concat(mine), mineAll), pillars.length > 1 ? pillars.map((p) => dash('p:' + p, p, charts.filter((c) => c.pillar === p))) : []);
|
|
187
268
|
const findings = findingsOf(charts);
|
|
188
|
-
const rep = reportRows(f.reports);
|
|
269
|
+
const rep = reportRows(f.reports, f.leads);
|
|
270
|
+
for (const d of dashboards) Object.assign(d, { insight: dashInsightOf(d.keys.map((k) => charts.concat(mine).find((c) => c.key === k)).filter(Boolean)) });
|
|
271
|
+
const pin0 = f.pinned !== undefined ? f.pinned : ((f.saved || []).find((d) => d.main) || {}).id, pinned = pin0 && dashboards.some((d) => d.id === pin0) ? pin0 : null;
|
|
189
272
|
const off = offOf(charts);
|
|
190
273
|
const board = f.board || {};
|
|
191
274
|
const model = {
|
|
@@ -194,7 +277,9 @@ function build(facts) {
|
|
|
194
277
|
charts, mine, mineGone, mineSaved: mineAll, noSeries, dashboards, rows: charts,
|
|
195
278
|
findings: findings.length ? findings : [{ kind: 'calm', key: null, text: charts.length ? (charts.some((c) => c.target !== null) ? 'Nothing stands out. No measure moved much, and none is far behind its line.' : 'Nothing stands out. No measure here has a target, so the series can only be described.') : '' }],
|
|
196
279
|
calm: !findings.length && charts.length > 0,
|
|
197
|
-
reports: Object.assign({ rows: rep, ok: f.reportsOk !== false, counts: { draft: rep.filter((r) => r.state === 'draft').length, issued: rep.filter((r) => r.state === 'issued').length }, missing: f.reportsOk === false }, setupsOf(f.setups, f.now)),
|
|
280
|
+
reports: Object.assign({ rows: rep, ok: f.reportsOk !== false, counts: { draft: rep.filter((r) => r.state === 'draft').length, issued: rep.filter((r) => r.state === 'issued').length }, missing: f.reportsOk === false }, latestOf(setupsOf(f.setups, f.now), rep)),
|
|
281
|
+
insight: insightOf(charts, findings, outcomes.length),
|
|
282
|
+
pinned,
|
|
198
283
|
measures: outcomes.map((o) => ({ id: o.id, title: clip(o.name, 120), pillar: o.pillar || '', charted: charts.some((c) => c.id === o.id) })),
|
|
199
284
|
empty: !outcomes.length ? 'No KR metric is recorded for this workspace, so there is nothing to chart. Add one where the KR metrics are kept.' : !charts.length ? 'No KR metric holds two readings yet, so nothing is drawn.' : '',
|
|
200
285
|
dock: { needs: off, label: off === 1 ? 'measure off its line' : 'measures off their line', next: findings[0] && findings[0].chart ? (charts.find((c) => c.key === findings[0].chart) || {}).title || null : null },
|
|
@@ -204,4 +289,4 @@ function build(facts) {
|
|
|
204
289
|
return model;
|
|
205
290
|
}
|
|
206
291
|
|
|
207
|
-
module.exports = { build, peekModel, chartOf, mineOf, findingsOf, shortDate, num };
|
|
292
|
+
module.exports = { build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
/* kit-update.js — check for a newer create-pmos, and update the kit or the workspace app, from the page (workspace-kit-update).
|
|
3
3
|
*
|
|
4
4
|
* readKit(root) → { present:false } | { present:true, version, kernelSource, installed, mode }
|
|
5
|
-
* status({ root, appVersion, appDir }) → { app: { version, fromCheckout }, kit }
|
|
5
|
+
* status({ root, appVersion, appDir }) → { app: { version, fromCheckout }, kit, changes } local only, no network
|
|
6
6
|
* source(env) → { kind:'npm' } | { kind:'local', path } | { kind:'local', path, error }
|
|
7
|
-
* latest({ exec, source }) → Promise<{ ok, version } | { ok:false, error }> npm view create-pmos version
|
|
7
|
+
* latest({ exec, source }) → Promise<{ ok, version, changes } | { ok:false, error }> npm view create-pmos version pmosChanges
|
|
8
|
+
* readChanges(appDir) → [{ v, at, prs: [{ n, s }] }] the installed app's changelog.json, newest first
|
|
9
|
+
* readLastCheck(stateDir) · writeLastCheck(stateDir, { latest, changes }) the last check's answer, kept in the state folder
|
|
8
10
|
* compare(st, latestVersion) → { appBehind, kitBehind }
|
|
9
11
|
* updateKit(root, { version, exec }) → Promise<{ ok, output, kit } | { ok:false, error, output }>
|
|
10
12
|
* upgradeApp(root, { version, logFile, spawn, env }) → { ok, log } | { ok:false, error }
|
|
@@ -23,6 +25,10 @@
|
|
|
23
25
|
* minute later. The app upgrade stops this server (create-pmos runs `pmos stop`), so it runs DETACHED, writes its output
|
|
24
26
|
* to a log file, and the page waits for the server to come back.
|
|
25
27
|
*
|
|
28
|
+
* WHAT'S NEW (premium-updates). kit-publish writes workspace/changelog.json (one summary per kit, copied from its merged PRs)
|
|
29
|
+
* and the newest 20 entries as the package's `pmosChanges` field. The installed list is read from disk; the check reads the
|
|
30
|
+
* newer kits' entries in the same `npm view` call, so the page can say what an update brings before it runs.
|
|
31
|
+
*
|
|
26
32
|
* NETWORK. These are the workspace's only egress to the npm registry. No HTTP client is opened here: npm and npx open
|
|
27
33
|
* their own. Every call is reached only from a POST the page sends when the PM presses a button (server.js
|
|
28
34
|
* /api/kit/check, /api/kit/update, /api/kit/upgrade-app); no timer and no GET reaches them. no-network.test.js holds
|
|
@@ -116,9 +122,43 @@ const npxArgs = (src, version, rest) => (src && src.kind === 'local'
|
|
|
116
122
|
? ['-y', `--package=${src.path}`, '--', PKG_NAME, ...rest]
|
|
117
123
|
: ['-y', `${PKG_NAME}@${version}`, ...rest]);
|
|
118
124
|
|
|
125
|
+
/** One changelog entry as the page may show it, or null: a version, a time, and PRs with a number and a summary. */
|
|
126
|
+
function cleanEntry(e) {
|
|
127
|
+
if (!e || !validVersion(e.v)) return null;
|
|
128
|
+
const prs = (Array.isArray(e.prs) ? e.prs : []).filter((p) => p && typeof p.s === 'string' && p.s.trim())
|
|
129
|
+
.map((p) => ({ n: Number.isInteger(p.n) ? p.n : null, s: p.s.trim().slice(0, 400) }));
|
|
130
|
+
return { v: e.v, at: typeof e.at === 'string' && !Number.isNaN(Date.parse(e.at)) ? e.at : null, prs };
|
|
131
|
+
}
|
|
132
|
+
const cleanList = (list) => (Array.isArray(list) ? list.map(cleanEntry).filter(Boolean) : []);
|
|
133
|
+
|
|
134
|
+
/** The installed app's changelog.json (shipped by kit-publish), newest first; [] in a checkout or an older install. */
|
|
135
|
+
function readChanges(appDir) {
|
|
136
|
+
try { return cleanList(JSON.parse(fs.readFileSync(path.join(String(appDir || ''), 'changelog.json'), 'utf8'))); } catch { return []; }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const LAST_CHECK = 'kit-last-check.json';
|
|
140
|
+
/** The last check's answer: { at, latest, changes } or null. Written by the check route, read by GET /api/kit/status. */
|
|
141
|
+
function readLastCheck(stateDir) {
|
|
142
|
+
try {
|
|
143
|
+
const j = JSON.parse(fs.readFileSync(path.join(String(stateDir || ''), LAST_CHECK), 'utf8'));
|
|
144
|
+
return j && validVersion(j.latest) && !Number.isNaN(Date.parse(j.at)) ? { at: j.at, latest: j.latest, changes: cleanList(j.changes) } : null;
|
|
145
|
+
} catch { return null; }
|
|
146
|
+
}
|
|
147
|
+
function writeLastCheck(stateDir, { latest: v, changes, at = new Date().toISOString() } = {}) {
|
|
148
|
+
if (!validVersion(v)) return null;
|
|
149
|
+
const rec = { at, latest: v, changes: cleanList(changes) };
|
|
150
|
+
try {
|
|
151
|
+
fs.mkdirSync(String(stateDir), { recursive: true });
|
|
152
|
+
const f = path.join(String(stateDir), LAST_CHECK);
|
|
153
|
+
fs.writeFileSync(f + '.tmp', JSON.stringify(rec) + '\n', { mode: 0o600 });
|
|
154
|
+
fs.renameSync(f + '.tmp', f);
|
|
155
|
+
} catch { /* the page still has the answer it was given */ }
|
|
156
|
+
return rec;
|
|
157
|
+
}
|
|
158
|
+
|
|
119
159
|
function status({ root, appVersion, appDir, env }) {
|
|
120
160
|
const src = source(env);
|
|
121
|
-
return { app: { version: appVersion || null, fromCheckout: fromCheckout(appDir) }, kit: readKit(root), source: src.kind === 'local' ? { kind: 'local', path: src.path, error: src.error || null } : { kind: 'npm' } };
|
|
161
|
+
return { app: { version: appVersion || null, fromCheckout: fromCheckout(appDir) }, kit: readKit(root), changes: readChanges(appDir), source: src.kind === 'local' ? { kind: 'local', path: src.path, error: src.error || null } : { kind: 'npm' } };
|
|
122
162
|
}
|
|
123
163
|
|
|
124
164
|
function compare(st, latestVersion) {
|
|
@@ -155,15 +195,24 @@ async function latest({ exec = cp.execFile, source: src = source() } = {}) {
|
|
|
155
195
|
if (src.kind === 'local') {
|
|
156
196
|
if (src.error) return { ok: false, error: src.error };
|
|
157
197
|
if (!src.version) return { ok: false, error: `${src.path} has no version number` };
|
|
158
|
-
|
|
198
|
+
let changes = [];
|
|
199
|
+
try { changes = cleanList(JSON.parse(fs.readFileSync(path.join(src.path, 'package.json'), 'utf8')).pmosChanges); } catch { /* a .tgz, or none */ }
|
|
200
|
+
return { ok: true, version: src.version, changes, source: 'local' };
|
|
159
201
|
}
|
|
160
|
-
|
|
202
|
+
// pmosChanges: the newest kits' summaries (premium-updates). A package published before it has none, and npm then answers
|
|
203
|
+
// with the version alone, as a plain JSON string.
|
|
204
|
+
const r = await run(exec, NPM, ['view', PKG_NAME, 'version', 'pmosChanges', '--json'], { timeout: CHECK_TIMEOUT_MS });
|
|
161
205
|
const bad = why(r, 'The check');
|
|
162
206
|
if (bad) return { ok: false, error: bad };
|
|
163
207
|
let v = r.stdout.trim();
|
|
164
|
-
|
|
208
|
+
let changes = [];
|
|
209
|
+
try {
|
|
210
|
+
const j = JSON.parse(v);
|
|
211
|
+
if (typeof j === 'string') v = j;
|
|
212
|
+
else if (j && typeof j === 'object') { v = j.version; changes = cleanList(j.pmosChanges); }
|
|
213
|
+
} catch { /* plain text */ }
|
|
165
214
|
if (!validVersion(v)) return { ok: false, error: 'The check did not return a version number' };
|
|
166
|
-
return { ok: true, version: v };
|
|
215
|
+
return { ok: true, version: v, changes };
|
|
167
216
|
}
|
|
168
217
|
|
|
169
218
|
/**
|
|
@@ -250,4 +299,4 @@ function upgradeApp(root, { version, logFile, spawn = cp.spawn, env = updateEnv(
|
|
|
250
299
|
}
|
|
251
300
|
}
|
|
252
301
|
|
|
253
|
-
module.exports = { PKG_NAME, cmpVer, notServedYet, validVersion, source, npxArgs, readKit, fromCheckout, status, compare, latest, updateKit, updateEnv, upgradeApp, whereFrom };
|
|
302
|
+
module.exports = { PKG_NAME, cmpVer, readChanges, readLastCheck, writeLastCheck, notServedYet, validVersion, source, npxArgs, readKit, fromCheckout, status, compare, latest, updateKit, updateEnv, upgradeApp, whereFrom };
|
|
@@ -8,10 +8,13 @@
|
|
|
8
8
|
* fold(lines) → { [board]: [{ id, board, name, purpose, charts, main, at }] } PURE
|
|
9
9
|
* list(root, board) → the dashboards of one board, the main one first, then in the order they were made
|
|
10
10
|
* save(root, input, actor, { now, known }) → { ok: true, dashboard, dashboards } | { ok: false, status, error }
|
|
11
|
+
* pinned(root, board) → the id of the board's pinned dashboard ('all' for All measures, or a saved id) | null
|
|
12
|
+
* pin(root, input, actor, { now }) → { ok: true, pinned } | { ok: false, status, error } input = { board, id: 'all' | saved id | null }
|
|
11
13
|
*
|
|
12
14
|
* THE LEDGER. Lines { v: 1, ev: save | remove, id, board, name, purpose, charts, main, actor, at }. `board` is the board's id in the workspace whose
|
|
13
15
|
* state folder holds the file. `charts` is an ordered list of KR metric ids. The fold keeps the last save of each id and drops an id once it is removed.
|
|
14
|
-
* One dashboard per board is main: the latest save that says main
|
|
16
|
+
* One dashboard per board is main (the pinned one, initiative insights-one-list L4): the latest save that says main, or the latest `pin` line, wins, and the
|
|
17
|
+
* others read as not main. A `pin` line { v, ev: 'pin', board, id, actor, at } names 'all' (All measures), a saved id, or null (nothing pinned). The file is never rewritten. A torn line, or one
|
|
15
18
|
* without an id and a board, is skipped. This store is the premium page's own: the console's dashboard layouts (lib/report-dashboards.js) are not touched.
|
|
16
19
|
*/
|
|
17
20
|
const fs = require('fs');
|
|
@@ -39,7 +42,7 @@ function readLines(file) {
|
|
|
39
42
|
const out = [];
|
|
40
43
|
for (const raw of text.split('\n')) {
|
|
41
44
|
if (!raw.trim()) continue;
|
|
42
|
-
try { const l = JSON.parse(raw); if (isObj(l) && (l.ev === 'save' || l.ev === 'remove') && typeof l.id === 'string' && typeof l.
|
|
45
|
+
try { const l = JSON.parse(raw); if (isObj(l) && typeof l.board === 'string' && (((l.ev === 'save' || l.ev === 'remove') && typeof l.id === 'string') || (l.ev === 'pin' && (l.id === null || typeof l.id === 'string')))) out.push(l); } catch { /* a torn line is skipped */ }
|
|
43
46
|
}
|
|
44
47
|
return out;
|
|
45
48
|
}
|
|
@@ -73,11 +76,13 @@ function check(input) {
|
|
|
73
76
|
|
|
74
77
|
/** Every board's dashboards after the ledger's lines, in order. PURE. The main one of a board is the last one saved with main; a later save of that
|
|
75
78
|
* same dashboard without main, or its removal, leaves the board with none. */
|
|
76
|
-
function fold(lines) {
|
|
79
|
+
function fold(lines) { return walk(lines).out; }
|
|
80
|
+
function walk(lines) {
|
|
77
81
|
const byId = new Map(); // id → dashboard; `first` keeps the order they were first made
|
|
78
82
|
const mainOf = new Map(); // board → id
|
|
79
83
|
let made = 0;
|
|
80
84
|
for (const l of lines || []) {
|
|
85
|
+
if (l.ev === 'pin') { if (l.id === null) mainOf.delete(l.board); else mainOf.set(l.board, l.id); continue; }
|
|
81
86
|
const prev = byId.get(l.id);
|
|
82
87
|
if (prev && prev.board !== l.board) continue; // an id never moves between boards
|
|
83
88
|
if (l.ev === 'remove') { byId.delete(l.id); if (mainOf.get(l.board) === l.id) mainOf.delete(l.board); continue; }
|
|
@@ -91,10 +96,25 @@ function fold(lines) {
|
|
|
91
96
|
.sort((a, z) => (z.main - a.main) || (a.first - z.first))
|
|
92
97
|
.map(({ id, board, name, purpose, charts, main, at }) => ({ id, board, name, purpose, charts, main, at }));
|
|
93
98
|
}
|
|
94
|
-
return out;
|
|
99
|
+
return { out, mainOf };
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
const list = (root, board) => fold(readLines(ledgerFile(root)))[board] || [];
|
|
103
|
+
const pinned = (root, board) => walk(readLines(ledgerFile(root))).mainOf.get(board) || null;
|
|
104
|
+
|
|
105
|
+
/** Pin a dashboard to the top of Insights, or unpin (id null). 'all' is All measures; any other id must be a saved dashboard of the board. */
|
|
106
|
+
function pin(root, input, actor, { now } = {}) {
|
|
107
|
+
const i = isObj(input) ? input : {};
|
|
108
|
+
const board = typeof i.board === 'string' ? i.board : '';
|
|
109
|
+
if (!ID_RE.test(board)) return refuse(400, 'Name the board the dashboard belongs to.');
|
|
110
|
+
const id = i.id == null || i.id === '' ? null : i.id;
|
|
111
|
+
if (id !== null && (typeof id !== 'string' || !ID_RE.test(id))) return refuse(400, 'That dashboard id is not valid.');
|
|
112
|
+
if (id !== null && id !== 'all' && !list(root, board).some((d) => d.id === id)) return refuse(404, 'That dashboard is not on this board.');
|
|
113
|
+
const file = ledgerFile(root), t = now == null ? Date.now() : now;
|
|
114
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
115
|
+
fs.appendFileSync(file, JSON.stringify({ v: 1, ev: 'pin', board, id, actor: actor || null, at: new Date(t).toISOString() }) + '\n');
|
|
116
|
+
return { ok: true, pinned: pinned(root, board) };
|
|
117
|
+
}
|
|
98
118
|
|
|
99
119
|
/** THE SINGLE WRITER of premium-dashboards.jsonl. `v`, `id` (for a new one) and `at` are set here.
|
|
100
120
|
* known = { charts: Set of KR metric ids of the workspace } — a chart outside it is refused. */
|
|
@@ -124,4 +144,4 @@ function save(root, input, actor, { now, known } = {}) {
|
|
|
124
144
|
return { ok: true, dashboard: v.remove ? null : after.find((d) => d.id === line.id) || null, dashboards: after };
|
|
125
145
|
}
|
|
126
146
|
|
|
127
|
-
module.exports = { NAME_MAX, PURPOSE_MAX, CHARTS_MAX, ADVISED_MAX, ledgerFile, readLines, check, fold, list, save };
|
|
147
|
+
module.exports = { NAME_MAX, PURPOSE_MAX, CHARTS_MAX, ADVISED_MAX, ledgerFile, readLines, check, fold, list, pinned, pin, save };
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* premium-studio-chart adds the board's saved charts (lib/premium-charts.js list).
|
|
9
9
|
* briefing-premium-reports adds the board's saved dashboards (lib/premium-dashboards.js list) and the workspace's GET /api/report-setups answer
|
|
10
10
|
* (setups, findings, asks). That GET is the console's own read: like the console, it may move old dashboard schedules into recurring reports once
|
|
11
|
-
* per repository.
|
|
11
|
+
* per repository. insights-one-list adds the pinned dashboard (lib/premium-dashboards.js pinned) and the opening sentence of each report file, read here
|
|
12
|
+
* from the workspace's repository. This route itself writes nothing. The page's presses post to /api/report-setups/* and /api/premium-dashboards/save. */
|
|
12
13
|
const Insights = require('./insights-premium.js');
|
|
13
14
|
const boards = require('./routes-boards.js');
|
|
14
15
|
const strategy = require('./routes-c3-strategy.js');
|
|
@@ -26,6 +27,19 @@ async function via(mod, pathAndQuery, req, ctx) {
|
|
|
26
27
|
const handled = await mod.handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, u, c);
|
|
27
28
|
return handled === false ? { status: 404, body: null } : out;
|
|
28
29
|
}
|
|
30
|
+
/** The opening sentence of each listed report file (insights-one-list L6), read from the workspace's repository. A file that cannot be read has none. */
|
|
31
|
+
const LEADS_MAX = 60;
|
|
32
|
+
function leadsOf(ctx, ws, list) {
|
|
33
|
+
const out = {};
|
|
34
|
+
let root = null;
|
|
35
|
+
try { root = require('path').resolve(ctx.getWs(ws).root); } catch { return out; }
|
|
36
|
+
for (const r of list.slice().sort((a, b) => String(b.slot).localeCompare(String(a.slot))).slice(0, LEADS_MAX)) {
|
|
37
|
+
const rel = String(r.path || '');
|
|
38
|
+
if (!rel || rel.includes('..') || require('path').isAbsolute(rel)) continue;
|
|
39
|
+
try { out[rel] = Insights.leadOf(require('fs').readFileSync(require('path').join(root, rel), 'utf8').slice(0, 20000)); } catch { /* an unreadable file has no lead */ }
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
29
43
|
const qs = (o) => '?' + Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
30
44
|
|
|
31
45
|
module.exports = {
|
|
@@ -49,16 +63,17 @@ module.exports = {
|
|
|
49
63
|
} catch (e) { return fail('the KR metric records could not be read: ' + ((e && e.message) || e)); }
|
|
50
64
|
const reportsOk = !!(rp.body && rp.body.ok !== false);
|
|
51
65
|
const missing = reportsOk ? [] : ['reports'];
|
|
52
|
-
let saved = [], mine = [];
|
|
53
|
-
if (pick && pick.id) { try {
|
|
66
|
+
let saved = [], mine = [], pinned = null;
|
|
67
|
+
if (pick && pick.id) { try { const root = require('path').resolve(ctx.getWs(pick.ws).root); saved = PD.list(root, pick.id); pinned = PD.pinned(root, pick.id); } catch { missing.push('dashboards'); } }
|
|
54
68
|
if (pick && pick.id) { try { mine = require('./premium-charts.js').list(require('path').resolve(ctx.getWs(pick.ws).root), pick.id); } catch { missing.push('saved charts'); } }
|
|
55
69
|
const su = await via(setups, '/api/report-setups' + q, req, ctx).catch(() => ({ status: 500, body: null }));
|
|
56
70
|
const setupsOk = su.status === 200 && !!su.body && Array.isArray(su.body.setups);
|
|
57
71
|
if (!setupsOk) missing.push('report setups');
|
|
72
|
+
const leads = reportsOk ? leadsOf(ctx, ws, rp.body.reports || []) : {};
|
|
58
73
|
const model = Insights.build({
|
|
59
74
|
now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Insights' }, boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })),
|
|
60
75
|
outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
|
|
61
|
-
setups: setupsOk ? su.body : null,
|
|
76
|
+
setups: setupsOk ? su.body : null, pinned, leads,
|
|
62
77
|
});
|
|
63
78
|
ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
|
|
64
79
|
return true;
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* POST /api/premium-dashboards/save { ws, board, id?, name, purpose, charts, main, remove? } → { ok, dashboard, dashboards }
|
|
5
5
|
* one `save` or `remove` line in <state>/premium-dashboards.jsonl (lib/premium-dashboards.js, the one writer)
|
|
6
6
|
*
|
|
7
|
+
* POST /api/premium-dashboards/pin { ws, board, id: 'all' | saved id | null } → { ok, pinned } (initiative insights-one-list L4)
|
|
8
|
+
* one `pin` line in the same ledger: the dashboard shown at the top of Insights, and nowhere else
|
|
9
|
+
*
|
|
7
10
|
* The page reads the dashboards through GET /api/insights-premium, so this module has no GET.
|
|
8
11
|
*
|
|
9
12
|
* WHO WRITES. The POST refuses a request that carries an agent session header (403), as routes-custom-docs.js does, and passes pm-guard
|
|
@@ -33,7 +36,8 @@ function krIds(ctx, ws) {
|
|
|
33
36
|
|
|
34
37
|
async function handle(req, res, url, ctx) {
|
|
35
38
|
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
36
|
-
|
|
39
|
+
const isPin = url.pathname === '/api/premium-dashboards/pin';
|
|
40
|
+
if (url.pathname !== '/api/premium-dashboards/save' && !isPin) return send(bad(404, 'no such premium-dashboards route'));
|
|
37
41
|
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
38
42
|
const read = await ctx.readJson(req);
|
|
39
43
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
@@ -43,6 +47,13 @@ async function handle(req, res, url, ctx) {
|
|
|
43
47
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
44
48
|
const w = wsOf(ctx, text(body.ws));
|
|
45
49
|
if (!w) return send(bad(404, 'no such workspace'));
|
|
50
|
+
if (isPin) {
|
|
51
|
+
const ids = boardIds(ctx, w);
|
|
52
|
+
if (!ids) return send(bad(503, 'The boards could not be read. Try again in a moment.'));
|
|
53
|
+
if (!ids.has(text(body.board))) return send(bad(404, 'no such board in this workspace'));
|
|
54
|
+
const r = PD.pin(w.root, body, g.actor, { now: Date.now() });
|
|
55
|
+
return send(r.ok ? { status: 200, body: { ok: true, pinned: r.pinned } } : bad(r.status, r.error));
|
|
56
|
+
}
|
|
46
57
|
const c = PD.check(body);
|
|
47
58
|
if (!c.ok) return send(bad(c.status, c.error));
|
|
48
59
|
const ids = boardIds(ctx, w);
|
|
@@ -63,7 +63,8 @@ const DEFS = Object.freeze({
|
|
|
63
63
|
'sess.idle': one('sessions', 'computer', ['15', '30', '60', 'never'], '30'),
|
|
64
64
|
'sess.share': one('sessions', 'computer', ['ws', 'job'], 'ws'),
|
|
65
65
|
'look.start': one('appearance', 'computer', ['brief', 'cal', 'work', 'init', 'rep'], 'brief'),
|
|
66
|
-
|
|
66
|
+
// premium-updates: once a day by default. An open page posts the check; the server never schedules one (no-network.test.js).
|
|
67
|
+
'upd.check': one('updates', 'computer', ['press', 'daily'], 'daily'),
|
|
67
68
|
'upd.apply': one('updates', 'computer', ['ask', 'idle'], 'ask'),
|
|
68
69
|
'upd.kits': one('updates', 'computer', ['all', 'each'], 'all'),
|
|
69
70
|
'upd.channel': one('updates', 'computer', ['stable', 'early'], 'stable'),
|
|
@@ -73,6 +74,7 @@ const DEFS = Object.freeze({
|
|
|
73
74
|
* shows; `off` is the value that turns the thing off, or null when any value wins. */
|
|
74
75
|
const ENV = Object.freeze([
|
|
75
76
|
{ key: 'notes.language', env: 'PMOS_WHISPER_LANG', off: null, effect: 'Every line is transcribed in this language, whatever the picker says.' },
|
|
77
|
+
{ key: 'upd.check', env: 'PMOS_UPDATE_CHECK', off: 'press', effect: 'Updates are checked only when you press Check on this computer.' },
|
|
76
78
|
{ key: 'rec.echo', env: 'PMOS_NOTES_ECHO', off: 'off', effect: 'Echo removal is off on this computer.' },
|
|
77
79
|
{ key: 'rec.final', env: 'PMOS_NOTES_FINAL', off: 'off', effect: 'The pass after Stop is off on this computer.' },
|
|
78
80
|
{ key: 'notes.wispr', env: 'PMOS_NOTES_WISPR', off: 'off', effect: 'Wispr Flow notes are not fetched on this computer.' },
|