create-pmos 0.439.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 (66) hide show
  1. package/bin/create-pmos.js +5 -2
  2. package/package.json +25 -25
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/planning/evals/eval-calibration.md +1 -1
  5. package/payload/planning/okrs/health-budgets.md +1 -1
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/briefing-premium-adddoc-test.js +16 -13
  8. package/workspace/briefing-premium-insights-test.js +1 -1
  9. package/workspace/briefing-premium-products-test.js +4 -4
  10. package/workspace/briefing-premium-sources-test.js +2 -2
  11. package/workspace/briefing-premium-test.js +29 -23
  12. package/workspace/changelog.json +24 -0
  13. package/workspace/guide/core-documents.md +2 -2
  14. package/workspace/guide/data-freshness.md +7 -5
  15. package/workspace/guide/home.md +4 -1
  16. package/workspace/guide/horizon-scan.md +1 -1
  17. package/workspace/guide/settings.md +2 -2
  18. package/workspace/lib/agent-inbox.js +20 -2
  19. package/workspace/lib/briefing-premium-sources.js +3 -0
  20. package/workspace/lib/briefing-premium.js +37 -7
  21. package/workspace/lib/driver-cli.js +1 -1
  22. package/workspace/lib/driver-run.js +15 -1
  23. package/workspace/lib/driver.js +31 -2
  24. package/workspace/lib/goal-status.js +2 -1
  25. package/workspace/lib/headless.js +18 -1
  26. package/workspace/lib/kit-update.js +2 -2
  27. package/workspace/lib/metric-draft-runs.js +10 -4
  28. package/workspace/lib/news-for-you.js +24 -9
  29. package/workspace/lib/pm-idle.js +12 -0
  30. package/workspace/lib/refresh.js +17 -8
  31. package/workspace/lib/routes-core-docs.js +1 -1
  32. package/workspace/lib/routes-metric-drafts.js +2 -2
  33. package/workspace/lib/routes-news.js +15 -1
  34. package/workspace/lib/routes-phone-day.js +6 -4
  35. package/workspace/need-shot.js +57 -0
  36. package/workspace/news-viewers-test.js +183 -0
  37. package/workspace/package-lock.json +2 -2
  38. package/workspace/package.json +1 -1
  39. package/workspace/premium-core-doc-issue-test.js +9 -8
  40. package/workspace/premium-phone-card-test.js +9 -6
  41. package/workspace/public/pm/bd-ini-panel.js +4 -11
  42. package/workspace/public/pm/cozy-ev.css +29 -0
  43. package/workspace/public/pm/cozy-live-pill.css +6 -0
  44. package/workspace/public/pm/cozy-news.js +186 -22
  45. package/workspace/public/pm/cozy-today.css +5 -0
  46. package/workspace/public/pm/cozy-viewer.js +4 -3
  47. package/workspace/public/pm/cozy-vw-shell.css +49 -0
  48. package/workspace/public/pm/home-adddoc.js +46 -26
  49. package/workspace/public/pm/home-app.js +137 -115
  50. package/workspace/public/pm/home-day.js +15 -11
  51. package/workspace/public/pm/home-draft.js +35 -23
  52. package/workspace/public/pm/home-ini.js +2 -2
  53. package/workspace/public/pm/home-need.js +336 -0
  54. package/workspace/public/pm/home-phone-card.js +4 -2
  55. package/workspace/public/pm/home-today.js +2 -2
  56. package/workspace/public/pm/home-work.js +51 -4
  57. package/workspace/public/pm/okr-list.js +8 -4
  58. package/workspace/public/pm/premium-insights.js +6 -5
  59. package/workspace/public/pm/small-vw.js +128 -0
  60. package/workspace/public/premium-intelligence.html +1 -1
  61. package/workspace/server.js +20 -11
  62. package/workspace/skills/initiative-drive.skill +4 -1
  63. package/workspace/test-lists/batch18-asks.json +5 -0
  64. package/workspace/test-lists/news-viewers.json +13 -0
  65. package/workspace/test-lists/small-viewers.json +5 -0
  66. package/workspace/test-run.js +3 -1
@@ -3,16 +3,23 @@
3
3
  *
4
4
  * For your information only: Given to you, Finished while you were away (GET /api/news-for-you), and today's digests from the morning
5
5
  * brief (GET /api/briefing-premium). Mentions owns every mention (batch 16 item 12), so none is here. An item leaves once it is seen: the
6
- * items shown are marked seen when the card closes, and Mark all seen marks them at once (POST /api/news-for-you/seen). Open on a row shows
7
- * the item: a task with its source; finished work opens where it waits. The page's meetings ring, its two legend cards, "Where
6
+ * items shown are marked seen when the card closes, and Mark all seen marks them at once (POST /api/news-for-you/seen). Open on a row opens
7
+ * the item as its own Viewer, one step in the trail, so the Viewer's ← comes back to the list (batch 18 item 2: one header, no second
8
+ * "New for you" back press); finished work opens where it waits. The page's meetings ring, its two legend cards, "Where
8
9
  * the rest went" and the "Not here" note are gone (FmAudit: Your day holds the meetings, and a page that explains itself is chrome).
9
- * openNews({ go?, view? }) → the body element; view: an item's id opens straight on that item */
10
+ * The item Viewers (batch 18 items 2 and 2b, canvas OvA5Overlap, OvA6Given), summary first with ONE primary:
11
+ * overlap Claude proposes: both initiatives by name with their stage and owner, "N of M parts overlap" and how sure when the agent said so,
12
+ * and the pick. Keep both, in this order (Claude's pick: POST /api/driver/keep) · Merge (Home's merge check with both set, through
13
+ * go({ merge })) · Not an overlap (POST /api/driver/drop, and /api/boards/notdup so the Board stops flagging the pair too).
14
+ * task Given to you: what it asks, when it is due, where it came from. The agent's part only as it really is: its draft ready
15
+ * ("Read my draft"), drafting now, or its offer ("Draft it": POST /api/my-work/act brief). Done, Not before… and ↗ its source in place.
16
+ * openNews({ go?, view? }) → the body element; view: an item's id opens straight on that item. go(d): Home's own opener ({ ini } | { merge }) */
10
17
  import { pmGet, pmPost } from './http.js';
11
- import { open as vwOpen, current as vwCurrent } from './cozy-viewer.js';
18
+ import { open as vwOpen, current as vwCurrent, back as vwBack, czSummary, czSections } from './cozy-viewer.js';
12
19
  import { esc, svg, ICON, toast, wsParam, wsQ, skelRows, cantRead, allClear } from './cozy-evui.js';
13
20
  import { initials, ago } from './cozy-evmodel.js';
14
21
 
