create-pmos 0.422.0 → 0.423.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/package.json +13 -13
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/board-programs-test.js +28 -0
  7. package/workspace/briefing-premium-adddoc-test.js +1 -1
  8. package/workspace/briefing-premium-board-test.js +12 -10
  9. package/workspace/briefing-premium-initiative-test.js +30 -38
  10. package/workspace/changelog.json +12 -0
  11. package/workspace/guide/briefing-premium.md +1 -1
  12. package/workspace/guide/home.md +9 -2
  13. package/workspace/guide/programs.md +1 -0
  14. package/workspace/guide/workflows.md +5 -1
  15. package/workspace/ini-workflow-test.js +4 -4
  16. package/workspace/lib/board-premium.js +3 -2
  17. package/workspace/lib/custom-docs.js +65 -3
  18. package/workspace/lib/engine/boards.js +25 -2
  19. package/workspace/lib/initiative-writer.js +63 -1
  20. package/workspace/lib/plan-items.js +36 -5
  21. package/workspace/lib/programs.js +11 -3
  22. package/workspace/lib/route-modules.js +1 -0
  23. package/workspace/lib/routes-board-premium.js +22 -0
  24. package/workspace/lib/routes-boards.js +50 -10
  25. package/workspace/lib/routes-initiatives.js +12 -0
  26. package/workspace/lib/routes-task-links.js +329 -0
  27. package/workspace/lib/split-merge-suggest.js +162 -0
  28. package/workspace/lib/split-merge.js +379 -0
  29. package/workspace/lib/task-cli.js +58 -5
  30. package/workspace/lib/task-items.js +14 -2
  31. package/workspace/lib/task-links.js +422 -0
  32. package/workspace/package-lock.json +2 -2
  33. package/workspace/package.json +1 -1
  34. package/workspace/premium-board-actions-test.js +2 -2
  35. package/workspace/premium-core-doc-issue-test.js +2 -2
  36. package/workspace/premium-vw-backlog-test.js +3 -3
  37. package/workspace/premium-vw-item-test.js +3 -3
  38. package/workspace/premium-vw-jira-test.js +6 -6
  39. package/workspace/product-lane-test.js +165 -0
  40. package/workspace/program-panel-test.js +1 -1
  41. package/workspace/public/pm/bd-ini-panel.js +16 -6
  42. package/workspace/public/pm/bd-prog.js +6 -1
  43. package/workspace/public/pm/bd-span.js +69 -15
  44. package/workspace/public/pm/bd-views.js +3 -2
  45. package/workspace/public/pm/cozy-board.css +10 -0
  46. package/workspace/public/pm/home-app.js +25 -8
  47. package/workspace/public/pm/home-ini-model.js +0 -34
  48. package/workspace/public/pm/home-ini.js +72 -204
  49. package/workspace/public/pm/ini-groups.js +228 -0
  50. package/workspace/public/pm/ini-links.js +561 -0
  51. package/workspace/public/pm/ini-tasks.js +58 -22
  52. package/workspace/public/pm/ini-versions.js +14 -9
  53. package/workspace/public/pm/ini-view-model.js +88 -4
  54. package/workspace/public/pm/ini-view.css +259 -18
  55. package/workspace/public/pm/ini-view.js +140 -32
  56. package/workspace/public/pm/premium-board.js +54 -6
  57. package/workspace/public/pm/split-merge.css +77 -0
  58. package/workspace/public/pm/split-merge.js +265 -0
  59. package/workspace/public/pm/stage-line.js +414 -0
  60. package/workspace/public/pm/task-card.js +5 -3
  61. package/workspace/public/pm/wf-page.css +2 -0
  62. package/workspace/public/pm/wf-page.js +2 -0
  63. package/workspace/public/pm/wf-stage.js +2 -1
  64. package/workspace/server.js +15 -1
  65. package/workspace/split-merge-ui-test.js +175 -0
  66. package/workspace/stage-card-test.js +12 -11
  67. package/workspace/task-card-test.js +3 -2
  68. package/workspace/task-delete-test.js +126 -0
  69. package/workspace/task-links-test.js +227 -0
  70. package/workspace/task-milestones-test.js +1 -1
  71. package/workspace/task-plans-test.js +6 -0
  72. package/workspace/task-views-test.js +1 -1
  73. package/workspace/test-lists/bd-ini-panel.json +8 -2
  74. package/workspace/test-lists/product-lane.json +6 -0
  75. package/workspace/test-lists/split-merge.json +15 -0
  76. package/workspace/test-lists/task-delete.json +5 -0
  77. package/workspace/test-lists/task-links.json +6 -0
  78. package/workspace/tk-tasks-test.js +173 -57
  79. package/workspace/workflows-setup-test.js +4 -3
