create-pmos 0.780.0 → 0.782.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 (66) hide show
  1. package/package.json +47 -73
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/design-system/ui/README.md +2 -2
  4. package/payload/design-system/ui/components/MainItem/README.md +4 -2
  5. package/payload/design-system/ui/components/MainItem/preview.html +2 -2
  6. package/payload/design-system/ui/components/MainSide/README.md +4 -2
  7. package/payload/design-system/ui/components/MainSide/preview.html +2 -2
  8. package/payload/design-system/ui/components/Popup/README.md +15 -0
  9. package/payload/design-system/ui/components/Popup/preview.html +8 -0
  10. package/payload/design-system/ui/components/Reading/README.md +19 -0
  11. package/payload/design-system/ui/components/Reading/preview.html +8 -0
  12. package/payload/design-system/ui/components/SingleColumn/README.md +4 -2
  13. package/payload/design-system/ui/components/SingleColumn/preview.html +2 -2
  14. package/payload/design-system/ui/components/bundle.css +29 -0
  15. package/payload/design-system/ui/pages.md +6 -6
  16. package/payload/design-system/ui/tokens.css +1 -1
  17. package/payload/design-system/ui/tokens.json +30 -0
  18. package/payload/planning/evals/eval-calibration.md +1 -1
  19. package/payload/planning/okrs/health-budgets.md +1 -1
  20. package/payload/state/discoveries.md +1 -1
  21. package/workspace/changelog.json +46 -0
  22. package/workspace/design-system/ui/README.md +2 -2
  23. package/workspace/design-system/ui/components/MainItem/README.md +4 -2
  24. package/workspace/design-system/ui/components/MainItem/preview.html +2 -2
  25. package/workspace/design-system/ui/components/MainSide/README.md +4 -2
  26. package/workspace/design-system/ui/components/MainSide/preview.html +2 -2
  27. package/workspace/design-system/ui/components/Popup/README.md +15 -0
  28. package/workspace/design-system/ui/components/Popup/preview.html +8 -0
  29. package/workspace/design-system/ui/components/Reading/README.md +19 -0
  30. package/workspace/design-system/ui/components/Reading/preview.html +8 -0
  31. package/workspace/design-system/ui/components/SingleColumn/README.md +4 -2
  32. package/workspace/design-system/ui/components/SingleColumn/preview.html +2 -2
  33. package/workspace/design-system/ui/components/bundle.css +29 -0
  34. package/workspace/design-system/ui/pages.md +6 -6
  35. package/workspace/design-system/ui/tokens.css +1 -1
  36. package/workspace/design-system/ui/tokens.json +30 -0
  37. package/workspace/guide/agent-capabilities.md +2 -1
  38. package/workspace/guide/claude-proposes.md +11 -1
  39. package/workspace/guide/cli.md +9 -1
  40. package/workspace/guide/layout.md +14 -0
  41. package/workspace/lib/card-catalog.js +67 -0
  42. package/workspace/lib/card-catalog.json +2032 -0
  43. package/workspace/lib/pmos-verbs.js +3 -0
  44. package/workspace/lib/routes-card-catalog.js +19 -0
  45. package/workspace/lib/routes-slash.js +7 -1
  46. package/workspace/lib/routes-star-drafts.js +36 -0
  47. package/workspace/lib/sprint-cli.js +79 -0
  48. package/workspace/lib/sprint-retro.js +176 -0
  49. package/workspace/lib/star-draft.js +99 -0
  50. package/workspace/lib/task-cli.js +26 -12
  51. package/workspace/package-lock.json +2 -2
  52. package/workspace/package.json +1 -1
  53. package/workspace/public/pm/action-run.js +120 -0
  54. package/workspace/public/pm/bd-pop-ds.js +2 -2
  55. package/workspace/public/pm/card-run.js +25 -0
  56. package/workspace/public/pm/cozy-pop-work.js +91 -10
  57. package/workspace/public/pm/goals-open.js +14 -2
  58. package/workspace/public/pm/komorebi.css +29 -1
  59. package/workspace/public/pm/premium-vw-doc.css +31 -0
  60. package/workspace/public/pm/premium-vw-doc.js +49 -3
  61. package/workspace/public/pm/reading-model.js +76 -0
  62. package/workspace/public/pm/star-draft.js +63 -0
  63. package/workspace/public/pm/state-blocks.js +18 -1
  64. package/workspace/test-lists/reading-layouts.json +9 -0
  65. package/workspace/test-lists/sprint-retro-one-change.json +9 -0
  66. package/workspace/test-lists/star-buttons-act-directly.json +13 -0
