create-pmos 0.535.0 → 0.537.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 +27 -41
- 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/board-programs-test.js +18 -13
- package/workspace/board-publish-ui-test.js +1 -1
- package/workspace/board-shared-ui-test.js +3 -3
- package/workspace/board-workflows-test.js +26 -32
- package/workspace/briefing-premium-board-test.js +34 -29
- package/workspace/changelog.json +26 -0
- package/workspace/fixtures/board-workflows-facts.js +7 -1
- package/workspace/guide/board.md +12 -1
- package/workspace/guide/programs.md +2 -2
- package/workspace/guide/reports.md +11 -1
- package/workspace/lib/report-engine.js +27 -6
- package/workspace/lib/report-library.js +1 -1
- package/workspace/lib/report-orders.js +218 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-report-flow.js +1 -1
- package/workspace/lib/routes-report-orders.js +161 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-vw-jira-test.js +1 -1
- package/workspace/public/pm/bd-acts.js +16 -11
- package/workspace/public/pm/bd-publish.js +1 -1
- package/workspace/public/pm/bd-wf.js +5 -28
- package/workspace/public/pm/cozy-board.css +64 -31
- package/workspace/public/pm/cozy-vw-rp.css +40 -0
- package/workspace/public/pm/premium-board.js +85 -52
- package/workspace/public/pm/premium-report-read.js +90 -9
- package/workspace/public/pm/readonly.js +1 -1
- package/workspace/public/pm/report-orders-ui.js +115 -0
- package/workspace/public/premium-board.html +27 -30
- package/workspace/skills/report-write.skill +1 -1
- package/workspace/test-lists/report-orders.json +11 -0
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.537.0",
|
|
4
|
+
"at": "2026-11-05T23:09:31.438Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1253,
|
|
9
|
+
"t": "One-row Board header, no workflow chips",
|
|
10
|
+
"s": "One-row Board header, no workflow chips",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"v": "0.536.0",
|
|
17
|
+
"at": "2026-11-05T10:03:22.177Z",
|
|
18
|
+
"f": 4,
|
|
19
|
+
"prs": [
|
|
20
|
+
{
|
|
21
|
+
"n": 1252,
|
|
22
|
+
"t": "Apply an order to a report draft, and save my own",
|
|
23
|
+
"s": "Apply an order to a report draft, and save my own",
|
|
24
|
+
"k": "new"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
2
28
|
{
|
|
3
29
|
"v": "0.535.0",
|
|
4
30
|
"at": "2026-11-05T09:07:13.086Z",
|
|
@@ -46,4 +46,10 @@ function facts(o = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
/** Only Product feature rows: the board as it is before any other workflow exists. */
|
|
48
48
|
const pfOnly = (o = {}) => F.facts(o);
|
|
49
|
-
|
|
49
|
+
/** Only the Tender rows (and the one in Won't do): a board on one PM-made workflow, which the Board draws by that workflow's own stages. The
|
|
50
|
+
* Board picks no workflow (batch 28 item 3), so this is how a test reaches one workflow's own stages. */
|
|
51
|
+
function tenderOnly(o = {}) {
|
|
52
|
+
const base = F.facts(), rows = WF_ROWS.filter((r) => r.wf.id === 'tender').map((r) => ({ ...r }));
|
|
53
|
+
return F.facts({ rows, total: rows.length, columns: base.columns, cancelled: [{ ...WONT }], counts: { ...base.counts, open: rows.length }, ...o });
|
|
54
|
+
}
|
|
55
|
+
module.exports = { facts, pfOnly, tenderOnly, WORKFLOWS, WF_ROWS, WONT };
|
package/workspace/guide/board.md
CHANGED
|
@@ -2,13 +2,24 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "pmos board: the items of every initiative"
|
|
4
4
|
description: "How pmos board prints the items of every initiative in four columns from a terminal, and where the workspace shows initiatives and their tasks."
|
|
5
|
-
timestamp: 2026-11-
|
|
5
|
+
timestamp: 2026-11-05
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# pmos board: the items of every initiative
|
|
9
9
|
|
|
10
10
|
The **Board** place of the workspace shows initiatives, not items: every initiative of the products you pick, by stage, with programs, a timeline and a list. [Programs on the Board](programs.md) explains it. An initiative's tasks show under it in Home's list and in the initiative's page in the Viewer.
|
|
11
11
|
|
|
12
|
+
## The top row
|
|
13
|
+
|
|
14
|
+
The Board has one row of controls at the top, on a phone and on a computer. The pieces are in this order:
|
|
15
|
+
|
|
16
|
+
- **The product picker.** Pick the products that the Board shows.
|
|
17
|
+
- **The view.** On a computer, press **List**, **By stage**, **Track** or **Timeline**. On the timeline, the span chip (for example **Quarter**) is next to the views. On a phone, press the view button. Its menu has the four views, the spans when the timeline shows, and **Shared with me**.
|
|
18
|
+
- **Needs a look.** One pill with a dot and a number for the new asks, late, at risk, blocked and idle initiatives. Press it to see each one. When all of them are zero, the pill does not show.
|
|
19
|
+
- **Find**, then the tools. On a computer: Adler's face (press it to read Jira again), **Group** (only when a program holds an initiative here), **Sort**, **Filter**, **Shared**, then **+** for a new program or initiative. On a phone, the tune button holds Group, Sort, Filter and the Jira read. A dot on it shows that the Jira read is old or that a filter is on.
|
|
20
|
+
|
|
21
|
+
**Sprint N only** is the first chip in Filter's Sprint group. It is on when the board has a sprint. The Board does not pick a workflow: with more than one workflow on a board, By stage and the track show the three categories To do, In progress and Done.
|
|
22
|
+
|
|
12
23
|
## What an initiative's status means
|
|
13
24
|
|
|
14
25
|
The status of an initiative tells only what PMOS read. If PMOS read nothing, the status is **No signal**.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Programs on the Board: All products, groupings and the program panel"
|
|
4
4
|
description: "A program groups initiatives across products. How it shows on the Board (stage track, Kanban, timeline and List), the All products mode, the By product grouping, the program panel and the side panel width."
|
|
5
|
-
timestamp: 2026-11-
|
|
5
|
+
timestamp: 2026-11-05
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Programs on the Board
|
|
@@ -19,7 +19,7 @@ A cancelled or archived initiative leaves its program's views: the band, the pro
|
|
|
19
19
|
- An address with `?ws=`, `?board=`, `?all=1` or `?pick=` is a one-off view: the Board shows what the address names and does not change the saved pick. A change in the list saves the pick and opens the Board without those parts.
|
|
20
20
|
- A program comes first. Its band shows the stage spread of its initiatives, the next milestone and how many initiatives are ready for it. Under the band, the initiatives sit under a small heading for each product. Then each product has its own group.
|
|
21
21
|
- A product's group head works like a program's: press the product's tile or name to open its page in Home's Viewer. Press the chevron to fold the group. This works in every view: the stage track, Kanban, the timeline and List. On a shared board, the product's name is plain text.
|
|
22
|
-
- To group by product only,
|
|
22
|
+
- To group by product only, press **Group** in the top row and choose **By product**. On a phone, Group is in the tune button. A program member then shows a small layers icon and stays under its product in every view, the timeline included. The Group button is blue while By product is on.
|
|
23
23
|
- **Kanban** shows programs as swimlanes, then products. Press a column header to fold the column to a strip with its count. An empty column starts folded. The Board remembers each fold.
|
|
24
24
|
- The **timeline** draws a program row that brackets its initiatives' bars, on every span. Program milestones are diamonds. Milestones that are close together merge into one diamond with a count.
|
|
25
25
|
- On the timeline, **every initiative has a row**, in a program or not, in every grouping. An initiative with no dates says **No dates** beside today; in each group it comes after the dated ones. Under the chart, a line gives how many have no dates, with **Ask to propose dates**.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Guide
|
|
3
3
|
title: "Reports: draft and issue a cadence report"
|
|
4
4
|
description: "How pmos report drafts a cadence report with every number, how the notes are kept when you draft again, and how you issue and freeze a report."
|
|
5
|
-
timestamp: 2026-11-
|
|
5
|
+
timestamp: 2026-11-05
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Reports: draft and issue a cadence report
|
|
@@ -65,6 +65,16 @@ When you draft a slot again, every note stays as you wrote it, next to its initi
|
|
|
65
65
|
|
|
66
66
|
When you ask Claude in a chat to change a report, the change goes to the latest draft of that report, in its own file. The report's session edits only the notes that the change is about, even when they have text, and keeps every other note and every number as it is. It keeps each caveat (a sentence that says something is provisional, not decided or unverified), also when you ask for shorter text, and it tells you which notes it changed and quotes any sentence it removed. It drafts the same slot again only when you ask for fresh numbers. It never drafts a new slot for today. A change to a number, a date, a section or a slide is not made in the draft: the session tells you which setting to change in the template or the studio. If the latest cycle is issued, it is frozen, and the change is not passed on.
|
|
67
67
|
|
|
68
|
+
## Orders: the slide order of a draft
|
|
69
|
+
|
|
70
|
+
An order is a default order of slides, for example the Weekly Review order. The writer keeps every reading, retitles each part as a finding, and adds or drops a part when the findings say so. PMOS has seven orders. You can also save your own.
|
|
71
|
+
|
|
72
|
+
- **Claude's pick.** When an order fits the question of a draft better than its own order, a ✦ shows under the slides. It names the order and the parts that it adds (in blue) or drops (struck through). Press ✓ to write the draft again in that order. Press ✕ to hide the ✦. No ✦ shows on an issued report, on a draft that started from an order, or when your readers agreed the order.
|
|
73
|
+
- **The orders.** The grid icon under the summary opens the orders: the draft as it is now, your orders, then the seven PMOS orders. Each card shows its first slides and its number of slides. Press a card to see all its slides, its parts and what it changes in your draft. Press ✓ to write the draft again in that order.
|
|
74
|
+
- **Agreed order.** When the readers agreed the order of the last issued report, today's draft stays as agreed. ✓ then reads "Use from the next cycle": the next draft starts in the order that you picked.
|
|
75
|
+
- **The name and Undo.** The order's name shows under the summary, from the draft to the issued report. For one day after a redraft, the Undo icon puts the draft back as it was. An issued report is frozen: it has no Undo.
|
|
76
|
+
- **My orders.** The bookmark icon under the summary saves the draft's order as yours. When you change a draft that started from an order, a ✦ asks if you want to save it. The bookmark under the slide saves one slide's layout to My slides. Only the parts and the slide layouts are saved, never the numbers or the words. Your orders are private and show first, marked Mine. You can rename and delete only your own orders. To use a saved slide in a draft is not possible yet.
|
|
77
|
+
|
|
68
78
|
## The commands
|
|
69
79
|
|
|
70
80
|
`pmos report draft <cadence> [<slot>]` writes the draft to `planning/reports/<cadence>/<slot>.md`. The slot is a date, YYYY-MM-DD. If you do not give a slot, the slot is today. If a draft for the slot exists, the command stops and writes nothing. To draft the slot again and keep every note, add `--redraft`. To fix the clock, add `--now <time>`: two drafts with the same inputs and the same `--now` are the same, byte for byte.
|
|
@@ -55,6 +55,7 @@ const READING_ID_RE = /^[a-z0-9][a-z0-9._-]{0,80}$/;
|
|
|
55
55
|
const SOURCE_ID_RE = /^[a-z0-9][a-z0-9._-]{0,40}$/;
|
|
56
56
|
const TOKEN_RE = /\{\{r:([a-z0-9][a-z0-9._-]{0,80})(?:\|(of|n|value|label))?\}\}/g;
|
|
57
57
|
const DAY = 86400000;
|
|
58
|
+
const NEXT_ORDER = 'order-next.json'; // the order the PM chose for the next cycle (lib/report-orders.js)
|
|
58
59
|
const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
59
60
|
const CYCLE_DAYS = { daily: 1, weekly: 7, biweekly: 14, 'bi-weekly': 14, monthly: 30, quarterly: 91 };
|
|
60
61
|
const LIMITS = Object.freeze({ readings: 2000, findings: 60, sections: 30, blocks: 40, rows: 60, cols: 12, text: 2000, title: 240, rules: 60 });
|
|
@@ -205,6 +206,14 @@ function issuedSlots(root, id) {
|
|
|
205
206
|
/** The headings of a document the engine did not write: the agreed outline of an older issue. */
|
|
206
207
|
const headingsOf = (md) => str(md).replace(/^---[\s\S]*?\n---\n?/, '').split('\n').filter((l) => /^## /.test(l)).map((l) => l.slice(3).trim()).filter(Boolean);
|
|
207
208
|
|
|
209
|
+
/** null when o is a usable order { id, name, outline: [{ part, layout }] } (1 to 30 parts, each layout one of lib/report-slides.js LAYOUTS), else why. */
|
|
210
|
+
function orderError(o) {
|
|
211
|
+
if (!isObj(o) || !/^[a-z0-9][a-z0-9:-]{0,60}$/.test(str(o.id)) || !str(o.name).trim()) return 'an order has an id and a name';
|
|
212
|
+
if (!Array.isArray(o.outline) || !o.outline.length || o.outline.length > 30) return 'an order has 1 to 30 parts';
|
|
213
|
+
const L = require('./report-slides.js').LAYOUTS;
|
|
214
|
+
const bad = o.outline.find((p) => !isObj(p) || !str(p.part).trim() || !L.includes(str(p.layout)));
|
|
215
|
+
return bad ? `part ${JSON.stringify(bad && bad.part)} has no known layout` : null;
|
|
216
|
+
}
|
|
208
217
|
function briefOf(root, id, { slot, ask, readers, sources, template, now = Date.now() } = {}) {
|
|
209
218
|
if (!ID_RE.test(str(id))) return refuse(400, 'the report id is lower case letters, digits and dashes, at most 40, starting with a letter');
|
|
210
219
|
const today = slot || dayOf(now);
|
|
@@ -281,10 +290,20 @@ function briefOf(root, id, { slot, ask, readers, sources, template, now = Date.n
|
|
|
281
290
|
from.push(LP.md.rel);
|
|
282
291
|
}
|
|
283
292
|
// a report template (lib/report-library.js) is a default order of slide layouts for a report with no agreed outline; the agreed one wins
|
|
293
|
+
// template is an id of lib/report-library.js TEMPLATES, or an order already resolved ({ id, name, outline }: a saved "my order" or the brief's own,
|
|
294
|
+
// kept across a re-read). chosen: the PM pressed ✓ on it for this cycle, so it wins over the agreed outline (batch 27 item 16, lib/report-orders.js).
|
|
295
|
+
// an order the PM chose on an agreed outline "from the next cycle" (lib/report-orders.js setNext): a later slot starts from it
|
|
296
|
+
if (!template) { const nx = readJson(path.join(paths(abs, id).dir, NEXT_ORDER)); if (nx && isObj(nx.order) && isDate(nx.from) && today > nx.from) template = { ...nx.order, chosen: true }; }
|
|
284
297
|
if (template) {
|
|
285
|
-
const t = require('./report-library.js').templateOf(str(template));
|
|
286
|
-
if (!t) return refuse(400, `there is no report template ${template}. The templates: ${require('./report-library.js').TEMPLATES.map((x) => x.id).join(', ')}`);
|
|
287
|
-
|
|
298
|
+
const t = isObj(template) ? orderError(template) ? null : template : require('./report-library.js').templateOf(str(template));
|
|
299
|
+
if (!t) return refuse(400, isObj(template) ? `the order is not usable: ${orderError(template)}` : `there is no report template ${template}. The templates: ${require('./report-library.js').TEMPLATES.map((x) => x.id).join(', ')}`);
|
|
300
|
+
const chosen = !!(isObj(template) && template.chosen);
|
|
301
|
+
if (!brief.agreed_outline.length || chosen) {
|
|
302
|
+
from.push(`template:${t.id}`);
|
|
303
|
+
brief.template = { id: str(t.id), name: str(t.name), outline: t.outline.map((o) => ({ part: str(o.part), layout: str(o.layout) })), ...(chosen ? { chosen: true } : {}) };
|
|
304
|
+
// the PM chose another order over the agreed one: the agreed outline is kept as an example only
|
|
305
|
+
if (chosen && brief.agreed_outline.length) { brief.earlier_outline = brief.agreed_outline; brief.agreed_outline = []; }
|
|
306
|
+
}
|
|
288
307
|
}
|
|
289
308
|
brief.rules = rulesOf(abs, id);
|
|
290
309
|
for (const r of brief.rules) if (r.kind === 'voice' || r.kind === 'wording') brief.voice.push(r.text);
|
|
@@ -778,7 +797,7 @@ function make(root, id, { slot, ask, readers, sources, template, add, gaps, addF
|
|
|
778
797
|
const old = readJson(P.brief.abs);
|
|
779
798
|
// a re-read keeps the brief's chat question and named sources unless new ones are given
|
|
780
799
|
const b = briefOf(abs, id, { slot: day, now, ask: ask || (old && old.from && old.from.includes('chat') ? old.question : undefined), readers: readers || (old && old.from && old.from.includes('readers') ? old.readers : undefined),
|
|
781
|
-
template: template || (old && old.template ? old.template.id : undefined),
|
|
800
|
+
template: template || (old && old.template ? (!old.template.chosen && require('./report-library.js').templateOf(old.template.id) ? old.template.id : old.template) : undefined),
|
|
782
801
|
sources: [...(old ? old.sources.filter((s) => s.kind === 'pack' || s.kind === 'connector' || s.kind === 'document') : []), ...(sources || [])] });
|
|
783
802
|
if (!b.ok) return b;
|
|
784
803
|
const rd = readingsOf(abs, b.brief, { add, gaps, keep: readJson(P.readings.abs), now });
|
|
@@ -790,6 +809,8 @@ function make(root, id, { slot, ask, readers, sources, template, add, gaps, addF
|
|
|
790
809
|
const fd = findingsOf(b.brief, rd, { prior, add: keepFiled.concat(Array.isArray(addFindings) ? addFindings : []) });
|
|
791
810
|
if (fd.ok === false) return fd;
|
|
792
811
|
writeJson(P.brief.abs, b.brief);
|
|
812
|
+
// the order chosen for the next cycle is used once: this brief now carries it, so the record goes
|
|
813
|
+
if (b.brief.template && b.brief.template.chosen) { const nf = path.join(P.dir, NEXT_ORDER); const nx = readJson(nf); if (nx && isObj(nx.order) && nx.order.id === b.brief.template.id && day > nx.from) { try { fs.unlinkSync(nf); } catch { /* already gone */ } } }
|
|
793
814
|
writeJson(P.readings.abs, { at: rd.at, readings: rd.readings, gaps: rd.gaps });
|
|
794
815
|
writeJson(P.findings.abs, fd);
|
|
795
816
|
return { ok: true, brief: b.brief, readings: { readings: rd.readings, gaps: rd.gaps }, findings: fd, paths: { brief: P.brief.rel, readings: P.readings.rel, findings: P.findings.rel, report: P.report.rel, md: P.md.rel } };
|
|
@@ -834,7 +855,7 @@ function engineDeckOf(absMd, look) {
|
|
|
834
855
|
}
|
|
835
856
|
|
|
836
857
|
module.exports = {
|
|
837
|
-
ID_RE, BEYOND, BEYOND_KEYS, VOICE, RULE_KINDS, BLOCK_KINDS, LIMITS,
|
|
838
|
-
paths, briefOf, readingsOf, findingsOf, resolve, tokensIn, bareFigures, checkReport, shapeError, renderMarkdown, deckOf, make, write,
|
|
858
|
+
ID_RE, NEXT_ORDER, BEYOND, BEYOND_KEYS, VOICE, RULE_KINDS, BLOCK_KINDS, LIMITS,
|
|
859
|
+
paths, briefOf, orderError, readingsOf, findingsOf, resolve, tokensIn, bareFigures, checkReport, shapeError, renderMarkdown, deckOf, make, write,
|
|
839
860
|
engineReportOf, engineDeckOf, rulesOf, addRule, removeRule, closeAsk, parseSource, sourcesFromText, full, valueText,
|
|
840
861
|
};
|
|
@@ -131,4 +131,4 @@ function templateDeck(id, o = {}) {
|
|
|
131
131
|
/** The library page: every layout, or one template (o.template). */
|
|
132
132
|
const libraryHtml = (o = {}) => RS.deckHtml(o.template ? templateDeck(o.template, o) : sampleDeck(o));
|
|
133
133
|
|
|
134
|
-
module.exports = { sampleDeck, libraryHtml, TEMPLATES, templateOf, templateCard, templateDeck };
|
|
134
|
+
module.exports = { sampleDeck, libraryHtml, TEMPLATES, templateOf, templateCard, templateDeck, NAMES };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* report-orders.js — apply an order to a report draft, and keep my own orders (batch 27 item 16, agreed by Wawan 2026-11-05 00:53 "Build the
|
|
3
|
+
* recommendation"; main canvas boards TpA, TpD, TpE; brief /mnt/project-files/feedback-batch-27/item16/build-brief.md).
|
|
4
|
+
*
|
|
5
|
+
* The app says "order", never "template": T<n> already names a report's saved settings (lib/report-templates.js). An ORDER is a default order of
|
|
6
|
+
* slide layouts, { id, name, outline: [{ part, layout }] }: the seven of lib/report-library.js TEMPLATES, or one the PM saved ("Mine"). It is never
|
|
7
|
+
* a fixed structure: the writer retitles each part as a finding and adds or drops a part when the findings say so.
|
|
8
|
+
*
|
|
9
|
+
* partsOf(report, brief) → [{ part, layout }] the draft's order: one per section, named by its order's part or its layout (pure)
|
|
10
|
+
* diff(now, order) → { adds: [part], drops: [part] } by layout; the title and sources slides every deck has are left out (pure)
|
|
11
|
+
* nowOf(brief, report) → { kind: 'agreed'|'order'|'standard', id, name, parts, mine, edited, changes } the draft's order (pure)
|
|
12
|
+
* pick(brief, report) → { id, name, adds, drops } | null the ✦: the order that fits the report's question, by plain rules (pure)
|
|
13
|
+
* orderOf(id, mine) → an order by id: a TEMPLATES id or a saved "mine-<n>" (mine = fold(...).orders)
|
|
14
|
+
* previewDeck(order) → the order drawn with placeholder words, one slide per part (lib/report-slides.js deckHtml takes it)
|
|
15
|
+
* snapshot / undoOf / undo the draft as it was before a redraft, kept one day (Undo)
|
|
16
|
+
* setNext / nextOf an order chosen on an agreed outline, used from the next cycle (lib/report-engine.js briefOf reads it)
|
|
17
|
+
* MY ORDERS (person level, private): <runtimeDir>/report-orders.jsonl, append only
|
|
18
|
+
* { ev: 'save', id: 'mine-<n>', kind: 'order'|'slide', name, outline, from: { report, slot }, at } { ev: 'rename', id, name, at } { ev: 'remove', id, at }
|
|
19
|
+
* fold(lines) → { orders, slides } (newest first) · readLines(dir) · save(dir, o) · rename(dir, id, name) · remove(dir, id)
|
|
20
|
+
*
|
|
21
|
+
* WHAT IS SAVED. Parts and slide layouts only. Never a number, a sentence or a reading: those belong to one cycle and would be stale. A part's
|
|
22
|
+
* name is its order's part name, else its layout's name ("Ledger"); never the section's title, which is a finding.
|
|
23
|
+
*/
|
|
24
|
+
const fs = require('fs');
|
|
25
|
+
const path = require('path');
|
|
26
|
+
const crypto = require('crypto');
|
|
27
|
+
const RL = require('./report-library.js');
|
|
28
|
+
|
|
29
|
+
const DAY = 86400000;
|
|
30
|
+
const UNDO_FOR = DAY; // the previous draft is kept one day (TpA 3)
|
|
31
|
+
const DRAFTING_FOR = 30 * 60000; // a redraft that has not landed after 30 minutes is no longer "redrafting"
|
|
32
|
+
const ALWAYS = new Set(['overview', 'sources']); // the engine draws the title and the sources slides on every deck
|
|
33
|
+
const LEDGER = 'report-orders.jsonl';
|
|
34
|
+
const MINE_RE = /^mine-[1-9][0-9]{0,5}$/;
|
|
35
|
+
const FILES = ['.md', '.report.json', '.brief.json', '.checks.json', '.findings.json'];
|
|
36
|
+
const str = (v) => (typeof v === 'string' ? v : v == null ? '' : String(v));
|
|
37
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
38
|
+
const nameOfLayout = (l) => (RL.NAMES[l] || (l === 'component' ? 'PMOS component' : 'Text'));
|
|
39
|
+
const RE = () => require('./report-engine.js');
|
|
40
|
+
|
|
41
|
+
/* ── the draft's order (pure) ── */
|
|
42
|
+
/** One part per section of the engine's report, in order. The name comes from the order the draft began with (the first unused part of the same
|
|
43
|
+
* layout), else from the layout. A section's own title is a finding, so it is never a part name. */
|
|
44
|
+
function partsOf(report, brief) {
|
|
45
|
+
const secs = isObj(report) && Array.isArray(report.sections) ? report.sections : [];
|
|
46
|
+
const pool = (brief && brief.template && Array.isArray(brief.template.outline) ? brief.template.outline : []).map((p) => ({ ...p, used: false }));
|
|
47
|
+
return secs.map((s) => {
|
|
48
|
+
const layout = str(s.layout) || 'blocks';
|
|
49
|
+
const m = pool.find((p) => !p.used && p.layout === layout);
|
|
50
|
+
if (m) m.used = true;
|
|
51
|
+
return { part: m ? m.part : nameOfLayout(layout), layout };
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const core = (parts) => (parts || []).filter((p) => !ALWAYS.has(p.layout));
|
|
55
|
+
/** What an order adds to the draft and what it drops, matched by layout (a layout used twice counts twice). */
|
|
56
|
+
function diff(now, order) {
|
|
57
|
+
const left = core(now).map((p) => ({ ...p, hit: false }));
|
|
58
|
+
const adds = [];
|
|
59
|
+
for (const p of core(order)) { const m = left.find((x) => !x.hit && x.layout === p.layout); if (m) m.hit = true; else adds.push(p.part); }
|
|
60
|
+
return { adds, drops: left.filter((x) => !x.hit).map((x) => x.part) };
|
|
61
|
+
}
|
|
62
|
+
const same = (d) => !d.adds.length && !d.drops.length;
|
|
63
|
+
const isMine = (id) => MINE_RE.test(str(id));
|
|
64
|
+
/** The draft's order: agreed with its readers, an order (edited or not), or the standard one the writer chose. */
|
|
65
|
+
function nowOf(brief, report) {
|
|
66
|
+
const parts = partsOf(report, brief);
|
|
67
|
+
const b = brief || {};
|
|
68
|
+
if (Array.isArray(b.agreed_outline) && b.agreed_outline.length) return { kind: 'agreed', id: 'agreed', name: 'Agreed order', parts, mine: false, edited: false, changes: { adds: [], drops: [] }, since: b.last_issue || null };
|
|
69
|
+
if (b.template && b.template.id) {
|
|
70
|
+
const ch = report ? diff(b.template.outline, parts) : { adds: [], drops: [] }; // what the draft added to its order (adds) and dropped (drops)
|
|
71
|
+
return { kind: 'order', id: str(b.template.id), name: str(b.template.name), parts, mine: isMine(b.template.id), edited: !!report && !same(ch), changes: { adds: ch.adds, drops: ch.drops } };
|
|
72
|
+
}
|
|
73
|
+
return { kind: 'standard', id: 'standard', name: 'Standard order', parts, mine: false, edited: false, changes: { adds: [], drops: [] } };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* ── the ✦ pick (pure). Plain rules over the brief's words, first match wins; no model. Silent (null) when the outline is agreed, when the draft
|
|
77
|
+
* already began from an order, or when the order would change nothing. Claude's own pick while drafting is not proven yet (owed: 5 real drafts). */
|
|
78
|
+
const RULES = [
|
|
79
|
+
['incident-review', /\b(incident|outage|post-?mortem|downtime|sev ?[0-4]|root cause)\b/],
|
|
80
|
+
['meeting-recap', /\b(meeting|recap|minutes|stand-?up|retro(spective)?|workshop)\b/],
|
|
81
|
+
['decision-brief', /\b(decide|decision|should we|go\/no-go|approve|approval)\b/],
|
|
82
|
+
['program-kickoff', /\b(kick-?off|charter|new program(me)?|program(me)? start)\b/],
|
|
83
|
+
['portfolio-snapshot', /\b(portfolio|programs|programmes|across products)\b/],
|
|
84
|
+
['quarterly-review', /\b(quarter(ly)?|q[1-4]|okr review|qbr)\b/],
|
|
85
|
+
['weekly-review', /\b(weekly|this week|week in review|last week)\b/],
|
|
86
|
+
];
|
|
87
|
+
function pick(brief, report) {
|
|
88
|
+
const b = brief || {};
|
|
89
|
+
if ((Array.isArray(b.agreed_outline) && b.agreed_outline.length) || (b.template && b.template.id)) return null;
|
|
90
|
+
const words = [b.title, b.question, ...(Array.isArray(b.questions) ? b.questions : []), b.readers].map(str).join(' \n ').toLowerCase();
|
|
91
|
+
let id = (RULES.find(([, re]) => re.test(words)) || [])[0] || null;
|
|
92
|
+
if (!id && b.recurring && b.cycle_days === 7) id = 'weekly-review';
|
|
93
|
+
if (!id && b.recurring && b.cycle_days >= 80) id = 'quarterly-review';
|
|
94
|
+
const t = id ? RL.templateOf(id) : null;
|
|
95
|
+
if (!t) return null;
|
|
96
|
+
const d = diff(partsOf(report, b), t.outline);
|
|
97
|
+
return report && same(d) ? null : { id: t.id, name: t.name, ...d };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* ── orders by id, and their pictures ── */
|
|
101
|
+
function asOrder(o) { return { id: o.id, name: o.name, outline: o.outline.map((p) => ({ part: p.part, layout: p.layout })) }; }
|
|
102
|
+
function orderOf(id, mine = []) {
|
|
103
|
+
const t = RL.templateOf(str(id));
|
|
104
|
+
if (t) return asOrder(t);
|
|
105
|
+
const m = isMine(id) ? (mine || []).find((x) => x.id === id) : null;
|
|
106
|
+
return m ? asOrder(m) : null;
|
|
107
|
+
}
|
|
108
|
+
/** One line under a card: what the order is for (a PMOS order) or when it was saved (mine). */
|
|
109
|
+
function subOf(id, mine) { const t = RL.templateOf(id); if (t) return t.use; const m = (mine || []).find((x) => x.id === id); return m ? 'Saved ' + str(m.at).slice(0, 10) : ''; }
|
|
110
|
+
/** The order with placeholder words: one slide per part, in its layout (the library's sample of that layout, titled by the part). */
|
|
111
|
+
function previewDeck(order, o = {}) {
|
|
112
|
+
if (!order) return null;
|
|
113
|
+
const lib = RL.sampleDeck(o).slides;
|
|
114
|
+
const slides = order.outline.map((p) => {
|
|
115
|
+
const s = lib.find((x) => x.layout === p.layout) || { ...lib.find((x) => x.layout === 'statement'), layout: 'statement' };
|
|
116
|
+
return { ...s, eyebrow: `${order.name} · ${p.part}`, title: p.part, sub: s.title, source: 'Order · placeholder words' };
|
|
117
|
+
});
|
|
118
|
+
slides.forEach((s, i) => { s.n = i + 1; });
|
|
119
|
+
return { name: order.name, today: o.today || '2026-11-04', slides };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* ── Undo: the draft before a redraft, kept one day ── */
|
|
123
|
+
const sha = (t) => crypto.createHash('sha256').update(String(t)).digest('hex').slice(0, 16);
|
|
124
|
+
const undoDir = (P, slot) => path.join(P.dir, '.undo', slot);
|
|
125
|
+
function readJson(f) { try { const o = JSON.parse(fs.readFileSync(f, 'utf8')); return isObj(o) ? o : null; } catch { return null; } }
|
|
126
|
+
/** Copy the draft's files aside before a redraft. One snapshot per slot: Undo gives back the draft as it was before the NEWEST redraft. */
|
|
127
|
+
function snapshot(root, id, slot, { order = null, now = Date.now() } = {}) {
|
|
128
|
+
const P = RE().paths(root, id, slot);
|
|
129
|
+
const dir = undoDir(P, slot);
|
|
130
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
131
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
132
|
+
const had = [];
|
|
133
|
+
for (const ext of FILES) { const f = path.join(P.dir, slot + ext); if (fs.existsSync(f)) { fs.copyFileSync(f, path.join(dir, slot + ext)); had.push(ext); } }
|
|
134
|
+
let md = ''; try { md = fs.readFileSync(P.md.abs, 'utf8'); } catch { /* no document yet */ }
|
|
135
|
+
const meta = { at: new Date(now).toISOString(), order: order ? { id: order.id, name: order.name } : null, had, md: sha(md) };
|
|
136
|
+
fs.writeFileSync(path.join(dir, 'meta.json'), JSON.stringify(meta) + '\n');
|
|
137
|
+
return meta;
|
|
138
|
+
}
|
|
139
|
+
/** The Undo of a slot: { at, until, order, state: 'drafting'|'done'|'late' } while its day lasts and the slot is not issued, else null.
|
|
140
|
+
* drafting = the document has not changed since the press (the session still writes); late = it has not changed after 30 minutes. */
|
|
141
|
+
function undoOf(root, id, slot, { now = Date.now(), issued = false } = {}) {
|
|
142
|
+
if (issued) return null;
|
|
143
|
+
let P; try { P = RE().paths(root, id, slot); } catch { return null; }
|
|
144
|
+
const meta = readJson(path.join(undoDir(P, slot), 'meta.json'));
|
|
145
|
+
if (!meta || !Number.isFinite(Date.parse(meta.at))) return null;
|
|
146
|
+
const at = Date.parse(meta.at);
|
|
147
|
+
if (now - at > UNDO_FOR) return null;
|
|
148
|
+
let md = ''; try { md = fs.readFileSync(P.md.abs, 'utf8'); } catch { /* gone */ }
|
|
149
|
+
const changed = sha(md) !== meta.md;
|
|
150
|
+
return { at: meta.at, until: new Date(at + UNDO_FOR).toISOString(), order: meta.order, state: changed ? 'done' : now - at > DRAFTING_FOR ? 'late' : 'drafting' };
|
|
151
|
+
}
|
|
152
|
+
/** Put the draft back as it was before the redraft: the files it had come back, the files it did not have go. */
|
|
153
|
+
function undo(root, id, slot, o = {}) {
|
|
154
|
+
const u = undoOf(root, id, slot, o);
|
|
155
|
+
if (!u) return { ok: false, status: 409, error: 'there is nothing to undo on this draft' };
|
|
156
|
+
const P = RE().paths(root, id, slot); const dir = undoDir(P, slot);
|
|
157
|
+
const meta = readJson(path.join(dir, 'meta.json'));
|
|
158
|
+
for (const ext of FILES) {
|
|
159
|
+
const to = path.join(P.dir, slot + ext);
|
|
160
|
+
if (meta.had.includes(ext)) fs.copyFileSync(path.join(dir, slot + ext), to);
|
|
161
|
+
else fs.rmSync(to, { force: true });
|
|
162
|
+
}
|
|
163
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
164
|
+
return { ok: true, order: u.order };
|
|
165
|
+
}
|
|
166
|
+
const dropUndo = (root, id, slot) => { try { const P = RE().paths(root, id, slot); fs.rmSync(undoDir(P, slot), { recursive: true, force: true }); } catch { /* none */ } };
|
|
167
|
+
|
|
168
|
+
/* ── an order for the next cycle (an agreed outline: today's draft stays as agreed) ── */
|
|
169
|
+
function setNext(root, id, order, from, { now = Date.now(), by = 'pm' } = {}) {
|
|
170
|
+
const P = RE().paths(root, id);
|
|
171
|
+
fs.mkdirSync(P.dir, { recursive: true });
|
|
172
|
+
fs.writeFileSync(path.join(P.dir, RE().NEXT_ORDER), JSON.stringify({ order: asOrder(order), from, at: new Date(now).toISOString(), by }) + '\n');
|
|
173
|
+
return { ok: true };
|
|
174
|
+
}
|
|
175
|
+
function nextOf(root, id) { try { const x = readJson(path.join(RE().paths(root, id).dir, RE().NEXT_ORDER)); return x && isObj(x.order) ? { id: x.order.id, name: x.order.name, from: x.from } : null; } catch { return null; } }
|
|
176
|
+
|
|
177
|
+
/* ── my orders: person level, private ── */
|
|
178
|
+
const ledger = (dir) => path.join(path.resolve(String(dir)), LEDGER);
|
|
179
|
+
function readLines(dir) {
|
|
180
|
+
let t; try { t = fs.readFileSync(ledger(dir), 'utf8'); } catch { return []; }
|
|
181
|
+
return t.split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(isObj);
|
|
182
|
+
}
|
|
183
|
+
function fold(lines) {
|
|
184
|
+
const m = new Map();
|
|
185
|
+
for (const e of lines || []) {
|
|
186
|
+
if (e.ev === 'save' && isMine(e.id) && Array.isArray(e.outline)) m.set(e.id, { id: e.id, kind: e.kind === 'slide' ? 'slide' : 'order', name: str(e.name), outline: e.outline, from: e.from || null, at: str(e.at) });
|
|
187
|
+
else if (e.ev === 'rename' && m.has(e.id)) m.get(e.id).name = str(e.name);
|
|
188
|
+
else if (e.ev === 'remove') m.delete(e.id);
|
|
189
|
+
}
|
|
190
|
+
const all = [...m.values()].reverse();
|
|
191
|
+
return { orders: all.filter((x) => x.kind === 'order'), slides: all.filter((x) => x.kind === 'slide') };
|
|
192
|
+
}
|
|
193
|
+
const cleanName = (n) => str(n).replace(/\{\{r:[^}]*\}\}/g, '').replace(/\s+/g, ' ').trim().slice(0, 80);
|
|
194
|
+
/** Save an order (kind 'order', the whole deck's parts) or one slide (kind 'slide', one part). Only parts and layouts are kept. */
|
|
195
|
+
function save(dir, { kind = 'order', name, outline, from = null }, { now = Date.now() } = {}) {
|
|
196
|
+
const nm = cleanName(name);
|
|
197
|
+
if (!nm) return { ok: false, status: 400, error: 'say its name' };
|
|
198
|
+
const parts = (Array.isArray(outline) ? outline : []).map((p) => ({ part: cleanName(p && p.part).slice(0, 60) || nameOfLayout(p && p.layout), layout: str(p && p.layout) }));
|
|
199
|
+
const err = RE().orderError({ id: 'mine-1', name: nm, outline: parts });
|
|
200
|
+
if (err) return { ok: false, status: 400, error: err };
|
|
201
|
+
if (kind === 'slide' && parts.length !== 1) return { ok: false, status: 400, error: 'a slide is one part' };
|
|
202
|
+
const lines = readLines(dir);
|
|
203
|
+
const n = lines.reduce((x, e) => Math.max(x, +(/^mine-(\d+)$/.exec(str(e.id)) || [0, 0])[1]), 0) + 1;
|
|
204
|
+
const e = { ev: 'save', id: 'mine-' + n, kind: kind === 'slide' ? 'slide' : 'order', name: nm, outline: parts, from: isObj(from) ? { report: str(from.report), slot: str(from.slot) } : null, at: new Date(now).toISOString() };
|
|
205
|
+
fs.mkdirSync(path.resolve(String(dir)), { recursive: true });
|
|
206
|
+
fs.appendFileSync(ledger(dir), JSON.stringify(e) + '\n');
|
|
207
|
+
return { ok: true, id: e.id, saved: fold(lines.concat(e)) };
|
|
208
|
+
}
|
|
209
|
+
function change(dir, ev, id, extra, now) {
|
|
210
|
+
if (!isMine(id) || ![...fold(readLines(dir)).orders, ...fold(readLines(dir)).slides].some((x) => x.id === id)) return { ok: false, status: 404, error: 'there is no saved order ' + id };
|
|
211
|
+
fs.appendFileSync(ledger(dir), JSON.stringify({ ev, id, ...extra, at: new Date(now).toISOString() }) + '\n');
|
|
212
|
+
return { ok: true };
|
|
213
|
+
}
|
|
214
|
+
function rename(dir, id, name, { now = Date.now() } = {}) { const nm = cleanName(name); if (!nm) return { ok: false, status: 400, error: 'say its name' }; return change(dir, 'rename', id, { name: nm }, now); }
|
|
215
|
+
function remove(dir, id, { now = Date.now() } = {}) { return change(dir, 'remove', id, {}, now); }
|
|
216
|
+
|
|
217
|
+
module.exports = { ALWAYS, LEDGER, UNDO_FOR, partsOf, diff, nowOf, pick, orderOf, subOf, previewDeck, isMine, nameOfLayout,
|
|
218
|
+
snapshot, undoOf, undo, dropUndo, setNext, nextOf, readLines, fold, save, rename, remove };
|
|
@@ -39,6 +39,7 @@ const MODULES = Object.freeze([
|
|
|
39
39
|
'routes-capture', // Run 3 (3C): ⌘K capture
|
|
40
40
|
'routes-board', // Run 4 (4D): the cross-initiative Board, Release
|
|
41
41
|
'routes-reports', // Run 5 (5C): drafts, Issue, notes
|
|
42
|
+
'routes-report-orders', // batch 27 item 16: apply an order to a report draft, Undo, my saved orders (canvas TpA, TpD, TpE)
|
|
42
43
|
'routes-report-flow', // batch 22 item 14: the report building flow (template versions, the report's own session, review)
|
|
43
44
|
'routes-notes', // meeting-notes Run 1: the Notes view (typed notes, dictation, transcripts, summaries)
|
|
44
45
|
'routes-my-work', // initiative my-work: the ranked list of work assigned to the PM, the brief, Read again
|
|
@@ -307,4 +307,4 @@ async function handle(req, res, url, ctx) {
|
|
|
307
307
|
return r.ok ? send({ status: 200, body: r }) : fail(r);
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
module.exports = { prefixes, handle, stateOf, askPrompt, draftWords };
|
|
310
|
+
module.exports = { prefixes, handle, stateOf, askPrompt, draftWords, ask };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-report-orders.js — apply an order to a report draft, Undo, and my saved orders (batch 27 item 16; main canvas TpA, TpD, TpE;
|
|
3
|
+
* lib/report-orders.js). The app says "order", never "template".
|
|
4
|
+
*
|
|
5
|
+
* GET /api/report-orders?ws&path → { ok, id, slot, issued, engine, now, pick, next, orders, slides, undo } what the draft's order is,
|
|
6
|
+
* the ✦ (pick), every order with what it adds and drops, my orders first, my slides, and the Undo
|
|
7
|
+
* GET /api/report-orders/preview?ws&order → text/html, the order drawn with placeholder words (one slide per part), sanitized
|
|
8
|
+
* POST /api/report-orders/apply { ws, path, order } → { ok, redraft: { session, started|passed } } | { ok, next: { id, name } }
|
|
9
|
+
* A draft: the draft is copied aside (Undo, one day), the brief takes the order (lib/report-engine.js make),
|
|
10
|
+
* and the report's own session is asked to write it again in that order, keeping its readings. An agreed outline:
|
|
11
|
+
* nothing changes today; the order is used from the next cycle. An issued cycle is refused 409 (it is frozen).
|
|
12
|
+
* POST /api/report-orders/undo { ws, path } → { ok } the draft as it was before the redraft (its day only)
|
|
13
|
+
* POST /api/report-orders/save { ws, path, name? } → { ok, id } the draft's parts and layouts as my order (never its numbers or words)
|
|
14
|
+
* POST /api/report-orders/slide { ws, path, n } → { ok, id, name } slide n (from 0) of the draft's deck as my slide: its layout and part
|
|
15
|
+
* POST /api/report-orders/rename { ws, id, name } → { ok }
|
|
16
|
+
* POST /api/report-orders/remove { ws, id } → { ok }
|
|
17
|
+
*
|
|
18
|
+
* MY ORDERS are the PM's own: they live in the per-user runtime directory (ctx.runtimeDir), not in any repository, and no other person reads them.
|
|
19
|
+
* WHO WRITES. Every POST passes pm-guard requirePagePress; a request with an agent session header is refused first (403). Nothing here sends
|
|
20
|
+
* anything outward; the redraft runs in the report's own session (lib/routes-report-flow.js ask), which never issues.
|
|
21
|
+
*/
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
const guard = require('./pm-guard.js');
|
|
25
|
+
const RO = require('./report-orders.js');
|
|
26
|
+
const RE = require('./report-engine.js');
|
|
27
|
+
const RL = require('./report-library.js');
|
|
28
|
+
const issues = require('./issues.js');
|
|
29
|
+
|
|
30
|
+
const prefixes = ['/api/report-orders'];
|
|
31
|
+
const POSTS = ['apply', 'undo', 'save', 'slide', 'rename', 'remove'];
|
|
32
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
33
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
34
|
+
const PATH_RE = /(?:^|\/)reports\/([a-z][a-z0-9-]{0,39})\/(\d{4}-\d{2}-\d{2})\.md$/;
|
|
35
|
+
function wsOf(ctx, id) { const w = ctx.getWs(id || null); return w && (!id || w.id === id) ? w : null; }
|
|
36
|
+
const mineDir = (ctx) => ctx.runtimeDir || require('./state-root.js').defaultRoot();
|
|
37
|
+
const readJson = (f) => { try { return JSON.parse(fs.readFileSync(f, 'utf8')); } catch { return null; } };
|
|
38
|
+
|
|
39
|
+
/** The draft a path names: { id, slot, P, issued } | { error }. The path must be a report document that exists. */
|
|
40
|
+
function draftOf(w, rel) {
|
|
41
|
+
const m = PATH_RE.exec(text(rel));
|
|
42
|
+
if (!m || text(rel).split('/').includes('..')) return { error: bad(400, 'path must be a report draft') };
|
|
43
|
+
let P; try { P = RE.paths(w.root, m[1], m[2]); } catch (e) { return { error: bad(400, e.message) }; }
|
|
44
|
+
if (!fs.existsSync(P.md.abs)) return { error: bad(404, 'no such report') };
|
|
45
|
+
let iss = false; try { iss = issues.isIssued(issues.readIssues(w.root), m[1], m[2]); } catch { iss = false; }
|
|
46
|
+
return { id: m[1], slot: m[2], P, issued: iss };
|
|
47
|
+
}
|
|
48
|
+
function setupName(w, id) { try { const RS = require('./report-setups.js'); const s = RS.fold(RS.readLines(RS.ledgerFile(w.root))).setups.get(id); return (s && s.name) || ''; } catch { return ''; } }
|
|
49
|
+
function reportName(w, id, brief) { return setupName(w, id) || (brief && brief.title) || id; }
|
|
50
|
+
/** A saved order's first name: the recurring report's ("Product weekly order"), else the order it began as ("Weekly Review, my way"), else
|
|
51
|
+
* "My order". Never an ad hoc report's title: that is its question, a sentence with dates in it. */
|
|
52
|
+
function savedName(w, id, brief) { const s = setupName(w, id); if (s) return s + ' order'; return brief && brief.template && brief.template.name ? brief.template.name.replace(/, my way$/, '') + ', my way' : 'My order'; }
|
|
53
|
+
const card = (o, now, mine, extra = {}) => ({ id: o.id, name: o.name, sub: RO.subOf(o.id, mine), n: o.outline.length, parts: o.outline, ...RO.diff(now.parts, o.outline), ...extra });
|
|
54
|
+
/** The whole state of one draft's order. */
|
|
55
|
+
function stateOf(ctx, w, d) {
|
|
56
|
+
const brief = readJson(d.P.brief.abs), report = readJson(d.P.report.abs);
|
|
57
|
+
const now = RO.nowOf(brief, report);
|
|
58
|
+
const my = RO.fold(RO.readLines(mineDir(ctx)));
|
|
59
|
+
const pk = d.issued ? null : RO.pick(brief, report);
|
|
60
|
+
const orders = my.orders.map((o) => card(o, now, my.orders, { mine: true }))
|
|
61
|
+
.concat(RL.TEMPLATES.map((t) => card({ id: t.id, name: t.name, outline: t.outline }, now, my.orders)));
|
|
62
|
+
return { ok: true, id: d.id, slot: d.slot, issued: d.issued, engine: !!report, name: reportName(w, d.id, brief),
|
|
63
|
+
now, pick: pk, next: RO.nextOf(w.root, d.id), orders, slides: my.slides.map((s) => ({ id: s.id, name: s.name, part: s.outline[0].part, layout: s.outline[0].layout, at: s.at })),
|
|
64
|
+
undo: RO.undoOf(w.root, d.id, d.slot, { issued: d.issued }) };
|
|
65
|
+
}
|
|
66
|
+
/** The words the report's session gets for a redraft in an order. */
|
|
67
|
+
function redraftWords(id, slot, rel, order) {
|
|
68
|
+
return `Write this draft again in the "${order.name}" order (${rel}, slot ${slot}). This change IS a redraft, of this slot only. `
|
|
69
|
+
+ `The brief (${slot}.brief.json) now carries the order as its template: follow skills/report-write.skill from step 3, with the order's parts as the starting outline, `
|
|
70
|
+
+ `each part in its slide layout and retitled as a finding; add or drop a part when the findings say so. Keep every reading and every finding already filed: `
|
|
71
|
+
+ `run \`pmos report make ${id} --slot ${slot}\` only when a source is missing. Then run \`pmos report write ${id} --slot ${slot} --from <file>\`.`;
|
|
72
|
+
}
|
|
73
|
+
/** The deck slide n as one saved part: its layout, and a part name that is never a finding. */
|
|
74
|
+
function slidePart(d, n) {
|
|
75
|
+
const deck = RE.engineDeckOf(d.P.md.abs, null);
|
|
76
|
+
if (!deck) return { error: bad(409, 'this draft was written before the report engine: its slides have no layouts to save') };
|
|
77
|
+
const s = deck.slides[n];
|
|
78
|
+
if (!s) return { error: bad(404, 'no such slide') };
|
|
79
|
+
const fixed = { title: ['Title', 'overview'], answer: ['The answer', s.layout], beyond: ['Beyond the question', 'agenda'], ask: ['Asks', 'decisions'], sources: ['Sources', 'sources'] };
|
|
80
|
+
if (fixed[s.kind]) return { part: fixed[s.kind][0], layout: fixed[s.kind][1] || 'statement' };
|
|
81
|
+
const report = readJson(d.P.report.abs), brief = readJson(d.P.brief.abs);
|
|
82
|
+
const parts = RO.partsOf(report, brief);
|
|
83
|
+
// the section slides come after the title and answer slides, in the report's order (a long text section may take several slides)
|
|
84
|
+
const k = deck.slides.slice(0, n + 1).filter((x) => x.kind === 'section' && !/\(continued\)$/.test(x.title)).length - 1;
|
|
85
|
+
const p = parts[k] || { part: RO.nameOfLayout(s.layout), layout: s.layout };
|
|
86
|
+
return { part: p.part, layout: p.layout };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function handle(req, res, url, ctx) {
|
|
90
|
+
const p = url.pathname;
|
|
91
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
92
|
+
const sub = p.replace(/^\/api\/report-orders\/?/, '');
|
|
93
|
+
if (req.method === 'GET') {
|
|
94
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
95
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
96
|
+
if (sub === 'preview') {
|
|
97
|
+
const o = RO.orderOf(text(url.searchParams.get('order')), RO.fold(RO.readLines(mineDir(ctx))).orders);
|
|
98
|
+
if (!o) return send(bad(404, 'no such order'));
|
|
99
|
+
const html = require('./report-design.js').sanitize(require('./report-slides.js').deckHtml(RO.previewDeck(o)));
|
|
100
|
+
res.writeHead && res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
|
|
101
|
+
if (res.end) res.end(html); else { res.status = 200; res.body = html; }
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if (sub !== '') return send(bad(404, 'no such route'));
|
|
105
|
+
const d = draftOf(w, url.searchParams.get('path'));
|
|
106
|
+
if (d.error) return send(d.error);
|
|
107
|
+
return send({ status: 200, body: stateOf(ctx, w, d) });
|
|
108
|
+
}
|
|
109
|
+
if (!POSTS.includes(sub)) return send(bad(404, 'no such route'));
|
|
110
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
111
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'a session cannot change a report: the PM presses on the page'));
|
|
112
|
+
const read = await ctx.readJson(req);
|
|
113
|
+
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
114
|
+
const body = read.body || {};
|
|
115
|
+
const g = guard.requirePagePress(req, body);
|
|
116
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
117
|
+
const w = wsOf(ctx, text(body.ws));
|
|
118
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
119
|
+
const dir = mineDir(ctx);
|
|
120
|
+
|
|
121
|
+
if (sub === 'rename') { const r = RO.rename(dir, text(body.id), text(body.name)); return send(r.ok ? { status: 200, body: { ok: true } } : bad(r.status, r.error)); }
|
|
122
|
+
if (sub === 'remove') { const r = RO.remove(dir, text(body.id)); return send(r.ok ? { status: 200, body: { ok: true } } : bad(r.status, r.error)); }
|
|
123
|
+
|
|
124
|
+
const d = draftOf(w, body.path);
|
|
125
|
+
if (d.error) return send(d.error);
|
|
126
|
+
if (sub === 'save') {
|
|
127
|
+
const report = readJson(d.P.report.abs), brief = readJson(d.P.brief.abs);
|
|
128
|
+
if (!report) return send(bad(409, 'this draft was written before the report engine: its slides have no layouts to save'));
|
|
129
|
+
const outline = [{ part: 'Title', layout: 'overview' }].concat(RO.partsOf(report, brief), [{ part: 'Sources', layout: 'sources' }]);
|
|
130
|
+
const r = RO.save(dir, { kind: 'order', name: text(body.name) || savedName(w, d.id, brief), outline, from: { report: d.id, slot: d.slot } });
|
|
131
|
+
return send(r.ok ? { status: 200, body: { ok: true, id: r.id } } : bad(r.status, r.error));
|
|
132
|
+
}
|
|
133
|
+
if (sub === 'slide') {
|
|
134
|
+
const n = Number(body.n);
|
|
135
|
+
if (!Number.isInteger(n) || n < 0) return send(bad(400, 'n is the slide, from 0'));
|
|
136
|
+
const sp = slidePart(d, n);
|
|
137
|
+
if (sp.error) return send(sp.error);
|
|
138
|
+
const r = RO.save(dir, { kind: 'slide', name: sp.part, outline: [sp], from: { report: d.id, slot: d.slot } });
|
|
139
|
+
return send(r.ok ? { status: 200, body: { ok: true, id: r.id, name: sp.part, layout: sp.layout } } : bad(r.status, r.error));
|
|
140
|
+
}
|
|
141
|
+
if (d.issued) return send(bad(409, `the ${d.slot} report is issued, so it is frozen. The next cycle starts from its order`));
|
|
142
|
+
if (sub === 'undo') { const r = RO.undo(w.root, d.id, d.slot); return send(r.ok ? { status: 200, body: { ok: true, order: r.order } } : bad(r.status, r.error)); }
|
|
143
|
+
|
|
144
|
+
// apply
|
|
145
|
+
const order = RO.orderOf(text(body.order), RO.fold(RO.readLines(dir)).orders);
|
|
146
|
+
if (!order) return send(bad(404, 'no such order'));
|
|
147
|
+
const brief = readJson(d.P.brief.abs);
|
|
148
|
+
if (brief && Array.isArray(brief.agreed_outline) && brief.agreed_outline.length) {
|
|
149
|
+
RO.setNext(w.root, d.id, order, d.slot, { by: g.actor });
|
|
150
|
+
return send({ status: 200, body: { ok: true, next: { id: order.id, name: order.name } } });
|
|
151
|
+
}
|
|
152
|
+
RO.snapshot(w.root, d.id, d.slot, { order });
|
|
153
|
+
const m = RE.make(w.root, d.id, { slot: d.slot, template: RL.templateOf(order.id) ? order.id : order });
|
|
154
|
+
if (!m.ok) { RO.undo(w.root, d.id, d.slot); return send(bad(m.status || 400, m.error)); }
|
|
155
|
+
const rel = d.P.md.rel;
|
|
156
|
+
const r = require('./routes-report-flow.js').ask(ctx, w, d.id, redraftWords(d.id, d.slot, rel, order), rel);
|
|
157
|
+
if (!r.ok) { RO.undo(w.root, d.id, d.slot); return send(bad(r.status || 409, r.error)); }
|
|
158
|
+
return send({ status: 200, body: { ok: true, redraft: { session: r.session, started: !!r.started, passed: !!r.passed }, order: { id: order.id, name: order.name } } });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = { prefixes, handle, stateOf, redraftWords };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.537.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.537.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|