create-pmos 0.482.0 → 0.484.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/package.json +27 -27
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/changelog.json +26 -0
  8. package/workspace/guide/briefing-premium.md +6 -2
  9. package/workspace/guide/home.md +1 -1
  10. package/workspace/home-rows-test.js +3 -1
  11. package/workspace/lib/goal-chat.js +29 -5
  12. package/workspace/lib/report-chat.js +3 -2
  13. package/workspace/lib/report-templates.js +172 -0
  14. package/workspace/lib/route-modules.js +1 -0
  15. package/workspace/lib/routes-report-flow.js +184 -0
  16. package/workspace/lib/routes-reports.js +4 -1
  17. package/workspace/package-lock.json +2 -2
  18. package/workspace/package.json +1 -1
  19. package/workspace/premium-chat-report-tab-test.js +40 -33
  20. package/workspace/premium-html-viewer-test.js +6 -0
  21. package/workspace/public/pm/cozy-vw-rp.css +48 -0
  22. package/workspace/public/pm/home-app.js +6 -2
  23. package/workspace/public/pm/home-chat.js +3 -3
  24. package/workspace/public/pm/home-list.js +10 -3
  25. package/workspace/public/pm/home-today.js +2 -2
  26. package/workspace/public/pm/premium-report-read.js +40 -6
  27. package/workspace/public/pm/premium-report-tab.js +163 -74
  28. package/workspace/public/pm/premium-vw-doc.css +6 -1
  29. package/workspace/public/pm/premium-vw-file.js +7 -2
  30. package/workspace/public/pm/premium-vw-pdf.js +42 -0
  31. package/workspace/public/pm/report-chat.js +5 -3
  32. package/workspace/public/pm/report-flow.js +163 -0
  33. package/workspace/public/vendor/pdf.min.js +28 -0
  34. package/workspace/public/vendor/pdf.worker.min.js +28 -0
  35. package/workspace/ready-dash-ui-test.js +2 -1
  36. package/workspace/server.js +3 -0
  37. package/workspace/test-lists/report-flow.json +11 -0
  38. package/workspace/third-party/README.md +9 -4
  39. package/workspace/third-party/pdfjs-dist-5.4.296.LICENSE +177 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.482.0",
3
+ "version": "0.484.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -32,6 +32,32 @@
32
32
  "audit"
33
33
  ],
34
34
  "pmosChanges": [
35
+ {
36
+ "v": "0.484.0",
37
+ "at": "2026-11-02T02:00:11.221Z",
38
+ "f": 3,
39
+ "prs": [
40
+ {
41
+ "n": 1143,
42
+ "t": "Program chats get the header pill; a phone shows every PDF page (batch 22 items 17, 18)",
43
+ "s": "Program chats get the header pill; a phone shows every PDF page (batch 22 items 17, 18)",
44
+ "k": "fix"
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ "v": "0.483.0",
50
+ "at": "2026-11-02T00:26:37.780Z",
51
+ "f": 3,
52
+ "prs": [
53
+ {
54
+ "n": 1144,
55
+ "t": "Report building flow \"A+ on Home\" (batch 22 item 14)",
56
+ "s": "Report building flow \"A+ on Home\" (batch 22 item 14)",
57
+ "k": "new"
58
+ }
59
+ ]
60
+ },
35
61
  {
36
62
  "v": "0.482.0",
37
63
  "at": "2026-11-01T23:25:19.509Z",
@@ -269,32 +295,6 @@
269
295
  "k": "new"
270
296
  }
271
297
  ]
272
- },
273
- {
274
- "v": "0.464.0",
275
- "at": "2026-10-31T02:53:30.027Z",
276
- "f": 3,
277
- "prs": [
278
- {
279
- "n": 1116,
280
- "t": "No folder per initiative in a document repository, finished worktrees clean up, one plain notice (D102)",
281
- "s": "No folder per initiative in a document repository, finished worktrees clean up, one plain notice",
282
- "k": "new"
283
- }
284
- ]
285
- },
286
- {
287
- "v": "0.463.0",
288
- "at": "2026-10-31T02:36:24.736Z",
289
- "f": 3,
290
- "prs": [
291
- {
292
- "n": 1114,
293
- "t": "Records are saved on the default branch only, and a document folder is put back on it by itself (D70)",
294
- "s": "Records are saved on the default branch only, and a document folder is put back on it by itself",
295
- "k": "fix"
296
- }
297
- ]
298
298
  }
299
299
  ]
300
300
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@aaa93bcb
2
- assembled: 2026-11-01
1
+ kernel-source: pmos@71cb4061
2
+ assembled: 2026-11-02
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-01T23:25:16Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-02T02:00:07Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-01T23:25:16Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-02T02:00:07Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-01T23:25:16Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-02T02:00:07Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  Newest first, ISO dates.
4
4
 
5
- ## 2026-11-01
5
+ ## 2026-11-02
6
6
 
7
7
  - Adopted OKF v0.2 (D73).
