create-pmos 0.661.0 → 0.663.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.
@@ -1,16 +1,23 @@
1
- /* pm/cozy-routine.js — Routine, the place (initiative routine-place, slice 8 of the six-place navigation; board 11 on Exploring 2; build plan
2
- * /mnt/project-files/nav-structure/build-plan.md; done test planning/done-tests/routine-place.md).
1
+ /* pm/cozy-routine.js — Routine, the place (initiative routine-place, slice 8 of the six-place navigation; rebuilt from the design system's
2
+ * blocks by initiative routine-ds-page, board RoutineDS on Exploring 3 page "pages"; done tests planning/done-tests/routine-place.md and
3
+ * planning/done-tests/routine-ds-page.md).
3
4
  *
4
- * One table of everything that repeats: Routine, Type, Product (two products or more), What it does, When, Next, and the same switch on every row. Groups: Waits for you,
5
- * Reports, PMOS reads, PMOS jobs, Your tasks (pm/cozy-routine-model.js). The kinds above it filter the table; PMOS remembers the choice on this
6
- * computer. "PMOS did" is one line on top; a press opens the full log in the popup, each line with its Undo. + opens Ask PMOS about a new
7
- * routine. A row opens the one popup (pm/cozy-routine-pop.js). It replaces the Scheduled work list of Settings › Connectors, which now goes here.
5
+ * Main + open item (Komorebi MainItem). The top line is the path, the product chip (the shared scope chip of Events), then + as an icon
6
+ * button: it asks PMOS for a new routine. "PMOS did" is one line on top (a pm-block flat); a press opens the full log in the popup, each line
7
+ * with its Undo. Then one Table block: the kinds as Tabs in its head (All, Reports, Reads, Jobs, Your tasks with counts; PMOS remembers the
8
+ * choice on this computer), and one pm-table of everything that repeats: Routine, Product (two products or more), What it does, When, Next,
9
+ * and the same switch on every row. Group rows (pm-group) say the type, so there is no Type column: Waits for you, Reports, PMOS reads,
10
+ * PMOS jobs, Your tasks (pm/cozy-routine-model.js). A proposed routine waits in Waits for you with its switch off.
11
+ * On a desk a row opens the Detail at the right (pm/cozy-routine-detail.js); a second press, Enter on the open row, or Open in full opens the
12
+ * one popup (pm/cozy-routine-pop.js for a report, pm/cozy-routine-job.js for the rest), where every value edits. Esc closes the Detail; j and
13
+ * k move to the next and the previous routine. A phone opens the popup at once. It replaces the Scheduled work list of Settings › Connectors.
8
14
  *
9
15
  * READS GET /api/workspaces, then per product GET /api/report-setups/routine?ws and GET /api/autonomy?ws; once GET /api/refresh and
10
16
  * GET /api/schedules?all=1. Every product is read: Routine has no product choice (slice 1).
11
17
  * WRITES, each the PM's press: a report's switch → POST /api/report-setups/pause | resume; a read or a job → POST /api/refresh/source { id, on };
12
- * your task → POST /api/schedules/update { id, enabled }; the switch of a proposed report (Waits for you) → /api/report-setups/confirm; Undo in the log →
13
- * POST /api/autonomy/undo. Nothing here runs a routine or sends anything. */
18
+ * your task → POST /api/schedules/update { id, enabled }; the switch of a proposed report (Waits for you), or Yes on its Suggestion →
19
+ * /api/report-setups/confirm | move; No on it → /api/report-setups/drop after its Undo; Yes on "run it again" → /api/refresh/run,
20
+ * /api/scan/now or /api/schedules/run; Undo in the log → POST /api/autonomy/undo. Nothing here sends anything outside. */
14
21
  import { pmGet, pmPost } from './http.js';
15
22
  import { mountNav } from './cozy-nav.js';
16
23
  import { mountLivePill } from './cozy-live-pill.js';
@@ -22,6 +29,7 @@ import { scopeChipHtml, openScope, scopeWords, whenNames, displayName, productNa
22
29
  import { atOf } from './cozy-evmodel.js';
23
30
  import { openReport } from './cozy-routine-pop.js';
24
31
  import { openJob, openNew } from './cozy-routine-job.js'; // reads, jobs, services and your tasks: manage them in the popup (round 3 item 3)
32
+ import { detailHtml } from './cozy-routine-detail.js'; // the Detail at the right (routine-ds-page)
25
33
 
26
34
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
27
35
  const svg = (d, n = 18) => `<svg class="pm-ic" viewBox="0 0 24 24" width="${n}" height="${n}" aria-hidden="true"><path d="${d}"/></svg>`;
@@ -32,7 +40,8 @@ const I = {
32
40
  };
33
41
  const KIND_KEY = 'pmos.routine.kind';
34
42
  const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* a private window */ } } };
