create-pmos 0.264.0 → 0.266.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.
@@ -0,0 +1,281 @@
1
+ /* pm/premium-acts.js — the board presses of the premium Board and initiative pages (initiative premium-board-actions).
2
+ *
3
+ * Every press is a route the console already uses, behind the launch nonce:
4
+ * triage POST /api/boards/asks/accept { board, ask, title, lane, anchor } · /asks/decline { board, ask, why }
5
+ * new POST /api/boards/asks/add { board, line, source } then /asks/accept, as the console's New initiative does
6
+ * move POST /api/boards/move { board, id, to }; its warnings never block
7
+ * hold, cancel POST /api/lifecycle { initiative_id, state: on-hold | cancelled | active, reason, back? }
8
+ * archive POST /api/boards/archive { board, id, archived, reason? }
9
+ * Each result has Undo, which writes the opposite line through the same route. The anchors of a new initiative are read from
10
+ * GET /api/boards/anchors. Nothing here reads or writes anything else.
11
+ *
12
+ * C, the page's context: { ws, board, boardName, self, first, reload }. A row: { id, title, acts } with acts from lib/board-premium.js actsOf
13
+ * (or lib/initiative-premium.js): { stages, stage, life: hold | cancelled | null, reason, back, backDay, archived: { reason, into } | null }. */
14
+ import { pmPost, pmGet } from './http.js';
15
+ import { $, $$, esc, openDlg, closeDlg, toast, turnA, ptx } from './premium-shell.js';
16
+
17
+ const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
18
+ const CHK = '<path d="M5 12.5l4.5 4.5L19 7.5"/>';
19
+ const SHD = '<path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z"/>';
20
+ const DOTS = '<circle cx="5" cy="12" r="1.4"/><circle cx="12" cy="12" r="1.4"/><circle cx="19" cy="12" r="1.4"/>';
21
+ export const LANES = [['feature', 'Feature', 'PRD and rubric'], ['discovery', 'Discovery', 'Spike brief'], ['chore', 'Chore', 'One-paragraph intent'], ['incident', 'Incident', 'Post-hoc record'], ['content', 'Content', 'Content brief'], ['prototype', 'Prototype', 'Quick brief, grilled as dialogue']];
22
+ const BACK = [['two', 'In 2 weeks', 14], ['month', 'In a month', 30], ['quarter', 'Next quarter', 80], ['none', 'No date', null]];
23
+ const WHY = [['needed', 'No longer needed'], ['replaced', 'Replaced by another initiative'], ['worth', 'Not worth it now'], ['kill', 'Hit a kill condition'], ['other', 'Other']];
24
+ const AWHY = [['unrelated', 'Not related to this board'], ['stale', 'Old idea, never started'], ['dup', 'Duplicate'], ['other', 'Other']];
25
+ const errOf = (r, d) => (r && r.error) || d;
26
+ const dayIso = (n) => { const t = new Date(Date.now() + n * 86400000); return t.getFullYear() + '-' + String(t.getMonth() + 1).padStart(2, '0') + '-' + String(t.getDate()).padStart(2, '0'); };
27
+
28
+ /* ── the writes ── */
29
+ const post = (C, path, body) => pmPost(path, { ws: C.ws, ...body });
30
+ const life = (C, id, state, reason, back) => post(C, '/api/lifecycle', { initiative_id: id, state, reason: reason || '', ...(back ? { back } : {}) });
31
+ const arch = (C, id, archived, reason) => post(C, '/api/boards/archive', { board: C.board, id, archived, ...(reason ? { reason } : {}) });
32
+ const move = (C, id, to) => post(C, '/api/boards/move', { board: C.board, id, to });
33
+
34
+ /* ── the result line with Undo, in the page's own toast ── */
35
+ let undoT = null;
36
+ export function undoToast(msg, undo) {
37
+ const t = $('#toast'); clearTimeout(undoT);
38
+ t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="undo" id="paUndo">Undo</button>' : ''}`;
39
+ t.classList.add('on');
40
+ if (undo) $('#paUndo').onclick = async () => { const b = $('#paUndo'); b.disabled = true; await undo(); };
41
+ undoT = setTimeout(() => t.classList.remove('on'), undo ? 9000 : 4200);
42
+ }
43
+ async function done(C, r, msg, undo) {
44
+ if (!r || r.ok !== true) { toast(errOf(r, 'Nothing was recorded. The server did not say why.')); return false; }
45
+ undoToast(msg, undo); await C.reload(); return true;
46
+ }
47
+ const prevOf = (r) => ({ life: r.acts.life, reason: r.acts.reason, backDay: r.acts.backDay || null, archived: !!r.acts.archived });
48
+ /** Write the state `p` the row had before a lifecycle press, through the lifecycle route. */
49
+ const lifeBack = (C, r, p) => (p.life === 'hold' ? life(C, r.id, 'on-hold', p.reason, p.backDay) : p.life === 'cancelled' ? life(C, r.id, 'cancelled', p.reason) : life(C, r.id, 'active', 'undo'));
50
+
51
+ /* ── what a row can do ── */
52
+ export function items(C, r) {
53
+ const a = r.acts, cur = a.stages.indexOf(a.stage), out = [];
54
+ if (a.archived) return [['restore', 'Restore', 'Back in the lists, as it was']];
55
+ if (a.life === 'cancelled') return [['reopen', 'Reopen', 'Back to ' + (a.stage || 'its stage') + ', active again']];
56
+ if (!C.self && !a.life && cur >= 0) {
57
+ if (a.stages[cur + 1]) out.push(['mv:' + (cur + 1), 'Move to ' + a.stages[cur + 1], 'The next stage of its workflow']);
58
+ if (cur > 0) out.push(['mv:' + (cur - 1), 'Back to ' + a.stages[cur - 1], 'The stage before']);
59
+ }
60
+ if (a.life === 'hold') out.push(['resume', 'Resume', 'Back to ' + (a.stage || 'its stage') + ', active again']);
61
+ else out.push(['hold', 'Put on hold', 'Pause it; keeps its stage and work']);
62
+ out.push(['cancel', 'Cancel', 'Stop it for good, with a reason'], ['archive', 'Archive', 'Out of every list; restore any time']);
63
+ return out;
64
+ }
65
+
66
+ export async function run(C, r, k) {
67
+ const a = r.acts, p = prevOf(r);
68
+ if (k.startsWith('mv:')) {
69
+ const to = a.stages[+k.slice(3)], from = a.stage; if (!to) return;
70
+ const res = await move(C, r.id, to);
71
+ const w = res && res.ok && Array.isArray(res.warnings) && res.warnings.length ? ' Warning: ' + res.warnings.join('; ') + '. Warnings never block.' : '';
72
+ await done(C, res, 'Moved to ' + to + '. Recorded as a move line in the board ledger.' + w, async () => done(C, await move(C, r.id, from), 'Back in ' + from + '. Recorded as a move line.'));
73
+ return;
74
+ }
75
+ if (k === 'hold') return openHold(C, r);
76
+ if (k === 'cancel') return openCancel(C, r);
77
+ if (k === 'archive') return openArchive(C, r);
78
+ if (k === 'resume' || k === 'reopen') {
79
+ await done(C, await life(C, r.id, 'active', k === 'resume' ? 'resumed' : 'reopened'), r.title + ' is active again, in ' + (a.stage || 'its stage') + '. Recorded as a lifecycle line.', async () => done(C, await lifeBack(C, r, p), 'Undone. Recorded as a lifecycle line.'));
80
+ return;
81
+ }
82
+ if (k === 'restore') await done(C, await arch(C, r.id, false), r.title + ' is restored. Recorded in the board ledger.', async () => done(C, await arch(C, r.id, true, a.archived.reason), r.title + ' is archived again.'));
83
+ }
84
+
85
+ /* ── the row's menu ── */
86
+ let menu = null;
87
+ export const dotsBtn = (r) => `<button type="button" class="inim" data-im="${esc(r.key)}" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for ${esc(r.title)}">${ICO(DOTS)}</button>`;
88
+ /** The key of the row whose menu is open, so a page that redraws can open it again on the new button. */
89
+ export const menuKey = () => (menu ? menu.btn.dataset.im : null);
90
+ export function closeMenu(back) {
91
+ if (!menu) return; const { m, btn } = menu; m.remove(); btn.setAttribute('aria-expanded', 'false'); menu = null; if (back) btn.focus();
92
+ }
93
+ export function openMenu(btn, C, r) {
94
+ if (menu && menu.btn === btn) { closeMenu(true); return; }
95
+ closeMenu();
96
+ const m = document.createElement('div'); m.className = 'dsmn bam2'; m.setAttribute('role', 'menu'); m.setAttribute('aria-label', 'Actions for ' + r.title);
97
+ m.innerHTML = items(C, r).map(([k, l, s]) => `<button type="button" role="menuitem" data-pk="${esc(k)}"><span><b>${esc(l)}</b><small>${esc(s)}</small></span></button>`).join('');
98
+ btn.parentElement.appendChild(m); btn.setAttribute('aria-expanded', 'true'); menu = { m, btn, C, r };
99
+ // a card clips what leaves it: near the card's foot the menu opens upward
100
+ const card = btn.closest('.card'); if (card && m.getBoundingClientRect().bottom > card.getBoundingClientRect().bottom - 8) m.classList.add('up');
101
+ const f = $('button', m); if (f) f.focus();
102
+ }
103
+ document.addEventListener('keydown', (e) => {
104
+ if (!menu) return;
105
+ if (e.key === 'Escape') { e.stopPropagation(); e.preventDefault(); closeMenu(true); return; }
106
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); const L = $$('button', menu.m), k = L.indexOf(document.activeElement); L[(k + (e.key === 'ArrowDown' ? 1 : L.length - 1)) % L.length].focus(); }
107
+ if (e.key === 'Tab') closeMenu();
108
+ }, true);
109
+ document.addEventListener('click', (e) => {
110
+ if (!menu) return;
111
+ const it = e.target.closest('.bam2 [data-pk]');
112
+ if (it) { const { C, r } = menu; closeMenu(); run(C, r, it.dataset.pk); return; }
113
+ if (!e.target.closest('.bam2') && !e.target.closest('[data-im]')) closeMenu();
114
+ });
115
+
116
+ /* ── the initiative page's bar ── */
117
+ export function barHtml(C, r) {
118
+ const a = r.acts, cur = a.stages.indexOf(a.stage), nx = a.stages[cur + 1], pv = cur > 0 ? a.stages[cur - 1] : null;
119
+ if (a.archived) return `<div class="lifeb"><div><b>Archived</b><span>${esc(a.archived.into ? 'Merged into ' + a.archived.into : a.archived.reason || 'No reason was given')}. It is out of every list and count of the board. Nothing is deleted.</span></div><button type="button" class="dmcta alt" data-pk="restore">Restore</button></div>`;
120
+ if (a.life === 'cancelled') return `<div class="lifeb"><div><b>Cancelled</b><span>${a.reason ? esc(a.reason) + '. ' : ''}It keeps its stage, work and history.</span></div><button type="button" class="dmcta alt" data-pk="reopen">Reopen</button></div>`;
121
+ if (a.life === 'hold') return `<div class="lifeb"><div><b>On hold${a.back ? ' · check back ' + esc(a.back) : ''}</b><span>${a.reason ? esc(a.reason) + '. ' : ''}It keeps ${esc(a.stage || 'its stage')}, its work and its history.</span></div><span class="baact"><button type="button" class="dmcta alt" data-pk="resume">Resume</button><button type="button" class="dlink" data-pk="cancel">Cancel</button></span></div>`;
122
+ const mv = C.self || cur < 0 ? `<span class="note">${C.self ? 'The stage comes from the repository. It moves when the files land.' : 'Its stage is not one of its workflow\'s stages, so it cannot move from here.'}</span>`
123
+ : `${pv ? `<button type="button" class="dmcta alt" data-pk="mv:${cur - 1}">${ICO('<path d="M15 6l-6 6 6 6"/>')}Back to ${esc(pv)}</button>` : ''}${nx ? `<button type="button" class="dmcta alt" data-pk="mv:${cur + 1}">Move to ${esc(nx)}${ICO('<path d="M9 6l6 6-6 6"/>')}</button>` : ''}`;
124
+ return `<div class="baiact">${mv}<span class="iamw">${dotsBtn({ key: 'bar', title: r.title }).replace('class="inim"', 'class="dmcta alt inmore"').replace(ICO(DOTS), 'More' + ICO('<path d="m6 9 6 6 6-6"/>'))}</span></div>`;
125
+ }
126
+ /** The bar's presses: a stage move or a lifecycle press runs at once, More opens the menu without the moves. */
127
+ export function onBar(e, C, r) {
128
+ if (e.target.closest('.bam2')) return false; // a menu item: the document's listener runs it
129
+ const m = e.target.closest('[data-im="bar"]');
130
+ if (m) { openMenu(m, C, { ...r, acts: { ...r.acts, stages: [] } }); return true; }
131
+ const b = e.target.closest('.baiact [data-pk], .lifeb [data-pk]');
132
+ if (!b || b.disabled) return false;
133
+ b.disabled = true; run(C, r, b.dataset.pk).finally(() => { b.disabled = false; });
134
+ return true;
135
+ }
136
+
137
+ /* ── the dialogs: one form in the standard dialog's pane, the conversation box hidden, as Add a document does ── */
138
+ const happens = (L) => `<div class="bahp"><p class="label">What happens</p><ul>${L.map((t) => `<li>${ICO(CHK)}<span>${esc(t)}</span></li>`).join('')}</ul></div>`;
139
+ const rec = (t) => `<p class="note barec">${ICO(SHD)}<span>${esc(t)}</span></p>`;
140
+ const pills = (id, L, cur, lab) => `<div class="chq bapl" id="${id}" role="radiogroup" aria-label="${esc(lab)}">${L.map(([v, l]) => `<button type="button" role="radio" data-v="${v}" aria-checked="${v === cur}" aria-pressed="${v === cur}">${esc(l)}</button>`).join('')}</div>`;
141
+ const pick = (e, id) => { const p = e.target.closest('#' + id + ' [data-v]'); if (!p) return null; $$('#' + id + ' [data-v]').forEach((q) => { q.setAttribute('aria-pressed', q === p); q.setAttribute('aria-checked', q === p); }); return p.dataset.v; };
142
+ const msgP = (id) => `<p class="note" id="${id}" role="status"></p>`;
143
+ function form(o) {
144
+ openDlg({ eye: o.eye, title: o.title, sub: o.sub, say: o.say, stream: turnA(ptx(o.say)), noteKey: null, pane: `<article class="paper doc"><div class="addf">${o.body}</div></article>`, label: o.label || 'Detail' });
145
+ $('#askF').hidden = true; $('#askNote').hidden = true;
146
+ }
147
+ async function press(go, m, fn) {
148
+ go.disabled = true; m.textContent = '';
149
+ const r = await fn();
150
+ if (r && r.ok === true) return r;
151
+ go.disabled = false; m.textContent = errOf(r, 'Nothing was recorded. The server did not say why.'); return null;
152
+ }
153
+
154
+ function openHold(C, r) {
155
+ let back = 'month';
156
+ form({ eye: 'Put on hold', title: 'Put on hold', sub: r.title, say: 'Say why it is paused, and when to look at it again.', body: `
157
+ <label><span>Why is it paused <em>optional</em></span><textarea id="paHR" rows="2" maxlength="500" placeholder="For example: waiting for the Q1 budget decision"></textarea></label>
158
+ <div><span class="label">Check back</span>${pills('paHB', BACK.map((q) => [q[0], q[1]]), back, 'Check back')}</div>
159
+ ${happens(['Keeps its stage' + (r.acts.stage ? ' (' + r.acts.stage + ')' : '') + ', its work and its history.', 'Shows as On hold and leaves the on-track and need-a-look counts.', 'The check-back day shows on its page.'])}
160
+ ${rec('Recorded: one on-hold line in lifecycle.jsonl, with your reason and the check-back day. Undo writes the state it had before.')}
161
+ ${msgP('paHM')}<div class="cact"><button type="button" class="cta" id="paHGo">Put on hold</button><button type="button" class="cta alt" id="paHNo">Not now</button></div>` });
162
+ $('#oMain').onclick = async (e) => {
163
+ const v = pick(e, 'paHB'); if (v) { back = v; return; }
164
+ if (e.target.closest('#paHNo')) { closeDlg(); return; }
165
+ if (!e.target.closest('#paHGo')) return;
166
+ const bk = BACK.find((q) => q[0] === back), day = bk[2] != null ? dayIso(bk[2]) : null, why = $('#paHR').value.trim(), p = prevOf(r);
167
+ const res = await press($('#paHGo'), $('#paHM'), () => life(C, r.id, 'on-hold', why, day)); if (!res) return;
168
+ closeDlg(); await done(C, res, r.title + ' is on hold. Recorded as a lifecycle line.', async () => done(C, await lifeBack(C, r, p), r.title + ' is back as it was.'));
169
+ };
170
+ }
171
+ function openCancel(C, r) {
172
+ let why = '';
173
+ form({ eye: 'Cancel', title: 'Cancel the initiative', sub: r.title, say: 'Pick a reason. Cancel needs one before it can record.', body: `
174
+ <div><span class="label">Why</span>${pills('paCW', WHY, '', 'Why')}</div>
175
+ <label><span>Note <em>optional</em></span><textarea id="paCN" rows="2" maxlength="400" placeholder="What did we learn, and who was told"></textarea></label>
176
+ ${happens(['Shows as Cancelled. The counts treat it as cancelled, not done.', 'It leaves the lists. Show them, under the list, brings it back into view.', 'Keeps its stage, its work and its history. Reopen it any time.'])}
177
+ ${rec('Recorded: one cancelled line in lifecycle.jsonl, with the reason. Undo writes the state it had before.')}
178
+ <p class="note" id="paCM" role="status">Pick a reason to cancel.</p><div class="cact"><button type="button" class="cta" id="paCGo" disabled>Cancel initiative</button><button type="button" class="cta alt" id="paCNo">Not now</button></div>` });
179
+ $('#oMain').onclick = async (e) => {
180
+ const v = pick(e, 'paCW'); if (v) { why = v; $('#paCGo').disabled = false; $('#paCM').textContent = ''; return; }
181
+ if (e.target.closest('#paCNo')) { closeDlg(); return; }
182
+ if (!e.target.closest('#paCGo')) return;
183
+ if (!why) { $('#paCM').textContent = 'Pick a reason to cancel.'; return; }
184
+ const n = $('#paCN').value.trim(), reason = WHY.find((q) => q[0] === why)[1] + (n ? ': ' + n : ''), p = prevOf(r);
185
+ const res = await press($('#paCGo'), $('#paCM'), () => life(C, r.id, 'cancelled', reason)); if (!res) return;
186
+ closeDlg(); await done(C, res, r.title + ' is cancelled. Recorded as a lifecycle line.', async () => done(C, await lifeBack(C, r, p), r.title + ' is back as it was.'));
187
+ };
188
+ }
189
+ function openArchive(C, r) {
190
+ let why = 'unrelated';
191
+ form({ eye: 'Archive', title: 'Archive the initiative', sub: r.title, say: 'Archive takes it out of the board. It is not a status, and nothing is deleted.', body: `
192
+ <div><span class="label">Why</span>${pills('paAW', AWHY, why, 'Why')}</div>
193
+ <label><span>Note <em>optional</em></span><textarea id="paAN" rows="2" maxlength="200" placeholder="Anything you want to remember about it"></textarea></label>
194
+ ${happens(['It leaves every list, count and timeline of the board.', 'Nothing is deleted. The record, its work and its history stay in the repository.', 'Restore it any time, as it was.'])}
195
+ ${rec('Recorded: one archive line in the board ledger (boards.jsonl), with the reason. Undo and Restore write a restore line.')}
196
+ ${msgP('paAM')}<div class="cact"><button type="button" class="cta" id="paAGo">Archive</button><button type="button" class="cta alt" id="paANo">Not now</button></div>` });
197
+ $('#oMain').onclick = async (e) => {
198
+ const v = pick(e, 'paAW'); if (v) { why = v; return; }
199
+ if (e.target.closest('#paANo')) { closeDlg(); return; }
200
+ if (!e.target.closest('#paAGo')) return;
201
+ const n = $('#paAN').value.trim().replace(/\s+/g, ' '), reason = AWHY.find((q) => q[0] === why)[1] + (n ? ': ' + n : '');
202
+ const res = await press($('#paAGo'), $('#paAM'), () => arch(C, r.id, true, reason)); if (!res) return;
203
+ closeDlg(); await done(C, res, r.title + ' is archived. Recorded in the board ledger.', async () => done(C, await arch(C, r.id, false), r.title + ' is restored.'));
204
+ };
205
+ }
206
+
207
+ /* ── new asks and New initiative ── */
208
+ export function asksHtml(C, A) {
209
+ const ic = ICO('<path d="M4 4h16v12H8l-4 4z"/>');
210
+ if (C.self) return `<section class="card baask" id="cAsks" aria-labelledby="hAsks"><div class="ch"><span class="ic">${ic}</span><h2 id="hAsks">New asks</h2><small>none</small></div><p class="note">PMOS-self has no ask source. New work starts at the pmos-router skill.</p></section>`;
211
+ const L = A.rows;
212
+ const body = A.missing ? '<p class="note">The new asks could not be read, so none is shown.</p>' : L.length ? `<div class="bal" role="list">${L.map((a) => `<div class="baa" role="listitem"><p class="baq">“${esc(a.line)}”</p><small class="bam">${esc([a.source || 'Typed in the console', a.by, a.at].filter(Boolean).join(' · '))}</small><div class="bad2">${a.draft.lane ? `<span>${esc(LANES.find((l) => l[0] === a.draft.lane)[1])}</span>` : ''}<span>${a.draft.anchor ? 'Anchor: ' + esc(a.draft.anchor) : 'No anchor suggested'}</span></div><div class="baact"><button type="button" class="dmcta" data-ask="acc:${esc(a.id)}">Accept</button><button type="button" class="dmcta alt" data-ask="dec:${esc(a.id)}">Decline</button></div></div>`).join('')}</div>` : '<p class="note">Nothing new to triage on this board.</p>';
213
+ return `<section class="card baask" id="cAsks" aria-labelledby="hAsks"><div class="ch"><span class="ic">${ic}</span><h2 id="hAsks">New asks</h2><small>${A.missing ? 'not read' : L.length + ' to triage'}</small></div>${body}
214
+ <p class="note">Accept starts an initiative in ${esc(C.first || 'the first stage')}. Decline records why. The title, lane and anchor come from the intake draft, and you can change them.</p></section>`;
215
+ }
216
+ export function onAsks(e, C, A) {
217
+ const b = e.target.closest('[data-ask]'); if (!b) return false;
218
+ const [k, id] = [b.dataset.ask.slice(0, 3), b.dataset.ask.slice(4)], a = A.rows.find((x) => x.id === id); if (!a) return true;
219
+ if (k === 'acc') openIniForm(C, a); else openDecline(C, a);
220
+ return true;
221
+ }
222
+
223
+ let anchors = null;
224
+ async function anchorsOf(C) {
225
+ if (anchors && anchors.key === C.ws + '/' + C.board) return anchors;
226
+ const r = await pmGet('/api/boards/anchors?ws=' + encodeURIComponent(C.ws || '') + '&board=' + encodeURIComponent(C.board || ''));
227
+ anchors = { key: C.ws + '/' + C.board, list: r && r.ok && Array.isArray(r.anchors) ? r.anchors : null };
228
+ return anchors;
229
+ }
230
+ /** The form of New initiative (a = null) and of Accept (a = the ask): title, lane and anchor, from the intake draft when there is one. */
231
+ export async function openIniForm(C, a) {
232
+ const d = a ? a.draft : { title: '', lane: 'feature', anchor: '' };
233
+ const lane0 = d.lane || 'feature';
234
+ form({ eye: a ? 'Accept an ask' : 'New initiative', title: a ? 'Accept ask' : 'New initiative', sub: C.boardName, label: 'Initiative',
235
+ say: a ? 'The intake draft gives the title, lane and anchor. Change any of them, then accept.' : 'Give it a title, a lane and an anchor. It lands in ' + (C.first || 'the first stage') + '.',
236
+ body: `${a ? `<p class="baq">“${esc(a.line)}”</p>` : ''}
237
+ <label>Title<input id="paNT" maxlength="120" value="${esc(d.title)}" placeholder="For example: Per-key API usage for partners"></label>
238
+ <div class="two"><label>Lane<select id="paNL">${LANES.map((l) => `<option value="${l[0]}"${l[0] === lane0 ? ' selected' : ''}>${l[1]}: ${l[2]}</option>`).join('')}</select></label>
239
+ <label id="paNAw">Anchor<select id="paNA" disabled><option>Reading the anchors</option></select></label></div>
240
+ <p class="note" id="paNAh">Every initiative anchors to a KR or a declared health budget. Unanchored work is rejected.</p>
241
+ ${rec(a ? 'Recorded: an accept line for the ask in the board ledger, and a new initiative record with the title, lane and anchor.' : 'Recorded: the title as an ask in the board ledger, its accept line, and a new initiative record with the title, lane and anchor, as the console\'s New initiative does.')}
242
+ ${msgP('paNM')}<div class="cact"><button type="button" class="cta" id="paNGo">${a ? 'Accept into ' : 'Create in '}${esc(C.first || 'the first stage')}</button><button type="button" class="cta alt" id="paNNo">Cancel</button></div>` });
243
+ const A = await anchorsOf(C);
244
+ if (!$('#paNA')) return;
245
+ if (A.list && A.list.length) {
246
+ const has = A.list.some((x) => x.value === d.anchor);
247
+ $('#paNA').outerHTML = `<select id="paNA"><option value="">Choose a KR or a health budget</option>${d.anchor && !has ? `<option value="${esc(d.anchor)}" selected>Suggested: ${esc(d.anchor)}</option>` : ''}${A.list.map((x) => `<option value="${esc(x.value)}"${x.value === d.anchor ? ' selected' : ''}>${esc(x.label || x.value)}</option>`).join('')}</select>`;
248
+ } else {
249
+ $('#paNA').outerHTML = `<input id="paNA" maxlength="120" value="${esc(d.anchor)}" placeholder="For example: health:tech">`;
250
+ $('#paNAh').textContent = 'The declared anchors could not be read, so type one: a KR id or health:<budget>. Unanchored work is rejected.';
251
+ }
252
+ $('#oMain').onclick = async (e) => {
253
+ if (e.target.closest('#paNNo')) { closeDlg(); return; }
254
+ if (!e.target.closest('#paNGo')) return;
255
+ const title = $('#paNT').value.trim(), lane = $('#paNL').value, anchor = $('#paNA').value.trim(), m = $('#paNM');
256
+ if (!title) { m.textContent = 'Give it a title.'; $('#paNT').focus(); return; }
257
+ if (!anchor) { m.textContent = 'Choose an anchor. Unanchored work is rejected.'; $('#paNA').focus(); return; }
258
+ const res = await press($('#paNGo'), m, async () => {
259
+ let ask = a ? a.id : null;
260
+ if (!ask) { const r0 = await post(C, '/api/boards/asks/add', { board: C.board, line: title, source: 'New initiative, typed by you' }); if (!r0 || r0.ok !== true) return r0; ask = r0.ask && r0.ask.id; }
261
+ return post(C, '/api/boards/asks/accept', { board: C.board, ask, title, lane, anchor });
262
+ });
263
+ if (!res) return;
264
+ closeDlg(); await done(C, res, '“' + title + '” is ' + (a ? 'accepted' : 'created') + ' in ' + (res.stage || C.first || 'the first stage') + ', anchored to ' + anchor + '.' + (res.initiative ? ' Its record is ' + res.initiative + '.' : ''));
265
+ };
266
+ }
267
+ function openDecline(C, a) {
268
+ form({ eye: 'Decline an ask', title: 'Decline ask', sub: [a.source, a.by].filter(Boolean).join(' · ') || C.boardName, say: 'Say why. The reason is kept with the ask.', body: `<p class="baq">“${esc(a.line)}”</p>
269
+ <label>Reason<textarea id="paDW" rows="3" maxlength="500" placeholder="Why not? The reason is kept with the ask."></textarea></label>
270
+ ${rec('Recorded: a decline line for the ask in the board ledger, with the reason.')}
271
+ ${msgP('paDM')}<div class="cact"><button type="button" class="cta" id="paDGo" disabled>Decline</button><button type="button" class="cta alt" id="paDNo">Cancel</button></div>` });
272
+ $('#oMain').oninput = (e) => { if (e.target.id === 'paDW') $('#paDGo').disabled = !e.target.value.trim(); };
273
+ $('#oMain').onclick = async (e) => {
274
+ if (e.target.closest('#paDNo')) { closeDlg(); return; }
275
+ if (!e.target.closest('#paDGo')) return;
276
+ const why = $('#paDW').value.trim().replace(/\s+/g, ' ');
277
+ if (!why) { $('#paDM').textContent = 'Say why. A decline needs a reason.'; return; }
278
+ const res = await press($('#paDGo'), $('#paDM'), () => post(C, '/api/boards/asks/decline', { board: C.board, ask: a.id, why })); if (!res) return;
279
+ closeDlg(); await done(C, res, 'Ask declined. The reason is kept in the board ledger.');
280
+ };
281
+ }
@@ -1,16 +1,21 @@
1
1
  /* pm/premium-board.js — the premium Board page (initiative briefing-premium-board, slice 5). Reads GET /api/board-premium and draws the model
2
2
  * lib/board-premium.js builds from the routes the production Initiatives page reads: the Initiatives card (List, By stage, Timeline), the Sprint and
3
- * Coming up cards, Core documents, the dock and the standard dialog. The one press is Draft it on a core document, through POST /api/core-docs/draft.
4
- * Nothing here moves an initiative or issues a document. */
3
+ * Coming up cards, Core documents, the dock and the standard dialog. The presses are Draft it on a core document, through POST /api/core-docs/draft,
4
+ * and the board's own presses of pm/premium-acts.js (initiative premium-board-actions): the New asks card, New initiative, and a row's menu (move,
5
+ * hold, cancel, archive and their Undo). Nothing here issues a document. */
5
6
  import { pmPost } from './http.js';
