create-pmos 0.410.0 → 0.411.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 (79) hide show
  1. package/package.json +13 -18
  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-adddoc-test.js +1 -1
  7. package/workspace/briefing-premium-initiative-test.js +9 -15
  8. package/workspace/changelog.json +12 -0
  9. package/workspace/chat-asks-test.js +146 -0
  10. package/workspace/guide/briefing-premium.md +1 -1
  11. package/workspace/guide/home.md +24 -0
  12. package/workspace/home-rows-test.js +149 -56
  13. package/workspace/ini-workflow-test.js +4 -4
  14. package/workspace/lib/briefing-premium-agent.js +8 -1
  15. package/workspace/lib/engine/boards.js +3 -1
  16. package/workspace/lib/goal-chat.js +94 -30
  17. package/workspace/lib/mention-cli.js +70 -0
  18. package/workspace/lib/mention-store.js +307 -0
  19. package/workspace/lib/pmos-verbs.js +3 -0
  20. package/workspace/lib/routes-boards.js +12 -0
  21. package/workspace/lib/routes-briefing-premium.js +2 -2
  22. package/workspace/lib/routes-mentions.js +62 -9
  23. package/workspace/lib/session-files.js +132 -0
  24. package/workspace/lib/session-name.js +103 -0
  25. package/workspace/lib/source-reads.js +4 -1
  26. package/workspace/package-lock.json +2 -2
  27. package/workspace/package.json +1 -1
  28. package/workspace/premium-board-actions-test.js +10 -8
  29. package/workspace/premium-chat-goal-setup-test.js +203 -0
  30. package/workspace/premium-chat-goal-view-test.js +28 -23
  31. package/workspace/premium-chat-line-test.js +189 -0
  32. package/workspace/premium-vw-backlog-test.js +1 -1
  33. package/workspace/premium-vw-item-test.js +1 -1
  34. package/workspace/premium-vw-jira-test.js +1 -1
  35. package/workspace/public/pm/chat-ask.js +17 -9
  36. package/workspace/public/pm/cozy-home-rows.css +39 -1
  37. package/workspace/public/pm/cozy-home.css +112 -12
  38. package/workspace/public/pm/cozy-search.js +2 -1
  39. package/workspace/public/pm/cozy-steps.css +69 -0
  40. package/workspace/public/pm/cozy-steps.js +90 -0
  41. package/workspace/public/pm/goal-chat.js +141 -23
  42. package/workspace/public/pm/home-app.js +68 -35
  43. package/workspace/public/pm/home-ask.js +121 -0
  44. package/workspace/public/pm/home-chat.js +120 -68
  45. package/workspace/public/pm/home-data.js +10 -2
  46. package/workspace/public/pm/home-goal.js +159 -0
  47. package/workspace/public/pm/home-ini.css +35 -0
  48. package/workspace/public/pm/home-ini.js +50 -19
  49. package/workspace/public/pm/home-line.css +59 -0
  50. package/workspace/public/pm/home-line.js +200 -0
  51. package/workspace/public/pm/home-list.js +2 -2
  52. package/workspace/public/pm/home-mentions.js +303 -111
  53. package/workspace/public/pm/home-ses-name.js +65 -0
  54. package/workspace/public/pm/home-stage-card.js +94 -0
  55. package/workspace/public/pm/home-sweep.js +112 -0
  56. package/workspace/public/pm/home-today.js +7 -2
  57. package/workspace/public/pm/premium-initiative-head.js +8 -4
  58. package/workspace/public/pm/rename-press.js +24 -0
  59. package/workspace/public/pm/wf-page.css +3 -0
  60. package/workspace/public/pm/wf-page.js +2 -1
  61. package/workspace/public/premium-workflows.html +1 -0
  62. package/workspace/server.js +125 -11
  63. package/workspace/session-names-test.js +144 -0
  64. package/workspace/skills/jira-push.skill +1 -0
  65. package/workspace/skills/morning-brief.skill +2 -1
  66. package/workspace/skills/report-daily.skill +1 -0
  67. package/workspace/skills/report-monthly.skill +1 -0
  68. package/workspace/skills/report-weekly.skill +1 -0
  69. package/workspace/skills/sources-read.skill +3 -2
  70. package/workspace/stage-card-test.js +203 -0
  71. package/workspace/test-lists/chat-asks.json +13 -0
  72. package/workspace/test-lists/chat-progress.json +13 -0
  73. package/workspace/test-lists/mentions-a-plus.json +9 -0
  74. package/workspace/test-lists/premium-chat-goal-setup.json +9 -0
  75. package/workspace/test-lists/session-files.json +5 -0
  76. package/workspace/test-lists/session-names.json +13 -0
  77. package/workspace/test-lists/stage-card.json +6 -0
  78. package/workspace/tk-tasks-test.js +1 -1
  79. package/workspace/workflows-setup-test.js +17 -0
