create-pmos 0.440.0 → 0.441.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 (51) hide show
  1. package/package.json +13 -13
  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 +16 -13
  7. package/workspace/briefing-premium-products-test.js +4 -4
  8. package/workspace/briefing-premium-sources-test.js +2 -2
  9. package/workspace/briefing-premium-test.js +29 -23
  10. package/workspace/changelog.json +12 -0
  11. package/workspace/guide/core-documents.md +2 -2
  12. package/workspace/guide/data-freshness.md +7 -5
  13. package/workspace/guide/home.md +1 -1
  14. package/workspace/guide/horizon-scan.md +1 -1
  15. package/workspace/lib/agent-inbox.js +20 -2
  16. package/workspace/lib/briefing-premium-sources.js +3 -0
  17. package/workspace/lib/briefing-premium.js +37 -7
  18. package/workspace/lib/driver-cli.js +1 -1
  19. package/workspace/lib/driver-run.js +15 -1
  20. package/workspace/lib/driver.js +31 -2
  21. package/workspace/lib/news-for-you.js +24 -9
  22. package/workspace/lib/pm-idle.js +12 -0
  23. package/workspace/lib/refresh.js +17 -8
  24. package/workspace/lib/routes-core-docs.js +1 -1
  25. package/workspace/lib/routes-news.js +15 -1
  26. package/workspace/lib/routes-phone-day.js +6 -4
  27. package/workspace/need-shot.js +57 -0
  28. package/workspace/news-viewers-test.js +183 -0
  29. package/workspace/package-lock.json +2 -2
  30. package/workspace/package.json +1 -1
  31. package/workspace/premium-core-doc-issue-test.js +9 -8
  32. package/workspace/public/pm/bd-ini-panel.js +4 -11
  33. package/workspace/public/pm/cozy-ev.css +29 -0
  34. package/workspace/public/pm/cozy-news.js +186 -22
  35. package/workspace/public/pm/cozy-today.css +5 -0
  36. package/workspace/public/pm/cozy-viewer.js +4 -3
  37. package/workspace/public/pm/cozy-vw-shell.css +49 -0
  38. package/workspace/public/pm/home-adddoc.js +46 -26
  39. package/workspace/public/pm/home-app.js +134 -112
  40. package/workspace/public/pm/home-day.js +10 -5
  41. package/workspace/public/pm/home-draft.js +35 -23
  42. package/workspace/public/pm/home-ini.js +2 -2
  43. package/workspace/public/pm/home-need.js +336 -0
  44. package/workspace/public/pm/home-today.js +2 -2
  45. package/workspace/public/pm/home-work.js +51 -4
  46. package/workspace/public/pm/small-vw.js +128 -0
  47. package/workspace/server.js +10 -6
  48. package/workspace/skills/initiative-drive.skill +4 -1
  49. package/workspace/test-lists/batch18-asks.json +5 -0
  50. package/workspace/test-lists/news-viewers.json +13 -0
  51. package/workspace/test-lists/small-viewers.json +5 -0
@@ -1,10 +1,11 @@
1
- /* home-draft.js — a core document's draft, read in Home's Viewer, with Issue it (premium-agreed-design; initiative premium-core-doc-issue).
2
- * Drawn in the Viewer's card shape (canvas HmMyWork: the title, the line under it, the chips, the foot): the Issue it bar above the text,
3
- * Read and Edit. Edit is the document page's own editor (premium-vw-doc.js, ctx.host), so a save goes through POST /api/doc-sheet/edit as everywhere else.
1
+ /* home-draft.js — a core document's draft, read in Home's Viewer, with Issue it (premium-agreed-design; initiative premium-core-doc-issue;
2
+ * batch 18 item 2-C, canvas OvA9Docs). Shell A: the title, "A draft · <initiative>" under it, ✎ Edit in the header (pressed while editing,
3
+ * in place of the old Read | Edit tabs), ⋯ Copy path (the path is not in the body). The summary waits for you to read, with Issue it the one
4
+ * primary, above the text. Edit is the document page's own editor (premium-vw-doc.js, ctx.host), so a save goes through POST /api/doc-sheet/edit as everywhere else.
4
5
  * Issue it posts POST /api/core-docs/issue { ws, scope, key, slot } and nothing else: it marks the draft issued and sends nothing to anyone.
5
6
  * Issue it is refused here while the editor holds typed text that is not saved.
6
7
  *
7
- * openDraftVw({ VW, pmGet, pmPost, toast, ws, scope, doc, onIssued })
8
+ * openDraftVw({ VW, pmGet, pmPost, toast, ws, scope, doc, iniTitle?, onIssued })
8
9
  * doc the docs row: { key, title, path, slot, st, state }
9
10
  * onIssued awaited after the route answers ok (the page reads again)
10
11
  */
@@ -12,20 +13,22 @@ import { mdHtml } from './premium-doc-edit.js';
12
13
 
13
14
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
14
15
 
