create-pmos 0.285.0 → 0.287.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.
@@ -5,7 +5,7 @@
5
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
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. */
7
7
  import { pmPost } from './http.js';
8
- import { proposalsModel, editBody, acceptBody, rejectBody, askBody, askLine, issueBody, mdHtml } from './premium-doc-edit.js';
8
+ import { mountDocSheet } from './premium-doc-sheet.js';
9
9
  import { $, $$, esc, openDlg, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, kv, H2, CHECK, CHEV, crumbHtml, wireCrumb, AI, openAddDoc } from './premium-shell.js';
10
10
  import { barHtml, onBar, closeMenu } from './premium-acts.js';
11
11
 
@@ -14,6 +14,7 @@ let taskView = 'list';
14
14
  const DAY = 86400000;
15
15
  let docFilter = 'all', docQuery = '';
16
16
  let readTimer = null;
17
+ const docSheet = mountDocSheet({ ws: () => M.board.ws, scope: () => M.docs.scope, rows: () => M.docs.rows, reload: () => load(), noteKey: (d) => 'doc:' + M.id + ':' + d.key, sub: () => M.title, again: false });
17
18
  wireRail('init');
18
19
  const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
19
20
  const DOCI = '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>';
@@ -114,7 +115,7 @@ $('#iMain').addEventListener('click', (e) => {
114
115
  const f = e.target.closest('[data-dmf]'); if (f) { docFilter = f.dataset.dmf; drawDocList(); return; }
115
116
  const d = e.target.closest('[data-draft]'); if (d && !d.disabled) { draft(d); return; }
116
117
  const all = e.target.closest('[data-draftall]'); if (all && !all.disabled) { draftAll(all); return; }
117
- const o = e.target.closest('[data-doc]'); if (o) { openSheet(M.docs.rows.find((x) => x.key === o.dataset.doc)); }
118
+ const o = e.target.closest('[data-doc]'); if (o) { docSheet.open(M.docs.rows.find((x) => x.key === o.dataset.doc)); }
118
119
  });
119
120
  const STATES = ['To do', 'In progress', 'In review', 'Done'];
