create-pmos 0.617.0 → 0.619.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 (35) hide show
  1. package/package.json +33 -27
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-initiative-test.js +2 -1
  7. package/workspace/changelog.json +32 -0
  8. package/workspace/guide/layout.md +13 -6
  9. package/workspace/lib/board-premium.js +1 -0
  10. package/workspace/lib/board-trail.js +3 -1
  11. package/workspace/lib/core-docs.js +1 -1
  12. package/workspace/lib/engine/boards.js +2 -2
  13. package/workspace/lib/okr-goals.js +2 -1
  14. package/workspace/lib/routes-boards.js +20 -4
  15. package/workspace/lib/status-when.js +15 -2
  16. package/workspace/package-lock.json +2 -2
  17. package/workspace/package.json +1 -1
  18. package/workspace/premium-board-actions-test.js +1 -0
  19. package/workspace/public/pm/bd-work.css +5 -4
  20. package/workspace/public/pm/cozy-day-pick.css +9 -8
  21. package/workspace/public/pm/cozy-home.css +54 -2
  22. package/workspace/public/pm/cozy-pop-work.css +29 -0
  23. package/workspace/public/pm/cozy-pop-work.js +157 -14
  24. package/workspace/public/pm/cozy-popup.css +6 -1
  25. package/workspace/public/pm/cozy-popup.js +26 -7
  26. package/workspace/public/pm/cozy-status-when.js +17 -2
  27. package/workspace/public/pm/cozy-task-pop.css +34 -0
  28. package/workspace/public/pm/cozy-task-pop.js +199 -0
  29. package/workspace/public/pm/home-app.js +7 -1
  30. package/workspace/public/pm/home-chat.js +13 -7
  31. package/workspace/public/pm/home-data.js +31 -1
  32. package/workspace/public/pm/home-ini.js +8 -1
  33. package/workspace/public/pm/page-chat.js +1 -1
  34. package/workspace/public/pm/premium-board.js +18 -4
  35. package/workspace/test-lists/chat-turns.json +9 -0