15
- const N = { r: null, dig: null, view: '', body: null, shown: new Set(), busy: false };
22
+ const N = { r: null, dig: null, view: '', body: null, shown: new Set(), busy: false, go: null };
16
23
  const homeUrl = (params) => { const q = new URLSearchParams(params); if (wsParam()) q.set('ws', wsParam()); return '/premium.html?' + q.toString(); };
17
24
  const https = (u) => (/^https:\/\/\S+$/i.test(String(u || '')) ? u : '');
18
25
  /** The deep link of a finished item, as the bell's was: a My work item opens its dialog; anything else opens on Home. */
@@ -21,10 +28,13 @@ const finHref = (it) => (/^item:/.test(it.open) ? homeUrl({ item: it.open.slice(
21
28
  function items() { return N.r && N.r.ok ? N.r.groups.flatMap((g) => g.items) : []; }
22
29
  function rowHtml(it) {
23
30
  const who = it.kind === 'task' ? (it.from || 'Someone') : (it.product || 'Agent');
24
- const av = `<span class="ev-av${it.kind === 'finished' ? ' b' : ''}" aria-hidden="true">${esc(initials(who))}</span>`;
25
- const sub = it.kind === 'task' ? ['From ' + (it.from || 'a source') + (it.key ? ' ' + it.key : ''), it.due ? 'due ' + it.due : '', it.initiative ? 'filed under ' + it.initiative : ''].filter(Boolean).join(' · ')
31
+ // an overlap note is Claude's proposal (batch 18 item 2b): the ✦ tile and both initiatives by name, never an id or "a source"
32
+ const av = it.kind === 'overlap' ? `<span class="ev-av sp" aria-hidden="true">${svg(SPARK, 15)}</span>` : `<span class="ev-av${it.kind === 'finished' ? ' b' : ''}" aria-hidden="true">${esc(initials(who))}</span>`;
33
+ const sub = it.kind === 'overlap' ? [[it.a && it.a.title, it.b && it.b.title].filter(Boolean).join(' and ') || 'Two open initiatives', it.at ? ago(new Date(it.at).toISOString()) : ''].filter(Boolean).join(' · ')
34
+ : it.kind === 'task' ? [it.from ? 'From ' + it.from + (it.key ? ' ' + it.key : '') : it.key, it.due ? 'due ' + dayWords(it.due) : '', it.iniTitle ? 'filed under ' + it.iniTitle : ''].filter(Boolean).join(' · ')
26
35
  : [it.what, it.product, it.target, it.at ? ago(new Date(it.at).toISOString()) : ''].filter(Boolean).join(' · ');
27
- return `<div class="ev-trow" data-ev-id="${esc(it.id)}"><i class="ev-dot you" aria-hidden="true"></i>${av}<div class="ev-tx"><p><b>${esc(it.title)}</b></p><p class="ev-small ev-mut">${esc(sub)}</p></div>`
36
+ const title = it.kind === 'task' ? String(it.title || '').replace(/^New task: /, '') : it.title;
37
+ return `<div class="ev-trow" data-ev-id="${esc(it.id)}"><i class="ev-dot you" aria-hidden="true"></i>${av}<div class="ev-tx"><p><b>${esc(title)}</b></p><p class="ev-small ev-mut">${esc(sub)}</p></div>`
28
38
  + `<button type="button" class="ev-ib" data-ev-open="${esc(it.id)}" aria-label="Open: ${esc(it.title)}" title="Open">${svg(ICON.open, 16)}</button></div>`;
29
39
  }
30
40
  function digHtml() {
@@ -43,25 +53,20 @@ function listHtml() {
43
53
  const notRead = r && r.ok && r.read ? [['inbox', 'The agents\' results'], ['work', 'Your tasks']].filter(([k]) => r.read[k] === false).map(([, l]) => l) : [];
44
54
  return head + body + (notRead.length ? `<p class="ev-small ev-mut" role="status">Not read: ${esc(notRead.join(', '))}.</p>` : '') + digHtml();
45
55
  }
46
- function detailHtml(it) {
47
- const back = '<div class="ev-head"><button type="button" class="ev-btn sm ghost" data-ev-back>' + svg(ICON.back, 16) + 'New for you</button></div>';
48
- const l = https(it.link);
49
- return back + `<p class="ev-lbl">Given to you · ${esc(it.from || 'a source')}</p><h2 class="ev-h2">${esc(it.title.replace(/^New task: /, ''))}</h2>`
50
- + `<p class="ev-small ev-mut">${esc([it.key, it.due ? 'due ' + it.due : '', it.initiative ? 'filed under ' + it.initiative : ''].filter(Boolean).join(' · '))}</p>`
51
- + `<div class="ev-acts"><a class="ev-btn sm pri" href="${esc(homeUrl({ item: it.tid }))}">Open in Home</a>${l ? `<a class="ev-btn sm" href="${esc(l)}" target="_blank" rel="noopener noreferrer">Open in ${esc(it.from || 'its source')}</a>` : ''}</div>`;
52
- }
53
56
  function draw() {
54
57
  const b = N.body; if (!b || !b.isConnected) return;
55
58
  { const c = vwCurrent(); if (!c || c.id !== 'news') return; } // the Viewer moved on to another item: a late read draws nothing
56
- const it = N.view && items().find((x) => x.id === N.view);
57
- b.innerHTML = it ? detailHtml(it) : listHtml();
58
- if (!it) for (const x of items()) N.shown.add(x.id);
59
+ b.innerHTML = listHtml();
60
+ for (const x of items()) N.shown.add(x.id);
59
61
  }
60
62
  async function read() {
61
63
  const [r, d] = await Promise.all([pmGet('/api/news-for-you' + wsQ()), N.dig ? Promise.resolve(null) : pmGet('/api/briefing-premium' + wsQ())]);
62
64
  N.r = r && r.ok ? r : { ok: false, error: (r && r.error) || 'the server did not answer' };
63
65
  if (d && d.ok && d.model) { const T = d.model.today || {}; N.dig = [].concat(T.earlier || [], T.ahead || []).filter((e) => e && e.kind === 'digest'); }
64
- draw();
66
+ // opened straight on one item (Your day's fold): its own Viewer, once the list is read; an item gone since shows the list
67
+ const it = N.view && items().find((x) => x.id === N.view);
68
+ N.view = '';
69
+ if (it && it.kind !== 'finished') openItem(it, { fresh: true }); else draw();
65
70
  if (N.r.ok) document.dispatchEvent(new CustomEvent('cz:news', { detail: { count: N.r.count } }));
66
71
  }
67
72
  /** Mark ids seen; the count in the menu follows. */
@@ -74,7 +79,12 @@ async function seen(ids) {
74
79
  }
75
80
 
76
81
  export function openNews(o = {}) {
77
- N.view = o.view || ''; N.shown = new Set(o.view ? [o.view] : []);
82
+ N.view = o.view || ''; N.shown = new Set(); N.go = typeof o.go === 'function' ? o.go : null;
83
+ if (N.view) { read(); return null; } // straight onto one item: its Viewer opens once the list is read
84
+ return openList(o);
85
+ }
86
+ function openList(o = {}) {
87
+ // ← from an item draws the list again and reads it again, so what was seen has left
78
88
  N.body = vwOpen({ id: 'news', kind: 'For your information', title: 'New for you', icon: ICON.news, render: (b) => { b.classList.add('ev-card-b', 'ev-news'); N.body = b; draw(); wire(b, o); },
79
89
  onClose: () => { const ids = [...N.shown]; N.shown = new Set(); seen(ids); } }); // an item leaves once seen: what the card showed is seen when it closes
80
90
  read();
@@ -85,7 +95,6 @@ function wire(b, o) {
85
95
  const t = e.target.closest('button'); if (!t || N.busy) return;
86
96
  if ('evRetry' in t.dataset) { N.r = null; draw(); read(); return; }
87
97
  if ('evSources' in t.dataset) { import('./cozy-settings.js').then((M) => M.openSettings('connectors')); return; }
88
- if ('evBack' in t.dataset) { N.view = ''; draw(); const f = b.querySelector('[data-ev-open]'); if (f) f.focus(); return; }
89
98
  if ('evAll' in t.dataset) {
90
99
  N.busy = true; const ids = items().map((x) => x.id);
91
100
  const ok = await seen(ids); N.busy = false;
@@ -96,10 +105,165 @@ function wire(b, o) {
96
105
  const it = items().find((x) => x.id === t.dataset.evOpen); if (!it) return;
97
106
  N.shown.add(it.id);
98
107
  if (it.kind === 'finished') { await seen([it.id]); location.assign(finHref(it)); return; }
99
- N.view = it.id; draw(); const f = b.querySelector('[data-ev-back]'); if (f) f.focus(); return;
108
+ openItem(it); return;
100
109
  }
101
110
  };
102
111
  void o;
103
112
  }
104
113
  /** Still open on this item? For a page that redraws around the Viewer. */
105
114
  export const isNewsOpen = () => { const c = vwCurrent(); return !!(c && c.id === 'news'); };
115
+
116
+ /* ── one item, as its own Viewer (batch 18 items 2 and 2b) ── */
117
+ const SPARK = 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z';
118
+ const TASK = 'M5 5h14v14H5zM8.5 12l2.5 2.5 4.5-5';
119
+ const CHEV = 'M9 6l6 6-6 6';
120
+ const INI = 'M12 4a8 8 0 1 0 0 16a8 8 0 1 0 0-16M12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6';
121
+ const P = { check: 'M5 12l4.5 4.5L19 7', clock: 'M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18M12 7v5l3 2', open: 'M14 4h6v6M20 4l-9 9M18 14v5H5V6h5', doc: 'M7 3h7l5 5v13H7zM14 3v5h5' };
122
+ const WD = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
123
+ const MO = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
124
+ /** "today", "tomorrow", "Thursday" (this week), else "Oct 30". Pure. */
125
+ export function dayWords(iso, now = Date.now()) {
126
+ const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); if (!m) return '';
127
+ const d = new Date(+m[1], +m[2] - 1, +m[3]), t = new Date(now); t.setHours(0, 0, 0, 0);
128
+ const n = Math.round((d - t) / 864e5);
129
+ return n === 0 ? 'today' : n === 1 ? 'tomorrow' : n > 1 && n < 7 ? WD[d.getDay()] : MO[d.getMonth()] + ' ' + d.getDate();
130
+ }
131
+ const whose = (owner) => (!owner ? 'no owner' : /^(you|me|pm)$/i.test(owner) ? 'yours' : owner + '’s');
132
+ const sureWord = { high: 'high', medium: 'medium', low: 'low' };
133
+
134
+ function openItem(it, o = {}) {
135
+ if (it.kind === 'overlap') return openOverlap(it, o);
136
+ if (it.kind === 'task') return openGiven(it, o);
137
+ return null;
138
+ }
139
+ /** After a pick: the item is seen, and the Viewer steps back (to the list, or to where it was opened from). */
140
+ async function doneWith(it, id) {
141
+ await seen([it.id]);
142
+ if (N.r && N.r.ok) { N.r = { ...N.r, count: Math.max(0, N.r.count - 1), groups: N.r.groups.map((g) => ({ ...g, items: g.items.filter((x) => x.id !== it.id) })).filter((g) => g.items.length) }; }
143
+ const c = vwCurrent(); if (c && c.id === id) vwBack();
144
+ }
145
+ const goIni = (id) => { if (N.go) N.go({ ini: id }); else location.assign(homeUrl({ ini: id })); };
146
+
147
+ /* the overlap note (OvA5Overlap): Claude proposes; both initiatives read from the Board, so each has its name, stage and owner */
148
+ function openOverlap(it, o = {}) {
149
+ const id = 'news:' + it.id, V = { a: null, b: null, pick: 'keep', busy: false };
150
+ const O = it.overlap || {};
151
+ const first = O.first === 'other' ? 'b' : O.first === 'this' ? 'a' : '';
152
+ const nameOf = (k) => (V[k] && V[k].title) || it[k].title || 'the other initiative';
153
+ const when = it.at ? ago(new Date(it.at).toISOString()) : '';
154
+ const draw = (body) => {
155
+ if (!body || !body.isConnected) return;
156
+ const one = first ? first : 'a', two = one === 'a' ? 'b' : 'a';
157
+ const card = (k) => {
158
+ const r = V[k], sub = r ? [r.stage, whose(r.owner)].filter(Boolean).join(' · ') : (V.read ? '' : 'Reading…');
159
+ const nth = first ? (k === one ? '1st' : '2nd') : '';
160
+ return `<button type="button" class="nv-ini" data-nv-ini="${esc(k)}" aria-label="${esc('Open ' + nameOf(k))}"><span class="nv-it" aria-hidden="true">${svg(INI, 16)}</span><span class="nv-tx"><b>${esc(nameOf(k))}</b>${sub ? `<em>${esc(sub)}</em>` : ''}</span>${nth ? `<span class="nv-nth">${nth}</span>` : ''}</button>`;
161
+ };
162
+ const parts = O.parts && O.of ? `${O.parts} of ${O.of} parts overlap` : '';
163
+ const text = O.text || it.why || `${nameOf('a')} and ${nameOf('b')} may cover the same work.`;
164
+ const sure = O.sure ? 'How sure: ' + sureWord[O.sure] + '.' + (O.sureWhy ? ' ' + O.sureWhy : '') : '';
165
+ const keepWhy = first ? (O.firstWhy || `${nameOf(one)} goes first, then ${nameOf(two)}.`) + ' I keep the order on record.' : 'Both stay as they are. I keep the note on record.';
166
+ const choices = [
167
+ ['keep', first ? 'Keep both, in this order' : 'Keep both', keepWhy, true],
168
+ ['merge', 'Merge into ' + nameOf(one), 'Opens Merge with both set. You see what moves first.', false],
169
+ ['not', 'Not an overlap', 'I stop flagging this pair.', false],
170
+ ];
171
+ const opts = `<div class="nv-opts" role="radiogroup" aria-label="What to do">${choices.map(([k, l, w, rec]) => `<button type="button" role="radio" class="nv-opt${V.pick === k ? ' on' : ''}" aria-checked="${V.pick === k}" data-nv-pick="${k}"><span class="nv-rd" aria-hidden="true"></span><span class="nv-tx"><b>${esc(l)}${rec ? ' <span class="nv-rec">I’d do this</span>' : ''}</b><em>${esc(w)}</em></span></button>`).join('')}</div>`;
172
+ const lbl = choices.find((c) => c[0] === V.pick)[1];
173
+ const go = `<div class="nv-go"><button type="button" class="czs-pri nv-pri" data-nv-go${V.busy ? ' disabled' : ''}>${svg(P.check, 16)}<span>${esc(lbl)}</span></button></div>`;
174
+ const items = Array.isArray(O.items) && O.items.length ? czSections([{ id: 'parts', title: O.items.length === 1 ? 'The part that overlaps' : 'The ' + O.items.length + ' parts that overlap', count: O.items.length,
175
+ html: `<ul class="nv-parts">${O.items.map((x) => `<li>${esc(x)}</li>`).join('')}</ul>` }], { key: 'news-overlap' }) : '';
176
+ body.innerHTML = `<div class="nv">${czSummary({ line: parts, tone: parts ? 'you' : '', text, meta: sure })}${card(one)}${card(two)}${opts}${go}${items}</div>`;
177
+ };
178
+ vwOpen({ id, kind: 'Claude proposes', title: 'Possible overlap', icon: SPARK, sub: ['Claude noticed', when].filter(Boolean).join(' · '), fresh: !!o.fresh,
179
+ more: [{ label: 'Open ' + nameOf('a'), on: () => goIni(it.a.id) }, { label: 'Open ' + nameOf('b'), on: () => goIni(it.b.id) }],
180
+ onClose: () => { if (o.fresh) seen([it.id]); },
181
+ render: (body) => {
182
+ body.classList.add('ev-card-b');
183
+ draw(body);
184
+ if (!V.read) {
185
+ Promise.all(['a', 'b'].map((k) => pmGet('/api/boards/initiative?ws=' + encodeURIComponent(it.ws) + '&id=' + encodeURIComponent(it[k].id)).catch(() => null)))
186
+ .then(([ra, rb]) => { V.read = true; for (const [k, r] of [['a', ra], ['b', rb]]) if (r && r.ok && r.row) V[k] = { title: r.row.title, stage: r.row.stage, owner: r.row.owner, board: (r.board || {}).id || '' }; draw(body); });
187
+ }
188
+ body.onclick = async (e) => {
189
+ const t = e.target.closest('button'); if (!t || V.busy) return;
190
+ if (t.dataset.nvPick) { V.pick = t.dataset.nvPick; draw(body); const f = body.querySelector(`[data-nv-pick="${V.pick}"]`); if (f) f.focus(); return; }
191
+ if (t.dataset.nvIni) { goIni(it[t.dataset.nvIni].id); return; }
192
+ if (!('nvGo' in t.dataset)) return;
193
+ const one = first || 'a', two = one === 'a' ? 'b' : 'a';
194
+ if (V.pick === 'merge') { await seen([it.id]); if (N.go) N.go({ merge: { from: it[two].id, into: it[one].id } }); else location.assign(homeUrl({ ini: it[two].id })); return; }
195
+ V.busy = true; draw(body);
196
+ let ok = false, err = '';
197
+ if (V.pick === 'keep') {
198
+ const r = await pmPost('/api/driver/keep', { ws: it.ws, proposal: it.pid }).catch(() => null);
199
+ ok = !!(r && r.ok); err = (r && r.error) || '';
200
+ if (ok) toast(first ? 'Kept both: ' + nameOf(one) + ' first.' : 'Kept both.');
201
+ } else {
202
+ const r = await pmPost('/api/driver/drop', { ws: it.ws, proposal: it.pid, note: 'Not an overlap with ' + it.b.id }).catch(() => null);
203
+ ok = !!(r && r.ok); err = (r && r.error) || '';
204
+ // the Board's own duplicate flag stops for the pair too; the note is dropped either way
205
+ const bd = (V.a && V.a.board) || (V.b && V.b.board) || '';
206
+ if (ok && bd) await pmPost('/api/boards/notdup', { ws: it.ws, board: bd, id: it.a.id, of: it.b.id }).catch(() => null);
207
+ if (ok) toast('Not an overlap. I won’t flag this pair again.');
208
+ }
209
+ V.busy = false;
210
+ if (!ok) { draw(body); toast('That did not go through' + (err ? ': ' + err : '.')); return; }
211
+ doneWith(it, id);
212
+ };
213
+ } });
214
+ }
215
+
216
+ /* a task given to you (OvA6Given): what it asks, due, from whom; the agent's part only as it really is; Done, Not before… and ↗ in place */
217
+ function openGiven(it, o = {}) {
218
+ const id = 'news:' + it.id, V = { busy: false, when: false, agent: it.agent || null };
219
+ const title = String(it.title || '').replace(/^New task: /, '');
220
+ const link = https(it.link);
221
+ const draw = (body) => {
222
+ if (!body || !body.isConnected) return;
223
+ const a = V.agent, due = it.due ? 'Due ' + dayWords(it.due) : '';
224
+ let text = '', primary = null, line = due, tone = due ? 'you' : '';
225
+ if (a && a.state === 'ready') { text = a.draft ? 'I drafted it: ' + a.draft : 'I drafted it. It waits for you to read.'; primary = { label: 'Read my draft', act: 'read' }; }
226
+ else if (a && ['queued', 'working', 'sending'].includes(a.state)) { text = 'I’m drafting it now. It shows here when it is ready.'; line = due || 'Drafting'; tone = 'live'; }
227
+ else if (a && a.state === 'failed') { text = 'I couldn’t finish the draft.'; primary = { label: 'Try again', act: 'draft' }; }
228
+ else if (a && a.state === 'suggest') { text = a.suggest ? 'I can ' + a.suggest.charAt(0).toLowerCase() + a.suggest.slice(1).replace(/\.?$/, '.') : 'I can draft it for you.'; primary = { label: 'Draft it', act: 'draft' }; }
229
+ else if (it.why) text = it.why;
230
+ const offer = text && a ? `<span class="nv-sp" aria-hidden="true">${svg(SPARK, 14)}</span>` : '';
231
+ const also = [{ act: 'done', label: 'Done', icon: P.check }, { act: 'later', label: 'Not before…', icon: P.clock }, link ? { act: 'src', label: 'Open in ' + (it.from || 'its source'), icon: P.open } : null];
232
+ const when = V.when ? `<div class="nv-when" role="group" aria-label="Not before">${[['later-today', 'Later today'], ['tomorrow', 'Tomorrow'], ['next-week', 'Next week']].map(([k, l]) => `<button type="button" class="ev-btn sm" data-nv-when="${k}">${l}</button>`).join('')}</div>` : '';
233
+ // where it came from and where it is filed: one quiet row each, the value on the right; a press opens it
234
+ const row = (act, k, v) => `<button type="button" class="nv-row" data-czs-act="${act}"${act ? '' : ' disabled'}><b>${esc(k)}</b><span>${esc(v)}</span>${act ? svg(CHEV, 15) : ''}</button>`;
235
+ const rows = [it.from ? row(link ? 'src' : '', 'From ' + it.from, it.status || it.key || '') : '', it.iniTitle ? row('ini', 'Filed under', it.iniTitle) : ''].filter(Boolean);
236
+ const secs = rows.length ? `<div class="nv-rows">${rows.join('')}</div>` : '';
237
+ body.innerHTML = `<div class="nv">${czSummary({ line, tone, text: text ? offer + esc(text) : '', textHtml: true, primary: primary && !V.busy ? primary : primary ? { ...primary, disabled: true } : null, also })}${when}${secs}</div>`;
238
+ };
239
+ vwOpen({ id, kind: 'Given to you', title, icon: TASK, sub: ['From ' + (it.from || 'your work'), it.key].filter(Boolean).join(' · '), fresh: !!o.fresh,
240
+ more: [link ? { label: 'Open in ' + (it.from || 'its source'), on: () => window.open(link, '_blank', 'noopener') } : null, { label: 'Open in your work', on: () => location.assign(homeUrl({ item: it.tid })) }].filter(Boolean),
241
+ onClose: () => { if (o.fresh) seen([it.id]); },
242
+ render: (body) => {
243
+ body.classList.add('ev-card-b');
244
+ draw(body);
245
+ body.onclick = async (e) => {
246
+ const t = e.target.closest('button'); if (!t || V.busy) return;
247
+ const act = t.dataset.czsAct || '';
248
+ if (act === 'src') { if (link) window.open(link, '_blank', 'noopener'); return; }
249
+ if (act === 'ini') { if (it.initiative) goIni(it.initiative); return; }
250
+ if (act === 'read') { location.assign(homeUrl({ item: it.tid })); return; }
251
+ if (act === 'later') { V.when = !V.when; draw(body); const f = body.querySelector('[data-nv-when]'); if (f) f.focus(); return; }
252
+ if (act === 'draft') {
253
+ V.busy = true; draw(body);
254
+ const r = await pmPost('/api/my-work/act', { action: 'brief', item: it.tid, ws: wsParam() || undefined }).catch(() => null);
255
+ V.busy = false;
256
+ if (!r || !r.ok) { draw(body); toast('The draft did not start' + (r && r.error ? ': ' + r.error : '.')); return; }
257
+ V.agent = { ...(V.agent || {}), state: 'queued' }; draw(body); toast('I’m drafting it.'); return;
258
+ }
259
+ if (act === 'done' || t.dataset.nvWhen) {
260
+ V.busy = true;
261
+ const r = act === 'done' ? await pmPost('/api/pm-items/done', { id: it.tid }).catch(() => null) : await pmPost('/api/pm-items/notyet', { id: it.tid, when: t.dataset.nvWhen }).catch(() => null);
262
+ V.busy = false;
263
+ if (!r || !r.ok) { toast('That did not go through' + (r && r.error ? ': ' + r.error : '.')); return; }
264
+ toast(act === 'done' ? 'Done.' : 'Put off: ' + t.textContent.toLowerCase() + '.');
265
+ doneWith(it, id);
266
+ }
267
+ };
268
+ } });
269
+ }
@@ -444,6 +444,10 @@ body.cz-home .hv-r.sp-on + .hv-r::before { display: none; }
444
444
  .hv-card .hv-r.two .hm-rm { min-height: 58px; }
445
445
  }
446
446
  body.cz-home .hm-hd.hv-bar { padding: 0; }
447
+ /* batch 18 item 10: the greeting is never cut. When it and the controls do not fit on one line, the controls go to a second line on the right, together */
448
+ body.cz-home .hm-hd.hv-bar { flex-wrap: wrap; height: auto; min-height: 44px; }
449
+ body.cz-home .hm-hd.hv-bar > .hv-hi { flex: 1 0 auto; max-width: 100%; }
450
+ .hv-acts { display: flex; align-items: center; gap: inherit; margin-left: auto; }
447
451
 
448
452
  /* A session's context (batch 13 item 8, XctxA1Desk): the pie sits at the row's end. Claude's ✦ Compact uses item 7's ✦ and ✓ (.hm-sv, .hm-cls) */
449
453
  .hm-rm .cz-ctx { margin: 0 6px 0 8px; }
@@ -500,6 +504,7 @@ body.cz-home .hm-hd.hv-bar { padding: 0; }
500
504
  .yd-nd { width: 8px; height: 8px; border-radius: 4px; background: var(--cz-blue); flex: none; margin-top: 12px; }
501
505
  .yd-av { width: 32px; height: 32px; border-radius: 16px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--cz-well); color: var(--cz-ink2); font-size: var(--fs-1); font-weight: 800; }
502
506
  .yd-av.b { background: var(--cz-bluebg); color: var(--cz-blueink); }
507
+ .yd-av.sp { background: var(--cz-bluebg); color: var(--cz-blue); border-radius: 10px; }
503
508
  .yd-nw .yd-mt b { font-weight: 600; }
504
509
  .yd-more { align-self: flex-start; border: 0; background: none; padding: 6px 6px 8px 58px; min-height: 36px; font: inherit; font-size: var(--fs-3); font-weight: 700; color: var(--cz-blueink); cursor: pointer; }
505
510
  .yd-all { width: 40px; height: 40px; border-radius: 20px; border: 0; background: none; color: var(--cz-ink2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
@@ -36,8 +36,9 @@
36
36
  * sub one quiet line under the title: what the item is when the title is its parent's name (a program's "Charter", canvas MsBCharter)
37
37
  * chip { n, label, on(button) }: the blue ✦ with its count right after the title (what Claude proposes on an initiative, batch 12
38
38
  * items 2, 3 and 4, canvas In development PiA0/TpA1). Hidden at zero. setChip(id, chip) changes it while the item is shown.
39
- * presses [{ act, label, icon, text?, solid?, pressed? }]: the item's own presses before ⋯ (a program's charter icon, canvas MsB0Entry; the
40
- * charter's Save, MsBCharter). text draws the word beside the icon (not on a phone); solid is the one dark primary.
39
+ * presses [{ act, label, icon, text?, solid?, blue?, pressed? }]: the item's own presses before ⋯ (a program's charter icon, canvas MsB0Entry; the
40
+ * charter's Save, MsBCharter). text draws the word beside the icon (not on a phone); solid is the one dark primary; blue
41
+ * makes it the round blue ✓ a form saves with (batch 18 item 2-C, canvas OvA8People, OvA9Docs).
41
42
  * onPress(act, button) runs them. setPresses(id, list) changes them while the item is shown (Save shows only after a change).
42
43
  * guard (go, anchor) → true when the item holds unsaved changes and asks first: Close, ←, Escape and another open() call it, and
43
44
  * nothing leaves until the caller runs go() (canvas MsB5Leave: Save or Discard). false or none: it leaves at once.
@@ -134,7 +135,7 @@ export function headHtml(it) {
134
135
  const more = typeof o.more === 'function' || (Array.isArray(o.more) && o.more.some((m) => m && !m.sep)) || o.url ? ib('more', 'More', P.more, ' aria-haspopup="menu" aria-expanded="false"') : '';
135
136
  const add = o.add && o.add.label && !phone ? ib('add', o.add.label, P.add) : '';
136
137
  const own = (o.presses || []).filter((x) => x && x.act && x.label).map((x) => x.solid
137
- ? `<button type="button" class="cz-vw-pri${x.text && !phone ? '' : ' i'}" data-cz-vw="press" data-cz-vw-p="${esc(x.act)}" aria-label="${esc(x.label)}" title="${esc(x.label)}">${svg(path(x.icon), 15, 2.2)}${x.text && !phone ? `<span>${esc(x.text)}</span>` : ''}</button>`
138
+ ? `<button type="button" class="cz-vw-pri${x.text && !phone ? '' : ' i'}${x.blue ? ' blue' : ''}" data-cz-vw="press" data-cz-vw-p="${esc(x.act)}" aria-label="${esc(x.label)}" title="${esc(x.label)}">${svg(path(x.icon), 15, 2.2)}${x.text && !phone ? `<span>${esc(x.text)}</span>` : ''}</button>`
138
139
  : `<button type="button" class="cz-vw-ib" data-cz-vw="press" data-cz-vw-p="${esc(x.act)}" aria-label="${esc(x.label)}" title="${esc(x.label)}"${x.pressed != null ? ` aria-pressed="${x.pressed ? 'true' : 'false'}"` : ''}>${svg(path(x.icon), 18)}</button>`).join('');
139
140
  const sub = o.sub ? `<p class="cz-vw-sub">${esc(o.sub)}</p>` : '';
140
141
  const chip = o.chip && (o.chip.n > 0 || o.chip.looking) ? `<button type="button" class="cz-vw-chip${o.chip.looking ? ' live' : ''}" data-cz-vw="chip" aria-haspopup="dialog" aria-label="${esc(o.chip.label || 'Claude proposes ' + o.chip.n + '. Open')}" title="${esc(o.chip.label || 'Claude proposes')}">${svg(ICONS.spark, 13, 2)}${o.chip.n > 0 ? `<b>${esc(o.chip.n)}</b>` : ''}</button>` : '';
@@ -17,6 +17,8 @@
17
17
  .cz-vw-pri { height: 36px; padding: 0 14px; margin: 0 4px; border-radius: 999px; border: 0; background: var(--cz-ink); color: var(--cz-card); font: inherit; font-size: var(--fs-3); font-weight: 700; display: inline-flex; align-items: center; gap: 6px; flex: none; cursor: pointer; }
18
18
  .cz-vw-pri.i { width: 40px; height: 40px; padding: 0; justify-content: center; }
19
19
  .cz-vw-pri:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
20
+ .cz-vw-pri.blue { background: var(--cz-solid); color: var(--cz-onsolid); } /* a form's round ✓ (batch 18 item 2-C, canvas OvA8People) */
21
+ @media (max-width: 760px) { .cz-vw-pri.i { width: 44px; height: 44px; } } /* 44 px targets on a phone */
20
22
  .cz-vw-ib { border-radius: 999px; }
21
23
 
22
24
  /* rename (canvas RnATask, RnAIni, RnAProg, RnAPhone): the title is the press; a tap makes it one field with a blue check */
@@ -173,3 +175,50 @@ body.cz-vw-rail [data-cz-vw-list] > :not(.cz-vw-railbar), body.cz-vw-rail #hmLis
173
175
  .cz-vw-chip:not(:has(b)) { padding: 0 6px; }
174
176
  .cz-vw-chip:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 1px; }
175
177
  @media (max-width: 760px) { .cz-vw-chip { min-height: 32px; } }
178
+
179
+ /* a form in the Viewer (batch 18 item 2-C, canvas OvA8People, OvA9Docs): ✓ in the header saves, ← cancels. Labels over 44 px fields,
180
+ * one-choice chips, a quiet note and a ✦ line; the same on Home and the Board (cozy-home.css is not loaded on the Board) */
181
+ .czf { display: flex; flex-direction: column; gap: 14px; margin: 0; }
182
+ .czf-l[hidden] { display: none; }
183
+ .czf-l { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-2); font-weight: 700; color: var(--cz-ink2); }
184
+ .czf-l input, .czf-l select { font: inherit; font-size: var(--fs-3); font-weight: 500; color: var(--cz-ink); height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--cz-hair); background: var(--cz-card); box-sizing: border-box; width: 100%; }
185
+ .czf-l input::placeholder { color: var(--cz-ink3); }
186
+ .czf-l input:disabled { background: var(--cz-well); color: var(--cz-ink3); }
187
+ .czf-l input:focus-visible, .czf-l select:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 1px; }
188
+ .czf-chips { display: flex; flex-wrap: wrap; gap: 8px; }
189
+ .czf-chips .cz-chip { height: 36px; padding: 0 14px; font-weight: 600; }
190
+ .czf-chips .cz-chip[aria-pressed="true"] { background: var(--cz-bluebg); border-color: transparent; color: var(--cz-blueink); font-weight: 700; }
191
+ .czf-chips .cz-chip svg { width: 13px; height: 13px; }
192
+ .czf-note { margin: 0; font-size: var(--fs-2); line-height: 1.45; color: var(--cz-ink3); }
193
+ .czf-spark { margin: 0; display: flex; gap: 8px; font-size: var(--fs-3); line-height: 1.5; color: var(--cz-ink2); }
194
+ .czf-spark svg { flex: none; width: 14px; height: 14px; margin-top: 4px; color: var(--cz-blue); }
195
+ .czf-err { margin: 0; font-size: var(--fs-2); color: var(--cz-red); }
196
+ .czf-err:empty { display: none; }
197
+ .czs-quiet { margin: 0; font-size: var(--fs-2); color: var(--cz-ink3); }
198
+ @media (max-width: 760px), (pointer: coarse) { .czf-chips .cz-chip { height: 44px; } .czf-l input, .czf-l select { font-size: var(--fs-4); } }
199
+
200
+ /* the Viewer's title wraps to two lines, then clamps (batch 18 item 2, the one pattern: OvA1Start). A title with Claude's ✦ chip keeps one. */
201
+ .cz-vw-title:not(.has-chip) { white-space: normal; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; overflow-wrap: anywhere; }
202
+ .cz-vw-hd { align-items: center; }
203
+
204
+ /* an ask's summary (batch 18 item 2-A, OvA1Start, OvA3Waited): ✦ Claude's offer, the progress of what it started, the amber "If it waits" line */
205
+ .nv { display: flex; flex-direction: column; gap: 12px; }
206
+ .nv-offer, .nv-cost { margin: 0; display: flex; gap: 8px; align-items: flex-start; font-size: var(--fs-3); line-height: 1.5; color: var(--cz-ink); }
207
+ .nv-offer svg { flex: none; margin-top: 3px; color: var(--cz-blueink); }
208
+ .nv-cost { font-size: var(--fs-2); font-weight: 700; color: var(--cz-risk); }
209
+ .nv-cost svg { flex: none; margin-top: 2px; }
210
+ .nv-bar { height: 6px; border-radius: 99px; background: var(--cz-hair); overflow: hidden; }
211
+ .nv-bar > span { display: block; height: 100%; border-radius: 99px; background: var(--cz-blue); }
212
+ .czs-pri svg { flex: none; }
213
+ /* the quiet owner line under the card: whose it is, the kind of work in words, the goal it moves */
214
+ .nv-own { margin: 0; display: flex; align-items: center; gap: 8px; font-size: var(--fs-2); font-weight: 600; color: var(--cz-ink3); line-height: 1.4; }
215
+ .nv-av { width: 22px; height: 22px; border-radius: 50%; background: var(--cz-bluebg); color: var(--cz-blueink); font-size: var(--fs-1); font-weight: 800; display: inline-grid; place-items: center; flex: none; }
216
+ /* a decision: the choices, Claude's pick marked, the why it wrote, and Record with its words */
217
+ .nv-dec { display: flex; flex-direction: column; gap: 8px; }
218
+ .nv-pick { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--cz-card); color: var(--cz-blueink); font-size: var(--fs-1); font-weight: 800; }
219
+ .nv .ut-field label em { font-style: normal; font-weight: 600; color: var(--cz-ink3); }
220
+ .nv-facts { margin: 0; display: grid; gap: 6px; }
221
+ .nv-facts div { display: grid; grid-template-columns: 110px 1fr; gap: 10px; }
222
+ .nv-facts dt { color: var(--cz-ink3); font-size: var(--fs-2); }
223
+ .nv-facts dd { margin: 0; overflow-wrap: anywhere; }
224
+ .nv-rev .czs-cv { align-self: center; font-size: var(--fs-4); }
@@ -1,48 +1,68 @@
1
- /* home-adddoc.js — Add a document, in Home's Viewer (premium-agreed-design; initiative briefing-premium-adddoc).
2
- * Drawn in the Viewer's card shape (canvas HmMyWork: the title, the fields, the foot with the press). It is the form the old
3
- * dialog had (title, phase, who writes it, where it lives, the address) and its one press posts to POST /api/custom-docs/add, nothing else.
1
+ /* home-adddoc.js — Add a document, in Home's Viewer (premium-agreed-design; initiative briefing-premium-adddoc; batch 18 item 2-C, canvas OvA9Docs).
2
+ * Shell A's form: ✓ in the header adds, ← cancels. A short note line, the title, Stage chips (an initiative only), Who writes it chips,
3
+ * Where it lives, and the page address only when it does not live in PMOS. Its one press posts to POST /api/custom-docs/add, nothing else.
4
4
  *
5
5
  * openAddDocVw({ VW, pmPost, toast, ws, scope, phases, title, back, onAdded })
6
6
  * VW the Home Viewer host (cozy-viewer): open({ id, kind, title, icon, render }) gives the body to draw in
7
7
  * ws the workspace the record is written in; scope 'initiative:<id>' or 'board:<id>'
8
- * phases the stages a phase can name (an initiative only); back() reopens what the form came from (Cancel)
8
+ * phases the stages a phase can name (an initiative only); back() reopens what the form came from (←)
9
9
  * onAdded awaited after the route answers ok
10
10
  */