16
+ const PEN = 'M4 20h4L19 9l-4-4L4 16zM14 6l4 4', COPY = 'M8 8h11v12H8zM5 16V4h11';
17
+
15
18
  export function openDraftVw(o) {
16
- const d = o.doc;
19
+ const d = o.doc, VW = o.VW;
17
20
  const X = { tab: 'read', text: null, err: '', issued: d.st !== 'draft', dirty: false, busy: false, msg: '' };
18
21
  const wsq = () => (o.ws ? '&ws=' + encodeURIComponent(o.ws) : '');
22
+ const id = 'draft:' + o.scope + ':' + d.key;
19
23
  let body = null;
20
- const bar = () => (X.issued
21
- ? '<div class="hm-iss done" data-issue-bar="done" role="status"><span>Issued. Nothing was sent to anyone.</span></div>'
22
- : `<div class="hm-iss" data-issue-bar="draft"><span>A draft. Nothing is sent: issuing marks it issued and sends nothing to anyone.</span><button type="button" class="hx-b pri" data-ds="issue"${X.busy ? ' disabled' : ''}>Issue it</button></div>`);
24
+ const sum = () => (X.issued
25
+ ? `<div data-issue-bar="done" role="status">${VW.czSummary({ line: 'Issued', tone: 'ok', text: 'Nothing was sent to anyone.' })}</div>`
26
+ : `<div data-issue-bar="draft">${VW.czSummary({ line: 'Waits for you to read', tone: 'you', text: 'When it reads right, issue it. Issuing marks it issued and sends nothing to anyone.', primary: { label: 'Issue it', act: 'issue', disabled: X.busy } })}</div>`);
27
+ const presses = () => [{ act: 'edit', label: X.tab === 'edit' ? 'Back to reading' : 'Edit the draft', icon: PEN, pressed: X.tab === 'edit' }];
23
28
  const draw = () => {
24
29
  if (!body) return;
25
- const tabs = `<div class="hx-tabs ut-chips" role="tablist" aria-label="Draft">${[['read', 'Read'], ['edit', 'Edit']].map(([k, l]) => `<button type="button" class="cz-chip${X.tab === k ? ' on' : ' gh'}" role="tab" aria-selected="${X.tab === k}" aria-pressed="${X.tab === k}" data-ds="${k}">${l}</button>`).join('')}</div>`;
26
30
  const text = X.text == null ? `<p class="hx-n">${esc(X.err || 'Reading the draft.')}</p>` : `<div class="dsbody hm-md">${mdHtml(X.text).html}</div>`;
27
- body.innerHTML = `<div class="ut-vc"><div><h2 class="ut-h2">${esc(d.title || 'Draft')}</h2><p class="ut-sub">${esc(d.path)}</p></div>` + bar() + `<p class="hx-n" id="dsErr" role="alert">${esc(X.msg)}</p>` + tabs
28
- + (X.tab === 'read' ? text : '<div class="hm-dsed" data-ds-host></div>') + '</div>';
31
+ body.innerHTML = sum() + `<p class="czf-err" id="dsErr" role="alert">${esc(X.msg)}</p>` + (X.tab === 'read' ? text : '<div class="hm-dsed" data-ds-host></div>');
29
32
  if (X.tab === 'edit') mountEditor();
30
33
  };
31
34
  async function read() {
@@ -42,19 +45,18 @@ export function openDraftVw(o) {
42
45
  host.addEventListener('input', () => { X.dirty = true; });
43
46
  host.addEventListener('keydown', (e) => { if (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Enter') X.dirty = true; });
44
47
  const M = await import('./premium-vw-doc.js');
45
- M.openDocPage({ path: d.path, title: d.title }, { host, ws: () => o.ws || '', onWrite: async () => { X.dirty = false; await read(); }, onClose: () => { X.dirty = false; X.tab = 'read'; draw(); } });
48
+ M.openDocPage({ path: d.path, title: d.title }, { host, ws: () => o.ws || '', onWrite: async () => { X.dirty = false; await read(); }, onClose: () => { X.dirty = false; tab('read'); } });
49
+ }
50
+ const say = (m) => { X.msg = m; const e = body.querySelector('#dsErr'); if (e) e.textContent = m; };
51
+ /** ✎ in the header: Edit, and pressed again, back to reading (refused while the editor holds typed text that is not saved) */
52
+ function tab(k) {
53
+ if (k === X.tab) return;
54
+ if (k === 'read' && X.dirty) { say('You have unsaved changes in Edit. Save or cancel them there.'); return; } // leaving Edit would drop the typed text
55
+ X.msg = ''; X.tab = k; if (VW.setPresses) VW.setPresses(id, presses()); draw(); if (k === 'read') read();
46
56
  }
47
- body = o.VW.open({ id: 'draft:' + o.scope + ':' + d.key, kind: 'Draft · ' + (d.state || 'Draft'), title: d.title, icon: 'doc', render: (b) => { body = b; draw(); } });
48
- body.onclick = async (e) => {
49
- const b = e.target.closest('[data-ds]'); if (!b || !body.contains(b)) return;
50
- const k = b.dataset.ds;
51
- if (k === 'read' || k === 'edit') {
52
- if (k === X.tab) return;
53
- if (k === 'read' && X.dirty) { X.msg = 'You have unsaved changes in Edit. Save or cancel them there.'; body.querySelector('#dsErr').textContent = X.msg; return; } // leaving Edit would drop the typed text
54
- X.msg = ''; X.tab = k; draw(); if (k === 'read') read(); return;
55
- }
56
- if (k !== 'issue') return;
57
- if (X.dirty) { X.msg = 'This draft has unsaved changes. Save or cancel them first, then issue it.'; body.querySelector('#dsErr').textContent = X.msg; return; }
57
+ async function issue() {
58
+ if (X.issued || X.busy) return;
59
+ if (X.dirty) { say('This draft has unsaved changes. Save or cancel them first, then issue it.'); return; }
58
60
  X.busy = true; X.msg = ''; draw();
59
61
  const r = await o.pmPost('/api/core-docs/issue', { ws: o.ws, scope: o.scope, key: d.key, slot: d.slot });
60
62
  X.busy = false;
@@ -62,6 +64,16 @@ export function openDraftVw(o) {
62
64
  X.issued = true; draw();
63
65
  o.toast('Issued. Nothing was sent to anyone.');
64
66
  if (o.onIssued) await o.onIssued();
67
+ }
68
+ body = VW.open({ id, kind: 'Draft · ' + (d.state || 'Draft'), title: d.title, sub: 'A draft' + (o.iniTitle ? ' · ' + o.iniTitle : ''), icon: 'doc',
69
+ presses: presses(), onPress: (a) => { if (a === 'edit') tab(X.tab === 'edit' ? 'read' : 'edit'); },
70
+ more: [{ label: 'Copy path', icon: COPY, on: () => copy() }],
71
+ render: (b) => { body = b; draw(); } });
72
+ async function copy() {
73
+ try { await navigator.clipboard.writeText(d.path); o.toast('Path copied.'); } catch { o.toast('The path was not copied: ' + d.path); }
74
+ }
75
+ body.onclick = (e) => {
76
+ const b = e.target.closest('[data-czs-act="issue"]'); if (b && body.contains(b)) issue();
65
77
  };
66
78
  read();
67
79
  return body;
@@ -598,7 +598,7 @@ function wire(body, id) {
598
598
  if (/^(draft|open):/.test(d.czsAct || '')) {
599
599
  const key = d.czsAct.slice(d.czsAct.indexOf(':') + 1), doc = (M.docs.rows || []).find((x) => x.key === key); if (!doc) return;
600
600
  if (d.czsAct.startsWith('draft:')) { after(await X.ctx.pmPost('/api/core-docs/draft', { ws: M.board.ws, scope: M.docs.scope, key }), 'The draft started. It waits for you to read.'); return; }
601
- if (doc.path && doc.st === 'draft' && doc.slot) { const A = await import('./home-draft.js'); A.openDraftVw({ VW: X.ctx.VW, pmGet: X.ctx.pmGet, pmPost: X.ctx.pmPost, toast: X.ctx.toast, wait: X.ctx.wait || '', ws: M.board.ws, scope: M.docs.scope, doc, onIssued: () => X.ctx.load() }); return; }
601
+ if (doc.path && doc.st === 'draft' && doc.slot) { const A = await import('./home-draft.js'); A.openDraftVw({ VW: X.ctx.VW, pmGet: X.ctx.pmGet, pmPost: X.ctx.pmPost, toast: X.ctx.toast, wait: X.ctx.wait || '', ws: M.board.ws, scope: M.docs.scope, doc, iniTitle: X.ctx.iniTitle(id), onIssued: () => X.ctx.load() }); return; }
602
602
  X.ctx.openFile({ path: doc.path, name: doc.title }); return;
603
603
  }
604
604
  if ('hiDby' in d) { menu(t, Object.entries(MD.DOC_BY).map(([k, l]) => ({ label: l, radio: true, on: X.doc.by === k, go: () => { X.doc.by = k; redrawView(); } })), 'Group documents by'); return; }
@@ -618,7 +618,7 @@ function wire(body, id) {
618
618
  if (d.ovDread) {
619
619
  const doc = (M.docs.rows || []).find((x) => x.key === d.ovDread); if (!doc) return;
620
620
  const A = await import('./home-draft.js');
621
- A.openDraftVw({ VW: X.ctx.VW, pmGet: X.ctx.pmGet, pmPost: X.ctx.pmPost, toast: X.ctx.toast, wait: X.ctx.wait || '', ws: M.board.ws, scope: M.docs.scope, doc, onIssued: () => X.ctx.load() });
621
+ A.openDraftVw({ VW: X.ctx.VW, pmGet: X.ctx.pmGet, pmPost: X.ctx.pmPost, toast: X.ctx.toast, wait: X.ctx.wait || '', ws: M.board.ws, scope: M.docs.scope, doc, iniTitle: X.ctx.iniTitle(id), onIssued: () => X.ctx.load() });
622
622
  return;
623
623
  }
624
624
  if ('ovAdddoc' in d) { addDoc(id); return; }
@@ -0,0 +1,336 @@
1
+ /* pm/home-need.js — the asks in the Viewer: every row of Home that waits on the PM (batch 18 item 2-A, canvas In development OvA1Start,
2
+ * OvA1After, OvA2Decide, OvA3Waited, OvA4Source, OvA11Dark, OvA12Edges, OvA10Desk).
3
+ *
4
+ * One pattern for every kind (start / blocked, decision, waited, source, agent drafts):
5
+ * header ← · tile · the thing's name (two lines at most) · Pin (aria-pressed) · Put off (Later today / Tomorrow / Next week) · ⋯
6
+ * (Open the record, Open on the Board, Copy link). A source row has Pin only: the server refuses to put it off.
7
+ * body the summary card: the state line, ✦ Claude's offer, the amber "If it waits" line when the row has one, ONE primary verb;
8
+ * then one quiet owner line (whose it is, the kind of work in words, the goal it moves); then the folds.
9
+ * No ids, lane codes, anchors or file paths in the body: the record's path is under ⋯.
10
+ * after a press that starts an agent keeps the same card: what it does now, its steps, Stop and its chat; then the result.
11
+ * edges no next step on record → "Find the next step"; a source the brief could not read → why, and sign in again; the row left Home
12
+ * while it was open (someone else did it) → says so, and Done.
13
+ *
14
+ * needModel(r, ctx) → { title, sub, icon, line, tone, right, text, offer, cost, meta, primary, also, owner, sections, pin, later } PURE
15
+ * plainStep(next) → { say, label, doing } | null the next step on record in plain words, its verb press and its "-ing" line PURE
16
+ * openNeed(r, h) draws it in the Viewer. h: { VW, P, esc, svg, pinned(key), togglePin(key), putOff(key, until), menu(anchor, items),
17
+ * start(r) → Promise<{ ok, session?, error? }>, sessions(), stopSession(sid), openSession(sid), ask(r, text),
18
+ * decide(r, choice, why) → Promise<{ ok, error? }>, openReturn(item), goIni(id), boardHref(r), recordHref(r),
19
+ * linkOf(r), toast(m), signIn(), rowGone(key) }
20
+ * refresh() draws the open ask again when its phase changed (a run finished, the row left Home); called after each read. */
21
+
22
+ const STEP_WORD = { spec: 'the spec', prototype: 'the prototype', contract: 'the agreed done-criteria', anchor: 'the goal it moves', route: 'its lane', brief: 'the problem brief', prd: 'the PRD', rubric: 'the rubric' };
23
+ const STEP_AT = { spec: 'the spec', prototype: 'the prototype', contract: 'the contract', anchor: 'the goal', route: 'routing' };
24
+ export const LANE_WORD = { feature: 'New feature', discovery: 'Discovery', chore: 'Upkeep', incident: 'Incident', content: 'Content', prototype: 'Prototype' };
25
+ const SRC_ICON = { Mail: 'M3.5 6h17v12h-17zM4 7l8 6 8-6', Jira: 'M4 4h16v16H4zM8.5 12.5l2.5 2.5 4.5-5', Slack: 'M9 3v18M15 3v18M3 9h18M3 15h18' };
26
+ const ICON = { goal: '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', warn: 'M12 3l9 16H3zM12 10v4M12 17h.01', doc: 'M7 3h7l5 5v13H7zM14 3v5h5', gate: 'M12 3l7 3v6c0 4-3 7-7 9-4-2-7-5-7-9V6z' };
27
+ export const OUT = 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6';
28
+ const CHEV = 'M10 7l5 5-5 5', CHAT = 'M4 5h16v11H9l-5 4z', STOP = 'M6 6l12 12M18 6L6 18', CHECK = 'M5 12l5 5 9-10', SPARK = 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z';
29
+
30
+ const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
31
+ const cap = (s) => (s ? s[0].toUpperCase() + s.slice(1) : s);
32
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
33
+ /** Plain words: no file paths, no decision ids (D13), no frontmatter keys (prd_path), no parentheses that hold either. */
34
+ export function noPaths(s) {
35
+ return String(s == null ? '' : s)
36
+ .replace(/\s*\((?:[^()]*\/[^()]*|D\d+[^()]*|skills?[^()]*|R\d+|O\d+)\)/g, '')
37
+ .replace(/\bpm-decisions\.md\b/g, 'the decision journal')
38
+ .replace(/`[^`]*`/g, 'the record')
39
+ .replace(/\b[\w.-]*\/[\w./-]+/g, 'the record')
40
+ .replace(/\b[\w-]+\.(md|js|json|jsonl|ya?ml|skill)\b/g, 'the record')
41
+ .replace(/\b[a-z]+_[a-z_]+\b/g, '')
42
+ .replace(/\s+([,.;:])/g, '$1').replace(/,\s*,/g, ',').replace(/\s{2,}/g, ' ').trim();
43
+ }
44
+ const VERB = /^(do|review|read|author|write|create|draft|run|land|name|point|set|add|agree|anchor|route|split|move|declare|fix|correct|scope|record|pick|choose|link|open|start|state|give|put)\b/i;
45
+ const ING = { do: 'Doing', author: 'Drafting', write: 'Drafting', create: 'Drafting', draft: 'Drafting', run: 'Running', set: 'Setting', put: 'Putting', split: 'Splitting', scope: 'Scoping', pick: 'Picking', state: 'Stating', give: 'Giving', agree: 'Agreeing on', move: 'Moving', declare: 'Declaring', name: 'Naming', route: 'Routing', anchor: 'Anchoring', choose: 'Choosing' };
46
+ const ingOf = (v) => ING[v] || (/e$/.test(v) ? cap(v.slice(0, -1)) + 'ing' : cap(v) + 'ing');
47
+ /** The next step on record, in plain words: say ("draft the PRD with its done-criteria"), label (the press: "Draft the PRD"), doing
48
+ * ("Drafting the PRD"). The record's sentence is the source: nothing is added to it, its paths and ids are dropped. null when empty. */
49
+ export function plainStep(next) {
50
+ let s = String(next == null ? '' : next).split(/\s[—–]\s/)[0];
51
+ const parts = s.split(/(?<=[.;])\s+/).map((x) => x.trim()).filter(Boolean);
52
+ s = parts.find((x) => VERB.test(x)) || parts[0] || '';
53
+ s = s.replace(/,?\s*(then|and)\s+(set|point|correct|clear)\s+[\s\S]*$/i, '');
54
+ s = noPaths(s).replace(/\s+in\s+the record$/i, '').replace(/[.;:,\s]+$/, '');
55
+ if (!s) return null;
56
+ const m = /^(\w+)\s*(.*)$/.exec(s), v = m[1].toLowerCase(), rest = m[2];
57
+ const verb = ['author', 'write', 'create'].includes(v) ? 'draft' : v;
58
+ const say = verb + (rest ? ' ' + rest : '');
59
+ const obj = rest.split(/\s+(?:with|in|so|or|before|after|from|first|then|to|for|at)\b|[,;]/i)[0].trim().split(/\s+/).slice(0, 5).join(' ');
60
+ if (!VERB.test(v) || !obj) return { say, label: 'Start it', doing: 'Working on it' };
61
+ return { say, label: cap(verb) + ' ' + obj, doing: ingOf(v) + ' ' + obj };
62
+ }
63
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
64
+ const dayOf = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : String(iso || ''); };
65
+ const initials = (n) => { const t = String(n || '').replace(/^pm:/, '').trim(); return t ? t[0].toUpperCase() : ''; };
66
+ const isPm = (o) => !o || /^pm(:|$)/i.test(String(o));
67
+ const goalWords = (g) => (!g || !g.title ? '' : g.kind === 'health' ? 'keeps ' + g.title + ' healthy' : 'moves ' + g.title);
68
+ /** "If you skip: …" on the record becomes the amber line: "If it waits: …". */
69
+ const costOf = (skip) => { const m = /^If you skip:\s*(.+)$/.exec(String(skip || '')); return m ? 'If it waits: ' + m[1] : ''; };
70
+ /** Why a step blocks, in words, from the rule the step enforces (scripts/workflow-state.js). */
71
+ function whyBlocked(step, rule, lane) {
72
+ if (/^O[12]$/.test(rule || '')) return 'The build was committed before its spec. The spec has to come first, so the order check keeps failing until it does.';
73
+ if (step === 'spec') return lane === 'chore' ? 'Upkeep needs one paragraph that says what it is for before it starts.' : 'A ' + (LANE_WORD[lane] || 'piece of work').toLowerCase() + ' needs its spec before the build: what the problem is, who has it, and how we will know it worked.';
74
+ if (step === 'prototype') return 'This idea needs a prototype people can look at before a PRD says what to build.';
75
+ if (step === 'contract') return 'The run needs its done-criteria agreed before it starts, so there is something to check it against.';
76
+ if (step === 'anchor') return 'Every initiative names the goal it moves. Work with no goal is turned away.';
77
+ if (step === 'route') return 'The initiative needs its lane, so the right rules run on it.';
78
+ return 'The ' + step + ' step is not done yet.';
79
+ }
80
+ const lineOf = (step, rule) => (/^O[12]$/.test(rule || '') ? 'Blocked: ' + (STEP_WORD[step] || 'the ' + step) + ' came after the build'
81
+ : /^O3$/.test(rule || '') ? 'Blocked: the prototype has to come first' : 'Blocked: ' + (STEP_WORD[step] || 'the ' + step + ' step') + ' is missing');
82
+ /** A fact the PM can read: the facts a row carries, without ids, records, anchors and lanes (those are under ⋯ or said in words). */
83
+ const plainFacts = (rows) => (rows || []).filter((x) => x && x[1] && !/^(initiative|record|anchor|lane|source|ticket|run|confidence|reply needed|product)$/i.test(String(x[0]))).map(([k, v]) => [k, noPaths(v)]).filter((x) => x[1]);
84
+ const factsHtml = (rows, esc) => (rows.length ? `<dl class="nv-facts">${rows.map(([k, v]) => `<div><dt>${esc(k)}</dt><dd>${esc(v)}</dd></div>`).join('')}</dl>` : '');
85
+
86
+ /** The model of one ask. ctx: { esc, run (the agent this ask started: { label, doing, state: 'running'|'ready', done?, n? }), gone (the row
87
+ * left Home while it was open), choice, why, pickedRec } */
88
+ export function needModel(r, ctx = {}) {
89
+ const esc = ctx.esc || ((s) => String(s));
90
+ const row = r.row || {}, d = row.dialog || {}, w = d.write || {}, det = row.detail || {}, kind = row.kind;
91
+ const name = det.title || (kind === 'waited' ? '' : clip(String(row.subject || '').split(' · ')[0], 120)) || r.name;
92
+ const m = { kind, title: name, sub: '', icon: ICON.goal, line: '', tone: '', right: '', text: '', offer: '', cost: '', meta: '', primary: null, also: [], owner: null, sections: [], pin: true, later: true };
93
+ const owner = (pre) => {
94
+ const bits = [pre, LANE_WORD[det.lane] || '', goalWords(det.goal)].filter(Boolean);
95
+ // a face only for someone on record, or the PM's own unblock (the ask is on the PM's Home)
96
+ return bits.length ? { av: det.owner ? (isPm(det.owner) ? 'pm' : initials(det.owner)) : pre ? 'pm' : '', text: bits.join(' · ') } : null;
97
+ };
98
+ if (ctx.gone) {
99
+ m.line = kind === 'blocked' ? 'Unblocked' : kind === 'decision' ? 'Decided' : 'Done'; m.tone = 'ok';
100
+ m.text = (kind === 'blocked' ? 'The step was done outside this card' : kind === 'decision' ? 'A decision is on record now' : 'It was handled outside this card') + '. Nothing is left for you here.';
101
+ m.also = [{ act: 'done', label: 'Done', icon: CHECK }];
102
+ m.pin = false; m.later = false;
103
+ if (kind === 'waited') m.title = r.name;
104
+ return m;
105
+ }
106
+ if (kind === 'blocked') {
107
+ const step = det.step || '', st = w.kind === 'start' ? plainStep(w.what || det.next) : null;
108
+ m.owner = owner(isPm(det.owner) ? 'Yours to unblock' : clip(String(det.owner).replace(/^pm:/, ''), 40) + ' owns it');
109
+ const why = { id: 'why', title: 'Why it is blocked', open: !ctx.run, html: '<p>' + esc(whyBlocked(step, det.rule, det.lane)) + '</p>' };
110
+ const status = ((d.pane && d.pane.rows) || []).find((x) => x[0] === 'Status');
111
+ const where = status && noPaths(status[1]) ? { id: 'where', title: 'Where it stands', html: '<p>' + esc(clip(noPaths(status[1]), 280)) + '</p>' } : null;
112
+ if (ctx.run && ctx.run.state === 'ready') {
113
+ m.line = 'Ready for you to read'; m.tone = 'ok';
114
+ m.text = 'The agent finished ' + (ctx.run.doing ? ctx.run.doing.replace(/^\w+/, (x) => x.toLowerCase()) : 'its work') + '. Read it before anything moves.';
115
+ m.meta = 'When it is on record, the block lifts and the next step can start.';
116
+ m.primary = { act: 'read', label: 'Read it', icon: ICON.doc };
117
+ m.sections = [why, where]; return m;
118
+ }
119
+ if (ctx.run) {
120
+ m.line = ctx.run.doing || 'Working on it'; m.tone = 'you';
121
+ m.right = ctx.run.n ? ctx.run.done + ' of ' + plural(ctx.run.n, 'step', 'steps') : 'started';
122
+ m.text = 'You can close this. The work lands in its chat, and this card says when it is ready.';
123
+ m.also = [{ act: 'stop', label: 'Stop the agent', icon: STOP }, { act: 'talk', label: 'Open its chat', icon: CHAT }];
124
+ m.progress = ctx.run.n ? Math.round((ctx.run.done / ctx.run.n) * 100) : null;
125
+ m.sections = [why, where]; return m;
126
+ }
127
+ if (st) {
128
+ m.line = lineOf(step, det.rule); m.tone = 'warn';
129
+ m.offer = 'I can ' + st.say + '. You read it before anything moves.';
130
+ m.cost = costOf(row.skip);
131
+ m.primary = { act: 'start', label: st.label, icon: SPARK };
132
+ } else {
133
+ m.line = 'Blocked at ' + (STEP_AT[step] || 'the ' + step + ' step'); m.tone = 'warn';
134
+ m.offer = 'No next step is on record, so I can’t start one yet. Tell me what unblocks it, or let me look.';
135
+ m.primary = { act: 'find', label: 'Find the next step', icon: SPARK };
136
+ m.also = [{ act: 'talk', label: 'Tell Claude in the chat', icon: CHAT }];
137
+ }
138
+ m.sections = [why, where];
139
+ return m;
140
+ }
141
+ if (kind === 'decision') {
142
+ const opts = d.opts || [], rec = d.rec && opts.some((o) => o.k === d.rec.k) ? d.rec : null;
143
+ m.icon = ICON.goal;
144
+ m.line = 'Your call: ' + opts.map((o) => o.t.replace(/ it$/, '').toLowerCase()).join(', ').replace(/, ([^,]*)$/, ' or $1'); m.tone = 'you';
145
+ m.right = det.meeting ? 'by ' + det.meeting.at + ' ' + det.meeting.title : '';
146
+ if (rec) {
147
+ const o = opts.find((x) => x.k === rec.k);
148
+ m.offer = 'I’d ' + o.t.replace(/ it$/, '').toLowerCase() + (rec.why ? ': ' + rec.why : '.');
149
+ if (rec.sure) m.meta = 'How sure: ' + rec.sure;
150
+ } else {
151
+ m.offer = 'No pick is on record, so none is chosen for you. I can read the record and the evidence and tell you which I’d pick and how sure I am.';
152
+ m.primary = { act: 'weigh', label: 'Weigh it for me', icon: SPARK };
153
+ }
154
+ m.cost = costOf(row.skip);
155
+ m.owner = det.lane ? owner('') : null;
156
+ const ev = plainFacts(d.facts);
157
+ m.sections = [ev.length ? { id: 'evidence', title: 'The evidence', count: ev.length, html: factsHtml(ev, esc) } : null];
158
+ m.decide = { opts, rec: rec ? rec.k : null };
159
+ return m;
160
+ }
161
+ if (kind === 'waited') {
162
+ const items = d.items || [];
163
+ m.title = plural(items.length, 'failed review', 'failed reviews'); m.icon = ICON.warn;
164
+ m.line = clip(String(row.subject || '').split(' · ')[0], 60) || 'Waiting'; m.tone = 'warn';
165
+ m.text = (items.length === 1 ? 'One review failed and none has passed since.' : cap(String(d.say || '').split('. ')[0]) + '.') + ' ' + (items.length === 1 ? 'It has its findings on record.' : 'Each one has its findings on record.');
166
+ m.offer = 'I can send ' + (items.length === 1 ? 'it' : 'each one') + ' back to its agent with the top finding as the note. You see each note before it goes.';
167
+ m.primary = { act: 'notes', label: items.length === 1 ? 'Prepare the note' : 'Prepare the ' + items.length + ' notes', icon: SPARK };
168
+ m.cost = costOf(row.skip);
169
+ m.sections = [{ id: 'reviews', title: 'The reviews', count: items.length, open: true,
170
+ html: items.map((x, i) => `<button type="button" class="czs-it nv-rev" data-nv-rev="${i}"><span class="w">${esc(x.t)}<span>${esc([x.s, x.days != null ? plural(x.days, 'day', 'days') : '', x.lead ? clip(noPaths(x.lead), 90) : ''].filter(Boolean).join(' · '))}</span></span><span class="czs-cv" aria-hidden="true">${(ctx.svg || (() => ''))(CHEV, 15)}</span></button>`).join('') }];
171
+ return m;
172
+ }
173
+ if (kind === 'source') {
174
+ const src = d.eye || 'the source', link = /^https:\/\//.test(d.link || '') ? d.link : '';
175
+ m.title = r.name; m.sub = clip(row.subject || '', 90); m.icon = SRC_ICON[src] || ICON.doc; m.later = false;
176
+ if (row.unread) {
177
+ m.line = row.unread.source + ' could not be read'; m.tone = 'warn';
178
+ m.text = 'The morning brief could not reach ' + row.unread.source + ', so this is its copy' + (row.unread.date ? ' from ' + dayOf(row.unread.date) : '') + ', not the live ' + row.unread.source.toLowerCase() + '.';
179
+ m.primary = { act: 'signin', label: 'Sign in to ' + row.unread.source + ' again', icon: OUT };
180
+ } else {
181
+ const why = /^Why now:\s*/.test(row.skip || '') ? row.skip.replace(/^Why now:\s*/, '') : '';
182
+ m.line = why ? 'Why now: ' + clip(why.replace(/\.$/, ''), 70) : /^Due /.test(row.skip || '') ? row.skip.replace(/\.$/, '') : 'From ' + src; m.tone = 'you';
183
+ m.text = d.say && d.say !== why ? clip(d.say, 400) : ''; // the brief's gist; never the why now again (say it once)
184
+ m.meta = 'Read from ' + src + ' by the morning brief. Nothing is recorded or sent from here.';
185
+ if (link) m.primary = { act: 'open', label: d.linkLabel || 'Open in ' + src, href: link, icon: OUT };
186
+ }
187
+ const f = plainFacts(d.facts).filter((x) => !/^(about)$/i.test(x[0]));
188
+ m.sections = [f.length ? { id: 'item', title: 'The item', count: f.length, html: factsHtml(f, esc) } : null];
189
+ return m;
190
+ }
191
+ // the agent's drafts (lib/briefing-premium-drafts.js) and any kind to come: the state, the agent's words, the facts it stated
192
+ m.title = r.name; m.icon = ICON.gate;
193
+ m.line = clip(String(row.subject || 'Waits on you'), 60); m.tone = 'you';
194
+ m.text = clip(noPaths(d.say || row.prepared || ''), 400);
195
+ const f = plainFacts(d.facts);
196
+ m.sections = [f.length ? { id: 'facts', title: d.head || 'What is on record', count: f.length, html: factsHtml(f, esc) } : null];
197
+ return m;
198
+ }
199
+
200
+ /** The chat beside the ask asks a question instead of repeating the Viewer's summary (OvA10Desk). */
201
+ export function introOf(r) {
202
+ const row = r.row || {}, w = (row.dialog || {}).write || {};
203
+ if (row.kind === 'blocked') {
204
+ const st = w.kind === 'start' ? plainStep(w.what) : null;
205
+ return st ? 'Anything I should know before I ' + st.say.split(/\s+(?:with|so|or)\b/)[0] + '? Tell me here, or just press ' + st.label + '.' : 'Do you know what unblocks it? Tell me here, or press Find the next step and I’ll look.';
206
+ }
207
+ if (row.kind === 'decision') return 'Which way are you leaning? Ask me anything about it here, or let me weigh it for you.';
208
+ if (row.kind === 'waited') return 'Want to look at one of them first, or shall I prepare the notes?';
209
+ if (row.kind === 'source') return 'Want me to draft a reply, or is reading it enough?';
210
+ return 'Anything you want to ask about it?';
211
+ }
212
+
213
+ /* ── drawing ── */
214
+ const NV = { r: null, h: null, st: null, sig: '' };
215
+ const RUNS_KEY = 'pmos.home.needRuns';
216
+ const store = {
217
+ get() { try { return JSON.parse(localStorage.getItem(RUNS_KEY) || '{}') || {}; } catch { return {}; } },
218
+ set(o) { try { localStorage.setItem(RUNS_KEY, JSON.stringify(o)); } catch { /* a private window forgets it */ } },
219
+ };
220
+ /** The agent this ask started (kept across reads and a reload) and where it stands now, from the session list. */
221
+ function runOf(r, h) {
222
+ const k = store.get()[r.key]; if (!k || !k.sid) return null;
223
+ const s = (h.sessions() || []).find((x) => x.id === k.sid);
224
+ // a session not listed yet (the list is read every few seconds) is starting, not finished
225
+ const ended = s ? ['needs', 'quiet', 'exited'].includes(s.shown) : Date.now() - (k.at || 0) > 60000;
226
+ const pr = s && s.progress && s.progress.n > 0 ? s.progress : null;
227
+ return { sid: k.sid, doing: k.doing, state: ended ? 'ready' : 'running', done: pr ? pr.done : 0, n: pr ? pr.n : 0 };
228
+ }
229
+ const keepRun = (key, v) => { const o = store.get(); if (v) o[key] = v; else delete o[key]; store.set(o); };
230
+
231
+ export function openNeed(r, h, o = {}) {
232
+ NV.r = r; NV.h = h;
233
+ const d = (r.row && r.row.dialog) || {};
234
+ NV.st = { choice: o.choice || null, why: null, msg: '', gone: false };
235
+ const draw = (b) => paint(b);
236
+ const m0 = model();
237
+ const more = () => {
238
+ const out = [];
239
+ const rec = h.recordHref(r); if (rec) out.push({ label: 'Open the record', on: () => window.open(rec, '_blank', 'noopener') });
240
+ const bd = h.boardHref(r); if (bd) out.push({ label: 'Open on the Board', on: () => window.open(bd, '_blank', 'noopener') });
241
+ out.push({ label: 'Copy link', on: async () => { try { await navigator.clipboard.writeText(h.linkOf(r)); h.toast('The link is copied.'); } catch { h.toast('The link could not be copied.'); } } });
242
+ return out;
243
+ };
244
+ const body = h.VW.open({ id: 'need:' + r.key, kind: ({ decision: 'Decision', blocked: 'Blocked', waited: 'Waiting', source: 'Source' }[r.row.kind] || 'Needs you'), title: m0.title, sub: m0.sub, icon: m0.icon,
245
+ presses: pressesOf(m0, r, h), more, onPress: (act, b) => pressHead(act, b), render: draw });
246
+ NV.sig = sigOf(m0);
247
+ if (body) {
248
+ body.oninput = (e) => { if (e.target.id === 'nvWhy') { NV.st.why = e.target.value; const b = body.querySelector('[data-nv-rec]'); if (b) b.disabled = !canRecord(); } };
249
+ body.onclick = (e) => { const t = e.target.closest('button, a'); if (t) press(t, body); };
250
+ }
251
+ if (d.write && d.write.kind === 'decision' && o.choice) setTimeout(() => { const t = body && body.querySelector('#nvWhy'); if (t) t.focus(); }, 0);
252
+ return body;
253
+ }
254
+ function model() {
255
+ const { r, h, st } = NV;
256
+ return needModel(r, { esc: h.esc, svg: h.svg, run: r.row.kind === 'blocked' ? runOf(r, h) : null, gone: st.gone });
257
+ }
258
+ const sigOf = (m) => [m.line, m.right, m.primary && m.primary.act, m.title].join('|');
259
+ function pressesOf(m, r, h) {
260
+ const out = [];
261
+ if (m.pin) { const on = h.pinned(r.key); out.push({ act: 'pin', label: on ? 'Unpin' : 'Pin to the top', icon: h.P.pin, pressed: on }); }
262
+ if (m.later) out.push({ act: 'later', label: 'Put off', icon: h.P.clock });
263
+ return out;
264
+ }
265
+ const canRecord = () => !!NV.st.choice && String(NV.st.why == null ? whyOf() : NV.st.why).trim().length >= 3;
266
+ const whyOf = () => { const rec = (NV.r.row.dialog || {}).rec; return NV.st.why != null ? NV.st.why : rec && rec.why && NV.st.choice === rec.k ? rec.why : ''; };
267
+ function paint(b) {
268
+ const { r, h, st } = NV, esc = h.esc, m = model();
269
+ NV.sig = sigOf(m);
270
+ const extra = (m.offer ? `<p class="nv-offer">${h.svg(SPARK, 14)}<span>${esc(m.offer)}</span></p>` : '')
271
+ + (m.progress != null ? `<div class="nv-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${m.progress}"><span style="width:${m.progress}%"></span></div>` : '')
272
+ + (m.cost ? `<p class="nv-cost">${h.svg(h.P.clock, 14)}<span>${esc(m.cost)}</span></p>` : '');
273
+ let sum = h.VW.czSummary({ line: m.line, tone: m.tone, right: m.right, text: m.text, meta: m.meta, extra, primary: m.primary && !m.primary.href ? m.primary : null, also: m.also });
274
+ if (m.primary && m.primary.href) { // ↗ Open in Mail: the item's own https link, in a new tab
275
+ const a = `<a class="czs-pri" id="srcLink" href="${esc(m.primary.href)}" target="_blank" rel="noopener noreferrer">${h.svg(OUT, 15)}${esc(m.primary.label)}</a>`;
276
+ sum = sum.replace(/<\/div>$/, `<div class="czs-acts">${a}</div></div>`);
277
+ } else if (m.primary) sum = sum.replace(`data-czs-act="${m.primary.act}">`, `data-czs-act="${m.primary.act}">${h.svg(m.primary.icon || SPARK, 15)}`);
278
+ const own = m.owner ? `<p class="nv-own">${m.owner.av ? `<span class="nv-av" aria-hidden="true">${esc(m.owner.av === 'pm' ? h.me() : m.owner.av)}</span>` : ''}<span>${esc(m.owner.text)}</span></p>` : '';
279
+ let dec = '';
280
+ if (m.decide && !st.gone) {
281
+ if (st.choice == null && m.decide.rec) st.choice = m.decide.rec;
282
+ dec = `<div class="nv-dec" role="radiogroup" aria-label="Choices">${m.decide.opts.map((o) => `<button type="button" class="ut-radio" role="radio" aria-checked="${st.choice === o.k}" data-nv-opt="${esc(o.k)}"><span class="o" aria-hidden="true"></span><span><b>${esc(o.t)}</b>${m.decide.rec === o.k ? ' <span class="nv-pick">I’d do this</span>' : ''}${o.d ? `<br><span class="ut-small ut-mut">${esc(noPaths(o.d))}</span>` : ''}</span></button>`).join('')}</div>`
283
+ + `<div class="ut-field"><label for="nvWhy">Why${m.decide.rec && st.choice === m.decide.rec ? ' <em>(I wrote it; change it if you like)</em>' : ' <em>· kept in the journal</em>'}</label><textarea id="nvWhy" rows="2" placeholder="Your reason goes in the journal with your choice">${esc(whyOf())}</textarea></div>`
284
+ + `<div class="czs-acts"><button type="button" class="czs-pri nv-rec" data-nv-rec${canRecord() ? '' : ' disabled'}>${h.svg(CHECK, 15)}${esc(st.choice ? 'Record: ' + ((m.decide.opts.find((o) => o.k === st.choice) || {}).t || '').replace(/ it$/, '').toLowerCase() : 'Record')}</button></div>`;
285
+ }
286
+ b.innerHTML = `<div class="nv">${sum}${own}${dec}${h.VW.czSections(m.sections, { key: 'need-' + m.kind })}<p class="ut-small ut-mut" role="status" id="nvMsg">${esc(st.msg || '')}</p></div>`;
287
+ }
288
+ const say = (body, t) => { NV.st.msg = t; const el = body.querySelector('#nvMsg'); if (el) el.textContent = t; };
289
+ function pressHead(act, b) {
290
+ const { r, h } = NV;
291
+ if (act === 'pin') { h.togglePin(r.key); h.VW.setPresses('need:' + r.key, pressesOf(model(), r, h)); return; }
292
+ if (act === 'later') {
293
+ const at = new Date(Date.now() + 3 * 3600000), hm = String(at.getHours()).padStart(2, '0') + ':' + String(at.getMinutes()).padStart(2, '0');
294
+ h.menu(b, [{ label: 'Later today', k: hm, go: () => h.putOff(r.key, 'later') }, { label: 'Tomorrow', k: '09:00', go: () => h.putOff(r.key, 'tomorrow') }, { label: 'Next week', k: 'Mon', go: () => h.putOff(r.key, 'nextweek') }], 'Put off');
295
+ }
296
+ }
297
+ async function press(t, body) {
298
+ const { r, h, st } = NV, d = r.row.dialog || {};
299
+ if (t.dataset.nvOpt) { st.choice = t.dataset.nvOpt; if (st.why == null) st.why = whyOf(); paint(body); return; }
300
+ if (t.dataset.nvRev != null) { const it = (d.items || [])[+t.dataset.nvRev]; if (it) h.openReturn(it); return; }
301
+ if ('nvRec' in t.dataset) {
302
+ t.disabled = true;
303
+ const res = await h.decide(r, st.choice, String(st.why == null ? whyOf() : st.why).trim());
304
+ if (!res.ok) { t.disabled = false; say(body, res.error); }
305
+ return;
306
+ }
307
+ const act = t.dataset.czsAct; if (!act) return;
308
+ if (act === 'start') {
309
+ t.disabled = true;
310
+ const st0 = plainStep((d.write || {}).what);
311
+ const res = await h.start(r);
312
+ if (!res.ok) { t.disabled = false; say(body, 'Not started: ' + res.error); return; }
313
+ const sid = res.session && (res.session.id || res.session);
314
+ if (typeof sid === 'string') keepRun(r.key, { sid, doing: st0 ? st0.doing : 'Working on it', at: Date.now() });
315
+ st.msg = ''; paint(body); return;
316
+ }
317
+ const run = runOf(r, h);
318
+ if (act === 'stop' && run) { const ok = await h.stopSession(run.sid); if (ok) { keepRun(r.key, null); st.msg = ''; paint(body); } else say(body, 'The agent did not stop. Try again.'); return; }
319
+ if ((act === 'talk' || act === 'read') && run) { h.openSession(run.sid); return; }
320
+ if (act === 'talk') { h.ask(r, ''); return; }
321
+ if (act === 'find') { h.ask(r, 'Find the next step that unblocks ' + model().title + ': read its record and its history, then tell me what it is and whether you can start it.'); return; }
322
+ if (act === 'weigh') { h.ask(r, 'Weigh this for me: read the record and the evidence, then tell me which choice you would pick, how sure you are, and why.'); return; }
323
+ if (act === 'notes') { h.ask(r, 'For each failed review, write the note that sends it back to its agent, with its top finding. Show me each note; send nothing until I return it.'); return; }
324
+ if (act === 'signin') { h.signIn(); return; }
325
+ if (act === 'done') { if (run) keepRun(r.key, null); h.VW.close(); }
326
+ }
327
+ /** After a read: the open ask draws again when its phase changed (the agent finished, the row left Home); typing is never redrawn. */
328
+ export function refresh() {
329
+ const { r, h } = NV; if (!r || !h) return;
330
+ const c = h.VW.current(); if (!c || c.id !== 'need:' + r.key) { NV.r = null; return; }
331
+ if (!NV.st.gone && h.rowGone(r.key)) NV.st.gone = true;
332
+ const m = model();
333
+ if (sigOf(m) === NV.sig) return;
334
+ h.VW.setPresses('need:' + r.key, pressesOf(m, r, h));
335
+ const b = h.VW.body(); if (b) paint(b);
336
+ }
@@ -274,12 +274,12 @@ export function listHtml(M, T, o) {
274
274
  const nw = o.news > 0 ? '. ' + o.news + ' new for you' : '';
275
275
  // Your impact (batch 16 item 7, GmA1Home): with it on, the greeting's face is its own press, Adler with the week's leaves (pm/impact.js faceHtml)
276
276
  const face = o.imFace && !o.err ? '' : AD.adler(o.err ? 'honest' : 'handled', 36, { label: false, cls: 'hv-ad' });
277
- const head = `<div class="hm-hd hv-bar">${o.imFace && !o.err ? o.imFace : ''}<button type="button" class="hv-hi" data-hm-day aria-expanded="${!!o.day}" aria-label="${esc(M.word || 'Today')}${nw}. Open your day">${face}<b>${esc(M.word || 'Today')}</b>${o.news > 0 ? '<i class="hv-nd" aria-hidden="true"></i>' : ''}${svg(P.chevD, 18)}</button>`
277
+ const head = `<div class="hm-hd hv-bar">${o.imFace && !o.err ? o.imFace : ''}<button type="button" class="hv-hi" data-hm-day aria-expanded="${!!o.day}" aria-label="${esc(M.word || 'Today')}${nw}. Open your day">${face}<b>${esc(M.word || 'Today')}</b>${o.news > 0 ? '<i class="hv-nd" aria-hidden="true"></i>' : ''}${svg(P.chevD, 18)}</button><span class="hv-acts">`
278
278
  // the product chip, always (it is also the way to add one): the ticked products' tiles, or All (canvas XhpA2States)
279
279
  + (o.pick ? chipHtml(o.pick, { id: 'hmPick', attrs: 'data-hm-pick', label: 'Products on Home', tones: o.tones }) : '')
280
280
  + (o.phone ? '' : `<button type="button" class="ut-ib hv-ib${flt ? ' on' : ''}" data-hm-flt aria-haspopup="menu" aria-label="Show: Today, Kept or Done${flt ? '. Now ' + esc(flt.label) : ''}" title="Show: Today, Kept or Done">${svg(P.filter, 18)}</button>`)
281
281
  + SO.btnHtml('ut-ib hv-ib' + (SO.layout().sort !== 'mine' ? ' on' : ''))
282
- + `<button type="button" class="ut-ib hv-ib" data-hm-new aria-haspopup="menu" aria-label="New" title="New">${svg(P.plus, 20)}</button></div>`
282
+ + `<button type="button" class="ut-ib hv-ib" data-hm-new aria-haspopup="menu" aria-label="New" title="New">${svg(P.plus, 20)}</button></span></div>`
283
283
  + (M.yours ? `<p class="hv-sub">${M.yours} ${M.yours === 1 ? 'is' : 'are'} yours</p>` : '');
284
284
  // the Today card only while the day has a moment; the plain day (its meetings and load) is in Your day
285
285
  const card = MOMENT.has(T.mode) ? todayHtml(T, { greet: M.greet, sub: '', phone: o.phone }) : '';
@@ -12,7 +12,7 @@
12
12
  * Every press is the PM's and goes to the Work page's own route under /api/pm-items, /api/pm-jobs or /api/my-work (pmPost carries the launch
13
13
  * nonce); this file adds no writer. A refused press shows the route's reason and changes nothing. Text from the list goes through esc(). */
14
14
  import { pmGet, pmPost } from './http.js';
15
- import { open as vwOpen, close as vwClose } from './cozy-viewer.js';
15
+ import { open as vwOpen, close as vwClose, retitle as vwRetitle, setCheck as vwSetCheck, czSummary, czSections } from './cozy-viewer.js';
16
16
  import { mdRender } from './markdown.js';
17
17
  import { tabsHtml } from './home-review.js';
18
18
 
@@ -55,13 +55,16 @@ const freshUi = () => ({ xp: null, ed: null, dd: '', sn: '', ask: null, body: nu
55
55
  /** Open My work in the Viewer on one tab (yours | waiting | review | stale). */
56
56
  export function openMyWork(tab = 'yours', o = {}) {
57
57
  if (tab === 'review' && askReview()) return null;
58
- const W = { solo: !!o.solo, home: o.view || null, r: null, M: null, tab: TABS.some((t) => t[0] === tab) || tab === 'review' ? tab : 'yours', msg: '', view: null, key: null, ui: freshUi(), refocus: null, want: o.item || null };
58
+ const W = { solo: !!o.solo, own: !!(o.solo && o.item), home: o.view || null, r: null, M: null, tab: TABS.some((t) => t[0] === tab) || tab === 'review' ? tab : 'yours', msg: '', view: null, key: null, ui: freshUi(), refocus: null, want: o.item || null };
59
59
  if (W.home) W.view = W.home;
60
60
  let body = null;
61
61
  const rowOf = (key) => ((W.M && W.M.rows) || []).find((r) => r.key === key) || null;
62
62
  const openR = () => (W.view === 'item' ? rowOf(W.key) : null);
63
63
  const focusIds = () => new Set(((W.M && W.M.focus && W.M.focus.suggestions[0]) || {}).item_ids || []);
64
64
  const setTitle = (t) => { const el = document.getElementById('czVwTitle'); if (el) el.textContent = t; };
65
+ // your own task opened alone: the header is the task's (its check, its name); it changes only when the name does
66
+ let ownT = '';
67
+ const ownHead = (r) => { if (ownT === r.title) return; ownT = r.title; vwRetitle('more:work', r.title); vwSetCheck('more:work', { state: 'todo', label: 'Mark ' + r.title + ' done', title: 'Done' }); };
65
68
 
66
69
  /* ── the list ── */
67
70
  function sideOf(r) {
@@ -189,7 +192,7 @@ export function openMyWork(tab = 'yours', o = {}) {
189
192
  + `<label class="mw-f"><span>Due</span><input type="date" id="xeD" class="mw-in" value="${esc(e.due)}"></label>`
190
193
  + `<div class="mw-f"><span>Priority</span><span class="hx-top" role="group" aria-label="Priority">${PRIS.map((p) => `<button type="button" class="hx-b" data-p="xpri" data-v="${p}" aria-pressed="${e.priority === p}">${p || 'None'}</button>`).join('')}</span></div>`
191
194
  + `<label class="mw-f"><span>Waiting on</span><input id="xeW" class="mw-in" maxlength="80" value="${esc(e.wo)}" placeholder="A name moves it to Waiting"></label>`
192
- + `<label class="mw-f"><span>Job</span><select id="xeJ" class="mw-in"><option value="">No job</option>${(W.M.jobs || []).map((j) => `<option value="${esc(j.id)}"${e.job === j.id ? ' selected' : ''}>${esc(j.name)}</option>`).join('')}</select></label>`
195
+ + (W.solo ? '' : `<label class="mw-f"><span>Job</span><select id="xeJ" class="mw-in"><option value="">No job</option>${(W.M.jobs || []).map((j) => `<option value="${esc(j.id)}"${e.job === j.id ? ' selected' : ''}>${esc(j.name)}</option>`).join('')}</select></label>`)
193
196
  + '<div class="hx-top"><button type="button" class="hx-b pri" data-p="xsave">Save</button><button type="button" class="hx-b" data-p="xt" data-k="edit">Cancel</button></div></div>';
194
197
  }
195
198
  if (x === 'steps') {
@@ -250,6 +253,44 @@ export function openMyWork(tab = 'yours', o = {}) {
250
253
  if (r.dialog.source) return h + srcHtml(r.dialog.source) + `<details class="mw-det"><summary>Details</summary>${kv}<p class="hx-n">${esc(p.file)}</p></details>`;
251
254
  return h + `<section class="mw-rec">${kv}<p class="hx-n">The item as your list holds it · ${esc(p.file)}</p></section>`;
252
255
  }
256
+ /* ── your own task, opened alone from Home (batch 18 item 2-C, canvas OvA9Docs): shell A. The header's check is Done, the title is the
257
+ * task's, "Your own task" under it, ⋯ holds Keep for later and Drop it (danger, last). The summary says when it is, with the agent's
258
+ * offer as the one primary ("Draft it") and the Not before icon; Steps, Waiting on, Priority and From are folds. No ids or file names. ── */
259
+ const SPARK = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/></svg>';
260
+ const CLOCK = 'M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18M12 7v5l3 2';
261
+ function ownHtml(r) {
262
+ const ui = W.ui, d = r.dialog, a = d.write.actions, e = d.edit, ag = d.agent, S = d.steps || [];
263
+ const when = whenOf(r), late = !!e.due && e.due < W.M.today;
264
+ const offer = ag && ag.state === 'suggest';
265
+ const words = offer ? (ag.ask ? ag.ask.replace(/\s*\.$/, '') + '. ' : '') + (ag.mine ? 'I can draft it here in PMOS. Nothing leaves PMOS.' : `I can draft it here in PMOS. Nothing goes to ${ag.where || 'anyone'} until you post it.`) : '';
266
+ const sum = czSummary({ line: late ? 'Due ' + dayLabel(e.due) + ', still open' : when[0] + (when[1] && !/^(not placed yet|you added it|off your lists until then)$/.test(when[1]) ? ' · ' + when[1] : ''), tone: late ? 'warn' : 'you',
267
+ text: offer || d.say === 'This is on your list.' ? '' : d.say || '', extra: offer ? `<p class="czf-spark">${SPARK}<span>${esc(words)}</span></p>` : '',
268
+ primary: offer ? { label: 'Draft it', act: 'ag-brief' } : null,
269
+ also: [{ act: 'when', label: d.defer && d.defer > W.M.today ? 'Not before ' + dayLabel(d.defer) + '. Change it' : 'Not before…', icon: CLOCK }] });
270
+ const whenPan = ui.xp === 'when' || ui.xp === 'defer' ? panelHtml(r, ui.xp) : '';
271
+ const mine = S.filter((x) => x.who !== 'you').length;
272
+ const dr = ag && ag.draft && (ag.draft.body || ag.draft.summary) ? ag.draft : null;
273
+ const sc = d.source, from = sc ? [sc.name, sc.where].filter(Boolean).join(' · ') : ((d.facts || []).find((f) => f[0] === 'From') || [0, ''])[1];
274
+ const rec = (d.pane.rows || []).filter(([k]) => k !== 'From');
275
+ const secs = czSections([
276
+ dr ? { id: 'draft', title: ag.state === 'sent' ? 'Posted' : 'The draft', open: true, html: `<div class="mw-md">${mdHtml(dr.body || dr.summary)}</div><div class="hx-top"><button type="button" class="hx-b" data-pp="copy">Copy</button></div>` } : null,
277
+ { id: 'steps', title: 'Steps', count: S.length ? S.length + (mine ? ' · ' + mine + ' for me' : '') : '', html: panelHtml(r, 'steps') },
278
+ a.includes('waiting') || e.waiting_on ? { id: 'wait', title: 'Waiting on', count: e.waiting_on || '', html: panelHtml(r, 'wait') } : null,
279
+ { id: 'pri', title: 'Priority', count: [e.priority || 'None', e.due ? 'due ' + dayLabel(e.due) : ''].filter(Boolean).join(' · '), html: panelHtml(r, 'edit') },
280
+ { id: 'from', title: 'From', count: from, html: sc ? srcHtml(sc) : rec.length ? `<dl class="hv-facts">${rec.map(([k, v]) => `<div><dt>${esc(k)}</dt><dd>${esc(v)}</dd></div>`).join('')}</dl>` : '' },
281
+ ], { key: 'own-task' });
282
+ return `<div class="mw-it mw-own" id="card" data-esc-layer>${sum}${whenPan ? `<div class="mw-ownwhen">${whenPan}</div>` : ''}<div id="agCard">${agCardInner(r)}</div>${secs}<p class="hx-n mw-err" id="cardErr" role="alert" hidden></p></div>`;
283
+ }
284
+ function ownMore() {
285
+ const r = openR(); if (!r) return [];
286
+ const a = r.dialog.write.actions;
287
+ return [
288
+ ...(a.includes('keep') ? [{ label: 'Keep for later', on: () => itemPress({ dataset: { p: 'keep' } }, r) }] : []),
289
+ ...(a.includes('flag') ? [{ label: 'Move to Today', on: () => itemPress({ dataset: { p: 'flag' } }, r) }] : []),
290
+ { sep: true },
291
+ { label: 'Drop it', danger: true, icon: 'M5 7h14M9 7V4h6v3M7 7l1 13h8l1-13', on: () => itemPress({ dataset: { p: 'remove' } }, r) },
292
+ ];
293
+ }
253
294
  function itemHtml(r) {
254
295
  const src = !!r.dialog.source;
255
296
  return `<div class="mw-sub mw-it ut-vc" data-esc-layer><div>${backBtn()}</div>`
@@ -290,6 +331,7 @@ export function openMyWork(tab = 'yours', o = {}) {
290
331
  const keep = body.scrollTop;
291
332
  if (!W.r) body.innerHTML = '<p class="hx-n">Reading My work.</p>';
292
333
  else if (!W.M) body.innerHTML = `<p class="hx-n">My work could not be read${W.r.error ? ': ' + esc(W.r.error) : ''}.</p>`;
334
+ else if (W.view === 'item' && openR() && W.own) { const r = openR(); body.innerHTML = ownHtml(r); ownHead(r); }
293
335
  else if (W.view === 'item' && openR()) { body.innerHTML = itemHtml(openR()); setTitle(openR().title); }
294
336
  else if (W.view === 'fjobs') { body.innerHTML = focusHtml(); setTitle('Focus and jobs'); }
295
337
  else if (W.solo) { vwClose(); return; } // opened alone from Home (an item, or Focus and jobs): there is no list behind it
@@ -449,6 +491,10 @@ export function openMyWork(tab = 'yours', o = {}) {
449
491
  if (t.dataset.pp === 'copy') { try { await navigator.clipboard.writeText(txt); toast('Draft copied.'); } catch { toast('Copy did not work here. Select the text and copy it.'); } return; }
450
492
  const u = URL.createObjectURL(new Blob([txt], { type: 'text/plain;charset=utf-8' })); window.open(u, '_blank', 'noopener'); setTimeout(() => URL.revokeObjectURL(u), 60000); return;
451
493
  }
494
+ if (t.dataset.czsAct && W.own && openR()) { // your own task's summary: Draft it, and the Not before icon opens When in place
495
+ if (t.dataset.czsAct === 'when') { W.ui.xp = W.ui.xp === 'when' || W.ui.xp === 'defer' ? null : 'when'; draw(W.ui.xp ? '.mw-ownwhen button' : '[data-czs-act="when"]'); return; }
496
+ itemPress({ dataset: { p: t.dataset.czsAct } }, openR()); return;
497
+ }
452
498
  if (t.dataset.p && openR()) { itemPress(t, openR()); return; }
453
499
  if (t.dataset.open) { openItem(t.dataset.open); return; }
454
500
  if (t.dataset.done) {
@@ -527,7 +573,8 @@ export function openMyWork(tab = 'yours', o = {}) {
527
573
  back();
528
574
  }
529
575
 
530
- body = vwOpen({ id: 'more:work', kind: W.solo ? (W.home === 'fjobs' ? 'Focus' : 'Task') : 'My work', title: W.solo ? (W.home === 'fjobs' ? 'Focus and jobs' : 'Task') : 'My work', icon: 'list', render: (b) => { b.classList.add('hx'); }, onClose: () => { removeEventListener('keydown', onEsc, true); clearInterval(timer); } });
576
+ body = vwOpen({ id: 'more:work', kind: W.solo ? (W.home === 'fjobs' ? 'Focus' : 'Task') : 'My work', title: W.solo ? (W.home === 'fjobs' ? 'Focus and jobs' : 'Task') : 'My work', icon: 'list',
577
+ ...(W.own ? { sub: 'Your own task', check: { state: 'todo', label: 'Mark done', title: 'Done' }, more: () => ownMore(), onPress: (a) => { if (a === 'check' && openR()) doneP(openR()); } } : {}), render: (b) => { b.classList.add('hx'); }, onClose: () => { removeEventListener('keydown', onEsc, true); clearInterval(timer); } });
531
578
  // delegated, as the other Home cards do: every control in the card is a real <button>; the drag repeats what the arrow keys do
532
579
  body.onclick = onClick;
533
580
  body.oninput = onInput;