6
7
  import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, CHECK, store, crumbHtml, wireCrumb, kv, H, openAddDoc } from './premium-shell.js';
8
+ import { dotsBtn, openMenu, closeMenu, menuKey, asksHtml, onAsks, openIniForm } from './premium-acts.js';
7
9
 
8
10
  const MODE_KEY = 'pmos.premium.openAs';
9
11
  let M = null; // the model
10
12
  let view = 'list';
11
13
  let shown = 25; // rows of the list on screen
12
14
  let readTimer = null;
15
+ let showGone = false; // the cancelled and archived rows under the list
13
16
  wireRail('init');
17
+ /** The context of the board presses (pm/premium-acts.js). */
18
+ const ctxOf = () => ({ ws: M.board.ws, board: M.board.id, boardName: M.board.name, self: M.board.self, first: (M.board.stages || [])[0] || '', reload: load });
14
19
  const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
15
20
  const DOCI = '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>';
16
21
  const STATE_ICO = { Linked: '<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>', Live: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>', 'Up to date': '<path d="M5 12.5l4.5 4.5L19 7.5"/>', Draft: '<path d="M4 20l4-1 11-11-3-3L5 16z"/>', 'Not started': '<circle cx="12" cy="12" r="9"/><path d="M12 8v5M12 16.5v.5"/>', Stale: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>', Due: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>' };
@@ -32,13 +37,22 @@ function drawHead() {
32
37
  /* ── initiatives ───────────────────────────────────────────────────────────────────────────────────────────── */
33
38
  const sub = (r) => `${esc(r.sub)}${r.statusLabel ? ` · <span class="${r.late ? 'bad' : 'warn'}">${esc(r.statusLabel)}</span>` : ''}`;
34
39
  function listRow(r, i) {
40
+ return `<div class="inirw">${listBtn(r)}${r.acts ? dotsBtn(r) : ''}</div>`;
41
+ }
42
+ function listBtn(r) {
35
43
  return `<button class="ini2 ibi${r.first ? ' first' : ''}" data-key="${esc(r.key)}"><span class="it"><b>${esc(r.title)}${r.first ? '<em class="tgf">Do this first</em>' : ''}</b><small>${sub(r)}</small></span><span class="wst"><span class="sg2" aria-hidden="true">${r.seg.map((c) => `<i class="${c}"></i>`).join('')}</span><em>${esc(r.stage || 'No stage')}${r.stageNote ? ' · ' + esc(r.stageNote) : ''}</em></span><span class="pg">${r.progress == null ? '' : `<i><b style="width:${r.progress}%"></b></i>`}</span><span class="rl${r.over ? ' over' : ''}">${esc(r.finish)}</span></button>`;
36
44
  }
37
45
  function drawList() {
38
46
  const L = M.initiatives.list.rows;
39
- if (!L.length) return '<p class="empty3 plain">No initiatives are on this board\'s now view.</p>';
40
- return `<div class="inih"><span>Initiative</span><span>Where it is</span><span>Progress</span><span>Planned finish</span></div>` + L.slice(0, shown).map(listRow).join('')
41
- + (L.length > shown ? `<p class="note" style="margin-top:10px">${L.length - shown} more are loaded. <button class="fold alt" id="more" type="button">Show ${Math.min(25, L.length - shown)} more</button></p>` : '');
47
+ if (!L.length) return '<p class="empty3 plain">No initiatives are on this board\'s now view.</p>' + goneHtml();
48
+ return `<div class="inih"><span>Initiative</span><span>Where it is</span><span>Progress</span><span>Planned finish</span></div><div class="inil">` + L.slice(0, shown).map(listRow).join('') + '</div>'
49
+ + (L.length > shown ? `<p class="note" style="margin-top:10px">${L.length - shown} more are loaded. <button class="fold alt" id="more" type="button">Show ${Math.min(25, L.length - shown)} more</button></p>` : '') + goneHtml();
50
+ }
51
+ /** The cancelled and archived rows, under a fold (initiative premium-board-actions). Their menu offers Reopen or Restore. */
52
+ function goneHtml() {
53
+ const G = M.initiatives.gone || { cancelled: [], archived: [] }, nc = G.cancelled.length, na = G.archived.length;
54
+ if (!nc && !na) return '';
55
+ return `<div class="bagone"><button class="dlink" type="button" id="goneT" aria-expanded="${showGone}">${[nc ? nc + ' cancelled' : '', na ? na + ' archived' : ''].filter(Boolean).join(' · ')}. ${showGone ? 'Hide them' : 'Show them'}</button>${showGone ? `<div class="inil">${G.cancelled.concat(G.archived).map((r) => `<div class="inirw gone">${listBtn(r)}${dotsBtn(r)}</div>`).join('')}</div>` : ''}</div>`;
42
56
  }
43
57
  function drawStages() {
44
58
  const S = M.initiatives.stages;
@@ -63,6 +77,8 @@ function drawInit() {
63
77
  $('#ibTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-v]'); if (!b) return; view = b.dataset.v; drawInit(); });
64
78
  $('#ibBody').addEventListener('click', (e) => {
65
79
  if (e.target.closest('#more')) { shown += 25; drawInit(); return; }
80
+ if (e.target.closest('#goneT')) { showGone = !showGone; drawInit(); const g = $('#goneT'); if (g) g.focus(); return; }
81
+ const im = e.target.closest('[data-im]'); if (im) { const r = rowOf(im.dataset.im); if (r) openMenu(im, ctxOf(), r); return; }
66
82
  const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key));
67
83
  });