11
11
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
12
12
  const KINDS = ['Confluence', 'Google Docs', 'Google Slides'];
13
+ const I = { doc: 'M7 3h7l5 5v13H7zM14 3v5h5', check: 'M5 12.5l4.5 4.5L19 7.5', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z' };
14
+ const svg = (d) => `<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
15
+ /** The ✦ line under the form: what happens to the record, said once, for the choices made. Pure. */
16
+ export function whereLine(kind, who) {
17
+ if (kind) return 'It is saved on the record with the ' + kind + ' page’s address. PMOS does not read or sync that page.';
18
+ return (who === 'you' ? 'You write it, and it is saved on the record.' : 'It is saved on the record as mine to draft.') + ' Pick Confluence or Google Docs to paste a page address instead.';
19
+ }
13
20
 
14
21
  export function openAddDocVw(o) {
15
22
  const ini = String(o.scope).startsWith('initiative:');
16
23
  const phases = (o.phases && o.phases.length ? o.phases : ['Discover', 'Plan', 'Build', 'Evaluate']);
17
- let who = 'drafts';
24
+ const X = { who: 'drafts', phase: phases[0], kind: '', busy: false };
25
+ const chips = (id, label, list, cur, attr) => `<div class="czf-l" role="group" aria-label="${label}"><span>${label}</span><div class="czf-chips" id="${id}">${list.map(([v, t, ic]) => `<button type="button" class="cz-chip" ${attr}="${esc(v)}" aria-pressed="${v === cur}">${ic ? svg(ic) : ''}${esc(t)}</button>`).join('')}</div></div>`;
18
26
  const draw = (b) => {
19
- b.innerHTML = `<div class="hx-sec hm-adf ut-vc"><div><h2 class="ut-h2">Add a document</h2>${o.title ? `<p class="ut-sub">${esc(o.title)}</p>` : ''}</div>`
20
- + `<p class="ut-small ut-mut" data-ad-note>Add a document the core set does not cover, for example a research plan, a UAT plan or a contract. It is saved on the ${ini ? 'initiative' : 'board'}'s record with the address of a copy that lives in Confluence or Google Docs. PMOS does not read or sync that page.</p>`
21
- + `<label class="hv-why"><span>Title</span><input id="adT" maxlength="80" placeholder="For example: UAT plan" autocomplete="off"></label>`
22
- + (ini ? `<label class="hv-why"><span>Phase</span><select id="adPh">${phases.map((k) => `<option>${esc(k)}</option>`).join('')}</select></label>` : '')
23
- + `<div class="hv-why"><span>Who writes it</span><div class="hx-tabs" id="adW" role="group" aria-label="Who writes it"><button type="button" data-w="drafts" aria-pressed="true">PMOS drafts it</button><button type="button" data-w="you" aria-pressed="false">I write it</button></div></div>`
24
- + `<label class="hv-why"><span>Where it lives</span><select id="adK"><option value="">In PMOS</option>${KINDS.map((k) => `<option>${k}</option>`).join('')}</select></label>`
25
- + `<label class="hv-why"><span>Page address</span><input id="adU" maxlength="300" placeholder="Paste the page address" disabled autocomplete="off"></label>`
26
- + `<p class="hx-n" id="adM" role="status"></p>`
27
- + `<div class="ut-foot"><button type="button" class="ut-btn pri" id="adGo">Add document</button><button type="button" class="ut-btn ghost" id="adNo">Cancel</button></div></div>`;
27
+ b.innerHTML = `<form class="czf hm-adf" data-czf-adddoc novalidate>`
28
+ + `<p class="czf-note" data-ad-note>For a document the core set does not cover, like a UAT plan or a contract.</p>`
29
+ + `<label class="czf-l"><span>Title</span><input id="adT" maxlength="80" placeholder="For example: UAT plan" autocomplete="off"></label>`
30
+ + (ini ? chips('adPh', 'Stage', phases.map((k) => [k, k]), X.phase, 'data-ph') : '')
31
+ + chips('adW', 'Who writes it', [['drafts', 'I draft it', I.spark], ['you', 'You write it']], X.who, 'data-w')
32
+ + `<label class="czf-l"><span>Where it lives</span><select id="adK"><option value="">In PMOS</option>${KINDS.map((k) => `<option>${k}</option>`).join('')}</select></label>`
33
+ + `<label class="czf-l" id="adUL" hidden><span>Page address</span><input id="adU" maxlength="300" placeholder="Paste the page address" autocomplete="off"></label>`
34
+ + `<p class="czf-spark" id="adS">${svg(I.spark)}<span>${esc(whereLine(X.kind, X.who))}</span></p>`
35
+ + `<p class="czf-err" id="adM" role="status"></p><button type="submit" hidden></button></form>`;
28
36
  };
