create-pmos 0.476.0 → 0.477.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 (82) hide show
  1. package/package.json +20 -14
  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/board-publish-ui-test.js +11 -16
  7. package/workspace/board-shared-ui-test.js +34 -33
  8. package/workspace/changelog.json +19 -0
  9. package/workspace/guide/briefing-premium.md +2 -2
  10. package/workspace/guide/claude-proposes.md +3 -1
  11. package/workspace/guide/forecast.md +16 -3
  12. package/workspace/guide/home.md +2 -2
  13. package/workspace/guide/workflows.md +13 -2
  14. package/workspace/home-railcard-test.js +4 -4
  15. package/workspace/home-rows-test.js +15 -4
  16. package/workspace/ini-workflow-test.js +1 -1
  17. package/workspace/lib/board-pack.js +20 -1
  18. package/workspace/lib/board-trail.js +17 -1
  19. package/workspace/lib/boards-host.js +22 -2
  20. package/workspace/lib/briefing-premium-agent.js +2 -2
  21. package/workspace/lib/engine/boards.js +15 -3
  22. package/workspace/lib/engine/workflows.js +79 -10
  23. package/workspace/lib/forecast-offer.js +57 -0
  24. package/workspace/lib/grill-runs.js +1 -0
  25. package/workspace/lib/grill.js +1 -1
  26. package/workspace/lib/insight-moves.js +8 -6
  27. package/workspace/lib/news-for-you.js +6 -4
  28. package/workspace/lib/report-chat.js +2 -0
  29. package/workspace/lib/routes-board-publish.js +7 -2
  30. package/workspace/lib/routes-boards.js +18 -5
  31. package/workspace/lib/routes-briefing-premium.js +16 -2
  32. package/workspace/lib/routes-forecast.js +8 -1
  33. package/workspace/lib/routes-insight-moves.js +7 -5
  34. package/workspace/lib/routes-news.js +3 -1
  35. package/workspace/lib/routes-workflows.js +13 -0
  36. package/workspace/lib/wf-bridge.js +165 -0
  37. package/workspace/package-lock.json +2 -2
  38. package/workspace/package.json +1 -1
  39. package/workspace/panels-test.js +1 -2
  40. package/workspace/public/pm/bd-fc-card.js +45 -0
  41. package/workspace/public/pm/bd-next.js +1 -1
  42. package/workspace/public/pm/bd-publish.css +22 -18
  43. package/workspace/public/pm/bd-publish.js +57 -48
  44. package/workspace/public/pm/bd-shared.css +92 -30
  45. package/workspace/public/pm/bd-shared.js +143 -55
  46. package/workspace/public/pm/bd-span.js +27 -7
  47. package/workspace/public/pm/cozy-board.css +15 -0
  48. package/workspace/public/pm/cozy-ev.css +46 -0
  49. package/workspace/public/pm/cozy-home.css +4 -4
  50. package/workspace/public/pm/cozy-insights.css +21 -0
  51. package/workspace/public/pm/cozy-jl.js +158 -0
  52. package/workspace/public/pm/cozy-news.js +56 -2
  53. package/workspace/public/pm/cozy-panels.js +3 -2
  54. package/workspace/public/pm/cozy-settings.js +11 -7
  55. package/workspace/public/pm/cozy-today.css +3 -0
  56. package/workspace/public/pm/cozy-viewer.js +19 -3
  57. package/workspace/public/pm/goal-forecast.js +101 -0
  58. package/workspace/public/pm/hi-pop.css +16 -0
  59. package/workspace/public/pm/home-app.js +11 -4
  60. package/workspace/public/pm/home-day.js +5 -3
  61. package/workspace/public/pm/home-list.js +14 -4
  62. package/workspace/public/pm/home-mentions.js +5 -0
  63. package/workspace/public/pm/home-task.js +1 -1
  64. package/workspace/public/pm/home-today.js +11 -4
  65. package/workspace/public/pm/ini-view-model.js +27 -14
  66. package/workspace/public/pm/ini-view.js +1 -1
  67. package/workspace/public/pm/ini-wf-model.js +76 -19
  68. package/workspace/public/pm/ini-wf.js +69 -18
  69. package/workspace/public/pm/metric-drafts.css +9 -0
  70. package/workspace/public/pm/metric-drafts.js +2 -2
  71. package/workspace/public/pm/premium-board.js +13 -3
  72. package/workspace/public/pm/premium-insights.js +43 -6
  73. package/workspace/public/pm/premium-report-tab.js +13 -3
  74. package/workspace/public/pm/premium-vw-item.js +1 -1
  75. package/workspace/public/pm/readonly.js +1 -0
  76. package/workspace/public/pm/report-chat.js +2 -1
  77. package/workspace/public/pm/task-card.js +4 -3
  78. package/workspace/public/pm/wf-page.css +9 -0
  79. package/workspace/public/pm/wf-page.js +30 -1
  80. package/workspace/run-tests.js +10 -2
  81. package/workspace/server.js +5 -2
  82. package/workspace/test-lists/forecast-board.json +5 -0