@@ -0,0 +1,120 @@
1
+ /* pm/action-run.js — one catalog button runs its pmos command through the page's own route, with Undo (initiative
2
+ * star-buttons-act-directly, done test A2–A4; the card catalog is lib/card-catalog.json, GET /api/card-catalog).
3
+ *
4
+ * runAction({ kind, action, id, args, was, ws, board, yes }, { pmPost, catalog? })
5
+ * → { ok: true, said, undo: async () => result, field, value } it ran: one POST, no chat, no session
6
+ * | { ok: false, needsYes: true, said } a "waits" button: it runs only with yes: true
7
+ * | { ok: false, ask: words } an "agent" button: PMOS does it; the words go to Ask PMOS
8
+ * | { ok: false, unknown: true, error } no route for this button: nothing was written
9
+ * | { ok: false, error } the route refused; nothing changed
10
+ * routeOf(run) → the ROUTES entry for "pmos <verb> <sub> …", or null PURE
11
+ * argsOf(run, args) → { flags, pos } the command's placeholders filled from args, by flag name, then by placeholder name PURE
12
+ *
13
+ * WHY THE PAGE ROUTES. A write is attributed from the call path (lib/actor.js): the page's routes name the PM, so a button runs the same
14
+ * route the command calls (lib/task-cli.js), never the CLI. After every run and every Undo it sends window event `pmos:action` with
15
+ * { kind, id, field, value, undo } so a card or a list can redraw (pm/live-edit.js shows the edit at once).
16
+ *
17
+ * A COMMENT has no Undo route. It is sent when its Undo window closes (UNDO_MS): Undo inside the window means it is never written. */
18
+ import { parseRun } from './card-run.js';
19
+
20
+ export const UNDO_MS = 8000;
21
+ const STATE = { 'to do': 'To do', todo: 'To do', 'in progress': 'In progress', doing: 'In progress', blocked: 'Blocked', done: 'Done', dropped: 'Dropped' };
22
+ const stateOf = (s) => STATE[String(s || '').trim().toLowerCase()] || String(s || '');
23
+ const clean = (s) => String(s == null ? '' : s).replace(/^"|"$/g, '');
24
+
25
+ /** The task family: what each "pmos task <sub>" sends, and how Undo puts it back. f: the filled flags, p: the positionals, a: the args. */
26
+ const ROUTES = {
27
+ 'task set': {
28
+ post: (f, p, a) => {
29
+ const b = { task: p[0] };
30
+ for (const k of ['due', 'start', 'owner', 'notes', 'description']) if (f[k] !== undefined) b[k] = f[k] === true ? '' : String(f[k]);
31
+ if (f.milestone !== undefined) b.milestone = f.milestone === true ? true : f.milestone !== 'false';
32
+ if (f.pin !== undefined) b.pinned = f.pin === true ? true : f.pin !== 'false';
33
+ return ['/api/boards/tasks/edit', b];
34
+ },
35
+ undo: (r, b) => (r && r.from ? ['/api/boards/tasks/edit', { task: b.task, ...r.from }] : null),
36
+ },
37
+ 'task state': {
38
+ post: (f, p) => ['/api/boards/tasks/state', { task: p[0], state: stateOf(f.to), ...(f.why && f.why !== true ? { why: String(f.why) } : {}) }],
39
+ undo: (r, b, a) => (a.was ? ['/api/boards/tasks/state', { task: b.task, state: stateOf(a.was), why: 'undo' }] : null),
40
+ },
41
+ 'task add': {
42
+ post: (f, p) => ['/api/boards/tasks/add', { initiative: p[0], title: String(p[1] || ''), ...(f.parent && f.parent !== true ? { parent: String(f.parent) } : {}) }],
43
+ undo: (r) => (r && r.item && r.item.uid ? ['/api/boards/tasks/undo-add', { task: r.item.uid }] : null),
44
+ },
45
+ 'task remove': {
46
+ post: (f, p) => ['/api/boards/tasks/delete', { task: p[0], ...(f.why && f.why !== true ? { why: String(f.why) } : {}) }],
47
+ undo: (r, b) => ['/api/boards/tasks/restore', { task: b.task }],
48
+ },
49
+ 'task comment': { post: (f, p) => ['/api/boards/tasks/comment', { task: p[0], text: String(p[1] || '') }], deferred: true },
50
+ };
51
+ const FIELD = { 'task set': (b) => ['due', 'start', 'owner', 'notes', 'description', 'milestone', 'pinned'].find((k) => k in b) || 'task',
52
+ 'task state': () => 'state', 'task add': () => 'task', 'task remove': () => 'removed', 'task comment': () => 'comment' };
53
+
54
+ export function routeOf(run) {
55
+ const c = parseRun(run);
56
+ return c ? ROUTES[c.verb + ' ' + c.sub] || null : null;
57
+ }
58
+
59
+ /** Fills "<id>", "<date>" … from args: a flag by its own name (args.due), else its placeholder's name (args.date); a positional by its
60
+ * placeholder (args.id, args.title, args.text). A flag with no value (--milestone) stays true. */
61
+ export function argsOf(run, args = {}) {
62
+ const c = parseRun(run);
63
+ if (!c) return null;
64
+ const fill = (v, name) => {
65
+ if (v === true) return true;
66
+ const ph = /^<([^>]*)>$/.exec(String(v).replace(/^"|"$/g, ''));
67
+ if (!ph) return clean(v);
68
+ const k = ph[1];
69
+ if (name && args[name] !== undefined) return args[name];
70
+ if (args[k] !== undefined) return args[k];
71
+ if (k === 'id' && args.task !== undefined) return args.task;
72
+ return undefined;
73
+ };
74
+ const flags = {};
75
+ for (const [k, v] of Object.entries(c.flags)) { const x = fill(v, k); if (x !== undefined) flags[k] = x; }
76
+ const pos = c.pos.map((v) => { const x = fill(v); return x === undefined ? undefined : x; });
77
+ return { verb: c.verb, sub: c.sub, flags, pos };
78
+ }
79
+
80
+ const actionsOf = (catalog, kind) => {
81
+ for (const g of (catalog && catalog.groups) || []) for (const k of g.kinds || []) if (k.id === kind) return k.actions || [];
82
+ return null;
83
+ };
84
+ function tell(detail) {
85
+ try { if (typeof window !== 'undefined' && window.dispatchEvent) window.dispatchEvent(new CustomEvent('pmos:action', { detail })); } catch { /* no window in Node */ }
86
+ }
87
+
88
+ export async function runAction(o = {}, { pmPost, catalog } = {}) {
89
+ const list = catalog ? actionsOf(catalog, o.kind) : null;
90
+ const act = typeof o.action === 'object' && o.action ? o.action : list ? list.find((a) => a.label === o.action) : null;
91
+ if (!act || !act.run) return { ok: false, unknown: true, error: 'No such button on a ' + (o.kind || 'card') + '.' };
92
+ if (act.who === 'agent') return { ok: false, ask: act.label + ' for ' + (o.id || 'this') + '.' };
93
+ if (act.who === 'waits' && !o.yes) return { ok: false, needsYes: true, said: act.label + ' waits for your yes.' };
94
+ const c = parseRun(act.run), key = c ? c.verb + ' ' + c.sub : '', R = ROUTES[key];
95
+ if (!R) return { ok: false, unknown: true, error: 'PMOS cannot run "' + act.label + '" from here yet.' };
96
+ const args = { ...(o.args || {}), id: o.id, task: o.id };
97
+ const filled = argsOf(act.run, args);
98
+ if (filled.pos.some((v) => v === undefined || v === '')) return { ok: false, error: act.label + ' needs ' + (act.field || 'a value') + '.' };
99
+ const [route, body0] = R.post(filled.flags, filled.pos, { ...args, was: o.was });
100
+ const body = { ws: o.ws, board: o.board, ...body0 };
101
+ const field = FIELD[key](body0), value = body0[field] !== undefined ? body0[field] : true;
102
+ if (!pmPost) return { ok: false, error: 'No way to write from here.' };
103
+
104
+ if (R.deferred) { // a comment: written when the Undo window closes, unless Undo came first
105
+ let off = false;
106
+ const tm = setTimeout(async () => { if (!off) { const r = await pmPost(route, body).catch(() => null); if (r && r.ok !== false) tell({ kind: o.kind, id: o.id, field, value, undo: false }); } }, o.deferMs != null ? o.deferMs : UNDO_MS);
107
+ return { ok: true, said: act.label + ' sent.', field, value, deferred: true,
108
+ undo: async () => { off = true; clearTimeout(tm); tell({ kind: o.kind, id: o.id, field, value: null, undo: true }); return { ok: true }; } };
109
+ }
110
+ const res = await pmPost(route, body).catch(() => null);
111
+ if (!res || res.ok === false) return { ok: false, error: (res && res.error) || 'The change did not land.' };
112
+ tell({ kind: o.kind, id: o.id, field, value, undo: false });
113
+ const back = R.undo ? R.undo(res, body, { was: o.was }) : null;
114
+ return { ok: true, said: act.label + ' done.', field, value, result: res,
115
+ undo: back ? async () => {
116
+ const u = await pmPost(back[0], { ws: o.ws, board: o.board, ...back[1] }).catch(() => null);
117
+ if (u && u.ok !== false) tell({ kind: o.kind, id: o.id, field, value: o.was !== undefined ? o.was : null, undo: true });
118
+ return u || { ok: false, error: 'The undo did not land.' };
119
+ } : null };
120
+ }
@@ -249,7 +249,7 @@ export function sourceItems(c, f = 'all') {
249
249
 
250
250
  /* ── the side column ── */
251
251
  /** The case: the lines PMOS read from the records, each a press that edits it in place; a line not written offers a PMOS draft. No line
252
- * written: one Suggestion drafts them all (✓ sends the asks to Ask PMOS), ✕ says not now, the pencil starts the first line yourself. */
252
+ * written: one Suggestion drafts them all (✓ runs each draft as a PMOS background job, pm/star-draft.js), ✕ says not now, the pencil starts the first line yourself. */
253
253
  function caseParts(W, o = {}) {
254
254
  const ov = W.overview || { lines: [] }, dr = o.dropped || new Set(), oid = o.oid || '';
255
255
  const L = ov.lines || [], none = L.length && L.every((x) => !x.text);
@@ -265,7 +265,7 @@ function caseParts(W, o = {}) {
265
265
  }
266
266
  const lines = L.filter((x) => !(none && top) || x.text).map((x) => {
267
267
  const ed = !o.ro && x.edit;
268
- const words = x.text ? esc(x.text) : 'Not written yet.';
268
+ const words = x.text ? esc(x.text) : x.drafting ? 'PMOS is drafting it. It shows here.' : 'Not written yet.';
269
269
  const tx = ed ? `<span class="pwd-cv${x.text ? '' : ' grey'}" data-pw-line="${esc(x.id)}" tabindex="0" role="button" aria-label="${esc((x.text ? 'Change the ' : 'Write the ') + x.k.toLowerCase())}">${words}</span>` : `<span class="${x.text ? '' : 'grey'}">${words}</span>`;
270
270
  const src = !o.ro && x.text && x.src ? (x.path ? ` <button type="button" class="pw-osrc" data-pw-src="${esc(x.path)}">from ${esc(x.src)}</button>` : ` <span class="pm-meta">from ${esc(x.src)}</span>`) : '';
271
271
  const off = !o.ro && !x.text && x.ask && !dr.has(sid(x)) ? `<span class="pm-row pwd-off"><button type="button" class="pm-btn" data-pw-lkeep="${esc(x.id)}" aria-label="Yes, PMOS drafts it" title="Yes, PMOS drafts it">${SV(I.star, 14)}</button><button type="button" class="pm-btn" data-pw-ldrop="${esc(sid(x))}" aria-label="No" title="No">${SV(I.x, 14)}</button></span>` : '';
@@ -0,0 +1,25 @@
1
+ /* pm/card-run.js — a catalog button's "run" read as a pmos command, for the page (star-buttons-act-directly; the same reading as
2
+ * lib/card-catalog.js parseRun, which card-catalog.test.js holds equal on every button of the catalog).
3
+ *
4
+ * words(s) → the words of a command: "a quoted part", <a placeholder> and plain words PURE
5
+ * parseRun(s) → { verb, sub, pos: [word], flags: { name: word | true } } | null (null when it is not "pmos …") PURE */
6
+ export function words(s) {
7
+ const out = []; const re = /"[^"]*"|<[^>]*>|\S+/g; let m;
8
+ while ((m = re.exec(s))) out.push(m[0]);
9
+ return out;
10
+ }
11
+ export function parseRun(run) {
12
+ const w = words(String(run || '').trim());
13
+ if (w[0] !== 'pmos' || !w[1]) return null;
14
+ const verb = w[1];
15
+ const sub = w[2] && !w[2].startsWith('-') && !w[2].startsWith('<') && !w[2].startsWith('"') ? w[2] : '';
16
+ const pos = [], flags = {};
17
+ for (let i = sub ? 3 : 2; i < w.length; i++) {
18
+ const x = w[i];
19
+ if (x.startsWith('--')) {
20
+ const nx = w[i + 1];
21
+ if (nx !== undefined && !nx.startsWith('--')) { flags[x.slice(2)] = nx; i++; } else flags[x.slice(2)] = true;
22
+ } else pos.push(x);
23
+ }
24
+ return { verb, sub, pos, flags };
25
+ }
@@ -33,6 +33,7 @@ import * as AK from './artefact-kind.js';
33
33
  import * as WT from './work-tree.js'; // subtasks, the epic check and its fix (initiative work-subtasks)
34
34
  import * as SEL from './work-select.js'; // select several rows and move them together (WorkBulkDS)
35
35
  import * as IF from './inline-fields.js'; // a task's sprint and priority, set in the row (initiative inline-sprint-priority)
36
+ import * as SD from './star-draft.js'; // a ✦ draft runs as a PMOS background job and lands on its line (star-buttons-act-directly A7)
36
37
  import * as PD from './bd-pop-ds.js'; // the popup on a computer, built from the design system's blocks (initiative work-ds-popup) // the Kind of a file and one row per kind (round 3 point 16), shared with the Library // the rename and its Undo, the same write as the old List (batch 18 item 16)
37
38
 
38
39
  const CSS = new URL('./cozy-pop-work.css', import.meta.url).href, DSCSS = new URL('./bd-pop-ds.css', import.meta.url).href;
@@ -181,7 +182,7 @@ function ovLines(ov, oid, edit = true) {
181
182
  const dr = dropped();
182
183
  return `<div class="pw-ols">${ov.lines.map((L) => {
183
184
  const ed = edit && L.edit;
184
- const words = L.text ? esc(L.text) : 'Not written yet.'; // the label already names it: said once (round 3 design check)
185
+ const words = L.text ? esc(L.text) : L.drafting ? 'PMOS is drafting it. It shows here.' : 'Not written yet.'; // the label already names it: said once (round 3 design check)
185
186
  const tx = ed ? `<span class="pw-otx${L.text ? '' : ' grey'}" data-pw-line="${esc(L.id)}" tabindex="0" role="button" aria-label="${esc((L.text ? 'Change the ' : 'Write the ') + L.k.toLowerCase())}">${words}</span>` : `<span class="${L.text ? '' : 'grey'}">${words}</span>`;
186
187
  const src = !RO && L.text && L.src ? (L.path ? ` <button type="button" class="pw-osrc" data-pw-src="${esc(L.path)}">from ${esc(L.src)}</button>` : ` <span class="pw-osrc">from ${esc(L.src)}</span>`) : '';
187
188
  const sid = 'ov:' + oid + ':' + L.id;
@@ -401,6 +402,7 @@ function model(r, v0, o) {
401
402
  const g = o.goal || goalOf(o.ws, o.board, r.anchor || v.anchor);
402
403
  const W = M.workOf(r, v, { ...o, goal: M.idShaped(g) ? '' : g, product: productName(o.product, o.ws), art: artOf(id, o.ws), open: S.open, shut: S.shut, moreOpen: S.moreOpen, farOpen: S.farOpen, focus: S.focus, subOpen: S.subOpen, subShut: S.subShut, mode: store.get(SPAN, 'full'), items: it || [], dropped: dropped() });
403
404
  if (pd && W.overview) for (const L of W.overview.lines || []) if (pd.lines[L.id] != null) { L.text = pd.lines[L.id]; delete L.ask; delete L.miss; }
405
+ if (W.overview) for (const L of W.overview.lines || []) if (!L.text && DRAFTING.has(id0 + ':' + L.id)) { L.drafting = true; delete L.ask; delete L.miss; }
404
406
  const mk = M.marksOf(W.span, W.today, W.view); W.tx = mk.today;
405
407
  W.epics = (r.epics || []).filter(Boolean); RSEL = S.sel; // the epic check and the picked rows, for the Gantt rows (initiative work-subtasks)
406
408
  // the Gantt's Jira column (work-subtasks-followups): on unless Choose columns hides it, and only when the work has a Jira row
@@ -600,12 +602,89 @@ function sendToChat(text) {
600
602
  const f = ta.closest('form'); if (f && f.requestSubmit) f.requestSubmit(); else ta.focus();
601
603
  return true;
602
604
  }
605
+ /* the words go to Ask PMOS (star-buttons-act-directly A5): the popup's chat when it is open, else the chat over the page (page-chat.js ask),
606
+ * written in and not sent. No press ends at a toast that only says to open the chat. */
607
+ function toAsk(text, h) {
608
+ if (!text || sendToChat(text)) return;
609
+ const w = h && h.where ? h.where() : {};
610
+ import('./page-chat.js').then((PC) => PC.ask(text, { ws: w.ws || (ASK_AT && ASK_AT.ws) || undefined, here: 'Work' })).catch(() => { if (h && h.toast) h.toast('Ask PMOS did not open. Try again.'); });
611
+ }
612
+ /* a ✦ draft (star-buttons-act-directly A7; Wawan chose "Yes, run drafts in background" on 2026-11-24): the words run as a PMOS background
613
+ * job (pm/star-draft.js, POST /api/star-drafts) with no chat and no session of the PM's. The line says PMOS is drafting it; the draft then
614
+ * lands on the line itself through the line's own save, with Undo. A job that fails says why, with Try again. */
615
+ const DRAFTING = new Set(); // '<popup key>:<line id>' while its job runs
616
+ async function draftLine(L, x, h) {
617
+ const w = h.where ? h.where() : {}, kid = keyOf(x.v(), x.o()), k = kid + ':' + L.id;
618
+ if (DRAFTING.has(k)) return;
619
+ DRAFTING.add(k); if (h.redraw) h.redraw();
620
+ const r = await SD.run(L.ask, { ws: w.ws || x.o().ws, pmPost, pmGet });
621
+ DRAFTING.delete(k);
622
+ if (!r.ok) { if (h.redraw) h.redraw(); undoToast(r.why, () => draftLine(L, x, h), 12000, 'Try again'); return; }
623
+ await saveLine(L, r.text.replace(/\s+/g, ' ').trim().slice(0, 600), x, h);
624
+ }
625
+ /* a program's line (its charter's why or goal): the same job, saved with POST /api/programs/save, and Undo saves the line as it was */
626
+ const LV_FIELD = { for: 'why', goal: 'goal' };
627
+ async function draftLevelLine(Lv, line, h) {
628
+ const f = LV_FIELD[line.id], k = 'level:' + Lv.id + ':' + line.id;
629
+ if (!f || !Lv.id || Lv.kind !== 'program') { toAsk(line.ask, h); return; }
630
+ if (DRAFTING.has(k)) return;
631
+ DRAFTING.add(k); if (h.redraw) h.redraw();
632
+ const r = await SD.run(line.ask, { ws: Lv.home || Lv.ws, pmPost, pmGet });
633
+ DRAFTING.delete(k);
634
+ if (!r.ok) { if (h.redraw) h.redraw(); undoToast(r.why, () => draftLevelLine(Lv, line, h), 12000, 'Try again'); return; }
635
+ const text = r.text.replace(/\s+/g, ' ').trim().slice(0, 600);
636
+ const all = await pmGet('/api/programs').catch(() => null), p = all && all.ok ? (all.programs || []).find((q) => q.id === Lv.id) : null;
637
+ if (!p) { if (h.redraw) h.redraw(); undoToast('The program was not found, so the draft was not saved.', () => draftLevelLine(Lv, line, h), 12000, 'Try again'); return; }
638
+ const was = p[f] || '';
639
+ const res = await pmPost('/api/programs/save', { ws: p.home, program: { ...p, [f]: text } }).catch(() => null);
640
+ if (!res || res.ok === false) { if (h.redraw) h.redraw(); undoToast(LE.notSaved(res), () => draftLevelLine(Lv, line, h), 12000, 'Try again'); return; }
641
+ if (h.reload) await h.reload(); else if (h.redraw) h.redraw();
642
+ undoToast(line.k + ' saved.', async () => {
643
+ const u = await pmPost('/api/programs/save', { ws: p.home, program: { ...((res && res.program) || p), [f]: was } }).catch(() => null);
644
+ if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
645
+ if (h.reload) await h.reload(); else if (h.redraw) h.redraw();
646
+ });
647
+ }
648
+ /* the documents a gate needs (d:draft): each is a PMOS background job with no chat. A core document runs its own draft run (POST
649
+ * /api/core-docs/draft) and lands in Artefacts as a draft for the PM to read; the done test is drafted by the ✦ job and lands as its checks
650
+ * (POST /api/artefacts/set, with Undo); a document PMOS has no writer for here (a PRD or rubric with no core-document entry) is drafted the
651
+ * same way and its draft is written into Ask PMOS with where to save it, so the PM reads it before anything is kept. */
652
+ async function draftDocs(s, x, h) {
653
+ const w = h.where ? h.where() : {}, o = x.o(), id = o.id, ws = w.ws || o.ws, kid = keyOf(x.v(), o), k = kid + ':d:draft';
654
+ if (DRAFTING.has(k)) return;
655
+ const W = model(x.r(), x.v(), o).W, miss = (W.artefacts || []).filter((a) => a.missing);
656
+ if (!miss.length) { toAsk(s.ask, h); return; }
657
+ DRAFTING.add(k);
658
+ if (h.toast) h.toast('PMOS is drafting ' + miss.map((a) => 'the ' + a.title).join(', ').replace(/, (?=[^,]*$)/, ' and ') + '. Each lands in Artefacts.');
659
+ let started = 0;
660
+ for (const a of miss) {
661
+ if (a.key) { const r = await pmPost('/api/core-docs/draft', { ws, scope: 'initiative:' + id, key: a.key }).catch(() => null); if (r && r.ok !== false) { started++; continue; } }
662
+ const done = /^done test$/i.test(a.title);
663
+ const ask = done ? 'Draft the done test for ' + (x.v().title || id) + ': two to four checks, one per line, each one testable. Do not invent anything the records do not say.'
664
+ : 'Draft the ' + a.title + ' for ' + (x.v().title || id) + ' from its documents. Do not invent anything the records do not say.';
665
+ const r = await SD.run(ask, { ws, pmPost, pmGet });
666
+ if (!r.ok) { undoToast(a.title + ': ' + r.why, () => draftDocs(s, x, h), 12000, 'Try again'); continue; }
667
+ started++;
668
+ if (done) {
669
+ const refs = [];
670
+ for (const line of r.text.split(/\n+/).map((t) => t.replace(/^\s*(?:[-*•]|\d+[.)])\s*/, '').trim()).filter(Boolean).slice(0, 6)) {
671
+ const res = await pmPost('/api/artefacts/set', { ws, scope: 'experiment:' + id, artefact: 'done-test', field: 'check', text: line }).catch(() => null);
672
+ if (res && res.ok !== false && res.line) refs.push(res.line.id);
673
+ }
674
+ ART.delete(id);
675
+ if (refs.length) undoToast('Done test drafted: ' + refs.length + (refs.length === 1 ? ' check.' : ' checks.'), async () => { for (const ref of refs) await pmPost('/api/artefacts/undo', { ws, ref }).catch(() => null); ART.delete(id); if (h.redraw) h.redraw(); });
676
+ } else toAsk('Here is a draft of the ' + a.title + ' for ' + (x.v().title || id) + '. Read it with me, then save it where the Artefacts list reads it.\n\n' + r.text, h);
677
+ }
678
+ DRAFTING.delete(k);
679
+ if (h.reload) await h.reload(); else if (h.redraw) h.redraw();
680
+ return started;
681
+ }
603
682
  /* a direct ✓ (bet 1f): the plan end, closing the open tasks, reopening. One press writes through POST /api/boards/ini-<act> with Undo; no chat
604
683
  * message, no session. Only when the route answers ask: true (the plain reading does not hold) do the words go to Ask PMOS, as before. */
605
684
  async function direct(d, ask, x, h) {
606
685
  const w = h.where ? h.where() : {}, id = x.o().id;
607
686
  const res = await pmPost('/api/boards/ini-' + d.act, { ws: w.ws, board: w.board, id, ...(d.to ? { to: d.to } : {}) }).catch(() => null);
608
- if (!res || res.ask) { if (ask && !sendToChat(ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
687
+ if (!res || res.ask) { toAsk(ask, h); return; }
609
688
  if (res.ok === false) { if (h.toast) h.toast(res.error || 'Nothing was changed.'); return; }
610
689
  if (h.reload) await h.reload();
611
690
  if (res.same) { if (h.toast) h.toast(res.said || 'Nothing to change.'); return; }
@@ -624,7 +703,8 @@ async function keepSug(s, x, h) {
624
703
  if (s.move && h.move) { await h.move(s.move.uid, { to: s.move.to, from: '', name: s.move.name }); return; }
625
704
  if (s.moveAll) { await moveAll(s.moveAll, h); return; }
626
705
  if (s.direct) { await direct(s.direct, s.ask, x, h); return; }
627
- if (s.ask && !sendToChat(s.ask) && h.toast) h.toast('Open Ask PMOS to send this.');
706
+ if (s.ask && s.id === 'd:draft') { draftDocs(s, x, h); return; }
707
+ if (s.ask) toAsk(s.ask, h);
628
708
  return;
629
709
  }
630
710
  if (s.sm) { if (h.sm) h.sm('yes'); return; }
@@ -728,20 +808,20 @@ export function wire(body, h0, x0) {
728
808
  if ('pwSpan' in d) { spanMenu(b, redraw); return; }
729
809
  if (d.pwTune) { tuneMenu(b, d.pwTune, redraw); return; }
730
810
  if ('pwBig' in d) { big(c, x, h); return; }
731
- if (d.pwKeep && /^merge:/.test(d.pwKeep)) { const m = mergeOf(W.artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
811
+ if (d.pwKeep && /^merge:/.test(d.pwKeep)) { const m = mergeOf(W.artefacts); if (m) toAsk(m.ask, h); return; }
732
812
  if (d.pwDrop && /^merge:/.test(d.pwDrop)) { const dd = dropped(); dd.add(d.pwDrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
733
- if (d.pwSug && /^merge:/.test(d.pwSug)) { const m = mergeOf(W.artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
813
+ if (d.pwSug && /^merge:/.test(d.pwSug)) { const m = mergeOf(W.artefacts); if (m) toAsk(m.ask, h); return; }
734
814
  if (d.pwKeep) { const s = findSug(W, d.pwKeep); if (s) { b.disabled = true; await keepSug(s, x, h); if (VW.current() && /^sug:/.test(VW.current().id)) VW.back(); } return; }
735
815
  if (d.pwDrop) { const s = findSug(W, d.pwDrop); if (s) { b.disabled = true; await dropSug(s, x, h); if (VW.current() && /^sug:/.test(VW.current().id)) VW.back(); } return; }
736
816
  if (d.pwSug) { const s = findSug(W, d.pwSug); if (s) openSug(s, c, x, h); return; }
737
817
  if ('pwProps' in d) { if (h.props) h.props(); return; }
738
818
  if (d.pwLine) { const L = W.overview.lines.find((q) => q.id === d.pwLine); if (L && L.edit) editLine(b, L, c, x, h); return; }
739
819
  // a phone asks for several lines in one proposal: "problem,done"
740
- if (d.pwLkeep) { const asks = d.pwLkeep.split(',').map((k) => W.overview.lines.find((q) => q.id === k)).filter((L) => L && L.ask).map((L) => L.ask); if (asks.length && !sendToChat(asks.join('\n\n')) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
820
+ if (d.pwLkeep) { const ls = d.pwLkeep.split(',').map((k) => W.overview.lines.find((q) => q.id === k)).filter((L) => L && L.ask); for (const L of ls) { if (L.edit) draftLine(L, x, h); else toAsk(L.ask, h); } return; }
741
821
  if (d.pwLdrop) { const dd = dropped(); for (const k of d.pwLdrop.split(',')) dd.add(k); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
742
822
  if ('pwPdocs' in d) { if (PH_ARTS.has(c.id)) PH_ARTS.delete(c.id); else PH_ARTS.add(c.id); redraw(); return; }
743
823
  if (d.pwSrc) { if (h.doc) h.doc(d.pwSrc); return; }
744
- if (d.pwChoice) { const [sid, k] = d.pwChoice.split('|'), s = findSug(W, sid), ch = s && s.choices && s.choices[+k]; if (ch && ch.direct) { b.disabled = true; await direct(ch.direct, ch.ask, x, h); return; } if (ch && !sendToChat(ch.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
824
+ if (d.pwChoice) { const [sid, k] = d.pwChoice.split('|'), s = findSug(W, sid), ch = s && s.choices && s.choices[+k]; if (ch && ch.direct) { b.disabled = true; await direct(ch.direct, ch.ask, x, h); return; } if (ch) toAsk(ch.ask, h); return; }
745
825
  if (d.pwMore != null) { S.moreOpen.add(d.pwMore); redraw(); return; }
746
826
  if (d.pwVer) { if (ARTOPEN.has(d.pwVer)) ARTOPEN.delete(d.pwVer); else ARTOPEN.add(d.pwVer); redraw(); return; }
747
827
  if (d.pwRowMore) { rowMenu(b, d.pwRowMore, c, h, body); return; }
@@ -1469,12 +1549,13 @@ function artItems(body) {
1469
1549
  const W = model(r, v, x.o()).W, mg = mergeOf(W.artefacts);
1470
1550
  return PD.artMenu(W.artefacts, { ro: RO, merge: mg }).map((it) => ({ ...it, top: true })).map((it) => (it.art != null ? { ...it, on: () => openArt(W.artefacts[it.art], h, x) }
1471
1551
  : it.add ? { ...it, on: () => addArt(x, h) }
1472
- : it.merge ? { ...it, on: () => { if (!sendToChat(mg.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); } } : it));
1552
+ : it.merge ? { ...it, on: () => toAsk(mg.ask, h) } : it));
1473
1553
  }
1474
1554
 
1475
1555
  /* ── one level up: a program or a product (boards 26, 27) ── */
1476
1556
  export function levelHtml(L, o = {}) {
1477
1557
  const W = M.levelOf(L, { today: o.today, mode: store.get(SPAN, 'full') }), C = cols(), mode = store.get(SPAN, 'full');
1558
+ for (const q of (W.overview && W.overview.lines) || []) if (!q.text && DRAFTING.has('level:' + L.id + ':' + q.id)) { q.drafting = true; delete q.ask; delete q.miss; }
1478
1559
  const mk = M.marksOf(W.span, W.today, W.view); W.tx = mk.today;
1479
1560
  const sug = !RO && W.suggests.length ? `<div class="pw-sugs" role="list" aria-label="PMOS suggests"><p class="pw-sugh">PMOS suggests</p>${W.suggests.map((s) => sugLine(s)).join('')}</div>` : '';
1480
1561
  // the same Overview shape as an initiative (round 3 point 10): what it is for, its goal, done when; then the status line and Details ›
@@ -1510,9 +1591,9 @@ export function wireLevel(body, h0, L0) {
1510
1591
  if (d.pwTune) { tuneMenu(b, d.pwTune, redraw); return; }
1511
1592
  if (d.pwDetails) { const S = stOf(d.pwDetails); S.details = !S.details; redraw(); return; }
1512
1593
  if (d.pwVer) { if (ARTOPEN.has(d.pwVer)) ARTOPEN.delete(d.pwVer); else ARTOPEN.add(d.pwVer); redraw(); return; }
1513
- if ((d.pwKeep || d.pwSug) && /^merge:/.test(d.pwKeep || d.pwSug)) { const m = mergeOf(M.levelOf(L()).artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
1594
+ if ((d.pwKeep || d.pwSug) && /^merge:/.test(d.pwKeep || d.pwSug)) { const m = mergeOf(M.levelOf(L()).artefacts); if (m) toAsk(m.ask, h); return; }
1514
1595
  if (d.pwDrop && /^merge:/.test(d.pwDrop)) { const dd = dropped(); dd.add(d.pwDrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
1515
- if (d.pwLkeep) { const x = M.levelOf(L()).overview.lines.find((q) => q.id === d.pwLkeep); if (x && x.ask && !sendToChat(x.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
1596
+ if (d.pwLkeep) { const Lv = L(), x = M.levelOf(Lv).overview.lines.find((q) => q.id === d.pwLkeep); if (x && x.ask) draftLevelLine(Lv, x, h); return; }
1516
1597
  if (d.pwLdrop) { const dd = dropped(); dd.add(d.pwLdrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
1517
1598
  if (d.pwGo) { const i = d.pwGo.indexOf(':'); if (h.go) h.go(d.pwGo.slice(0, i), d.pwGo.slice(i + 1), b); return; }
1518
1599
  if (d.pwArt != null) { const a = M.levelOf(L()).artefacts[+d.pwArt]; if (a && h.art && h.art(a, b)) return; if (a && a.url) window.open(a.url, '_blank', 'noopener'); else if (a && a.path && h.doc) h.doc(a.path); return; }
@@ -14,6 +14,8 @@
14
14
  import * as POP from './cozy-popup.js';
15
15
  import * as VW from './cozy-viewer.js';
16
16
  import * as GM from './goals-model.js';
17
+ import { pmGet, pmPost } from './http.js';
18
+ import * as SD from './star-draft.js'; // a ✦ draft runs as a PMOS background job and lands under its row (star-buttons-act-directly A7)
17
19
 
18
20
  const CSS = ['./cozy-pop-work.css', './cozy-goals.css'].map((p) => new URL(p, import.meta.url).href);
19
21
  if (typeof document !== 'undefined' && document.head) for (const h of CSS) if (!document.querySelector(`link[href="${h}"]`)) { const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = h; document.head.appendChild(l); }
@@ -25,6 +27,16 @@ const ib = (attr, label, d, cls = '') => `<button type="button" class="pw-ib${cl
25
27
  const row = (attr, label, val, cls = '') => `<button type="button" class="pw-src gl-src" ${attr}><span>${esc(label)}</span><span class="gl-srcv"><small class="${cls}">${esc(val || '')}</small>${SVG(P.right, 14)}</span></button>`;
26
28
  const ask = '<button type="button" class="pw-ask" data-gl-ask>' + SVG(P.chat, 15) + 'Ask PMOS about this</button>';
27
29
 
30
+ /** A ✦ draft (star-buttons-act-directly A7): the words run as a PMOS background job with no chat, and the draft lands under the row that
31
+ * was pressed, for the PM to read. ✓ writes the read draft into the chat with `keep` (what to keep), so nothing is kept without the PM. */
32
+ function draftHere(t, ctx, ask, what, keep) {
33
+ const host = (t.closest && t.closest('.pw-card, .pw-spc')) || t.parentElement;
34
+ if (!host || !host.after) { toChat(ask); return; }
35
+ let el = host.nextElementSibling;
36
+ if (!el || !el.hasAttribute || !el.hasAttribute('data-gl-draft')) { el = document.createElement('div'); el.setAttribute('data-gl-draft', ''); host.after(el); }
37
+ SD.mount(el, { ask, ws: ctx.ws || undefined, pmPost, pmGet, what, keep: async (text) => { toChat(keep + '\n\n' + text); return true; } });
38
+ }
39
+
28
40
  /** The words go in the chat on the right, as a draft the PM sends. The chat shows first when it was hidden. */
29
41
  export function toChat(text) {
30
42
  const a = document.querySelector('.cz-pop [data-pop="ask"]'); if (a && !a.closest('[hidden]')) a.click();
@@ -88,7 +100,7 @@ export function openSetup(ctx) {
88
100
  if ('glNsdrop' in d) { t.disabled = true; await ctx.dropNs(ns.row); return; }
89
101
  // the draft run files the draft this page waits for; the chat could not (initiative chat-saves-to-cards)
90
102
  if ('glNsdraft' in d) { t.disabled = true; if (ctx.startNs) { const ok = await ctx.startNs(); if (ok) b.innerHTML = '<div class="pw gl-pg"><p class="grey">PMOS is drafting the North Star. It shows here for your tick.</p></div>'; else t.disabled = false; } else toChat('Draft a North Star for this product from its key results. I approve it with a tick.'); return; }
91
- if (d.glName) { const n = S.names.find((x) => x.id === d.glName); if (n) toChat((n.named ? 'Check the name of ' : 'Name ') + n.label + ' (' + n.krs + '). Draft it from its key results; I approve it with a tick.'); return; }
103
+ if (d.glName) { const n = S.names.find((x) => x.id === d.glName); if (n) draftHere(t, ctx, (n.named ? 'Check the name of ' : 'Name ') + n.label + ' (' + n.krs + '). Draft it from its key results; I approve it with a tick.', 'a name for ' + n.label, 'Keep this name for ' + n.label + '.'); return; }
92
104
  if (d.glSrc) { const s = S.sources.find((x) => x.need === d.glSrc); if (s) toChat('Connect ' + s.need + '. ' + s.frees + '. Test a read before you keep it, and tell me what you need from me.'); return; }
93
105
  if ('glAsk' in d) toChat('About setting up Goals: what should I confirm or connect first?');
94
106
  });
@@ -107,7 +119,7 @@ export function openVerdict(ctx, id, back = false) {
107
119
  + ask + '</div>';
108
120
  show(ctx, { id: 'outcome:' + id, kind: 'Outcome', title: V.title, back }, html, (t) => {
109
121
  const d = t.dataset;
110
- if ('glJudge' in d) { toChat('Judge the outcome of ' + V.title + ': read the result, set it beside the promise and give me a verdict with the reason. Change nothing in the plan until I approve the lesson.'); return; }
122
+ if ('glJudge' in d) { draftHere(t, ctx, 'Judge the outcome of ' + V.title + ': read the result, set it beside the promise and give me a verdict with the reason. Change nothing in the plan until I approve the lesson.', 'a verdict on ' + V.title, 'Keep this verdict on the outcome of ' + V.title + '. Change nothing in the plan until I approve the lesson.'); return; }
111
123
  if (d.glKr) { openKr(ctx, d.glKr, true); return; }
112
124
  if (d.glIni) { openIni(ctx, d.glIni); return; }
113
125
  if ('glAsk' in d) toChat('About the outcome of ' + V.title + ': did it do what it promised?');
@@ -5,7 +5,7 @@
5
5
  * point at them (--fs-*, --fw-*, --lh-*): those sit at :root, so a change to one Komorebi token reaches every page, with or without the class. */
6
6
  .pm-ds{--raise:0 1px 2px rgba(42,46,53,.08), 0 4px 14px -6px rgba(70,80,50,.14);--lift:0 10px 28px -10px rgba(42,46,53,.28);--glow:0 0 0 2px #5F7A45, 0 0 0 5px rgba(95,122,69,.10)}
7
7
  .pm-ds.dark, html.dark .pm-ds, :root[data-theme="dark"] .pm-ds{--raise:0 1px 2px rgba(0,0,0,.4), 0 4px 14px -6px rgba(169,196,140,.08);--lift:0 10px 28px -10px rgba(0,0,0,.6);--glow:0 0 0 2px #A9C48C, 0 0 0 5px rgba(169,196,140,.12)}
8
- :root{--space-4:4px;--space-8:8px;--space-12:12px;--space-16:16px;--space-24:24px;--space-32:32px;--space-48:48px;--space-64:64px;--radius-sm:6px;--radius-md:10px;--radius-card:16px;--radius-panel:24px;--radius-pill:999px}
8
+ :root{--space-4:4px;--space-8:8px;--space-12:12px;--space-16:16px;--space-24:24px;--space-32:32px;--space-48:48px;--space-64:64px;--doc-measure:640px;--page-measure:960px;--width-side:340px;--width-item:480px;--width-contents:200px;--width-margin:240px;--radius-sm:6px;--radius-md:10px;--radius-card:16px;--radius-panel:24px;--radius-pill:999px}
9
9
  :root{--type-title:26px;--leading-title:32px;--weight-title:600;--type-heading:18px;--leading-heading:24px;--weight-heading:600;--type-body:15px;--leading-body:24px;--weight-body:400;--type-small:13px;--leading-small:20px;--weight-small:400;--type-code:13px;--leading-code:20px;--weight-code:400}
10
10
  .pm-ds .title{font-family:var(--font-sans);font-size:var(--type-title);line-height:var(--leading-title);font-weight:var(--weight-title)}
11
11
  .pm-ds .heading{font-family:var(--font-sans);font-size:var(--type-heading);line-height:var(--leading-heading);font-weight:var(--weight-heading)}
@@ -144,6 +144,34 @@
144
144
  .pm-ds .pm-rail .pm-count{position:absolute;top:3px;right:5px}
145
145
  .pm-ds .pm-path{display:flex;align-items:center;gap:6px;font-size:var(--type-small)}
146
146
  .pm-ds .pm-path a{color:var(--blue)}
147
+ .pm-ds .pm-main, .pm-ds .pm-side, .pm-ds .pm-item, .pm-ds .pm-margin, .pm-ds .pm-contents{display:flex;flex-direction:column;gap:var(--space-16);min-width:0}
148
+ .pm-ds .pm-layout-single, .pm-ds .pm-layout-popup{display:flex;flex-direction:column;gap:var(--space-16);width:100%;max-width:var(--page-measure);margin:0 auto}
149
+ .pm-ds .pm-layout-side, .pm-ds .pm-layout-open, .pm-ds .pm-layout-reading{display:grid;gap:var(--space-16);align-items:start}
150
+ .pm-ds .pm-layout-side{grid-template-columns:minmax(0,1fr) var(--width-side)}
151
+ .pm-ds .pm-layout-side>.pm-side, .pm-ds .pm-layout-reading>.pm-contents{position:sticky;top:0}
152
+ .pm-ds .pm-layout-open{grid-template-columns:minmax(0,1fr)}
153
+ .pm-ds .pm-layout-open:has(>.pm-item){grid-template-columns:minmax(0,1fr) var(--width-item)}
154
+ .pm-ds .pm-layout-open>.pm-item, .pm-ds .pm-layout-popup{background:var(--card);border-radius:var(--radius-panel);box-shadow:var(--raise);padding:var(--space-24)}
155
+ .pm-ds .pm-layout-popup{box-shadow:var(--lift);padding:var(--space-24) var(--space-32)}
156
+ .pm-ds .pm-head{display:flex;align-items:center;gap:var(--space-8);min-width:0}
157
+ .pm-ds .pm-layout-reading{grid-template:"head head head" auto "contents main margin" 1fr/var(--width-contents) minmax(0,var(--doc-measure)) var(--width-margin);gap:var(--space-24) var(--space-32);justify-content:center}
158
+ .pm-ds .pm-layout-reading:not(:has(>.pm-margin)){grid-template:"head head" auto "contents main" 1fr/var(--width-contents) minmax(0,var(--doc-measure))}
159
+ .pm-ds .pm-layout-reading>.pm-head{grid-area:head}
160
+ .pm-ds .pm-layout-reading>.pm-contents{grid-area:contents;gap:var(--space-4);font-size:var(--type-small)}
161
+ .pm-ds .pm-layout-reading>.pm-main{grid-area:main;gap:var(--space-24)}
162
+ .pm-ds .pm-layout-reading>.pm-margin{grid-area:margin}
163
+ @media (max-width: 1100px) {
164
+ .pm-ds .pm-layout-side{grid-template-columns:minmax(0,1fr)}
165
+ .pm-ds .pm-layout-reading{grid-template:"head head" auto "main margin" 1fr/minmax(0,var(--doc-measure)) var(--width-margin)}
166
+ .pm-ds .pm-layout-reading:not(:has(>.pm-margin)){grid-template:"head" auto "main" 1fr/minmax(0,var(--doc-measure))}
167
+ .pm-ds .pm-layout-reading>.pm-contents{display:none}
168
+ }
169
+ @media (max-width: 720px) {
170
+ .pm-ds .pm-layout-open:has(>.pm-item){grid-template-columns:minmax(0,1fr)}
171
+ .pm-ds .pm-layout-open:has(>.pm-item)>.pm-main, .pm-ds .pm-layout-reading>.pm-margin{display:none}
172
+ .pm-ds .pm-layout-popup{padding:var(--space-16);border-radius:0;box-shadow:none}
173
+ .pm-ds .pm-layout-reading, .pm-ds .pm-layout-reading:not(:has(>.pm-margin)){grid-template:"head" auto "main" 1fr/minmax(0,1fr)}
174
+ }
147
175
  .pm-ds .pm-state{margin:0;padding:var(--space-8) 0;font-size:var(--type-small);line-height:var(--leading-small);color:var(--muted)}
148
176
  .pm-ds .pm-state.empty{max-width:62ch}
149
177
  .pm-ds .pm-state.loading{display:flex;flex-direction:column;gap:var(--space-4)}
@@ -287,3 +287,34 @@ iframe.vwprint{position:fixed;right:0;bottom:0;width:1px;height:1px;border:0;opa
287
287
  .vwpdfp canvas{display:block;border-radius:var(--radius-mark);box-shadow:0 0 0 1px var(--hair)}
288
288
  .vwpdfs{margin:0;font-size:var(--fs-meta);color:var(--ink-3);line-height:var(--lh-meta);}
289
289
  .vwpdfs:empty{display:none}
290
+ /* The Reading layout (reading-layouts, A334; board ReadingDS): the grid, widths and gaps are the system's pm-layout-reading (komorebi.css).
291
+ Only the reader's own parts are here, on tokens. Body text keeps the page's 16 px reading size (.cf). */
292
+ .vwdoc.rdw{max-width:none}
293
+ .rd .pm-head{flex-wrap:wrap}
294
+ .rd .pm-contents a{padding:var(--space-4) var(--space-8);border-radius:var(--radius-sm);color:var(--muted);text-decoration:none}
295
+ .rd .pm-contents a:hover,.rd .pm-contents a[aria-current="true"]{background:var(--well);color:var(--ink)}
296
+ .rd .pm-head .vwdt{flex:1;min-width:0;margin:0}
297
+ .rd-lab{margin:0 0 var(--space-4);font-size:var(--fs-meta);line-height:var(--leading-small);font-weight:var(--fw-strong);letter-spacing:.06em;text-transform:uppercase;color:var(--muted)}
298
+ .rd-hd{display:flex;flex-direction:column;gap:var(--space-8)}
299
+ .rd-t{margin:0;font-family:var(--font-sans);font-size:var(--fs-display);line-height:var(--leading-title);font-weight:var(--fw-strong);color:var(--ink)}
300
+ .rd-meta{display:flex;align-items:center;flex-wrap:wrap;gap:var(--space-4);margin:0;font-size:var(--fs-meta);line-height:var(--leading-small);color:var(--muted)}
301
+ .rd-ai{display:inline-flex;color:var(--blue)}
302
+ .rd-ai svg{width:var(--space-12);height:var(--space-12)}
303
+ .rd-props>summary{cursor:pointer;font-size:var(--fs-meta);line-height:var(--leading-small);color:var(--muted)}
304
+ .rd-props>summary:focus-visible{outline:none;box-shadow:var(--glow);border-radius:var(--radius-sm)}
305
+ .rd-short{margin:0 0 var(--space-16);padding:var(--space-16) var(--space-24);border-radius:var(--radius-card);background:var(--well);font-size:var(--fs-panel);line-height:1.55;color:var(--ink)}
306
+ .rd-short p:last-child{margin-bottom:0}
307
+ .rd-doc.cf{background:none;border:0;box-shadow:none;padding:0}
308
+ .rd-sec{border-bottom:1px solid var(--line)}
309
+ .rd-sec>summary{display:flex;align-items:center;gap:var(--space-8);padding:var(--space-12) 0;cursor:pointer;list-style:none}
310
+ .rd-sec>summary::-webkit-details-marker{display:none}
311
+ .rd-sec>summary::before{content:"›";flex:none;width:var(--space-16);color:var(--muted);transition:transform var(--duration-quick) var(--ease-out)}
312
+ .rd-sec[open]>summary::before{transform:rotate(90deg)}
313
+ .rd-sec>summary h2{flex:1;margin:0}
314
+ .rd-sec>summary:focus-visible{outline:none;box-shadow:var(--glow);border-radius:var(--radius-sm)}
315
+ .rd-sb{padding:0 0 var(--space-16) var(--space-24)}
316
+ .rd-cn{font-size:var(--fs-meta);color:var(--muted)}
317
+ .rd-cm{padding:var(--space-12) var(--space-16);border-radius:var(--radius-md);background:var(--well);font-size:var(--fs-meta);line-height:var(--leading-small)}
318
+ .rd-cm p{margin:0}
319
+ .rd-q{color:var(--muted)}
320
+ @media (max-width: 720px){ .rd-sb{padding-left:0} .rd-short{padding:var(--space-12) var(--space-16)} }
@@ -13,7 +13,8 @@ import { vwOpen, vwStyle, vwConfirm } from './premium-viewer.js';
13
13
  import { $, $$, esc, toast, AI, CHECK } from './premium-shell.js';
14
14
  import { editBody, acceptBody, rejectBody, askBody, askLine, relationsOf, copyKindOf, copyView, proposalsModel } from './premium-doc-edit.js';
15
15
  import { bodyHtml, pageHead, propHtml, splitDoc, overlay, overlayLine, mergeEdit, readMinutes, dayOf, PANELS, signOffOf } from './premium-vw-doc-model.js';
16
- import { adler } from './cozy-adler.js'; // the sign-off under a page the agent drafted (batch 17 item 4-A, canvas AdH4)
16
+ import { adler } from './cozy-adler.js';
17
+ import { readingOf, foldKey, foldsOf, foldsWith } from './reading-model.js'; // the Reading layout (reading-layouts, A334) // the sign-off under a page the agent drafted (batch 17 item 4-A, canvas AdH4)
17
18
 
18
19
  const I = (d) => `<svg class="i" viewBox="0 0 24 24" aria-hidden="true">${d}</svg>`;
19
20
  const IC = {
@@ -271,11 +272,55 @@ function makePage(d, ctx) {
271
272
  const revs = (P.log && P.log.revisions) || [], so = signOffOf(revs[revs.length - 1], P.text);
272
273
  return so ? `<p class="vwsign" role="note">${adler(so.mood, 40, { label: false })}<span>${esc(so.text)}</span></p>` : '';
273
274
  }
275
+ /* ── the Reading layout (reading-layouts, A334; board ReadingDS): read mode with no agent edit open. Contents at left follows the scroll; the
276
+ * title and meta strip (who drafted ✦, who checked, for whom); In short; one section per heading, each folds and the open state is kept per
277
+ * document; comments in the margin beside their section, and no margin when there are none. Edit, Markdown and an agent's edit keep their page. */
278
+ const store = { get: (k) => { try { return localStorage.getItem(k); } catch { return null; } }, set: (k, val) => { try { localStorage.setItem(k, val); } catch { /* a private window */ } } };
279
+ function metaHtml(R) {
280
+ const revs = (P.log && P.log.revisions) || [], last = revs[revs.length - 1], m = R.meta, bits = [];
281
+ if (m.drafted) bits.push(`${m.drafted.by === 'PMOS' ? `<span class="rd-ai" aria-hidden="true">${AI}</span>PMOS drafted it` : `${esc(m.drafted.by)} wrote it`}${m.drafted.at ? ' ' + esc(dayOf(m.drafted.at)) : ''}`);
282
+ if (m.checked) bits.push(`${esc(m.checked.by)} checked it`);
283
+ else if (!m.drafted && last) bits.push(`Last change by ${esc(whoOf(last))}${last.at ? ' · ' + esc(dayOf(last.at)) : ''}`);
284
+ if (m.for) bits.push(`for ${esc(m.for)}`);
285
+ bits.push(`${v() ? 'v' + v() + ' · ' : ''}${readMinutes(P.text)} min read`);
286
+ return `<p class="rd-meta cfby">${bits.join(' · ')}</p>`;
287
+ }
288
+ function readingHtml(h, p) {
289
+ const R = readingOf(P.text, { title: h.title || String(d.path).split('/').pop(), revisions: (P.log && P.log.revisions) || [], comments: ctx.comments ? ctx.comments() : [] });
290
+ const folds = foldsOf(store.get(foldKey(d.path)));
291
+ const unsaved = P.work != null && P.work !== P.text ? `<p class="vwmut vwline" role="status">You have changes that are not saved yet. Edit shows them again.${P.stale ? ' The chat changed the file since. Cancel there shows the new text.' : ''}</p>` : '';
292
+ let start = 0;
293
+ const md = (src) => { const r = bodyHtml(src, { start }); start += r.heads.length; return r.html; };
294
+ const secs = R.sections.map((sx) => `<details class="rd-sec" id="${esc(sx.id)}" data-rd="${esc(sx.id)}"${folds[sx.id] === false ? '' : ' open'}><summary><h2>${esc(sx.name)}</h2>${sx.comments ? `<span class="rd-cn" title="${sx.comments} comments">${sx.comments}</span>` : ''}</summary><div class="rd-sb">${md(sx.md)}</div></details>`).join('');
295
+ const contents = R.contents.length > 1 ? `<nav class="pm-contents" aria-label="Contents"><p class="rd-lab">Contents</p>${R.contents.map((c, i) => `<a href="#${esc(c.id)}" data-rdto="${esc(c.id)}" aria-current="${i === 0}">${esc(c.name)}</a>`).join('')}</nav>` : '';
296
+ const margin = R.margin.length ? `<aside class="pm-margin" aria-label="Comments">${R.margin.map((c) => `<div class="rd-cm" data-for="${esc(c.id)}">${c.quote ? `<p class="rd-q">on “${esc(c.quote)}”</p>` : ''}<p><b>${esc(c.who || '')}</b>${c.at ? ' · ' + esc(dayOf(c.at) || c.at) : ''}</p><p>${esc(c.text)}</p></div>`).join('')}</aside>` : '';
297
+ return `<div class="pm-layout-reading rd"><div class="pm-head">${toolsHtml(p)}</div>${contents}<div class="pm-main">${moreBar()}${unsaved}`
298
+ + `<header class="rd-hd"><h1 class="rd-t cft">${esc(R.title)}</h1>${metaHtml(R)}`
299
+ + (h.labels.length ? `<div class="cflb">${h.labels.map((l) => `<span>${esc(l)}</span>`).join('')}</div>` : '')
300
+ + (h.props.length ? `<details class="rd-props"><summary>Properties · ${h.props.length}</summary><table class="cfpr" aria-label="Properties">${h.props.map(([k, val]) => `<tr><th scope="row">${esc(k)}</th><td>${propHtml(k, val)}</td></tr>`).join('')}</table></details>` : '') + '</header>'
301
+ + `<article class="cf rd-doc"><div class="cfb">`
302
+ + (R.inShort ? `<section class="rd-short" id="rd-in-short" aria-label="In short"><p class="rd-lab">In short</p>${md(R.inShort)}</section>` : '')
303
+ + `${R.lead ? md(R.lead) : ''}${secs || (R.lead ? '' : '<p class="vwmut">The file has no text yet.</p>')}</div>`
304
+ + `<footer class="cff"><span>${v() ? 'v' + v() : ''}</span><span class="gap"></span><code>${esc(d.path)}</code></footer></article>`
305
+ + signHtml() + sideHtml() + `</div>${margin}</div>`;
306
+ }
307
+ /** Wire the Reading layout: a fold is kept per document; Contents jumps to a section (opening it) and follows the scroll. */
308
+ function wireReading() {
309
+ const box = $('.rd', el); if (!box) return;
310
+ $$('.rd-sec', box).forEach((x) => x.addEventListener('toggle', () => store.set(foldKey(d.path), foldsWith(store.get(foldKey(d.path)), x.dataset.rd, x.open))));
311
+ const nav = $('.pm-contents', box); if (!nav) return;
312
+ const mark = (id) => $$('[data-rdto]', nav).forEach((a) => a.setAttribute('aria-current', String(a.dataset.rdto === id)));
313
+ nav.onclick = (e) => { const a = e.target.closest('[data-rdto]'); if (!a) return; e.preventDefault(); const t = box.querySelector('#' + CSS.escape(a.dataset.rdto)); if (!t) return; if (t.tagName === 'DETAILS') t.open = true; t.scrollIntoView({ block: 'start', behavior: 'smooth' }); mark(a.dataset.rdto); };
314
+ if (typeof IntersectionObserver !== 'function') return;
315
+ const io = new IntersectionObserver((es) => { const top = es.filter((x) => x.isIntersecting).sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top)[0]; if (top) mark(top.target.id); }, { root: el, rootMargin: '0px 0px -70% 0px' });
316
+ $$('#rd-in-short, .rd-sec', box).forEach((x) => io.observe(x));
317
+ }
274
318
  function pageHtml() {
275
319
  if (P.err) return `<p class="vwempty">${esc(P.err)}</p>`;
276
320
  if (P.text == null) return '<p class="vwempty">Reading the file.</p>';
277
321
  const h = pageHead(P.text), p = openProp();
278
322
  const o = p ? overlay(P.text, p, P.kept) : null;
323
+ if (P.mode === 'read' && !o && !ctx.host) return readingHtml(h, p);
279
324
  if (P.mode === 'md') return toolsHtml(p) + `<textarea id="vwMd" class="vwmd" spellcheck="false" aria-label="The file as Markdown">${esc(P.work != null ? P.work : P.text)}</textarea>` + saveRow();
280
325
  const body = o ? overlayBody(h, o) : readBody(h, P.mode === 'edit' && P.work != null ? P.work : P.text);
281
326
  const unsaved = P.mode === 'read' && P.work != null && P.work !== P.text ? `<p class="vwmut vwline" role="status">You have changes that are not saved yet. Edit shows them again.${P.stale ? ' The chat changed the file since. Cancel there shows the new text.' : ''}</p>` : '';
@@ -301,9 +346,10 @@ function makePage(d, ctx) {
301
346
  function draw() {
302
347
  if (!el || !el.isConnected) return;
303
348
  const keepScroll = el.scrollTop;
304
- el.innerHTML = `<div class="vwdoc">${pageHtml()}</div>`;
349
+ const reading = P.mode === 'read' && !ctx.host && P.text != null && !P.err && !openProp();
350
+ el.innerHTML = `<div class="vwdoc${reading ? ' rdw' : ''}">${pageHtml()}</div>`;
305
351
  el.scrollTop = keepScroll;
306
- if (P.mode === 'read') tocOf();
352
+ if (reading) wireReading(); else if (P.mode === 'read') tocOf();
307
353
  if (P.mode === 'edit') startEdit();
308
354
  }
309
355