@@ -0,0 +1,159 @@
1
+ /* home-goal — the goal before Start in a Home chat (XcbOptions B, row 1; Ready for development 2026-10-25). home-chat.js draws the messages;
2
+ * this module owns what the PM presses on a goal there: the method menu (Change), the plan editor in place (drag, ×, +, the date and what it
3
+ * may do; ✓ saves, × discards), a skipped point and its Undo, and the choice when /goal is typed while a goal works (In a new chat, or Here,
4
+ * instead of this goal). The drawing itself is pure, in goal-chat.js.
5
+ * goalUi(cx) → { blockOpts, readyDraft, choiceHtml, afterDraw, viewOpts, wire, press, submit, escape }. cx: { C, host, draw, send, read, openGoal, viewBody, live } */
6
+ import { splitGoal, goalChoiceHtml, methodSay, editedDraft, planRowHtml } from './goal-chat.js';
7
+
8
+ const PLAN = '[PMOS /goal plan]';
9
+ const isGoalCmd = (v) => /^\/goal(\s|$)/.test(String(v || '').trim());
10
+ const working = (g) => !!g && (g.state === 'started' || g.state === 'waiting');
11
+
12
+ export function goalUi(cx) {
13
+ const { C, host } = cx;
14
+ const goal = () => (C.th && C.th.goal) || null;
15
+ const msgs = () => (C.conv && C.conv.messages) || [];
16
+
17
+ /** The newest plan: Claude's newest ready block, the PM's own saved edit in the transcript, or the saved edit on record when it is newer. */
18
+ function readyDraft() {
19
+ const ms = msgs(); let found = null;
20
+ for (let i = ms.length - 1; i >= 0 && !found; i--) {
21
+ const m = ms[i];
22
+ if (m.role === 'assistant') { const b = splitGoal(m.text).block; if (b && b.step === 'ready') found = { draft: b.draft || null, at: m.at, mi: i }; }
23
+ else if (m.role === 'user' && String(m.text || '').startsWith(PLAN)) { try { found = { draft: JSON.parse(String(m.text).split('\n')[1]), at: m.at, mi: i }; } catch { /* not a plan line */ } }
24
+ }
25
+ const g = goal();
26
+ if (g && g.state === 'grilling' && g.plan && (!found || !(Date.parse(g.planAt) <= Date.parse(found.at)))) return g.plan;
27
+ return found ? found.draft : null;
28
+ }
29
+ /** The index of the message that holds the newest ready block (its card shows the newest plan, edits included). */
30
+ function newestReady() {
31
+ const ms = msgs();
32
+ for (let i = ms.length - 1; i >= 0; i--) { if (ms[i].role !== 'assistant') continue; const b = splitGoal(ms[i].text).block; if (b && b.step === 'ready') return i; }
33
+ return -1;
34
+ }
35
+ /** What goalBlockHtml takes for one message: the block (the newest ready one carries the newest plan), whether the method menu is open, the editor. */
36
+ function blockOpts(mi, block, live) {
37
+ const g = goal();
38
+ const b = block && block.step === 'ready' && mi === newestReady() ? { ...block, draft: readyDraft() || block.draft } : block;
39
+ return { block: b, live, state: g && g.state, menu: live && C.goalMenu === mi, edit: live && C.goalEdit && C.goalEdit.where === 'chat' ? C.goalEdit.snap : null };
40
+ }
41
+ /** The Goal view in the Viewer: the editor while the PM changes a working goal there. */
42
+ const viewOpts = () => ({ live: cx.live(), edit: C.goalEdit && C.goalEdit.where === 'view' ? C.goalEdit.snap : null });
43
+ /** The choice card at the end of the log while it is open. */
44
+ const choiceHtml = () => (C.goalQ ? goalChoiceHtml(goal() && goal().draft && goal().draft.goal, { newChat: !!host.newGoalChat }) : '');
45
+
46
+ /* ── the editor: drawn from the plan as it was when Change was pressed (snap), so a redraw does not lose the caret; what the PM types
47
+ * is kept in cur and put back when a redraw does replace the card ── */
48
+ const fieldsOf = (d) => ({ goal: d.goal || '', done: Array.isArray(d.done) && d.done.length ? d.done.slice() : [''], by: d.by || '', may: d.may || '' });
49
+ function readEdit(ed) {
50
+ const v = (k) => { const f = ed.querySelector(`[data-goal-fld="${k}"]`); return f ? f.value : ''; };
51
+ C.goalEdit.cur = { goal: v('goal'), done: [...ed.querySelectorAll('[data-goal-fld="done"]')].map((f) => f.value), by: v('by'), may: v('may') };
52
+ }
53
+ const size = (ta) => { ta.style.height = 'auto'; ta.style.height = ta.scrollHeight + 'px'; };
54
+ function fill(root) {
55
+ const ed = root && root.querySelector('[data-goal-ed]'); if (!ed || !C.goalEdit || ed.__filled) return;
56
+ ed.__filled = true;
57
+ const cur = C.goalEdit.cur, ol = ed.querySelector('.edl');
58
+ if (ol.children.length !== cur.done.length) ol.innerHTML = cur.done.map((x, i) => planRowHtml(i)).join('');
59
+ ed.querySelectorAll('[data-goal-fld="done"]').forEach((f, i) => { f.value = cur.done[i] || ''; });
60
+ for (const k of ['goal', 'by', 'may']) { const f = ed.querySelector(`[data-goal-fld="${k}"]`); if (f) f.value = cur[k]; }
61
+ ed.querySelectorAll('textarea').forEach(size);
62
+ }
63
+ function afterDraw(log) {
64
+ fill(log);
65
+ el().classList.toggle('hm-goalq', !!C.goalQ); // the progress line turns blue while the choice is open
66
+ const ta = el().querySelector('textarea#hmIn'); if (!ta) return;
67
+ const ms = msgs(), last = ms[ms.length - 1], b = last && last.role === 'assistant' ? splitGoal(last.text).block : null;
68
+ if (C.goalEdit && C.goalEdit.where === 'chat') ta.placeholder = 'Or tell Claude what to change';
69
+ else if (b && b.step === 'question' && cx.live()) ta.placeholder = 'Answer, or pick one above';
70
+ }
71
+ const el = () => cx.el;
72
+ function renumber(ed) { ed.querySelectorAll('.edl > li').forEach((li, i) => { li.dataset.gi = i; const f = li.querySelector('textarea'); if (f) f.setAttribute('aria-label', 'Done point ' + (i + 1)); }); }
73
+ function openEdit(where) {
74
+ const d = where === 'view' ? (goal() && goal().draft) : readyDraft(); if (!d) return;
75
+ const f = fieldsOf(d);
76
+ C.goalEdit = { where, base: d, snap: { ...d, done: f.done }, cur: f };
77
+ if (where === 'view') cx.openGoal(); else cx.draw();
78
+ const root = where === 'view' ? cx.viewBody() : el();
79
+ const first = root && root.querySelector('[data-goal-ed] [data-goal-fld="done"]'); if (first && host.desk()) first.focus();
80
+ }
81
+ async function save(ed) {
82
+ readEdit(ed);
83
+ const g = goal(); if (!g || !C.t.key) return;
84
+ const draft = editedDraft(C.goalEdit.base, C.goalEdit.cur);
85
+ if (!draft.goal || !draft.done.length) { host.toast('The plan needs a sentence and at least one done point.'); return; }
86
+ const r = await post({ act: 'plan', draft });
87
+ if (r && r.ok) { C.goalEdit = null; cx.read(); if (cx.viewBody()) cx.openGoal(); else cx.draw(); }
88
+ }
89
+ const post = (body) => host.pmPost('/api/briefing-premium/goal' + (C.t.ws ? '?ws=' + encodeURIComponent(C.t.ws) : ''), { key: C.t.key, id: goal().id, ...body }).catch(() => null)
90
+ .then((r) => { if (!r || !r.ok) host.toast((r && r.error) || 'The press did not reach the session.'); return r; });
91
+
92
+ /** A press inside the chat or the Goal view that this module owns; true when it handled it. */
93
+ async function press(b) {
94
+ const d = b.dataset, ed = b.closest('[data-goal-ed]');
95
+ if ('goalMeth' in d) { const mi = msgs().length - 1; C.goalMenu = C.goalMenu === mi ? null : mi; cx.draw(); const f = el().querySelector('.gmenu [role=menuitem]'); if (f && C.goalMenu != null) f.focus(); return true; }
96
+ if (d.goalMethod) { C.goalMenu = null; const say = methodSay(d.goalMethod); if (say) { b.disabled = true; await cx.send(say); } return true; }
97
+ if (d.goal === 'change') { openEdit(working(goal()) ? 'view' : 'chat'); return true; }
98
+ if (ed && 'goalSave' in d) { b.disabled = true; await save(ed); b.disabled = false; return true; }
99
+ if (ed && 'goalDiscard' in d) { const w = C.goalEdit && C.goalEdit.where; C.goalEdit = null; if (w === 'view') cx.openGoal(); else cx.draw(); return true; }
100
+ if (ed && 'goalAdd' in d) {
101
+ readEdit(ed); const ol = ed.querySelector('.edl'); ol.insertAdjacentHTML('beforeend', planRowHtml(ol.children.length)); readEdit(ed);
102
+ const f = ol.lastElementChild.querySelector('textarea'); if (f) f.focus(); return true;
103
+ }
104
+ if (ed && 'goalRm' in d) {
105
+ const li = b.closest('li'), ol = li.parentElement;
106
+ if (ol.children.length > 1) { const next = li.nextElementSibling || li.previousElementSibling; li.remove(); renumber(ed); const f = next && next.querySelector('textarea'); if (f) f.focus(); }
107
+ else { const f = li.querySelector('textarea'); f.value = ''; f.focus(); }
108
+ readEdit(ed); return true;
109
+ }
110
+ if (d.goalSkip || d.goalUnskip) { b.disabled = true; const r = await post({ act: d.goalSkip ? 'skip' : 'unskip', point: d.goalSkip || d.goalUnskip }); if (r && r.ok) cx.read(); else b.disabled = false; return true; }
111
+ if (d.goalWhere) {
112
+ const q = C.goalQ; C.goalQ = null;
113
+ if (q && d.goalWhere === 'new') host.newGoalChat(q.text, C.t);
114
+ else if (q && d.goalWhere === 'here') { b.disabled = true; const r = await post({ act: 'replace' }); if (r && r.ok) await cx.send(q.text); }
115
+ cx.draw(); return true;
116
+ }
117
+ return false;
118
+ }
119
+ /** The box's text on send: /goal while a goal works here opens the choice instead of sending; true when it did. */
120
+ function submit(v) {
121
+ if (C.goalQ) C.goalQ = null; // another message closes the choice
122
+ if (!isGoalCmd(v) || !working(goal()) || !C.t || !C.t.key) return false;
123
+ C.goalQ = { text: String(v).trim() }; cx.draw(); return true;
124
+ }
125
+ /** Esc closes the method menu or the choice; true when it did. */
126
+ function escape() {
127
+ if (C.goalMenu != null) { C.goalMenu = null; cx.draw(); return true; }
128
+ if (C.goalQ) { C.goalQ = null; cx.draw(); return true; }
129
+ return false;
130
+ }
131
+ /** Typing, dragging and the arrow keys inside an editor under root (the chat, or the Goal view's body). */
132
+ function wire(root) {
133
+ if (!root || root.__goalWired) return; root.__goalWired = true;
134
+ root.addEventListener('input', (e) => { const ed = e.target.closest('[data-goal-ed]'); if (!ed || !C.goalEdit) return; if (e.target.tagName === 'TEXTAREA') size(e.target); readEdit(ed); });
135
+ root.addEventListener('keydown', (e) => {
136
+ const g = e.target.closest && e.target.closest('[data-goal-grip]'); if (!g || !(e.key === 'ArrowUp' || e.key === 'ArrowDown')) return;
137
+ e.preventDefault(); const li = g.closest('li'), ed = li.closest('[data-goal-ed]');
138
+ if (e.key === 'ArrowUp' && li.previousElementSibling) li.parentElement.insertBefore(li, li.previousElementSibling);
139
+ else if (e.key === 'ArrowDown' && li.nextElementSibling) li.parentElement.insertBefore(li.nextElementSibling, li);
140
+ renumber(ed); readEdit(ed); g.focus();
141
+ });
142
+ // drag a point by its handle (mouse or finger): the row moves under the pointer, and the order is read when it is let go
143
+ root.addEventListener('pointerdown', (e) => {
144
+ const g = e.target.closest && e.target.closest('[data-goal-grip]'); if (!g) return;
145
+ e.preventDefault(); const li = g.closest('li'), ol = li.parentElement, ed = li.closest('[data-goal-ed]');
146
+ li.classList.add('drag'); try { g.setPointerCapture(e.pointerId); } catch { /* an old browser: the move still works while over the list */ }
147
+ const move = (ev) => {
148
+ for (const o of ol.children) {
149
+ if (o === li) continue; const r = o.getBoundingClientRect(), mid = r.top + r.height / 2;
150
+ if (ev.clientY < mid && o.compareDocumentPosition(li) & Node.DOCUMENT_POSITION_FOLLOWING) { ol.insertBefore(li, o); break; }
151
+ if (ev.clientY > mid && o.compareDocumentPosition(li) & Node.DOCUMENT_POSITION_PRECEDING) { ol.insertBefore(li, o.nextElementSibling); }
152
+ }
153
+ };
154
+ const up = () => { li.classList.remove('drag'); g.removeEventListener('pointermove', move); g.removeEventListener('pointerup', up); g.removeEventListener('pointercancel', up); renumber(ed); readEdit(ed); };
155
+ g.addEventListener('pointermove', move); g.addEventListener('pointerup', up); g.addEventListener('pointercancel', up);
156
+ });
157
+ }
158
+ return { readyDraft, blockOpts, viewOpts, choiceHtml, afterDraw, fill, press, submit, escape, wire };
159
+ }
@@ -213,3 +213,38 @@ button.hi-pill { cursor: pointer; }
213
213
  .hi-wfrow > .hi-small { grid-column: 1 / -1; }