@@ -0,0 +1,158 @@
1
+ /* pm/cozy-jl.js — Settings › Jev and Laya (canvas JlA1Empty, JlA2On, JlA3Failed, JlA4Phone; batch 20). It brings back, in the
2
+ * cozy Settings, what PR #1021 removed with the console: the TypeSafe key, the local model, and the per-repository switches.
3
+ * Page only: every control calls a route the server already has.
4
+ * Jev (the key) GET /api/typesafe · PUT and DELETE /api/typesafe/key (the key is never read back, only present or not)
5
+ * Laya POST /api/typesafe/local { backend: 'laya' | 'off' } · /api/typesafe/local/setup (a terminal with the
6
+ * commands typed in; the PM presses Enter) · /api/typesafe/local/test (one question to 127.0.0.1)
7
+ * per repository GET and POST /api/validate/repo { ws, consent } "Jev may read this repository" (D79)
8
+ * POST /api/doccat/jev { ws, categorize } Sort documents into categories (D82)
9
+ * POST /api/claims/watch { ws, watch } + /api/claims/jev { ws, jev } Check claims (both, D80)
10
+ * GET /api/notes/engine · POST /api/notes/switch { ws, jev | check } Label notes, Check notes (D91)
11
+ * With no key and no local model, Claude proposes Laya once as a ✦; the terminal icon approves it, ✕ hides it on this computer.
12
+ * html() · load(workspaces, redraw) · press(button, redraw, say) → true when the press was this section's · reset() */
13
+ import { pmGet, pmPost, pressFetch } from './http.js';
14
+ import { esc, svg, ICON } from './cozy-evui.js';
15
+
16
+ const IC = { term: 'M4 6l6 6-6 6M12 18h8', pulse: 'M3 12h4l2.5-6 4 12 2.5-6H21', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z' };
17
+ const NOT_NOW = 'pmos.cz.jl.laya-not-now';
18
+ const J = { key: null, err: '', repos: {}, test: null, busy: false, ws: [] };
19
+ const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* no storage */ } } };
20
+
21
+ async function send(method, path, body) {
22
+ try { const res = await pressFetch(path, { method, ...(body === undefined ? {} : { body: JSON.stringify(body) }) }); return await res.json(); }
23
+ catch (e) { return { ok: false, error: 'could not reach the workspace server: ' + ((e && e.message) || String(e)) }; }
24
+ }
25
+ const ib = (attr, label, d, pri) => `<button type="button" class="ev-ib${pri ? ' ev-jl-pri' : ''}" ${attr} aria-label="${esc(label)}" title="${esc(label)}">${svg(d, 18)}</button>`;
26
+ const sw = (on, attr, label, dis) => `<button type="button" class="ev-sw" role="switch" aria-checked="${!!on}" aria-label="${esc(label)}" ${attr}${dis ? ' disabled' : ''}>${on ? 'On' : 'Off'}</button>`;
27
+ const row = (title, sub, right, cls = '') => `<div class="ev-trow${cls}"><div class="ev-tx"><b>${esc(title)}</b>${sub ? `<p class="ev-small ev-mut">${esc(sub)}</p>` : ''}</div>${right}</div>`;
28
+
29
+ /** A saved key (or the environment's), not the local stand-in that status() also calls present. */
30
+ const keyed = () => !!(J.key && J.key.present && J.key.source !== 'local');
31
+ const local = () => (J.key && J.key.local) || null;
32
+
33
+ function repoHtml(w) {
34
+ const r = J.repos[w.id], name = w.label || w.name || w.id;
35
+ if (!r) return row(name, 'Reading.', '', ' ev-jl-r');
36
+ if (r.error) return row(name, 'Not read: ' + r.error, '', ' ev-jl-r');
37
+ const who = keyed() ? 'Jev' : local() ? 'Laya' : '';
38
+ const sub = r.consent ? (who ? who + ' may read the text of this repository.' : 'Allowed, but there is no key or Laya yet. Nothing is read.')
39
+ : who ? 'Off. ' + who + ' reads nothing from it.' : 'Needs a key or Laya first. Nothing is read.';
40
+ const left = r.consent && r.exclude && r.exclude.length ? `<span class="ev-pill">${r.exclude.length} left out</span>` : '';
41
+ const head = row(name, sub, left + sw(r.consent, `data-jl-sw="consent" data-ws="${esc(w.id)}"`, 'Jev may read ' + name), ' ev-jl-r');
42
+ if (!r.consent) return head;
43
+ const n = r.notes || {};
44
+ const sub2 = [
45
+ ['categorize', 'Sort documents into categories', 'Asks Jev about documents the local rules cannot place.', r.categorize],
46
+ ['claims', 'Check claims', 'Keeps claims.jsonl in the repository up to date and asks Jev only about changed pairs.', r.watch && r.jev],
47
+ ['label', 'Label notes', 'Names the line a meeting note is about. A private note is never sent.', n.jev],
48
+ ['check', 'Check notes against the repository', 'Says whether a note agrees with the closest passage.', n.check],
49
+ ];
50
+ return head + '<div class="ev-jl-ind">' + sub2.map(([k, t, s, on]) => row(t, s, sw(on, `data-jl-sw="${k}" data-ws="${esc(w.id)}"`, t + ' in ' + name, k === 'check' && !n.jev), ' ev-jl-r')).join('') + '</div>';
51
+ }
52
+
53
+ export function html() {
54
+ if (!J.key && !J.err) return '<p class="ev-small ev-mut">Reading Jev and Laya.</p>';
55
+ if (J.err) return `<p class="ev-small ev-mut">Jev and Laya could not be read: ${esc(J.err)}.</p>`;
56
+ const k = J.key, l = local(), has = keyed();
57
+ const propose = !has && !l && store.get(NOT_NOW) !== '1'
58
+ ? `<div class="ev-card ev-jl-need"><span class="ev-av sp" aria-hidden="true">${svg(IC.spark, 15)}</span><p>No key is saved, so Jev is asleep. <b>Laya</b> runs on this computer and needs no key. Set it up?</p>${ib('data-jl="setup"', 'Set up Laya: opens a terminal, you press Enter', IC.term, true)}${ib('data-jl="notnow"', 'Not now', ICON.close)}</div>` : '';
59
+ const keySub = has ? (k.source === 'environment' ? 'Set in TYPESAFE_API_KEY when PMOS started. A key saved here is used first.' : 'Saved on this computer only. PMOS never shows it again.') : 'Not set. Jev is asleep until you save one.';
60
+ const keyRight = (has ? '<span class="ev-jl-ok"><i class="ev-dot ok" aria-hidden="true"></i>Saved</span>' : '')
61
+ + `<label class="ev-vh" for="evJlKey">${has ? 'Replace the TypeSafe key' : 'TypeSafe key'}</label><input id="evJlKey" class="ev-inp ev-jl-key" type="password" autocomplete="off" spellcheck="false" placeholder="${has ? 'Replace the key' : 'Paste the key'}" data-jl-key>`
62
+ + ib('data-jl="keysave"', has ? 'Save the new key' : 'Save the key', ICON.check, !has)
63
+ + (has && k.source === 'settings' ? ib('data-jl="keyclear"', 'Remove the key', ICON.close) : '');
64
+ const isLaya = !!(l && l.backend === 'laya');
65
+ const laSub = l ? (isLaya ? 'Runs on this computer, port ' + l.port + '. Answers when there is no key, or when Jev cannot be reached.' : (l.name || l.backend) + ' is set on port ' + l.port + '. Choose Laya to use Laya instead.')
66
+ : 'A model that runs on this computer. Answers when there is no key, or when Jev cannot be reached.';
67
+ const seg = `<span class="ev-seg" role="group" aria-label="Local model"><button type="button" data-jl-local="off" aria-pressed="${!l}">Off</button><button type="button" data-jl-local="laya" aria-pressed="${isLaya}">Laya</button></span>`;
68
+ const laRight = seg + (l ? ib('data-jl="setup"', 'Set up Laya: opens a terminal with the commands typed in', IC.term) + ib('data-jl="test"', 'Test Laya', IC.pulse) : '');
69
+ const test = J.test ? `<p class="${J.test.ok ? 'ev-jl-ok' : 'ev-jl-bad'}" role="status"><i class="ev-dot ${J.test.ok ? 'ok' : 'risk'}" aria-hidden="true"></i>${esc(J.test.text)}</p>` : '';
70
+ const repos = J.ws.length ? `<p class="ev-mlbl ev-jl-lbl">Repositories</p><div class="ev-jl-rp">${J.ws.map(repoHtml).join('<div class="ev-jl-hr"></div>')}</div>` : '';
71
+ return '<p class="ev-small ev-mut ev-jl-lead">Advice only. Neither one changes your files.</p>' + propose
72
+ + row('Jev', keySub, `<span class="ev-jl-ctl">${keyRight}</span>`)
73
+ + row('Laya', laSub, `<span class="ev-jl-ctl">${laRight}</span>`) + test + repos;
74
+ }
75
+
76
+ async function loadRepo(w) {
77
+ const q = 'ws=' + encodeURIComponent(w.id);
78
+ const [v, e] = await Promise.all([pmGet('/api/validate/repo?' + q), pmGet('/api/notes/engine?' + q)]);
79
+ if (!v || v.ok === false) { J.repos[w.id] = { error: (v && v.error) || 'the server did not answer' }; return; }
80
+ J.repos[w.id] = { consent: !!v.consent, exclude: v.exclude || [], watch: !!v.watch, jev: !!v.jev, categorize: !!v.categorize, notes: e && e.ok && e.jev ? { jev: !!e.jev.jev, check: !!e.jev.check } : {} };
81
+ if (v.key) J.key = v.key;
82
+ }
83
+
84
+ export async function load(workspaces, redraw) {
85
+ const r = await pmGet('/api/typesafe');
86
+ if (r && r.ok) { J.key = r.key; J.err = ''; } else J.err = (r && r.error) || 'the server did not answer';
87
+ redraw();
88
+ if (!workspaces) return;
89
+ J.ws = workspaces;
90
+ await Promise.all(workspaces.map(loadRepo));
91
+ redraw();
92
+ }
93
+
94
+ export function reset() { J.key = null; J.err = ''; J.repos = {}; J.test = null; J.busy = false; J.ws = []; }
95
+
96
+ const SAID = {
97
+ consent: (on) => (on ? 'Saved. Jev may read this repository.' : 'Saved. Jev reads nothing from this repository.'),
98
+ categorize: (on) => (on ? 'Saved. Jev sorts the documents the local rules cannot place.' : 'Saved. Documents are sorted by the local rules only.'),
99
+ claims: (on) => (on ? 'Saved. Claims are checked as the files change.' : 'Saved. Claims are no longer checked by Jev.'),
100
+ label: (on) => (on ? 'Saved. Jev labels meeting note lines.' : 'Saved. Meeting note lines keep their local labels.'),
101
+ check: (on) => (on ? 'Saved. Jev checks notes against this repository.' : 'Saved. Notes are not checked against this repository.'),
102
+ };
103
+
104
+ async function flip(kind, ws) {
105
+ const r = J.repos[ws]; if (!r) return { ok: false, error: 'This repository is not read yet.' };
106
+ const n = r.notes || {};
107
+ if (kind === 'consent') { const out = await pmPost('/api/validate/repo', { ws, consent: !r.consent }); if (out && out.ok) { r.consent = !!out.consent; if (out.key) J.key = out.key; } return { out, on: r.consent }; }
108
+ if (kind === 'categorize') { const out = await pmPost('/api/doccat/jev', { ws, categorize: !r.categorize }); if (out && out.ok) r.categorize = !r.categorize; return { out, on: r.categorize }; }
109
+ if (kind === 'claims') {
110
+ const on = !(r.watch && r.jev);
111
+ const a = await pmPost('/api/claims/watch', { ws, watch: on }); if (!a || !a.ok) return { out: a, on: r.watch && r.jev };
112
+ r.watch = on;
113
+ const b = await pmPost('/api/claims/jev', { ws, jev: on }); if (b && b.ok) r.jev = on;
114
+ return { out: b, on: r.watch && r.jev };
115
+ }
116
+ const field = kind === 'label' ? 'jev' : 'check';
117
+ const out = await pmPost('/api/notes/switch', { ws, [field]: !n[field] });
118
+ if (out && out.ok && out.jev) r.notes = { jev: !!out.jev.jev, check: !!out.jev.check };
119
+ return { out, on: !!(r.notes || {})[field] };
120
+ }
121
+
122
+ export async function press(t, redraw, say) {
123
+ const a = t.dataset.jl, sw2 = t.dataset.jlSw, lc = t.dataset.jlLocal;
124
+ if (!a && !sw2 && !lc) return false;
125
+ if (J.busy) return true;
126
+ J.busy = true;
127
+ try {
128
+ if (a === 'notnow') { store.set(NOT_NOW, '1'); say(''); }
129
+ else if (a === 'keysave' || a === 'keyclear') {
130
+ const clear = a === 'keyclear', inp = document.getElementById('evJlKey'), val = inp ? inp.value.trim() : '';
131
+ if (!clear && !val) say('Paste the key first.');
132
+ else {
133
+ const r = clear ? await send('DELETE', '/api/typesafe/key') : await send('PUT', '/api/typesafe/key', { key: val });
134
+ if (inp) inp.value = '';
135
+ if (r && r.ok) J.key = r.key;
136
+ say(r && r.ok ? (clear ? 'The saved key is removed. Jev is asleep.' : 'Saved on this computer. Jev is awake.') : (r && r.error) || 'Not saved.');
137
+ }
138
+ } else if (lc) {
139
+ const r = await pmPost('/api/typesafe/local', { backend: lc });
140
+ if (r && r.ok) { J.key = r.key; J.test = null; }
141
+ say(r && r.ok ? (lc === 'off' ? 'Laya is off.' : 'Laya is chosen. Set it up from the terminal icon, then test it.') : (r && r.error) || 'Not saved.');
142
+ } else if (a === 'setup') {
143
+ const r = await pmPost('/api/typesafe/local/setup', {});
144
+ if (r && r.ok) { J.key = r.key; J.test = null; }
145
+ say(!r || !r.ok ? (r && r.error) || 'Laya was not set up.' : r.started ? 'A terminal opened with the commands typed in. Read them and press Enter there. Laya keeps running in it.' : 'The terminal did not open: ' + (r.reason || 'no reason given') + '.');
146
+ } else if (a === 'test') {
147
+ say('');
148
+ const r = await pmPost('/api/typesafe/local/test', {});
149
+ const port = (local() && local().port) || 8000;
150
+ J.test = r && r.ok ? { ok: true, text: 'Laya answered the test.' } : { ok: false, text: 'Laya did not answer on port ' + port + '. Is its terminal still open? Set it up again from the terminal icon.' };
151
+ } else if (sw2) {
152
+ const { out, on } = await flip(sw2, t.dataset.ws);
153
+ say(out && out.ok ? SAID[sw2](on) : (out && out.error) || 'Not saved.');
154
+ }
155
+ } finally { J.busy = false; }
156
+ redraw();
157
+ return true;
158
+ }
@@ -13,11 +13,16 @@
13
13
  * go({ merge })) · Not an overlap (POST /api/driver/drop, and /api/boards/notdup so the Board stops flagging the pair too).