120
121
  function openTask(t) {
@@ -219,187 +220,6 @@ function openAsk(q) {
219
220
  }
220
221
 
221
222
  /* ── the document sheet: Read, Edit, Proposals, Edit log, Health. ─────────────────────────────────────────────── */
222
- let sheet = null; // { d, tab, text, log, health, props, draft, why, ask, askText, picked, busy, msg, err }
223
- const TABS = [['read', 'Read'], ['edit', 'Edit'], ['props', 'Proposals'], ['log', 'Edit log'], ['health', 'Health']];
224
- const wsq = () => (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) : '');
225
- const propsM = (s) => proposalsModel(s.props || []);
226
- /** The bar above a draft (core document Issue, initiative premium-core-doc-issue). The words are fixed; the state is the row's own. */
227
- function issueBar(s) {
228
- const d = s.d;
229
- if (s.issued && d.st !== 'draft') return `<div class="dsiss dsok" data-issue-bar="done" role="status"><span>${CHECK}Issued. Nothing was sent to anyone. The row now reads ${esc(d.state)}.</span></div>`;
230
- if (d.st !== 'draft' || !d.slot) return '';
231
- return `<div class="dsiss" data-issue-bar="draft"><span>${AI}PMOS drafted this from its sources. Nothing is sent. Read it, change what you like, then issue it.</span><button class="dmcta dark" data-ds="issue"${s.busy ? ' disabled' : ''}>Issue it</button></div>`
232
- + (s.msg && s.tab === 'read' ? `<p class="note" id="dsErr" role="alert" style="margin:-4px 0 10px;color:var(--ember-ink)">${esc(s.msg)}</p>` : '');
233
- }
234
- function sheetPane() {
235
- const s = sheet, d = s.d;
236
- const cnt = (k) => (k === 'props' && s.props && propsM(s).count ? ` <em>${propsM(s).count}</em>` : '');
237
- const EYE = '<svg class="i" viewBox="0 0 24 24"><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"/></svg>';
238
- const menu = `<div class="dsvr" id="shT"><span class="dsvw"><button type="button" class="dsvb" id="shV" aria-haspopup="menu" aria-expanded="${!!s.vm}">${EYE}${esc(TABS.find((t) => t[0] === s.tab)[1])}${cnt(s.tab)}${CHEV}</button>${s.vm ? `<div class="dsmn" role="menu" aria-label="Document views">${TABS.map(([k, n]) => `<button type="button" role="menuitem" data-sh="${k}" aria-current="${s.tab === k}">${n}${cnt(k)}${s.tab === k ? CHECK : ''}</button>`).join('')}</div>` : ''}</span></div>`;
239
- const head = `<p class="dpath">${esc(d.path)}</p><div class="dsm"><span class="${d.st === 'ok' ? 'ok' : d.st === 'draft' ? 'warn' : 'mut'}">${esc(d.state)}</span>${d.when ? `<span>updated ${esc(d.when)}</span>` : ''}${d.by ? `<span>${esc(d.by)}</span>` : ''}</div>`;
240
- let body = '';
241
- if (s.err) body = `<p class="empty3 plain">${esc(s.err)}</p>`;
242
- else if (s.tab === 'read') {
243
- if (s.text == null) body = '<p class="empty3 plain">Reading the file.</p>';
244
- else { const m = s.md || (s.md = mdHtml(s.text)); body = issueBar(s) + (m.fm.length ? kv(m.fm) : '') + `<div class="dsrd${m.outline.length > 2 ? '' : ' no'}">${m.outline.length > 2 ? `<nav class="dso" aria-label="Outline"><p class="label">Outline <em>${m.outline.length} headings</em></p>${m.outline.map((t, n) => `<button data-go="${n}">${esc(t)}${s.props && propsM(s).marked.has(t) ? '<i></i>' : ''}</button>`).join('')}</nav>` : ''}<div class="dsbody">${m.html}</div></div>`; }
245
- } else if (s.tab === 'edit') {
246
- if (s.text == null) body = '<p class="empty3 plain">Reading the file.</p>';
247
- else {
248
- const cur = s.draft == null ? s.text : s.draft, nv = ((s.log && s.log.revisions) || []).length + 1;
249
- body = `<textarea id="dsEd" class="dsed" spellcheck="true" aria-label="Edit the document">${esc(cur)}</textarea>`
250
- + `<p class="note" id="dsNote" style="margin:8px 0">${cur === s.text ? 'No changes yet.' : 'Changed. Health checks the document again after you save.'}</p>`
251
- + `<input id="dsWhy" class="dsy" placeholder="Why are you changing it? Kept in the edit log." aria-label="Why are you changing it" value="${esc(s.why || '')}">`
252
- + `<p class="note" id="dsErr" role="alert" style="margin:6px 0 0;color:var(--ember-ink)">${esc(s.msg || '')}</p>`
253
- + `<div class="dsfoot"><span class="note">Saved by you as v${nv}</span><span><button class="dmcta alt" data-ds="discard">Cancel</button><button class="dmcta dark" id="dsSave" data-ds="save"${s.busy || cur === s.text ? ' disabled' : ''}>Save as v${nv}</button></span></div>`;
254
- }
255
- } else if (s.tab === 'props') {
256
- if (!s.props) body = '<p class="empty3 plain">Reading the proposals.</p>';
257
- else {
258
- const m = propsM(s), line = askLine(s.ask);
259
- body = `<div class="dsask2"><p class="label">${AI}Ask the agent</p><textarea id="dsAsk" rows="3" placeholder="Tell the agent what to change, for example: add a one-paragraph summary at the top" aria-label="Tell the agent what to change">${esc(s.askText || '')}</textarea><div class="dsrow"><button class="dmcta alt" data-ds="ask"${s.busy || (s.ask && s.ask.state === 'working') ? ' disabled' : ''}>${AI}Ask the agent</button></div><p class="note" style="margin:8px 0 0">The agent drafts a proposal and can only read. Nothing in the document changes until you accept it, and your request is kept in the edit log.</p>${line ? `<p class="note" role="status" style="margin:6px 0 0">${esc(line)}</p>` : ''}</div>`
260
- + `<p class="label" style="margin:18px 0 8px">Open proposals · ${m.count}</p>`
261
- + (m.count ? m.open.map((p) => propHtml(s, p)).join('') : `<div class="dsnone">${CHECK}No open proposals.</div>`)
262
- + (m.closed.length ? `<p class="label" style="margin:18px 0 8px">Closed · ${m.closed.length}</p>${m.closed.map((p) => `<div class="dsp ${esc(p.state)}"><div><b>${esc(p.who)}</b><span>${esc(p.request)}</span>${p.why ? `<q>${esc(p.why)}</q>` : ''}</div><span class="dst2">${esc(p.label)}</span></div>`).join('')}` : '')
263
- + `<p class="note" id="dsErr" role="alert" style="margin:10px 0 0;color:var(--ember-ink)">${esc(s.msg || '')}</p>`;
264
- }
265
- } else if (s.tab === 'log') {
266
- if (!s.log) body = '<p class="empty3 plain">Reading the log.</p>';
267
- else {
268
- const R = (s.log.revisions || []).slice().reverse(), E = (s.log.events || []).slice().reverse();
269
- body = (R.length ? `<div class="evl">${R.map((r) => `<div class="hsr"><time>${esc(when(r.at))}</time><span><b>v${esc(r.rev)}</b> ${esc(r.why || (r.by === 'baseline' ? 'The file as the sheet first saw it' : 'No reason recorded'))}${r.by ? ' · ' + esc(r.by) : ''}</span></div>`).join('')}</div>` : '<p class="mut">No revision is recorded.</p>')
270
- + (E.length ? `<p class="label" style="margin:18px 0 8px">Other entries</p><div class="evl">${E.map((e) => `<div class="hsr"><time>${esc(when(e.at))}</time><span><b>${esc(e.kind)}</b> ${esc(e.prompt || e.why || '')}</span></div>`).join('')}</div>` : '');
271
- }
272
- } else if (s.tab === 'health') {
273
- if (!s.health) body = '<p class="empty3 plain">Checking the document.</p>';
274
- else body = `<p class="note" style="margin:0 0 10px">${s.health.passed} of ${s.health.total} checks that had the input they need passed. A check with no input is not counted.</p><div class="ckl">${s.health.checks.map((c) => `<div class="ckr ${c.pass === true ? 'done' : c.pass === false ? 'blocked' : 'skipped'}"><i></i><b>${esc(c.id)}</b><span>${c.pass === true ? 'Passed' : c.pass === false ? 'Not passed' : 'No input'}</span><small>${esc(c.reason || '')}</small></div>`).join('')}</div>`;
275
- }
276
- return `<article class="paper doc">${head}${menu}<div id="shBody">${body}</div><p class="xn">Every change is kept in the Edit log with its reason. The file changes only when you press Save or Accept.</p></article>`;
277
- }
278
- function propHtml(s, p) {
279
- const picked = s.picked && s.picked[p.id], on = (n) => (picked ? picked.includes(n) : true);
280
- const secs = p.sections.map((x) => `<div class="dsdf">${p.sections.length > 1 && !x.stale ? `<label><input type="checkbox" data-pk="${esc(p.id)}" value="${esc(x.name)}"${on(x.name) ? ' checked' : ''}> ` : ''}<b>${esc(x.name)}</b>${p.sections.length > 1 && !x.stale ? '</label>' : ''} ${x.stale ? '<span class="dst2">Changed since this was proposed</span>' : `<ins>+ ${esc(x.add)}</ins>`}</div>`).join('');
281
- return `<div class="dsp"><div><b>${esc(p.who)}</b><span>${esc(p.request)}</span>${secs}${p.staleAll ? '<q>The document changed since this was proposed, so it cannot be accepted. Ask again.</q>' : ''}</div><div class="dsa">${p.canAccept ? `<button class="dmcta dark" data-ds="acc:${esc(p.id)}"${s.busy ? ' disabled' : ''}>Accept</button>` : ''}<button class="dmcta alt" data-ds="rej:${esc(p.id)}"${s.busy ? ' disabled' : ''}>Reject</button></div>${s.rejecting === p.id ? `<div class="dsrow" style="grid-column:1/-1"><input id="dsRj" class="dsy" placeholder="Why are you rejecting it? Kept in the edit log." aria-label="Why are you rejecting it" value="${esc(s.rejWhy || '')}"><button class="dmcta dark" data-ds="rejgo:${esc(p.id)}"${s.busy ? ' disabled' : ''}>Reject it</button><button class="dmcta alt" data-ds="rejno">Cancel</button></div>` : ''}</div>`;
282
- }
283
- function drawSheet() { $('#oMain').innerHTML = sheetPane(); }
284
- async function getJson(url, init) { try { const r = await fetch(url, Object.assign({ credentials: 'same-origin' }, init || {})); return await r.json(); } catch { return null; } }
285
- async function loadTab(tab) {
286
- const s = sheet, p = encodeURIComponent(s.d.path), ws = M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) : '';
287
- if (tab !== 'props' && tab !== 'log' && tab !== 'health' && !s.props) {
288
- const pr = await getJson('/api/doc-sheet/proposals?path=' + p + ws);
289
- if (sheet !== s) return;
290
- if (pr && pr.ok) s.props = pr.proposals || [];
291
- }
292
- if ((tab === 'read' || tab === 'edit') && s.text == null) {
293
- const lg = s.log || (s.log = await getJson('/api/doc-sheet/log?path=' + p + ws));
294
- if (sheet !== s) return;
295
- const revs = lg && lg.ok ? lg.revisions || [] : [];
296
- const at = revs.length ? await getJson('/api/doc-sheet/at?path=' + p + '&rev=' + revs[revs.length - 1].rev + ws) : null;
297
- if (sheet !== s) return;
298
- if (at && at.ok) s.text = at.text; else s.err = (at && at.error) || (lg && lg.error) || 'The file could not be read.';
299
- } else if (tab === 'props' && !s.props) {
300
- const pr = await getJson('/api/doc-sheet/proposals?path=' + p + ws);
301
- if (sheet !== s) return;
302
- if (!pr || pr.ok === false) s.err = (pr && pr.error) || 'The proposals could not be read.'; else s.props = pr.proposals || [];
303
- } else if (tab === 'log' && !s.log) {
304
- s.log = await getJson('/api/doc-sheet/log?path=' + p + ws);
305
- if (sheet !== s) return;
306
- if (!s.log || s.log.ok === false) { s.err = (s.log && s.log.error) || 'The edit log could not be read.'; s.log = null; }
307
- } else if (tab === 'health' && !s.health) {
308
- const h = await getJson('/api/doc-health/check', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ path: s.d.path, ws: M.board.ws }) });
309
- if (sheet !== s) return;
310
- if (!h || h.ok === false) s.err = (h && h.error) || 'The health check could not run.'; else s.health = h.health;
311
- }
312
- if (sheet === s && s.tab === tab) drawSheet();
313
- }
314
- function openSheet(d) {
315
- if (!d || !d.path) return;
316
- sheet = { d, tab: 'read', text: null, log: null, health: null, props: null, draft: null, why: '', ask: null, askText: '', picked: {}, busy: false, msg: '', err: null };
317
- const key = 'doc:' + M.id + ':' + d.key, say = d.title + ' is ' + d.state.toLowerCase() + (d.by ? '. ' + d.by + '.' : '.') + ' I can read the file with you and answer questions. I change nothing; only you change the file, with Save or Accept.';
318
- openDlg({ eye: 'Document · real data', title: d.title, sub: M.title, say, stream: turnA(logHtml({ logTitle: 'Read from the repository', log: ['Found the file ' + d.path, 'Read its revisions from the document sheet', 'Left the file as it is'] })) + turnA(ptx(say)), noteKey: key, pane: '', label: 'Document' });
319
- drawSheet(); loadThread(key); loadTab('read');
320
- }
321
- $('#oMain').addEventListener('click', (e) => {
322
- if (sheet && sheet.vm && !e.target.closest('.dsvw')) { sheet.vm = false; drawSheet(); }
323
- if (sheet && e.target.closest('#shV')) { keepDraft(); sheet.vm = !sheet.vm; drawSheet(); return; }
324
- const t = e.target.closest('[data-sh]');
325
- if (t && sheet) { keepDraft(); sheet.vm = false; sheet.tab = t.dataset.sh; sheet.err = null; sheet.msg = ''; drawSheet(); loadTab(sheet.tab); return; }
326
- const b = e.target.closest('[data-ds]'); if (b && sheet) { sheetPress(b.dataset.ds); return; }
327
- const g = e.target.closest('[data-go]'); if (g) { const h = $('#ds-h' + g.dataset.go); if (h) h.scrollIntoView({ block: 'start', behavior: 'smooth' }); }
328
- });
329
- $('#oMain').addEventListener('change', (e) => { const c = e.target.closest('[data-pk]'); if (c && sheet) sheet.picked[c.dataset.pk] = $$('[data-pk]', $('#oMain')).filter((x) => x.dataset.pk === c.dataset.pk && x.checked).map((x) => x.value); });
330
- $('#oMain').addEventListener('input', (e) => {
331
- if (!sheet) return;
332
- if (e.target.id === 'dsEd') { sheet.draft = e.target.value; const ch = sheet.draft !== sheet.text; $('#dsSave').disabled = !ch || sheet.busy; $('#dsNote').textContent = ch ? 'Changed. Health checks the document again after you save.' : 'No changes yet.'; }
333
- else if (e.target.id === 'dsWhy') sheet.why = e.target.value;
334
- else if (e.target.id === 'dsAsk') sheet.askText = e.target.value;
335
- else if (e.target.id === 'dsRj') sheet.rejWhy = e.target.value;
336
- });
337
- function keepDraft() { if (!sheet) return; const ed = $('#dsEd'), w = $('#dsWhy'), a = $('#dsAsk'), rj = $('#dsRj'); if (rj) sheet.rejWhy = rj.value; if (ed) sheet.draft = ed.value; if (w) sheet.why = w.value; if (a) sheet.askText = a.value; }
338
- /* the sheet's presses: each posts to one existing /api/doc-sheet route (ws in the query, as the routes read it) and then reads the routes again */
339
- const dsPost = (route, body) => pmPost('/api/doc-sheet/' + route + (M.board.ws ? '?ws=' + encodeURIComponent(M.board.ws) : ''), body);
340
- async function reloadSheet(s) {
341
- s.text = null; s.md = null; s.log = null; s.health = null; s.props = null; s.draft = null; s.why = ''; s.rejecting = null;
342
- await loadTab(s.tab);
343
- if (sheet === s) { s.busy = false; drawSheet(); }
344
- }
345
- async function sheetPress(act) {
346
- const s = sheet; keepDraft();
347
- const fail = (m) => { s.busy = false; s.msg = m; drawSheet(); };
348
- if (act === 'rejno') { s.rejecting = null; s.msg = ''; drawSheet(); return; }
349
- if (act === 'discard') { s.draft = null; s.why = ''; s.msg = ''; drawSheet(); return; }
350
- if (act === 'issue') {
351
- const r = issueBody(M.board.ws, M.docs.scope, s.d.key, s.d.slot, s.draft != null && s.draft !== s.text); if (r.error) return fail(r.error);
352
- s.busy = true; s.msg = ''; drawSheet();
353
- const res = await pmPost('/api/core-docs/issue', r.body); if (sheet !== s) return;
354
- if (!res || res.ok !== true) return fail((res && res.error) || 'The document could not be issued.');
355
- toast('Issued. Nothing was sent to anyone.');
356
- s.issued = true; await load(); if (sheet !== s) return;
357
- s.d = M.docs.rows.find((x) => x.key === s.d.key) || s.d;
358
- return reloadSheet(s);
359
- }
360
- if (act === 'save') {
361
- const r = editBody(s.d.path, s.text, s.draft == null ? s.text : s.draft, s.why); if (r.error) return fail(r.error);
362
- s.busy = true; s.msg = ''; drawSheet();
363
- const res = await dsPost('edit', r.body); if (sheet !== s) return;
364
- if (!res || res.ok !== true) return fail((res && res.error) || 'The document could not be saved.');
365
- toast('Saved. The reason is in the Edit log.'); return reloadSheet(s);
366
- }
367
- if (act === 'ask') {
368
- const r = askBody(s.d.path, s.askText); if (r.error) return fail(r.error);
369
- s.busy = true; s.msg = ''; drawSheet();
370
- const res = await dsPost('ask', r.body); if (sheet !== s) return;
371
- s.busy = false;
372
- if (!res || res.ok !== true || !res.id) return fail((res && res.error) || 'The agent could not be asked.');
373
- s.askText = ''; s.ask = { state: 'working', id: res.id }; drawSheet(); return pollAsk(s, res.id);
374
- }
375
- const [kind, id] = [act.split(':')[0], act.slice(act.indexOf(':') + 1)];
376
- const p = propsM(s).open.find((x) => x.id === id); if (!p) return;
377
- if (kind === 'acc') {
378
- const r = acceptBody(s.d.path, p, s.picked[id] || p.sections.filter((x) => !x.stale).map((x) => x.name)); if (r.error) return fail(r.error);
379
- s.busy = true; s.msg = ''; drawSheet();
380
- const res = await dsPost('accept', r.body); if (sheet !== s) return;
381
- if (!res || res.ok !== true) { await reloadSheet(s); return fail((res && res.error) || 'The proposal could not be accepted.'); }
382
- toast('Accepted. The file changed and the request is in the Edit log.'); return reloadSheet(s);
383
- }
384
- if (kind === 'rej') { s.rejecting = id; s.rejWhy = ''; s.msg = ''; drawSheet(); const f = $('#dsRj'); if (f) f.focus(); return; }
385
- if (kind === 'rejgo') {
386
- const r = rejectBody(s.d.path, p, s.rejWhy); if (r.error) return fail(r.error);
387
- s.busy = true; s.msg = ''; drawSheet();
388
- const res = await dsPost('reject', r.body); if (sheet !== s) return;
389
- if (!res || res.ok !== true) return fail((res && res.error) || 'The proposal could not be rejected.');
390
- toast('Rejected. The file is as it was.'); return reloadSheet(s);
391
- }
392
- }
393
- async function pollAsk(s, id) {
394
- for (let i = 0; i < 400 && sheet === s; i++) {
395
- await new Promise((r) => setTimeout(r, 2000));
396
- const a = await getJson('/api/doc-sheet/ask?id=' + encodeURIComponent(id) + wsq()); if (sheet !== s) return;
397
- if (!a || a.ok === false) { s.ask = { state: 'failed', error: (a && a.error) || 'The answer could not be read.' }; drawSheet(); return; }
398
- s.ask = a;
399
- if (a.state !== 'working') { s.props = null; await loadTab('props'); if (sheet === s) drawSheet(); return; }
400
- if (s.tab === 'props') drawSheet();
401
- }
402
- }
403
223
  $('#dBody').addEventListener('click', (e) => { const lt = e.target.closest('#logT'); if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); } });