29
- const body = o.VW.open({ id: 'adddoc:' + o.scope, kind: 'New document', title: 'Add a document' + (o.title ? ' · ' + o.title : ''), icon: 'doc', render: draw });
37
+ const body = o.VW.open({ id: 'adddoc:' + o.scope, kind: 'New document', title: 'Add a document', sub: o.title || '', icon: I.doc, back: true,
38
+ presses: [{ act: 'add', label: 'Add the document', icon: I.check, solid: true, blue: true }],
39
+ onPress: (a) => { if (a === 'add') add(); },
40
+ render: draw });
30
41
  const $ = (s) => body.querySelector(s);
31
- body.onchange = (e) => { if (e.target.id === 'adK') { $('#adU').disabled = !e.target.value; if (e.target.value) $('#adU').focus(); } };
32
- body.onclick = async (e) => {
33
- const w = e.target.closest('[data-w]');
34
- if (w) { who = w.dataset.w; body.querySelectorAll('#adW button').forEach((x) => x.setAttribute('aria-pressed', String(x === w))); return; }
35
- if (e.target.closest('#adNo')) { if (o.back) o.back(); return; }
36
- if (!e.target.closest('#adGo')) return;
37
- const title = $('#adT').value.trim(), m = $('#adM'), kind = $('#adK').value, url = ($('#adU').value || '').trim();
42
+ const say = () => { const s = $('#adS span'); if (s) s.textContent = whereLine(X.kind, X.who); };
43
+ body.onchange = (e) => {
44
+ if (e.target.id !== 'adK') return;
45
+ X.kind = e.target.value; $('#adUL').hidden = !X.kind; say();
46
+ if (X.kind) $('#adU').focus();
47
+ };
48
+ body.onclick = (e) => {
49
+ const w = e.target.closest('[data-w]'), ph = e.target.closest('[data-ph]');
50
+ if (w) { X.who = w.dataset.w; body.querySelectorAll('#adW [data-w]').forEach((x) => x.setAttribute('aria-pressed', String(x === w))); say(); }
51
+ if (ph) { X.phase = ph.dataset.ph; body.querySelectorAll('#adPh [data-ph]').forEach((x) => x.setAttribute('aria-pressed', String(x === ph))); }
52
+ };
53
+ body.addEventListener('submit', (e) => { e.preventDefault(); add(); });
54
+ async function add() {
55
+ if (X.busy) return;
56
+ const title = $('#adT').value.trim(), m = $('#adM'), kind = X.kind, url = ($('#adU').value || '').trim();
38
57
  if (!title) { m.textContent = 'Give the document a title.'; $('#adT').focus(); return; }
39
58
  if (kind && !url) { m.textContent = 'Paste the address of the ' + kind + ' page, or choose In PMOS.'; $('#adU').focus(); return; }
40
- const go = $('#adGo'); go.disabled = true;
41
- const res = await o.pmPost('/api/custom-docs/add', { ws: o.ws, scope: o.scope, title, writer: who, phase: ini ? $('#adPh').value : undefined, kind: kind || undefined, url: kind ? url : undefined });
42
- if (!res || res.ok !== true) { go.disabled = false; m.textContent = (res && res.error) || 'The document could not be added.'; return; }
59
+ X.busy = true; m.textContent = '';
60
+ const res = await o.pmPost('/api/custom-docs/add', { ws: o.ws, scope: o.scope, title, writer: X.who, phase: ini ? X.phase : undefined, kind: kind || undefined, url: kind ? url : undefined });
61
+ X.busy = false;
62
+ if (!res || res.ok !== true) { m.textContent = (res && res.error) || 'The document could not be added.'; return; }
43
63
  o.toast('Document added. It is saved on the record.');
44
64
  if (o.onAdded) await o.onAdded();
45
- };
65
+ }
46
66
  const t = $('#adT'); if (t) t.focus();
47
67
  return body;
48
68
  }