14
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
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
+ * wf-bridge Claude proposes (batch 20 item 3, canvas WmB): move every initiative of a replaced workflow to the new one. Each new stage with the
17
+ * old stages that go into it and how many initiatives and tasks land there; ✕ Not now (raised once: it is marked seen) and ✓ (POST
18
+ * /api/workflows/switch-all, the bridge saved with the new workflow). The toast's Undo puts everything back (POST …/switch-all/undo);
19
+ * the initiative's own workflow picker keeps it for 7 days.
16
20
  * openNews({ go?, view? }) → the body element; view: an item's id opens straight on that item. go(d): Home's own opener ({ ini } | { merge }) */
17
21
  import { pmGet, pmPost } from './http.js';
18
22
  import { open as vwOpen, current as vwCurrent, back as vwBack, czSummary, czSections } from './cozy-viewer.js';
19
23
  import { esc, svg, ICON, toast, wsParam, wsQ, skelRows, cantRead, allClear } from './cozy-evui.js';
20
24
  import { initials, ago } from './cozy-evmodel.js';
25
+ import { toast as undoToast } from './c3-toast.js'; // the dark toast with Undo (the bridge's 7-day way back)
21
26
 
22
27
  const N = { r: null, dig: null, view: '', body: null, shown: new Set(), busy: false, go: null };
23
28
  const homeUrl = (params) => { const q = new URLSearchParams(params); if (wsParam()) q.set('ws', wsParam()); return '/premium.html?' + q.toString(); };
@@ -26,11 +31,13 @@ const https = (u) => (/^https:\/\/\S+$/i.test(String(u || '')) ? u : '');
26
31
  const finHref = (it) => (/^item:/.test(it.open) ? homeUrl({ item: it.open.slice(5) }) : homeUrl(it.pws ? { open: it.open, pws: it.pws } : { open: it.open }));
27
32
 
28
33
  function items() { return N.r && N.r.ok ? N.r.groups.flatMap((g) => g.items) : []; }
34
+ /** A bridge row's second line: "From Product feature · into Discovery, Implementation, Evaluation". */
35
+ export const bridgeSub = (it) => ['From ' + ((it.from && it.from.name) || 'the old workflow'), (it.groups || []).length ? 'into ' + it.groups.map((g) => g.name).join(', ') : ''].filter(Boolean).join(' · ');
29
36
  function rowHtml(it) {
30
37
  const who = it.kind === 'task' ? (it.from || 'Someone') : (it.product || 'Agent');
31
38
  // 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(' · ')
39
+ const av = it.kind === 'overlap' || it.kind === 'wf-bridge' ? `<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>`;
40
+ const sub = it.kind === 'wf-bridge' ? bridgeSub(it) : 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
41
  : 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(' · ')
35
42
  : [it.what, it.product, it.target, it.at ? ago(new Date(it.at).toISOString()) : ''].filter(Boolean).join(' · ');
36
43
  const title = it.kind === 'task' ? String(it.title || '').replace(/^New task: /, '') : it.title;
@@ -133,6 +140,7 @@ const sureWord = { high: 'high', medium: 'medium', low: 'low' };
133
140
 
134
141
  function openItem(it, o = {}) {
135
142
  if (it.kind === 'overlap') return openOverlap(it, o);
143
+ if (it.kind === 'wf-bridge') return openBridge(it, o);
136
144
  if (it.kind === 'task') return openGiven(it, o);
137
145
  return null;
138
146
  }
@@ -213,6 +221,52 @@ function openOverlap(it, o = {}) {
213
221
  } });
214
222
  }
215
223
 
