create-pmos 0.440.0 → 0.442.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 (95) hide show
  1. package/package.json +25 -25
  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/adler-seasons-art-test.js +106 -0
  7. package/workspace/adler-seasons-test.js +111 -0
  8. package/workspace/briefing-premium-adddoc-test.js +16 -13
  9. package/workspace/briefing-premium-board-test.js +19 -17
  10. package/workspace/briefing-premium-initiative-test.js +7 -4
  11. package/workspace/briefing-premium-products-test.js +4 -4
  12. package/workspace/briefing-premium-sources-test.js +2 -2
  13. package/workspace/briefing-premium-test.js +29 -23
  14. package/workspace/changelog.json +24 -0
  15. package/workspace/guide/adler.md +10 -0
  16. package/workspace/guide/core-documents.md +2 -2
  17. package/workspace/guide/data-freshness.md +7 -5
  18. package/workspace/guide/home.md +3 -1
  19. package/workspace/guide/horizon-scan.md +1 -1
  20. package/workspace/ini-workflow-test.js +6 -2
  21. package/workspace/lib/agent-inbox.js +20 -2
  22. package/workspace/lib/briefing-premium-sources.js +3 -0
  23. package/workspace/lib/briefing-premium.js +37 -7
  24. package/workspace/lib/driver-cli.js +1 -1
  25. package/workspace/lib/driver-run.js +15 -1
  26. package/workspace/lib/driver.js +31 -2
  27. package/workspace/lib/news-for-you.js +24 -9
  28. package/workspace/lib/pm-idle.js +12 -0
  29. package/workspace/lib/refresh.js +17 -8
  30. package/workspace/lib/routes-core-docs.js +1 -1
  31. package/workspace/lib/routes-news.js +15 -1
  32. package/workspace/lib/routes-phone-day.js +6 -4
  33. package/workspace/lib/settings-store.js +38 -0
  34. package/workspace/metric-drafts-ui-test.js +2 -2
  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-board-actions-test.js +2 -1
  40. package/workspace/premium-chat-attach-test.js +2 -0
  41. package/workspace/premium-core-doc-issue-test.js +9 -8
  42. package/workspace/program-panel-test.js +1 -1
  43. package/workspace/public/pm/bd-ini-panel.js +6 -13
  44. package/workspace/public/pm/c3-ini-ui.js +1 -1
  45. package/workspace/public/pm/cozy-adler.css +21 -0
  46. package/workspace/public/pm/cozy-adler.js +415 -8
  47. package/workspace/public/pm/cozy-ev.css +44 -0
  48. package/workspace/public/pm/cozy-home.css +8 -0
  49. package/workspace/public/pm/cozy-news.js +186 -22
  50. package/workspace/public/pm/cozy-seasons.js +318 -0
  51. package/workspace/public/pm/cozy-settings.js +88 -5
  52. package/workspace/public/pm/cozy-today.css +5 -0
  53. package/workspace/public/pm/cozy-viewer.js +12 -7
  54. package/workspace/public/pm/cozy-vw-shell.css +49 -0
  55. package/workspace/public/pm/cozy.css +65 -0
  56. package/workspace/public/pm/dash-view.js +4 -2
  57. package/workspace/public/pm/home-adddoc.js +46 -26
  58. package/workspace/public/pm/home-app.js +142 -114
  59. package/workspace/public/pm/home-chat.js +1 -1
  60. package/workspace/public/pm/home-day.js +17 -9
  61. package/workspace/public/pm/home-draft.js +35 -23
  62. package/workspace/public/pm/home-ini.js +4 -4
  63. package/workspace/public/pm/home-mentions.js +1 -1
  64. package/workspace/public/pm/home-need.js +336 -0
  65. package/workspace/public/pm/home-today.js +2 -2
  66. package/workspace/public/pm/home-work.js +51 -4
  67. package/workspace/public/pm/impact.js +1 -1
  68. package/workspace/public/pm/ini-groups.js +15 -10
  69. package/workspace/public/pm/ini-links.js +1 -1
  70. package/workspace/public/pm/ini-tasks.js +208 -44
  71. package/workspace/public/pm/ini-view-model.js +8 -2
  72. package/workspace/public/pm/ini-view.css +305 -1
  73. package/workspace/public/pm/ini-view.js +190 -80
  74. package/workspace/public/pm/mission.js +234 -0
  75. package/workspace/public/pm/premium-board.js +1 -1
  76. package/workspace/public/pm/premium-welcome.js +2 -2
  77. package/workspace/public/pm/small-vw.js +128 -0
  78. package/workspace/public/pm/split-merge.js +1 -1
  79. package/workspace/public/pm/stage-line.js +2 -2
  80. package/workspace/server.js +10 -6
  81. package/workspace/skills/initiative-drive.skill +4 -1
  82. package/workspace/split-merge-ui-test.js +1 -1
  83. package/workspace/stage-card-test.js +48 -11
  84. package/workspace/task-links-test.js +2 -0
  85. package/workspace/task-milestones-test.js +5 -1
  86. package/workspace/task-plans-test.js +3 -3
  87. package/workspace/task-views-test.js +90 -37
  88. package/workspace/test-lists/adler-seasons-art.json +13 -0
  89. package/workspace/test-lists/batch18-adler-seasons.json +13 -0
  90. package/workspace/test-lists/batch18-asks.json +5 -0
  91. package/workspace/test-lists/mission.json +5 -0
  92. package/workspace/test-lists/news-viewers.json +13 -0
  93. package/workspace/test-lists/small-viewers.json +5 -0
  94. package/workspace/test-lists/viewer-tasks.json +5 -0
  95. package/workspace/tk-tasks-test.js +25 -30