@@ -1,4 +1,30 @@
1
1
  [
2
+ {
3
+ "v": "0.484.0",
4
+ "at": "2026-11-02T02:00:11.221Z",
5
+ "f": 3,
6
+ "prs": [
7
+ {
8
+ "n": 1143,
9
+ "t": "Program chats get the header pill; a phone shows every PDF page (batch 22 items 17, 18)",
10
+ "s": "Program chats get the header pill; a phone shows every PDF page (batch 22 items 17, 18)",
11
+ "k": "fix"
12
+ }
13
+ ]
14
+ },
15
+ {
16
+ "v": "0.483.0",
17
+ "at": "2026-11-02T00:26:37.780Z",
18
+ "f": 3,
19
+ "prs": [
20
+ {
21
+ "n": 1144,
22
+ "t": "Report building flow \"A+ on Home\" (batch 22 item 14)",
23
+ "s": "Report building flow \"A+ on Home\" (batch 22 item 14)",
24
+ "k": "new"
25
+ }
26
+ ]
27
+ },
2
28
  {
3
29
  "v": "0.482.0",
4
30
  "at": "2026-11-01T23:25:19.509Z",
@@ -457,7 +457,11 @@ Sending and the option presses need the page's launch nonce, so an agent session
457
457
 
458
458
  Any chat can become a report. There is no button for it: say it in the chat, for example "make this a report for the growth leads" or "make it weekly on Wednesdays". Claude answers in a few lines, and the **Report** tab opens beside the conversation (on a phone, a bar over the message box offers it). The chip under Claude's answer opens the tab again.
459
459
 
460
- - **A new report** shows its name, what it answers, who reads it, its format and its sections. The chip under Claude's answer says **Set it up in the Report tab**. Press ✓ (**Set it up**) at the top of the tab: that one press records the report and writes its first draft. If you did not say a schedule, its **Schedule** is **Off**: it runs once, and you can give it a schedule later.
460
+ - **A new report** asks a few questions first, and Claude's picks are filled in: **Format**, **Readers**, **Goes out** (**Once** or **Repeats**, with how often, the day and the time), **Look** (the standard PMOS look, 16:9 slides) and **Sources**. The chip under Claude's answer says **Answer a few questions, then Draft it**. Change any answer, then press **Draft it**. Nothing goes out. That press records the report and its first template (T1), and the report drafts in its own session, not in your chat. While it drafts, the tab says so. If the session ends with no draft, **Draft it again** starts it again.
461
+ - **The report's current state.** When a report is set up, the chip under Claude's answer says **Open the report**, and the tab opens its latest draft in the reader. Under a draft that is not issued, Claude's review reads it as your readers would and lists what to fix, in the ✦ pattern: **Do it** passes one fix to the report's own session, **Do all** passes them all, and **Not now** hides one. The checks that found nothing are named under it. There is no score.
462
+ - **A change from the chat.** Ask for a change to the draft in the chat, for example "use 30 Jun on both slides". The chip says **Change to the draft** and passes it to the report's own session. Your chat does not draft the report.
463
+ - **Template versions.** The template icon in the reader's header opens the questions with the current answers. A changed answer is marked and said in words, for example "Format: Slides → Document". **Make a different template** saves it as the next version (T2, T3, …), and **Keep the current template** leaves it. **Template history** lists each version with the cycles issued under it, and **Go back** makes an earlier one current. Nothing is deleted. **Sections, look and cycles** opens the structure, the design and the cycles below.
464
+ - **A goal with a report in it.** When a goal names a report, that point counts only when you issue the report. If only report points are open, the goal waits for you to issue it.
461
465
  - **Your own sections.** Name them in the chat, for example "use these sections: Decision question; Current position; Options and recommendation; Open items; Sources". The tab shows them as the slides. ✓ saves them as the report's structure (S1), and the first draft follows them. Your first section is the report's lead, the one before Sources holds the asks to the readers, and Sources is always last. If you describe a change without a list, **Structure and look** shows the change: the first draft uses the seven standard sections, Claude starts the change right after ✓, and **Use this** keeps it. When you press **Use this**, Claude writes the draft again with the new sections.
462
466
  - **A look to follow.** Say how the report should look, or name a file for it to follow, such as your draft deck (a PDF, PowerPoint, Word file or picture). **Structure and look** shows **Look** with the file's name. After ✓, Claude adds the file as the look's sample and makes the look from it.
463
467
  - **While Claude works.** When Claude reshapes the sections, makes the look or writes the draft again, a line with a pulsing dot says so on the report and in the tab, and says how long it takes. The line goes when the work is done, and the new draft opens in its place.
@@ -504,7 +508,7 @@ Press **+** at the left of the message box. The menu has three items: **Add file
504
508
 
505
509
  ### Open a file Claude names
506
510
 
507
- A PDF that Claude names opens in the Viewer, in the browser's own PDF viewer. It takes the whole width and height of the Viewer, with its path under it. Other files show as text.
511
+ A PDF that Claude names opens in the Viewer, in the browser's own PDF viewer. It takes the whole width and height of the Viewer, with its path under it. On a phone, where the browser shows only the first page, the Viewer draws every page itself, one under the other. Other files show as text.
508
512
 
509
513
  ### Give Claude a goal with `/goal`
510
514
 
@@ -25,7 +25,7 @@ Home, the Board, Insights and the Viewer use one type scale: 11, 12, 14, 16, 20
25
25
  - A **program** comes first, above the products. Its header shows the program icon, its name, the next milestone (◆ and the date) and how many of its initiatives are ready for that milestone. Inside it, the program's own tasks come first, then its initiatives under a small heading for each product. Each initiative shows once. Press the program's name to open the program in the Viewer. The chat then talks about the program. Press the chevron to close or open the group.
26
26
  - The **product picker** is the chip on the top line. It shows the tiles of the ticked products, overlapped, with **+N** after 3, or **All** when every product is ticked. It shows even with one product. A git worktree of a repository is not a product: it does not appear in the list. Its repository stands for it. Hold the pointer on it to read the names. Press it to open the list: **All products**, then each product with its tile, its name and one line (for example "3 initiatives · 1 of 2 goals"), then **Add a product**. Press a product to tick or untick it; the list stays open, and the last ticked product stays ticked. The pick applies when the list closes (Escape, a press outside, or the chip again). On a phone the list is a sheet at the bottom. The pick is one saved setting (`ws.briefing.include`) that Home, the Board and Insights share, so a product that you untick on one page goes from all three. With **All** ticked, a product that you add later is ticked too. The **Product** row in Settings opens the same list.
27
27
  - A program with no open initiative yet still shows, with "No initiatives yet" or "No open initiatives". A program shows only when it holds work of a ticked product. Home reads again when you come back to its tab, so a program made on the Board shows at once.
28
- - Then the list is grouped by **product**. A product header shows a tile with the product's short name, the product name, one dot for each goal (green on track, amber off track) and a chevron. When the product has chats of its own (the product's chat and its new sessions), the header has the same pill as an initiative row: press it to see them, and **+** starts a new session in the product. These chats are not under **Not in an initiative**. You set the short name in Settings. Press the product's name to open the product in the Viewer, with its goals and this week's update and metrics review. The chat then talks about the product. This is the same for every product in the list: Home stays on the workspace you opened it on. For another product, the weekly update and the metrics review open that product's own Home in a new tab. An initiative of another product opens from that product's own board, and its chat works in that product's workspace. This is also true for a new initiative that an agent made with `pmos initiative new` and that is not on the board's Now list yet: it opens with its title, stage and tasks.
28
+ - Then the list is grouped by **product**. A product header shows a tile with the product's short name, the product name, one dot for each goal (green on track, amber off track) and a chevron. When the product has chats of its own (the product's chat and its new sessions), the header has the same pill as an initiative row: press it to see them, and **+** starts a new session in the product. These chats are not under **Not in an initiative**. A program header has the same pill for the program's own chats, and **+** starts a new session in the program. The chat then shows the program or the product as its scope, not **Loose**. You set the short name in Settings. Press the product's name to open the product in the Viewer, with its goals and this week's update and metrics review. The chat then talks about the product. This is the same for every product in the list: Home stays on the workspace you opened it on. For another product, the weekly update and the metrics review open that product's own Home in a new tab. An initiative of another product opens from that product's own board, and its chat works in that product's workspace. This is also true for a new initiative that an agent made with `pmos initiative new` and that is not on the board's Now list yet: it opens with its title, stage and tasks.
29
29
  - Each row is one line. A dot is a session: blue when it waits on you, a ring while it runs. A check box is a task: amber when it is late. The stage track on the right shows where the initiative is. A session that runs under an initiative shows indented under it. An initiative shows its 3 most urgent tasks, and **N more** shows the rest.
