create-pmos 0.402.0 → 0.404.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 (110) hide show
  1. package/package.json +25 -30
  2. package/payload/AGENTS.md +2 -0
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/mods/pmos-cockpit/hooks/lib/session-facts.mjs +1 -1
  5. package/payload/planning/evals/eval-calibration.md +1 -1
  6. package/payload/planning/okrs/health-budgets.md +1 -1
  7. package/payload/state/discoveries.md +1 -1
  8. package/workspace/board-programs-test.js +32 -5
  9. package/workspace/briefing-premium-adddoc-test.js +28 -22
  10. package/workspace/briefing-premium-board-test.js +91 -73
  11. package/workspace/briefing-premium-calendar-2-test.js +23 -10
  12. package/workspace/briefing-premium-calendar-3-test.js +23 -19
  13. package/workspace/briefing-premium-calendar-test.js +19 -17
  14. package/workspace/briefing-premium-initiative-test.js +25 -12
  15. package/workspace/briefing-premium-insights-test.js +31 -18
  16. package/workspace/briefing-premium-metrics-test.js +8 -8
  17. package/workspace/briefing-premium-test.js +4 -3
  18. package/workspace/changelog.json +24 -0
  19. package/workspace/fixtures/premium-viewer-fixtures.js +24 -2
  20. package/workspace/guide/jira.md +38 -6
  21. package/workspace/guide/programs.md +2 -0
  22. package/workspace/home-rows-test.js +184 -0
  23. package/workspace/lib/briefing-premium-agent.js +3 -0
  24. package/workspace/lib/calendar-layers.js +8 -4
  25. package/workspace/lib/initiative-layout.js +4 -3
  26. package/workspace/lib/jira-cli.js +17 -12
  27. package/workspace/lib/jira-status.js +1 -1
  28. package/workspace/lib/jira-tickets.js +126 -24
  29. package/workspace/lib/meeting-files.js +58 -0
  30. package/workspace/lib/meeting-learn.js +139 -0
  31. package/workspace/lib/meeting-material.js +12 -5
  32. package/workspace/lib/notes.js +3 -0
  33. package/workspace/lib/program-chat.js +32 -0
  34. package/workspace/lib/routes-brief-page.js +8 -1
  35. package/workspace/lib/routes-calendar-views.js +24 -3
  36. package/workspace/lib/routes-meeting-material.js +38 -0
  37. package/workspace/lib/routes-meeting-points.js +23 -3
  38. package/workspace/package-lock.json +2 -2
  39. package/workspace/package.json +1 -1
  40. package/workspace/premium-board-actions-test.js +30 -24
  41. package/workspace/premium-chat-context-test.js +1 -1
  42. package/workspace/premium-chat-goal-view-test.js +1 -1
  43. package/workspace/premium-chat-viewer-test.js +1 -1
  44. package/workspace/premium-core-doc-issue-test.js +13 -7
  45. package/workspace/premium-discuss-landing-test.js +83 -0
  46. package/workspace/premium-link-suggest-test.js +103 -0
  47. package/workspace/premium-report-read-test.js +86 -82
  48. package/workspace/premium-vw-backlog-test.js +6 -5
  49. package/workspace/premium-vw-cal-test.js +46 -23
  50. package/workspace/premium-vw-item-test.js +8 -6
  51. package/workspace/premium-vw-jira-test.js +3 -2
  52. package/workspace/premium-vw-meet-test.js +122 -66
  53. package/workspace/premium-vw-notes-test.js +7 -6
  54. package/workspace/premium-vw-rec-test.js +14 -13
  55. package/workspace/premium-vw-slides-test.js +11 -5
  56. package/workspace/program-panel-test.js +64 -55
  57. package/workspace/public/pm/bd-acts.js +1 -1
  58. package/workspace/public/pm/bd-asks.js +22 -7
  59. package/workspace/public/pm/bd-ini-panel.js +232 -0
  60. package/workspace/public/pm/bd-pop.js +2 -2
  61. package/workspace/public/pm/bd-prog-panel.js +176 -191
  62. package/workspace/public/pm/cozy-board.css +5 -28
  63. package/workspace/public/pm/cozy-evui.js +4 -2
  64. package/workspace/public/pm/cozy-home-rows.css +54 -0
  65. package/workspace/public/pm/cozy-home.css +9 -0
  66. package/workspace/public/pm/cozy-insights.css +1 -2
  67. package/workspace/public/pm/cozy-mtg-present.css +160 -0
  68. package/workspace/public/pm/cozy-panel.css +11 -34
  69. package/workspace/public/pm/cozy-rec-pill.css +12 -0
  70. package/workspace/public/pm/cozy-rec-pill.js +46 -0
  71. package/workspace/public/pm/cozy-viewer.js +307 -43
  72. package/workspace/public/pm/cozy-vw-mtg.css +96 -94
  73. package/workspace/public/pm/cozy-vw-rp.css +40 -25
  74. package/workspace/public/pm/cozy-vw-shell.css +127 -0
  75. package/workspace/public/pm/cozy-xv.css +51 -0
  76. package/workspace/public/pm/cozy-xv.js +34 -0
  77. package/workspace/public/pm/goal-chat.js +1 -1
  78. package/workspace/public/pm/home-app.js +122 -58
  79. package/workspace/public/pm/home-chat.js +11 -2
  80. package/workspace/public/pm/home-day.js +64 -0
  81. package/workspace/public/pm/home-ini-model.js +1 -1
  82. package/workspace/public/pm/home-ini.js +197 -54
  83. package/workspace/public/pm/home-list.js +6 -14
  84. package/workspace/public/pm/home-mentions.js +187 -0
  85. package/workspace/public/pm/home-rec-row.js +67 -0
  86. package/workspace/public/pm/home-review.js +20 -10
  87. package/workspace/public/pm/home-task.js +19 -18
  88. package/workspace/public/pm/home-today.js +3 -3
  89. package/workspace/public/pm/premium-board.js +83 -235
  90. package/workspace/public/pm/premium-insights.js +118 -82
  91. package/workspace/public/pm/premium-mtg-present.js +408 -100
  92. package/workspace/public/pm/premium-mtg-replay.js +70 -10
  93. package/workspace/public/pm/premium-report-read.js +118 -63
  94. package/workspace/public/pm/premium-vw-cal.js +62 -34
  95. package/workspace/public/pm/premium-vw-mtg.js +348 -192
  96. package/workspace/public/pm/rec-state.js +63 -0
  97. package/workspace/public/pm/rp-parts.js +33 -8
  98. package/workspace/public/pm/tk-draft.js +107 -0
  99. package/workspace/public/pm/tk-model.js +134 -0
  100. package/workspace/public/pm/tk-send.js +124 -0
  101. package/workspace/public/pm/tk-tasks.css +120 -0
  102. package/workspace/public/premium-board.html +0 -1
  103. package/workspace/server.js +4 -2
  104. package/workspace/skills/jira-push.skill +3 -3
  105. package/workspace/test-lists/prd-to-jira.json +6 -0
  106. package/workspace/test-lists/program-chat.json +6 -0
  107. package/workspace/test-lists/viewer-home-rows.json +9 -0
  108. package/workspace/test-lists/viewer-meetings.json +9 -0
  109. package/workspace/test-lists/viewer-shell-a.json +15 -0
  110. package/workspace/tk-tasks-test.js +199 -0