35
- const S = { ws: [], reports: [], refresh: [], tasks: [], done: [], kind: KINDS.some(([k]) => k === store.get(KIND_KEY)) ? store.get(KIND_KEY) : 'all', rows: [], busy: new Set(), gone: new Set(), read: false, err: '', pick: null, all: false, openG: new Set() };
43
+ const S = { ws: [], reports: [], refresh: [], tasks: [], done: [], kind: KINDS.some(([k]) => k === store.get(KIND_KEY)) ? store.get(KIND_KEY) : 'all', rows: [], busy: new Set(), gone: new Set(), read: false, err: '', pick: null, all: false, openG: new Set(), open: null, msg: '' };
44
+ const NOFAIL = 'pmos.routine.nofail.'; // No on "run it again": hidden for those runs on this computer
36
45
  const $ = (id) => document.getElementById(id);
37
46
  /** A short line at the bottom. With `undo`, it carries an Undo button and stays 10 s, the time the undo has. */
38
47
  const toast = (t, undo) => {
@@ -92,8 +101,8 @@ async function load() {
92
101
  }
93
102
 
94
103
  function kindsHtml(n) {
95
- // each kind says how many it holds (round 2); All needs no number, and a kind with none says none (zero is silence)
96
- return KINDS.map(([k, l]) => `<button type="button" class="pm-tab" data-kind="${k}" aria-pressed="${S.kind === k}"${k !== 'all' && n ? ` aria-label="${esc(l + ', ' + (n[k] || 0))}"` : ''}>${esc(l)}${k !== 'all' && n && n[k] ? `<span class="rt-n">${n[k]}</span>` : ''}</button>`).join('');
104
+ // the Tabs part: each kind says how many it holds (round 2); a kind with none says none (zero is silence)
105
+ return `<div class="pm-tabs" role="tablist" aria-label="Show">${KINDS.map(([k, l]) => `<button type="button" class="pm-tab" role="tab" data-kind="${k}" aria-selected="${S.kind === k}"${n ? ` aria-label="${esc(l + ', ' + (n[k] || 0))}"` : ''}>${esc(l)}${n && n[k] ? ` <span class="rt-n">${n[k]}</span>` : ''}</button>`).join('')}</div>`;
97
106
  }
98
107
  /* ── the chip (round 2, PR 3): the shared scope chip of Events (pm/scope-chip.js). Products is the saved pick of Work; Programs and Projects
99
108
  * are this page's own (kept on this computer). A report is under a program or a project when its setup says so (lib/routine-reports.js
@@ -155,21 +164,24 @@ function drawPick(groups) {
155
164
  whenNames().then(() => draw()); // product display names (IDPF, not a folder name) arrive after the first draw
156
165
  addEventListener('pp:changed', (e) => { if (e.detail && e.detail.ok) { S.pick = e.detail; S.all = false; draw(); } });
157
166
  /** The fold line at the end of Reports: one-time reports and loose drafts, opened as plain rows. */
158
- const foldHtml = (f) => `<div class="rt-r rt-fold" role="row"><button type="button" class="pm-fold" role="cell" data-once aria-expanded="${!!S.once}">${svg(I.chev, 14)}<span>${esc(f.words)}</span></button></div>`;
167
+ const foldHtml = (f, cols) => `<tr class="rt-fold"><td colspan="${cols}"><button type="button" class="pm-fold" data-once aria-expanded="${!!S.once}">${svg(I.chev, 14)}<span>${esc(f.words)}</span></button></td></tr>`;
159
168
  /** The Product cell: the product, or the first and +N when one report is in several. Empty for what serves every product. */
160
169
  const prodWords = (r) => (r.wss && r.wss.length ? r.wss[0] + (r.wss.length > 1 ? ' +' + (r.wss.length - 1) : '') : '');
161
170
  function rowHtml(r, multi) {
162
171
  const busy = S.busy.has(r.key);
163
172
  // round 3 item 1: the same switch on every row. A proposed routine's switch is off, and turning it on is the yes.
164
173
  const label = r.proposed ? r.name + ': proposed by PMOS. Press to start it' : r.name + (r.on ? ': on. Press to pause it' : ': paused. Press to start it again');
165
- const end = r.on === null ? '<span></span>'
166
- : `<button type="button" class="rt-sw pm-switch" role="switch" aria-checked="${r.on}" data-sw="${esc(r.key)}" aria-label="${esc(label)}" title="${r.proposed ? 'Proposed. Turn on to start it' : r.on ? 'On' : 'Paused'}"${busy ? ' disabled' : ''}></button>`;
167
- const next = r.late || (r.group === 'once' && r.draft) ? `<span class="w pm-badge alert">${esc(r.next)}</span>` : esc(r.next);
168
- return `<div class="rt-r rt-row${r.off ? ' off' : ''}" role="row" tabindex="0" data-key="${esc(r.key)}" aria-label="${esc('Open ' + r.name)}">`
169
- + `<span class="ic" role="cell">${svg(I[r.kind], 17)}</span><span class="n" role="cell" title="${esc(r.name)}">${esc(r.name)}</span>`
170
- + `<span class="c type" role="cell">${esc(r.type || '')}</span>${multi ? `<span class="c prod" role="cell" title="${esc((r.wss || []).join(', '))}">${esc(prodWords(r))}</span>` : ''}`
171
- + `<span class="c does" role="cell" title="${esc(r.does)}">${esc(r.does)}</span><span class="c when" role="cell" title="${esc(r.when)}">${esc(r.when)}</span>`
172
- + `<span class="c" role="cell">${next}</span><span role="cell" class="e">${end}</span>${r.proposed && r.kind === 'reports' ? `<span class="go" role="cell"><button type="button" class="rt-drop pm-btn" data-drop="${esc(r.key)}" aria-label="${esc('Drop ' + r.name + '. PMOS stops proposing it')}" title="Drop this proposal">${svg(I.x, 14)}</button></span>` : `<span class="go" aria-hidden="true">${svg(I.chev, 14)}</span>`}</div>`;
174
+ const end = r.on === null ? ''
175
+ : `<button type="button" class="pm-switch" role="switch" aria-checked="${r.on}" data-sw="${esc(r.key)}" aria-label="${esc(label)}" title="${r.proposed ? 'Proposed. Turn on to start it' : r.on ? 'On' : 'Paused'}"${busy ? ' disabled' : ''}></button>`;
176
+ // ✕ on a proposed report: PMOS stops proposing it, with Undo (shown on hover, beside the switch)
177
+ const drop = r.proposed && r.kind === 'reports' ? `<button type="button" class="pm-btn rt-drop" data-drop="${esc(r.key)}" aria-label="${esc('Drop ' + r.name + '. PMOS stops proposing it')}" title="Drop this proposal">${svg(I.x, 14)}</button>` : '';
178
+ // a proposal has no Next (its group says it waits); a stuck or missed one, or a draft that waits, is the alert Badge
179
+ const next = r.proposed ? '' : r.late || (r.group === 'once' && r.draft) ? `<span class="pm-badge alert">${esc(r.next)}</span>` : `<span class="pm-meta rt-next">${esc(r.next)}</span>`;
180
+ const star = r.proposed ? `<b class="pm-star" aria-hidden="true">✦</b> ` : '';
181
+ return `<tr class="rt-row${r.off && !r.proposed ? ' off' : ''}${S.open === r.key ? ' sel' : ''}" tabindex="0" data-key="${esc(r.key)}" aria-label="${esc('Open ' + r.name)}"${S.open === r.key ? ' aria-current="true"' : ''}>`
182
+ + `<td class="rt-name">${star}<b title="${esc(r.name)}">${esc(r.name)}</b></td>${multi ? `<td class="rt-prod" title="${esc((r.wss || []).join(', '))}">${esc(prodWords(r))}</td>` : ''}`
183
+ + `<td class="rt-does" title="${esc(r.does)}">${esc(r.does)}</td><td class="rt-when"><span class="pm-meta">${esc(r.when)}</span></td>`
184
+ + `<td class="rt-nx">${next}</td><td class="rt-on"><span class="pm-row">${drop}${end}</span></td></tr>`;
173
185
  }
174
186
  function draw() {
175
187
  const on = onSet();
@@ -180,10 +192,11 @@ function draw() {
180
192
  const known = new Set([...groups.programs, ...groups.projects].map((g) => g.id));
181
193
  if (S.read) S.sel = { programs: S.sel.programs.filter((t) => known.has(t)), projects: S.sel.projects.filter((t) => known.has(t)) };
182
194
  const mine = S.read ? tag(routineRows({ reports: S.reports.filter(inPick(on)), refresh: S.refresh, jobs: S.jobs, tasks: S.tasks.filter(inPick(on)), spaces: S.ws.flatMap((x) => [x.id, x.name]) })).filter(inScope) : [];
183
- $('rtKinds').innerHTML = kindsHtml(S.read ? kindCounts(mine.filter((r) => r.group !== 'once' && (!r.unclear || S.unclear))) : null); // the routines, not the one-time reports
195
+ const counts = S.read ? kindCounts(mine.filter((r) => r.group !== 'once' && (!r.unclear || S.unclear))) : null; // the routines, not the one-time reports
184
196
  drawPick(groups);
185
197
  const D = didLine(S.done);
186
- $('rtDid').innerHTML = D ? `<button type="button" class="rt-did pm-sug" data-did aria-label="${esc(D.text + ' Open the full log')}"><b class="pm-star" aria-hidden="true">✦</b><span class="say">${esc(D.text)} <em>${esc(D.sub)}</em></span>${svg(I.chev, 14)}</button>` : '';
198
+ // PMOS did: one flat block, PMOS speaking; the chevron opens the full log with Undo on each line
199
+ $('rtDid').innerHTML = D ? `<section class="pm-block flat rt-did" aria-label="PMOS did" data-did><b class="pm-star" aria-hidden="true">✦</b><span class="rt-say">${esc(D.text)} <span class="pm-meta">${esc(D.sub)}</span></span><button type="button" class="pm-btn" data-did aria-label="${esc('See what PMOS did. ' + D.text)}" title="See what PMOS did">${svg(I.chev, 16)}</button></section>` : '';
187
200
  if (!S.read) return;
188
201
  S.rows = mine.filter((r) => !S.gone.has(r.key)); // a deleted task leaves at once; its delete is sent when the Undo has passed
189
202
  // rows a PM cannot read are held back, counted in one grey line (round 3 item 2); one-time reports fold under Reports (item 1)
@@ -204,20 +217,25 @@ function draw() {
204
217
  // with a program or project picked, PMOS reads and PMOS jobs fold to their heading: they serve every product, so the picked
205
218
  // work's own reports come first (design note on #1384). Pressing the heading opens the rows.
206
219
  const shut = (g) => extraOn() && (g.id === 'reads' || g.id === 'jobs') && !S.openG.has(g.id) && g.rows.length > 0;
220
+ const cols = multi ? 6 : 5;
221
+ const gwords = { wait: 'PMOS proposes it; turn it on to start' };
222
+ const gline = (g) => `<b>${esc(g.title)}</b> <span class="pm-meta">${g.rows.filter((r) => !r.fold).length}${gwords[g.id] ? ' · ' + gwords[g.id] : ''}</span>`;
207
223
  const head = (g) => shut(g) || (extraOn() && S.openG.has(g.id))
208
- ? `<div class="rt-r rt-g pm-group" role="row"><div role="rowheader"><button type="button" class="rt-gf" data-gfold="${esc(g.id)}" aria-expanded="${!shut(g)}" aria-label="${esc((shut(g) ? "Show " : "Fold ") + g.title)}">${svg(I.chev, 14)}<span>${esc(g.title)}</span>${shut(g) ? `<em>${g.rows.length}</em>` : ''}</button></div></div>`
209
- : `<div class="rt-r rt-g pm-group" role="row"><div role="rowheader">${esc(g.title)}</div></div>`;
210
- const unLine = unclear.length ? `<p class="rt-hid">${unclear.length === 1 ? 'One row is' : unclear.length + ' rows are'} hidden because their source is unclear. <button type="button" data-unclear>Show</button></p>` : '';
224
+ ? `<tr class="rt-g"><th colspan="${cols}" scope="rowgroup" class="pm-group"><button type="button" class="rt-gf" data-gfold="${esc(g.id)}" aria-expanded="${!shut(g)}" aria-label="${esc((shut(g) ? 'Show ' : 'Fold ') + g.title)}">${svg(I.chev, 14)}${gline(g)}</button></th></tr>`
225
+ : `<tr class="rt-g"><th colspan="${cols}" scope="rowgroup" class="pm-group">${gline(g)}</th></tr>`;
226
+ const unLine = unclear.length ? `<p class="rt-hid pm-meta">${unclear.length === 1 ? 'One row is' : unclear.length + ' rows are'} hidden because their source is unclear. <button type="button" class="pm-chip" data-unclear>Show</button></p>` : '';
211
227
  const only = extraOn() ? scopeWords(on ? S.pick : null, S.sel, groups) : '';
212
- const hidLine = unLine + (hid ? `<p class="rt-hid">${only ? esc('Showing ' + only + ' only. ') + (hid === 1 ? 'One routine is' : hid + ' routines are') : hid === 1 ? 'One routine of another product is' : hid + ' routines of other products are'} not shown. <button type="button" data-showall>Show all</button></p>` : '');
213
- const f = document.activeElement && document.activeElement.closest && document.activeElement.closest('[data-key],[data-sw],[data-yes]');
214
- const fk = f ? (f.dataset.key || f.dataset.sw || f.dataset.yes) + (f.dataset.sw ? ':sw' : f.dataset.yes ? ':yes' : '') : '';
215
- $('rtTable').innerHTML = hidLine + (S.err ? `<p class="rt-quiet">${esc(S.err)}</p>`
216
- : !G.length ? `<p class="rt-quiet">${S.kind === 'all' ? 'Nothing repeats yet. Tell PMOS what to do on a schedule with +.' : 'Nothing of this kind repeats.'}</p>`
217
- : `<div class="rt-tbl${multi ? ' multi' : ''} pm-block list" role="table" aria-label="Routine"><div class="rt-r rt-h" role="row"><span role="columnheader"><span class="vh">Kind</span></span><span role="columnheader">Routine</span><span role="columnheader" class="type">Type</span>${multi ? '<span role="columnheader" class="prod">Product</span>' : ''}<span role="columnheader" class="does">What it does</span><span role="columnheader" class="when">When</span><span role="columnheader">Next</span><span role="columnheader"><span class="vh">On</span></span></div>`
218
- + G.map((g) => head(g) + (shut(g) ? '' : g.rows.map((r) => (r.fold ? foldHtml(r) : rowHtml(r, multi))).join(''))).join('') + '</div>'
219
- + '<p class="rt-note pm-meta">Everything that repeats, in one table. Press a row to open it. The switch pauses it.</p>');
220
- if (fk) { const [k, x] = [fk.replace(/:(sw|yes)$/, ''), (/:(sw|yes)$/.exec(fk) || [])[1]]; const el = $('rtTable').querySelector(x === 'sw' ? `[data-sw="${CSS.escape(k)}"]` : x === 'yes' ? `[data-yes="${CSS.escape(k)}"]` : `[data-key="${CSS.escape(k)}"]`); if (el) el.focus(); }
228
+ const hidLine = unLine + (hid ? `<p class="rt-hid pm-meta">${only ? esc('Showing ' + only + ' only. ') + (hid === 1 ? 'One routine is' : hid + ' routines are') : hid === 1 ? 'One routine of another product is' : hid + ' routines of other products are'} not shown. <button type="button" class="pm-chip" data-showall>Show all</button></p>` : '');
229
+ const f = document.activeElement && document.activeElement.closest && document.activeElement.closest('[data-key],[data-sw],[data-yes],[data-kind]');
230
+ const fk = f ? (f.dataset.kind ? 'kind:' + f.dataset.kind + ':kind' : (f.dataset.key || f.dataset.sw || f.dataset.yes) + (f.dataset.sw ? ':sw' : f.dataset.yes ? ':yes' : '')) : '';
231
+ const tabs = kindsHtml(counts);
232
+ // the Table block: the Tabs in its head, then one pm-table; the group rows say the type
233
+ $('rtTable').innerHTML = `<section class="pm-block rt-tbl" aria-label="Everything that repeats"><div class="head">${tabs}</div>` + hidLine + (S.err ? `<p class="rt-quiet pm-meta">${esc(S.err)}</p>`
234
+ : !G.length ? `<p class="rt-quiet pm-meta">${S.kind === 'all' ? 'Nothing repeats yet. Tell PMOS what to do on a schedule with +.' : 'Nothing of this kind repeats.'}</p>`
235
+ : `<table class="pm-table" aria-label="Routine"><thead><tr><th scope="col">Routine</th>${multi ? '<th scope="col" class="rt-prod">Product</th>' : ''}<th scope="col" class="rt-does">What it does</th><th scope="col" class="rt-when">When</th><th scope="col">Next</th><th scope="col" class="rt-on">On</th></tr></thead>`
236
+ + G.map((g) => `<tbody>${head(g)}${shut(g) ? '' : g.rows.map((r) => (r.fold ? foldHtml(r, cols) : rowHtml(r, multi))).join('')}</tbody>`).join('') + '</table>') + '</section>';
237
+ drawDetail();
238
+ if (fk) { const [k, x] = [fk.replace(/:(sw|yes|kind)$/, ''), (/:(sw|yes|kind)$/.exec(fk) || [])[1]]; const el = $('rtTable').querySelector(x === 'kind' ? `[data-kind="${CSS.escape(k.slice(5))}"]` : x === 'sw' ? `[data-sw="${CSS.escape(k)}"]` : x === 'yes' ? `[data-yes="${CSS.escape(k)}"]` : `[data-key="${CSS.escape(k)}"]`); if (el) el.focus(); }
221
239
  }
222
240
 
223
241
  const rowOf = (k) => S.rows.find((r) => r.key === k);
@@ -226,7 +244,7 @@ const said = (x, ok) => (x && x.ok !== false && !(x && x.error) ? ok : 'Nothing
226
244
  async function press(key, fn) {
227
245
  if (S.busy.has(key)) return;
228
246
  S.busy.add(key); draw();
229
- try { say(await fn()); } finally { S.busy.delete(key); }
247
+ try { const m = await fn(); say(m); if (S.open === key) S.msg = m; } finally { S.busy.delete(key); }
230
248
  await load();
231
249
  }
232
250
  function flip(r) {
@@ -294,6 +312,70 @@ function open(r) {
294
312
  openJob(r, H);
295
313
  }
296
314
 
315
+ /* ── the Detail at the right (Main + open item; pm/cozy-routine-detail.js draws it) ── */
316
+ const desk = () => typeof innerWidth !== 'number' || innerWidth > 760;
317
+ const hidden = () => { const h = new Set(); try { for (let i = 0; i < localStorage.length; i++) { const k = localStorage.key(i); if (k && k.startsWith(NOFAIL)) h.add(k.slice(NOFAIL.length)); } } catch { /* a private window */ } return h; };
318
+ function detailOf(r) {
319
+ if (r.kind === 'reports') return { row: r, rep: reportOf(r) || null, hide: hidden(), busy: S.busy.has(r.key), msg: S.msg };
320
+ const g = rawOf(r);
321
+ return { row: r, job: { raw: g.raw || {}, tools: g.tools || null, own: g.own || null, svc: r.svc || null, extra: g.extra || null }, hide: hidden(), busy: S.busy.has(r.key), msg: S.msg };
322
+ }
323
+ function drawDetail() {
324
+ const host = $('rtDetail'), page = $('stage'); if (!host) return;
325
+ const r = S.open && desk() ? rowOf(S.open) : null;
326
+ if (S.open && !r && S.read) S.open = null; // the open routine left the table (a filter, a drop): the Detail closes
327
+ const had = host.querySelector('.rt-detail'), keep = had && had.dataset.key === (r && r.key);
328
+ host.innerHTML = r ? detailHtml(detailOf(r)) : '';
329
+ const sec = host.querySelector('.rt-detail'); if (sec) { sec.dataset.key = r.key; if (keep) sec.classList.remove('pm-motion-enter'); }
330
+ if (page) page.classList.toggle('rt-open', !!r);
331
+ }
332
+ /** Show a routine in the Detail (a desk), or open it in full (a phone, or a second press on the open one). */
333
+ function show(r) {
334
+ if (!desk() || S.open === r.key) { open(r); return; }
335
+ S.open = r.key; S.msg = ''; draw();
336
+ const d = $('rtDetail').querySelector('.rt-detail h2'); if (d) d.setAttribute('tabindex', '-1');
337
+ }
338
+ function closeDetail() {
339
+ const k = S.open; if (!k) return;
340
+ S.open = null; S.msg = ''; draw();
341
+ const row = $('rtTable').querySelector(`[data-key="${CSS.escape(k)}"]`); if (row) row.focus(); // back to the list, the row still there
342
+ }
343
+ /** j and k: the next and the previous routine in the table, as it shows. */
344
+ function step(n) {
345
+ const keys = [...$('rtTable').querySelectorAll('tr[data-key]')].map((x) => x.dataset.key), i = keys.indexOf(S.open);
346
+ const k = keys[i < 0 ? 0 : Math.max(0, Math.min(keys.length - 1, i + n))]; if (!k || k === S.open) return;
347
+ S.open = k; S.msg = ''; draw();
348
+ const row = $('rtTable').querySelector(`[data-key="${CSS.escape(k)}"]`); if (row) row.focus();
349
+ }
350
+ /** Yes on "run it again": the same routes as ▶ in the popup (pm/cozy-routine-job.js run). */
351
+ function runNow(r) {
352
+ return press(r.key, async () => {
353
+ const ws = S.home || undefined;
354
+ if (r.kind === 'tasks') return said(await pmPost('/api/schedules/run', { id: r.id }), 'Started. ' + r.name + ' runs now.');
355
+ if (r.id === 'scan') return said(await pmPost('/api/scan/now', { ws }), 'Started. PMOS scans now.');
356
+ if (r.svc) return said(await pmPost('/api/refresh/run', { id: r.parent, svcs: [r.svc], ws }), 'Started. PMOS reads ' + r.name + ' now.');
357
+ return said(await pmPost('/api/refresh/run', { id: r.id, ws }), 'Started. ' + r.name + ' runs now.');
358
+ });
359
+ }
360
+ async function detailPress(t) {
361
+ const r = rowOf(S.open); if (!r) return;
362
+ const k = t.dataset.rd;
363
+ if (k === 'close') { closeDetail(); return; }
364
+ if (k === 'full') { open(r); return; }
365
+ if (k === 'chat') { const PC = await import('./page-chat.js'); PC.openChat({ id: 'routine-' + r.key, kind: 'routine', title: r.name }, { ws: r.ws || S.home }); return; }
366
+ if (k === 'issue' && t.dataset.path) { const M = await import('./premium-report-read.js'); VW.drill(); M.openReportView(t.dataset.path, { ws: r.ws || undefined, name: r.name }); }
367
+ }
368
+ function sugPress(t) {
369
+ const r = rowOf(t.dataset.key); if (!r) return;
370
+ const a = t.dataset.rsug, pat = t.dataset.pat;
371
+ if (a === 'edit') { open(r); return; } // Change it first: the full popup, where every value edits and the chat is about it
372
+ if (pat === 'wait') { if (a === 'yes') yes(r); else drop(r); return; }
373
+ if (pat === 'fail') {
374
+ if (a === 'yes') { runNow(r); return; }
375
+ store.set(NOFAIL + t.dataset.sig, '1'); draw();
376
+ }
377
+ }
378
+
297
379
  /* PMOS did, the full log: newest first, each with what it did, why, when, and Undo (POST /api/autonomy/undo) */
298
380
  const logHtml = () => `<div class="rt-log" role="list">${S.done.map((d) => `<div class="l" role="listitem"><span><b>${esc(d.title || 'Done')}</b><em>${esc([d.reason, atOf(d.at)].filter(Boolean).join(' · '))}</em></span>`
299
381
  + `<button type="button" data-undo="${esc(d.ref)}" data-ws="${esc(d.ws)}" aria-label="${esc('Undo: ' + (d.title || 'this'))}" title="Undo">${svg(I.undo, 16)}</button></div>`).join('') || '<p class="rt-quiet">Nothing in the last 14 days.</p>'}</div>`;
@@ -315,6 +397,8 @@ document.addEventListener('click', (e) => {
315
397
  const k = e.target.closest('[data-kind]');
316
398
  if (k) { S.kind = k.dataset.kind; store.set(KIND_KEY, S.kind); draw(); return; }
317
399
  if (e.target.closest('[data-did]')) { openLog(); return; }
400
+ const rd = e.target.closest('[data-rd]'); if (rd) { detailPress(rd); return; }
401
+ const rs = e.target.closest('[data-rsug]'); if (rs) { if (!rs.disabled) sugPress(rs); return; }
318
402
  if (e.target.closest('[data-showall]')) { S.all = true; draw(); return; }
319
403
  if (e.target.closest('[data-unclear]')) { S.unclear = true; draw(); return; }
320
404
  if (e.target.closest('[data-once]')) { S.once = !S.once; draw(); return; }
@@ -325,13 +409,18 @@ document.addEventListener('click', (e) => {
325
409
  const d = e.target.closest('[data-drop]'); if (d) { const r = rowOf(d.dataset.drop); if (r) drop(r); return; }
326
410
  const s = e.target.closest('[data-sw]'); if (s) { const r = rowOf(s.dataset.sw); if (r && !s.disabled) flip(r); return; }
327
411
  const y = e.target.closest('[data-yes]'); if (y) { const r = rowOf(y.dataset.yes); if (r && !y.disabled) yes(r); return; }
328
- const row = e.target.closest('[data-key]'); if (row && $('rtTable').contains(row)) { const r = rowOf(row.dataset.key); if (r) open(r); }
412
+ const row = e.target.closest('tr[data-key]'); if (row && $('rtTable').contains(row)) { const r = rowOf(row.dataset.key); if (r) show(r); }
329
413
  });
330
414
  document.addEventListener('keydown', (e) => {
415
+ const typing = e.target && e.target.closest && e.target.closest('input, textarea, select, [contenteditable="true"]');
416
+ if (S.open && !POP.isOpen() && !typing && !e.metaKey && !e.ctrlKey && !e.altKey) {
417
+ if (e.key === 'Escape') { e.preventDefault(); closeDetail(); return; }
418
+ if (e.key === 'j' || e.key === 'k') { e.preventDefault(); step(e.key === 'j' ? 1 : -1); return; }
419
+ }
331
420
  if (e.key !== 'Enter' && e.key !== ' ') return;
332
- const row = e.target.closest && e.target.closest('[data-key]');
421
+ const row = e.target.closest && e.target.closest('tr[data-key]');
333
422
  if (!row || e.target !== row) return;
334
- e.preventDefault(); const r = rowOf(row.dataset.key); if (r) open(r);
423
+ e.preventDefault(); const r = rowOf(row.dataset.key); if (r) show(r);
335
424
  });
336
425
  document.addEventListener('visibilitychange', () => { if (!document.hidden) load(); });
337
426
  document.addEventListener('cz:chat-turn', () => load()); // PMOS changed something from the chat: the table shows it
@@ -5,11 +5,11 @@
5
5
  <meta name="pmos-nonce" content="" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
7
7
  <title>PMOS · Routine</title>
8
- <!-- Routine (initiative routine-place, slice 8 of the six-place navigation; board 11 on Exploring 2): one table of everything that repeats.
9
- Reports with who they tell, what PMOS reads, PMOS's own jobs and your own scheduled tasks, each with When, Next and a switch that pauses it.
10
- "PMOS did" is one line on top. A row opens the one popup (pm/cozy-popup.js): a report with its newest issue and its setup, or the setup of
11
- the routine (pm/cozy-routine-pop.js). The rail (pm/cozy-nav.js) is the navigation. The page code is pm/cozy-routine.js.
12
- The page is drawn from the PMOS design system (Komorebi): pm-ds on the page panel, brand, charts and komorebi sheets. -->
8
+ <!-- Routine (initiative routine-place, slice 8 of the six-place navigation; rebuilt from the design system's blocks by initiative
9
+ routine-ds-page, board RoutineDS on Exploring 3 page "pages"): Main + open item. The top line is the path, the product chip and + (ask PMOS
10
+ for a new routine). "PMOS did" is one line on top. One Table block holds everything that repeats, grouped by type, each row with When, Next
11
+ and the same switch. A row opens the Detail at the right (pm/cozy-routine-detail.js); a second press opens the one popup
12
+ (pm/cozy-popup.js). The rail (pm/cozy-nav.js) is the navigation. The page code is pm/cozy-routine.js. -->
13
13
  <link rel="preload" href="/vendor/plus-jakarta-sans-var.woff2" as="font" type="font/woff2" crossorigin />
14
14
  <link rel="stylesheet" href="/pm/brand.css" />
15
15
  <link rel="stylesheet" href="/pm/charts.css" />
@@ -22,13 +22,19 @@
22
22
  <main class="cz-panel stage rt-page pm-ds" id="stage">
23
23
  <div class="rt-toast pm-toast" id="toast" role="status" aria-live="polite"></div>
24
24
  <h1 class="vh">Routine</h1>
25
- <div class="rt-bar">
25
+ <div class="rt-top">
26
+ <nav class="pm-path" aria-label="Path"><b>Routine</b></nav>
26
27
  <div class="rt-pick" id="rtPick"></div>
27
- <div class="rt-seg pm-tabs" id="rtKinds" role="group" aria-label="Show"></div>
28
- <button type="button" class="rt-add pm-btn primary" id="rtAdd" aria-label="Tell PMOS a new routine" title="Tell PMOS a new routine"><svg class="pm-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg></button>
28
+ <span class="rt-sp"></span>
29
+ <button type="button" class="pm-btn" id="rtAdd" aria-label="Ask PMOS for a new routine" title="Ask PMOS for a new routine"><svg class="pm-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg></button>
30
+ </div>
31
+ <div class="rt-mi">
32
+ <div class="rt-main">
33
+ <div id="rtDid"></div>
34
+ <div id="rtTable"><p class="rt-quiet pm-meta">Reading what repeats.</p></div>
35
+ </div>
36
+ <aside class="rt-aside" id="rtDetail"></aside>
29
37
  </div>
30
- <div id="rtDid"></div>
31
- <div id="rtTable"><p class="rt-quiet pm-meta">Reading what repeats.</p></div>
32
38
  <p class="rt-msg pm-meta" id="rtMsg" role="status"></p>
33
39
  </main>
34
40
  <noscript>This page needs JavaScript.</noscript>
@@ -3492,6 +3492,8 @@ const liveRound = require('./lib/live-round.js').install({
3492
3492
  spawn: (spec) => spawnSession({ name: spec.name, agent: 'claude', ws: spec.ws, origin: spec.origin, initialInput: spec.initialInput, initiative: spec.initiative,
3493
3493
  writePaths: spec.writePaths, addDirs: spec.addDirs, autoDelete: undefined, onDone: spec.onDone }),
3494
3494
  stop: (s) => { if (s && s.child) stopHeadless(s); },
3495
+ // the design critic (lib/design-critic.js, initiative design-critic-pass): a read-only ask run reads each version before the PM sees it
3496
+ critic: require('./lib/design-critic.js').askVia(spawnSession),
3495
3497
  artefact: (dir, line, by) => { const AF = require('./lib/artefacts.js'); return AF.set(AF.file(dir), line, { by }); },
3496
3498
  // the chat explains the change (initiative live-round-iterative): a line typed into the initiative's chat session, when one is open
3497
3499
  tell: (ws, ini, text) => { const id = require('./lib/briefing-premium-agent.js').chatSessionOf(STATE, 'init:' + ini); return id ? sendToSession(id, text) : false; },
@@ -0,0 +1,7 @@
1
+ {
2
+ "_comment": "Design critic (initiative design-critic-pass, bet 4 of the factory line): every standing design rule of the product as a named check; a read-only ask run reads each live round version before it opens, its findings join the one fix run and the fix is read again; pmos lab critic for any screenshots; ledger with the PM's real/noise labels (lib/design-critic.js, lib/live-round.js, lib/routes-lab.js /api/lab/critic, lib/lab-cli.js, lib/idle-lab-engine.js renderCheck shots). Backend only.",
3
+ "modules": [
4
+ "design-critic.test.js"
5
+ ],
6
+ "seconds": { "design-critic.test.js": 1 }
7
+ }