404
224
 
405
225
  /* ── load: the routes derive the initiatives in the background, so the first answers are "reading" ────────── */
@@ -256,11 +256,17 @@ function repDlg(o) {
256
256
  closeDlg(); await load();
257
257
  };
258
258
  }
259
+ /* Words for a refused press: what the server said, then how to go on. A reason (set-up | dismissed | gone) means the list this window came from is out of date, so it is read again and a retry would only repeat the refusal. */
260
+ const pressFailed = (res, plain) => {
261
+ const e = res && res.error ? String(res.error) : plain;
262
+ if (res && res.reason) return e + ' This window is out of date. Close it; the list has been read again.';
263
+ return e + ' Nothing was recorded. Press the button to try again.';
264
+ };
259
265
  /* A press: post, then say the result in words, or keep the dialog open with the server's refusal. */
260
266
  const press = (sub, body, said) => async (m) => {
261
267
  m.textContent = 'Recording.';
262
268
  const res = await repPost(sub, body);
263
- if (!res || res.ok !== true) { m.textContent = (res && res.error) || 'That did not go through.'; return 'keep'; }
269
+ if (!res || res.ok !== true) { m.textContent = pressFailed(res, 'That did not go through.'); if (res && res.reason) load(); return 'keep'; }
264
270
  toast(typeof said === 'function' ? said(res) : said); return null;
265
271
  };