@@ -45,6 +45,7 @@
45
45
  .cz .ev-dot.you { background: var(--cz-blue); } .cz .ev-dot.risk { background: var(--cz-dot-risk); } .cz .ev-dot.ok { background: var(--cz-dot-ok); } .cz .ev-dot.none { background: transparent; }
46
46
  .cz .ev-av { width: 22px; height: 22px; border-radius: 50%; background: var(--cz-well2); color: var(--cz-ink2); font-size: var(--fs-1); font-weight: 800; display: inline-flex; align-items: center; justify-content: center; flex: none; }
47
47
  .cz .ev-av.b { background: var(--cz-bluebg); color: var(--cz-blueink); }
48
+ .cz .ev-av.sp { border-radius: 7px; background: var(--cz-bluebg); color: var(--cz-blue); }
48
49
  .cz .ev-trow { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--cz-hair); font-size: var(--fs-3); color: var(--cz-ink); }
49
50
  .cz .ev-trow:last-child { border-bottom: 0; }
50
51
  .cz .ev-trow p { margin: 0; }
@@ -243,6 +244,20 @@
243
244
  .cz .ev-ad-hd { display: flex; align-items: center; gap: 12px; padding: 4px 4px 10px; }
244
245
  .cz .ev-sp-ad { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
245
246
  .cz .ev-sp-ad p { margin: 0; }
247
+ /* Settings › Adler › Dress for the day (feedback batch 18 item 8, AsSet1): the header with its master switch, what he wears now or next,
248
+ * the place pickers, the More festivals list under its row, and Wear now */
249
+ .ev-st .ev-dr-hd { display: flex; align-items: center; gap: 8px; margin: 0 0 4px -6px; }
250
+ .ev-st .ev-dr-hd h4 { margin: 0; font-size: var(--fs-4); font-weight: 800; }
251
+ .ev-st .ev-dr-now { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; background: var(--cz-well); }
252
+ .ev-st .ev-dr-now p { margin: 0; display: flex; flex-direction: column; gap: 2px; }
253
+ .ev-st .ev-dr-pl { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
254
+ .ev-st .ev-dr-pl select.ev-inp { max-width: 190px; }
255
+ .ev-st .ev-dr-more { padding-left: 16px; border-left: 2px solid var(--cz-hair); }
256
+ .ev-st .ev-dr-more .ev-trow { padding: 8px 0; }
257
+ .ev-st .ev-dr-wbtns { display: flex; gap: 10px; }
258
+ .ev-st .ev-wear { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 12px; border-radius: 16px; border: 1px solid var(--cz-hair); background: var(--cz-card); color: var(--cz-ink); font: inherit; cursor: pointer; min-width: 88px; }
259
+ .ev-st .ev-wear[aria-pressed="true"] { background: var(--cz-bluebg); color: var(--cz-blueink); border-color: transparent; }
260
+ @media (max-width: 760px) { .ev-st .ev-dr-pl { width: 100%; justify-content: flex-start; } .ev-st .ev-dr-pl select.ev-inp { max-width: none; flex: 1; } .ev-st .ev-dr-hd .ev-ib { width: 44px; height: 44px; } }
246
261
  /* Settings › Connectors: each source's last read (feedback batch 16 item 5, FmA3Settings; was the Sources card), and the amber box on top */
247
262
  .ev-st-main > .ev-st-warn { margin-bottom: 12px; color: var(--cz-ink); }
248
263
  .ev-st-warn .ev-ib-card { background: var(--cz-card); }
@@ -252,3 +267,32 @@
252
267
  .ev-st .ev-ib-sp { width: 32px; flex: none; }
253
268
  .ev-st-nav .ev-mi .ev-dot.risk { margin-left: 6px; }
254
269
  .ev-st .ev-rl { margin: 4px 0; }
270
+
271
+ /* New for you's item Viewers (batch 18 items 2 and 2b, canvas OvA5Overlap, OvA6Given): the summary, then the two initiatives, the pick and ONE primary */
272
+ .nv { display: flex; flex-direction: column; gap: 10px; }
273
+ .nv-ini, .nv-opt { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 12px 14px; border: 1px solid var(--cz-hair); border-radius: 14px; background: var(--cz-card); color: var(--cz-ink); text-align: left; font: inherit; cursor: pointer; }
274
+ .nv-ini:hover, .nv-opt:hover { background: var(--cz-well); }
275
+ .nv-it { width: 32px; height: 32px; border-radius: 10px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--cz-bluebg); color: var(--cz-blueink); }
276
+ .nv-tx { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
277
+ .nv-tx b { font-size: var(--fs-3); font-weight: 800; overflow-wrap: anywhere; }
278
+ .nv-tx em { font-style: normal; font-size: var(--fs-1); color: var(--cz-ink3); }
279
+ .nv-nth { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--cz-well2); color: var(--cz-ink2); font-size: var(--fs-1); font-weight: 800; }
280
+ .nv-opts { display: flex; flex-direction: column; gap: 8px; }
281
+ .nv-opt { align-items: flex-start; }
282
+ .nv-opt.on { border-color: var(--cz-blue); background: var(--cz-bluebg); }
283
+ .nv-rd { width: 18px; height: 18px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--cz-ink3); flex: none; box-sizing: border-box; }
284
+ .nv-opt.on .nv-rd { border: 5px solid var(--cz-blue); }
285
+ /* "I’d do this" on the overlap choice the agent recommends (batch 18 item 2-B); not .nv-rec, which is the ask Viewer's Record press (2-A) */
286
+ .nv-idd { 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; vertical-align: 1px; }
287
+ .nv-go { padding-top: 2px; }
288
+ .nv-pri svg { flex: none; }
289
+ .nv-parts { margin: 0; padding: 0 0 0 18px; display: flex; flex-direction: column; gap: 6px; color: var(--cz-ink2); }
290
+ .nv-sp { display: inline-flex; vertical-align: -2px; margin-right: 6px; color: var(--cz-blue); }
291
+ .nv-when { display: flex; flex-wrap: wrap; gap: 8px; }
292
+ .nv-rows { border: 1px solid var(--cz-hair); border-radius: 14px; background: var(--cz-card); overflow: hidden; }
293
+ .nv-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 14px; border: 0; background: none; color: var(--cz-ink); font: inherit; text-align: left; cursor: pointer; }
294
+ .nv-row + .nv-row { border-top: 1px solid var(--cz-hair); }
295
+ .nv-row:disabled { cursor: default; }
296
+ .nv-row b { flex: none; font-weight: 800; }
297
+ .nv-row span { flex: 1; min-width: 0; text-align: right; color: var(--cz-ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
298
+ .nv-row svg { flex: none; color: var(--cz-ink3); }
@@ -560,6 +560,14 @@ form.hm-box textarea { min-height: 48px; border: 0; background: none; resize: no
560
560
  .vwgoal .gpts li.sk s { color: var(--cz-ink3); }
561
561
  .hm-chat .atrow { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
562
562
  .hm-chat .atc { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 10px; background: var(--cz-card); font-size: var(--fs-2); cursor: pointer; border: 1px solid var(--cz-hair); }
563
+ /* batch 18 item 13: the chip's picture is a 36 px thumbnail (premium.css is not loaded on Home, so a pasted screenshot drew at full size out of
564
+ the bubble); the chip opens the file beside the conversation */
565
+ .hm-chat .atc { max-width: min(260px, 100%); min-width: 0; }
566
+ .atc .ath { width: 36px; height: 36px; border-radius: 8px; flex: none; object-fit: cover; background: var(--cz-well); display: block; }
567
+ .atc .atx { display: grid; place-items: center; font-size: var(--fs-1); font-weight: 700; letter-spacing: .04em; color: var(--cz-ink3); }
568
+ .atc .atn { display: grid; min-width: 0; text-align: left; }
569
+ .atc .atn b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
570
+ .atc .atn em { font-style: normal; font-size: var(--fs-1); color: var(--cz-ink3); }
563
571
  .hm-peek { display: flex; align-items: center; gap: 10px; min-height: 40px; margin-top: 8px; padding: 0 14px; border: 0; border-radius: 12px; background: var(--cz-bluebg); color: var(--cz-ink); font-size: var(--fs-2); cursor: pointer; text-align: left; }
564
572
  .hm-peek[hidden] { display: none; }
565
573
  .hm-peek span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@@ -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-idd">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
+ }