214
214
  .hi-end { flex-wrap: wrap; }
215
215
  }
216
+
217
+ /* ── stage card D: the stage as a live step list (canvas XscD, XscDDesk); the list itself is cozy-steps.css ── */
218
+ .hm-card.hm-sc { padding: 0; background: transparent; box-shadow: none; }
219
+ .hm-box.hm-scb { background: var(--cz-card); border-radius: 18px; padding: 12px; gap: 0; box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--cz-blue) 45%, transparent); }
220
+ .hm-sch { display: flex; align-items: center; gap: 8px; min-height: 28px; }
221
+ .hm-sch > b { font-size: 15px; font-weight: 800; color: var(--cz-ink); }
222
+ .hm-sch .of { font-size: 12.5px; color: var(--cz-ink3); font-weight: 600; }
223
+ .hm-sch .hm-wf { display: inline-flex; align-items: center; justify-content: center; padding: 3px; margin-left: 2px; border: 0; border-radius: 9px; background: none; cursor: pointer; color: inherit; }
224
+ .hm-sch .hm-wf:hover, .hm-sch .hm-wf[aria-expanded="true"] { background: var(--cz-well); }
225
+ .hm-sct { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--cz-ink3); font-weight: 600; white-space: nowrap; }
226
+ .hm-sct.over { color: var(--cz-risk); }
227
+ .hm-bars.hm-scbars { margin: 10px 0 8px; }
228
+ .hm-bars.hm-scbars i.skip { background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--cz-ink3) 40%, transparent) 0 4px, transparent 4px 7px); }
229
+ .hm-scl { border-top: 1px solid var(--cz-hair); padding-top: 8px; margin-top: 2px; }
230
+ .hm-scwhy { margin: 0; padding: 4px 0 2px 34px; font-size: 12.5px; color: var(--cz-ink3); }
231
+ .hm-scb > .hm-none { margin: 4px 0 0; font-size: 12.5px; color: var(--cz-ink3); }
232
+ /* the move sheet: Move now and Back as two quiet buttons, side by side on a desktop, stacked on the phone */
233
+ .hi-nxa { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--cz-hair); }
234
+ .hi-nxa .hi-btn { flex: 1; justify-content: center; height: 40px; border-radius: 12px; }
235
+ .hi-pop .hi-swl { font-size: 14px; font-weight: 700; color: var(--cz-ink); min-height: 44px; }
236
+ .hi-pop .hi-swl > span { flex: 1; }
237
+ .hi-pop .hi-sw { width: 44px; height: 28px; }
238
+ .hi-pop .hi-sw::after { top: 4px; left: 4px; width: 20px; height: 20px; }
239
+ .hi-pop .hi-sw[aria-checked="true"]::after { left: 20px; }
240
+ @media (max-width: 760px) {
241
+ /* the 44 px floor drew the switch as a big circle: the press stays 44 px tall, the track inside it is drawn 44 by 28 */
242
+ .hi-pop .hi-sw, .hi-v .hi-sw, .hi-pop .hi-sw[aria-checked="true"], .hi-v .hi-sw[aria-checked="true"], :root[data-theme="dark"] .hi-pop .hi-sw, :root[data-theme="dark"] .hi-v .hi-sw { width: 44px; height: 44px; min-height: 44px; background: none; }
243
+ .hi-pop .hi-sw::before, .hi-v .hi-sw::before { content: ""; position: absolute; left: 0; right: 0; top: 8px; height: 28px; border-radius: 999px; background: var(--cz-c-d9dce1); }
244
+ :root[data-theme="dark"] .hi-pop .hi-sw::before, :root[data-theme="dark"] .hi-v .hi-sw::before { background: var(--cz-c-4a4f58); }
245
+ .hi-pop .hi-sw[aria-checked="true"]::before, .hi-v .hi-sw[aria-checked="true"]::before, :root[data-theme="dark"] .hi-pop .hi-sw[aria-checked="true"]::before, :root[data-theme="dark"] .hi-v .hi-sw[aria-checked="true"]::before { background: var(--cz-blue); }
246
+ .hi-pop .hi-sw::after, .hi-v .hi-sw::after { top: 12px; z-index: 1; background: var(--cz-onsolid); }
247
+ .hi-pop.sheet .hi-nxa { flex-direction: column; border-top: 0; padding-top: 0; }
248
+ .hi-pop.sheet .hi-nxa .hi-btn { height: 48px; border-radius: 14px; font-size: 14.5px; font-weight: 800; }
249
+ .hi-pop.sheet .hi-h3 { font-size: 17px; }
250
+ }
@@ -8,8 +8,11 @@
8
8
  * need a look. "Show N more" and "Show all N" drill into Tasks and Documents, with ← back to the page. true when it opened.