266
272
  const setupSaid = (res) => { const d = res.drafted || {}; return 'Set up. ' + (d.path ? 'The first draft is ' + d.path + '.' : 'The first draft was not written' + (d.error ? ': ' + d.error : '') + '. Draft it now on the report tries again.'); };
@@ -271,9 +277,9 @@ function openFound(f) {
271
277
  html: `<p class="lede" style="margin:0 0 12px">${esc(f.why)}</p>${propHtml(f.proposal)}<h3 class="h2">What PMOS saw · ${f.evidence.length}</h3><ul class="pdev">${f.evidence.map((x) => `<li>${esc(x.text)}${x.kind ? ` <small>${esc(x.kind)}</small>` : ''}</li>`).join('')}</ul><p class="note">Set it up records the report in the report ledger and drafts its first cycle as a file. Not a report hides it; you can undo for 5 seconds.</p>`,
272
278
  acts: [['set', 'Set it up'], ['no', 'Not a report', 1]],
273
279
  on: {
274
- set: press('setup', { finding: f.id }, setupSaid),
280
+ set: press('setup', { finding: f.id, name: f.name }, setupSaid),
275
281
  no: (m) => {
276
- const t = setTimeout(async () => { dismissing.delete(f.id); const res = await repPost('dismiss', { finding: f.id }); if (!res || res.ok !== true) toast((res && res.error) || 'Not a report did not go through.'); await load(); }, 5000);
282
+ const t = setTimeout(async () => { dismissing.delete(f.id); const res = await repPost('dismiss', { finding: f.id, name: f.name }); if (!res || res.ok !== true) toast(pressFailed(res, 'Not a report did not go through.')); await load(); }, 5000);
277
283
  dismissing.set(f.id, t); drawReps();
278
284
  m.innerHTML = 'Hidden. It is recorded as not a report in 5 seconds. <button class="lk" id="rxUndo">Undo</button>';
279
285
  $('#rxUndo').onclick = () => { clearTimeout(dismissing.get(f.id)); dismissing.delete(f.id); drawReps(); m.textContent = 'Undone. Nothing was recorded.'; $$('#oMain [data-rx]').forEach((x) => { x.disabled = false; }); };
@@ -4,6 +4,7 @@
4
4
  * My work depth (initiative premium-work-depth): the dialog's tool row (Edit, Who does each step, Not before, Someday), the Focus bar and its jobs, the agent on an item
5
5
  * (draft, stop, edit, post after a confirm, send back, try again), and keys and swipe on the rows. */
6
6
  import { pmPost } from './http.js';
7
+ import { mdRender } from './markdown.js';
7
8
  import { $, $$, esc, openDlg, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, turnU, ptx, CHECK, RM, S } from './premium-shell.js';
8
9
 
9
10
  let M = null; // the model
@@ -15,6 +16,9 @@ const GLYPH = {
15
16
  Board: '<path d="M12 3 3 8l9 5 9-5z"/><path d="m3 13 9 5 9-5"/>',
16
17
  Yours: '<path d="M4 20l4-1 11-11-3-3L5 16z"/>',
17
18
  };
19
+ const mdHtml = (t) => { try { const d = document.createElement('div'); d.append(...mdRender(String(t)).blocks.map((b) => b.node || b)); return d.innerHTML; } catch { return '<p class="tt">' + esc(t) + '</p>'; } }; // mdRender builds nodes, never a string, so nothing in a draft runs
20
+ const KIND = { ask: 'You asked', draft: 'Agent drafted', edit: 'You edited it', note: 'You sent it back', sent: 'Posted', post: 'Posted' };
21
+ const turnsHtml = (a) => (a.turns && a.turns.length ? `<h3 class="h2">Conversation with the agent</h3><ol class="agturns">${a.turns.map((t) => `<li class="${t.who}"><b>${esc(t.who === 'agent' ? 'Agent' : 'You')}</b> ${esc(KIND[t.kind] || t.kind || 'said')}${t.at ? ' · ' + esc(String(t.at).slice(0, 10)) : ''}${t.text ? `<span>${esc(t.text)}</span>` : ''}</li>`).join('')}</ol>` : '');
18
22
  const glyph = (src) => GLYPH[src] || '<circle cx="12" cy="12" r="4"/>';
19
23
  wireRail('work');
20
24
  const WS = new URLSearchParams(location.search).get('ws') || '';
@@ -47,7 +51,9 @@ function rowHtml(r, o = {}) {
47
51
  else lead = `<button class="wck" data-ck="${esc(r.id)}" aria-pressed="false" aria-label="Mark done: ${esc(r.title)}">${CHECK}</button>`;
48
52
  const meta = r.chip ? `<span class="wm"><span class="due${r.overdue ? ' od' : ''}">${esc(r.chip)}</span></span>` : '';
49
53
  const state = sm === 'ag' ? ' · ' + ({ ready: 'draft ready to review', failed: 'the run failed', queued: 'queued', working: 'working', sending: 'sending' }[r.agent] || '') : '';
50
- return `<div class="wrw"><div class="wrow${sm ? ' sm' : ''}${inbox ? ' inb' : ''}${o.first ? ' first' : ''}" data-key="${esc(r.key)}">${lead}<button class="wrh" aria-haspopup="dialog"${desc}><span class="wtx"><span class="wtit">${esc(r.title)}${o.first ? '<em class="tgf">Do this first</em>' : ''}${r.focus ? '<em class="xfc">Focus</em>' : ''}</span><span class="ws">${esc(r.sub)}${esc(state)}</span></span>${meta}</button></div></div>`;
54
+ const sug = !sm && r.sug ? `<span class="wsg">${ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}<span><b>${esc(r.sug.b)}</b> ${esc(r.sug.t)}</span></span>` : '';
55
+ const cta = !sm && r.cta ? `<button type="button" class="wcta" data-key="${esc(r.key)}" data-act="${r.cta.act}" aria-label="${esc(r.cta.label + ': ' + r.title)}">${esc(r.cta.label)}</button>` : '';
56
+ return `<div class="wrw"><div class="wrow${sm ? ' sm' : ''}${cta ? ' hc' : ''}${inbox ? ' inb' : ''}${o.first ? ' first' : ''}" data-key="${esc(r.key)}">${lead}<button class="wrh" aria-haspopup="dialog"${desc}><span class="wtx"><span class="wtit">${esc(r.title)}${o.first ? '<em class="tgf">Do this first</em>' : ''}${r.focus ? '<em class="xfc">Focus</em>' : ''}</span><span class="ws">${esc(r.sub)}${esc(state)}</span>${sug}</span>${meta}</button>${cta}</div></div>`;
51
57
  }
52
58
  function drawPlate() {
53
59
  const P = M.plate;
@@ -89,7 +95,17 @@ function drawReview() {
89
95
  $('#revCap').textContent = R.n + ' ' + (R.n === 1 ? 'item' : 'items');
90
96
  $('#revTxt').innerHTML = `<b>${R.n}</b> ${R.n === 1 ? 'item has' : 'items have'} sat untouched for ${R.days} days. Open one to keep it or let it go.`;
91
97
  }
92
- function draw() { drawHero(); drawFocus(); drawPlate(); drawTray(); drawAgents(); drawWaiting(); drawReview(); drawDock(); onScroll(); backFocus(); }
98
+ function drawWeek() {
99
+ const W = M.week; if (!W) return;
100
+ $('#weekCap').textContent = W.cap;
101
+ const top = Math.max(60, ...W.days.map((d) => d.meet_min));
102
+ $('#weekBody').innerHTML = `<div class="wkd" role="list">${W.days.map((d) => {
103
+ const h = d.meet_min ? Math.max(8, Math.round(d.meet_min / top * 100)) : 0;
104
+ const hrs = d.meet_min ? (Math.round(d.meet_min / 6) / 10) + ' h' : '';
105
+ return `<div class="wkc${d.today ? ' now' : ''}${d.past ? ' past' : ''}" role="listitem" aria-label="${esc(d.dow + ' ' + d.n + ': ' + (W.calendar ? (d.meet_min ? hrs + ' of meetings, ' : 'no meetings, ') : '') + d.done + ' done, ' + d.due + ' due')}"><span class="wkl">${d.dow}</span><b>${d.n}</b><span class="wkb">${h ? `<i style="height:${h}%"></i>` : ''}</span><span class="wkt">${W.calendar ? (hrs || 'free') : '·'}</span><span class="wkn">${d.done} done${d.due ? ' · ' + d.due + ' due' : ''}</span></div>`;
106
+ }).join('')}</div><p class="note" style="margin-top:12px">${esc(W.note)}</p>`;
107
+ }
108
+ function draw() { drawHero(); drawWeek(); drawFocus(); drawPlate(); drawTray(); drawAgents(); drawWaiting(); drawReview(); drawDock(); onScroll(); backFocus(); }
93
109
  const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || null;
94
110
 
95
111
  /* ── the dialog: detail first, the presses of the Work page, the tool row, the agent, the read-only agent beside it ─────────────────── */
@@ -107,7 +123,7 @@ function agentHtml(r) {
107
123
  const a = r.dialog.agent;
108
124
  if (!a) return '';
109
125
  const w = a.where || 'anyone', dr = a.draft;
110
- const draftBox = dr && dr.body ? `<div class="agdraft"><p class="agtag">Agent draft · not checked</p>${paras(dr.body)}</div>` : dr && dr.summary ? `<div class="agdraft"><p class="agtag">Agent draft · not checked</p><p>${esc(dr.summary)}</p></div>` : '';
126
+ const draftBox = dr && dr.body ? `<div class="agdraft"><p class="agtag">Agent draft · not checked</p><div class="mdr">${mdHtml(dr.body)}</div></div>${turnsHtml(a)}` : dr && dr.summary ? `<div class="agdraft"><p class="agtag">Agent draft · not checked</p><p>${esc(dr.summary)}</p></div>` : '';
111
127
  let h = '';
112
128
  if (a.state === 'suggest') {
113
129
  h = `<p class="nodef">${a.mine ? 'The agent can draft a first version of this for you. You read it here. Nothing leaves PMOS.' : `The agent can draft this for you. You read it here first. Nothing goes to ${esc(w)} until you post it.`}</p>`
@@ -428,6 +444,14 @@ $('#agl').addEventListener('click', (e) => { listClick(e); });
428
444
  $('#waitBody').addEventListener('click', (e) => { listClick(e); });
429
445
  $('#trayBody').addEventListener('click', (e) => { listClick(e); });
430
446
  async function listClick(e) {
447
+ const cta = e.target.closest('.wcta');
448
+ if (cta) {
449
+ const r = rowOf(cta.dataset.key); if (!r) return;
450
+ const o = { list: true };
451
+ refocus = null;
452
+ if (cta.dataset.act === 'open') openRow(r); else if (cta.dataset.act === 'tomorrow') deferP(r, addIso(M.today, 1), o); else todayP(r, o);
453
+ return;
454
+ }
431
455
  const ck = e.target.closest('.wck');
432
456
  if (ck && ck.dataset.open) { openRow(rowOf(ck.dataset.open)); return; }
433
457
  if (ck) {
@@ -1784,6 +1784,19 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
1784
1784
  .phstats span{font-size:var(--t-small);color:var(--ink-3)}
1785
1785
  }
1786
1786
 
1787
+ /* My work: per-row suggestion and press, and the This week card */
1788
+ .wrow.hc .wcta{grid-column:2;justify-self:start;margin-bottom:10px}
1789
+ .wcta{min-height:44px;padding:0 16px;border-radius:999px;background:var(--solid);color:var(--on-solid);font-size:13px;font-weight:650;white-space:nowrap}
1790
+ .wkd{display:grid;grid-template-columns:repeat(5,1fr);gap:8px}
1791
+ .wkc{display:flex;flex-direction:column;align-items:center;gap:4px;padding:10px 4px 8px;border-radius:18px;border:1.5px solid transparent;font-size:12px;color:var(--ink-3)}
1792
+ .wkc.now{border-color:var(--ink)}.wkc.past{opacity:.75}
1793
+ .wkl{font:500 11px var(--mono);letter-spacing:.06em}.wkc b{font-size:20px;color:var(--ink);font-weight:650}
1794
+ .wkb{display:flex;align-items:flex-end;width:26px;height:84px;border-radius:10px;background:var(--well);overflow:hidden}.wkb i{display:block;width:100%;background:var(--ink-3);border-radius:10px 10px 0 0}
1795
+ .wkt{font-weight:650;color:var(--ink-2)}.wkn{font-size:11.5px;text-align:center}
1796
+ @media (max-width:520px){.wkd{gap:4px}.wkn{font-size:11px}}
1797
+
1798
+ .agdraft .mdr{font-size:14px;line-height:1.55;overflow-x:auto}.agdraft .mdr table{border-collapse:collapse;margin:8px 0}.agdraft .mdr th,.agdraft .mdr td{border:1px solid var(--hair);padding:5px 9px;text-align:left}
1799
+ .agturns{list-style:none;margin:8px 0 0;padding:0;display:grid;gap:8px;font-size:13px;color:var(--ink-3)}.agturns li b{color:var(--ink)}.agturns span{display:block;color:var(--ink-2)}
1787
1800
  /* the meeting dialog, as the mockup draws it (briefing-artifact.html, meetCanvas): header chips, Focus and Record, Prepared for you, Material, Previous meetings, Topics */
1788
1801
  .mtg .mh2{display:flex;justify-content:space-between;align-items:flex-start;gap:14px;flex-wrap:wrap}
1789
1802
  .mtg .mh2 .d1{font-size:28px;line-height:1.2;margin:0 0 2px;font-weight:700;letter-spacing:-.02em}
@@ -1835,3 +1848,33 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
1835
1848
  .mtg .tp i{width:24px;height:24px;border-radius:50%;display:grid;place-items:center;font:600 12.5px var(--mono);font-style:normal;box-shadow:inset 0 0 0 1.8px var(--ink-3);color:var(--ink-3)}
1836
1849
  .mtg .tp small{color:var(--ink-3);font-size:12.5px}
1837
1850
  .mtg .mtg-link{margin:8px 0 6px}
1851
+
1852
+ /* the document sheet as the mockup and the console reader draw it: one status line, the file's path and front matter behind a toggle, an outline with Find, a full-width body */
1853
+ .dsm2{display:flex;flex-wrap:wrap;gap:6px 8px;align-items:center;margin:0 0 12px}
1854
+ .dsm2 .chp{padding:4px 10px;font-size:12px;gap:6px;font-weight:600}
1855
+ .dsm2 .chp b{font-weight:700;color:var(--ink)}
1856
+ .dsm2 .chp.mono{font-family:var(--mono)}
1857
+ .dsm2 .chp.lk{cursor:pointer;min-height:32px}
1858
+ .dsm2 .chp.lk:hover{background:var(--b3)}
1859
+ .dsm2 .chp.lk[aria-expanded="true"]{background:var(--solid);color:var(--on-solid)}
1860
+ .dsmeta{margin:0 0 14px;padding:12px 14px;border-radius:14px;background:var(--well)}
1861
+ .dsmeta .dpath{margin:0 0 8px}
1862
+ .dsmeta .kv2{margin:0}
1863
+ .dsrd.no{grid-template-columns:minmax(0,1fr)}
1864
+ .dsvb.ol{margin-left:auto;font-weight:600}
1865
+ .dsfind{width:100%;min-height:36px;margin:0 0 8px;padding:0 10px;border-radius:10px;border:1px solid var(--hair);background:var(--well);font:inherit;font-size:12.5px;color:inherit}
1866
+ .dso{max-height:62vh;overflow:auto}
1867
+ .dso .l2{padding-left:20px}
1868
+ .dso .l3{padding-left:30px;color:var(--ink-3)}
1869
+ .dsbody .mdt{overflow-x:auto;margin:0 0 14px;border-radius:12px;box-shadow:inset 0 0 0 1px var(--hair)}
1870
+ .dsbody table{border-collapse:collapse;width:100%;font-size:13.5px}
1871
+ .dsbody th{font:600 11px var(--mono);letter-spacing:.06em;text-transform:uppercase;color:var(--ink-3);text-align:left;padding:8px 12px;background:var(--well)}
1872
+ .dsbody td{padding:8px 12px;border-top:1px solid var(--hair);vertical-align:top;line-height:1.5}
1873
+ .dsbody code{font:12.5px var(--mono);padding:1px 5px;border-radius:6px;background:var(--well)}
1874
+ .dsbody a{color:var(--ember-ink);text-decoration:underline;text-underline-offset:2px}
1875
+ .dsbody ol{margin:0 0 10px;padding-left:22px;font-size:15px;line-height:1.6}
1876
+ #dsOlItems{display:grid;gap:2px}
1877
+ .dso button{display:block;width:100%}
1878
+ @media (max-width:700px){#dsOlItems{display:flex;flex-wrap:wrap;gap:6px}.dso button{display:inline-flex;width:auto}.dso .l2,.dso .l3{padding-left:10px}.dso{max-height:none}}
1879
+ .dsbody .dsat{display:flex;align-items:center;gap:6px;margin:-2px 0 8px;font-size:12px;color:var(--ink-3)}
1880
+ .dsbody .dsat i{width:18px;height:18px;border-radius:50%;background:var(--well);display:grid;place-items:center;font:600 10px var(--mono);font-style:normal;color:var(--ink-2)}
@@ -145,6 +145,7 @@ function cardHtml(r) {
145
145
  return `${head}${opts}${err}${ask ? `<p class="nodef">Start this agent session? It drafts “${esc(w.what)}” for you to read and sends nothing outside PMOS.</p><div class="cact" id="cardAct"><button class="cta" id="startGo" data-start="go">${CHECK}<span>Start the session</span></button><button class="cta alt" data-start="no">Not now</button></div>` : `<div class="cact" id="cardAct"><button class="cta" id="startBtn" data-start="ask">${CHECK}<span>${esc(d.prim[d.sel])}</span></button></div>${d.hold ? holdNote(d.hold) : ''}`}</div>`;
146
146
  }
147
147
  if (d.opts.length) return `${head}${opts}${d.nodef ? `<p class="nodef">${esc(d.nodef)}</p>` : ''}<div class="cact" id="cardAct"><button class="cta" disabled title="${esc(d.hold || 'Nothing here can be recorded yet.')}">${o ? esc(d.prim[o.k]) : 'Your call: choose one'}</button></div>${d.hold ? holdNote(d.hold) : ''}</div>`;
148
+ if (d.proposals) return `${head}<div class="cact"><button class="cta" id="openProps" type="button">Review the drafts</button></div><p class="nodef">Keep, send back and Drop are under Around you, Agent proposals. Nothing here changes a record.</p></div>`;
148
149
  if (d.link) return `${head}<div class="cact"><a class="cta" id="srcLink" href="${esc(d.link)}" target="_blank" rel="noopener noreferrer">${esc(d.linkLabel || 'Open the source')}</a></div></div>`;
149
150
  return `${head}${d.nodef ? `<p class="nodef">${esc(d.nodef)}</p>` : ''}${d.action ? `<div class="cact"><button class="cta" disabled title="${esc(d.hold || 'Nothing here can be recorded.')}">${CHECK}${esc(d.action)}</button></div>${d.hold ? holdNote(d.hold) : ''}` : ''}</div>`;
150
151
  }
@@ -189,6 +190,7 @@ $('#dBody').addEventListener('click', (e) => {
189
190
  const lt = e.target.closest('#logT');
190
191
  if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); return; }
191
192
  if (!openR) return;
193
+ if (e.target.closest('#openProps')) { closeDlg(); openPropsDlg(); return; }
192
194
  const op = e.target.closest('[data-op]');
193
195
  if (op) { WHY[openR.key] = ($('#why') || {}).value || ''; SEL[openR.key] = op.dataset.op; $('#card').outerHTML = cardHtml(openR); $('#oMain').innerHTML = paneHtml(openR); ctaState(openR); return; }
194
196
  const st = e.target.closest('[data-start]');
@@ -58,6 +58,10 @@
58
58
  </section>
59
59
  </div>
60
60
  <div>
61
+ <section class="card rise" style="--d:6" id="weekCard" aria-labelledby="hWeek">
62
+ <div class="ch"><span class="ic"><svg class="i" viewBox="0 0 24 24"><rect x="4" y="5" width="16" height="15" rx="3"/><path d="M4 10h16M9 3v4M15 3v4"/></svg></span><h2 id="hWeek">This week</h2><small id="weekCap"></small></div>
63
+ <div id="weekBody"></div>
64
+ </section>
61
65
  <section class="card rise" style="--d:7" id="agCard" aria-labelledby="hAg">
62
66
  <div class="ch"><span class="ic"><svg class="i" viewBox="0 0 24 24"><path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/></svg></span><h2 id="hAg">With agents</h2><small id="agCap"></small></div>
63
67
  <div class="pipe" id="pipe"></div>
@@ -50,6 +50,7 @@
50
50
  "briefing-premium-calendar-3.test.js",
51
51
  "briefing-premium-products.test.js",
52
52
  "briefing-premium-sources.test.js",
53
+ "briefing-premium-drafts.test.js",
53
54
  "briefing-premium-metrics.test.js",
54
55
  "premium-welcome.test.js",
55
56
  "calendar-events.test.js",
@@ -220,6 +221,7 @@
220
221
  "briefing-premium-calendar-3.test.js": 1,
221
222
  "briefing-premium-products.test.js": 1,
222
223
  "briefing-premium-sources.test.js": 1,
224
+ "briefing-premium-drafts.test.js": 1,
223
225
  "briefing-premium-metrics.test.js": 1,
224
226
  "premium-welcome.test.js": 1,
225
227
  "calendar-events.test.js": 1,