68
84
  /* A click opens the initiative page, as the mockup's Page setting does; the Popup setting opens the dialog. The choice is kept in this browser. */
@@ -137,6 +153,14 @@ $('#docBody').addEventListener('click', async (e) => {
137
153
 
138
154
  $('#addDoc').onclick = () => openAddDoc({ ws: M.board.ws, scope: M.docs.scope, sub: M.board.name, onAdded: load });
139
155
 
156
+ /* ── new asks and New initiative (initiative premium-board-actions) ───────────────────────────────────────── */
157
+ function drawAsks() {
158
+ $('#asksHost').innerHTML = asksHtml(ctxOf(), M.asks);
159
+ $('#newIni').hidden = !!M.board.self || !M.board.id;
160
+ }
161
+ $('#asksHost').addEventListener('click', (e) => { if (M) onAsks(e, ctxOf(), M.asks); });
162
+ $('#newIni').onclick = () => { closeMenu(); openIniForm(ctxOf(), null); };
163
+
140
164
  /* ── dock ───────────────────────────────────────────────────────────────────────────────────────────────── */
141
165
  function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.label; $('#dNext').innerHTML = M.dock.next ? `<i></i>First <b>${esc(M.dock.next)}</b>` : 'Nothing is late or at risk'; }
142
166
 
@@ -156,7 +180,12 @@ function openRow(r) {
156
180
  $('#dBody').addEventListener('click', (e) => { const lt = e.target.closest('#logT'); if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); } });