30
30
  - **Not in an initiative** is one line at the end, with a blue dot, an amber square and a count. Press it to open the items that have no initiative.
31
31
  - **Kept** and **Done** are in the filter icon's menu, on a desktop only.
@@ -239,9 +239,11 @@ const recentOf = (m) => ({ ...m, recent: [...m.toread, ...m.answered] });
239
239
  await A.close();
240
240
 
241
241
  /* E: a heavy day, 30+ days, the edges */
242
+ // The six asks stay inside today: an hour apart, or closer just after midnight (CI ran 00:10 UTC and "newest today" became yesterday's).
243
+ const TODAY_STEP = Math.max(1, Math.min(60, Math.floor((Date.now() - new Date().setHours(0, 0, 0, 0)) / 60000 / 7)));
242
244
  const many = MENTIONS(INI);
243
245
  many.waiting = [conv('aaaaaaaaaac0', { source: 'mail', who: 'Budi Santoso', people: ['Budi Santoso'], where: 'Q4 budget', waiting: true, count: 1, since: ago(34 * D), last: ago(34 * D), check: true, gist: 'Budget sign-off for Q4.', draft: 'Signed.' })]
244
- .concat(Array.from({ length: 6 }, (_, i) => conv('aaaaaaaaaac' + (i + 1), { who: 'Person' + i + ' X', people: ['Person' + i + ' X'], where: '#ascent', waiting: true, count: 1, since: ago((6 - i) * 60), last: ago((6 - i) * 60), gist: 'Ask ' + i, draft: i < 3 ? 'Yes.' : undefined })));
246
+ .concat(Array.from({ length: 6 }, (_, i) => conv('aaaaaaaaaac' + (i + 1), { who: 'Person' + i + ' X', people: ['Person' + i + ' X'], where: '#ascent', waiting: true, count: 1, since: ago((6 - i) * TODAY_STEP), last: ago((6 - i) * TODAY_STEP), gist: 'Ask ' + i, draft: i < 3 ? 'Yes.' : undefined })));
245
247
  many.count = 7;