@@ -0,0 +1,63 @@
1
+ /* pm/rec-state.js — is a meeting recording now? One answer for every page (Viewer kit, meetings: the pinned row on Home, XvARecHome;
2
+ * the pill on Board and Insights, XvARecBoard).
3
+ *
4
+ * recState({ fresh }) → Promise<State> the recording now, read from GET /api/notes (kept 5 s unless fresh)
5
+ * onRecording(fn) → unsubscribe fn(State) now and on each change; while someone listens the page reads again every 10 s
6
+ * announce() a page that just started, paused, resumed or stopped a recording asks for a fresh read
7
+ * EVENT = 'cz:recording' the same State, as a CustomEvent on document, on each change
8
+ * window.czRecording = { state: recState, on: onRecording }
9
+ *
10
+ * State = { on, paused, id, title, startedAt, elapsedMs, href, here }
11
+ * on a note is recording or paused (false: no recording; every other field is then empty)
12
+ * paused it is paused (nothing is kept until it resumes)
13
+ * startedAt ms when this stretch of the meeting clock started, so a page can tick it: elapsed = elapsedMs + (Date.now() - readAt)
14
+ * elapsedMs the meeting time heard so far, at readAt
15
+ * href where the recording is shown: Home with the meeting open (/premium.html?meeting=<note id>)
16
+ * here this page holds the recorder (premium-meeting.js sets window.__premiumHolding)
17
+ * The answer comes from the notes the server keeps, so a page that did not start the recording still knows of it. Nothing is written. */
18
+ import { pmGet } from './http.js';
19
+
20
+ export const EVENT = 'cz:recording';
21
+ const OFF = Object.freeze({ on: false, paused: false, id: '', title: '', startedAt: 0, elapsedMs: 0, readAt: 0, href: '', here: false });
22
+ let last = null, lastAt = 0, inflight = null, timer = null;
23
+ const subs = new Set();
24
+ const same = (a, b) => !!a && !!b && a.on === b.on && a.paused === b.paused && a.id === b.id && a.title === b.title;
25
+
26
+ /** The State of the note list (pure). rows: GET /api/notes .notes */
27
+ export function stateOf(rows, now = Date.now(), holding = null) {
28
+ const live = (Array.isArray(rows) ? rows : []).filter((n) => n && (n.state === 'recording' || n.state === 'paused'));
29
+ if (!live.length) return { ...OFF, readAt: now };
30
+ const n = live.find((x) => x.state === 'recording') || live[0];
31
+ const el = Math.max(0, Number(n.meeting_ms) || 0);
32
+ return { on: true, paused: n.state === 'paused', id: String(n.id), title: String((n.meeting && n.meeting.title) || n.title || 'Meeting'), startedAt: n.state === 'recording' ? now - el : 0,
33
+ elapsedMs: el, readAt: now, href: '/premium.html?meeting=' + encodeURIComponent(n.id), here: !!(holding && holding.id === n.id) };
34
+ }
35
+
36
+ export async function recState({ fresh = false } = {}) {
37
+ if (!fresh && last && Date.now() - lastAt < 5000) return last;
38
+ if (!inflight) inflight = pmGet('/api/notes').then((r) => {
39
+ const s = stateOf(r && r.ok ? r.notes : [], Date.now(), typeof window !== 'undefined' ? window.__premiumHolding : null);
40
+ const changed = !same(s, last);
41
+ last = s; lastAt = Date.now();
42
+ if (changed) emit(s);
43
+ return s;
44
+ }).catch(() => last || { ...OFF }).finally(() => { inflight = null; });
45
+ return inflight;
46
+ }
47
+ function emit(s) {
48
+ for (const fn of subs) { try { fn(s); } catch { /* one listener does not stop the rest */ } }
49
+ try { document.dispatchEvent(new CustomEvent(EVENT, { detail: s })); } catch { /* no document */ }
50
+ }
51
+
52
+ export function onRecording(fn) {
53
+ if (typeof fn !== 'function') return () => {};
54
+ subs.add(fn);
55
+ recState().then((s) => { if (subs.has(fn)) { try { fn(s); } catch { /* the listener's own */ } } });
56
+ if (!timer && typeof setInterval === 'function') timer = setInterval(() => { if (typeof document === 'undefined' || !document.hidden) recState({ fresh: true }); }, 10000);
57
+ return () => { subs.delete(fn); if (!subs.size && timer) { clearInterval(timer); timer = null; } };
58
+ }
59
+
60
+ /** A recording was started, paused, resumed or stopped on this page: read again now. */
61
+ export function announce() { return recState({ fresh: true }); }
62
+
63
+ if (typeof window !== 'undefined') window.czRecording = { state: recState, on: onRecording, EVENT };
@@ -9,6 +9,9 @@
9
9
  * paperModel(W, o) · paperHtml(P) the report as a paper document, cut into pages (RpDoc)
10
10
  * liveModel(m, o) · liveHtml(L, s) the report as a live page, from GET /api/insights-premium (RpLive)
11
11
  * presentHtml(o) the full-screen presenting view (RpPhone Present, MtPresent's strip)
12
+ * reportSummary(o) the summary card on top of a report in Viewer shell A (XvAReport, XvAReportDoc): one line, the
13
+ * words, the meta and the one primary (Issue a draft, Share an issued cycle, Bring back an archived one);
14
+ * cozy-viewer.js czSummary draws it
12
15
  *
13
16
  * THE RULE (as the premium models): every number, date and chip comes from a field of a record. Where a record is silent the part says so or
14
17
  * is left out; nothing is filled with a guess. */
@@ -166,18 +169,40 @@ export function paperModel(W, o = {}) {
166
169
  });
167
170
  return { eye, title: (W && W.title) || o.name || 'Report', minute, pages, foot, n: pages.length };
168
171
  }