157
181
 
158
182
  /* ── load: the routes derive the initiatives in the background, so the first answers are "reading" ───────────── */
159
- function draw() { drawMode(); drawHead(); drawInit(); drawSide(); drawDocs(); drawDock(); onScroll(); }
183
+ function draw() {
184
+ const mk = menuKey(); closeMenu();
185
+ drawMode(); drawHead(); drawInit(); drawAsks(); drawSide(); drawDocs(); drawDock(); onScroll();
186
+ // a read that lands while a row's menu is open draws the row again: open its menu again, with what the row holds now
187
+ if (mk) { const b = $$('#ibBody [data-im]').find((x) => x.dataset.im === mk), r = rowOf(mk); if (b && r) openMenu(b, ctxOf(), r); }
188
+ }
160
189
  async function load() {
161
190
  const p = new URLSearchParams(location.search), q = [p.get('ws') ? 'ws=' + encodeURIComponent(p.get('ws')) : '', p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
162
191
  let r = null, status = 0;
@@ -178,7 +207,7 @@ async function load() {
178
207
  $('#brief').textContent = '';
179
208
  const first = !M; M = r.model; draw();
180
209
  if (first && M.board.ws) startMetrics(M.board.ws); // the Metrics card of a tenant's board reads apart from the board
181
- if (M.docs.rows.some((d) => d.running)) setTimeout(load, 5000); // a core-document run is going: ask again until it ends
210
+ if (M.docs.rows.some((d) => d.running) || r.stale) setTimeout(load, r.stale ? 2000 : 5000); // a core-document run is going, or a press is still being derived: ask again // a core-document run is going: ask again until it ends
182
211
  }
183
212
  $('#brief').textContent = 'Reading the board.';
184
213
  load();
@@ -2,10 +2,12 @@
2
2
  * model lib/initiative-premium.js builds from the routes the production Initiatives sheet reads: the overview and checks, the Tasks card (PRD requirements and
3
3
  * the board's tracker items) and the Core documents card. A document row with a file opens the document sheet (Read, Edit, Proposals, Edit log, Health) in the
4
4
  * standard dialog beside the read-only agent. The presses are Draft it (POST /api/core-docs/draft), the sheet's Save, Ask the agent, Accept and Reject (the
5
- * existing /api/doc-sheet routes, initiative briefing-premium-doc-edit), Add a task and a task's status. Nothing here issues a document or moves an initiative. */
5
+ * existing /api/doc-sheet routes, initiative briefing-premium-doc-edit), Add a task and a task's status, and the bar under the stages (initiative
6
+ * premium-board-actions, pm/premium-acts.js): move to the next stage or back, hold, cancel, archive, resume, reopen and restore, each with Undo. Nothing here issues a document. */
6
7
  import { pmPost } from './http.js';