246
248
  many.gaps = [{ kind: 'source', source: 'mail', state: 'never' }, { kind: 'stale', upto: ago(26 * 60) }];
247
249
  const E = await open({ w: 390, h: 844, mentions: recentOf(many) });
@@ -113,11 +113,33 @@ function goalOf(runtimeDir, key) {
113
113
  else if (e.event === 'edited') g = { ...g, draft: e.draft, open: ((e.draft && e.draft.done) || []).filter((x) => !(g.met || []).includes(x)) }; // ... and while it works
114
114
  else if (e.event === 'skip') g = { ...g, skipped: [...new Set((g.skipped || []).concat(e.point))], skipAt: { ...(g.skipAt || {}), [e.point]: e.at } };
115
115
  else if (e.event === 'unskip') g = { ...g, skipped: (g.skipped || []).filter((x) => x !== e.point) };
116
+ else if (e.event === 'report-issued') g = { ...g, reportIssued: (g.reportIssued || []).concat(e.report || 'report') }; // a report this goal asked for was issued
116
117
  else if (e.event === 'resumed') g = { ...g, state: 'started', reason: undefined, at: e.at };
117
- else if (['done', 'stopped', 'waiting'].includes(e.event)) g = { ...g, state: e.event, ...(e.reason ? { reason: e.reason } : {}), met: e.met || g.met, open: e.open || g.open, at: e.at };
118
+ else if (['done', 'stopped', 'waiting'].includes(e.event)) g = { ...g, state: e.event, reason: e.reason || undefined, met: e.met || g.met, open: e.open || g.open, at: e.at };
118
119
  }
120
+ if (g && g.draft) g.met = reportMet(g, g.met || []);
119
121
  return g;
120
122
  }
123
+ /* A done point about a report counts at Issued (batch 22 item 14): Claude's "the report is drafted" does not meet it; the PM's Issue it does.
124
+ * routes-reports.js appends a report-issued line for the goal of the conversation the report came from. */
125
+ const REPORT_POINT_RE = /\breports?\b/i;
126
+ const reportPoints = (g) => ((g && g.draft && g.draft.done) || []).filter((x) => REPORT_POINT_RE.test(x));
127
+ /** The met points with the report points held back until a report is issued, and counted once one is. */
128
+ function reportMet(g, met) {
129
+ const rp = reportPoints(g);
130
+ if (!rp.length) return met;
131
+ const rest = (met || []).filter((x) => !rp.includes(x));
132
+ return g.reportIssued && g.reportIssued.length ? rest.concat(rp.filter((x) => !(g.skipped || []).includes(x))) : rest;
133
+ }
134
+ /** A report was issued: the started goal of the conversation it came from counts its report points as met. → true when a goal took it. */
135
+ function reportIssued({ runtimeDir, key, report, now = new Date() }) {
136
+ const g = key && goalOf(runtimeDir, key);
137
+ if (!g || !g.draft || !['started', 'waiting', 'stopped', 'done'].includes(g.state) || !reportPoints(g).length) return false;
138
+ append(runtimeDir, { event: 'report-issued', id: g.id, key, report: String(report || 'report').slice(0, 80), at: now.toISOString() });
139
+ const after = goalOf(runtimeDir, key), all = requiredOf(after), met = (after.met || []).filter((x) => all.includes(x));
140
+ if (after.state === 'waiting' && all.length && met.length === all.length) append(runtimeDir, { event: 'done', id: g.id, key, met, open: [], at: now.toISOString() });
141
+ return true;
142
+ }
121
143
  /** Every key's goal state in one read: { <key>: { state, rounds, limit } } (premium-session-list L1: the session list's Goals group). */