224
+ /* moving a replaced workflow's initiatives (WmB): Claude proposes once; the proposal is the preview; the PM only approves */
225
+ const XMARK = 'M6 6l12 12M18 6L6 18', ARROW = 'M5 12h14M13 6l6 6-6 6';
226
+ function openBridge(it, o = {}) {
227
+ const id = 'news:' + it.id, V = { busy: false };
228
+ const n = it.n || 0, nW = n === 1 ? '1 initiative' : n + ' initiatives';
229
+ const draw = (body) => {
230
+ if (!body || !body.isConnected) return;
231
+ const names = (it.groups || []).map((g) => g.name).join(', ');
232
+ const text = 'You made ' + (names || (it.wf && it.wf.name) || 'a new workflow') + '. ' + nW + ' still ' + (n === 1 ? 'runs' : 'run') + ' on ' + ((it.from && it.from.name) || 'the old workflow')
233
+ + '. Each stage and its tasks move together, so none is left out of a stage.';
234
+ const rows = (it.groups || []).map((g) => {
235
+ const cnt = [g.inis ? (g.inis === 1 ? '1 initiative' : g.inis + ' initiatives') : '', g.tasks ? (g.tasks === 1 ? '1 task' : g.tasks + ' tasks') : ''].filter(Boolean).join(' · ');
236
+ return `<div class="nv-br"><span class="nv-bo">${esc(g.from.join(' · ') || 'nothing moves in')}</span><span class="nv-ba" aria-hidden="true">${svg(ARROW, 18)}</span><b class="nv-bn">${esc(g.name)}</b>${cnt ? `<em class="nv-bc">${esc(cnt)}</em>` : ''}</div>`;
237
+ }).join('');
238
+ const keep = '<p class="ev-small ev-mut">' + esc(it.saved ? 'The bridge is saved with ' + it.wf.name + '.' : 'I save this bridge with ' + it.wf.name + ', so a later switch from ' + it.from.name + ' uses it too.') + ' Undo stays open for 7 days.</p>';
239
+ const go = `<div class="nv-go nv-goi"><button type="button" class="ev-ib" data-nv-no aria-label="Not now" title="Not now"${V.busy ? ' disabled' : ''}>${svg(XMARK, 18)}</button>`
240
+ + `<button type="button" class="czs-pri nv-pri nv-ico" data-nv-go aria-label="${esc('Approve and move all ' + n)}" title="${esc('Approve and move all ' + n)}"${V.busy ? ' disabled' : ''}>${svg(P.check, 18)}</button></div>`;
241
+ body.innerHTML = `<div class="nv">${czSummary({ line: nW, tone: 'you', text })}<div class="nv-bridge" role="list" aria-label="Where each stage goes">${rows}</div>${keep}${go}</div>`;
242
+ };
243
+ const after = async (r) => {
244
+ if (!r || !r.ok) { V.busy = false; return false; }
245
+ const moved = (r.moved === 1 ? '1 initiative' : r.moved + ' initiatives') + (r.tasks ? ' and ' + (r.tasks === 1 ? '1 task' : r.tasks + ' tasks') : '');
246
+ undoToast({ text: 'Moved ' + moved + (r.failed && r.failed.length ? '. ' + r.failed.length + ' could not move.' : ''), timeout: 12000, onAction: async () => {
247
+ const u = await pmPost('/api/workflows/switch-all/undo', { ws: it.ws, batch: r.batch }).catch(() => null);
248
+ if (!u || !u.ok) { toast('The undo did not go through' + (u && u.error ? ': ' + u.error : '.')); return; }
249
+ toast(u.undone + ' of ' + u.of + ' undone.' + (u.kept && u.kept.length ? ' ' + u.kept.length + ' moved since, so ' + (u.kept.length === 1 ? 'it stays' : 'they stay') + ' where ' + (u.kept.length === 1 ? 'it is' : 'they are') + '.' : ''));
250
+ } });
251
+ return true;
252
+ };
253
+ vwOpen({ id, kind: 'Claude proposes', title: it.title || 'Move to the new workflow', icon: SPARK, sub: ['Claude noticed', it.at ? ago(new Date(it.at).toISOString()) : ''].filter(Boolean).join(' · '), fresh: !!o.fresh,
254
+ more: [{ label: 'Change the bridge in Settings', on: () => location.assign('/premium-workflows.html?wf=' + encodeURIComponent(it.wf.id) + (wsParam() ? '&ws=' + encodeURIComponent(wsParam()) : '')) }],
255
+ render: (body) => {
256
+ body.classList.add('ev-card-b');
257
+ draw(body);
258
+ body.onclick = async (e) => {
259
+ const t = e.target.closest('button'); if (!t || V.busy) return;
260
+ if ('nvNo' in t.dataset) { await doneWith(it, id); toast('Not now. The bridge waits in Settings, Workflows.'); return; }
261
+ if (!('nvGo' in t.dataset)) return;
262
+ V.busy = true; draw(body);
263
+ const r = await pmPost('/api/workflows/switch-all', { ws: it.ws, id: it.wf.id, from: it.from.id }).catch(() => null);
264
+ if (!(await after(r))) { draw(body); toast('That did not go through' + (r && r.error ? ': ' + r.error : '.')); return; }
265
+ doneWith(it, id);
266
+ };
267
+ } });
268
+ }
269
+
216
270
  /* 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
271
  function openGiven(it, o = {}) {
218
272
  const id = 'news:' + it.id, V = { busy: false, when: false, agent: it.agent || null };
@@ -124,7 +124,7 @@ function layout() {
124
124
  sync();
125
125
  const B = document.body, phone = isPhone(), man = managed(), ids = [C, ...vs().map((p) => p.id)];
126
126
  const back = S.man && !man; // back to today's split: cozy-viewer.js decides the width and the rail again
127
- if (back) { S.keepList = false; P.rail(false); }
127
+ if (back) { S.keepList = false; P.rail(P.owned && P.owned() !== null ? P.owned() : false); }
128
128
  S.man = man;
129
129
  B.classList.toggle('cz-pn', !phone);
130
130
  B.classList.toggle('cz-pn-man', man);
@@ -148,7 +148,8 @@ function layout() {
148
148
  if (man && !phone && !S.page) {
149
149
  const room = S.desk.clientWidth - 64 - (S.row.length - 1) * 22; // the desk less its padding and the gaps
150
150
  const list = document.getElementById('hmList'), lw = list ? list.offsetWidth || 316 : 0;
151
- const fold = !S.keepList && (!S.row.includes(C) || room - lw < S.row.length * PANEL);
151
+ const own = P.owned ? P.owned() : null; // Home owns its list's fold (batch 20 item 6): only full screen takes its room, and it comes back as it was
152
+ const fold = own !== null ? own || (S.row.length === 1 && S.row[0] !== C) : !S.keepList && (!S.row.includes(C) || room - lw < S.row.length * PANEL);
152
153
  if (fold !== P.railOn()) P.rail(fold);
153
154
  }
154
155
  if (back) P.rest(); else P.relayout();
@@ -5,6 +5,7 @@
5
5
  * for Adler's leaf, the impact log and the weekly check; the page hears `pmos:impact`), Agents write to Jira (fixed: only after Commit)
6
6
  * Claude’s checks Grill by itself (Full, Only at stage exits, Off) and the monthly credit for checks with what this month used (grill.mode,
7
7
  * grill.cap, POST /api/settings; GET /api/grill; canvas GrillEntry). At the cap Claude pauses and says so once here.
8
+ * Jev and Laya the TypeSafe key, Laya on this computer and the per-repository switches (pm/cozy-jl.js; canvas JlA1Empty–JlA4Phone)
8
9
  * Adler how much of Claude's face shows, Motion, Celebrations, Quiet after (adler.*, POST /api/settings; canvas AdM5, batch 16 item 2)
9
10
  * › Dress for the day (adler.dress.*, canvas AsSet1, batch 18 item 8): the master switch, where you are, one switch per group,
10
11
  * "More festivals" with one switch per day, big sports and your colours, exam season, your days, Wear now (pm/cozy-seasons.js).
@@ -26,6 +27,7 @@
26
27
  * PMOS reads the sources and never posts to them.
27
28
  * openSettings(section?) */