7
8
  import { proposalsModel, editBody, acceptBody, rejectBody, askBody, askLine } from './premium-doc-edit.js';
8
9
  import { $, $$, esc, openDlg, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, kv, H2, CHECK, crumbHtml, wireCrumb, AI, openAddDoc } from './premium-shell.js';
10
+ import { barHtml, onBar, closeMenu } from './premium-acts.js';
9
11
 
10
12
  let M = null; // the model
11
13
  let taskView = 'list';
@@ -46,6 +48,10 @@ function checksHtml() {
46
48
  const all = M.allSteps.length ? `<details class="src"><summary>All ${M.allSteps.length} workflow steps</summary><div class="ckl">${M.allSteps.map((c) => `<div class="ckr"><i></i><b>${esc(c.label)}</b><span>${esc(c.stateLabel)}</span><small>${esc(c.note)}</small></div>`).join('')}</div></details>` : '';
47
49
  return `<section class="card rise" style="--d:4" id="cIniChk" aria-labelledby="hChk"><div class="ch"><span class="ic">${ICO('<path d="M5 12l5 5L20 7"/>')}</span><h2 id="hChk">Checks</h2><small>from the workflow engine</small></div><div class="ckl">${M.checks.map((c) => `<div class="ckr ${esc(c.state)}${c.cur ? ' cur' : ''}"><i></i><b>${esc(c.label)}</b><span>${esc(c.stateLabel)}</span>${c.owed ? `<small>${esc(c.owed)}</small>` : ''}</div>`).join('')}</div>${all}</section>`;
48
50
  }