122
144
  function statesAt(runtimeDir) {
123
145
  let t; try { t = fs.readFileSync(path.join(runtimeDir, RUNS), 'utf8'); } catch { return {}; }
@@ -136,7 +158,7 @@ function statesAt(runtimeDir) {
136
158
  const NO_PROGRESS = 3;
137
159
  /** The done points that still count: the draft's, less the ones the PM skipped. */
138
160
  const requiredOf = (g) => ((g.draft && g.draft.done) || []).filter((x) => !(g.skipped || []).includes(x));
139
- const REASON = { deadline: 'The deadline has passed.', limit: 'It used all its rounds.', 'no-progress': 'Three rounds in a row met no new done point.', pm: 'You stopped it.', replaced: 'You replaced it with a new goal.' };
161
+ const REASON = { issue: 'The report waits for you to issue it.', deadline: 'The deadline has passed.', limit: 'It used all its rounds.', 'no-progress': 'Three rounds in a row met no new done point.', pm: 'You stopped it.', replaced: 'You replaced it with a new goal.' };
140
162
  /** The last fenced pmos-goal block in a message, parsed, or null. */
141
163
  function blockOf(text) {
142
164
  const re = /```pmos-goal[^\n]*\n([\s\S]*?)```/g;
@@ -170,10 +192,12 @@ function onStop({ runtimeDir, key, message, now = new Date() }) {
170
192
  const d = g.draft, b = blockOf(message), all = requiredOf(g);
171
193
  const p = b && b.step === 'progress' ? b : null;
172
194
  // the plan decides what is met and open: Claude's own open list and its "done" alone do not count
173
- const met = p && Array.isArray(p.met) ? matchPoints(strs(p.met), all) : (g.met || []).filter((x) => all.includes(x));
195
+ const met = reportMet(g, p && Array.isArray(p.met) ? matchPoints(strs(p.met), all) : (g.met || []).filter((x) => all.includes(x))).filter((x) => all.includes(x));
174
196
  const open = all.filter((x) => !met.includes(x));
175
197
  const base = { id: g.id, key, met, open, at: now.toISOString() };
176
198
  if (all.length && !open.length) { append(runtimeDir, { event: 'done', ...base }); return {}; }
199
+ // only report points are open: they count when the PM presses Issue it, which Claude cannot do, so the goal waits on the PM
200
+ if (open.length && open.every((x) => REPORT_POINT_RE.test(x))) { append(runtimeDir, { event: 'waiting', reason: 'issue', ...base }); return {}; }
177
201
  const prev = roundsOf(runtimeDir, g.id), last = prev[prev.length - 1];
178
202
  const needs = !!(p && p.state === 'needs-you');
179
203
  // the goal works on its own (feedback 2026-10-25): the first needs-you is sent back; a second one in a row waits on the PM
@@ -223,7 +247,7 @@ function goalRowsAt(runtimeDir, now = Date.now()) {
223
247
  const at = Date.parse(g.at || '');
224
248
  if (Number.isFinite(at) && now - at > ROW_DAYS * 86400000) continue;
225
249
  const all = requiredOf(g), met = (g.met || []).filter((x) => all.includes(x)).length;
226
- const why = g.state === 'stopped' ? (REASON[g.reason] || 'It stopped.') : g.state === 'waiting' ? 'Claude asked you something in the conversation.' : 'Claude reports every done point met. It checked its own work.';
250
+ const why = g.state === 'stopped' ? (REASON[g.reason] || 'It stopped.') : g.state === 'waiting' ? (g.reason === 'issue' ? REASON.issue : 'Claude asked you something in the conversation.') : 'Claude reports every done point met. It checked its own work.';
227
251
  out.push({
228
252
  kind: 'goal', key: 'goal:' + key, chatKey: key, goalState: g.state, title: ROW_TITLE[g.state], subject: clip(g.draft.goal, 90),
229
253
  prepared: met + ' of ' + all.length + ' done points met, as Claude reports it. ' + why,
@@ -339,4 +363,4 @@ function decide({ runtimeDir, key, id, act, draft, point, session, sessions, now
339
363
  return { status: 200, body: { ok: true, id, state: act === 'start' ? 'started' : 'cancelled' } };
340
364
  }
341
365
 
342
- module.exports = { parseCommand, grillPrompt, methodMessage, planMessage, skipMessage, unskipMessage, METHODS, startMessage, cancelMessage, cleanDraft, goalOf, statesAt, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, askToolReply, goalToolReply, matchPoints, ASK_TOOL, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
366
+ module.exports = { reportIssued, reportMet, REPORT_POINT_RE, parseCommand, grillPrompt, methodMessage, planMessage, skipMessage, unskipMessage, METHODS, startMessage, cancelMessage, cleanDraft, goalOf, statesAt, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, askToolReply, goalToolReply, matchPoints, ASK_TOOL, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
@@ -24,9 +24,10 @@ const RULE = [
24
24
  ' When the PM names the sections (or you propose a list and the PM agrees), add "sections": ["Section title", …] next to "proposal": the titles in order, up to 10, in the PM\'s words. The tab shows them, and setting it up saves them and drafts the first report with them.',
25
25
  ' When the PM wants other contents but names no list, add "structure": "the change, in plain words" instead. Once the PM sets it up, the tab starts that change and the PM keeps it with one press.',
26
26
  ' When the PM says how it should look, or asks it to follow a file (a draft deck, a sample), add "design": "the look, in the PM\'s words" and, for a file, "sample": "<its path in the workspace>" (a .pdf, .pptx, .docx, .png or .jpg). Once the PM sets it up, the tab adds the sample and starts that look.',
27
- ' The PM sets a new report up with ONE press: the check button (Set it up) at the top of the Report tab. Name it like that. Never say Create, Save or any other button.',
28
- ' In your words, say what the tab will show: the sections it will have, then the one press. Never describe contents the block does not carry.',
27
+ ' The report view asks a few questions first, with your picks filled in: the format, who reads it, when it goes out, the look and the sources. The PM changes any of them, then presses Draft it. Say it like that: "A few questions before I draft. My picks are filled in on the right. Change any, then press Draft it." Never say Create, Save or any other button.',
28
+ ' The report then drafts in its own session, not in this chat. Never describe contents the block does not carry.',
29
29
  '- A report that is set up already: {"kind":"report","id":"<its id>"} and, only when the PM asked for it, "schedule": {…} or "off", "sections": ["the new section titles, in order"] or "structure": "the change to its sections, in the PM\'s words", "design": "the change to its look, in the PM\'s words".',
30
+ ' A change to the draft of a set-up report (a date, a slide, a wording): {"kind":"report","id":"<its id>","change":"the change, in the PM\'s words"}. The PM\'s press on the chip passes it to the report\'s own session, which changes the draft; nothing is issued. Do not change the draft yourself.',
30
31
  ' The set-up reports are the setup lines of report-setups.jsonl (planning/ or pmos/state/); a later change line wins, a remove line deletes one.',
31
32
  '- A chart of one measure: {"kind":"chart","proposal":{"measure":"<KR metric id>","title":"short title","question":"what it answers","form":"line|bars|number|meter","range":null,"target":null,"better":"higher|lower","note":""}}',
32
33
  ' measure is the id of a KR metric record (planning/records/kr-metrics.jsonl). range is how many of the latest readings to draw, or null for all. A meter needs a target.',
@@ -0,0 +1,172 @@
1
+ 'use strict';
2
+ /* report-templates.js — a report's template versions and its review (batch 22 item 14, the report building flow "A+ on Home", canvas RfH1–RfH7).
3
+ *
4
+ * ledgerOf(root, id) <state>/reports/<id>/template.jsonl
5
+ * readLines(root, id) · fold(lines) → { current, versions: [{ n, settings, at, why, current }], chat, log }
6
+ * settingsOf(setup) → { output, audience, schedule } the three settings a template is
7
+ * sameSettings(a, b) · diffWords(a, b) "Format: Slides → Document"
8
+ * ensureFirst(root, id, setup, { chat, now }) → T1 from the setup, once. `chat` is the conversation key the report was proposed in
9
+ * addVersion(root, id, settings, { why, now }) → { ok, n } the PM's ✓ on a changed template: T<n+1> becomes the current one
10
+ * restore(root, id, n, { now }) → { ok, n } Go back to T<n>: that version is the current one again. Nothing is deleted
11
+ * cyclesOf(folded, issued) → Map n → issued cycles while that version was the current one
12
+ * chatOf(root, id) the conversation a report came from (its goal's report points count at Issued)
13
+ * review(markdown, { slot, now, listed }) → { fix: [{ id, title, why }], passed: [label] } Claude's review, from the checks PMOS runs
14
+ *
15
+ * THE LINES. { v: 1, ev, …, at }:
16
+ * version { n, settings, why, chat? } T<n>; the newest version line is the current template until a restore line
17
+ * restore { n } Go back to T<n>
18
+ * A template is its settings: the format (output), who reads it (audience) and when it goes out (schedule). A change to any of them is a new
19
+ * version (the agreed note: "Changing any setting makes a different template"); the drafts and issued cycles stay with the version they were made
20
+ * under. The setup line in report-setups.jsonl keeps the live values: the route applies a version there with report-setups change and reschedule.
21
+ *
22
+ * THE REVIEW is deterministic: the three Issue checks (lib/viewer-report.js) and the three document checks (lib/report-checks.js) on the draft's own
23
+ * text. A failed check becomes one ✦ fix; a passed one is named in "N other checks found nothing". There is no score (not proven).
24
+ *
25
+ * Nothing here starts a session or sends anything. lib/routes-report-flow.js is the one caller that writes.
26
+ */
27
+ const fs = require('fs');
28
+ const path = require('path');
29
+ const VR = require('./viewer-report.js');
30
+ const RC = require('./report-checks.js');
31
+
32
+ const ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
33
+ const CHAT_RE = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,159}$/;
34
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
35
+ const refuse = (status, error) => ({ ok: false, status, error });
36
+
37
+ function stateRel(root) { try { return require('./report-draft.js').stateRel(root); } catch { return 'planning'; } }
38
+ function ledgerOf(root, id) { return path.join(path.resolve(String(root)), stateRel(root), 'reports', id, 'template.jsonl'); }
39
+
40
+ function readLines(root, id) {
41
+ if (!ID_RE.test(String(id || ''))) return [];
42
+ let t; try { t = fs.readFileSync(ledgerOf(root, id), 'utf8'); } catch { return []; }
43
+ return t.split('\n').filter((l) => l.trim()).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(isObj);
44
+ }
45
+ function append(root, id, line, now) {
46
+ const f = ledgerOf(root, id);
47
+ fs.mkdirSync(path.dirname(f), { recursive: true });
48
+ const rec = { v: 1, ...line, at: new Date(now == null ? Date.now() : now).toISOString() };
49
+ fs.appendFileSync(f, JSON.stringify(rec) + '\n');
50
+ return rec;
51
+ }
52
+
53
+ /** The three settings of a template, as report-setups keeps them. */
54
+ function settingsOf(s) {
55
+ const x = isObj(s) ? s : {};
56
+ const sc = isObj(x.schedule) ? x.schedule : null;
57
+ const paused = x.status === 'paused';
58
+ return { output: String(x.output || ''), audience: String(x.audience || ''), schedule: !sc || paused || sc.cadence === 'off' ? 'off' : { cadence: sc.cadence, ...(sc.day ? { day: sc.day } : {}), ...(sc.dayOfMonth ? { dayOfMonth: sc.dayOfMonth } : {}), time: sc.time || '09:00' } };
59
+ }
60
+ function cleanSettings(s) {
61
+ if (!isObj(s)) return null;
62
+ const out = {};
63
+ if (typeof s.output === 'string' && s.output.trim()) out.output = s.output.trim().slice(0, 40);
64
+ if (typeof s.audience === 'string' && s.audience.trim()) out.audience = s.audience.replace(/\s+/g, ' ').trim().slice(0, 120);
65
+ if (s.schedule === 'off' || (isObj(s.schedule) && s.schedule.cadence === 'off')) out.schedule = 'off';
66
+ else if (isObj(s.schedule) && typeof s.schedule.cadence === 'string') out.schedule = { cadence: s.schedule.cadence, ...(s.schedule.day ? { day: String(s.schedule.day) } : {}), ...(s.schedule.dayOfMonth ? { dayOfMonth: +s.schedule.dayOfMonth } : {}), time: /^\d{1,2}:\d{2}$/.test(String(s.schedule.time || '')) ? String(s.schedule.time) : '09:00' };
67
+ return Object.keys(out).length ? out : null;
68
+ }
69
+ const key = (sc) => JSON.stringify(sc === 'off' || !sc ? 'off' : { c: sc.cadence, d: sc.day || null, m: sc.dayOfMonth || null, t: sc.time || '09:00' });
70
+ function sameSettings(a, b) { return !!a && !!b && a.output === b.output && a.audience === b.audience && key(a.schedule) === key(b.schedule); }
71
+
72
+ const FORMAT = { 'google-slides': 'Slides', 'google-doc': 'Document', pdf: 'PDF', 'google-sheets': 'Sheets', confluence: 'Confluence page' };
73
+ const DAYS = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
74
+ function goesWords(sc) {
75
+ if (!sc || sc === 'off') return 'once';
76
+ const t = sc.time || '09:00';
77
+ if (sc.cadence === 'daily') return 'every day ' + t;
78
+ if (sc.cadence === 'monthly') return 'every month on day ' + (sc.dayOfMonth || 1) + ' ' + t;
79
+ return (sc.cadence === 'bi-weekly' ? 'every two weeks, ' : 'every week, ') + (DAYS[sc.day] || 'Monday') + ' ' + t;
80
+ }
81
+ /** What changed between two templates, in words: ["Format: Slides → Document", …]. */
82
+ function diffWords(a, b) {
83
+ const out = [];
84
+ if (!a || !b) return out;
85
+ if (a.output !== b.output) out.push('Format: ' + (FORMAT[a.output] || a.output || 'none') + ' → ' + (FORMAT[b.output] || b.output || 'none'));
86
+ if (a.audience !== b.audience) out.push('Readers: ' + (a.audience || 'none') + ' → ' + (b.audience || 'none'));
87
+ if (key(a.schedule) !== key(b.schedule)) out.push('Goes out: ' + goesWords(a.schedule) + ' → ' + goesWords(b.schedule));
88
+ return out;
89
+ }
90
+ /** One line naming a template's settings: "Format: Slides · readers: The team · goes out once". */
91
+ function settingsWords(s) {
92
+ if (!s) return '';
93
+ return 'Format: ' + (FORMAT[s.output] || s.output || 'none') + ' · readers: ' + (s.audience || 'none') + ' · goes out ' + goesWords(s.schedule);
94
+ }
95
+
96
+ function fold(lines) {
97
+ const versions = new Map(); let current = null, chat = null; const log = [];
98
+ for (const l of Array.isArray(lines) ? lines : []) {
99
+ if (l.ev === 'version' && Number.isInteger(l.n) && l.n >= 1 && isObj(l.settings)) {
100
+ versions.set(l.n, { n: l.n, settings: l.settings, at: l.at || null, why: typeof l.why === 'string' ? l.why : '' });
101
+ current = l.n; log.push({ n: l.n, at: l.at || null });
102
+ if (typeof l.chat === 'string' && CHAT_RE.test(l.chat) && !chat) chat = l.chat;
103
+ } else if (l.ev === 'restore' && versions.has(l.n)) { current = l.n; log.push({ n: l.n, at: l.at || null, restore: true }); }
104
+ }
105
+ const list = [...versions.values()].sort((a, b) => b.n - a.n).map((v) => ({ ...v, current: v.n === current }));
106
+ return { current, versions: list, chat, log };
107
+ }
108
+
109
+ /** T1, from the setup as it is now. Once: a report with a version already keeps it. `chat` names the conversation it came from. */
110
+ function ensureFirst(root, id, setup, { chat, now } = {}) {
111
+ if (!ID_RE.test(String(id || ''))) return refuse(400, 'id must be a report id');
112
+ const f = fold(readLines(root, id));
113
+ if (f.current != null) return { ok: true, n: f.current, existing: true };
114
+ const line = { ev: 'version', n: 1, settings: settingsOf(setup), why: 'First shape, from your chat.' };
115
+ if (typeof chat === 'string' && CHAT_RE.test(chat)) line.chat = chat;
116
+ append(root, id, line, now);
117
+ return { ok: true, n: 1 };
118
+ }
119
+ /** The PM's ✓ on a changed template: T<n+1> with these settings is the current one. Unchanged settings write nothing. */
120
+ function addVersion(root, id, settings, { why, now } = {}) {
121
+ if (!ID_RE.test(String(id || ''))) return refuse(400, 'id must be a report id');
122
+ const f = fold(readLines(root, id));
123
+ const cur = f.versions.find((v) => v.current);
124
+ const next = { ...(cur ? cur.settings : {}), ...(cleanSettings(settings) || {}) };
125
+ if (cur && sameSettings(cur.settings, next)) return { ok: true, n: cur.n, unchanged: true };
126
+ const n = f.versions.reduce((m, v) => Math.max(m, v.n), 0) + 1;
127
+ append(root, id, { ev: 'version', n, settings: next, why: typeof why === 'string' && why.trim() ? why.trim().slice(0, 200) : diffWords(cur && cur.settings, next).join('; ') }, now);
128
+ return { ok: true, n, settings: next };
129
+ }
130
+ /** Go back to T<n>: that version is the current one again. Nothing is deleted. */
131
+ function restore(root, id, n, { now } = {}) {
132
+ const f = fold(readLines(root, id));
133
+ const v = f.versions.find((x) => x.n === +n);
134
+ if (!v) return refuse(404, 'no such template version');
135
+ if (v.current) return { ok: true, n: v.n, settings: v.settings, unchanged: true };
136
+ append(root, id, { ev: 'restore', n: v.n }, now);
137
+ return { ok: true, n: v.n, settings: v.settings };
138
+ }
139
+ /** How many cycles were issued while each version was the current one. issued: [{ at }] of this report. */
140
+ function cyclesOf(folded, issued) {
141
+ const out = new Map(); const log = (folded && folded.log) || [];
142
+ for (const i of Array.isArray(issued) ? issued : []) {
143
+ const t = Date.parse(i.at || ''); if (!Number.isFinite(t)) continue;
144
+ let n = null; for (const e of log) { if (Date.parse(e.at || '') <= t) n = e.n; }
145
+ if (n == null && log.length) n = log[0].n;
146
+ if (n != null) out.set(n, (out.get(n) || 0) + 1);
147
+ }
148
+ return out;
149
+ }
150
+ const chatOf = (root, id) => fold(readLines(root, id)).chat;
151
+
152
+ /* ── the review: the checks PMOS runs on the draft's own text, as ✦ fixes ── */
153
+ const FIX = {
154
+ sources: 'Reach the missing sources, or say why they are missing',
155
+ sections: 'Fill the empty sections, or take them out',
156
+ figures: 'Refresh the old figure',
157
+ 'numbers-sourced': 'Give each figure its source',
158
+ 'dates-in-full': 'Write each date in full',
159
+ 'decisions-risk': 'Add the Decisions and Risk watch sections',
160
+ };
161
+ const LABEL = { sources: 'sources', sections: 'sections', figures: 'figures', 'numbers-sourced': 'numbers', 'dates-in-full': 'dates', 'decisions-risk': 'decisions' };
162
+ function review(markdown, { slot = '', now = Date.now(), listed = [] } = {}) {
163
+ const fix = [], passed = [];
164
+ let a = [], b = [];
165
+ try { a = VR.issueChecks(markdown, { slot, now }); } catch { a = []; }
166
+ try { b = RC.reportChecks(markdown, { listed }); } catch { b = []; }
167
+ for (const c of a) (c.ok ? passed : fix).push(c.ok ? LABEL[c.id] || c.id : { id: c.id, title: FIX[c.id] || c.id, why: c.text });
168
+ for (const c of b) (c.pass ? passed : fix).push(c.pass ? LABEL[c.id] || c.id : { id: c.id, title: FIX[c.id] || c.id, why: c.reason });
169
+ return { fix, passed };
170
+ }
171
+
172
+ module.exports = { ID_RE, CHAT_RE, FORMAT, ledgerOf, readLines, fold, settingsOf, cleanSettings, sameSettings, diffWords, settingsWords, goesWords, ensureFirst, addVersion, restore, cyclesOf, chatOf, review };
@@ -38,6 +38,7 @@ const MODULES = Object.freeze([
38
38
  'routes-capture', // Run 3 (3C): ⌘K capture
39
39
  'routes-board', // Run 4 (4D): the cross-initiative Board, Release
40
40
  'routes-reports', // Run 5 (5C): drafts, Issue, notes
41
+ 'routes-report-flow', // batch 22 item 14: the report building flow (template versions, the report's own session, review)
41
42
  'routes-notes', // meeting-notes Run 1: the Notes view (typed notes, dictation, transcripts, summaries)
42
43
  'routes-my-work', // initiative my-work: the ranked list of work assigned to the PM, the brief, Read again
43
44
  'routes-intake', // planning-flows run 4: one-line intake draft (drafts only)