@@ -0,0 +1,199 @@
1
+ /* pm/cozy-task-pop.js — one task in a small popup on top of the one popup (popup round 3 point 20, Wawan 2026-11-19: "When open task, can it also
2
+ * open a smaller popup on top of current one?"). The initiative popup stays behind it, dimmed a little, not closed and not scrolled.
3
+ *
4
+ * openTask(uid, ctx) opens the task. ctx: { ws, board, ini, pmPost(path, body), toast(msg, undo?), onChange(), iniTitle?(id),
5
+ * row?(uid) → the row the host drew (GET /api/boards/items adds the owner and notes when it answers), list?() → [uid] (↑ ↓ step through it),
6
+ * rename?(task, title) → Promise (the title,
7
+ * pressed, becomes a field; Enter or leaving it saves), onClose?(uid) (the host
8
+ * lights the row), openIni?(id) }
9
+ * closeTask() closes it, as ✕, Esc or a press outside do. Esc closes only the small popup.
10
+ *
11
+ * Inside: the kind (Task or Milestone, pressed to switch) and the title; the one task card (pm/task-card.js mountCard: status, due, owner, notes,
12
+ * where it sits, what PMOS changed) whose status pick asks when it really happened (pm/cozy-status-when.js, point 18); ⋯ with Make it a
13
+ * milestone and Archive (Undo). No chat inside: one level only, a second task replaces the content. On a phone it is a sheet from the bottom.
14
+ * Every write is the PM's press, on the board's own routes. The UI says PMOS, never Claude; icon-only buttons carry aria-label. */
15
+ import { taskOf, mountCard, boardSaver, cardStyle, historyFor } from './task-card.js';
16
+ import * as SWN from './cozy-status-when.js';
17
+
18
+ const CSS = new URL('./cozy-task-pop.css', import.meta.url).href;
19
+ if (typeof document !== 'undefined' && document.head && !document.querySelector(`link[href="${CSS}"]`)) {
20
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = CSS; document.head.appendChild(l);
21
+ }
22
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
23
+ const SVG = (d) => `<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
24
+ const P = {
25
+ x: 'M6 6l12 12M18 6L6 18', up: 'M7 14l5-5 5 5', down: 'M7 10l5 5 5-5', chat: 'M4 5h16v11H9l-5 4z', more: 'M5 12h.01M12 12h.01M19 12h.01',
26
+ dia: 'M12 4l8 8-8 8-8-8z', box: 'M6 5h12a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z',
27
+ };
28
+ const ib = (attr, label, d) => `<button type="button" class="ctp-ib" ${attr} aria-label="${esc(label)}" title="${esc(label)}">${SVG(d)}</button>`;
29
+
30
+ let S = null; // { el, scrim, uid, ctx, card, t, raw, nextDay, prevFocus }
31
+
32
+ /** The task's row: the board's items (its owner and notes too), else the row the host drew. */
33
+ async function rowOf(uid, ctx) {
34
+ const q = 'board=' + encodeURIComponent(ctx.board || '') + (ctx.ws ? '&ws=' + encodeURIComponent(ctx.ws) : '');
35
+ const I = ctx.board ? await fetch('/api/boards/items?' + q, { credentials: 'same-origin' }).then((x) => x.json()).catch(() => null) : null;
36
+ const it = I && I.ok ? (I.items || []).find((x) => x.uid === uid) : null;
37
+ const own = ctx.row ? ctx.row(uid) : null;
38
+ return it ? { ...(own || {}), ...it } : own || null;
39
+ }
40
+
41
+ export function closeTask() {
42
+ if (!S) return;
43
+ const { el, scrim, uid, ctx, prevFocus } = S;
44
+ S = null;
45
+ document.removeEventListener('keydown', onKey, true);
46
+ el.remove(); scrim.remove();
47
+ document.body.classList.remove('ctp-on');
48
+ if (ctx.onClose) ctx.onClose(uid);
49
+ if (prevFocus && prevFocus.isConnected) prevFocus.focus();
50
+ }
51
+
52
+ function onKey(e) {
53
+ if (!S) return;
54
+ if (e.key === 'Escape') {
55
+ // a picker open inside the card closes first (its own Escape); then only the small popup
56
+ if (e.target.closest && e.target.closest('.hi-pop, .dp-cal, [data-tkc-notes]')) return;
57
+ e.preventDefault(); e.stopPropagation(); closeTask(); return;
58
+ }
59
+ if ((e.key === 'ArrowUp' || e.key === 'ArrowDown') && S.el.contains(e.target) && !e.target.closest('input, textarea, [role="menu"], .sw, .tkc-dp')) {
60
+ const L = S.ctx.list ? S.ctx.list() : [], i = L.indexOf(S.uid), j = i + (e.key === 'ArrowUp' ? -1 : 1);
61
+ if (i >= 0 && j >= 0 && j < L.length) { e.preventDefault(); show(L[j]); }
62
+ }
63
+ }
64
+
65
+ /** Opens the small popup on top; a second call while it is open replaces its content (one level only). */
66
+ export async function openTask(uid, ctx = {}) {
67
+ cardStyle();
68
+ if (!S) {
69
+ const scrim = document.createElement('div'); scrim.className = 'ctp-scrim'; scrim.addEventListener('click', closeTask);
70
+ const el = document.createElement('div'); el.className = 'cz ctp'; el.setAttribute('role', 'dialog'); el.setAttribute('aria-modal', 'true'); el.setAttribute('data-esc-layer', '');
71
+ document.body.append(scrim, el);
72
+ document.body.classList.add('ctp-on');
73
+ S = { el, scrim, ctx, uid, prevFocus: document.activeElement };
74
+ document.addEventListener('keydown', onKey, true);
75
+ el.addEventListener('click', press);
76
+ // the status pick waits for the day (point 18): the card's own press is held here, the line opens under the card
77
+ el.addEventListener('click', holdStatus, true);
78
+ }
79
+ S.ctx = ctx;
80
+ await show(uid);
81
+ }
82
+
83
+ async function show(uid) {
84
+ if (!S) return;
85
+ const ctx = S.ctx;
86
+ S.uid = uid;
87
+ S.el.setAttribute('aria-busy', 'true');
88
+ const raw = await rowOf(uid, ctx);
89
+ if (!S || S.uid !== uid) return;
90
+ S.el.removeAttribute('aria-busy');
91
+ if (!raw) { S.el.innerHTML = `<div class="ctp-h">${ib('data-ctp-close', 'Close', P.x)}</div><p class="ctp-none">This task could not be read. It may have been removed.</p>`; return; }
92
+ const t = taskOf(raw, { iniTitle: ctx.iniTitle ? ctx.iniTitle(raw.ini || ctx.ini) : '', board: ctx.board, ini: ctx.ini });
93
+ S.raw = raw; S.t = t; S.nextDay = null;
94
+ const L = ctx.list ? ctx.list() : [], i = L.indexOf(uid);
95
+ const kind = `<button type="button" class="ctp-kind" data-ctp-kind aria-label="${esc(t.milestone ? 'Milestone. Make it a task' : 'Task. Make it a milestone')}"${t.jira ? ' disabled' : ''}>${SVG(t.milestone ? P.dia : P.box)}<span>${t.milestone ? 'Milestone' : 'Task'}</span></button>`;
96
+ const title = !t.jira && ctx.rename ? `<button type="button" class="ctp-t" data-ctp-rename aria-label="${esc('Rename ' + t.title)}">${esc(t.title)}</button>` : `<span class="ctp-t">${esc(t.title)}</span>`;
97
+ const step = L.length > 1 && i >= 0 ? ib(`data-ctp-step="-1"${i === 0 ? ' disabled' : ''}`, 'Previous task', P.up) + ib(`data-ctp-step="1"${i === L.length - 1 ? ' disabled' : ''}`, 'Next task', P.down) : '';
98
+ const more = !t.jira ? ib('data-ctp-more aria-haspopup="menu"', 'More for this task', P.more) : '';
99
+ S.el.setAttribute('aria-label', 'Task: ' + t.title);
100
+ S.el.innerHTML = `<div class="ctp-h">${kind}${title}<span class="ctp-tools">${step}${more}${ib('data-ctp-close', 'Close', P.x)}</span></div>`
101
+ + '<div class="ctp-b"></div><div class="ctp-when" hidden></div>';
102
+ const base = boardSaver({ ws: ctx.ws, board: raw.board || ctx.board, t, post: (p, b) => ctx.pmPost(p, b) });
103
+ const save = (patch) => {
104
+ // a status the PM dated earlier carries that day; Undo and every other change go as they always did
105
+ const day = patch.status != null ? S && S.nextDay : null;
106
+ if (S) S.nextDay = null;
107
+ if (day && !t.jira) return ctx.pmPost('/api/boards/tasks/state', { ws: ctx.ws, board: raw.board || ctx.board, task: t.uid, state: patch.status, happened: day });
108
+ return base(patch);
109
+ };
110
+ const changed = () => { raw.status = t.status; raw.end = t.due; raw.start = t.start; raw.owner = t.owner; raw.notes = t.notes; raw.milestone = t.milestone; clearTimeout(changed.t); changed.t = setTimeout(() => { if (ctx.onChange) ctx.onChange(); }, 400); };
111
+ const toast = (msg, undo) => (ctx.toast ? ctx.toast(msg, undo) : undefined);
112
+ S.card = mountCard(S.el.querySelector('.ctp-b'), t, {
113
+ save, toast, changed, now: () => Date.now(),
114
+ openIni: (id) => { closeTask(); if (ctx.openIni) ctx.openIni(id); },
115
+ iniTitleOf: (id) => (ctx.iniTitle ? ctx.iniTitle(id) : id),
116
+ owners: () => (ctx.owners ? ctx.owners() : []),
117
+ inis: () => (ctx.inis ? ctx.inis() : []),
118
+ history: historyFor({ ws: ctx.ws, board: raw.board || ctx.board, t, post: (p, b) => ctx.pmPost(p, b) }),
119
+ });
120
+ const f = S.el.querySelector('.ctp-t') || S.el.querySelector('button'); if (f) f.focus();
121
+ }
122
+
123
+ /* the card's status press waits for "When did this happen?": Today preselected, so a second press of the status or Enter keeps today */
124
+ function holdStatus(e) {
125
+ if (!S || !S.t) return;
126
+ const b = e.target.closest('[data-tkc-state]'); if (!b || !S.el.contains(b) || S.t.jira) return;
127
+ const st = b.dataset.tkcState;
128
+ if (st === S.t.status) return;
129
+ if (S.held === st) { S.held = null; S.nextDay = null; hideWhen(); return; } // the second press of the same status: today, as the card does
130
+ e.stopPropagation(); e.preventDefault();
131
+ S.held = st;
132
+ // the line sits right under the facts card (the status row), the card does not redraw while it waits
133
+ const w = S.el.querySelector('.ctp-when'), facts = S.el.querySelector('.ctp-b .tkc-f');
134
+ if (facts && w.previousElementSibling !== facts) facts.after(w);
135
+ w.hidden = false; w.innerHTML = '';
136
+ S.el.querySelectorAll('[data-tkc-state]').forEach((x) => x.classList.toggle('ctp-held', x.dataset.tkcState === st));
137
+ const pick = (day) => { const s = S; if (!s) return; s.held = null; s.nextDay = day && day !== SWN.localDay() ? day : null; hideWhen(); s.card.setStatus(st); };
138
+ const head = document.createElement('p'); head.className = 'ctp-wh'; head.textContent = st; w.appendChild(head);
139
+ const box = document.createElement('div'); w.appendChild(box);
140
+ SWN.askWhen(box, { since: S.raw.since || '', onPick: pick });
141
+ const t0 = box.querySelector('[data-sw]'); if (t0) t0.focus();
142
+ }
143
+ function hideWhen() { if (!S) return; const w = S.el.querySelector('.ctp-when'); if (w) { w.hidden = true; w.innerHTML = ''; S.el.appendChild(w); } S.el.querySelectorAll('.ctp-held').forEach((x) => x.classList.remove('ctp-held')); }
144
+
145
+ async function press(e) {
146
+ if (!S) return;
147
+ const b = e.target.closest('button'); if (!b || b.disabled || !S.el.contains(b)) return;
148
+ const d = b.dataset, ctx = S.ctx, t = S.t;
149
+ if ('ctpClose' in d) { closeTask(); return; }
150
+ if (d.ctpStep) { const L = ctx.list ? ctx.list() : [], j = L.indexOf(S.uid) + Number(d.ctpStep); if (j >= 0 && j < L.length) show(L[j]); return; }
151
+ if ('ctpRename' in d && t && ctx.rename) { renameField(b); return; }
152
+ if ('ctpKind' in d && t) { kindOf(!t.milestone); return; }
153
+ if ('ctpMore' in d && t) { moreMenu(b); return; }
154
+ }
155
+ /* Task or Milestone: the card's own write (POST /api/boards/tasks/edit milestone), with Undo */
156
+ async function kindOf(on) {
157
+ const s = S; if (!s) return;
158
+ const post = (v) => s.ctx.pmPost('/api/boards/tasks/edit', { ws: s.ctx.ws, board: s.raw.board || s.ctx.board, task: s.t.uid, milestone: v });
159
+ const r = await post(on).catch(() => null);
160
+ if (!r || r.ok === false) { if (s.ctx.toast) s.ctx.toast((r && r.error) || 'Nothing was changed.'); return; }
161
+ s.raw.milestone = on;
162
+ if (s.ctx.toast) s.ctx.toast(on ? 'It is a milestone now.' : 'It is a task now.', async () => { const u = await post(!on).catch(() => null); if (u && u.ok !== false) { s.raw.milestone = !on; if (S === s) show(s.uid); if (s.ctx.onChange) s.ctx.onChange(); } return u || { ok: false }; });
163
+ if (s.ctx.onChange) s.ctx.onChange();
164
+ if (S === s) show(s.uid);
165
+ }
166
+ function moreMenu(btn) {
167
+ const s = S; if (!s) return;
168
+ let m = s.el.querySelector('.ctp-menu');
169
+ if (m) { m.remove(); btn.setAttribute('aria-expanded', 'false'); return; }
170
+ m = document.createElement('div'); m.className = 'ctp-menu'; m.setAttribute('role', 'menu'); m.setAttribute('aria-label', 'More for this task');
171
+ m.innerHTML = `<button type="button" role="menuitem" data-k="kind">${SVG(s.t.milestone ? P.box : P.dia)}${s.t.milestone ? 'Make it a task' : 'Make it a milestone'}</button>`
172
+ + (s.t.status !== 'Archived' ? '<button type="button" role="menuitem" data-k="arch">Archive</button>' : '');
173
+ btn.setAttribute('aria-expanded', 'true');
174
+ btn.closest('.ctp-h').appendChild(m);
175
+ m.querySelector('button').focus();
176
+ m.addEventListener('click', (e) => {
177
+ const x = e.target.closest('[data-k]'); if (!x) return;
178
+ e.stopPropagation(); m.remove(); btn.setAttribute('aria-expanded', 'false');
179
+ if (x.dataset.k === 'kind') kindOf(!s.t.milestone);
180
+ else if (x.dataset.k === 'arch') s.card.setStatus('Archived');
181
+ });
182
+ m.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.stopPropagation(); m.remove(); btn.setAttribute('aria-expanded', 'false'); btn.focus(); } });
183
+ }
184
+ /* the title becomes a field: Enter or leaving it saves (the host's rename, with its Undo); Escape keeps the old name */
185
+ function renameField(btn) {
186
+ const s = S; if (!s) return;
187
+ const inp = document.createElement('input');
188
+ inp.className = 'ctp-t ctp-ti'; inp.value = s.t.title; inp.maxLength = 200; inp.setAttribute('aria-label', 'Name of the task');
189
+ btn.replaceWith(inp); inp.focus(); inp.select();
190
+ let done = false;
191
+ const leave = async (save) => {
192
+ if (done) return; done = true;
193
+ const v = inp.value.trim();
194
+ if (save && v && v !== s.t.title) { await Promise.resolve(s.ctx.rename(s.raw, v)).catch(() => null); s.raw.title = v; }
195
+ if (S === s) show(s.uid);
196
+ };
197
+ inp.addEventListener('blur', () => leave(true));
198
+ inp.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); leave(true); } else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); leave(false); } });
199
+ }
@@ -77,6 +77,7 @@ import { mountPull } from './cozy-pull.js'; // pull to refresh on Your day, Ad
77
77
  import * as DB from './dash-view.js'; // the page model's parts on the product page: the reports, the proposals (batch 17 item 1)
78
78
  import * as PV from './prog-page.js'; // the product page is the one program and product page (batch 21 item 2, canvas RdProgL–RdProgP)
79
79
  import { initiativeRename, taskRename } from './rename-press.js'; // tap the title to rename (canvas RnATask, RnASaved) // the pinned recording row above it (XvARecHome)
80
+ import * as SWN from './cozy-status-when.js'; // a stage move asks when it really happened (round 3 follow-up of point 18)
80
81
 
81
82
  const $ = (s, r = document) => r.querySelector(s);
82
83
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
@@ -1891,7 +1892,12 @@ function openOverview() {
1891
1892
  const after = async (r, ok) => { if (r && r.ok !== false) { toast(ok); await load(); if (S.ini === id && S.IM) M = S.IM; draw(body); } else { const m = body.querySelector('#ovMsg'); if (m) m.textContent = (r && r.error) || 'Nothing was changed.'; } };
1892
1893
  body.onclick = async (e) => {
1893
1894
  const t = e.target.closest('button'); if (!t || !M) return;
1894
- if (t.dataset.ovMove) { if (t.getAttribute('aria-pressed') === 'true') return; after(await pmPost('/api/boards/move', { ...bw(), id, to: t.dataset.ovMove }), 'Moved to ' + t.dataset.ovMove + '.'); return; }
1895
+ if (t.dataset.ovMove) { // asks when it really happened (round 3 follow-up of point 18)
1896
+ if (t.getAttribute('aria-pressed') === 'true') return;
1897
+ const to = t.dataset.ovMove;
1898
+ SWN.whenPop(t, { title: 'Move to ' + to, since: (M.acts && M.acts.movedOn) || '', onPick: async (day) => { await after(await pmPost('/api/boards/move', { ...bw(), id, to, ...(day ? { happened: day } : {}) }), SWN.whenWords('Moved to ' + to, day)); } });
1899
+ return;
1900
+ }
1895
1901
  if (t.dataset.ovLife === 'active') { after(await pmPost('/api/lifecycle', { ws: M.board.ws, initiative_id: id, state: 'active', reason: '' }), 'Recorded.'); return; }
1896
1902
  if (t.dataset.ovLife) { ask = t.dataset.ovLife; draw(body); const w = body.querySelector('#ovWhy'); if (w) w.focus(); return; } // the reason is asked inline, not in a browser dialog
1897
1903
  if ('ovLifeNo' in t.dataset) { ask = null; draw(body); return; }
@@ -1,7 +1,7 @@
1
1
  /* pm/home-chat.js — Home's chat column (initiative premium-agreed-design, Home; mockup Main.dc.html section "Conversation", AgChat*).
2
2
  *
3
3
  * On a desktop a header line names what is open: its mark, its title and the chip of where it sits (HvACDesk; host.head(t) draws it).
4
- * Home's own chat has none. The stream: the role's avatar and name over each agent message with Copy, Retry and Make a work-item; the
4
+ * Home's own chat has none. The stream: the role's avatar and name over each agent message with Copy, Retry and Make it a task; the
5
5
  * PM's bubbles with "You · HH:MM"; "Worked …" folds (under the message that asks, while it asks); a Today divider; "New since you left"; "N earlier messages · show";
6
6
  * a permission card with the change before → after, Allow and Deny. At the top of the chat, the progress line (XcbOptions B, home-line.js): one
7
7
  * line for the goal or the session while it works, with Stop; a tap opens its steps in place on a phone and in the Viewer on a desktop; blue while
@@ -15,7 +15,7 @@
15
15
  * started, POST /ask and /press) or a session with no chat key (GET /api/sessions/conversation?id=, POST /api/session/say and /keys).
16
16
  * A loose session the host can place (host.suggestLink(target, firstText) → { id, title }) shows one chip: Link it (host.linkTo) or × (host.dismissLink).
17
17
  * On a phone (batch 31 item 5) the stream is messages only: no avatar column and no name or time line (both still read out), and
18
- * Copy, Retry and Make a work-item show on the newest message; an older one shows them on press and hold. The In:/To: chip and the
18
+ * Copy, Retry and Make it a task show on the newest message; an older one shows them on press and hold. The In:/To: chip and the
19
19
  * waiting bar leave the box there: the top bar's context line and ⋯ hold them (pm/phone-chat-head.js).
20
20
  * Every write is the PM's press. mountChat(el, host) returns { open(target), refresh(), focus(), send(text) }.
21
21
  * target: { key?, sid?, title, scope: { text, icon, loose }, role: { name, initial }, intro?: { role, text, at, mood? (Adler as the avatar while the log is empty), pills: [{ label, primary, go }] },
@@ -161,8 +161,10 @@ export function mountChat(el, host) {
161
161
  const id = 'w' + i, on = C.open.has(id);
162
162
  // the tool steps of one answer fold into one grey line, "5 steps" (popup round 3 point 9); the press opens them
163
163
  const n = it.calls.length || Object.values(it.tools || {}).reduce((k, v) => k + (Number(v) || 0), 0);
164
- const what = n ? n + (n === 1 ? ' step' : ' steps') : 'Worked' + (it.took ? ' ' + it.took : '');
164
+ const what = it.folded ? 'Worked ' + (n + (it.notes || []).length) + ((n + (it.notes || []).length) === 1 ? ' step' : ' steps') + (it.took ? ' · ' + it.took : '')
165
+ : n ? n + (n === 1 ? ' step' : ' steps') : 'Worked' + (it.took ? ' ' + it.took : '');
165
166
  return `<div class="hm-worked"><button type="button" class="hm-wk" data-hm-wk="${id}" aria-expanded="${on}" title="${esc(toolLine(it.tools) + (it.took ? ' · ' + it.took : ''))}">${SVG(CHEV, 12, 2.4)}<span>${esc(what)}</span></button>`
167
+ + (on && it.notes && it.notes.length ? `<div class="hm-notes">${it.notes.slice(0, 20).map((t) => `<p>${esc(t)}</p>`).join('')}</div>` : '')
166
168
  + (on ? `<ol class="hm-calls">${it.calls.slice(0, 40).map((c) => `<li><b>${esc(c.tool.split(/__|\//).pop())}</b><code>${esc(c.target || '')}</code></li>`).join('')}</ol>` : '') + '</div>'
167
169
  + (it.ask ? askHtmlOf(it, R) : '');
168
170
  }
@@ -176,7 +178,7 @@ export function mountChat(el, host) {
176
178
  const stopAt = R.stop && i === R.lastAgent;
177
179
  const av = last && isClaude(R.role) ? adlerAvHtml(asking || ak.block ? 'needs-you' : stopAt ? 'honest' : running() ? 'thinking' : 'handled') : avHtml(R.role);
178
180
  return (stopAt ? dividerHtml({ tone: R.stop.tone, text: R.stop.text }) : '') + `<div class="hm-a${asking ? ' ask' : ''}${last ? ' last' : ''}">${av}<div class="hm-ab"><p class="hm-who">${esc(R.role.name)} <span>${esc(hm(it.at))}</span></p>${rp.text ? verHtml(rp.text) : ''}${srcHtml(sr.src)}${goalBlockHtml(go.block, go)}${reportChipHtml(rp.block, it.mi)}${R.chips(it.mi)}`
179
- + (asking ? '' : `<div class="hm-tools" role="group" aria-label="Message actions"><button type="button" data-hm-copy="${i}">Copy</button>${last && !running() && !(stopAt && R.stop.actions.length) ? `<button type="button" data-hm-retry>Retry</button>` : ''}<button type="button" data-hm-wi="${i}">Make a work-item</button></div>`) + '</div></div>'
181
+ + (asking ? '' : `<div class="hm-tools" role="group" aria-label="Message actions"><button type="button" data-hm-copy="${i}">Copy</button>${last && !running() && !(stopAt && R.stop.actions.length) ? `<button type="button" data-hm-retry>Retry</button>` : ''}<button type="button" data-hm-wi="${i}">Make it a task</button></div>`) + '</div></div>'
180
182
  + (stopAt && R.stop.actions.length ? `<div class="hm-fix" role="group" aria-label="What to do next">${R.stop.actions.map((a, k) => iconBtn({ icon: a.icon, label: a.label, attr: a.data, pri: k === 0 })).join('')}</div>` : '')
181
183
  + blockAskHtml(ak.block, it, R);
182
184
  }
@@ -266,7 +268,9 @@ export function mountChat(el, host) {
266
268
  drawSug();
267
269
  const R = { role: role() };
268
270
  const msgs = (C.conv && C.conv.messages) || [];
269
- const items = streamOf(msgs, { seen: C.seenAt, show: C.show });
271
+ // the narrow chat (the popup's column, a phone): one turn = one answer, its notes and steps in one line (popup round 3 point 19c)
272
+ const narrow = !!(el.closest && el.closest('.cz-pop-chat')) || (typeof matchMedia === 'function' && matchMedia('(max-width: 760px)').matches);
273
+ const items = streamOf(msgs, { seen: C.seenAt, show: C.show, turns: narrow, live: running() });
270
274
  R.lastAgent = -1; items.forEach((it, i) => { if (it.t === 'agent') R.lastAgent = i; });
271
275
  R.asking = !!(C.conv && C.conv.state !== 'ended' && C.conv.ask);
272
276
  // while it asks, the "Worked …" line of its turn sits under the message that asks, over the permission card (AgChatAsk)
@@ -286,7 +290,9 @@ export function mountChat(el, host) {
286
290
  html += GU.choiceHtml(); // /goal while a goal works here: In a new chat, or Here instead
287
291
  for (const n of C.notes || []) if (t.ini && n.ini === t.ini) html += `<p class="hm-note hm-you">${esc(n.text)}</p>`;
288
292
  if (C.th && C.th.working) html += `<p class="hm-note" role="status">The agent is answering. You can write again when it has.</p>`;
289
- if (C.conv && C.conv.state === 'ended') html += '<p class="hm-note">This session has ended. Your conversation is kept here, and your next message picks it up.</p>';
293
+ // the narrow chat says it as one quiet divider (popup round 3 point 19f)
294
+ if (C.conv && C.conv.state === 'ended') html += narrow ? '<div class="hm-day hm-ended" role="separator"><span></span>Session ended · continues when you write<span></span></div>'
295
+ : '<p class="hm-note">This session has ended. Your conversation is kept here, and your next message picks it up.</p>';
290
296
  // an empty chat: Adler resting, because nothing runs here yet (canvas AdH1)
291
297
  if (!html) html = `<div class="hm-empty hm-empty-ad">${adler('resting', 'l', { id: 'chatempty' })}<p>${esc(t.empty || 'Ask anything. It works in a real Claude Code session.')}</p></div>`;
292
298
  put(log, html);
@@ -734,7 +740,7 @@ export function mountChat(el, host) {
734
740
  // a hand edit in the canvas's inspector (pm/cozy-proto.js 'pmos:note'): one quiet line in the conversation, so it shows on both sides.
735
741
  // It lives on this page only; the next version reads the edit itself from edits.json.
736
742
  window.addEventListener('pmos:note', (e) => { if (!mine(e) || !e.detail.text) return; C.notes = [...(C.notes || []).filter((n) => n.ini === C.t.ini), { ini: C.t.ini, text: String(e.detail.text).slice(0, 200) }].slice(-4); draw(); });
737
- /* An older message's Copy, Retry and Make a work-item on a phone (batch 31 item 5): press and hold the message to show them (the CSS
743
+ /* An older message's Copy, Retry and Make it a task on a phone (batch 31 item 5): press and hold the message to show them (the CSS
738
744
  * shows them on the newest message, and on focus for a keyboard). A tap elsewhere hides them again. */
739
745
  let holdT = null;
740
746
  const unhold = () => el.querySelectorAll('.hm-a.held').forEach((x) => x.classList.remove('held'));
@@ -8,7 +8,8 @@
8
8
  * productCard(D) the product's card (every anchor from D.board.anchorRows when sent): "This week", the KRs and the budget on track or at risk, Then, the next routine, the CTA
9
9
  * weeklyUpdate(D) the weekly update the Viewer shows and Send turns into a mail draft: risks to confirm, At risk, Needs a decision, On track,
10
10
  * Not read (workspace grill W2); updateNews(D) says whether there is one to draft this week
11
- * streamOf(conv, o) the chat's stream: day dividers, "New since you left", "N earlier messages", messages, Worked-for folds
11
+ * streamOf(conv, o) the chat's stream: day dividers, "New since you left", "N earlier messages", messages, Worked-for folds;
12
+ * o.turns folds each turn's notes and steps into one worked line above its answer (the narrow chat), o.live: the newest turn works
12
13
  * meetLineOf(P) the meeting line: the current or next meeting, +N for the rest of the day
13
14
  * roleOf(s, roles) an agent's role name and initial for a session ("Claude" when no skill names one)
14
15
  * D is { brief, board, sessions, desk, trail, today, schedules, now }: the answers of GET /api/briefing-premium, /api/board-premium,
@@ -354,6 +355,7 @@ export function streamOf(messages, o = {}) {
354
355
  lastAt = m.at || lastAt;
355
356
  }
356
357
  for (const it of items) if (it.t === 'worked') it.took = it.start && it.end ? dur(Date.parse(it.end) - Date.parse(it.start)) : '';
358
+ if (o.turns) foldTurns(items, o.live);
357
359
  const show = o.show == null ? 12 : o.show;
358
360
  const hidden = Math.max(0, items.length - show);
359
361
  const shown = items.slice(hidden);
@@ -370,6 +372,34 @@ export function streamOf(messages, o = {}) {
370
372
  }
371
373
  return out;
372
374
  }
375
+ /** One turn = one answer (popup round 3 point 19c, the narrow chat): inside one turn (from a message of the PM to the next) the small progress
376
+ * notes and the step lines fold into ONE worked line above the final answer, "Worked 6 steps · 20 s", which opens them. Only the last answer
377
+ * shows in full. A turn still at work (live, the newest) keeps its steps as they are: the progress line shows the current one. Mutates items. */
378
+ function foldTurns(items, live) {
379
+ let i = 0;
380
+ while (i < items.length) {
381
+ if (items[i].t === 'user') { i++; continue; }
382
+ let j = i; while (j < items.length && items[j].t !== 'user') j++;
383
+ const turn = items.slice(i, j), lastAgent = turn.map((x) => x.t).lastIndexOf('agent');
384
+ const atWork = live && j === items.length;
385
+ const before = lastAgent < 0 ? [] : turn.slice(0, lastAgent);
386
+ if (!atWork && (before.some((x) => x.t === 'agent') || before.filter((x) => x.t === 'worked').length > 1)) {
387
+ const w = { t: 'worked', tools: {}, calls: [], notes: [], start: null, end: null, at: null, ask: null, askMsg: null, mi: before[0].mi, folded: true };
388
+ for (const x of before) {
389
+ if (x.t === 'agent') { if (x.text) w.notes.push(x.text); if (!w.start) w.start = x.at; continue; }
390
+ for (const [k, v] of Object.entries(x.tools || {})) w.tools[k] = (w.tools[k] || 0) + v;
391
+ w.calls = w.calls.concat(x.calls || []); w.start = w.start || x.start; w.end = x.end || w.end; w.at = x.at || w.at;
392
+ if (x.ask) { w.ask = x.ask; w.askMsg = x.askMsg; }
393
+ }
394
+ w.end = turn[lastAgent].at || w.end;
395
+ w.took = w.start && w.end ? dur(Date.parse(w.end) - Date.parse(w.start)) : '';
396
+ items.splice(i, before.length, w);
397
+ j -= before.length - 1;
398
+ }
399
+ i = j;
400
+ }
401
+ return items;
402
+ }
373
403
  /** The live run: who works, on which step, how long, and how far (for the steps card and the run strip). */
374
404
  export function runOf(conv, role, now = Date.now()) {
375
405
  if (!conv || (conv.turn !== 'agent' && conv.turn !== 'tool')) return null;
@@ -533,6 +533,7 @@ export function iniLight(id, uid) {
533
533
  LIT = id && uid ? { id, uid: String(uid), seen: false } : null;
534
534
  if (id) PW.focus(id, LIT ? LIT.uid : '');
535
535
  if (LIT) ED.openRow(id, LIT.uid);
536
+ if (id) PW.openOnDraw(id, LIT ? LIT.uid : ''); // and the small task popup opens on top at it (popup round 3 point 20g)
536
537
  }
537
538
  function light(b, id) {
538
539
  if (!LIT || LIT.id !== id || !b) return;
@@ -699,7 +700,13 @@ function wire(body, id) {
699
700
  }
700
701
  if ('ovAdddoc' in d) { addDoc(id); return; }
701
702
  // stage
702
- if (d.ovMove) { if (t.getAttribute('aria-pressed') === 'true') return; const ok = await after(await X.ctx.pmPost('/api/boards/move', { ...bw(M), id, to: d.ovMove, why: 'Moved by hand' }), 'Moved to ' + d.ovMove + '.'); void ok; return; }
703
+ // a stage move asks when it really happened (round 3 follow-up of point 18): Today preselected, an earlier day never before the last move
704
+ if (d.ovMove) {
705
+ if (t.getAttribute('aria-pressed') === 'true') return;
706
+ const to = d.ovMove;
707
+ SWN.whenPop(t, { title: 'Move to ' + to, since: (M.acts && M.acts.movedOn) || '', onPick: async (day) => { await after(await X.ctx.pmPost('/api/boards/move', { ...bw(M), id, to, why: 'Moved by hand', ...(day ? { happened: day } : {}) }), SWN.whenWords('Moved to ' + to, day)); } });
708
+ return;
709
+ }
703
710
  if (d.ovLife === 'active') { after(await X.ctx.pmPost('/api/lifecycle', { ws: M.board.ws, initiative_id: id, state: 'active', reason: '' }), 'Recorded.'); return; }
704
711
  if (d.ovLife) { STAGE_ASK = d.ovLife; redrawView(); const w = body.querySelector('#ovWhy'); if (w) w.focus(); return; }
705
712
  if ('ovLifeNo' in d) { STAGE_ASK = null; redrawView(); return; }
@@ -66,7 +66,7 @@ function host() {
66
66
  if (c && ((c.cos && c.here) || c.popAbout)) { Q.t = cosTarget('', c.ws); Q.chat.open(Q.t); }
67
67
  },
68
68
  onTo: () => {}, onLink: () => {},
69
- workItem: () => toast('Make a work-item from Home, in the initiative’s own chat.'),
69
+ workItem: () => toast('Make it a task from Home, in the initiative’s own chat.'),
70
70
  viewerClosed: () => false, reopenViewer: () => {}, desk: () => true, head: () => '',
71
71
  // a finished turn: the page reads its records again, so what Claude changed shows with no refresh (as Home, batch 25 item 3)
72
72
  turnEnded: () => document.dispatchEvent(new CustomEvent('cz:chat-turn')),
@@ -674,7 +674,21 @@ function stageMenu(r, el) {
674
674
  const b = el.getBoundingClientRect();
675
675
  m.style.left = Math.max(8, Math.min(b.left, innerWidth - m.offsetWidth - 8)) + 'px'; m.style.top = Math.max(8, Math.min(b.bottom + 4, innerHeight - m.offsetHeight - 8)) + 'px';
676
676
  (m.querySelector('.on') || m.querySelector('[data-to]')).focus();
677
- m.addEventListener('click', (e) => { const x = e.target.closest('[data-to]'); if (!x) return; closeStageMenu(); el.focus(); if (x.dataset.to !== cur) moveStage(r, cur, x.dataset.to); });
677
+ // a pick asks when it really happened (round 3 follow-up of point 18): Today is preselected, so a second press of the stage or Enter keeps it
678
+ let picked = null;
679
+ const go = (to, day) => { closeStageMenu(); el.focus(); moveStage(r, cur, to, day && day !== SWN.localDay() ? day : null); };
680
+ m.addEventListener('click', (e) => {
681
+ const x = e.target.closest('[data-to]'); if (!x) return;
682
+ const to = x.dataset.to;
683
+ if (to === cur && !picked) { closeStageMenu(); el.focus(); return; }
684
+ if (picked === to) { go(to, null); return; }
685
+ picked = to;
686
+ m.querySelectorAll('[data-to]').forEach((b) => { const on = b.dataset.to === to; b.setAttribute('aria-checked', String(on)); b.classList.toggle('on', on); });
687
+ let w = m.querySelector('.wk-when'); if (!w) { w = document.createElement('div'); w.className = 'wk-when'; m.appendChild(w); } else w.innerHTML = '';
688
+ SWN.askWhen(w, { since: r.acts.movedOn || '', onPick: (day) => go(to, day) });
689
+ const t = w.querySelector('[data-sw]'); if (t) t.focus();
690
+ m.style.top = Math.max(8, Math.min(b.bottom + 4, innerHeight - m.offsetHeight - 8)) + 'px';
691
+ });
678
692
  m.addEventListener('keydown', (e) => {
679
693
  if (e.key === 'Escape' || e.key === 'Tab') { e.preventDefault(); e.stopPropagation(); closeStageMenu(); el.focus(); return; }
680
694
  if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
@@ -890,11 +904,11 @@ $('#ibBody').addEventListener('drop', async (e) => {
890
904
  moveStage(r, from, to);
891
905
  });
892
906
  /** Move an initiative to another of its stages (POST /api/boards/move), with Undo in the toast: the By stage drag and Work's Stage cell. */
893
- async function moveStage(r, from, to) {
907
+ async function moveStage(r, from, to, happened) {
894
908
  const body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, id: r.id };
895
- const res = await pmPost('/api/boards/move', { ...body, to }).catch(() => null);
909
+ const res = await pmPost('/api/boards/move', { ...body, to, ...(happened ? { happened } : {}) }).catch(() => null);
896
910
  if (!res || !res.ok) { say((res && res.error) || 'It did not move. The server did not say why.'); return; }
897
- say('Moved to ' + to + ' · ' + r.title + '.', async () => { const u = await pmPost('/api/boards/move', { ...body, to: from, why: 'Undo' }).catch(() => null); say(u && u.ok ? 'Back in ' + from + '.' : (u && u.error) || 'The undo did not land.'); load(); });
911
+ say(r.title + ' · ' + SWN.whenWords('Moved to ' + to, happened), async () => { const u = await pmPost('/api/boards/move', { ...body, to: from, why: 'Undo' }).catch(() => null); say(u && u.ok ? 'Back in ' + from + '.' : (u && u.error) || 'The undo did not land.'); load(); });
898
912
  load();
899
913
  }
900
914
  /** The step key of one of the board's own stage names, by the same old-name map as the model (lib/board-premium.js OLD_STEP). */
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Popup round 3 point 19c: one turn = one answer in the narrow chat (pm/home-data.js streamOf turns). No browser.",
3
+ "modules": [
4
+ "chat-turns.test.js"
5
+ ],
6
+ "seconds": {
7
+ "chat-turns.test.js": 1
8
+ }
9
+ }