51
+ /* the bar's presses (pm/premium-acts.js): the page's context and the initiative as a row */
52
+ const actCtx = () => ({ ws: M.board.ws, board: M.board.id, boardName: M.board.name, self: !!M.acts.self, first: M.acts.stages[0] || '', reload: load });
53
+ const actRow = () => ({ id: M.id, key: 'bar', title: M.title, acts: M.acts });
54
+ $('#iMain').addEventListener('click', (e) => { if (M && M.acts && e.target.closest('#iBar')) onBar(e, actCtx(), actRow()); });
49
55
  $('#iMain').addEventListener('click', (e) => {
50
56
  const h = e.target.closest('[data-help]'); if (!h) return;
51
57
  const a = M.help[+h.dataset.help]; if (!a) return;
@@ -409,7 +415,8 @@ function draw() {
409
415
  $('#snap').textContent = M.header.text;
410
416
  $('#snap').title = 'Every figure on this page comes from a record. A date, owner or progress shows only when one was set.';
411
417
  const keepQ = $('#dmQ') && document.activeElement === $('#dmQ');
412
- $('#iMain').innerHTML = headHtml() + `<div class="bcols"><div>${overviewHtml()}</div><div>${checksHtml()}</div></div>` + tasksHtml() + docsHtml();
418
+ closeMenu();
419
+ $('#iMain').innerHTML = headHtml() + (M.acts ? `<div id="iBar">${barHtml(actCtx(), actRow())}</div>` : '') + `<div class="bcols"><div>${overviewHtml()}</div><div>${checksHtml()}</div></div>` + tasksHtml() + docsHtml();
413
420
  if ($('#dmList')) drawDocList();
414
421
  if (keepQ) { const q = $('#dmQ'); q.focus(); q.setSelectionRange(q.value.length, q.value.length); }
415
422
  pillOf($('#tkTabs'));
@@ -261,3 +261,62 @@ export async function openSettings() {
261
261
  };
262
262
  await load();
263
263
  }
264
+
265
+ /* ── Agent sessions: the running list with Stop (initiative premium-sessions) ──────────────────────────────────────────────────────────────
266
+ * Reads GET /api/sessions, the list the console dock reads. The one write is POST /api/session/remove, a page press. A session's terminal, a new
267
+ * session and a run's questions stay in the console. Every word on a row is a field of the session record. */
268
+ const sessLive = (s) => s && s.shown !== 'exited';
269
+ const readSessions = async () => { const r = await pmGet('/api/sessions'); return r && Array.isArray(r.sessions) ? r.sessions.filter(sessLive) : null; };
270
+ const sessAgo = (t) => { const ms = Date.now() - new Date(t).getTime(); if (!(ms >= 0)) return ''; const m = Math.max(1, Math.round(ms / 60000)); return 'Started ' + (m < 60 ? m + ' min ago' : Math.floor(m / 60) + ' h ' + (m % 60) + ' min ago'); };
271
+ function sessBadge(n) { const b = $('#sessBdg'); if (!b) return; b.textContent = String(n || ''); b.hidden = !n; const a = $('#sessBtn'); if (a) a.setAttribute('aria-label', 'Agent sessions, ' + (n ? n + ' running' : 'none running')); }
272
+ {
273
+ const b = $('#sessBtn');
274
+ if (b) {
275
+ b.onclick = () => openSessions();
276
+ const poll = async () => { if (document.hidden) return; const l = await readSessions(); if (l) sessBadge(l.length); };
277
+ poll(); setInterval(poll, 15000);
278
+ }
279
+ }
280
+ export async function openSessions() {
281
+ const M = { list: null, ask: null, busy: null, slow: null, done: null, err: '' };
282
+ const draw = () => {
283
+ const l = M.list, n = l ? l.length : 0;
284
+ $('#dTitle').textContent = l === null ? 'Agent sessions' : n ? n + ' running' : 'None running';
285
+ const rows = l === null ? '<p class="note">Reading the sessions.</p>' : n ? `<ul class="ssl">${l.map((x) => {
286
+ if (M.done && M.done.id === x.id) return `<li class="ssr"><p class="ssdone">Ended “${esc(x.name)}”.</p></li>`;
287
+ const busy = M.busy === x.id, ask = M.ask === x.id, slow = M.slow === x.id;
288
+ const what = x.headless ? 'This ends the background run.' : 'This ends the session and closes its terminal.';
289
+ return `<li class="ssr"${busy ? ' aria-busy="true"' : ''}><i class="ssd ${esc(x.shown || '')}" aria-hidden="true"></i>
290
+ <div class="ssb"><h3>${esc(x.name)}</h3><p class="ssn">${esc(x.note || 'No note')}</p>
291
+ <p class="ssm">${[x.headless ? 'Background run' : '', x.agent, x.label, x.cwd, sessAgo(x.created), x.automatic ? 'Started by PMOS' : ''].filter(Boolean).map((t) => `<span>${esc(t)}</span>`).join('')}</p></div>
292
+ <button type="button" class="cta alt" data-stop="${esc(x.id)}" aria-label="Stop ${esc(x.name)}"${ask || busy || slow ? ' disabled' : ''}>${busy ? 'Ending…' : 'Stop'}</button>
293
+ ${ask && !busy ? `<div class="ssc" role="group" aria-label="Confirm stop"><p><b>Stop “${esc(x.name)}”?</b> ${what} Files it already wrote stay where they are.</p><div class="ssx"><button type="button" class="cta bad" data-yes="${esc(x.id)}">Stop</button><button type="button" class="cta alt" data-no="${esc(x.id)}">Keep running</button></div></div>` : ''}
294
+ ${slow ? `<div class="ssc" role="group" aria-label="Still running"><p><b>Asked “${esc(x.name)}” to end.</b> It has not exited yet. Press Stop again to remove it.</p><div class="ssx"><button type="button" class="cta bad" data-yes="${esc(x.id)}">Stop again</button><button type="button" class="cta alt" data-no="${esc(x.id)}">Keep running</button></div></div>` : ''}</li>`;
295
+ }).join('')}</ul>` : '<div class="sse"><b>No agent sessions running.</b><p>New sessions start in the console.</p></div>';
296
+ $('#oMain').innerHTML = `<article class="paper doc"><div class="addf">${rows}
297
+ <p class="note" id="ssM" role="status" style="margin:0;min-height:1.2em">${esc(M.err)}</p>
298
+ <p class="note" style="margin:0">Terminals, new sessions and run questions stay in the console. <a href="/c3.html">Open the console</a>.</p></div></article>`;
299
+ };
300
+ openDlg({ eye: 'Agent sessions · real data', title: 'Agent sessions', say: 'The sessions running now. Stop ends one.', stream: turnA(ptx('The sessions running now, read from the same list the console shows. Stop ends one and says so.')), noteKey: null, pane: '<article class="paper doc"></article>', label: 'Sessions' });
301
+ $('#askF').hidden = true; setMode('detail'); draw();
302
+ const load = async () => { M.list = await readSessions(); if (M.list === null) { M.list = []; M.err = 'The sessions could not be read.'; } else sessBadge(M.list.length); draw(); };
303
+ const focusNext = () => { const b = $('#oMain [data-stop]:not([disabled])') || $('#dTitle'); if (b) b.focus(); };
304
+ $('#oMain').onclick = async (e) => {
305
+ if (M.busy) return;
306
+ const st = e.target.closest('[data-stop]'), yes = e.target.closest('[data-yes]'), no = e.target.closest('[data-no]');
307
+ M.err = '';
308
+ if (st) { M.ask = st.dataset.stop; M.slow = null; draw(); const k = $(`#oMain [data-no="${M.ask}"]`); if (k) k.focus(); }
309
+ else if (no) { const id = no.dataset.no; M.ask = null; M.slow = null; draw(); const b = $(`#oMain [data-stop="${id}"]`); if (b) b.focus(); }
310
+ else if (yes) {
311
+ const id = yes.dataset.yes, x = M.list.find((y) => y.id === id); if (!x) return;
312
+ M.busy = id; M.ask = null; M.slow = null; draw();
313
+ const r = await pmPost('/api/session/remove', { id }); M.busy = null;
314
+ if (r && r.ok && r.removed === false) M.slow = id; // asked to end, not exited yet: say so, never claim an end that did not happen
315
+ else if (r && r.ok) { M.done = x; toast('Ended “' + x.name + '”.'); } else M.err = (r && (r.error || r.reason)) || 'Not stopped.';
316
+ draw();
317
+ if (M.done) setTimeout(async () => { M.done = null; await load(); focusNext(); }, 1600);
318
+ else if (M.slow) { const b = $(`#oMain [data-yes="${id}"]`); if (b) b.focus(); }
319
+ }
320
+ };
321
+ await load();
322
+ }
@@ -807,6 +807,25 @@ a.round{color:inherit;text-decoration:none}
807
807
  .dmcta.alt:hover{filter:none;background:var(--well)}
808
808
  .dmcta{min-height:44px}
809
809
 
810
+ /* ── board actions (initiative premium-board-actions): the row menu, the New asks card, the bar on the initiative page and their dialogs; the mockup's rules, cut by class ── */
811
+ .inirw{position:relative}.inirw>.ini2{padding-right:56px;border-top:1px solid var(--hair)}
812
+ .inim{position:absolute;right:-8px;top:50%;transform:translateY(-50%);width:44px;height:44px;border-radius:14px;display:grid;place-items:center;color:var(--ink-2);transition:background .2s}.inim:hover,.inim[aria-expanded="true"]{background:var(--well);color:var(--ink)}.inim svg{width:20px;height:20px;fill:currentColor;stroke:none}
813
+ .inirw.gone .ini2{opacity:.62}.inirw.gone .ini2 .it b{text-decoration:line-through;text-decoration-thickness:1px}
814
+ .bagone{margin-top:8px;padding-top:8px;border-top:1px solid var(--hair)}.bagone .dlink{min-height:44px}
815
+ .bam2{left:auto;right:0;top:calc(100% - 4px);min-width:250px}.bam2.up{top:auto;bottom:calc(100% - 4px)}.bam2 button{height:auto;min-height:44px;padding:8px 12px;font-family:inherit}.bam2 button span{display:grid;gap:2px}.bam2 button b{font-size:13px;color:var(--ink);font-weight:650}.bam2 button small{font-size:12px;color:var(--ink-3);font-weight:500}
816
+ .baask{margin-bottom:24px}.baask .bal{display:grid;gap:10px}.baa{padding:12px 14px;border-radius:14px;background:var(--well);display:grid;gap:6px}
817
+ .baq{margin:0;font-size:14px;line-height:1.45;color:var(--ink)}.bam{font-size:12.5px;color:var(--ink-3)}
818
+ .bad2{display:flex;flex-wrap:wrap;gap:6px}.bad2 span{display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:999px;background:var(--card-solid);font-size:12.5px;font-weight:600;color:var(--ink-2)}
819
+ .baact{display:flex;flex-wrap:wrap;gap:8px;align-items:center}.baa .baact{margin-top:4px}
820
+ .baiact{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:0 0 20px}.baiact .note{margin:0}.iamw{position:relative}
821
+ .lifeb{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:12px;padding:14px 18px;margin:0 0 20px;border-radius:18px;background:color-mix(in oklab,var(--ink) 6%,transparent);box-shadow:inset 3px 0 0 var(--ink-3)}.lifeb>div{display:grid;gap:3px;flex:1 1 260px}.lifeb b{font-size:15px}.lifeb span{font-size:13px;color:var(--ink-2);line-height:1.45}
822
+ .addf textarea{border-radius:14px;border:1px solid var(--hair);background:var(--card-solid);padding:10px 12px;font:inherit;font-size:15px;color:var(--ink);min-width:0;width:100%;resize:vertical}.addf textarea:focus-visible{outline:2px solid var(--ember);outline-offset:1px}
823
+ .bapl button{min-height:40px}#oMain .addf .bapl button[aria-pressed="true"]{background:var(--solid);color:var(--on-solid)}
824
+ .bahp{padding:12px 14px;border-radius:14px;background:var(--well)}.bahp .label{margin:0 0 6px}.bahp ul{list-style:none;margin:0;padding:0;display:grid;gap:6px}.bahp li{display:grid;grid-template-columns:16px minmax(0,1fr);gap:8px;font-size:13px;line-height:1.45;color:var(--ink-2)}.bahp svg{width:14px;height:14px;margin-top:2px;color:var(--ok)}
825
+ .barec{display:flex;gap:8px;margin:0;align-items:flex-start}.barec svg{width:14px;height:14px;flex:none;margin-top:3px}
826
+ .addf .cact{display:flex;flex-wrap:wrap;gap:10px}.addf .note[role="status"]{margin:0;min-height:1.2em}
827
+ @media (max-width:760px){.inirw>.ini2{padding-right:48px}.baiact .dmcta,.lifeb .dmcta,.baa .dmcta{height:44px}.baa .baact .dmcta{flex:1;justify-content:center}.bapl button{min-height:44px}}
828
+
810
829
  /* ── initiative page (initiative briefing-premium-initiative) ── */
811
830
  .ckr.current i{background:var(--ember)}
812
831
  .ckr.done i{background:var(--ok)}
@@ -1310,3 +1329,26 @@ button.dsn:hover{box-shadow:inset 0 0 0 1.5px rgb(79,109,245)}
1310
1329
  .mtg-link{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin:10px 0 8px}
1311
1330
  .mtg-link select{flex:1 1 220px;min-width:0;min-height:44px;border-radius:18px;border:1px solid var(--hair);background:var(--well);padding:0 14px;font:inherit;color:inherit}
1312
1331
  @media (max-width:700px){#todayCard .ch{flex-wrap:wrap;row-gap:8px}}
1332
+
1333
+ /* Agent sessions dialog and its header button (initiative premium-sessions) */
1334
+ .sbtn{position:relative}
1335
+ .sbdg{position:absolute;top:-3px;right:-3px;min-width:22px;height:22px;padding:0 6px;border-radius:999px;background:var(--ember);color:rgb(20,22,31);font:650 12.5px var(--mono);display:grid;place-items:center;pointer-events:none}
1336
+ .sbdg[hidden]{display:none}
1337
+ .ssl{list-style:none;margin:0;padding:0;display:grid;gap:10px}
1338
+ .ssr{display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:6px 14px;align-items:start;padding:16px 18px;border-radius:var(--r-in);background:var(--well)}
1339
+ .ssd{width:10px;height:10px;border-radius:50%;margin-top:7px;background:var(--ink-3)}
1340
+ .ssd.working{background:var(--ok)}.ssd.needs,.ssd.blocked{background:var(--ember)}
1341
+ .ssb{min-width:0}.ssb h3{font-size:16px;font-weight:650;letter-spacing:-.01em;overflow-wrap:anywhere}
1342
+ .ssn{color:var(--ink-2);font-size:var(--t-small);margin-top:2px;overflow-wrap:anywhere}
1343
+ .ssm{display:flex;flex-wrap:wrap;gap:2px 14px;margin-top:8px;font:500 12.5px var(--mono);color:var(--ink-3)}
1344
+ .ssr>.cta{height:44px;padding:0 20px}
1345
+ .ssc,.ssdone{grid-column:1/-1}
1346
+ .ssc{border-top:1px solid var(--hair);padding-top:14px;margin-top:8px;font-size:var(--t-small);color:var(--ink-2)}
1347
+ .ssc b{color:var(--ink);font-weight:650}
1348
+ .ssx{display:flex;gap:10px;flex-wrap:wrap;margin-top:12px}.ssx .cta{height:44px;padding:0 20px}
1349
+ .cta.bad{background:var(--bad);color:rgb(255,255,255)}
1350
+ @media (prefers-color-scheme:dark){:root:not([data-theme="light"]) .cta.bad{color:rgb(40,12,10)}}
1351
+ :root[data-theme="dark"] .cta.bad{color:rgb(40,12,10)}
1352
+ .ssdone{color:var(--ok);font-weight:650}
1353
+ .sse{padding:34px 20px;text-align:center;border-radius:var(--r-in);background:var(--well)}.sse b{display:block;font-size:17px;font-weight:650}.sse p{color:var(--ink-2);margin-top:6px;font-size:var(--t-small)}
1354
+ @media (max-width:700px){.ssr{grid-template-columns:auto minmax(0,1fr)}.ssr>.cta{grid-column:2}}
@@ -36,6 +36,7 @@
36
36
  <div class="tools tools-top"><span class="snap" id="snap">Reading the board</span>
37
37
  <span class="seg modeseg" id="modeSeg" role="group" aria-label="How an initiative opens"><i class="pill"></i><button data-m="page" aria-pressed="true">Page</button><button data-m="popup" aria-pressed="false">Popup</button></span>
38
38
  <a class="glass round" id="toConsole" href="/c3.html" aria-label="Open the console" title="Open the console"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="m7 9 3 3-3 3M13 15h4"/></svg></a>
39
+ <button class="glass round sbtn" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions" title="Agent sessions"><svg class="i" viewBox="0 0 24 24"><path d="M4 6h16M4 12h10M4 18h6"/><circle cx="18" cy="16" r="3"/></svg><span class="sbdg" id="sessBdg" aria-hidden="true" hidden></span></button>
39
40
  <button class="glass round" id="settingsBtn" aria-label="Settings" title="Settings"><svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6 7 7M17 17l1.4 1.4M5.6 18.4 7 17M17 7l1.4-1.4"/></svg></button>
40
41
  <button class="glass round" id="theme" aria-label="Switch light or dark"><svg class="i" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg></button></div>
41
42
  </header>
@@ -49,7 +50,7 @@
49
50
  <div class="bcols">
50
51
  <div>
51
52
  <section class="card rise" style="--d:5" id="cIni" aria-labelledby="hIni">
52
- <div class="ch"><span class="ic"><svg class="i" viewBox="0 0 24 24"><path d="M12 3 3 8l9 5 9-5z"/><path d="m3 13 9 5 9-5"/></svg></span><h2 id="hIni">Initiatives</h2><small id="iniCap"></small></div>
53
+ <div class="ch"><span class="ic"><svg class="i" viewBox="0 0 24 24"><path d="M12 3 3 8l9 5 9-5z"/><path d="m3 13 9 5 9-5"/></svg></span><h2 id="hIni">Initiatives</h2><small id="iniCap"></small><button class="fold alt dmadd2" id="newIni" type="button" hidden>New initiative</button></div>
53
54
  <div class="mprog" id="iniBar" role="progressbar" aria-label="Open initiatives on track" aria-valuemin="0" hidden><b></b></div>
54
55
  <div class="seg" id="ibTabs" role="group" aria-label="Initiatives view"><i class="pill"></i><button data-v="list" aria-pressed="true">List</button><button data-v="stages" aria-pressed="false">By stage</button><button data-v="time" aria-pressed="false">Timeline</button></div>
55
56
  <div id="ibBody"></div>
@@ -57,6 +58,7 @@
57
58
  </section>
58
59
  </div>
59
60
  <div>
61
+ <div id="asksHost"></div>
60
62
  <section class="card rise" style="--d:6" id="cSpr" aria-labelledby="hSpr">
61
63
  <div class="ch"><span class="ic"><svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg></span><h2 id="hSpr">Sprint</h2><small id="sprCap"></small></div>
62
64
  <div id="sprBody"></div>
@@ -73,7 +75,7 @@
73
75
  <div class="dmg two" id="docBody" role="list"></div>
74
76
  <p class="note" id="docNote" style="margin-top:12px"></p>
75
77
  </section>
76
- <p class="foot" id="foot">This page reads the board's own records, the same ones the Initiatives page reads. Its presses are Draft it on a core document, which starts the existing read-only run that writes a draft and sends nothing, and Add a document, which saves a document on the board's record. Issue, Drop and moving an initiative are not built here. The Metrics charts are not drawn, because PMOS holds no metric series for a board. A sprint appears only when a session has read Jira.</p>
78
+ <p class="foot" id="foot">This page reads the board's own records, the same ones the Initiatives page reads. Its presses are Draft it on a core document, which starts the existing read-only run that writes a draft and sends nothing, Add a document, which saves a document on the board's record, and the board's own presses: accept or decline a new ask, New initiative, and move, hold, cancel or archive an initiative, each through the console's route and each with Undo. Issue and Drop are not built here. The Metrics charts are not drawn, because PMOS holds no metric series for a board. A sprint appears only when a session has read Jira.</p>
77
79
  </main>
78
80
  <noscript>This page needs JavaScript.</noscript>
79
81
  <script type="module" src="/pm/premium-board.js"></script>