28
29
  import { mountClaudeSetup } from './cozy-claude-setup.js';
30
+ import * as JL from './cozy-jl.js';
29
31
  import { pmGet, pmPost, pressFetch } from './http.js';
30
32
  import { esc, svg, ICON, toast, wsParam, wsQ } from './cozy-evui.js';
31
33
  import { sourceRows, staleOf, partsOf } from './cozy-evmodel.js';
@@ -38,7 +40,7 @@ async function pmSend(method, path, body) {
38
40
  try { const res = await pressFetch(path, { method, ...(body === undefined ? {} : { body: JSON.stringify(body) }) }); const out = await res.json(); if (out && typeof out === 'object' && !res.ok) out.status = res.status; return out; }
39
41
  catch (e) { return { ok: false, error: 'could not reach the workspace server — ' + ((e && e.message) || String(e)) }; }
40
42
  }
41
- const SECTIONS = [['general', 'General'], ['claude', 'Claude'], ['checks', 'Claude’s checks'], ['adler', 'Adler'], ['connectors', 'Connectors'], ['workspaces', 'Workspaces'], ['workflows', 'Workflows'], ['updates', 'Updates']];
43
+ const SECTIONS = [['general', 'General'], ['claude', 'Claude'], ['checks', 'Claude’s checks'], ['jl', 'Jev and Laya'], ['adler', 'Adler'], ['connectors', 'Connectors'], ['workspaces', 'Workspaces'], ['workflows', 'Workflows'], ['updates', 'Updates']];
42
44
  const PAGE_LINKS = { workflows: '/premium-workflows.html' }; // a section that is a page of its own: the row goes there
43
45
  const SRC = { calendar: 'Calendar', wispr: 'Wispr Flow', mail: 'Mail', slack: 'Slack', jira: 'Jira', confluence: 'Confluence', github: 'GitHub', drive: 'Google Drive', figma: 'Figma', website: 'Your websites' };
44
46
  const VIEWER_KEY = 'pmos.cz.viewer';
@@ -47,7 +49,7 @@ const cmpVer = (a, b) => { const x = String(a || '0').split('-')[0].split('.').m
47
49
  const home = () => (T.ws && T.ws[0] ? T.st[T.ws[0].id] : null);
48
50
  const latest = () => { const s = home(); return (s && (s.latest || (s.lastCheck && s.lastCheck.latest))) || null; };
49
51
  const fromGit = () => { const s = home(); return !!(s && s.app && s.app.fromCheckout && !(s.source && s.source.kind === 'local')); };
50
- const kitsBehind = () => (T.ws || []).filter((w) => T.st[w.id] && T.st[w.id].kitBehind);
52
+ const kitsBehind = () => (T.ws || []).filter((w) => !w.linked && T.st[w.id] && T.st[w.id].kitBehind);
51
53
  const appBehind = () => { const s = home(); return !!(s && s.appBehind && !fromGit()); };
52
54
  const ready = () => appBehind() || kitsBehind().length > 0;
53
55
  const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* no storage */ } } };
@@ -205,7 +207,7 @@ function updates() {
205
207
  : L ? `<b>PMOS ${esc(app)} is up to date</b><p class="ev-small ev-mut">${fromGit() && s.appBehind ? esc(L) + ' is published. This PMOS runs from a checkout: update it with git pull.' : 'The newest published kit is ' + esc(L) + '.'}</p>`
206
208
  : `<b>PMOS ${esc(app)}</b><p class="ev-small ev-mut">Press Check now to ask for the latest version.</p>`;
207
209
  const acts = T.phase === 'busy' ? '' : `<button type="button" class="ev-btn sm" data-ev-upd="check"${T.busy ? ' disabled' : ''}>Check now</button>${ready() ? `<button type="button" class="ev-btn sm dark" data-ev-upd="update">${appBehind() ? 'Restart to update' : 'Update'}</button>` : ''}`;
208
- const kits = (T.ws || []).map((w) => { const k = T.st[w.id], kit = k && k.kit; return trow(w.label || w.name || w.id, kit && kit.present ? 'kit ' + (kit.version || 'vendored by hand') : 'no kit in this workspace', k && k.kitBehind && L ? `<span class="ev-pill y">${esc(L)} ready</span>` : kit && kit.present && (k.lastCheck || k.latest) ? '<span class="ev-pill ok">Up to date</span>' : ''); }).join('');
210
+ const kits = (T.ws || []).filter((w) => !w.linked).map((w) => { const k = T.st[w.id], kit = k && k.kit; return trow(w.label || w.name || w.id, kit && kit.present ? 'kit ' + (kit.version || 'vendored by hand') : 'no kit in this workspace', k && k.kitBehind && L ? `<span class="ev-pill y">${esc(L)} ready</span>` : kit && kit.present && (k.lastCheck || k.latest) ? '<span class="ev-pill ok">Up to date</span>' : ''); }).join('');
209
211
  const last = s.lastCheck ? 'Last checked ' + new Date(s.lastCheck.at).toLocaleString() + '. ' : '';
210
212
  return `<div class="ev-card ev-upd first">${mood ? adFace(mood) : ''}<div class="ev-tx ev-grow">${head}</div>${acts}</div>${kits}<p class="ev-small ev-mut">${esc(last)}${s.checkDaily ? 'PMOS checks when you open Updates and once a day while a page is open; Check now asks again.' : 'PMOS checks only when you press Check now.'}</p>${weeks()}`;
211
213
  }
@@ -258,13 +260,13 @@ function checksSec() {
258
260
  + trow('Monthly credit for checks', C.paused ? 'Paused at the limit this month. Claude starts again next month, or when you raise it.' : 'At the limit Claude pauses and says so once. It never charges beyond it.', seg('Monthly credit for checks', 'grill.cap', C.cap, caps.map((v) => [v, usd(v)])))
259
261
  + `<div class="ev-trow ev-gcap"><span class="ev-small"><b>${esc(usd(C.spent))}</b> of ${esc(usd(C.cap))} used this month</span><span class="ev-gbar" role="img" aria-label="${used}% of the monthly credit used"><i style="width:${used}%"></i></span></div>`;
260
262
  }
261
- const BODY = { general, claude: claudeSec, checks: checksSec, adler: adlerSec, connectors, workspaces, updates };
263
+ const BODY = { general, claude: claudeSec, checks: checksSec, jl: JL.html, adler: adlerSec, connectors, workspaces, updates };
262
264
  let disposeClaudeSetup = null;