@@ -0,0 +1,561 @@
1
+ /* pm/ini-links.js — links between tasks that move together, in the initiative's Tasks (feedback batch 11 item 15; canvas In development, row
2
+ * "Task dependencies": DepAGrill, DepA8Suggest, DepA9Adjust, DepA1Timeline, DepA2Drag, DepA3Joint, DepA4Move, DepA6Risk, DepA5List,
3
+ * DepA7Phone, DepA0Rules). The fold, the engine and the routes are lib/task-links.js and lib/routes-task-links.js; the Board's row carries
4
+ * r.links (null: nothing linked, proposed or waiting).
5
+ *
6
+ * of(v) → the links view to draw for the one view's model (the newest of the Board's read and a write's answer), with a
7
+ * title for every task; null while a draft is shown (Claude adjusts Live only)
8
+ * headHtml(lk) the Tasks header's chips, each hidden at zero: the blue ✦ (Claude's proposals), the grey ✦ (the quiet moves since
9
+ * last seen; an orange dot when something waits on you), the orange late count
10
+ * barExtra(x, lk, quick) what a Timeline bar carries: its two link dots (grey when that end is linked), the orange start edge of a task that
11
+ * waits on a late one, the small blue ✦ of a quiet move not yet seen
12
+ * dataOf(lk) the Timeline's links, for the drawing (data-lk on .ivt)
13
+ * metaHtml(x, lk, quick) the List's and Kanban's meta: the link icon and the first task this one waits on, then +N; a press opens Waits on / Then
14
+ * draw(root) the elbows with arrowheads over each Timeline under root: grey; dark for the task under the pointer or pressed;
15
+ * orange when late or broken; proposals dashed blue while the ✦ list is open or their task is selected
16
+ * press(b, d, root, H, e) a press this file owns → true: the chips, a joint, the meta link, a bar on a phone
17
+ * wrap(H) the host's handlers with the PM's own move routed here when the task has links: what waits follows, "Moved N
18
+ * tasks with it" with Undo
19
+ * sweep(id, H) once per initiative and session: the quiet pass (a date changed outside a drag), then a new read when it moved
20
+ *
21
+ * The host gives h.where() → { ws, board }, h.reload() (read the Board again, then draw), h.toast(text, undo?) and h.redraw(). A link is not
22
+ * a status: the five task states stay as they are. */
23
+ import { pmPost } from './http.js';
24
+
25
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
26
+ const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
27
+ export const PL = {
28
+ spark: 'M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8',
29
+ link: 'M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1',
30
+ unlink: 'M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1M4 4l16 16',
31
+ check: 'M5 12l5 5 9-10', x: 'M6 6l12 12M18 6L6 18', undo: 'M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3', minus: 'M5 12h14', plus: 'M12 5v14M5 12h14',
32
+ search: 'M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4', cal: 'M4 5h16v15H4zM8 3v4M16 3v4M4 10h16', dia: 'M12 4l8 8-8 8-8-8z', jira: 'M12 3l9 9-9 9-9-9z',
33
+ // the four types, the two ends joined: the waited-on end on the left, the waiting end on the right
34
+ fs: 'M3 7h8v10h10M17 13l4 4-4 4', ss: 'M7 4v6h14M7 10v10M17 6l4 4-4 4', ff: 'M3 7h14v10H7M17 13v8', sf: 'M7 4v13h10M7 17h0M13 13l4 4-4 4',
35
+ };
36
+ const TYPES = [['fs', 'Finish → start'], ['ss', 'Start → start'], ['ff', 'Finish → finish'], ['sf', 'Start → finish']];
37
+ const typeName = (t) => (TYPES.find((x) => x[0] === t) || TYPES[0])[1];
38
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
39
+ const DAY = /^(\d{4})-(\d{2})-(\d{2})/;
40
+ const md = (iso) => { const m = DAY.exec(String(iso || '')); return m ? MON[+m[2] - 1] + ' ' + +m[3] : ''; };
41
+ const span = (a, b) => { if (!a && !b) return ''; if (!a || !b || a === b) return md(a || b); const x = DAY.exec(a), y = DAY.exec(b); return md(a) + ' → ' + (x[1] === y[1] && x[2] === y[2] ? +y[3] : md(b)); };
42
+ const clip = (s, n) => { s = String(s || ''); return s.length > n ? s.slice(0, n - 1) + '…' : s; };
43
+ const lagText = (n) => (n > 0 ? '+' + n + 'd' : n < 0 ? '−' + -n + 'd' : '+0d');
44
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
45
+
46
+ /* ── what the PM sees now: the Board's read, or a write's newer answer ── */
47
+ const CACHE = new Map(); // initiative id → { v, at } a write's answer, until a Board read as new (the ledger's last line, v.t)
48
+ const VIEWS = new Map(); // initiative id → the links view drawn last, with its titles
49
+ const SWEPT = new Set(); // initiatives the quiet pass ran for this session
50
+ let OPEN = null; // 'prop:<id>' while the blue ✦ list is open (proposals draw dashed)
51
+ let PIN = null; // { id, uid } the task pressed: its links draw dark
52
+ let HOVER = null; // { id, uid } the task under the pointer
53
+ let HOFF = 0; // the timer that lets go of HOVER a moment after the pointer leaves the bar
54
+ /** For the tests: forget the answers, the pins and the sweeps. */
55
+ export const resetLinks = () => { CACHE.clear(); VIEWS.clear(); SWEPT.clear(); OPEN = null; PIN = null; HOVER = null; };
56
+
57
+ /** The tasks the view names: uid → { title, start, due, jira, ms, closed } (the List's rows and the open Jira tickets). */
58
+ function tasksOfView(v) {
59
+ const M = new Map();
60
+ const walk = (s) => {
61
+ if (s.stages) { for (const x of s.stages) walk(x); return; }
62
+ for (const x of [...(s.top || []), ...(s.groups || []).flatMap((g) => g.rows), ...(s.done || []), ...(s.archived || [])]) if (x.uid) M.set(x.uid, { title: x.title, start: x.start, due: x.end, ms: !!x.ms, closed: !!x.closed });
63
+ if (s.jira) for (const k of s.jira.open) M.set(k.key, { title: k.key + ' ' + k.title, start: k.start || '', due: k.due, jira: true });
64
+ };
65
+ for (const s of (v.tasks && v.tasks.sections) || []) walk(s);
66
+ return M;
67
+ }
68
+ export function of(v) {
69
+ if (!v || (v.vs && v.vs.draft)) return null;
70
+ const id = v.id || v.key, c = CACHE.get(id), base = v.links || null;
71
+ const lk = c && (!base || String(base.t || '') < String(c.v.t || '')) ? c.v : base;
72
+ if (!lk) { VIEWS.delete(id); return null; }
73
+ const T = tasksOfView(v);
74
+ for (const l of lk.links || []) for (const u of [l.from, l.to]) if (!T.has(u) && l.other) T.set(u, { title: l.other.title, other: l.other });
75
+ const out = { ...lk, id, T };
76
+ VIEWS.set(id, out);
77
+ return out;
78
+ }
79
+ const nameOf = (lk, uid) => { const t = lk && lk.T.get(uid); return t ? t.title : uid; };
80
+ const waitsOn = (lk, uid) => (lk ? lk.links.filter((l) => l.to === uid) : []);
81
+ const thenOf = (lk, uid) => (lk ? lk.links.filter((l) => l.from === uid) : []);
82
+
83
+ /* ── the header ── */
84
+ export function headHtml(lk) {
85
+ if (!lk) return '';
86
+ let h = '';
87
+ const np = (lk.proposals || []).length;
88
+ if (np) h += `<button type="button" class="lk-chip pr" data-lk-chip="prop" aria-haspopup="dialog" aria-expanded="${OPEN === 'prop:' + lk.id}" aria-label="${esc('Claude proposes ' + plural(np, 'change', 'changes') + ' to the links. Open')}" title="Claude proposes">${SVG(PL.spark, 14, 2)}<b>${np}</b></button>`;
89
+ const nm = lk.moved ? lk.moved.n : 0, na = (lk.asks || []).filter((a) => !a.sent).length;
90
+ if (nm || na) h += `<button type="button" class="lk-chip mv" data-lk-chip="moved" aria-haspopup="dialog" aria-expanded="false" aria-label="${esc((nm ? 'Claude moved ' + plural(nm, 'task', 'tasks') + ' to keep your links' : '') + (nm && na ? '; ' : '') + (na ? plural(na, 'thing waits', 'things wait') + ' on you' : '') + '. Open')}" title="Kept in line">${SVG(PL.spark, 14, 2)}${nm ? `<b>${nm}</b>` : ''}${na ? '<i class="lk-ask" aria-hidden="true"></i>' : ''}</button>`;
91
+ const nl = (lk.late || []).length;
92
+ if (nl) h += `<button type="button" class="lk-chip lt" data-lk-chip="late" aria-pressed="${!!(PIN && PIN.uid === '*late' && PIN.id === lk.id)}" aria-label="${esc(plural(nl, 'task waits', 'tasks wait') + ' on a late task. Show the chain')}" title="Waits on a late task"><i aria-hidden="true"></i><b>${nl}</b></button>`;
93
+ return h;
94
+ }
95
+
96
+ /* ── the Timeline ── */
97
+ const endsOf = (lk, uid) => {
98
+ const s = new Set();
99
+ for (const l of lk.links) { if (l.from === uid) s.add(l.type[0] === 'f' ? 'r' : 'l'); if (l.to === uid) s.add(l.type[1] === 's' ? 'l' : 'r'); }
100
+ return s;
101
+ };
102
+ export function barExtra(x, lk, quick) {
103
+ if (!lk || !x.uid) return '';
104
+ const on = endsOf(lk, x.uid), late = (lk.late || []).includes(x.uid), mv = lk.moved && lk.moved.tasks.includes(x.uid);
105
+ const dot = (e) => `<span class="lk-dt ${e}${on.has(e) ? ' on' : ''}"${quick && !x.closed ? ` data-lk-dot="${e === 'l' ? 'start' : 'finish'}"` : ''} aria-hidden="true"></span>`;
106
+ return (quick && !x.closed ? dot('l') + dot('r') : (on.has('l') ? dot('l') : '') + (on.has('r') ? dot('r') : ''))
107
+ + (late ? '<span class="lk-le" aria-hidden="true"></span>' : '') + (mv ? `<span class="lk-mv" role="img" aria-label="Moved by Claude to keep a link" title="Moved by Claude to keep a link">${SVG(PL.spark, 10, 2.4)}</span>` : '');
108
+ }
109
+ /** What a bar says about its links, for its aria-label. */
110
+ export function barWords(x, lk) {
111
+ if (!lk || !x.uid) return '';
112
+ const w = waitsOn(lk, x.uid), t = thenOf(lk, x.uid), out = [];
113
+ if (w.length) out.push('waits on ' + w.map((l) => clip(nameOf(lk, l.from), 40)).join(', '));
114
+ if (t.length) out.push(plural(t.length, 'task waits', 'tasks wait') + ' on it');
115
+ if ((lk.late || []).includes(x.uid)) out.push('waits on a late task');
116
+ return out.join(', ');
117
+ }
118
+ export function dataOf(lk) {
119
+ if (!lk) return '';
120
+ const d = { id: lk.id, links: lk.links.map((l) => ({ f: l.from, t: l.to, y: l.type, g: l.lag, s: l.state })), props: (lk.proposals || []).filter((p) => p.kind === 'link').map((p) => ({ f: p.from, t: p.to, y: p.type })) };
121
+ return d.links.length || d.props.length ? ` data-lk="${esc(JSON.stringify(d))}"` : '';
122
+ }
123
+ /** The legend's key, only while a link is in view. */
124
+ export const legendHtml = (lk) => (lk && lk.links.length ? `<span>${SVG('M3 7h9v10h9M17 13l4 4-4 4', 16, 1.8)}Waits on</span>` : '');
125
+
126
+ const NS = 'http://www.w3.org/2000/svg';
127
+ /** The bar (or the Jira ticket's day) a uid draws as, in this Timeline. */
128
+ const barEl = (T, uid) => T.querySelector(`[data-ivt-bar="${CSS.escape(uid)}"], [data-ivt-jr="${CSS.escape(uid)}"]`);
129
+ export function draw(root, fresh) {
130
+ if (!root || !root.querySelectorAll || typeof document === 'undefined') return;
131
+ // fresh: only a Timeline not drawn yet (the host calls it after each redraw; the drawing itself must not draw again)
132
+ for (const T of root.querySelectorAll('.ivt[data-lk]')) { if (fresh && T.__lk) continue; T.__lk = true; drawOne(T); }
133
+ }
134
+ function drawOne(T) {
135
+ let d = null; try { d = JSON.parse(T.dataset.lk); } catch { d = null; }
136
+ const inner = T.querySelector('.ivt-in'); if (!d || !inner) return;
137
+ let svg = inner.querySelector(':scope > svg.lk-sv');
138
+ if (!svg) { svg = document.createElementNS(NS, 'svg'); svg.setAttribute('class', 'lk-sv'); svg.setAttribute('aria-hidden', 'true'); inner.appendChild(svg); }
139
+ for (const n of inner.querySelectorAll(':scope > .lk-jt')) n.remove();
140
+ while (svg.firstChild) svg.removeChild(svg.firstChild);
141
+ const box = inner.getBoundingClientRect();
142
+ svg.setAttribute('width', String(inner.scrollWidth)); svg.setAttribute('height', String(inner.scrollHeight));
143
+ const sel = (PIN && PIN.id === d.id ? PIN.uid : null) || (HOVER && HOVER.id === d.id ? HOVER.uid : null);
144
+ const lateSel = sel === '*late';
145
+ const at = (el, end) => { const r = el.getBoundingClientRect(); return { x: (end === 'r' ? r.right : r.left) - box.left, y: r.top + r.height / 2 - box.top, h: r.height }; };
146
+ const one = (l, cls, joint) => {
147
+ const a = barEl(T, l.f), b = barEl(T, l.t); if (!a || !b || !a.offsetParent || !b.offsetParent) return;
148
+ const p = at(a, l.y[0] === 'f' ? 'r' : 'l'), qe = l.y[1] === 's' ? 'l' : 'r', q = at(b, qe);
149
+ // an elbow: out of the waited-on end, along to just inside the waiting end, then down (or up) onto it, with an arrowhead
150
+ const vx = qe === 'l' ? q.x + 7 : q.x - 7, dn = q.y > p.y, ty = dn ? q.y - q.h / 2 - 1 : q.y + q.h / 2 + 1;
151
+ const path = document.createElementNS(NS, 'path');
152
+ path.setAttribute('d', `M${p.x} ${p.y}H${vx}V${ty}`); path.setAttribute('class', 'lk-ln ' + cls);
153
+ const head = document.createElementNS(NS, 'path');
154
+ head.setAttribute('d', dn ? `M${vx - 4} ${ty - 6}L${vx} ${ty}L${vx + 4} ${ty - 6}` : `M${vx - 4} ${ty + 6}L${vx} ${ty}L${vx + 4} ${ty + 6}`); head.setAttribute('class', 'lk-ah ' + cls);
155
+ svg.appendChild(path); svg.appendChild(head);
156
+ if (joint) {
157
+ const j = document.createElement('button');
158
+ j.type = 'button'; j.className = 'lk-jt ' + cls; j.dataset.lkJoint = l.f + '>' + l.t;
159
+ j.setAttribute('aria-label', 'The link: ' + typeName(l.y) + '. Change'); j.title = typeName(l.y) + (l.g ? ' ' + lagText(l.g) : '');
160
+ j.style.setProperty('--tl-lk-x', vx + 'px'); j.style.setProperty('--tl-lk-y', ((p.y + ty) / 2) + 'px');
161
+ inner.appendChild(j);
162
+ }
163
+ };
164
+ const lateSet = new Set(['late', 'jira', 'promise', 'done']);
165
+ for (const l of d.links) {
166
+ const mine = sel && (l.f === sel || l.t === sel);
167
+ const bad = lateSet.has(l.s);
168
+ if (lateSel ? bad : !(mine || bad)) continue;
169
+ one(l, (bad ? 'or' : 'dk') + (mine ? ' sel' : ''), true);
170
+ }
171
+ for (const l of d.props) if (OPEN === 'prop:' + d.id || (sel && (l.f === sel || l.t === sel))) one(l, 'pp', false);
172
+ // the bars that are part of what is drawn get a ring; a Jira ticket a link would move gets "!"
173
+ for (const n of T.querySelectorAll('.lk-on')) n.classList.remove('lk-on');
174
+ if (sel && !lateSel) { const s = barEl(T, sel); if (s) s.classList.add('lk-on'); }
175
+ for (const n of inner.querySelectorAll(':scope > .lk-bang')) n.remove();
176
+ for (const l of d.links) if (l.s === 'jira') { const b = barEl(T, l.t); if (!b) continue; const q = at(b, 'l'), x = document.createElement('span'); x.className = 'lk-bang'; x.textContent = '!'; x.setAttribute('aria-hidden', 'true'); x.style.setProperty('--tl-lk-x', q.x - 12 + 'px'); x.style.setProperty('--tl-lk-y', q.y + 'px'); inner.appendChild(x); }
177
+ }
178
+ const redrawAll = () => { if (typeof document !== 'undefined') draw(document); };
179
+
180
+ /* ── the List's and Kanban's meta: the link icon and the first task this one waits on, then +N ── */
181
+ export function metaHtml(x, lk, quick) {
182
+ if (!lk || !x.uid) return '';
183
+ const w = waitsOn(lk, x.uid), t = thenOf(lk, x.uid);
184
+ if (!w.length && !t.length) return '';
185
+ const bad = w.some((l) => l.state !== 'ok' && l.state !== 'short');
186
+ const first = w.length ? clip(nameOf(lk, w[0].from), 26) : '', more = w.length > 1 ? w.length - 1 : 0;
187
+ const lbl = (w.length ? 'Waits on ' + w.map((l) => nameOf(lk, l.from)).join(', ') : '') + (t.length ? (w.length ? '. ' : '') + plural(t.length, 'task waits', 'tasks wait') + ' on it' : '');
188
+ const inner = `${SVG(PL.link, 13, 2)}${first ? esc(first) : ''}${more ? ` <b>+${more}</b>` : ''}`;
189
+ return quick ? `<button type="button" class="lk-mt${bad ? ' w' : ''}" data-lk-meta="${esc(x.uid)}" aria-haspopup="dialog" aria-expanded="false" aria-label="${esc(lbl + '. Open')}" title="Waits on / Then">${inner}</button>`
190
+ : `<span class="lk-mt${bad ? ' w' : ''}" role="img" aria-label="${esc(lbl)}">${inner}</span>`;
191
+ }
192
+
193
+ /* ── the popover: right under its press; a bottom sheet on a phone ── */
194
+ let POP = null;
195
+ const phone = () => typeof matchMedia === 'function' && matchMedia('(max-width: 640px)').matches;
196
+ function closePop() { if (!POP) return; const { el, scrim, anchor, onClose } = POP; POP = null; el.remove(); if (scrim) scrim.remove(); if (anchor && anchor.isConnected) anchor.setAttribute('aria-expanded', 'false'); if (onClose) onClose(); }
197
+ function openPop(anchor, html, onPress, o = {}) {
198
+ closePop();
199
+ const sheet = (o.sheet && phone()) || o.forceSheet;
200
+ const el = document.createElement('div');
201
+ el.className = 'tkc ivq vs-pop lk-pop' + (sheet ? ' sheet' : ''); el.dataset.escLayer = ''; el.innerHTML = html;
202
+ let scrim = null;
203
+ if (sheet) { scrim = document.createElement('div'); scrim.className = 'vs-scrim'; document.body.appendChild(scrim); }
204
+ document.body.appendChild(el);
205
+ if (!sheet) {
206
+ const r = o.at || anchor.getBoundingClientRect(), w = el.offsetWidth, h = el.offsetHeight;
207
+ const left = Math.max(8, Math.min(r.left, innerWidth - w - 8)), below = r.bottom + 6 + h <= innerHeight - 8;
208
+ el.style.setProperty('--tl-x', left + 'px'); el.style.setProperty('--tl-y', (below ? r.bottom + 6 : Math.max(8, r.top - 6 - h)) + 'px');
209
+ }
210
+ if (anchor && anchor.setAttribute) anchor.setAttribute('aria-expanded', 'true');
211
+ POP = { el, scrim, anchor, onPress, onClose: o.onClose || null };
212
+ if (!o.noFocus) { const f = el.querySelector('input, button'); if (f) f.focus({ preventScroll: true }); }
213
+ return el;
214
+ }
215
+ if (typeof document !== 'undefined' && document.head) {
216
+ document.addEventListener('pointerdown', (e) => { if (POP && !POP.el.contains(e.target) && e.target !== POP.anchor && !(POP.anchor && POP.anchor.contains && POP.anchor.contains(e.target)) && e.target !== POP.scrim) closePop(); }, true);
217
+ // a press on a phone sheet's scrim closes it (the document's listener: the scrim is not a control)
218
+ document.addEventListener('click', (e) => { if (POP && POP.scrim && e.target === POP.scrim) closePop(); });
219
+ document.addEventListener('click', (e) => { if (!POP) return; const b = e.target.closest && e.target.closest('button'); if (b && POP.el.contains(b)) POP.onPress(b, e); });
220
+ document.addEventListener('input', (e) => { if (POP && POP.onInput && POP.el.contains(e.target)) POP.onInput(e.target); });
221
+ document.addEventListener('keydown', (e) => { if (POP && e.key === 'Escape') { e.stopPropagation(); const a = POP.anchor; closePop(); if (a && a.isConnected && a.focus) a.focus(); } }, true);
222
+ addEventListener('resize', () => { if (POP && !POP.scrim) closePop(); redrawAll(); });
223
+ // the task under the pointer draws its links (desktop); a press elsewhere in the Timeline lets go of the pressed one
224
+ document.addEventListener('pointerover', (e) => {
225
+ const t = e.target, bar = t && t.closest && t.closest('[data-ivt-bar], [data-ivt-jr]'), T = bar && bar.closest('.ivt[data-lk]');
226
+ const uid = bar ? bar.dataset.ivtBar || bar.dataset.ivtJr : null;
227
+ let id = null; try { id = T ? JSON.parse(T.dataset.lk).id : null; } catch { id = null; }
228
+ const nx = uid && id ? { id, uid } : null;
229
+ if ((nx && HOVER && nx.uid === HOVER.uid && nx.id === HOVER.id) || (!nx && !HOVER)) return;
230
+ if (!nx && t && t.closest && t.closest('.lk-jt, .lk-sv')) { clearTimeout(HOFF); return; } // on the joint: keep the lines
231
+ clearTimeout(HOFF);
232
+ // off a bar: the lines stay a moment, so the pointer can travel to a joint
233
+ if (!nx) { HOFF = setTimeout(() => { HOVER = null; redrawAll(); }, 700); return; }
234
+ HOVER = nx; redrawAll();
235
+ });
236
+ document.addEventListener('pointerdown', (e) => {
237
+ const t = e.target; if (!t || !t.closest) return;
238
+ if (t.closest('[data-lk-dot]')) { linkDown(e); return; }
239
+ const bar = t.closest('[data-ivt-bar], [data-ivt-jr]'), T = t.closest('.ivt[data-lk]');
240
+ if (!T) return;
241
+ let id = null; try { id = JSON.parse(T.dataset.lk).id; } catch { id = null; }
242
+ if (t.closest('.lk-jt')) return; // the joint's own press: the drawing (and the joint) stay as they are
243
+ const nx = bar ? { id, uid: bar.dataset.ivtBar || bar.dataset.ivtJr } : null;
244
+ if ((nx && PIN && nx.uid === PIN.uid && nx.id === PIN.id) || (!nx && !PIN)) return;
245
+ PIN = nx; redrawAll();
246
+ }, true);
247
+ document.addEventListener('pointermove', (e) => linkMove(e), true);
248
+ document.addEventListener('pointerup', (e) => linkUp(e), true);
249
+ }
250
+
251
+ /* ── link by dragging a dot onto another bar's end: the two ends joined set the type ── */
252
+ let LD = null, LINKED = 0; // LINKED: when a dot was last pressed (the bar's click that follows is not its date picker)
253
+ function linkDown(e) {
254
+ LINKED = Date.now();
255
+ const dot = e.target.closest('[data-lk-dot]'), bar = dot.closest('[data-ivt-bar]'), T = bar && bar.closest('.ivt[data-lk], .ivt');
256
+ if (!bar || !T || T.offsetWidth < 520) return;
257
+ e.stopPropagation(); e.preventDefault(); // not the bar's own drag
258
+ const inner = T.querySelector('.ivt-in');
259
+ LD = { from: bar.dataset.ivtBar, end: dot.dataset.lkDot, T, inner, x0: e.clientX, y0: e.clientY, target: null, tEnd: null };
260
+ try { dot.setPointerCapture(e.pointerId); } catch { /* the document still hears it */ }
261
+ dot.classList.add('drag');
262
+ }
263
+ function linkMove(e) {
264
+ const g = LD; if (!g) return;
265
+ e.stopPropagation();
266
+ const box = g.inner.getBoundingClientRect();
267
+ let svg = g.inner.querySelector(':scope > svg.lk-sv');
268
+ if (!svg) { svg = document.createElementNS(NS, 'svg'); svg.setAttribute('class', 'lk-sv'); g.inner.appendChild(svg); svg.setAttribute('width', String(g.inner.scrollWidth)); svg.setAttribute('height', String(g.inner.scrollHeight)); }
269
+ let tmp = svg.querySelector('.lk-tmp'); if (!tmp) { tmp = document.createElementNS(NS, 'path'); tmp.setAttribute('class', 'lk-ln pp lk-tmp'); svg.appendChild(tmp); }
270
+ const src = g.T.querySelector(`[data-ivt-bar="${CSS.escape(g.from)}"]`).getBoundingClientRect();
271
+ const sx = (g.end === 'finish' ? src.right + 9 : src.left - 9) - box.left, sy = src.top + src.height / 2 - box.top;
272
+ tmp.setAttribute('d', `M${sx} ${sy}L${e.clientX - box.left} ${e.clientY - box.top}`);
273
+ // the bar under the pointer, and its nearer end
274
+ const under = document.elementsFromPoint(e.clientX, e.clientY).map((n) => n.closest && n.closest('[data-ivt-bar], [data-ivt-jr]')).find((n) => n && (n.dataset.ivtBar || n.dataset.ivtJr) !== g.from) || null;
275
+ for (const n of g.T.querySelectorAll('.lk-tg')) n.classList.remove('lk-tg', 'l', 'r');
276
+ let tip = g.T.querySelector('.lk-tip');
277
+ if (!under) { g.target = null; if (tip) tip.remove(); return; }
278
+ const r = under.getBoundingClientRect(), endR = e.clientX > r.left + r.width / 2;
279
+ g.target = under.dataset.ivtBar || under.dataset.ivtJr; g.tEnd = endR ? 'finish' : 'start';
280
+ under.classList.add('lk-tg', endR ? 'r' : 'l');
281
+ const type = (g.end === 'finish' ? 'f' : 's') + (g.tEnd === 'start' ? 's' : 'f');
282
+ const lk = VIEWS.get(idOfT(g.T));
283
+ if (!tip) { tip = document.createElement('span'); tip.className = 'lk-tip'; g.inner.appendChild(tip); }
284
+ tip.innerHTML = `${SVG(PL[type], 13, 2)}<b>${esc(typeName(type))}</b> · ${esc(clip(nameOf(lk, g.target), 34))} waits on ${esc(clip(nameOf(lk, g.from), 34))}`;
285
+ tip.style.setProperty('--tl-lk-x', (endR ? r.right : r.left) - box.left + 'px'); tip.style.setProperty('--tl-lk-y', r.bottom - box.top + 6 + 'px');
286
+ }
287
+ const idOfT = (T) => { try { return JSON.parse(T.dataset.lk).id; } catch { const r = T.closest('[data-iv]'); return r ? r.dataset.iv : null; } };
288
+ const hostOf = (n) => { for (let e = n; e; e = e.parentElement) if (e.__iv) return e.__iv; return {}; };
289
+ function linkUp(e) {
290
+ const g = LD; if (!g) return;
291
+ LD = null; e.stopPropagation(); LINKED = Date.now();
292
+ for (const n of g.T.querySelectorAll('.lk-tg, .lk-dt.drag')) n.classList.remove('lk-tg', 'l', 'r', 'drag');
293
+ const tip = g.T.querySelector('.lk-tip'); if (tip) tip.remove();
294
+ const tmp = g.inner.querySelector('.lk-tmp'); if (tmp) tmp.remove();
295
+ if (!g.target) return;
296
+ const type = (g.end === 'finish' ? 'f' : 's') + (g.tEnd === 'start' ? 's' : 'f');
297
+ link(hostOf(g.T), idOfT(g.T), { from: g.from, to: g.target, type, lag: 0 });
298
+ }
299
+
300
+ /* ── the writes ── */
301
+ async function write(H, route, body) {
302
+ const at = H.where ? H.where() : {};
303
+ return pmPost('/api/task-links' + route, { ws: at.ws, board: at.board, ...body }).catch(() => null);
304
+ }
305
+ const say = (H, m, undo) => { if (H.toast) H.toast(m, undo); };
306
+ const failed = (H, res, m) => { say(H, (res && res.error) || m || 'Nothing was changed.'); return false; };
307
+ const took = (id, res) => { if (res && res.links !== undefined) CACHE.set(id, { v: res.links || { links: [], proposals: [], moved: null, asks: [], late: [], quiet: true, t: new Date().toISOString() }, at: new Date().toISOString() }); };
308
+ const after = async (H) => { if (H.reload) await H.reload(); else if (H.redraw) H.redraw(); };
309
+ const undoBatch = (H, batch) => async () => { const u = await write(H, '/undo', { batch }); if (!u || u.ok === false) { failed(H, u, 'The undo did not land.'); return; } if (u.kept) say(H, plural(u.kept, 'task was', 'tasks were') + ' changed since and kept ' + (u.kept === 1 ? 'its' : 'their') + ' dates.'); await after(H); };
310
+ /** "Moved 4 tasks with it · 1 can't move (Jira)", or what the move left waiting on the PM. */
311
+ function movedText(res, lead) {
312
+ const n = (res.moved || []).length, c = res.cant || [];
313
+ const jira = c.filter((x) => x.kind === 'jira').length, ms = c.filter((x) => x.kind !== 'jira' && x.kind !== 'done').length;
314
+ const bits = [n ? 'Moved ' + plural(n, 'task', 'tasks') + ' with it' : lead];
315
+ if (jira) bits.push(jira + ' can’t move (Jira)');
316
+ if (ms) bits.push(plural(ms, 'promise waits', 'promises wait') + ' on you');
317
+ return bits.join(' · ');
318
+ }
319
+ async function link(H, id, l) {
320
+ const res = await write(H, '/link', l);
321
+ if (!res || res.ok === false) return failed(H, res, 'The link was not made.');
322
+ took(id, res);
323
+ const lk = VIEWS.get(id);
324
+ const undo = async () => {
325
+ const u = res.from ? await write(H, '/link', { from: l.from, to: l.to, type: res.from.type, lag: res.from.lag }) : await write(H, '/unlink', { from: l.from, to: l.to });
326
+ if (res.batch) await write(H, '/undo', { batch: res.batch });
327
+ if (!u || u.ok === false) failed(H, u, 'The undo did not land.'); else took(id, u);
328
+ await after(H);
329
+ };
330
+ say(H, res.from ? typeName(l.type) + (l.lag ? ' ' + lagText(l.lag) : '') + ': ' + clip(nameOf(lk, l.to), 40) + '.' : movedText(res, 'Linked: ' + clip(nameOf(lk, l.to), 40) + ' waits on ' + clip(nameOf(lk, l.from), 40)) + '.', undo);
331
+ await after(H);
332
+ return true;
333
+ }
334
+ async function unlink(H, id, from, to) {
335
+ const res = await write(H, '/unlink', { from, to });
336
+ if (!res || res.ok === false) return failed(H, res);
337
+ const lk = VIEWS.get(id);
338
+ say(H, 'Unlinked: ' + clip(nameOf(lk, to), 40) + ' no longer waits on ' + clip(nameOf(lk, from), 40) + '.', async () => { const u = await write(H, '/link', res.from); if (u && u.ok) took(id, u); await after(H); });
339
+ CACHE.delete(id); await after(H);
340
+ return true;
341
+ }
342
+ /** The PM's own move of a task with links: its dates, then what waits on it; Undo puts them all back. */
343
+ async function ownMove(H, id, uid, patch) {
344
+ const res = await write(H, '/move', { task: uid, ...patch });
345
+ if (!res || res.ok === false) return failed(H, res);
346
+ const lk = VIEWS.get(id);
347
+ say(H, res.pulled ? 'Dates saved: ' + clip(nameOf(lk, uid), 40) + '. Claude proposes pulling ' + plural(res.pulled, 'task', 'tasks') + ' in (✦).' : movedText(res, 'Dates saved: ' + clip(nameOf(lk, uid), 40)) + '.', undoBatch(H, res.batch));
348
+ CACHE.delete(id); await after(H);
349
+ return true;
350
+ }
351
+
352
+ /* ── the blue ✦: Claude's proposals, ✓ each, Add all, ✕ for good ── */
353
+ function propHtml(lk) {
354
+ const P = lk.proposals || [];
355
+ const nl = P.filter((p) => p.kind === 'link').length;
356
+ const head = nl === P.length ? 'Claude proposes ' + plural(nl, 'link', 'links') : 'Claude proposes';
357
+ const row = (p) => {
358
+ let ic, t, s;
359
+ if (p.kind === 'link') { ic = SVG(PL[p.type] || PL.fs, 16, 1.8); t = `${esc(clip(nameOf(lk, p.from), 30))} ${SVG('M5 12h14M13 6l6 6-6 6', 12, 2.2)} ${esc(clip(nameOf(lk, p.to), 30))}`; s = p.why; }
360
+ else if (p.kind === 'pull') { ic = SVG(PL.undo, 16, 1.8); t = esc('Pull ' + plural(p.tasks.length, 'task', 'tasks') + ' in by ' + plural(p.days, 'day', 'days')); s = p.why + ': ' + p.tasks.map((u) => clip(nameOf(lk, u), 30)).join(', '); }
361
+ else { ic = SVG(PL.cal, 16, 1.8); t = esc('Move ' + plural(p.tasks.length, 'task', 'tasks') + ' to keep your links'); s = p.tasks.map((m) => clip(m.title || nameOf(lk, m.task), 26) + ' ' + span(m.to.start, m.to.due)).join(', '); }
362
+ return `<div class="lk-pr"><span class="ic" aria-hidden="true">${ic}</span><span class="w"><b>${t}</b><small>${esc(s)}</small></span>`
363
+ + `<button type="button" class="vs-ti ok" data-lk-yes="${esc(p.id)}" aria-label="Approve" title="Approve">${SVG(PL.check, 16, 2.4)}</button><button type="button" class="vs-ti" data-lk-no="${esc(p.id)}" aria-label="Drop it" title="Drop it">${SVG(PL.x, 15, 2)}</button></div>`;
364
+ };
365
+ return `<div class="tkc-pop lk-m" role="dialog" aria-label="${esc(head)}"><div class="lk-mh">${SVG(PL.spark, 14, 2)}<b>${esc(head)}</b>${P.length > 1 ? `<button type="button" class="vs-ok" data-lk-all aria-label="Add all" title="Add all">${SVG(PL.check, 16, 2.4)}</button>` : ''}</div>${P.map(row).join('')}</div>`;
366
+ }
367
+ function openProps(b, H, id) {
368
+ const lk = VIEWS.get(id); if (!lk) return;
369
+ OPEN = 'prop:' + id; redrawAll();
370
+ openPop(b, propHtml(lk), async (x) => {
371
+ const q = x.dataset;
372
+ if ('lkAll' in q || q.lkYes) {
373
+ const ids = 'lkAll' in q ? (VIEWS.get(id).proposals || []).map((p) => p.id) : [q.lkYes];
374
+ closePop();
375
+ const res = await write(H, '/accept', { initiative: id, ids });
376
+ if (!res || res.ok === false) { failed(H, res); return; }
377
+ took(id, res);
378
+ const n = res.linked.length, m = res.moved.length;
379
+ say(H, [n ? plural(n, 'link', 'links') + ' added' : '', m ? 'moved ' + plural(m, 'task', 'tasks') + ' to keep ' + (n === 1 ? 'it' : 'them') : ''].filter(Boolean).join(', ').replace(/^./, (c) => c.toUpperCase()) + '.',
380
+ n ? async () => { for (const l of res.linked) await write(H, '/unlink', l); CACHE.delete(id); await after(H); } : undefined);
381
+ await after(H);
382
+ return;
383
+ }
384
+ if (q.lkNo) {
385
+ const res = await write(H, '/drop', { initiative: id, id: q.lkNo });
386
+ if (!res || res.ok === false) { failed(H, res); return; }
387
+ const v = VIEWS.get(id); if (v) { v.proposals = v.proposals.filter((p) => p.id !== q.lkNo); CACHE.set(id, { v: { ...v, T: undefined }, at: new Date().toISOString() }); }
388
+ if (v && v.proposals.length && POP) POP.el.innerHTML = propHtml(v); else closePop();
389
+ if (H.redraw) H.redraw();
390
+ }
391
+ }, { sheet: true, onClose: () => { OPEN = null; redrawAll(); } });
392
+ }
393
+
394
+ /* ── the grey ✦: what Claude moved quietly, Undo all; Needs you (✓ / ✕); the switch for quiet moves ── */
395
+ function movedHtml(lk) {
396
+ const B = lk.moved ? lk.moved.batches : [], A = (lk.asks || []).filter((a) => !a.sent);
397
+ let h = '';
398
+ if (B.length) {
399
+ const when = B[0].at ? new Date(B[0].at) : null, hm = when ? String(when.getHours()).padStart(2, '0') + ':' + String(when.getMinutes()).padStart(2, '0') : '';
400
+ h += `<div class="lk-mh">${SVG(PL.spark, 14, 2)}<b>Moved to keep your links${hm ? ' · ' + (when.toDateString() === new Date().toDateString() ? 'today ' : md(when.toISOString())) + hm : ''}</b><button type="button" class="vs-ti" data-lk-undoall aria-label="Undo all" title="Undo all">${SVG(PL.undo, 16, 1.8)}</button></div>`;
401
+ for (const b of B) for (const m of b.moves) h += `<div class="lk-pr mv"><span class="ic" aria-hidden="true">${SVG(PL.spark, 14, 2)}</span><span class="w"><b>${esc(clip(m.title, 36))} · ${esc(span(m.to.start, m.to.due))}</b><small>${esc('Was ' + span(m.from.start, m.from.due) + '. ' + (m.why || '').replace(/^./, (c) => c.toUpperCase()))}</small></span></div>`;
402
+ }
403
+ if (A.length) {
404
+ h += `${B.length ? '<hr>' : ''}<span class="h lk-ny">Needs you</span>`;
405
+ for (const a of A) {
406
+ const ic = a.kind === 'jira' ? `<span class="ic jr" aria-hidden="true">${SVG(PL.jira, 14, 2)}</span>` : `<span class="ic ms" aria-hidden="true">${SVG(PL.dia, 14, 2.2)}</span>`;
407
+ const t = a.kind === 'jira' ? a.head : 'Move ' + (a.ms ? '◇ ' : '') + clip(a.title, 34) + ' to ' + md(a.to.due) + '?';
408
+ h += `<div class="lk-pr">${ic}<span class="w"><b>${esc(t)}</b><small>${esc(a.text)}</small></span><button type="button" class="vs-ok" data-lk-ay="${esc(a.id)}" aria-label="${a.kind === 'jira' ? 'Put the comment in the outbox' : 'Move it'}" title="${a.kind === 'jira' ? 'Put the comment in the outbox' : 'Move it'}">${SVG(PL.check, 16, 2.4)}</button><button type="button" class="vs-ti" data-lk-an="${esc(a.id)}" aria-label="Keep the date" title="Keep the date">${SVG(PL.x, 15, 2)}</button></div>`;
409
+ }
410
+ }
411
+ h += `<hr><button type="button" class="o lk-q" role="menuitemcheckbox" aria-checked="${!!lk.quiet}" data-lk-quiet><span class="nn">Keep dates in line quietly<small>${lk.quiet ? 'Claude moves what waits, and lists it here' : 'Off: every move is a proposal under the blue ✦'}</small></span><i class="lk-sw${lk.quiet ? ' on' : ''}" aria-hidden="true"></i></button>`;
412
+ return `<div class="tkc-pop lk-m" role="dialog" aria-label="Kept in line">${h}</div>`;
413
+ }
414
+ function openMoved(b, H, id) {
415
+ const lk = VIEWS.get(id); if (!lk) return;
416
+ if (lk.moved && lk.moved.n) write(H, '/seen', { initiative: id }); // the PM has seen them: the count and the ✦ on the bars go at the next read
417
+ openPop(b, movedHtml(lk), async (x) => {
418
+ const q = x.dataset;
419
+ if ('lkUndoall' in q) {
420
+ closePop();
421
+ for (const bt of lk.moved.batches) await write(H, '/undo', { batch: bt.batch });
422
+ say(H, 'Undone: the dates are back as they were.'); CACHE.delete(id); await after(H);
423
+ return;
424
+ }
425
+ if (q.lkAy || q.lkAn) {
426
+ const a = (lk.asks || []).find((z) => z.id === (q.lkAy || q.lkAn));
427
+ closePop();
428
+ const res = await write(H, '/ask', { initiative: id, id: q.lkAy || q.lkAn, answer: q.lkAy ? 'yes' : 'no' });
429
+ if (!res || res.ok === false) { failed(H, res); return; }
430
+ if (q.lkAn) say(H, 'Kept the date. The link stays orange.');
431
+ else if (res.outbox) say(H, 'The comment is in the outbox for ' + (a ? a.task : 'the ticket') + '.');
432
+ else say(H, 'Moved ' + clip(a ? a.title : 'it', 40) + (res.moved > 1 ? ' and ' + plural(res.moved - 1, 'task', 'tasks') + ' after it' : '') + '.', res.batch ? undoBatch(H, res.batch) : undefined);
433
+ CACHE.delete(id); await after(H);
434
+ return;
435
+ }
436
+ if ('lkQuiet' in q) {
437
+ const on = !lk.quiet;
438
+ const res = await write(H, '/quiet', { initiative: id, on });
439
+ if (!res || res.ok === false) { failed(H, res); return; }
440
+ lk.quiet = on; if (POP) POP.el.innerHTML = movedHtml(lk);
441
+ say(H, on ? 'Claude keeps the dates in line quietly again.' : 'Quiet moves are off: Claude proposes each move instead.');
442
+ CACHE.delete(id); await after(H);
443
+ }
444
+ }, { sheet: true });
445
+ }
446
+
447
+ /* ── a joint: the type (4 icons), the lag (± days), unlink, and the link in one sentence ── */
448
+ function jointHtml(lk, l) {
449
+ const a = clip(nameOf(lk, l.from), 34), b = clip(nameOf(lk, l.to), 34);
450
+ const verb = { fs: ['starts when', 'finishes'], ss: ['starts when', 'starts'], ff: ['finishes when', 'finishes'], sf: ['finishes when', 'starts'] }[l.type];
451
+ const seg = TYPES.map(([k, n]) => `<button type="button" class="${k === l.type ? 'on' : ''}" role="radio" aria-checked="${k === l.type}" data-lk-type="${k}" aria-label="${esc(n)}" title="${esc(n)}">${SVG(PL[k], 16, 1.8)}${k === l.type ? esc(n) : ''}</button>`).join('');
452
+ return `<div class="tkc-pop lk-jc" role="dialog" aria-label="The link"><div class="lk-jr"><div class="seg" role="radiogroup" aria-label="Type">${seg}</div><span class="vr" aria-hidden="true"></span>`
453
+ + `<span class="lk-lag"><button type="button" class="vs-ti" data-lk-lag="-1" aria-label="A day less" title="A day less">${SVG(PL.minus, 14, 2)}</button><b aria-live="polite">${esc(lagText(l.lag || 0))}</b><button type="button" class="vs-ti" data-lk-lag="1" aria-label="A day more" title="A day more">${SVG(PL.plus, 14, 2)}</button></span><span class="vr" aria-hidden="true"></span>`
454
+ + `<button type="button" class="vs-ti" data-lk-unlink aria-label="Unlink" title="Unlink">${SVG(PL.unlink, 16, 1.8)}</button></div>`
455
+ + `<p class="lk-say"><b>${esc(b)}</b> ${verb[0]} <b>${esc(a)}</b> ${verb[1]}${l.lag ? ', ' + (l.lag > 0 ? plural(l.lag, 'day', 'days') + ' after' : plural(-l.lag, 'day', 'days') + ' before') : ''}</p></div>`;
456
+ }
457
+ function openJoint(b, H, id, key) {
458
+ const lk = VIEWS.get(id); if (!lk) return;
459
+ const [from, to] = key.split('>');
460
+ const l0 = lk.links.find((x) => x.from === from && x.to === to); if (!l0) return;
461
+ const l = { ...l0 };
462
+ openPop(b, jointHtml(lk, l), async (x) => {
463
+ const q = x.dataset;
464
+ if (q.lkType) { if (q.lkType === l.type) return; l.type = q.lkType; closePop(); await link(H, id, { from, to, type: l.type, lag: l.lag || 0 }); return; }
465
+ if (q.lkLag) { l.lag = (l.lag || 0) + Number(q.lkLag); if (POP) { POP.el.innerHTML = jointHtml(lk, l); } clearTimeout(POP && POP.t); const P = POP; if (P) P.t = setTimeout(() => { if (POP === P) closePop(); link(H, id, { from, to, type: l.type, lag: l.lag }); }, 900); return; }
466
+ if ('lkUnlink' in q) { closePop(); await unlink(H, id, from, to); }
467
+ });
468
+ }
469
+
470
+ /* ── Waits on / Then: the List's and Kanban's link, the phone's sheet; a search for a task or a milestone here or in another initiative ── */
471
+ let POOL = null; // { at, items } the board's tasks, for the search
472
+ async function pool(H) {
473
+ if (POOL && Date.now() - POOL.at < 60000) return POOL.items;
474
+ const at = H.where ? H.where() : {};
475
+ try { const r = await (await fetch('/api/boards/items?ws=' + encodeURIComponent(at.ws || '') + '&board=' + encodeURIComponent(at.board || ''), { credentials: 'same-origin' })).json(); POOL = { at: Date.now(), items: (r && r.items) || [] }; } catch { POOL = { at: Date.now(), items: [] }; }
476
+ return POOL.items;
477
+ }
478
+ const sub = (l, lk, side) => {
479
+ const t = lk.T.get(side === 'from' ? l.from : l.to) || {};
480
+ const w = { fs: side === 'from' ? 'Starts after it finishes' : 'Starts after this finishes', ss: 'Starts when it starts', ff: 'Finishes when it finishes', sf: 'Finishes when it starts' }[l.type];
481
+ return [l.other && l.other.ini ? 'Another initiative' : '', w, t.ms ? '◇ ' + md(t.due) : span(t.start, t.due)].filter(Boolean).join(' · ');
482
+ };
483
+ function sheetHtml(lk, uid, o = {}) {
484
+ const w = waitsOn(lk, uid), t = thenOf(lk, uid);
485
+ const cant = (l) => l.state === 'jira' || l.state === 'promise' || l.state === 'done';
486
+ const row = (l, side) => `<button type="button" class="o lk-wr" data-lk-joint="${esc(l.from + '>' + l.to)}"><span class="ck" aria-hidden="true">${SVG(PL[l.type], 16, 1.8)}</span><span class="nn">${l.other && l.other.tile ? `<i class="lk-tile">${esc(l.other.tile)}</i>` : ''}${esc(clip(nameOf(lk, side === 'from' ? l.from : l.to), 46))}<small>${esc(sub(l, lk, side))}</small></span>`
487
+ + `${side === 'to' && cant(l) ? '<span class="lk-cm">can’t move</span>' : (l.lag ? `<span class="k">${esc(lagText(l.lag))}</span>` : '')}</button>`;
488
+ let h = o.title ? `<b class="lk-st">${esc(o.title)}</b>` : '';
489
+ if (w.length || o.search) h += '<span class="h">Waits on</span>' + w.map((l) => row(l, 'from')).join('');
490
+ if (o.search) h += `<label class="lk-sr">${SVG(PL.search, 15, 2)}<input type="search" data-lk-find placeholder="Find a task or a milestone, here or in another initiative" aria-label="Find a task or a milestone to wait on"></label><div class="lk-res" data-lk-res></div>`;
491
+ if (t.length) h += '<hr><span class="h">Then</span>' + t.map((l) => row(l, 'to')).join('');
492
+ if (o.dates) h += `<hr><button type="button" class="o" data-lk-dates><span class="ck" aria-hidden="true">${SVG(PL.cal, 15, 1.8)}</span><span class="nn">Change the dates</span></button>`;
493
+ if (o.add) h += `<button type="button" class="o" data-lk-add><span class="ck" aria-hidden="true">${SVG(PL.plus, 15, 2)}</span><span class="nn">Add a link</span></button>`;
494
+ return `<div class="tkc-pop ivq-m lk-m lk-wt" role="dialog" aria-label="Waits on and then">${h}</div>`;
495
+ }
496
+ function openWaits(b, H, id, uid, o = {}) {
497
+ const lk = VIEWS.get(id); if (!lk) return;
498
+ let opts = { search: !o.phone, ...o };
499
+ const el = openPop(b, sheetHtml(lk, uid, opts), async (x) => {
500
+ const q = x.dataset;
501
+ if (q.lkJoint) { closePop(); openJoint(b, H, id, q.lkJoint); return; }
502
+ if ('lkDates' in q) { closePop(); if (o.onDates) o.onDates(); return; }
503
+ if ('lkAdd' in q) { opts = { ...opts, search: true, add: false }; POP.el.innerHTML = sheetHtml(lk, uid, opts); const i = POP.el.querySelector('[data-lk-find]'); if (i) i.focus(); return; }
504
+ if (q.lkPick) { closePop(); await link(H, id, { from: q.lkPick, to: uid, type: 'fs', lag: 0 }); }
505
+ }, { sheet: true, forceSheet: !!o.phone, noFocus: !!o.phone });
506
+ if (!el) return;
507
+ POP.onInput = async (inp) => {
508
+ if (!inp.matches('[data-lk-find]')) return;
509
+ const s = inp.value.trim().toLowerCase(), res = POP.el.querySelector('[data-lk-res]'); if (!res) return;
510
+ if (s.length < 2) { res.innerHTML = ''; return; }
511
+ const items = await pool(H);
512
+ const have = new Set(waitsOn(lk, uid).map((l) => l.from).concat(uid));
513
+ const hits = items.filter((x) => x && x.kind !== 'Epic' && x.uid && !have.has(x.uid) && x.status !== 'Archived' && (String(x.title || '').toLowerCase().includes(s) || String(x.uid).toLowerCase().includes(s))).slice(0, 8);
514
+ res.innerHTML = hits.length ? hits.map((x) => `<button type="button" class="o" data-lk-pick="${esc(x.uid)}"><span class="ck" aria-hidden="true">${SVG(x.milestone ? PL.dia : x.src === 'jira' ? PL.jira : PL.link, 14, 2)}</span><span class="nn">${esc(clip(x.src === 'jira' ? x.uid + ' ' + x.title : x.title, 50))}<small>${esc([x.ini && x.ini !== id ? 'Another initiative · ' + x.ini : '', x.milestone ? '◇ ' + md(x.end) : span(x.start, x.end)].filter(Boolean).join(' · '))}</small></span></button>`).join('')
515
+ : '<p class="lk-none">No task or milestone by that name</p>';
516
+ };
517
+ }
518
+
519
+ /* ── the presses ── */
520
+ export function press(b, d, root, H) {
521
+ const id = root && root.dataset.iv; if (!id) return false;
522
+ if (d.lkChip) {
523
+ if (POP && POP.anchor === b) { closePop(); return true; }
524
+ if (d.lkChip === 'prop') openProps(b, H, id);
525
+ else if (d.lkChip === 'moved') openMoved(b, H, id);
526
+ else { PIN = PIN && PIN.uid === '*late' ? null : { id, uid: '*late' }; b.setAttribute('aria-pressed', String(!!PIN)); redrawAll(); }
527
+ return true;
528
+ }
529
+ if (d.lkJoint) { openJoint(b, H, id, d.lkJoint); return true; }
530
+ if (d.lkMeta) { openWaits(b, H, id, d.lkMeta); return true; }
531
+ if (d.ivtBar && Date.now() - LINKED < 600) return true;
532
+ // a phone: a tap on a bar with links draws them and opens Waits on / Then; its dates are one row down
533
+ if (d.ivtBar) {
534
+ const T = b.closest('.ivt'), lk = VIEWS.get(id);
535
+ if (T && T.offsetWidth < 520 && lk && (waitsOn(lk, d.ivtBar).length || thenOf(lk, d.ivtBar).length)) {
536
+ PIN = { id, uid: d.ivtBar }; redrawAll();
537
+ const t = lk.T.get(d.ivtBar) || {};
538
+ openWaits(b, H, id, d.ivtBar, { phone: true, title: t.title, dates: true, add: true, onDates: () => { if (H.__dates) H.__dates(b); } });
539
+ return true;
540
+ }
541
+ }
542
+ return false;
543
+ }
544
+ /** The host's handlers, with the PM's own move of a linked task routed here (what waits follows; Undo takes all of it back). */
545
+ export function wrap(H, idOf) {
546
+ const W = { ...H };
547
+ W.dates = (uid, patch) => {
548
+ const id = idOf(), lk = id && VIEWS.get(id);
549
+ if (lk && !/^dt:/.test(String(uid)) && lk.links.some((l) => l.from === uid || l.to === uid) && !('milestone' in patch)) return ownMove(W, id, uid, patch);
550
+ return H.dates && H.dates(uid, patch);
551
+ };
552
+ return W;
553
+ }
554
+ /** Once per initiative and session, when its Tasks show and it has links: the quiet pass (a date changed outside a drag, a late task). */
555
+ export async function sweep(id, H) {
556
+ const lk = VIEWS.get(id);
557
+ if (!id || SWEPT.has(id) || !lk || !lk.links.length || !lk.quiet) return;
558
+ SWEPT.add(id);
559
+ const res = await write(H, '/sweep', { initiative: id });
560
+ if (res && res.ok && res.moved) { took(id, res); await after(H); }
561
+ }