9
9
  * iniOverview(v, o) the initiative in the Viewer: Tasks (the default), Documents or Stage; o.back keeps the page behind it. true when it opened.
10
10
  *
11
- * The stage move (InStage): the card shows "Moves on by itself when all N are done" (a switch, on by default, kept in file mode) and Move to <next>
12
- * with Back beside it. Move with items still open asks first (Move anyway, with a note); Back always asks for a reason. Both go to POST /api/boards/move
11
+ * The stage move (stage card D, canvas XscD and XscDDesk; it replaced InStage's switch, Move to <next> and Back on the card): the card's last
12
+ * node is the next stage (home-stage-card.js). A press opens the move sheet on the phone and a popover under it on a desktop, with the
13
+ * reason, "Moves on by itself when all N are done" (a switch, on by default, kept in file mode), Move now and Back. Every step done and
14
+ * the next stage a milestone (or the switch off): the last node is the button Move to ◆ <next>. Move with items still open asks first
15
+ * (Move anyway, with a note); Back always asks for a reason. Both go to POST /api/boards/move
13
16
  * with the note or reason as the move's why. When every exit item is done and the switch is on, the page moves the stage by itself, never into a
14
17
  * milestone (Deliver, Evaluate), and says so in a toast with Undo; Undo moves it back and keeps it from moving out of that stage by itself again.
15
18
  * Tasks (InTasks): grouped by stage, by groups the PM names (drag a task between them; group sets are saved for the workspace), by owner, by status
@@ -23,7 +26,9 @@
23
26
  * under ⋯; the phone keeps the Tasks | Documents | Stage switch. The pure half of the tickets is tk-model.js. */
24
27
  import * as MD from './home-ini-model.js';
25
28
  import * as TKM from './tk-model.js';
26
- import * as WF from './ini-wf.js'; // D99: the initiative's own workflow (Change picker, switch, Won't do, Archive)
29
+ import * as WF from './ini-wf.js';
30
+ import * as SC from './home-stage-card.js';
31
+ import { ensureCss as ensureStepsCss } from './cozy-steps.js'; // stage card D: the card's last node and the move sheet's words // D99: the initiative's own workflow (Change picker, switch, Won't do, Archive)
27
32
 
28
33
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
29
34
  const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
@@ -68,15 +73,7 @@ async function press(id, M, body) {
68
73
  return false;
69
74
  }
70
75
 
71
- /* ── the stage move in the card (InStage) ── */
72
- function moveHtml(id, M, mv) {
73
- if (mv.why) return `<div class="hi-mv" data-hi-mv><p class="hi-why">${esc(mv.why)}</p></div>`;
74
- return `<div class="hi-mv" data-hi-mv>`
75
- + `<div class="hi-swl"><button type="button" class="hi-sw" role="switch" aria-checked="${mv.auto}" data-hi-auto aria-label="Moves on by itself">${''}</button><span>${esc(mv.swText)}</span></div>`
76
- + (mv.msNote ? `<p class="hi-note">${mv.ready ? '<b>Ready to move.</b> ' : ''}${esc(mv.msNote)}</p>` : mv.held && mv.auto ? `<p class="hi-note">You undid a move by itself out of ${esc(mv.cur)}, so it waits for you here.</p>` : '')
77
- + `<div class="hi-mvb"><button type="button" class="hi-btn sm dark" data-hi-move aria-haspopup="dialog" aria-expanded="${!!(X.pop && X.pop.kind === 'move')}">Move to ${mv.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(mv.next)}${SVG(I.next, 14)}</button>`
78
- + (mv.canBack ? `<button type="button" class="hi-ib" data-hi-back aria-haspopup="dialog" aria-label="Move back a stage, to ${esc(mv.prev)}" title="Move back to ${esc(mv.prev)}">${SVG(I.back, 16)}</button>` : '') + '</div></div>';
79
- }
76
+ /* ── the stage move: the card's last node opens the move sheet (stage card D) ── */
80
77
  /** D99: an initiative on a workflow of the library moves between ITS stages (the row's wfStages; a skipped stage is left out), and that
81
78
  * stage's Moves on by itself is the default (the PM's own choice for this one initiative wins, POST /api/boards/ini-auto). */
82
79
  const rowOf = (id) => (X.ctx.rowOf ? X.ctx.rowOf(id) : null) || {};
@@ -200,6 +197,38 @@ function popBack(anchor, id, M, mv) {
200
197
  const sync = () => { el.querySelector('[data-hi-go]').disabled = !MD.backReady(chip, el.querySelector('#hiWhy').value); };
201
198
  el.querySelector('#hiWhy').addEventListener('input', sync);
202
199
  }
200
+ /** The move sheet (stage card D): a tap on the next stage opens it, a sheet on the phone and a popover under the line on a desktop. It holds
201
+ * the reason, the "Moves on by itself" switch (the workflow stage sets the default; the switch changes it for this initiative only),
202
+ * Move now (with open steps it asks for a note, as before) and Back. A milestone next has no switch: it never moves into one by itself. */
203
+ function nextSheetHtml(id, M, mv) {
204
+ const h = X.ctx.S.H || {}, row = rowOf(id), own = ownWf(row);
205
+ const sw = !mv.ms && mv.canMove ? `<div class="hi-swl"><span>${esc(mv.swText)}</span><button type="button" class="hi-sw" role="switch" aria-checked="${mv.auto}" data-hi-auto aria-label="Moves on by itself"></button></div>`
206
+ + `<p class="hi-small">${own ? esc('The ' + ((row.wf || {}).name || 'workflow') + ' workflow sets the default. This switch changes it for this initiative only.') : 'PMOS moves it and tells you, with Undo. It never moves into a milestone by itself.'}</p>`
207
+ + (mv.held && mv.auto ? `<p class="hi-small">You undid a move by itself out of ${esc(mv.cur)}, so it waits for you here.</p>` : '') : '';
208
+ const open = mv.open.length;
209
+ return `<p class="hi-h3">Next: ${mv.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(mv.next)}</p>`
210
+ + (SC.nextReason(h) ? `<p class="hi-small">${esc(SC.nextReason(h))}</p>` : '')
211
+ + (mv.ms ? `<p class="hi-small">${esc(mv.msNote)}</p>` : '') + sw
212
+ + `<div class="hi-nxa">${mv.canMove ? `<button type="button" class="hi-btn" data-hi-go>Move to ${esc(mv.next)} now${SVG(I.next, 14)}</button>` : ''}`
213
+ + (mv.canBack ? `<button type="button" class="hi-btn" data-hi-goback>${SVG(I.back, 14)}Back to ${esc(mv.prev)}</button>` : '') + '</div>'
214
+ + (mv.canMove && open ? `<p class="hi-small">${open === 1 ? '1 step is' : open + ' steps are'} still open. You add a note when you move anyway.</p>` : '');
215
+ }
216
+ function popNext(anchor, id, M) {
217
+ const mv = mvOf(id, M);
218
+ const reopen = () => { const a = document.querySelector('#czViewer [data-hi-next]') || anchor; return a; };
219
+ openPop(anchor, 'next', nextSheetHtml(id, M, mv), async (b, el) => {
220
+ const d = b.dataset, mv2 = mvOf(id, curM() || M);
221
+ if ('hiAuto' in d) {
222
+ const on = b.getAttribute('aria-checked') !== 'true';
223
+ b.setAttribute('aria-checked', String(on)); // the switch answers at once; a refused write puts it back
224
+ const ok = ownWf(rowOf(id)) ? await autoPress(id, M, on) : await press(id, M, { kind: 'auto', on });
225
+ if (ok === false) b.setAttribute('aria-checked', String(!on));
226
+ return;
227
+ }
228
+ if ('hiGo' in d) { closePop(); if (!mv2.canMove) return; if (mv2.open.length) popMove(reopen(), id, M, mv2); else doMove(id, M, mv2.next, 'Moved by hand: every exit item is done.'); return; }
229
+ if ('hiGoback' in d) { closePop(); if (mv2.canBack) popBack(reopen(), id, M, mv2); }
230
+ }, { label: 'Next: ' + mv.next, wide: false, sheetFocus: '[data-hi-go], [data-hi-goback]' });
231
+ }
203
232
  /** A small menu: items [{ label, sub?, on?, go }] with optional labels { head: 'Group by' } between them. */
204
233
  function menu(anchor, items, label) {
205
234
  openPop(anchor, 'menu', items.map((x, i) => (x.head ? `<p class="hi-mlbl">${esc(x.head)}</p>` : x.hr ? '<div class="hi-hr"></div>'
@@ -225,9 +254,9 @@ export function iniList(sc) {
225
254
 
226
255
  /* ── the initiative's page in the Viewer (canvas HbCDesk, HbCNew, HbCPhone) ── */
227
256
  function pageHtml(id, M) {
228
- const L = Lof(id), mv = mvOf(id, M), rows = MD.taskRows(M, L), T = MD.listTasks(rows);
229
- let card = X.ctx.cardHtml(id, { page: true });
230
- if (mv.cur) { const at = card.lastIndexOf('<div class="hm-acts">'); if (at > 0) card = card.slice(0, at) + moveHtml(id, M, mv) + card.slice(at); }
257
+ const L = Lof(id), rows = MD.taskRows(M, L), T = MD.listTasks(rows);
258
+ // stage card D: the card's last node is the next stage (or Move to ◆ Deliver), from the move model of the card's own head
259
+ const card = X.ctx.cardHtml(id, { page: true, tail: (h) => SC.tailOf(h, MD.moveModel(h, wfM(id, M), wfL(id, L), Date.now())) });
231
260
  const trow = (t) => `<div class="hm-r hi-r">`
232
261
  + (t.canCheck ? `<button type="button" class="hi-chk" data-hi-chk="${esc(t.key)}" aria-pressed="false" aria-label="Mark ${esc(t.title)} done"></button>` : '<span class="hi-chk off" aria-hidden="true"></span>')
233
262
  + `<button type="button" class="hm-rm" data-hi-task="${esc(t.key)}"><span class="hm-rt"><b>${esc(t.title)}</b><em class="${t.late ? 'late' : 'q'}">${esc([t.owner || (t.jira ? 'Jira' : ''), t.due].filter(Boolean).join(' · ') || t.state)}</em></span></button></div>`;
@@ -267,8 +296,9 @@ const moreBtn = () => document.querySelector('#czViewer [data-cz-vw="more"]') ||
267
296
  /** Moves on by itself for this one initiative, on a workflow of the library (POST /api/boards/ini-auto): the stage sets the default. */
268
297
  async function autoPress(id, M, on) {
269
298
  const r = await X.ctx.pmPost('/api/boards/ini-auto', { ...bw(M), id, stage: rowOf(id).wfStage.key, auto: on });
270
- if (!r || r.ok === false) { X.ctx.toast((r && r.error) || 'Nothing was changed.'); return; }
299
+ if (!r || r.ok === false) { X.ctx.toast((r && r.error) || 'Nothing was changed.'); return false; }
271
300
  await X.ctx.load(); redrawView();
301
+ return true;
272
302
  }
273
303
  export function iniPage() {
274
304
  if (!X.ctx) return false;
@@ -636,9 +666,9 @@ async function openTask(id, M, key) {
636
666
  /** A press on the initiative's page: the card's own presses go to Home; a task or a document drills in, so ← comes back to the page. */
637
667
  function pagePress(t, id, M) {
638
668
  const d = t.dataset, C = X.ctx, VW = C.VW;
639
- if ('hmCta' in d) { C.cta(); return true; }
640
- if ('hmOv' in d) { C.overviewAsk(id); return true; }
641
- if ('hmCfold' in d) { C.foldCard(); redrawView(); return true; }
669
+ if ('hmGo' in d) { C.cta(); return true; } // the PM's step: the one primary opens it (the old CTA's target)
670
+ if ('hmMore' in d) { C.S.stepsMore = true; redrawView(); return true; }
671
+ if ('hiNext' in d) { popNext(t, id, M); return true; }
642
672
  if ('hmWf' in d) { if (!(M.acts && M.acts.self)) WF.openPicker(t, wfUi(), id); else C.toast('This board takes its stages from the workflow engine.'); return true; }
643
673
  if ('wfBack' in d) { WF.backToTriage(wfUi(), id); return true; }
644
674
  if ('hmDone' in d) { C.S.doneOpen = !C.S.doneOpen; redrawView(); return true; }
@@ -661,6 +691,7 @@ export function mountIni(ctx) {
661
691
  X.ctx = ctx;
662
692
  if (typeof document === 'undefined') return X;
663
693
  if (!document.querySelector('link[data-hi-css]')) { const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = '/pm/home-ini.css'; l.dataset.hiCss = ''; document.head.appendChild(l); }
694
+ ensureStepsCss(); // the stage card's step list (cozy-steps.css), before the first draw
664
695
  if (!document.querySelector('link[data-tk-css]')) { const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = '/pm/tk-tasks.css'; l.dataset.tkCss = ''; document.head.appendChild(l); }
665
696
  ctx.VW.onChange((v) => { if (!v.open || !/^ov:/.test(v.id || '')) closePop(); });
666
697
  return X;
@@ -0,0 +1,59 @@
1
+ /* pm/home-line.css — the chat progress line (canvas XcbOptions B). home-line.js adds it once. Tokens only (cozy.css), dark by the same tokens.
2
+ * The line: one row with the spinner, the step, the count, a chevron and Stop; blue while Claude asks; tinted while the Viewer shows it.
3
+ * The divider: a quiet line where a run finished, a check for done, amber words for a stop. */
4
+ .hm-pl { box-sizing: border-box; flex: none; margin: 0 0 8px; border-radius: 16px; background: var(--cz-card); border: 1px solid var(--cz-hair); box-shadow: var(--cz-lift); color: var(--cz-ink); font-family: var(--cz-sans); }
5
+ .hm-pl.on { background: var(--cz-bluebg); box-shadow: inset 0 0 0 1.5px var(--cz-blue); }
6
+ .hm-pl.you, .hm-goalq .hm-pl { background: var(--cz-bluebg); border-color: transparent; }
7
+ .pl-row { display: flex; align-items: center; gap: 4px; min-height: 48px; padding: 2px 4px 2px 0; }
8
+ .pl-hit { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 6px 0 14px; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 14px; }
9
+ .pl-hit:focus-visible, .pl-stop:focus-visible, .pl-ib:focus-visible, .pl-dvb:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
10
+ .pl-t { flex: 1; min-width: 0; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
11
+ .hm-pl.open .pl-t { white-space: normal; }
12
+ .hm-pl.you .pl-t, .hm-goalq .pl-t { color: var(--cz-blueink); }
13
+ .pl-n { flex: none; font-size: 12.5px; font-weight: 600; color: var(--cz-ink3); }
14
+ .pl-cv { flex: none; display: inline-flex; color: var(--cz-ink3); }
15
+ .pl-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--cz-blue); }
16
+ .pl-clk { display: inline-flex; color: var(--cz-ink3); }
17
+ .pl-stop { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--cz-hair); background: var(--cz-card); color: var(--cz-ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
18
+ .pl-body { padding: 0 14px 12px; }
19
+ .pl-head { margin: 0 0 10px; font-size: 12.5px; color: var(--cz-ink3); line-height: 1.4; }
20
+ .pl-sl { margin-top: 2px; }
21
+ .pl-now { display: flex; align-items: center; gap: 8px; margin: 4px 0 0; padding-top: 10px; border-top: 1px solid var(--cz-hair); font-size: 12.5px; min-width: 0; }
22
+ .pl-now b { flex: none; font-weight: 800; }
23
+ .pl-now code { min-width: 0; font-family: var(--cz-mono); font-size: 12px; color: var(--cz-ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
24
+ .hm-pl.open .pl-now code { white-space: normal; word-break: break-all; }
25
+ .pl-acts { display: flex; gap: 8px; margin-top: 10px; }
26
+ .pl-ib { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--cz-hair); background: var(--cz-card); color: var(--cz-ink2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
27
+ .pl-ib.pri { background: var(--cz-solid); color: var(--cz-onsolid); border-color: transparent; }
28
+
29
+ /* the Viewer (a desktop) */
30
+ .pl-vw { padding: 16px 20px; }
31
+ .pl-vwh { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
32
+ .pl-vwh b { flex: 1; min-width: 0; font-size: 16px; font-weight: 800; line-height: 1.3; }
33
+
34
+ /* the divider where a run finished */
35
+ .pl-dv { display: flex; align-items: center; gap: 10px; margin: 4px 0; font-size: 13px; font-weight: 700; color: var(--cz-ink2); }
36
+ .pl-dv .ln { flex: 1; height: 1px; background: var(--cz-hair); }
37
+ .pl-dv.stop { color: var(--cz-risk); }
38
+ .pl-dvb { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 8px; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; border-radius: 10px; }
39
+ span.pl-dvb { cursor: default; }
40
+ .pl-dk { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; background: var(--cz-okbg); color: var(--cz-ok); }
41
+ .pl-dva { display: flex; gap: 8px; padding-left: 36px; }
42
+
43
+ /* a Home row's ring: fills as the points or steps are met */
44
+ .hv-ring { display: block; flex: none; }
45
+ .hv-ring .bg { fill: none; stroke: var(--cz-c-a9aeb6); stroke-width: 1.5; opacity: .5; }
46
+ .hv-ring .fg { fill: none; stroke: var(--cz-blue); stroke-width: 1.8; stroke-linecap: round; }
47
+
48
+ /* where the line sits: over the log, as wide as it; on a phone it stays at the top while the page scrolls */
49
+ .hm-plw { flex: none; }
50
+ .hm-plw[hidden] { display: none; }
51
+ body.cz-home:not(.hm-vw-open) .hm-plw { box-sizing: border-box; width: 100%; max-width: 880px; align-self: center; }
52
+ .hm-qn .hm-qx { color: var(--cz-ink3); display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; }
53
+ @media (max-width: 760px) {
54
+ .hm-plw { position: sticky; top: 56px; z-index: 6; padding-top: 4px; background: var(--cz-card); }
55
+ .hm-plw .hm-pl { margin: 0 0 8px; }
56
+ /* a phone chat has no floating menu (the line and the top bar hold what it held), and the log needs no room for it */
57
+ body.cz-home:not(.hm-plist):not(.hm-sheet) .cz-fabw { display: none; }
58
+ body.cz-home:not(.hm-plist) .hm-log { padding-bottom: 12px; }
59
+ }
@@ -0,0 +1,200 @@
1
+ /* pm/home-line.js — the chat progress line (initiative premium-agreed-design; canvas In development, XcbOptions B). Pure string builders
2
+ * and models (the first call in a page adds /pm/home-line.css once): Node tests them (chat-line.test.js).
3
+ *
4
+ * One line at the top of a chat shows the progress of the goal or of the session (one thing: Wawan, 2026-10-25). Folded it shows a spinner,
5
+ * the step it is on, "1 of 4 done" and Stop. A tap opens it in place on a phone (the goal's points, a Now row with the newest tool call,
6
+ * Watch its terminal) and in the Viewer on a desktop (viewHtml). A session that never wrote a step list shows "Working · 3:12", never an
7
+ * invented count. When Claude needs the PM the line turns blue ("Claude asks before it goes on"). When the run ends the line goes away and a
8
+ * divider stays where it finished (dividerHtml): "Goal done", or in amber why it stopped.
9
+ *
10
+ * goalModel(goal, conv, o) a working goal (state started or waiting) → model, else null
11
+ * sessionModel(conv, o) a running session (its turn is the agent's or a tool's) → model, else null
12
+ * o: { now (ms), asking (a card waits on the PM), open (the PM opened it), all (Show all pressed), on (the Viewer shows it) }
13
+ * lineHtml(m) the line; m:
14
+ * { icon: 'spin'|'clock'|'none', text, count, clock, tone: ''|'you', stopLabel, open, on, head, title,
15
+ * items: [{ text, state: done|now|next|skip, sub, code, avatar: { initial, name }, act: { attr, icon, label } }], now, more, term }
16
+ * presses (data-pl): toggle (the line), stop, all (Show all N), term (Watch its terminal)
17
+ * viewHtml(m) the same steps for the Viewer on a desktop: the head line, every item, the Now row, Stop and the terminal
18
+ * dividerHtml(d) { tone: 'ok'|'stop', text, attr, actions: [{ icon, label, data }] } the quiet line where a run finished
19
+ * goalDivider(goal) the divider of a goal that is done or stopped, else null
20
+ * stepsStop(conv) "Stopped at 2 of 4" for a session that ended or was stopped with steps left, else ''
21
+ * ringHtml(p, label) a Home row's ring: it fills as the points or steps are met, no number. p: { done, n } or null (plain ring) */
22
+ import { stepsHtml, nodeHtml, spinHtml } from './cozy-steps.js';
23
+
24
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
25
+ const SVG = (d, w = 16, sw = 2) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
26
+ const P = {
27
+ down: 'M6 9l6 6 6-6', up: 'M6 15l6-6 6 6', term: 'M4 5h16v14H4zM8 10l3 2-3 2M13 15h3', check: 'M5 12l5 5 9-10',
28
+ clock: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 7v5l3 2', target: 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8',
29
+ stop: 'M6 6h12v12H6z', pencil: 'M4 20h4L19 9l-4-4L4 16v4z',
30
+ };
31
+ export const ICON = P;
32
+ const STOP_SQ = '<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="currentColor"><rect x="5" y="5" width="14" height="14" rx="2"/></svg>';
33
+ const pad = (n) => String(n).padStart(2, '0');
34
+ const CAP = 5;
35
+ let css = false;
36
+ function ensureCss() {
37
+ if (css || typeof document === 'undefined' || !document.head) return;
38
+ css = true;
39
+ if (document.querySelector('link[data-hm-line-css]')) return;
40
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = '/pm/home-line.css'; l.dataset.hmLineCss = ''; document.head.appendChild(l);
41
+ } // more than 5 items: the ones around the current one, and "Show all N" (principle 4, summary first)
42
+
43
+ /** m:ss since the PM's last message: how long the run has gone on. */
44
+ export function clockOf(conv, now = Date.now()) {
45
+ const u = ((conv && conv.messages) || []).filter((m) => m.role === 'user').pop();
46
+ const t0 = u && u.at ? Date.parse(u.at) : NaN;
47
+ if (!Number.isFinite(t0)) return '';
48
+ const s = Math.max(0, Math.round((now - t0) / 1000));
49
+ return Math.floor(s / 60) + ':' + pad(s % 60);
50
+ }
51
+ /** The newest tool call of the turn that runs now ("Edit · planning/prd/x.md"), or '' once the PM wrote after it. */
52
+ export function nowCall(conv) {
53
+ const ms = (conv && conv.messages) || [];
54
+ for (let i = ms.length - 1; i >= 0; i--) {
55
+ if (ms[i].role === 'user') return '';
56
+ const c = ms[i].role === 'tool' && (ms[i].calls || []).slice(-1)[0];
57
+ if (c) return String(c.tool || '').split(/__|\//).pop() + (c.target ? ' · ' + c.target : '');
58
+ }
59
+ return '';
60
+ }
61
+ const running = (conv) => !!conv && (conv.turn === 'agent' || conv.turn === 'tool') && conv.state !== 'ended';
62
+
63
+ /** The items to show: all of them, or (more than CAP, not opened in full) the ones around the current one. */
64
+ function window5(items, cur, all) {
65
+ if (all || items.length <= CAP) return { items, more: 0 };
66
+ const at = Math.max(0, cur);
67
+ const from = Math.max(0, Math.min(at - 1, items.length - CAP));
68
+ return { items: items.slice(from, from + CAP), more: items.length };
69
+ }
70
+
71
+ /** A working goal (started, or waiting on the PM) as the line's model. goal: the GET /thread goal record. */
72
+ export function goalModel(goal, conv, o = {}) {
73
+ if (!goal || !goal.draft || !['started', 'waiting'].includes(goal.state)) return null;
74
+ const d = goal.draft, pts = Array.isArray(d.done) ? d.done : [], met = new Set(goal.met || []);
75
+ const skip = new Set(goal.skipped || []);
76
+ const count = pts.filter((x) => !skip.has(x)).length;
77
+ const cur = pts.findIndex((x) => !met.has(x) && !skip.has(x));
78
+ const limit = Number.isInteger(d.limit) ? d.limit : 12;
79
+ const asking = goal.state === 'waiting' || !!o.asking;
80
+ const run = running(conv) || goal.state === 'started';
81
+ // skip (the goal-setup workstream's presses): × on a point not met, not skipped, not the current one and never the last one left;
82
+ // Undo while the skip is newer than the last round, after that the row only says so
83
+ const left = pts.filter((x) => !met.has(x) && !skip.has(x)).length;
84
+ const at = (p) => Date.parse((goal.skipAt || {})[p] || ''), round = Date.parse(goal.roundAt || '');
85
+ const undo = (p) => Number.isFinite(at(p)) && (!Number.isFinite(round) || at(p) > round);
86
+ const all = pts.map((x, i) => {
87
+ const st = met.has(x) ? 'done' : skip.has(x) ? 'skip' : i === cur && run && !asking ? 'now' : 'next';
88
+ const sub = st === 'done' ? 'met' : st === 'skip' ? (undo(x) ? 'Skipped by you · Claude drops it after this step' : 'Skipped by you') : i === cur && !asking ? 'now · Stop or tell Claude to skip it' : '';
89
+ const act = st === 'skip' && undo(x) ? { attr: `data-goal-unskip="${esc(x)}"`, icon: 'undo', label: 'Undo the skip' }
90
+ : st === 'next' && i !== cur && left > 1 ? { attr: `data-goal-skip="${esc(x)}"`, icon: 'x', label: 'Skip this point' } : null;
91
+ return { text: x, state: st, sub, act };
92
+ });
93
+ const w = window5(all, cur, o.all);
94
+ const nMet = pts.filter((x) => met.has(x)).length;
95
+ return {
96
+ kind: 'goal', icon: asking ? 'none' : 'spin', tone: asking ? 'you' : '',
97
+ text: asking ? 'Claude asks before it goes on' : cur >= 0 ? pts[cur] : d.goal || 'Goal',
98
+ count: asking ? '' : `${nMet} of ${count} done`, clock: '',
99
+ title: d.goal || 'Goal',
100
+ head: `${nMet} of ${count} points met · round ${Math.max(1, (goal.rounds || 0) + 1)} of ${limit}${d.by ? ' · due ' + d.by : ''} · Claude checks its own points`,
101
+ items: w.items, more: w.more, now: run ? nowCall(conv) : '', term: !!o.term,
102
+ open: !!o.open, on: !!o.on, frac: count ? nMet / count : 0,
103
+ };
104
+ }
105
+
106
+ /** A running session as the line's model: its own step list (TodoWrite) when it wrote one, else the clock only. */
107
+ export function sessionModel(conv, o = {}) {
108
+ if (!running(conv) && !(o.asking && conv && conv.state !== 'ended')) return null;
109
+ const steps = Array.isArray(conv.steps) && conv.steps.length ? conv.steps : null;
110
+ const asking = !!o.asking;
111
+ const clock = clockOf(conv, o.now);
112
+ if (!steps) {
113
+ return { kind: 'session', icon: asking ? 'none' : 'spin', tone: asking ? 'you' : '', text: asking ? 'Claude asks before it goes on' : 'Working', clock: asking ? '' : clock, count: '',
114
+ title: o.title || 'Working', head: '', items: [], more: 0, now: running(conv) ? nowCall(conv) : '', term: !!o.term, open: !!o.open, on: !!o.on, frac: 0, plain: true };
115
+ }
116
+ const cur = steps.findIndex((s) => s.state === 'now');
117
+ const done = steps.filter((s) => s.state === 'done').length;
118
+ const all = steps.map((s) => ({ text: s.text, state: s.state === 'done' ? 'done' : s.state === 'now' && !asking ? 'now' : 'next', sub: s.sub || '', code: s.state === 'now' ? s.call || '' : '' }));
119
+ const w = window5(all, cur, o.all);
120
+ return {
121
+ kind: 'session', icon: asking ? 'none' : 'spin', tone: asking ? 'you' : '',
122
+ text: asking ? 'Claude asks before it goes on' : cur >= 0 ? steps[cur].text : 'Working',
123
+ count: asking ? '' : `${done} of ${steps.length} done`, clock: '',
124
+ title: o.title || 'Steps', head: `${done} of ${steps.length} done${clock ? ' · ' + clock : ''}`,
125
+ items: w.items, more: w.more, now: cur >= 0 && steps[cur].call ? '' : nowCall(conv), term: !!o.term,
126
+ open: !!o.open, on: !!o.on, frac: steps.length ? done / steps.length : 0,
127
+ };
128
+ }
129
+
130
+ const STATE = { done: 'done', now: 'run', next: 'wait', skip: 'skip' };
131
+ function listHtml(m, label) {
132
+ const steps = m.items.map((x) => ({ state: STATE[x.state] || 'wait', label: x.text, note: x.sub || '', code: x.code || '',
133
+ owner: x.avatar ? { kind: 'person', initials: x.avatar.initial, name: x.avatar.name } : null, act: x.act || null }));
134
+ return stepsHtml(steps, { label, cls: 'pl-sl', more: m.more ? { n: m.more, attr: 'data-pl="all"', label: 'Show all ' + m.more } : null });
135
+ }
136
+ const nowRow = (m) => (m.now ? `<p class="pl-now">${spinHtml(14)}<b>Now</b><code>${esc(m.now)}</code></p>` : '');
137
+ const leadOf = (m) => (m.icon === 'spin' ? spinHtml(16) : m.icon === 'clock' ? `<span class="pl-clk">${SVG(P.clock, 16, 2)}</span>` : m.tone === 'you' ? '<i class="pl-dot" aria-hidden="true"></i>' : '');
138
+
139
+ /** The line. Folded: one row; open: the head line, the items, the Now row and Watch its terminal. */
140
+ export function lineHtml(m) {
141
+ if (!m) return '';
142
+ ensureCss();
143
+ const tail = m.count ? `<span class="pl-n">${esc(m.count)}</span>` : m.clock ? `<span class="pl-n">${esc(m.clock)}</span>` : '';
144
+ const text = m.clock && !m.count && m.icon !== 'none' ? m.text + ' · ' + m.clock : m.text;
145
+ const say = [m.open ? m.title : text, m.count].filter(Boolean).join(', ');
146
+ const stop = `<button type="button" class="pl-stop" data-pl="stop" aria-label="${esc(m.stopLabel || 'Stop')}" title="${esc(m.stopLabel || 'Stop')}">${STOP_SQ}</button>`;
147
+ const row = `<div class="pl-row"><button type="button" class="pl-hit" data-pl="toggle" aria-expanded="${!!m.open}" aria-label="${esc(say)}">${leadOf(m)}`
148
+ + `<span class="pl-t">${esc(m.open && m.kind === 'goal' ? m.title : text)}</span>${m.open ? '' : (m.clock && !m.count ? '' : tail)}<span class="pl-cv">${SVG(m.open ? P.up : P.down, 14, 2.2)}</span></button>${stop}</div>`;
149
+ const body = m.open && m.tone !== 'you' ? `<div class="pl-body">${m.head ? `<p class="pl-head">${esc(m.head)}</p>` : ''}${m.items.length ? listHtml(m, m.kind === 'goal' ? 'The goal’s points' : 'Steps') : ''}${nowRow(m)}`
150
+ + (m.term ? `<div class="pl-acts"><button type="button" class="pl-ib" data-pl="term" aria-label="Watch its terminal" title="Watch its terminal">${SVG(P.term, 18, 1.8)}</button></div>` : '') + '</div>' : '';
151
+ const cls = ['hm-pl', m.tone === 'you' ? 'you' : '', m.open ? 'open' : '', m.on ? 'on' : '', m.plain ? 'plain' : ''].filter(Boolean).join(' ');
152
+ return `<div class="${cls}" role="status" data-kind="${esc(m.kind || '')}">${row}${body}</div>`;
153
+ }
154
+
155
+ /** The steps in the Viewer (a desktop): the head line, every item, the Now row; Stop and the terminal as icons. */
156
+ export function viewHtml(m) {
157
+ if (!m) return '';
158
+ ensureCss();
159
+ return `<div class="vwdoc pl-vw"><div class="pl-vwh"><b>${esc(m.title)}</b><button type="button" class="pl-stop" data-pl="stop" aria-label="${esc(m.stopLabel || 'Stop')}" title="${esc(m.stopLabel || 'Stop')}">${STOP_SQ}</button></div>`
160
+ + (m.head ? `<p class="pl-head">${esc(m.head)}</p>` : '')
161
+ + (m.items.length ? listHtml({ ...m, more: 0 }, m.kind === 'goal' ? 'The goal’s points' : 'Steps') : '') + nowRow(m)
162
+ + (m.term || m.change ? `<div class="pl-acts">${m.term ? `<button type="button" class="pl-ib" data-pl="term" aria-label="Watch its terminal" title="Watch its terminal">${SVG(P.term, 18, 1.8)}</button>` : ''}`
163
+ // m.change: the pencil that opens the plan editor for a working goal (home-goal.js; the change applies after the current step)
164
+ + `${m.change ? `<button type="button" class="pl-ib" data-goal="change" aria-label="Change the plan" title="Change the plan">${SVG('M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4', 18, 1.8)}</button>` : ''}</div>` : '') + '</div>';
165
+ }
166
+
167
+ /** The quiet line where a run finished: "Goal done" (a check), or in amber why it stopped. A tap opens what it holds. */
168
+ export function dividerHtml(d) {
169
+ if (!d || !d.text) return '';
170
+ ensureCss();
171
+ const ico = d.tone === 'ok' ? `<span class="pl-dk">${SVG(P.check, 12, 2.8)}</span>` : '';
172
+ const label = d.attr ? `<button type="button" class="pl-dvb" ${d.attr}>${ico}<span>${esc(d.text)}</span>${SVG(P.down, 12, 2.2)}</button>` : `<span class="pl-dvb">${ico}<span>${esc(d.text)}</span></span>`;
173
+ const acts = (d.actions || []).length ? `<div class="pl-dva">${d.actions.map((a, i) => `<button type="button" class="pl-ib${i === 0 ? ' pri' : ''}" ${a.data || ''} aria-label="${esc(a.label)}" title="${esc(a.label)}">${SVG(a.icon, 16, 2)}</button>`).join('')}</div>` : '';
174
+ return `<div class="pl-dv ${d.tone === 'ok' ? 'ok' : 'stop'}" role="separator" aria-label="${esc(d.text)}"><span class="ln"></span>${label}<span class="ln"></span></div>${acts}`;
175
+ }
176
+ const WHY = { deadline: 'the deadline passed', limit: 'it used all its rounds', 'no-progress': 'three rounds met no new point', pm: 'you stopped it', replaced: 'replaced' };
177
+ /** A done or stopped goal's divider, else null. */
178
+ export function goalDivider(goal) {
179
+ if (!goal || !goal.draft) return null;
180
+ if (goal.state === 'done') return { tone: 'ok', text: 'Goal done', attr: 'data-goal-open' };
181
+ if (goal.state === 'stopped') return { tone: 'stop', text: 'Goal stopped: ' + (WHY[goal.reason] || 'it stopped'), attr: 'data-goal-open' };
182
+ return null;
183
+ }
184
+ /** "Stopped at 2 of 4": a session's step list with steps left, once its run ended. '' when it wrote none or finished them all. */
185
+ export function stepsStop(conv) {
186
+ const s = conv && Array.isArray(conv.steps) ? conv.steps : [];
187
+ if (!s.length) return '';
188
+ const done = s.filter((x) => x.state === 'done').length;
189
+ return done < s.length ? `Stopped at ${done} of ${s.length}` : '';
190
+ }
191
+
192
+ /** A Home row's ring: it fills as the points or steps are met, with no number; with no list, the plain running ring. */
193
+ export function ringHtml(p, label = 'Running') {
194
+ ensureCss();
195
+ const n = p && p.n > 0 ? p.n : 0, f = n ? Math.max(0, Math.min(1, (p.done || 0) / n)) : 0;
196
+ if (!n) return `<span class="hv-d run" role="img" aria-label="${esc(label)}"></span>`;
197
+ const r = 5, c = 2 * Math.PI * r; // the size of the plain ring's row mark, so a row does not jump when its list appears
198
+ return `<svg class="hv-ring" role="img" aria-label="${esc(label + ', ' + (p.done || 0) + ' of ' + n + ' done')}" width="12" height="12" viewBox="0 0 12 12"><circle cx="6" cy="6" r="${r}" class="bg"/><circle cx="6" cy="6" r="${r}" class="fg" stroke-dasharray="${(c * f).toFixed(2)} ${c.toFixed(2)}" transform="rotate(-90 6 6)"/></svg>`;
199
+ }
200
+ export { nodeHtml };