169
- /** The paper as html: one sheet per page. o = { state, issuedOn } */
170
- export function paperHtml(P, o = {}) {
171
- const st = o.state === 'issued' ? 'Issued' + (o.issuedOn ? ' ' + o.issuedOn : '') : o.state === 'archived' ? 'Archived' : 'Draft';
172
- return `<div class="rp-paperwell"><div class="rp-paperbar"><span data-rp-page aria-live="polite">Page 1 of ${P.n}</span><span class="rp-pill">${esc(st)}</span><span class="vz-sp"></span>`
173
- + `<button type="button" class="rp-linkbtn" data-r="dlm" aria-haspopup="menu">Download as PDF or Word</button></div>`
174
- + P.pages.map((pg, i) => `<article class="rp-pg" data-pg="${i + 1}" aria-label="Page ${i + 1} of ${P.n}">`
172
+ /** The paper as html: one sheet per page, then "Page n of N" said once under the sheets (Viewer shell A, XvAReportDoc). The summary card
173
+ * over it says the state, and Download is under ⋯, so there is no bar over the sheets. */
174
+ export function paperHtml(P) {
175
+ return `<div class="rp-paperwell">` + P.pages.map((pg, i) => `<article class="rp-pg" data-pg="${i + 1}" aria-label="Page ${i + 1} of ${P.n}">`
175
176
  + (i === 0 ? `<p class="rp-eye">${esc(P.eye)}</p><h1>${esc(P.title)}</h1>${P.minute ? `<div class="rp-minute"><p class="rp-mh">In one minute</p>${P.minute}</div>` : ''}` : '')
176
177
  + pg.map((b) => b.html).join('')
177
- + (i === P.n - 1 && P.foot ? `<div class="rp-fn">${P.foot}</div>` : '')
178
- + `<p class="rp-pno">${i + 1} / ${P.n}</p></article>`).join('') + '</div>';
178
+ + (i === P.n - 1 && P.foot ? `<div class="rp-fn">${P.foot}</div>` : '') + '</article>').join('')
179
+ + `</div><p class="rp-count" data-rp-page aria-live="polite">Page 1 of ${P.n}</p>`;
179
180
  }
180
181
 
182
+ /* ── the summary card (Viewer shell A: XvAReport, XvAReportDoc) ── */
183
+ /**
184
+ * The summary on top of a report: { line, tone, text, meta, primary: { r, label } }. Every part comes from the records the reader read;
185
+ * a part with no source is left out (zero is silence). o = {
186
+ * state 'draft'|'issued'|'archived' · slot 'YYYY-MM-DD' · purpose (the template's) · sub (the file's subtitle) · schedule (schedLabel, or '')
187
+ * dataFrom ('19 Oct', the headline figure's as-of) · shares ({ links, views } of the open links, or null when not read) · nextDraft ('YYYY-MM-DD')
188
+ * view 'deck'|'doc'|'live' · slides (count) · pages (count) · foot (true when the sources are footnotes) · path (for Bring back) }
189
+ * draft "Draft · Oct 21 cycle" in the warn tone, the purpose, "Every Mon 09:00 · data from 19 Oct", Issue
190
+ * issued "Issued 19 Oct", "Not shared yet." (or the open links) and the next cycle's day, the form it is read in, Share
191
+ * archived "Archived · issued 19 Oct", "It stays as sent.", Bring back
192
+ */
193
+ export function reportSummary(o = {}) {
194
+ const m = slotOf(o.slot), short = m ? MONS[+m[2] - 1] + ' ' + +m[3] : String(o.slot || ''), on = dayMon(o.slot);
195
+ const form = o.view === 'doc' && o.pages ? 'Document · ' + o.pages + (o.pages === 1 ? ' page' : ' pages') + (o.foot ? ' · sources as footnotes' : '')
196
+ : o.view === 'live' ? 'Live page' : o.slides ? o.slides + (o.slides === 1 ? ' slide' : ' slides') : '';
197
+ const data = o.dataFrom ? 'data from ' + o.dataFrom : '';
198
+ if (o.state === 'archived') return { line: 'Archived' + (on ? ' · issued ' + on : ''), tone: '', text: 'It stays as sent.', meta: [form].filter(Boolean).join(' · '), primary: { r: 'unarch|' + (o.path || ''), label: 'Bring back' } };
199
+ if (o.state === 'issued') {
200
+ const S = o.shares, shared = !S ? '' : S.links ? 'Shared: ' + S.links + (S.links === 1 ? ' link' : ' links') + ' open, ' + (S.views ? S.views + (S.views === 1 ? ' view.' : ' views.') : 'not opened yet.') : 'Not shared yet.';
201
+ const next = o.nextDraft && dayMon(o.nextDraft) ? 'The next cycle starts ' + dayMon(o.nextDraft) + '.' : '';
202
+ return { line: 'Issued' + (on ? ' ' + on : ''), tone: '', text: [shared, next].filter(Boolean).join(' '), meta: [form, data].filter(Boolean).join(' · '), primary: { r: 'share', label: 'Share' } };
203
+ }
204
+ return { line: 'Draft' + (short ? ' · ' + short + ' cycle' : ''), tone: 'warn', text: String(o.purpose || o.sub || '').trim(), meta: [o.schedule, data].filter(Boolean).join(' · '), primary: { r: 'issue', label: 'Issue' } };
205
+ }
181
206
  /* ── the live page (RpLive) ── */
182
207
  const DAY = 86400000;
183
208
  const ms = (d) => Date.parse(String(d).slice(0, 10) + 'T00:00:00Z');
@@ -0,0 +1,107 @@
1
+ /* pm/tk-draft.js — one task as its drafted Jira ticket, in the team's template (canvas PgTkDraft; kit 2, T2).
2
+ *
3
+ * openDraft({ VW, ws, initiative, id, view?, ui: { menu, ask }, toast?, onChange?(), onSend?(id) })
4
+ *
5
+ * A drill-in of the initiative's Tasks (back: true, so ← returns to them). Type, Priority, Estimate and Depends on are four fields; the
6
+ * User story and the Acceptance criteria are shown; Additional context, User flow, Functional requirements, Terminal states and Refs are
7
+ * folded rows with a count. Every field and section is editable in place (POST /api/jira/edit, a page press: it writes the draft file,
8
+ * never Jira). The one send icon opens the Send sheet with this ticket ticked (tk-send.js). A ticket in Jira and unchanged has no send
9
+ * icon: there is nothing to send. ⋯ holds Edit the title and Edit with Claude. The model is tk-model.js draftModel. */
10
+ import { pmGet, pmPost } from './http.js';
11
+ import { draftModel, SECTION_NAMES } from './tk-model.js';
12
+ import { ensureCss } from './tk-send.js';
13
+
14
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
15
+ 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>`;
16
+ const I = { send: 'M4 12l16-8-6 16-3-7z', edit: 'M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4', right: 'M10 7l5 5-5 5', down: 'M7 10l5 5 5-5' };
17
+ const viewUrl = (ws, id) => '/api/jira/tickets?initiative=' + encodeURIComponent(id) + (ws ? '&ws=' + encodeURIComponent(ws) : '');
18
+ /** A section's text as paragraphs and lists, every character escaped: the draft is the PM's text, never markup. */
19
+ function textHtml(s) {
20
+ const out = []; let list = null;
21
+ for (const raw of String(s || '').split('\n')) {
22
+ const l = raw.trim();
23
+ const m = /^([-*]|\d+[.)])\s+(.*)$/.exec(l);
24
+ if (m) { const tag = /\d/.test(m[1]) ? 'ol' : 'ul'; if (!list || list.tag !== tag) { list = { tag, items: [] }; out.push(list); } list.items.push(m[2]); continue; }
25
+ list = null;
26
+ if (l && !/^[—–-]$/.test(l)) out.push(l.replace(/^#{1,6}\s+/, ''));
27
+ }
28
+ return out.map((x) => (typeof x === 'string' ? `<p>${esc(x)}</p>` : `<${x.tag}>${x.items.map((i) => `<li>${esc(i)}</li>`).join('')}</${x.tag}>`)).join('');
29
+ }
30
+
31
+ export function draftHtml(D, st = {}) {
32
+ if (!D) return '<p class="tk-note">This ticket is not in the draft any more.</p>';
33
+ const field = (f) => `<button type="button" class="tk-f" data-tk-field="${esc(f.k)}" aria-haspopup="menu" aria-label="${esc(f.label)}: ${esc(f.value || f.none || '')}. Change"><span class="tk-fl">${esc(f.label)}</span><span class="tk-fv${f.value ? '' : ' mut'}">${esc(f.value || f.none || '')}</span></button>`;
34
+ const editor = (s) => `<div class="tk-ed"><label class="tk-vh" for="tkEd">${esc(s.name)}</label><textarea id="tkEd" rows="6" maxlength="20000">${esc(s.text)}</textarea><div class="tk-eda"><button type="button" class="tk-go sm" data-tk-save="${esc(s.key)}">Save</button><button type="button" class="tk-c sm" data-tk-noedit>Cancel</button></div></div>`;
35
+ const editBtn = (s) => `<button type="button" class="tk-ib" data-tk-edit="${esc(s.key)}" aria-label="Edit ${esc(s.name)}" title="Edit">${SVG(I.edit, 15)}</button>`;
36
+ const missing = (s) => (s.missing ? `<p class="tk-miss"><span class="tk-mk warn" aria-hidden="true"></span>Missing. A ticket needs it before it can be sent.</p>` : '');
37
+ const shown = D.shown.map((s) => {
38
+ const body = st.edit === s.key ? editor(s)
39
+ : s.entries && s.entries.length ? s.entries.map((e, i) => `<div class="tk-ac"><em>${i + 1}</em><span>${esc(e)}</span></div>`).join('') : s.text ? textHtml(s.text) : missing(s);
40
+ return `<section class="tk-card tk-sec2"><div class="tk-sh"><h3>${esc(s.name)}</h3>${st.edit === s.key ? '' : editBtn(s)}</div>${body}</section>`;
41
+ }).join('');
42
+ const folded = D.folded.map((s) => {
43
+ const open = st.open && st.open.has(s.key);
44
+ return `<div class="tk-coll${open ? ' on' : ''}"><button type="button" class="tk-cr" data-tk-fold="${esc(s.key)}" aria-expanded="${!!open}"><b>${esc(s.name)}</b><span class="tk-cn">${esc(s.count === 'empty' ? (s.missing ? 'missing' : '') : s.count)}</span>${SVG(open ? I.down : I.right, 15, 2)}</button>`
45
+ + (open ? `<div class="tk-cb2">${st.edit === s.key ? editor(s) : (s.text ? textHtml(s.text) : missing(s) || '<p class="tk-mut">Empty.</p>') + `<div class="tk-cba">${editBtn(s)}</div>`}</div>` : '') + '</div>';
46
+ }).join('');
47
+ const mark = D.mark ? `<p class="tk-flag ${esc(D.mark[0])}"><span class="tk-mk ${esc(D.mark[0])}" aria-hidden="true"></span>${esc(D.mark[1])}</p>` : '';
48
+ return `<div class="tk-v tk-draft">${D.group ? `<p class="tk-crumb">${esc(D.group)}</p>` : ''}${D.inJira ? `<p class="tk-crumb">${esc(D.key)} · in Jira</p>` : ''}${mark}`
49
+ + `<div class="tk-fields">${D.fields.map(field).join('')}</div>${shown}<div class="tk-card tk-folds">${folded}</div>`
50
+ + `<p class="tk-msg" role="status" id="tkMsg">${esc(st.msg || '')}</p>`
51
+ + (D.selectable ? `<button type="button" class="tk-fab" data-tk-send aria-label="Send to Jira" title="Send to Jira">${SVG(I.send, 20)}</button>` : '')
52
+ + '</div>';
53
+ }
54
+
55
+ export async function openDraft(o) {
56
+ ensureCss();
57
+ const st = { v: o.view || null, open: new Set(), edit: null, msg: '' };
58
+ const D = () => draftModel(st.v, o.id);
59
+ let body = null;
60
+ const read = async () => { const v = await pmGet(viewUrl(o.ws, o.initiative)); if (v && v.ok === true) st.v = v; return !!(v && v.ok); };
61
+ const draw = () => { if (body && body.isConnected) { const sc = body.scrollTop; body.innerHTML = draftHtml(D(), st); body.scrollTop = sc; } };
62
+ const save = async (patch, ok) => {
63
+ const r = await pmPost('/api/jira/edit', { ws: o.ws, initiative: o.initiative, id: o.id, patch });
64
+ if (!r || r.ok === false) { st.msg = (r && r.error) || 'Nothing was changed.'; draw(); return false; }
65
+ st.edit = null; st.msg = ''; await read(); draw();
66
+ if (o.toast && ok) o.toast(ok);
67
+ if (o.onChange) o.onChange();
68
+ return true;
69
+ };
70
+ if (!st.v) await read();
71
+ const d0 = D();
72
+ const more = [
73
+ { label: 'Edit the title', on: (b) => o.ui.ask(b, 'Title', (D() || d0 || {}).title || '', (v) => save({ summary: v }, 'Title changed.'), { max: 250 }) },
74
+ { label: 'Edit with Claude', on: () => {
75
+ const ta = document.getElementById('hmIn'); if (!ta) { if (o.toast) o.toast('The chat is not on this page.'); return; }
76
+ ta.value = `Edit the drafted Jira ticket ${o.id} of the initiative ${o.initiative} (pmos jira show ${o.initiative}). Change: `;
77
+ ta.dispatchEvent(new Event('input', { bubbles: true })); ta.focus(); ta.setSelectionRange(ta.value.length, ta.value.length);
78
+ } },
79
+ ];
80
+ body = o.VW.open({ id: 'tk:' + o.initiative + ':' + o.id, kind: 'Jira ticket · drafted', title: (d0 && d0.title) || o.id, icon: 'jira', back: true, more,
81
+ render: (b) => { body = b; b.innerHTML = draftHtml(D(), st); wire(b); } });
82
+ function wire(b) {
83
+ b.onclick = async (e) => {
84
+ const t = e.target.closest('button'); if (!t || t.disabled) return;
85
+ const d = t.dataset, M = D(); if (!M) return;
86
+ if (d.tkFold) { if (st.open.has(d.tkFold)) st.open.delete(d.tkFold); else st.open.add(d.tkFold); draw(); return; }
87
+ if (d.tkEdit) { st.edit = d.tkEdit; st.open.add(d.tkEdit); draw(); const ta = b.querySelector('#tkEd'); if (ta) ta.focus(); return; }
88
+ if ('tkNoedit' in d) { st.edit = null; draw(); return; }
89
+ if (d.tkSave) { const ta = b.querySelector('#tkEd'); await save({ sections: { [d.tkSave]: ta ? ta.value : '' } }, SECTION_NAMES[d.tkSave] + ' saved.'); return; }
90
+ if ('tkSend' in d) { if (o.onSend) o.onSend(o.id); return; }
91
+ if (d.tkField) {
92
+ const f = M.fields.find((x) => x.k === d.tkField); if (!f) return;
93
+ if (f.k === 'depends') {
94
+ if (!M.others.length) { st.msg = 'This is the only ticket, so it depends on nothing here.'; draw(); return; }
95
+ const on = new Set(f.ids);
96
+ o.ui.menu(t, [{ head: 'Depends on' }, ...M.others.map((x) => ({ label: x.title, sub: x.id, radio: true, on: on.has(x.id), go: () => { if (on.has(x.id)) on.delete(x.id); else on.add(x.id); save({ depends: [...on] }, 'Depends on changed.'); } })),
97
+ ...(on.size ? [{ hr: true }, { label: 'Depends on nothing', go: () => save({ depends: [] }, 'Depends on changed.') }] : [])], 'Depends on');
98
+ return;
99
+ }
100
+ o.ui.menu(t, [{ head: f.label }, ...f.options.map((v) => ({ label: v, radio: true, on: f.value === v, go: () => save({ [f.k]: v }, f.label + ' changed.') })),
101
+ ...(f.k === 'estimate' ? [{ label: 'Not set', radio: true, on: !f.value, go: () => save({ estimate: null }, 'Estimate cleared.') }] : [])], f.label);
102
+ }
103
+ };
104
+ b.onkeydown = (e) => { if (e.key === 'Escape' && st.edit) { e.stopPropagation(); st.edit = null; draw(); } };
105
+ }
106
+ return body;
107
+ }
@@ -0,0 +1,134 @@
1
+ /* pm/tk-model.js — the pure half of the initiative's PRD-to-Jira tasks (canvas PgTkList, PgTkDraft, PgTkSend, PgTkSent; kit 2, T1 to T3).
2
+ * No DOM, no request: it turns the answer of GET /api/jira/tickets (lib/jira-tickets.js view) into what the Tasks view, the drafted
3
+ * ticket and the Send sheet draw, so a node test loads it with import().
4
+ *
5
+ * ticketGroups(v) T1: the tasks grouped by the Jira epic they go into, with the send icon's count
6
+ * readLine(iso, now) T1: "Jira read at 9:02", said once under the groups
7
+ * draftModel(v, id) T2: the four fields, the two sections shown and the folded ones with their counts
8
+ * sendModel(v, { group, ticket, projects }) T3: the project, each epic with its Change, the tickets with their ticks, Send N
9
+ *
10
+ * Every task is a PRD story whose Jira ticket PMOS drafted. PMOS owns the text and Jira owns the status (D88): after the send a task shows
11
+ * its key, a status square for its Jira status category and its assignee when the Jira read holds one, never a guess.
12
+ * Several epics: a ticket names its epic group (v.groups); a ticket with no group goes under the initiative's one epic (v.epic). */
13
+
14
+ const str = (s) => (typeof s === 'string' ? s.trim() : '');
15
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
16
+ const initials = (name) => { const w = str(name).split(/\s+/).filter(Boolean); return !w.length ? '' : w.length > 1 ? (w[0][0] + w[1][0]).toUpperCase() : w[0].slice(0, 2).replace(/^./, (c) => c.toUpperCase()); };
17
+ export const projectOf = (key) => (/^[A-Z][A-Z0-9_]*-\d+$/.test(str(key)) ? str(key).replace(/-\d+$/, '') : null);
18
+
19
+ /** One marker per task, the most urgent first (the view decides the flag): [tone, words]. Zero is silence: no flag, no marker. */
20
+ export function markOf(t) {
21
+ if (!t || !t.flag) return null;
22
+ if (t.flag === 'incomplete') return ['warn', 'Missing ' + (t.missing || []).join(', ')];
23
+ if (t.flag === 'prd-changed') return ['warn', 'The PRD changed this story'];
24
+ if (t.flag === 'removed') return ['warn', 'No longer in the PRD'];
25
+ if (t.flag === 'blocked') return ['warn', 'Blocked in Jira' + (t.jira && t.jira.reason ? ': ' + t.jira.reason : '')];
26
+ if (t.flag === 'pushing') return ['info', 'Sending to Jira'];
27
+ if (t.flag === 'edited') return ['info', 'Edited, not in Jira yet'];
28
+ return null;
29
+ }
30
+ const CAT = { todo: 'To do', doing: 'In progress', done: 'Done' };
31
+ function rowOf(t) {
32
+ const j = t.jira || null;
33
+ const cat = t.inJira ? (j && CAT[j.category] ? j.category : 'todo') : null;
34
+ const who = j && str(j.assignee) ? str(j.assignee) : '';
35
+ return {
36
+ id: t.id, title: str(t.summary) || t.id, inJira: !!t.inJira, key: t.key || null, cat, status: t.inJira ? (j && str(j.status)) || CAT[cat] : '',
37
+ who, av: initials(who), sub: t.inJira ? t.key : [t.type, t.estimate].filter(Boolean).join(' · '), mark: markOf(t), selectable: !!t.selectable,
38
+ };
39
+ }
40
+
41
+ /** T1. The groups: each epic group in the order the PRD gives them, then the tickets in no group. A group's `send` counts the tasks the
42
+ * Send sheet can tick; the header shows its send icon only when it is more than zero. */
43
+ export function ticketGroups(v) {
44
+ if (!v || v.ok !== true || !v.drafted) return [];
45
+ const groups = Array.isArray(v.groups) ? v.groups : [];
46
+ const by = new Map(groups.map((g) => [g.id, { id: g.id, name: g.name, key: g.key || null, locked: !!g.locked, rows: [] }]));
47
+ const ep = v.epic || {};
48
+ const loose = { id: '', name: groups.length ? 'Other tickets' : 'Tickets', key: ep.key || null, locked: !!ep.locked, rows: [], loose: true };
49
+ for (const t of v.tickets || []) (by.get(t.epic) || loose).rows.push(rowOf(t));
50
+ return [...by.values(), loose].filter((g) => g.rows.length).map((g) => ({ ...g, n: g.rows.length, send: g.rows.filter((r) => r.selectable).length, inJira: g.rows.filter((r) => r.inJira).length }));
51
+ }
52
+
53
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
54
+ /** "Jira read at 9:02" today, "Jira read 23 Oct, 9:02" before; '' when Jira was never read. */
55
+ export function readLine(iso, now = Date.now()) {
56
+ const t = Date.parse(iso || '');
57
+ if (!Number.isFinite(t)) return '';
58
+ const d = new Date(t), n = new Date(now);
59
+ const hm = d.getHours() + ':' + String(d.getMinutes()).padStart(2, '0');
60
+ return d.toDateString() === n.toDateString() ? 'Jira read at ' + hm : 'Jira read ' + d.getDate() + ' ' + MON[d.getMonth()] + ', ' + hm;
61
+ }
62
+
63
+ /* ── T2 · one drafted ticket ── */
64
+ const lines = (s) => String(s || '').split('\n').map((l) => l.trim()).filter((l) => l && !/^[—–-]$/.test(l));
65
+ const listItems = (s) => lines(s).filter((l) => /^([-*]|\d+[.)])\s+/.test(l));
66
+ /** The entries of a list section, without their bullets; a section with no list reads as its lines. */
67
+ export const entriesOf = (s) => { const L = listItems(s); return (L.length ? L : lines(s)).map((l) => l.replace(/^([-*]|\d+[.)])\s+/, '')); };
68
+ function countOf(key, text) {
69
+ const L = listItems(text);
70
+ if (!lines(text).length) return 'empty';
71
+ if (key === 'refs') return /PRD/.test(text) && L.length <= 1 ? 'PRD' : String(L.length || lines(text).length);
72
+ if (key === 'flow') return plural(L.length || lines(text).length, 'step', 'steps');
73
+ if (L.length) return String(L.length);
74
+ return plural(lines(text).length, 'line', 'lines');
75
+ }
76
+ const SHOWN = ['story', 'acceptance'];
77
+ const FOLDED = ['context', 'flow', 'functional', 'terminal', 'refs'];
78
+ const NAMES = { story: 'User story', context: 'Additional context', flow: 'User flow', functional: 'Functional requirements', terminal: 'Terminal states', acceptance: 'Acceptance criteria', refs: 'Refs' };
79
+ export const SECTION_NAMES = NAMES;
80
+ /** The drafted ticket: { id, title, group, fields, shown, folded, missing, inJira, key, selectable, mark } or null. */
81
+ export function draftModel(v, id) {
82
+ const t = v && v.ok === true ? (v.tickets || []).find((x) => x.id === id) : null;
83
+ if (!t) return null;
84
+ const all = new Map((v.tickets || []).map((x) => [x.id, str(x.summary) || x.id]));
85
+ const g = (v.groups || []).find((x) => x.id === t.epic);
86
+ const miss = new Set((t.missing || []).map((m) => m.toLowerCase()));
87
+ const sec = (k) => ({ key: k, name: NAMES[k], text: (t.sections || {})[k] || '', missing: miss.has(String({ story: 'User Story', functional: 'Functional Requirements', acceptance: 'Acceptance Criteria' }[k] || '').toLowerCase()) });
88
+ return {
89
+ id: t.id, title: str(t.summary) || t.id, group: g ? g.name : (v.groups || []).length ? 'Other tickets' : '', inJira: !!t.inJira, key: t.key || null, selectable: !!t.selectable, mark: markOf(t),
90
+ fields: [
91
+ { k: 'type', label: 'Type', value: t.type || 'Task', options: v.types || ['Task', 'Story', 'Bug'] },
92
+ { k: 'priority', label: 'Priority', value: t.priority || 'Medium', options: v.priorities || ['Highest', 'High', 'Medium', 'Low'] },
93
+ { k: 'estimate', label: 'Estimate', value: t.estimate || '', options: v.estimates || ['XS', 'S', 'M', 'L', 'XL'], none: 'Not set' },
94
+ { k: 'depends', label: 'Depends on', value: (t.depends || []).map((d) => all.get(d) || d).join(', '), ids: t.depends || [], none: 'Nothing' },
95
+ ],
96
+ shown: SHOWN.map((k) => ({ ...sec(k), entries: k === 'acceptance' ? entriesOf(sec(k).text) : null })),
97
+ folded: FOLDED.map((k) => ({ ...sec(k), count: countOf(k, sec(k).text) })),
98
+ others: (v.tickets || []).filter((x) => x.id !== t.id).map((x) => ({ id: x.id, title: str(x.summary) || x.id })),
99
+ };
100
+ }
101
+
102
+ /* ── T3 · confirm and send ── */
103
+ /**
104
+ * The Send sheet. Opened from a group's send icon (group: its id, '' for the tickets in no group), from a ticket's send icon (ticket: its
105
+ * id) or from the Commit row (neither: every group). It lists the tickets that can go to Jira now, ticked; a ticket that lacks text is
106
+ * listed, not ticked and not tickable, with what it lacks. A ticket in Jira and unchanged is not listed: there is nothing to send.
107
+ * projects: the board's Jira projects (lib/routes-boards.js jiraProjects), for when no epic key names the project.
108
+ * → { project, sections: [{ id, name, epic: { label, key, mode, locked }, items: [{ id, title, on, can, why, update }] }], n, empty }
109
+ */
110
+ export function sendModel(v, { group = null, ticket = null, projects = [] } = {}) {
111
+ const G = ticketGroups(v);
112
+ const one = ticket ? (v.tickets || []).find((t) => t.id === ticket) : null;
113
+ const scopeId = one ? (one.epic && G.some((g) => g.id === one.epic) ? one.epic : '') : group;
114
+ const pick = scopeId == null ? G : G.filter((g) => g.id === scopeId);
115
+ const byId = new Map((v && v.tickets ? v.tickets : []).map((t) => [t.id, t]));
116
+ const ep = (v && v.epic) || {};
117
+ const sections = pick.map((g) => {
118
+ const items = g.rows.filter((r) => !r.inJira || r.selectable).map((r) => {
119
+ const t = byId.get(r.id) || {};
120
+ const why = (t.missing || []).length ? 'Missing ' + t.missing.join(', ') : t.removed ? 'No longer in the PRD' : '';
121
+ return { id: r.id, title: r.title, can: r.selectable, on: r.selectable && (!one || r.id === one.id), why, update: r.inJira };
122
+ });
123
+ const name = g.loose ? str(ep.summary) || str(v.title) || 'this initiative' : g.name;
124
+ const label = g.key ? g.key : 'New: ' + name;
125
+ return { id: g.id, name: g.loose && !(v.groups || []).length ? '' : g.name, epic: { label, key: g.key, mode: g.key ? 'existing' : 'new', locked: g.locked, group: g.loose ? null : g.id }, items };
126
+ }).filter((s) => s.items.length);
127
+ const keys = sections.map((s) => s.epic.key).filter(Boolean);
128
+ const list = (Array.isArray(projects) ? projects : []).map(str).filter(Boolean);
129
+ const project = projectOf(keys[0]) || (list.length ? list[0] : '');
130
+ const n = sections.reduce((a, s) => a + s.items.filter((i) => i.on).length, 0);
131
+ return { project, projectFrom: projectOf(keys[0]) ? 'epic' : project ? 'board' : 'ask', sections, n, empty: !sections.length };
132
+ }
133
+ /** The label of the final press: it is the one labeled button, since a send cannot be undone. */
134
+ export const sendLabel = (n) => (n ? 'Send ' + n : 'Send');
@@ -0,0 +1,124 @@
1
+ /* pm/tk-send.js — the Send to Jira sheet (canvas PgTkSend; kit 2, T3). The one path to Jira: a group's send icon, a drafted ticket's send
2
+ * icon (tk-draft.js) and the Board's "Your Commit · push N tickets" row all open this sheet, and nothing reaches Jira before its Send.
3
+ *
4
+ * openSend({ ws, initiative, group?, ticket?, projects?, board?, toast?, onDone? })
5
+ * group an epic group's id ('' for the tickets in no group); ticket: one ticket's id; neither: every ticket that can go now
6
+ * projects the board's Jira projects, for when no epic key names the project; with none, board: the board to read them from
7
+ *
8
+ * The sheet names the project and the epic of each group (New: <group name>, or the existing epic chosen with Change), lists the tickets
9
+ * with a tick each and ends with the one labeled press, "Send N". Send is a PM-only press (pm-guard act `push`): POST /api/jira/push
10
+ * records the selection and starts the Push to Jira session, which creates the epics and tickets with the PM's own Atlassian connection
11
+ * and records their keys (D53, D88). Change writes the epic choice (POST /api/jira/epic, a page press). The model is tk-model.js. */
12
+ import { pmGet, pmPost } from './http.js';
13
+ import { sendModel, sendLabel } from './tk-model.js';
14
+
15
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
16
+ const SVG = (d, w = 14, sw = 2) => `<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>`;
17
+ const TICK = 'M5 12l4 4 10-10', RIGHT = 'M10 7l5 5-5 5';
18
+ const isPhone = () => typeof innerWidth === 'number' && innerWidth <= 760;
19
+ export function ensureCss() {
20
+ if (typeof document === 'undefined' || document.querySelector('link[data-tk-css]')) return;
21
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = '/pm/tk-tasks.css'; l.dataset.tkCss = ''; document.head.appendChild(l);
22
+ }
23
+ const viewUrl = (ws, id) => '/api/jira/tickets?initiative=' + encodeURIComponent(id) + (ws ? '&ws=' + encodeURIComponent(ws) : '');
24
+
25
+ let OPEN = null;
26
+ export function closeSend() {
27
+ if (!OPEN) return;
28
+ const { el, scrim, back } = OPEN; OPEN = null;
29
+ el.remove(); scrim.remove();
30
+ if (back && back.isConnected) { try { back.focus(); } catch { /* gone */ } }
31
+ }
32
+
33
+ function sheetHtml(M, st) {
34
+ const where = `<div class="tk-wr"><span class="tk-wl">Project</span>${st.projects.length > 1 && M.projectFrom !== 'epic'
35
+ ? `<select class="tk-sel" data-tk-project aria-label="Jira project">${st.projects.map((p) => `<option${p === st.project ? ' selected' : ''}>${esc(p)}</option>`).join('')}</select>`
36
+ : M.project ? `<span class="tk-wv">${esc(M.project)}</span>` : '<span class="tk-wv mut">Claude asks you before it creates anything</span>'}</div>`;
37
+ const sec = M.sections.map((s) => {
38
+ const ch = st.change === s.id;
39
+ const epic = `<div class="tk-wr"><span class="tk-wl">Epic</span><span class="tk-wv">${esc(s.epic.label)}</span>`
40
+ + (s.epic.locked ? '' : `<button type="button" class="tk-chg" data-tk-change="${esc(s.id)}" aria-expanded="${ch}" aria-label="Change the epic${s.name ? ' of ' + esc(s.name) : ''}">Change${SVG(RIGHT)}</button>`) + '</div>'
41
+ + (ch ? `<div class="tk-chgbox"><button type="button" class="tk-opt${s.epic.mode === 'new' ? ' on' : ''}" data-tk-new="${esc(s.id)}">Create a new epic<em>${esc(s.epic.mode === 'new' ? s.epic.label.replace(/^New: /, '') : s.name || 'named after the initiative')}</em></button>`
42
+ + `<label class="tk-fld"><span>Or use an existing epic</span><span class="tk-row2"><input data-tk-key="${esc(s.id)}" maxlength="200" autocomplete="off" placeholder="Paste its Jira link or key" value="${esc(s.epic.key || '')}"><button type="button" class="tk-use" data-tk-use="${esc(s.id)}">Use</button></span></label></div>` : '');
43
+ const items = s.items.map((i) => {
44
+ const on = st.on.has(i.id);
45
+ return `<button type="button" class="tk-it" role="checkbox" aria-checked="${on}" data-tk-tick="${esc(i.id)}"${i.can ? '' : ' aria-disabled="true"'}>`
46
+ + `<span class="tk-cb${on ? '' : ' off'}" aria-hidden="true">${on ? SVG(TICK, 12, 3) : ''}</span><span class="tk-itx"><b>${esc(i.title)}</b>${i.why ? `<span class="tk-why">${esc(i.why)}</span>` : i.update ? '<span class="tk-why">Updates its Jira ticket</span>' : ''}</span></button>`;
47
+ }).join('');
48
+ // one epic: the project and the epic share one card (PgTkSend); several: the project once, then each epic with its tickets
49
+ const one = M.sections.length === 1;
50
+ return `<section class="tk-sec" aria-label="${esc(s.name || 'Tickets')}">${!one && s.name ? `<p class="tk-sn">${esc(s.name)}</p>` : ''}<div class="tk-where">${one ? where : ''}${epic}</div><div class="tk-items">${items}</div></section>`;
51
+ }).join('');
52
+ const n = st.on.size;
53
+ return '<div class="tk-grab" aria-hidden="true"></div><h2 class="tk-h">Send to Jira</h2>'
54
+ + (M.empty ? '<p class="tk-note">Every ticket here is in Jira and unchanged. There is nothing to send.</p>'
55
+ : `${M.sections.length === 1 ? '' : `<div class="tk-where">${where}</div>`}${sec}`)
56
+ + `<p class="tk-msg" role="status">${esc(st.msg || '')}</p>`
57
+ + `<div class="tk-acts"><button type="button" class="tk-c" data-tk-cancel>Cancel</button><button type="button" class="tk-go" data-tk-go${n && !st.busy ? '' : ' disabled'}>${esc(sendLabel(n))}</button></div>`;
58
+ }
59
+
60
+ /** Open the sheet. Resolves when it is drawn; onDone() runs after a send started. */
61
+ export async function openSend(o = {}) {
62
+ if (typeof document === 'undefined') return null;
63
+ ensureCss(); closeSend();
64
+ const back = document.activeElement;
65
+ const scrim = document.createElement('div'); scrim.className = 'tk-scrim';
66
+ const el = document.createElement('div');
67
+ el.className = 'cz tk-sheet' + (isPhone() ? ' phone' : '');
68
+ el.setAttribute('role', 'dialog'); el.setAttribute('aria-modal', 'true'); el.setAttribute('aria-label', 'Send to Jira'); el.setAttribute('data-esc-layer', '');
69
+ el.innerHTML = '<p class="tk-note" role="status">Reading the tickets.</p>';
70
+ document.body.append(scrim, el);
71
+ OPEN = { el, scrim, back };
72
+ scrim.onclick = closeSend;
73
+ const st = { v: null, on: new Set(), change: null, msg: '', busy: false, projects: (o.projects || []).filter(Boolean), project: '' };
74
+ const model = () => sendModel(st.v, { group: o.group == null ? null : o.group, ticket: o.ticket || null, projects: st.projects });
75
+ const draw = () => { if (!OPEN || OPEN.el !== el) return; const M = model(); el.innerHTML = sheetHtml(M, st); };
76
+ const read = async (keepTicks) => {
77
+ const v = await pmGet(viewUrl(o.ws, o.initiative));
78
+ if (!v || v.ok !== true) { el.innerHTML = `<p class="tk-note">${esc((v && v.error) || 'The tickets could not be read.')}</p><div class="tk-acts"><button type="button" class="tk-c" data-tk-cancel>Close</button></div>`; return false; }
79
+ st.v = v;
80
+ const M = model();
81
+ const can = new Set(M.sections.flatMap((s) => s.items.filter((i) => i.can).map((i) => i.id)));
82
+ if (!keepTicks) st.on = new Set(M.sections.flatMap((s) => s.items.filter((i) => i.on).map((i) => i.id)));
83
+ else st.on = new Set([...st.on].filter((id) => can.has(id)));
84
+ if (!st.project) st.project = M.project;
85
+ draw();
86
+ return true;
87
+ };
88
+ const setEpic = async (gid, body) => {
89
+ const r = await pmPost('/api/jira/epic', { ws: o.ws, initiative: o.initiative, ...(gid ? { group: gid } : {}), ...body });
90
+ if (!r || r.ok === false) { st.msg = (r && r.error) || 'The epic was not changed.'; draw(); return; }
91
+ st.change = null; st.msg = ''; await read(true);
92
+ };
93
+ el.addEventListener('change', (e) => { if (e.target.matches('[data-tk-project]')) st.project = e.target.value; });
94
+ el.addEventListener('keydown', (e) => {
95
+ if (e.key === 'Escape') { e.stopPropagation(); e.preventDefault(); closeSend(); return; }
96
+ if (e.key === 'Enter' && e.target.matches('[data-tk-key]')) { e.preventDefault(); const b = el.querySelector(`[data-tk-use="${CSS.escape(e.target.dataset.tkKey)}"]`); if (b) b.click(); }
97
+ });
98
+ el.addEventListener('click', async (e) => {
99
+ const b = e.target.closest('button'); if (!b || b.disabled) return;
100
+ const d = b.dataset;
101
+ if ('tkCancel' in d) { closeSend(); return; }
102
+ if (d.tkTick) { if (b.getAttribute('aria-disabled') === 'true') return; if (st.on.has(d.tkTick)) st.on.delete(d.tkTick); else st.on.add(d.tkTick); draw(); const n = el.querySelector(`[data-tk-tick="${CSS.escape(d.tkTick)}"]`); if (n) n.focus(); return; }
103
+ if (d.tkChange != null) { st.change = st.change === d.tkChange ? null : d.tkChange; draw(); const n = el.querySelector('[data-tk-key]'); if (n) n.focus(); return; }
104
+ if (d.tkNew != null) { await setEpic(d.tkNew, { mode: 'new' }); return; }
105
+ if (d.tkUse != null) { const inp = el.querySelector(`[data-tk-key="${CSS.escape(d.tkUse)}"]`); const key = inp ? inp.value.trim() : ''; if (!key) { st.msg = 'Paste the epic\'s Jira link or key, such as IDPF-400.'; draw(); return; } await setEpic(d.tkUse, { mode: 'existing', key }); return; }
106
+ if ('tkGo' in d) {
107
+ const ids = [...st.on]; if (!ids.length) return;
108
+ st.busy = true; st.msg = ''; draw();
109
+ const r = await pmPost('/api/jira/push', { ws: o.ws, initiative: o.initiative, ids, ...(st.project && model().projectFrom !== 'epic' ? { project: st.project } : {}) });
110
+ st.busy = false;
111
+ if (!r || r.ok === false) { st.msg = (r && r.error) || 'Nothing was sent.'; draw(); return; }
112
+ closeSend();
113
+ if (o.toast) o.toast(`Sending ${ids.length === 1 ? 'the ticket' : ids.length + ' tickets'} to Jira. Claude creates ${ids.length === 1 ? 'it' : 'them'} with your Atlassian connection, then reads ${ids.length === 1 ? 'it' : 'them'} back.`);
114
+ if (o.onDone) o.onDone(r);
115
+ }
116
+ });
117
+ if (!st.projects.length && o.board) { // the board's Jira projects, for when no epic key names the project
118
+ const b = await pmGet('/api/boards/items?board=' + encodeURIComponent(o.board) + (o.ws ? '&ws=' + encodeURIComponent(o.ws) : ''));
119
+ if (b && b.ok && Array.isArray(b.jiraProjects)) st.projects = b.jiraProjects.filter(Boolean);
120
+ }
121
+ const ok = await read(false);
122
+ if (ok) { const f = el.querySelector('[data-tk-go]:not([disabled])') || el.querySelector('[data-tk-cancel]'); if (f) f.focus(); }
123
+ return el;
124
+ }