263
265
  function draw() {
264
266
  const el = T.el; if (!el || el.hidden) return;
265
267
  // a redraw replaces the nodes: keep focus on the same control (by its data-ev-* key), else on the open section, never on the body
266
268
  const ae = document.activeElement, had = ae && el.contains(ae), key = had ? [...ae.attributes].find((a) => a.name.startsWith('data-ev-')) : null;
267
- const n = { connectors: T.src === null ? '' : Object.keys(SRC).filter((k) => T.src[k]).length + T.conn.filter((c) => !c.source && T.con[c.name]).length, workspaces: T.ws ? T.ws.length : '', updates: ready() ? '<span class="ev-pill y">1</span>' : '' };
269
+ const n = { connectors: T.src === null ? '' : Object.keys(SRC).filter((k) => T.src[k]).length + T.conn.filter((c) => !c.source && T.con[c.name]).length, workspaces: T.ws ? T.ws.filter((x) => !x.linked).length : '', updates: ready() ? '<span class="ev-pill y">1</span>' : '' };
268
270
  const stale = T.fresh && T.fresh.ok ? staleOf(T.fresh.sources) : null;
269
271
  el.querySelector('.ev-st-nav').innerHTML = '<h2 class="ev-h2">Settings</h2>' + SECTIONS.map(([k, l]) => PAGE_LINKS[k] ? `<a href="${PAGE_LINKS[k]}" class="ev-mi">${esc(l)}</a>` : `<a href="#${k}" class="ev-mi" data-ev-sec="${k}"${T.sec === k ? ' aria-current="page"' : ''}>${esc(l)}${k === 'connectors' && stale ? '<i class="ev-dot risk" aria-label="A source is stale" role="img"></i>' : ''}${n[k] !== undefined && n[k] !== '' ? `<span class="ev-k">${typeof n[k] === 'number' ? n[k] : n[k]}</span>` : ''}</a>`).join('');
270
272
  const label = (SECTIONS.find((x) => x[0] === T.sec) || SECTIONS[0])[1];
@@ -356,6 +358,7 @@ async function press(e) {
356
358
  T.msg = r && r.ok ? (clear ? 'The saved key is removed.' : 'Saved on this computer. Claude\u2019s own runs use it from now on.') : (r && r.error) || 'Not saved.';
357
359
  draw(); return;
358
360
  }
361
+ if (await JL.press(t, draw, (m) => { T.msg = m; })) return;
359
362
  if (t.dataset.evRead || 'evReadall' in t.dataset) { readAgain(t.dataset.evRead || ''); return; }
360
363
  if (T.busy) return;
361
364
  T.busy = true; T.msg = '';
@@ -382,7 +385,7 @@ async function upd(a, quiet) {
382
385
  if (a === 'check') {
383
386
  T.checking = true; T.msg = ''; draw();
384
387
  try {
385
- for (const w of T.ws || []) { const r = await pmPost('/api/kit/check', { ws: w.id }); if (r && r.ok) T.st[w.id] = { ...(T.st[w.id] || {}), ...r }; else T.msg = (r && r.error) || 'The check failed.'; }
388
+ for (const w of (T.ws || []).filter((x) => !x.linked)) { const r = await pmPost('/api/kit/check', { ws: w.id }); if (r && r.ok) T.st[w.id] = { ...(T.st[w.id] || {}), ...r }; else T.msg = (r && r.error) || 'The check failed.'; }
386
389
  } finally { T.checking = false; }
387
390
  if (!T.msg && !quiet) toast(ready() ? 'PMOS ' + latest() + ' is ready' : 'Checked. PMOS is up to date');
388
391
  return;
@@ -440,6 +443,7 @@ async function load() {
440
443
  pmGet('/api/profiles').then(async (pr) => { const k = await pmGet('/api/anthropic'); T.cl = { profiles: pr && Array.isArray(pr.profiles) ? pr.profiles : [], prefs: (pr && pr.prefs) || {}, perr: pr && pr.ok === false ? (pr.error || 'the server did not answer') : '', key: k && k.ok ? k.key : { present: false, source: null }, off: !!(k && k.off) }; draw(); }).catch(() => { T.cl = { profiles: [], prefs: {}, perr: 'the server did not answer', key: { present: false, source: null } }; draw(); });
441
444
  const [w, p, s, b] = await Promise.all([pmGet('/api/workspaces'), pmGet('/api/proactive/settings'), pmGet('/api/settings'), pmGet('/api/briefing-premium')]);
442
445
  T.ws = w && Array.isArray(w.workspaces) ? w.workspaces : [];
446
+ JL.load(T.ws.filter((x) => !x.linked), draw); // a linked worktree is its repository: one row each
443
447
  T.src = p && p.ok && p.settings ? { ...p.settings.briefSources } : {}; T.con = p && p.ok && p.settings ? { ...p.settings.connectors } : {};
444
448
  T.conn = p && p.connectors && Array.isArray(p.connectors.list) ? p.connectors.list : [];
445
449
  T.set = s && s.ok ? s : null;
@@ -454,7 +458,7 @@ async function load() {
454
458
  export function openSettings(section) {
455
459
  const el = mount();
456
460
  if (section === 'dress') { T.sec = 'adler'; T.dress = true; } else if (section && BODY[section]) { T.sec = section; T.dress = false; }
457
- if (el.hidden) { const ae = document.activeElement; T.back = ae && ae !== document.body ? ae : null; T.ws = null; T.src = null; T.msg = ''; T.phase = ''; T.auto = false; T.wkOpen = new Set(); T.arc = false; T.fresh = null; T.note = {}; T.dset = {}; T.cl = null; T.gr = null; }
461
+ if (el.hidden) { const ae = document.activeElement; T.back = ae && ae !== document.body ? ae : null; T.ws = null; T.src = null; T.msg = ''; T.phase = ''; T.auto = false; T.wkOpen = new Set(); T.arc = false; T.fresh = null; T.note = {}; T.dset = {}; T.cl = null; T.gr = null; JL.reset(); }
458
462
  el.hidden = false; document.getElementById('evStScrim').hidden = false; el.setAttribute('data-esc-layer', '');
459
463
  draw();
460
464
  const f = el.querySelector('[aria-current="page"]'); if (f) f.focus();
@@ -543,3 +543,6 @@ body.cz-home .hm-hd.hv-bar > .hv-hi { flex: 1 0 auto; max-width: 100%; }
543
543
  /* Home's one grill line (canvas FcPhone, Home): quiet, with ✦ at its end */
544
544
  .hv-gn { display: flex; align-items: center; gap: 8px; color: var(--cz-ink2); }
545
545
  .hv-gn span { flex: 1; min-width: 0; }
546
+ /* a product's own chats: the same pill as an initiative row, on its header (batch 20 item 10) */
547
+ .hv-gh.hv-prg { position: relative; }
548
+ .hv-gh.hv-prg > .hv-sp { flex: none; }
@@ -117,7 +117,11 @@ const kindKey = (k) => String(k || 'item').trim().toLowerCase().replace(/^file
117
117
  * key or the last open() went to, so the exported API always speaks of the Viewer used last. G is what the page has once: its list's rail,
118
118
  * the listeners, the rail's card. Only the first instance (#czViewer) writes the browser history; another keeps its own ← → trail.
119
119
  * Without cozy-panels.js (Board, Intelligence) the limit stays 1 and there is one Viewer, as before. */
120
- const G = { subs: [], card: null, railKey: null, rail: false, lw: 0, hold: 0, tick: 0, limit: 1, beside: null, place: null, managed: null };
120
+ const G = { subs: [], card: null, railKey: null, rail: false, lw: 0, hold: 0, tick: 0, limit: 1, beside: null, place: null, managed: null, own: null };
121
+ /** The list's fold, when the page owns it (Home, batch 20 item 6): { folded() → bool, show() }. Then only the list's own icon folds or unfolds it:
122
+ * a Viewer's width, its reset, open wide and its close never do. null: the Viewer folds the list to a rail as it needs (a page without one). */
123
+ export function listFold(o) { G.own = o && typeof o.folded === 'function' ? o : null; }
124
+ const owned = () => (G.own ? !!G.own.folded() : null);
121
125
  const mk = (i) => ({ i, el: null, cur: null, back: null, stack: [], fwd: [], wide: false, w: 0, drill: false, over: false, used: 0, ph: false, via: '' });
122
126
  let V = mk(0);
123
127
  const ALL = [V];
@@ -275,6 +279,7 @@ function setRail(on) {
275
279
  bar.innerHTML = `<button type="button" class="cz-vw-ib" data-cz-vw-rail="show" aria-label="Show the list" title="Show the list">${svg(P.list, 18)}</button><div class="cz-vw-railtiles"></div>`;
276
280
  bar.addEventListener('click', (e) => {
277
281
  const b = e.target.closest('[data-cz-vw-rail]'); if (!b) return;
282
+ if (b.dataset.czVwRail === 'show' && G.own) { if (G.own.show) G.own.show(); return; } // the page unfolds its own list
278
283
  if (b.dataset.czVwRail === 'show' && G.managed && ALL.some((x) => shown(x) && G.managed('v' + x.i))) { setRail(false); return; } // cozy-panels.js lays it out
279
284
  if (b.dataset.czVwRail === 'show') { V.wide = false; apply(Math.min(V.w, sideMax())); redraw(); return; }
280
285
  // a group's tile: the page's card of that group's rows, beside the tile (batch 18 item 14, FlA1); the rail and the Viewer stay
@@ -325,6 +330,17 @@ function apply(px) {
325
330
  // cozy-panels.js lays the panels out itself (two Viewers, a Viewer full or sliding over): it sizes this one, the rail is its own call
326
331
  if (G.managed && G.managed('v' + V.i)) { el.style.width = ''; el.classList.toggle('cz-vw-w2', el.offsetWidth >= W2); return; } // its flex is the engine's; V.w keeps the width beside the chat
327
332
  let r = room();
333
+ if (G.own) {
334
+ // the page owns the fold: the rail is its choice, and the Viewer takes only the room beside it (batch 20 item 6)
335
+ setRail(owned()); r = room();
336
+ const over = !r.float && r.hasList && r.side < MIN && !!(el.parentNode && el.parentNode.hasAttribute('data-cz-vw-overlay'));
337
+ if (over !== V.over) { V.over = over; document.body.classList.toggle('cz-vw-over', over); }
338
+ const cap = r.float ? r.wideMax : over ? r.right : Math.max(MIN, G.rail ? r.wideMax : r.side);
339
+ const w = Math.max(Math.min(MIN, cap), Math.min(Math.round(px || r.def), cap));
340
+ V.w = w; el.style.width = w + 'px'; el.style.flexBasis = w + 'px'; el.classList.toggle('cz-vw-w2', w >= W2);
341
+ const g = el.querySelector('.cz-vw-grip'); if (g) { g.setAttribute('aria-valuenow', String(w)); g.setAttribute('aria-valuemin', String(MIN)); g.setAttribute('aria-valuemax', String(cap)); }
342
+ return;
343
+ }
328
344
  // a host that keeps its list (Home, HbCNarrow): with no room beside the chat the Viewer lies over the chat, at most the room right of the list
329
345
  const over = !r.float && r.hasList && r.side < MIN && !V.wide && !!(el.parentNode && el.parentNode.hasAttribute('data-cz-vw-overlay'));
330
346
  if (over !== V.over) { V.over = over; document.body.classList.toggle('cz-vw-over', over); }
@@ -355,7 +371,7 @@ export function wide(on) {
355
371
  redraw();
356
372
  return V.wide;
357
373
  }
358
- function resetW() { if (!V.cur) return; store.set('cz-vw-w:' + kindKey(V.cur.kind), null); V.wide = false; setRail(false); apply(room().def); redraw(); }
374
+ function resetW() { if (!V.cur) return; store.set('cz-vw-w:' + kindKey(V.cur.kind), null); V.wide = false; if (!G.own) setRail(false); apply(room().def); redraw(); }
359
375
  function grip(el) {
360
376
  const g = document.createElement('div'), x = V;
361
377
  g.className = 'cz-vw-grip'; g.setAttribute('role', 'separator'); g.setAttribute('aria-orientation', 'vertical'); g.tabIndex = 0;
@@ -766,6 +782,6 @@ export const panels = {
766
782
  relayout() { ALL.filter(shown).forEach((x) => on(x, () => { apply(V.wide ? room().wideMax : V.w || room().def); redraw(); })); },
767
783
  /** Back beside the chat after the engine laid it out: the width its kind keeps, else the default. */
768
784
  rest() { ALL.filter(shown).forEach((x) => on(x, () => { const k = widthOf(V.cur.kind); V.wide = false; apply(k || room().def); redraw(); })); },
769
- rail(v) { setRail(!!v); }, railOn: () => G.rail,
785
+ rail(v) { setRail(!!v); }, railOn: () => G.rail, owned,
770
786
  };
771
787
  if (typeof window !== 'undefined') window.czViewer = { open, close, back, forward, trail, replaceUrl, drill, setPresses, setChip, setCheck, isOpen, current, body, onChange, placeholder, retitle, czSummary, czSections, widthOf, setWidth, wide, railOn, railCard, railSync, keepWide, ICONS };
@@ -0,0 +1,101 @@
1
+ /* goal-forecast — a goal's forecast in the goal Viewer (canvas boards FcViewer and the Viewer parts of FcPhone; build brief Grill and Forecast).
2
+ * The data is g.forecast on /api/insights-premium (lib/forecast.js, one straight-line method): { state, likely, low, high, by, asOf, source,
3
+ * driftFrom, weeks, why, baseline, offer }. This module is pure HTML; premium-insights.js draws it in the goal Viewer and wires the presses.
4
+ *
5
+ * stateHtml(g, o) the state line: a tag (On track, At risk, Will miss, Held, Too early) and its words. '' when there is no forecast
6
+ * chartLayer(g, x, y) what the goal chart adds: the range band, the dashed likely path and the shaded readings a baseline leaves out
7
+ * legendHtml(g) under the chart: history, likely, range, and "Projected, not promised"
8
+ * baselineHtml(g, o) the ✓ that keeps a baseline ("Without the reading of 14 Sep, the range is 2 to 4%"), or the kept one with its ×
9
+ * baselineBody(g, o) the POST /api/forecast/baseline body for the offer
10
+ *
11
+ * o: { md(ms) → "Oct 8", day(iso) → ms, unit(v) → "3.1%", next: "The next reading comes from Jira on Nov 3.", source, ws, rid, dismissed }
12
+ * What-if lines (FcViewer's "Simulated, not the plan") are not drawn: no what-if proposal is filed on a goal yet. */
13
+
14
+ const RANGED = new Set(['on-track', 'at-risk', 'will-miss', 'held']);
15
+ const TAG = { 'on-track': ['On track', 'ok'], 'at-risk': ['At risk', 'risk'], 'will-miss': ['Will miss', 'late'], held: ['Held', ''], 'too-early': ['Too early', ''] };
16
+ const e = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
17
+ const n1 = (v) => String(Math.round(v * 10) / 10);
18
+ const ICON = {
19
+ ok: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12l5 5 9-10"/></svg>',
20
+ x: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',
21
+ read: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 12a8 8 0 1 1-2.3-5.6M20 4v5h-5"/></svg>',
22
+ };
23
+
24
+ /** A forecast that has a range to draw (a held one keeps the range it was read with). */
25
+ export const ranged = (g) => !!(g && g.forecast && RANGED.has(g.forecast.state) && Number.isFinite(g.forecast.low) && Number.isFinite(g.forecast.high));
26
+
27
+ /** "2 to 5%": the range in the goal's unit, the unit said once at the end; "about 3%" when both ends agree. */
28
+ export function rangeTxt(lo, hi, unit) {
29
+ const a = n1(Math.min(lo, hi)), b = n1(Math.max(lo, hi));
30
+ return a === b ? 'about ' + unit(+a) : a + ' to ' + unit(+b);
31
+ }
32
+
33
+ /** The state line (FcViewer: "At risk. Likely 3.1%, range 2 to 5%. Was on track on 8 Oct."; FcPhone: Held, Too early). */
34
+ export function stateHtml(g, o) {
35
+ const F = g && g.forecast;
36
+ if (!F || !TAG[F.state]) return '';
37
+ const [label, tone] = TAG[F.state];
38
+ let say = '', act = '';
39
+ if (F.state === 'too-early') {
40
+ const n = (g.series || []).length, wk = Math.floor(F.weeks || 0);
41
+ say = 'I need 3 weeks of readings to forecast. I have ' + (n === 1 ? '1 reading' : n + ' readings' + (wk >= 1 ? ' over ' + wk + (wk === 1 ? ' week' : ' weeks') : '')) + '. ' + (o.next || '');
42
+ } else if (F.state === 'held') {
43
+ const ago = F.asOf && o.today ? Math.round((o.today - o.day(F.asOf)) / 864e5) : null;
44
+ const when = ago !== null ? ago + ' days ago' : 'on ' + o.md(o.day(F.asOf));
45
+ say = (o.source ? o.source + ' was last read ' + when : 'The last reading came ' + when) + '. The range is paused and not extended.';
46
+ if (o.canRead) act = `<button type="button" class="cz-ib sm solid" data-fc="read" aria-label="Read it now" title="Read it now">${ICON.read}</button>`;
47
+ } else {
48
+ say = 'Likely ' + o.unit(+n1(F.likely)) + ', range ' + rangeTxt(F.low, F.high, o.unit) + '.' + (F.driftFrom ? ' Was on track on ' + o.md(o.day(F.driftFrom)) + '.' : '');
49
+ }
50
+ return `<div class="fc-state"><span class="fc-tag${tone ? ' ' + tone : ''}">${e(label)}</span><span class="fc-say">${e(say)}</span>${act}</div>`;
51
+ }
52
+
53
+ /** The spans a kept baseline leaves out, else the ones the offer would leave out: shaded on the chart so the ✓ is read against them. */
54
+ const spansOf = (F) => (F.baseline && F.baseline.exclude) || (F.offer && F.offer.exclude) || [];
55
+
56
+ /** The chart's forecast layer, under the readings: the shaded left-out readings, the range band from the last reading to the target date and the
57
+ * dashed likely path. x(ms) and y(v) are the chart's own scales; last = { t, v } is the latest reading. Answers { under, over } as SVG text. */
58
+ export function chartLayer(g, o) {
59
+ if (!ranged(g)) return { under: '', over: '' };
60
+ const F = g.forecast, by = o.day(F.by), f = (n) => n.toFixed(1), L = o.last;
61
+ if (by === null || !L || by <= L.t) return { under: '', over: '' };
62
+ let under = '';
63
+ for (const s of spansOf(F)) {
64
+ const a = o.day(s.from), z = o.day(s.to);
65
+ if (a === null || z === null) continue;
66
+ const xa = o.x(a) - 7, xz = o.x(z) + 7;
67
+ under += `<rect class="fc-skip" x="${f(xa)}" y="8" width="${f(Math.max(14, xz - xa))}" height="${f(o.H - 24)}" rx="4"/>`;
68
+ }
69
+ const lx = o.x(L.t), ly = o.y(L.v), bx = o.x(by);
70
+ under += `<path class="fc-band${F.state === 'held' ? ' held' : ''}" d="M${f(lx)} ${f(ly)}L${f(bx)} ${f(o.y(F.high))}L${f(bx)} ${f(o.y(F.low))}Z"/>`;
71
+ const over = F.state === 'held' ? '' : `<path class="fc-likely" d="M${f(lx)} ${f(ly)}L${f(bx)} ${f(o.y(F.likely))}"/>`;
72
+ return { under, over };
73
+ }
74
+
75
+ /** The values the chart's scale must hold so the band fits. */
76
+ export const scaleVals = (g) => (ranged(g) ? [g.forecast.low, g.forecast.high, g.forecast.likely].filter(Number.isFinite) : []);
77
+
78
+ /** Under the chart: what each mark is, and that the range is a projection. */
79
+ export function legendHtml(g) {
80
+ if (!ranged(g)) return '';
81
+ return `<div class="fc-legend"><span><i class="fc-k dot" aria-hidden="true"></i>history</span>${g.forecast.state === 'held' ? '' : '<span><i class="fc-k dash" aria-hidden="true"></i>likely</span>'}<span><i class="fc-k band" aria-hidden="true"></i>range</span><span class="fc-sp"></span><span class="fc-tag risk">Projected, not promised</span></div>`;
82
+ }
83
+
84
+ /** The baseline row (FcViewer): the offer with ✓ (keep it) and × (not now), or the kept baseline with × (count every reading). '' when neither. */
85
+ export function baselineHtml(g, o) {
86
+ const F = g && g.forecast;
87
+ if (!F) return '';
88
+ if (F.baseline) {
89
+ return `<div class="fc-base"><b>Counted ${e(F.baseline.label)}.</b><button type="button" class="cz-ib sm" data-fc="base-off" aria-label="Count every reading" title="Count every reading">${ICON.x}</button></div>`;
90
+ }
91
+ const O = F.offer;
92
+ if (!O || (o.dismissed && o.dismissed(keyOf(g, O)))) return '';
93
+ const lead = O.label.charAt(0).toUpperCase() + O.label.slice(1);
94
+ return `<div class="fc-base"><b>${e(lead)}, the range is ${e(rangeTxt(O.low, O.high, o.unit))}</b><button type="button" class="cz-ib sm solid" data-fc="base" aria-label="Use this baseline" title="Use this baseline">${ICON.ok}</button><button type="button" class="cz-ib sm" data-fc="base-no" aria-label="Keep as is" title="Keep as is">${ICON.x}</button></div>`;
95
+ }
96
+
97
+ /** The key a "Keep as is" is remembered under on this browser: the goal and the spans, so a new offer shows again. */
98
+ export const keyOf = (g, O) => 'pmos-fc-no:' + g.id + ':' + O.exclude.map((s) => s.from + '..' + s.to).join(',');
99
+
100
+ /** POST /api/forecast/baseline: { ws, goal, label, exclude }. */
101
+ export const baselineBody = (g, o) => ({ ws: o.ws, goal: o.rid, label: g.forecast.offer.label, exclude: g.forecast.offer.exclude });
@@ -68,12 +68,28 @@
68
68
  .hi-wfland { display: flex; align-items: center; gap: 8px; }
69
69
  .hi-wfland span { flex: 1; }
70
70
  .hi-wfland select { font: inherit; font-size: var(--fs-2); font-weight: 700; color: var(--cz-ink); background: var(--cz-well); border: 0; border-radius: 10px; padding: 6px 10px; max-width: 60%; }
71
+ /* A's bridge (batch 20 item 3, canvas WmB): old stages grouped into each new stage, the scope, one picker per old stage, ✕ and ✓ as icons */
72
+ .hi-wfrow.hi-wfgrp { grid-template-columns: minmax(0, 1fr) 14px minmax(0, 150px); }
73
+ .hi-wfgrp i { font-style: normal; color: var(--cz-ink3); }
74
+ .hi-wfgrp em { display: inline; margin-left: 4px; }
75
+ .hi-wfseg { display: inline-flex; align-self: flex-start; background: var(--cz-well); border-radius: 14px; padding: 3px; }
76
+ .hi-wfsegb { min-height: 32px; padding: 0 12px; border: 0; border-radius: 11px; background: none; color: var(--cz-ink2); font: inherit; font-size: var(--fs-2); font-weight: 800; cursor: pointer; }
77
+ .hi-wfsegb.on { background: var(--cz-card); color: var(--cz-ink); box-shadow: 0 1px 2px rgba(20,24,40,.15); }
78
+ .hi-wfmore summary { cursor: pointer; color: var(--cz-ink2); }
79
+ .hi-wfmaps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; padding-top: 8px; }
80
+ .hi-wfmap { display: flex; align-items: center; gap: 8px; }
81
+ .hi-wfmap span { flex: 1; min-width: 0; }
82
+ .hi-wfmap select { font: inherit; font-size: var(--fs-2); font-weight: 700; color: var(--cz-ink); background: var(--cz-well); border: 0; border-radius: 10px; padding: 6px 8px; max-width: 60%; }
83
+ .hi-actsi { justify-content: flex-end; }
84
+ .hi-actsi .hi-ib { width: 44px; height: 44px; background: var(--cz-well); }
85
+ .hi-actsi .hi-ib.pri { background: var(--cz-solid); color: var(--cz-onsolid); }
71
86
  .hi-end { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; background: var(--cz-well); font-size: var(--fs-3); }
72
87
  .hi-end p { margin: 0; flex: 1; min-width: 0; color: var(--cz-ink2); }
73
88
  .hi-endi { display: inline-flex; color: var(--cz-ink3); }
74
89
  @media (max-width: 760px) {
75
90
  .hi-wfrow { grid-template-columns: minmax(0, 1fr) 14px minmax(0, 1fr); }
76
91
  .hi-wfrow > .hi-small { grid-column: 1 / -1; }
92
+ .hi-wfmaps { grid-template-columns: 1fr; }
77
93
  .hi-end { flex-wrap: wrap; }
78
94
  }
79
95
  .hi-pop .wfi { display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: 6px; background: var(--cz-well); color: var(--cz-ink2); }