create-pmos 0.610.0 → 0.611.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/package.json +50 -14
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/board-columns-test.js +2 -1
  7. package/workspace/board-deliveries-test.js +2 -1
  8. package/workspace/board-programs-test.js +7 -3
  9. package/workspace/board-publish-ui-test.js +2 -1
  10. package/workspace/board-shared-ui-test.js +2 -1
  11. package/workspace/board-workflows-test.js +2 -1
  12. package/workspace/briefing-premium-board-test.js +3 -2
  13. package/workspace/briefing-premium-doc-edit-test.js +2 -1
  14. package/workspace/briefing-premium-insights-test.js +4 -3
  15. package/workspace/briefing-premium-test.js +3 -2
  16. package/workspace/calm-timeline-test.js +2 -1
  17. package/workspace/changelog.json +49 -0
  18. package/workspace/core-docs-workflow-test.js +2 -1
  19. package/workspace/ev-everywhere-test.js +3 -2
  20. package/workspace/guide/home.md +2 -2
  21. package/workspace/guide/index.md +4 -0
  22. package/workspace/guide/layout.md +62 -2
  23. package/workspace/guide/programs.md +16 -2
  24. package/workspace/guide/routine.md +50 -0
  25. package/workspace/guide/scheduled-tasks-and-cli.md +1 -1
  26. package/workspace/guide/settings-and-switches.md +1 -1
  27. package/workspace/impact-screens-test.js +3 -1
  28. package/workspace/ini-workflow-test.js +2 -1
  29. package/workspace/lib/classic-board.js +15 -0
  30. package/workspace/lib/events-place.js +216 -0
  31. package/workspace/lib/library-items.js +78 -0
  32. package/workspace/lib/notes.js +6 -1
  33. package/workspace/lib/route-modules.js +4 -0
  34. package/workspace/lib/routes-events-place.js +166 -0
  35. package/workspace/lib/routes-library.js +89 -0
  36. package/workspace/lib/routes-pop-work.js +39 -0
  37. package/workspace/lib/routes-report-setups.js +20 -0
  38. package/workspace/lib/routes-today-log.js +48 -0
  39. package/workspace/lib/routine-reports.js +52 -0
  40. package/workspace/lib/today-log.js +131 -0
  41. package/workspace/live-pill-round-test.js +10 -7
  42. package/workspace/metric-drafts-ui-test.js +3 -1
  43. package/workspace/milestone-pins-test.js +2 -1
  44. package/workspace/milestone-suggest-test.js +3 -1
  45. package/workspace/package-lock.json +2 -2
  46. package/workspace/package.json +1 -1
  47. package/workspace/panels-test.js +2 -1
  48. package/workspace/premium-board-actions-test.js +3 -1
  49. package/workspace/premium-rec-tab-test.js +2 -1
  50. package/workspace/premium-vw-backlog-test.js +3 -1
  51. package/workspace/premium-vw-item-test.js +3 -1
  52. package/workspace/premium-vw-jira-test.js +3 -1
  53. package/workspace/product-lane-test.js +2 -1
  54. package/workspace/program-charter-test.js +3 -1
  55. package/workspace/program-leave-test.js +2 -1
  56. package/workspace/program-order-test.js +2 -1
  57. package/workspace/program-panel-test.js +3 -1
  58. package/workspace/public/pm/bd-ini-panel.js +72 -7
  59. package/workspace/public/pm/bd-prog-panel.js +55 -8
  60. package/workspace/public/pm/bd-work.css +130 -0
  61. package/workspace/public/pm/bd-work.js +356 -0
  62. package/workspace/public/pm/cozy-ev.css +2 -1
  63. package/workspace/public/pm/cozy-events-view.js +142 -0
  64. package/workspace/public/pm/cozy-events.css +107 -0
  65. package/workspace/public/pm/cozy-events.js +210 -0
  66. package/workspace/public/pm/cozy-evmodel.js +1 -1
  67. package/workspace/public/pm/cozy-library.css +36 -0
  68. package/workspace/public/pm/cozy-live-pill.js +1 -0
  69. package/workspace/public/pm/cozy-nav.js +5 -5
  70. package/workspace/public/pm/cozy-pop-work.css +165 -0
  71. package/workspace/public/pm/cozy-pop-work.js +427 -0
  72. package/workspace/public/pm/cozy-routine-model.js +111 -0
  73. package/workspace/public/pm/cozy-routine-pop.js +196 -0
  74. package/workspace/public/pm/cozy-routine.css +102 -0
  75. package/workspace/public/pm/cozy-routine.js +156 -0
  76. package/workspace/public/pm/cozy-schedwork.js +6 -5
  77. package/workspace/public/pm/cozy-today-app.js +236 -0
  78. package/workspace/public/pm/cozy-today-model.js +176 -0
  79. package/workspace/public/pm/cozy-today-page.css +100 -0
  80. package/workspace/public/pm/cozy-today-view.js +76 -0
  81. package/workspace/public/pm/home-app.js +18 -3
  82. package/workspace/public/pm/home-ini.js +36 -5
  83. package/workspace/public/pm/library-model.js +69 -0
  84. package/workspace/public/pm/library-open.js +34 -0
  85. package/workspace/public/pm/pop-work-model.js +335 -0
  86. package/workspace/public/pm/premium-board.js +130 -8
  87. package/workspace/public/pm/premium-library.js +122 -0
  88. package/workspace/public/premium-board.html +1 -0
  89. package/workspace/public/premium-events.html +42 -0
  90. package/workspace/public/premium-library.html +31 -0
  91. package/workspace/public/premium-routine.html +31 -0
  92. package/workspace/public/today.html +50 -0
  93. package/workspace/ready-dash-ui-test.js +3 -1
  94. package/workspace/rename-test.js +2 -1
  95. package/workspace/run-tests.js +4 -1
  96. package/workspace/server.js +3 -2
  97. package/workspace/sort-order-test.js +2 -1
  98. package/workspace/split-merge-ui-test.js +3 -1
  99. package/workspace/stage-card-tasks-test.js +3 -1
  100. package/workspace/stage-card-test.js +2 -1
  101. package/workspace/task-delete-test.js +2 -1
  102. package/workspace/task-links-test.js +2 -1
  103. package/workspace/task-milestones-test.js +4 -2
  104. package/workspace/task-plans-test.js +3 -1
  105. package/workspace/task-press-test.js +3 -1
  106. package/workspace/task-views-test.js +3 -1
  107. package/workspace/test-lists/events-place.json +11 -0
  108. package/workspace/test-lists/library-place.json +9 -0
  109. package/workspace/test-lists/pop-work.json +9 -0
  110. package/workspace/test-lists/routine-place.json +9 -0
  111. package/workspace/test-lists/today-log.json +9 -0
  112. package/workspace/test-lists/work-view.json +9 -0
  113. package/workspace/timeline-holds-test.js +3 -1
  114. package/workspace/tk-tasks-test.js +2 -1
@@ -0,0 +1,111 @@
1
+ /* pm/cozy-routine-model.js — Routine's table, as data (initiative routine-place, slice 8 of the six-place navigation; board 11 on Exploring 2;
2
+ * done test planning/done-tests/routine-place.md T2). PURE: no DOM and no fetch, so node tests it (routine-place.test.js).
3
+ *
4
+ * routineRows({ reports, refresh, tasks, many }, now) → [row] everything that repeats, as one kind of row
5
+ * reports GET /api/report-setups/routine rows of every workspace, each with { ws, wsName } (lib/routine-reports.js)
6
+ * refresh GET /api/refresh rows (lib/routes-refresh.js): what PMOS reads (run 'skill', a service of Your tools is a row of its own) and
7
+ * PMOS's own jobs (run 'job'); rows that only follow a change (run 'change') are not routines
8
+ * tasks GET /api/schedules?all=1 schedules that have not ended: your own scheduled tasks
9
+ * many true when the reports come from more than one product: "What it does" names the product too
10
+ * row: { key, kind: reports | reads | jobs | tasks, group: wait | reports | reads | jobs | tasks, name, does, when, next, on, wait, ws, id }
11
+ * on true or false: the switch that pauses it; null: no switch (a report with no setup, a service that follows Your tools)
12
+ * off true when it does not run now (its switch is off, or the switch of Your tools for a service)
13
+ * wait { act, label, say } on a row of Waits for you: its one ✓ (confirm the definition, or move it to the product it is about)
14
+ * routineGroups(rows, kind) → [{ id, title, rows }] the groups in order; a group with no row is left out (zero is silence)
15
+ * didLine(done, now) → { n, recent, shown, text } | null the one "PMOS did" line over GET /api/autonomy done of every product
16
+ * KINDS the filter: All, Reports, Reads, PMOS jobs, Your tasks
17
+ *
18
+ * Every word comes from a field of a record. A field the record leaves silent is '' and its cell is empty; nothing is filled with a guess. */
19
+ import { nextOf, atOf, everyLine } from './cozy-evmodel.js';
20
+
21
+ export const KINDS = [['all', 'All'], ['reports', 'Reports'], ['reads', 'Reads'], ['jobs', 'PMOS jobs'], ['tasks', 'Your tasks']];
22
+ export const GROUPS = [['wait', 'Waits for you'], ['reports', 'Reports'], ['reads', 'PMOS reads'], ['jobs', 'PMOS jobs'], ['tasks', 'Your tasks']];
23
+ const DAY = 86400000;
24
+ const DAYN = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
25
+ const str = (v) => (typeof v === 'string' ? v : '');
26
+ const firstUp = (s) => s.replace(/^./, (c) => c.toUpperCase());
27
+
28
+ /** A report's Next: Paused, a draft that waits, or when it drafts next. */
29
+ function reportNext(r, now) {
30
+ if (r.status === 'paused') return 'Paused';
31
+ if (r.act && r.act.act === 'issue' && r.latest && r.latest.state === 'draft') return 'A draft waits';
32
+ return r.next ? firstUp(nextOf(r.next, now)) : '';
33
+ }
34
+ /** What a report does: who it tells (its audience), and the product when the reports come from more than one. */
35
+ function reportDoes(r, many) {
36
+ const tells = r.audience ? 'Tells ' + r.audience : '';
37
+ return [tells, many ? r.wsName || r.ws || '' : ''].filter(Boolean).join(' · ');
38
+ }
39
+ /** Your task's repeat in words: "Every hour at :15", "Every Friday at 16:00". */
40
+ export function taskWhen(s) {
41
+ if (!s) return '';
42
+ const t = String(s.time || '09:00'), d = DAYN[s.day] || 'Monday';
43
+ return s.cadence === 'hourly' ? 'Every hour at :' + t.slice(-2) : s.cadence === 'daily' ? 'Every day at ' + t : s.cadence === 'weekly' ? 'Every ' + d + ' at ' + t
44
+ : s.cadence === 'bi-weekly' ? 'Every other ' + d + ' at ' + t : s.cadence === 'monthly' ? 'On day ' + (s.dayOfMonth || 1) + ' of each month at ' + t
45
+ : s.cadence === 'once' ? 'Once, ' + (s.date || '') + ' at ' + t : String(s.cadence || '');
46
+ }
47
+ /** A read or a job's Next: Paused, Stuck, Missed, Running now, or when it runs next. */
48
+ function refreshNext(r, now) {
49
+ if (!r.on) return 'Paused';
50
+ if (r.stall) return 'Stuck since ' + atOf(r.stall.since, now);
51
+ if (r.missed_at) return 'Missed ' + atOf(r.missed_at, now);
52
+ if (r.state === 'running') return 'Running now';
53
+ return r.next_at ? firstUp(nextOf(r.next_at, now)) : '';
54
+ }
55
+
56
+ export function routineRows({ reports = [], refresh = [], tasks = [], many = false } = {}, now = Date.now()) {
57
+ const out = [];
58
+ for (const r of reports) {
59
+ if (!r || !r.id) continue;
60
+ const a = r.act && (r.act.act === 'confirm' || r.act.act === 'move') ? r.act : null;
61
+ out.push({
62
+ key: 'r:' + (r.ws || '') + ':' + r.id, kind: 'reports', group: a ? 'wait' : 'reports', ws: r.ws || '', id: r.id, name: r.name || r.id,
63
+ does: reportDoes(r, many), when: str(r.when), late: !!a,
64
+ next: a ? (a.act === 'confirm' ? 'Say yes to start it' : a.label) : reportNext(r, now),
65
+ on: a || !r.status ? null : r.status === 'active', off: r.status === 'paused',
66
+ wait: a ? { act: a.act, label: a.act === 'confirm' ? 'Yes, start it' : a.label, say: a.act === 'confirm' ? 'Its definition waits for your word' : 'It is about ' + (a.toName || 'another product') } : null,
67
+ });
68
+ }
69
+ for (const r of refresh) {
70
+ if (!r || !r.id || (r.run !== 'skill' && r.run !== 'job')) continue;
71
+ const kind = r.run === 'skill' ? 'reads' : 'jobs';
72
+ if (r.run === 'skill' && Array.isArray(r.svcs) && r.svcs.length) {
73
+ // a service of Your tools is a row of its own (batch 31 item 6); it follows the switch of Your tools, so it has none
74
+ for (const v of r.svcs) {
75
+ if (!v || !v.id) continue;
76
+ const sv = { on: r.on, stall: r.stall && v.reading && (!r.stall.svcs || r.stall.svcs.includes(v.id)) ? r.stall : null, missed_at: v.missed_at, state: v.reading ? 'running' : '', next_at: v.next_at };
77
+ out.push({ key: 'j:' + r.id + '.' + v.id, kind, group: kind, ws: '', id: r.id + '.' + v.id, name: v.label || v.id,
78
+ does: 'PMOS reads ' + (v.label || v.id) + ' for the Briefing', when: everyLine(v.own ? v.schedule_text : r.schedule_text), next: refreshNext(sv, now), on: null, off: !r.on, late: !!(r.on && (sv.stall || sv.missed_at)), wait: null });
79
+ }
80
+ continue;
81
+ }
82
+ out.push({ key: 'j:' + r.id, kind, group: kind, ws: '', id: r.id, name: r.label || r.id, does: str(r.what).replace(/\.\s.*$/, '').replace(/\.$/, ''),
83
+ when: everyLine(r.schedule_text) || (r.set_in ? 'Set in ' + r.set_in.replace(/, /, ' › ') : ''), next: refreshNext(r, now), on: !!r.on, off: !r.on, late: !!(r.on && (r.stall || r.missed_at)), wait: null });
84
+ }
85
+ for (const s of tasks) {
86
+ if (!s || !s.id || s.endedReason) continue;
87
+ const on = s.enabled !== false;
88
+ out.push({ key: 't:' + s.id, kind: 'tasks', group: 'tasks', ws: s.ws || '', id: s.id, name: s.name || s.skill || s.id, does: s.skill || s.task ? 'Runs ' + (s.skill || s.task) : '',
89
+ when: taskWhen(s), next: !on ? 'Paused' : s.next ? firstUp(nextOf(s.next, now)) : '', on, off: !on, late: false, wait: null });
90
+ }
91
+ return out;
92
+ }
93
+
94
+ /** The groups in order, for one kind or all. A group with no row is not drawn. */
95
+ export function routineGroups(rows, kind = 'all') {
96
+ const mine = (rows || []).filter((r) => kind === 'all' || r.kind === kind);
97
+ return GROUPS.map(([id, title]) => ({ id, title, rows: mine.filter((r) => r.group === id) })).filter((g) => g.rows.length);
98
+ }
99
+
100
+ /** "PMOS did 76 things since yesterday. It showed you 2 of them." → null when nothing was done in the 14 days the log keeps. */
101
+ export function didLine(done, now = Date.now()) {
102
+ const all = (done || []).filter((d) => d && d.ref);
103
+ if (!all.length) return null;
104
+ const recent = all.filter((d) => { const t = Date.parse(d.at || ''); return Number.isFinite(t) && now - t <= DAY; });
105
+ const shown = recent.filter((d) => d.way === 'show').length;
106
+ const n = recent.length;
107
+ const thing = (k) => (k === 1 ? 'one thing' : k + ' things');
108
+ const text = n ? 'PMOS did ' + thing(n) + ' since yesterday.' : 'PMOS did ' + thing(all.length) + ' in the last 14 days.';
109
+ const sub = n && shown ? (shown === n ? 'It showed you each of them.' : 'It showed you ' + shown + ' of them. The others were small and it did them quietly.') : n ? 'Each was small, so it did them quietly.' : 'Nothing since yesterday.';
110
+ return { n: all.length, recent: n, shown, text, sub };
111
+ }
@@ -0,0 +1,196 @@
1
+ /* pm/cozy-routine-pop.js — a routine in the one popup (initiative routine-place, slice 8 of the six-place navigation; board 10 on Exploring 2;
2
+ * done test planning/done-tests/routine-place.md T3, T4).
3
+ *
4
+ * Press a row of Routine: the popup of slice 2 (cozy-popup.js) opens, the routine on the left and Ask PMOS on the right, already about it.
5
+ * A REPORT the newest issue to read; above it one ✦ line "Issue this draft to <who it tells>?" with ✓ and ✕ while that issue is a draft
6
+ * and the report's one act is Issue (lib/report-acts.js); the issue chooser, Draft or Issued, and the pencil that opens the full
7
+ * report reader (premium-report-read.js: Edit, Present, Share, Download stay there). Beside it ONE grey box, the setup: On,
8
+ * Repeats, Next, Tells, After the run, Built from, then the issues (press one to read it). Press a value to change it, or tell
9
+ * PMOS in the chat ("send it on Thursdays"). A field the record leaves silent is not drawn.
10
+ * A report that waits for your word (its definition, or a move to the product it is about) shows that one ✦ line instead.
11
+ * The chat is the report's own conversation (report-flow.js chatOf), so a change PMOS writes goes to the report's own session.
12
+ * ANY OTHER the setup cozy-schedwork.js draws for it (Active, Next run, Repeats, Working hours only, PMOS's ✦ rhythm, History, ▶).
13
+ *
14
+ * WRITES, each the PM's press on a route that exists: ✓ issue → GET /api/report/draft (the sha as read) then POST /api/report/issue, which
15
+ * freezes the issue; nothing is sent outward, the PM sends it from their own mail, as today. On → /api/report-setups/pause | resume.
16
+ * Repeats → /api/report-setups/edit { schedule }. Tells → /api/report-setups/edit { audience } on Enter or leaving the field. ✓ of a waiting
17
+ * report → /api/report-setups/confirm | move. ✕ hides the ✦ line for that issue on this computer.
18
+ * reportHtml(R, now) — pure, for the tests: R = { row, text, path, hide, msg, busy, editTells } */
19
+ import { mdHtml } from './chat-md.js';
20
+ import { nextOf } from './cozy-evmodel.js';
21
+ import { CADENCES, chatOf } from './report-flow.js';
22
+
23
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
24
+ const svg = (d, n = 16) => `<svg viewBox="0 0 24 24" width="${n}" height="${n}" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
25
+ const I = { check: 'M5 12.5l4.5 4.5L19 7.5', x: 'M6 6l12 12M18 6L6 18', pen: 'M5 19l1-4L16.5 4.5l3 3L9 18z', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z' };
26
+ const MONS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
27
+ const DAYS = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
28
+ /** "18 Nov", from a YYYY-MM-DD slot. */
29
+ export const dayMon = (s) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(s || '')); return m ? +m[3] + ' ' + MONS[+m[2] - 1] : String(s || ''); };
30
+ /** "Issue 2 · 18 Nov": issues are counted from the first. */
31
+ export function issueName(issues, path) {
32
+ const L = (issues || []).slice().sort((a, b) => (a.slot < b.slot ? -1 : 1)), i = L.findIndex((x) => x.path === path);
33
+ return i < 0 ? '' : 'Issue ' + (i + 1) + ' · ' + dayMon(L[i].slot);
34
+ }
35
+ /** Where a report is built from, in words: "Your work", "Goals", "A dashboard" (lib/report-setups.js sources), with the product. */
36
+ export function builtFrom(row) {
37
+ const s = String((row && row.source) || '');
38
+ const w = s === 'work' ? 'Your work' : /^intelligence:/.test(s) ? 'Goals' : /^dashboard:/.test(s) ? 'A dashboard' : /^ready:/.test(s) ? 'A ready-made report' : s ? s.replace(/^./, (c) => c.toUpperCase()) : '';
39
+ return [row && row.wsName, w].filter(Boolean).join(' · ');
40
+ }
41
+ /** The Repeats choices: the four cadences, the current one selected (a cadence PMOS does not offer stays as it is). */
42
+ export function repeatChoices(sch) {
43
+ const cur = sch && sch.cadence;
44
+ const L = CADENCES.map(([v, l]) => [v, l, v === cur]);
45
+ if (cur && !L.some((x) => x[2])) L.push([cur, cur, true]);
46
+ return L;
47
+ }
48
+ const at = (sch) => (sch && sch.cadence === 'monthly' ? 'day ' + (sch.dayOfMonth || 1) + ', ' : sch && sch.day && sch.cadence !== 'daily' ? (DAYS[sch.day] || sch.day).slice(0, 3) + ' ' : '') + ((sch && sch.time) || '');
49
+ const sw = (on, label) => `<button type="button" class="rt-sw" role="switch" aria-checked="${!!on}" data-rp="on" aria-label="${esc(label)}" title="${esc(label)}"></button>`;
50
+ const kv = (k, v, cls = '') => `<div class="rp-r${cls}"><span>${esc(k)}</span>${v}</div>`;
51
+ const fm = (t) => String(t || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
52
+
53
+ /** The report in the popup, as html. Pure. */
54
+ export function reportHtml(R, now = Date.now()) {
55
+ const r = R.row || {}, issues = r.issues || [], cur = issues.find((x) => x.path === R.path) || r.latest || null;
56
+ const a = r.act || null, who = r.audience || '';
57
+ const nope = R.hide && cur && R.hide.has(cur.path);
58
+ // the one ✦ line: a waiting definition or move, else a draft to issue
59
+ let sg = '';
60
+ if (a && (a.act === 'confirm' || a.act === 'move')) {
61
+ const t = a.act === 'confirm' ? 'Its definition waits for your word. Start it as it is?' : 'It is about ' + (a.toName || 'another product') + '. Move it there?';
62
+ sg = `<div class="rp-sg" role="group" aria-label="PMOS suggests"><h5>${svg(I.spark, 13)}PMOS suggests</h5><div><span>${esc(t)}</span>`
63
+ + `<button type="button" class="rp-y" data-rp="${a.act}" aria-label="${esc(a.act === 'confirm' ? 'Yes, start it' : a.label)}" title="${esc(a.act === 'confirm' ? 'Yes, start it' : a.label)}"${R.busy ? ' disabled' : ''}>${svg(I.check, 14)}</button></div></div>`;
64
+ } else if (a && a.act === 'issue' && cur && cur.state === 'draft' && cur.path === (r.latest && r.latest.path) && !nope) {
65
+ sg = `<div class="rp-sg" role="group" aria-label="PMOS suggests"><h5>${svg(I.spark, 13)}PMOS suggests</h5><div><span>${esc('Issue this draft' + (who ? ' to ' + who : '') + '?')}</span>`
66
+ + `<button type="button" class="rp-y" data-rp="issue" aria-label="Yes, issue it" title="Yes, issue it"${R.busy ? ' disabled' : ''}>${svg(I.check, 14)}</button>`
67
+ + `<button type="button" class="rp-n" data-rp="nope" aria-label="Not now" title="Not now">${svg(I.x, 14)}</button></div></div>`;
68
+ }
69
+ const pick = issues.length > 1 ? `<label class="vh" for="rpIss">Issue</label><select id="rpIss" class="rp-ch" data-rp="pick">${issues.map((x) => `<option value="${esc(x.path)}"${cur && x.path === cur.path ? ' selected' : ''}>${esc(issueName(issues, x.path))}</option>`).join('')}</select>`
70
+ : cur ? `<span class="rp-ch">${esc(issueName(issues, cur.path))}</span>` : '';
71
+ const meta = cur ? `<div class="rp-m">${pick}<span>${cur.state === 'issued' ? 'Issued' : 'Draft'}</span><button type="button" class="rp-ed" data-rp="edit" aria-label="Change the text" title="Change the text">${svg(I.pen, 17)}</button></div>` : '';
72
+ const body = !cur ? '<p class="rp-q">No issue is written yet. PMOS drafts the first one on its day.</p>'
73
+ : R.text == null ? '<p class="rp-q">Reading the issue.</p>' : R.err ? `<p class="rp-q">${esc(R.err)}</p>` : `<div class="rp-txt">${mdHtml(fm(R.text))}</div>`;
74
+ // the setup: only what the records say
75
+ const s = r.schedule;
76
+ const rows = [];
77
+ if (r.status) rows.push(kv('On', sw(r.status === 'active', r.status === 'active' ? 'On. Press to pause it' : 'Paused. Press to start it again')));
78
+ if (r.status && s) rows.push(kv('Repeats', `<label class="vh" for="rpRep">Repeats</label><select id="rpRep" class="rp-sel" data-rp="rep"${R.busy ? ' disabled' : ''}>${repeatChoices(s).map(([v, l, on]) => `<option value="${esc(v)}"${on ? ' selected' : ''}>${esc(l + (on && at(s) ? ', ' + at(s) : ''))}</option>`).join('')}</select>`));
79
+ else if (r.when) rows.push(kv('Repeats', `<em>${esc(r.when)}</em>`));
80
+ if (r.status === 'active' && r.next) rows.push(kv('Next', `<em>${esc(nextOf(r.next, now).replace(/^./, (c) => c.toUpperCase()))}</em>`));
81
+ if (r.status) rows.push(kv('Tells', R.editTells ? `<label class="vh" for="rpTells">Tells</label><input id="rpTells" class="rp-in" data-rp="tells" value="${esc(who)}" maxlength="120">`
82
+ : `<button type="button" class="rp-sel" data-rp="tells-ed" aria-label="${esc('Tells: ' + (who || 'nobody named') + '. Press to change it')}">${esc(who || 'Name who reads it')}</button>`));
83
+ else if (who) rows.push(kv('Tells', `<em>${esc(who)}</em>`));
84
+ if (r.status) rows.push(kv('After the run', '<em>You issue it</em>'));
85
+ if (builtFrom(r)) rows.push(kv('Built from', `<em>${esc(builtFrom(r))}</em>`));
86
+ const iss = issues.slice(0, 8).map((x) => `<button type="button" class="rp-r rp-i${cur && x.path === cur.path ? ' cur' : ''}" data-rp="open" data-path="${esc(x.path)}"><span>${esc(issueName(issues, x.path))}</span><em${x.state === 'draft' ? ' class="w"' : ''}>${x.state === 'issued' ? (x.archived ? 'Archived' : 'Issued') : 'Draft'}</em></button>`).join('');
87
+ const box = `<aside class="rp-box" aria-label="Setup"><h6>Setup</h6>${rows.join('')}${iss ? `<h6>Issues</h6>${iss}` : ''}`
88
+ + (r.status ? '<p>To change the setup, press a value. Or tell PMOS on the right, for example “send it on Thursdays”.</p>' : '') + '</aside>';
89
+ const msg = R.msg ? `<p class="rp-msg" role="status">${esc(R.msg)}</p>` : '<p class="rp-msg" role="status"></p>';
90
+ return `<div class="rp-w"><div class="rp-main">${sg}${meta}${body}${msg}</div>${box}</div>`;
91
+ }
92
+
93
+ /* ── the popup: open, draw, presses ── */
94
+ const NOPE = 'pmos.routine.nope.';
95
+ const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* a private window */ } } };
96
+ let P = null; // the report shown: { R, body, h }
97
+ const q = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
98
+
99
+ /** Open a report row of Routine in the popup. h: { VW, http: { pmGet, pmPost }, reload(), toast(text) } */
100
+ export async function openReport(row, h) {
101
+ const hide = new Set(); for (const x of row.issues || []) if (store.get(NOPE + x.path)) hide.add(x.path);
102
+ const R = { row, path: row.latest ? row.latest.path : '', text: null, err: '', hide, msg: '', busy: false, editTells: false };
103
+ const me = P = { R, body: null, h };
104
+ const PC = await import('./page-chat.js');
105
+ const base = PC.targetOf({ id: 'report-' + row.id, kind: 'report', title: row.name }, row.ws);
106
+ const t = { ...base, ...chatOf({ name: row.name, audience: row.audience, output: row.output, latest: row.latest }, row.id), ws: row.ws || undefined, scope: base.scope, role: base.role };
107
+ t.empty = 'Ask about ' + row.name + ', or tell PMOS what to change. Nothing is issued.';
108
+ if (typeof t.intro === 'string') t.intro = { text: t.intro }; // the chat draws an intro as { text }
109
+ h.VW.open({ id: 'routine:' + row.ws + ':' + row.id, kind: 'Report', title: row.name, icon: 'report',
110
+ pop: { id: 'report-' + row.id, kind: 'report', title: row.name, ws: row.ws || undefined, target: t },
111
+ render: (b) => { me.body = b; draw(me); wire(me); },
112
+ onClose: () => { if (P === me) P = null; } });
113
+ read(me);
114
+ return me;
115
+ }
116
+ function draw(me) { if (me.body && me.body.isConnected) me.body.innerHTML = reportHtml(me.R); }
117
+ async function read(me) {
118
+ const R = me.R; if (!R.path) { R.text = ''; draw(me); return; }
119
+ try {
120
+ const r = await fetch('/api/doc?' + q({ ws: R.row.ws, path: R.path }), { credentials: 'same-origin' });
121
+ R.text = r.ok ? await r.text() : ''; R.err = r.ok ? '' : 'The issue could not be read.';
122
+ } catch { R.text = ''; R.err = 'The issue could not be read.'; }
123
+ if (P === me) draw(me);
124
+ }
125
+ const said = (r, ok) => (r && r.ok !== false && !(r && r.error) ? ok : 'Nothing changed: ' + ((r && r.error) || 'the server did not answer') + '.');
126
+ async function refresh(me) {
127
+ const j = await me.h.http.pmGet('/api/report-setups/routine?' + q({ ws: me.R.row.ws })).catch(() => null);
128
+ const row = j && j.ok && (j.reports || []).find((x) => x.id === me.R.row.id);
129
+ if (row) me.R.row = { ...row, ws: me.R.row.ws, wsName: me.R.row.wsName };
130
+ if (me.h.reload) me.h.reload();
131
+ }
132
+ function wire(me) {
133
+ const b = me.body; if (!b || b.__rp) return; b.__rp = true;
134
+ const post = me.h.http.pmPost, R = me.R;
135
+ const act = async (fn) => { if (R.busy) return; R.busy = true; draw(me); try { R.msg = await fn(); } finally { R.busy = false; } await refresh(me); if (P === me) draw(me); };
136
+ b.addEventListener('click', async (e) => {
137
+ const t = e.target.closest('[data-rp]'); if (!t || t.tagName === 'SELECT' || t.tagName === 'INPUT') return;
138
+ const k = t.dataset.rp, row = R.row, ws = row.ws || undefined;
139
+ if (k === 'open') { R.path = t.dataset.path; R.text = null; R.msg = ''; draw(me); read(me); return; }
140
+ if (k === 'nope') { store.set(NOPE + R.path, '1'); R.hide.add(R.path); R.msg = 'PMOS will not ask about this draft again.'; draw(me); return; }
141
+ if (k === 'edit') { const M = await import('./premium-report-read.js'); me.h.VW.drill(); M.openReportView(R.path, { ws: row.ws, name: row.name }); return; }
142
+ if (k === 'tells-ed') { R.editTells = true; draw(me); const i = b.querySelector('#rpTells'); if (i) { i.focus(); i.select(); } return; }
143
+ if (k === 'on') return act(async () => { const on = row.status !== 'active'; return said(await post('/api/report-setups/' + (on ? 'resume' : 'pause'), { ws, id: row.id }), on ? 'On. PMOS drafts it on its day again.' : 'Paused. PMOS does not draft it until you turn it on.'); });
144
+ if (k === 'confirm') return act(async () => said(await post('/api/report-setups/confirm', { ws, id: row.id }), 'Started. Its drafts follow the definition as it is.'));
145
+ if (k === 'move') return act(async () => said(await post('/api/report-setups/move', { ws, id: row.id, to: row.act.to }), 'Moved to ' + row.act.toName + '. It drafts there from now on.'));
146
+ if (k === 'issue') {
147
+ return act(async () => {
148
+ const c = /\/([^/]+)\/(\d{4}-\d{2}-\d{2})\.md$/.exec(R.path) || [];
149
+ const cur = await me.h.http.pmGet('/api/report/draft?' + q({ ws: row.ws, cadence: c[1], slot: c[2] })).catch(() => null);
150
+ if (!cur || !cur.sha) return 'Not issued: the draft could not be read. Open it with the pencil and issue it there.';
151
+ const r = await post('/api/report/issue', { ws, cadence: c[1], slot: c[2], sha: cur.sha });
152
+ if (r && r.ok) { if (me.h.toast) me.h.toast('Issued. Send it from your own mail.'); return 'Issued. It stays as it is now. Send it from your own mail.'; }
153
+ return said(r, '');
154
+ });
155
+ }
156
+ });
157
+ b.addEventListener('change', (e) => {
158
+ const t = e.target; if (!t.dataset) return;
159
+ if (t.dataset.rp === 'pick') { R.path = t.value; R.text = null; R.msg = ''; draw(me); read(me); return; }
160
+ if (t.dataset.rp === 'rep') {
161
+ const row = R.row, s = row.schedule || {}, v = t.value;
162
+ const sch = { cadence: v, time: s.time || '09:00', ...(v === 'weekly' || v === 'bi-weekly' ? { day: s.day || 'Mon' } : {}), ...(v === 'monthly' ? { dayOfMonth: s.dayOfMonth || 1 } : {}), ...(s.anchor && v === 'bi-weekly' ? { anchor: s.anchor } : {}) };
163
+ act(async () => said(await post('/api/report-setups/edit', { ws: row.ws || undefined, id: row.id, schedule: sch }), 'Saved. ' + (CADENCES.find((x) => x[0] === v) || [0, v])[1] + '.'));
164
+ }
165
+ });
166
+ const tells = (i) => {
167
+ if (!R.editTells) return;
168
+ R.editTells = false;
169
+ const v = String(i.value || '').trim(), row = R.row;
170
+ if (!v || v === (row.audience || '')) { draw(me); return; }
171
+ act(async () => said(await post('/api/report-setups/edit', { ws: row.ws || undefined, id: row.id, audience: v }), 'Saved. It tells ' + v + '.'));
172
+ };
173
+ b.addEventListener('keydown', (e) => {
174
+ const t = e.target; if (!t.dataset || t.dataset.rp !== 'tells') return;
175
+ if (e.key === 'Enter') { e.preventDefault(); tells(t); } else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); R.editTells = false; draw(me); }
176
+ });
177
+ b.addEventListener('focusout', (e) => { const t = e.target; if (t.dataset && t.dataset.rp === 'tells') tells(t); });
178
+ }
179
+
180
+ /** Open a read, a job or one of your tasks in the popup: the setup cozy-schedwork.js draws. h: { VW, reload() } */
181
+ export async function openJob(row, h) {
182
+ const SW = await import('./cozy-schedwork.js');
183
+ const kind = row.kind === 'tasks' ? 'task' : 'job';
184
+ let sub = 'sw:' + kind + ':' + row.id, msg = '', body = null;
185
+ const draw = () => { if (body && body.isConnected) body.innerHTML = `<div class="cz ev-st rp-job">${SW.swBody(sub)}${msg ? `<p class="ev-small rp-msg" role="status">${esc(msg)}</p>` : ''}</div>`; };
186
+ const fresh = () => { if (h.reload) h.reload(); };
187
+ const H = { go: (k) => { if (!k || k === 'list') { h.VW.closePop(); return; } sub = 'sw:' + k; msg = ''; draw(); }, say: (m) => { msg = m; }, draw, fresh };
188
+ h.VW.open({ id: 'routine:' + row.key, kind: row.kind === 'tasks' ? 'Your task' : row.kind === 'reads' ? 'PMOS reads' : 'PMOS job', title: row.name, icon: row.kind === 'tasks' ? 'task' : row.kind === 'reads' ? 'source' : 'gear',
189
+ pop: { id: 'routine-' + row.id, kind: 'routine', title: row.name },
190
+ render: (b) => {
191
+ body = b; draw();
192
+ b.addEventListener('click', (e) => { const t = e.target.closest('button, a'); if (t && body.contains(t)) SW.swPress(t, H); });
193
+ b.addEventListener('change', (e) => { SW.swChange(e.target, H); });
194
+ } });
195
+ await SW.swLoad(draw);
196
+ }
@@ -0,0 +1,102 @@
1
+ /* pm/cozy-routine.css — Routine (initiative routine-place, board 11) and a routine in the popup (board 10). One container: the page panel; the
2
+ * table is one card with a thin border; the setup is one grey box. Tokens are cozy.css's. */
3
+ .rt-page { gap: 14px; }
4
+ .rt-bar { display: flex; align-items: center; gap: 12px; }
5
+ .rt-seg { display: inline-flex; gap: 2px; padding: 4px; border-radius: 999px; background: var(--cz-well); flex-wrap: wrap; }
6
+ .rt-seg button { all: unset; cursor: pointer; height: 30px; padding: 0 14px; border-radius: 999px; font-size: var(--fs-body); font-weight: var(--fw-strong); color: var(--cz-ink2); display: inline-flex; align-items: center; }
7
+ .rt-seg button[aria-pressed="true"] { background: var(--cz-card); color: var(--cz-ink); box-shadow: 0 1px 2px rgba(30, 40, 60, .12); }
8
+ .rt-seg button:focus-visible, .rt-add:focus-visible, .rt-did:focus-visible, .rt-r:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
9
+ .rt-add { all: unset; cursor: pointer; margin-left: auto; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--cz-ink2); }
10
+ .rt-add svg, .rt-did svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
11
+ .rt-add:hover { background: var(--cz-well); }
12
+ .rt-did { all: unset; box-sizing: border-box; cursor: pointer; width: 100%; display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 14px; background: var(--cz-well); font-size: var(--fs-body); color: var(--cz-ink); }
13
+ .rt-did > b { color: var(--cz-c-6b4fa3); }
14
+ .rt-did span { flex: 1; min-width: 0; }
15
+ .rt-did em { font-style: normal; color: var(--cz-ink3); }
16
+ .rt-tbl { border-radius: 16px; background: var(--cz-card); box-shadow: inset 0 0 0 1px var(--cz-hair); overflow: hidden; font-size: var(--fs-body); color: var(--cz-ink); }
17
+ .rt-r { display: grid; grid-template-columns: 26px minmax(0, 1.3fr) minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, .8fr) 44px; align-items: center; column-gap: 12px; min-height: 46px; padding: 0 18px; box-shadow: inset 0 -1px 0 var(--cz-hair); }
18
+ .rt-r:last-child { box-shadow: none; }
19
+ .rt-r.rt-h { min-height: 38px; background: var(--cz-well); font-size: var(--fs-meta); font-weight: var(--fw-strong); color: var(--cz-ink2); }
20
+ .rt-r.rt-g { min-height: 34px; font-size: var(--fs-meta); font-weight: var(--fw-strong); color: var(--cz-ink3); background: var(--cz-well); }
21
+ .rt-r.rt-g > div { grid-column: 1 / -1; }
22
+ .rt-r.rt-row { cursor: pointer; }
23
+ .rt-r.rt-row:hover { background: var(--cz-well); }
24
+ .rt-r .e { display: flex; justify-content: flex-end; align-items: center; }
25
+ .rt-r .ic { color: var(--cz-ink3); display: grid; place-items: center; }
26
+ .rt-r .ic svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
27
+ .rt-r .n { font-weight: var(--fw-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
28
+ .rt-r .c { color: var(--cz-ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
29
+ .rt-r .w { color: var(--cz-risk); font-weight: var(--fw-strong); display: inline-flex; align-items: center; gap: 7px; }
30
+ .rt-r .w::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--cz-dot-risk); flex: none; }
31
+ .rt-r.off .n, .rt-r.off .c { color: var(--cz-ink3); }
32
+ .rt-sw { all: unset; box-sizing: border-box; cursor: pointer; width: 34px; height: 20px; border-radius: 999px; background: var(--cz-well2); position: relative; justify-self: end; flex: none; }
33
+ .rt-sw::after { content: ''; position: absolute; left: 3px; top: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--cz-card); box-shadow: 0 1px 2px rgba(30, 40, 60, .25); transition: left .15s; }
34
+ .rt-sw[aria-checked="true"] { background: var(--cz-blue); }
35
+ .rt-sw[aria-checked="true"]::after { left: 17px; }
36
+ .rt-sw:focus-visible, .rt-yes:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
37
+ .rt-yes { all: unset; cursor: pointer; justify-self: end; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--cz-ink); color: var(--cz-card); }
38
+ .rt-yes svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
39
+ .rt-yes[disabled], .rt-sw[disabled] { opacity: .5; cursor: default; }
40
+ .rt-note, .rt-quiet { margin: 0 6px; font-size: var(--fs-meta); color: var(--cz-ink3); }
41
+ .rt-msg { margin: 0 6px; font-size: var(--fs-meta); color: var(--cz-ink2); min-height: 1em; }
42
+ .rt-toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 90; padding: 10px 16px; border-radius: 12px; background: var(--cz-ink); color: var(--cz-card); font-size: var(--fs-body); opacity: 0; pointer-events: none; transition: opacity .2s; }
43
+ .rt-toast.on { opacity: 1; }
44
+ @media (max-width: 760px) {
45
+ .rt-r { grid-template-columns: 22px minmax(0, 1fr) minmax(0, .8fr) 44px; padding: 0 12px; min-height: 52px; }
46
+ .rt-r .c.does, .rt-r .c.when, .rt-r.rt-h .does, .rt-r.rt-h .when { display: none; }
47
+ .rt-seg { border-radius: 16px; }
48
+ }
49
+ .vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
50
+
51
+ /* PMOS did, the full log (in the popup) */
52
+ .rt-log { display: flex; flex-direction: column; gap: 2px; padding: 4px 2px 20px; font-size: var(--fs-body); color: var(--cz-ink); }
53
+ .rt-log .l { display: flex; align-items: flex-start; gap: 10px; padding: 10px 4px; box-shadow: inset 0 -1px 0 var(--cz-hair); }
54
+ .rt-log .l span { flex: 1; min-width: 0; }
55
+ .rt-log .l b { font-weight: var(--fw-strong); display: block; }
56
+ .rt-log .l em { font-style: normal; color: var(--cz-ink3); font-size: var(--fs-meta); }
57
+ .rt-log .l button { all: unset; cursor: pointer; flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--cz-ink2); }
58
+ .rt-log .l button:hover { background: var(--cz-well); }
59
+ .rt-log .l button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
60
+ .rt-log .l button[disabled] { opacity: .4; cursor: default; }
61
+
62
+ /* a report in the popup (board 10): the issue on the left, the setup in one grey box */
63
+ .rp-w { display: grid; grid-template-columns: minmax(0, 1fr) 300px; column-gap: 22px; align-items: start; padding: 4px 4px 24px; }
64
+ @media (max-width: 1100px) { .rp-w { grid-template-columns: minmax(0, 1fr); row-gap: 16px; } }
65
+ .rp-main { font-size: var(--fs-body); line-height: 1.55; color: var(--cz-ink); min-width: 0; }
66
+ .rp-sg { margin: 0 0 16px; border-radius: 12px; background: var(--cz-card); box-shadow: inset 0 0 0 1px rgba(107, 91, 210, .28); padding: 8px 12px; }
67
+ .rp-sg h5 { margin: 0 0 2px; font-size: var(--fs-meta); font-weight: var(--fw-strong); color: var(--cz-c-6b4fa3); display: flex; align-items: center; gap: 5px; }
68
+ .rp-sg div { display: flex; align-items: center; gap: 8px; font-size: var(--fs-body); line-height: 1.4; }
69
+ .rp-sg div span { flex: 1; min-width: 0; }
70
+ .rp-sg button { all: unset; cursor: pointer; flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--cz-card); box-shadow: inset 0 0 0 1px var(--cz-hair); color: var(--cz-ink); }
71
+ .rp-sg button.rp-y { background: var(--cz-ink); color: var(--cz-card); box-shadow: none; }
72
+ .rp-sg button[disabled] { opacity: .5; cursor: default; }
73
+ .rp-m { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: var(--fs-meta); color: var(--cz-ink3); }
74
+ .rp-ch { height: 28px; padding: 0 10px; border-radius: 999px; background: var(--cz-well); font: inherit; font-weight: var(--fw-strong); color: var(--cz-ink2); border: 0; display: inline-flex; align-items: center; }
75
+ .rp-ed { all: unset; cursor: pointer; margin-left: auto; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--cz-ink2); }
76
+ .rp-ed:hover { background: var(--cz-well); }
77
+ .rp-txt h1, .rp-txt h2, .rp-txt h3, .rp-txt h4 { font-size: var(--fs-body); font-weight: var(--fw-strong); color: var(--cz-ink2); margin: 20px 0 4px; }
78
+ .rp-txt p { margin: 0 0 8px; }
79
+ .rp-txt ul, .rp-txt ol { margin: 0 0 8px; padding-left: 20px; }
80
+ .rp-txt table { border-collapse: collapse; font-size: var(--fs-body); margin: 6px 0 10px; }
81
+ .rp-txt th, .rp-txt td { padding: 4px 8px; box-shadow: inset 0 -1px 0 var(--cz-hair); text-align: left; }
82
+ .rp-q { color: var(--cz-ink3); font-size: var(--fs-body); }
83
+ .rp-msg { margin: 10px 0 0; font-size: var(--fs-meta); color: var(--cz-ink2); min-height: 1em; }
84
+ .rp-box { border-radius: 16px; background: var(--cz-well); padding: 12px 14px 14px; font-size: var(--fs-meta); color: var(--cz-ink); }
85
+ .rp-box h6 { margin: 4px 2px; font-size: var(--fs-meta); font-weight: var(--fw-strong); color: var(--cz-ink3); }
86
+ .rp-box h6 + .rp-r { box-shadow: none; }
87
+ .rp-box h6:not(:first-child) { margin-top: 14px; }
88
+ .rp-box .rp-r { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 2px; box-shadow: inset 0 1px 0 var(--cz-hair); }
89
+ .rp-box .rp-r > span { flex: 1; min-width: 0; color: var(--cz-ink2); }
90
+ .rp-box .rp-r em { font-style: normal; text-align: right; }
91
+ .rp-box .rp-r em.w { color: var(--cz-risk); font-weight: var(--fw-strong); }
92
+ .rp-box .rp-i { cursor: pointer; }
93
+ .rp-box .rp-i.cur > span { font-weight: var(--fw-strong); color: var(--cz-ink); }
94
+ .rp-box .rp-sel { all: unset; cursor: pointer; height: 28px; padding: 0 10px; border-radius: 999px; background: var(--cz-card); font-weight: var(--fw-strong); font-size: var(--fs-meta); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
95
+ .rp-box select.rp-sel { appearance: auto; }
96
+ .rp-box .rp-in { height: 28px; border-radius: 10px; border: 0; padding: 0 8px; font: inherit; font-size: var(--fs-meta); background: var(--cz-card); max-width: 170px; }
97
+ .rp-box p { margin: 12px 2px 0; font-size: var(--fs-meta); line-height: 1.45; color: var(--cz-ink3); }
98
+ .rp-box .rt-sw { justify-self: auto; }
99
+ /* a read, a job or your task in the popup: the setup cozy-schedwork.js draws, without the Settings dialog's frame */
100
+ .ev-st.rp-job { position: static; transform: none; z-index: auto; width: auto; height: auto; display: block; overflow: visible; box-shadow: none; border-radius: 0; background: none; max-width: 680px; padding: 4px 4px 24px; }
101
+ .rp-job .ev-dr-hd:has([data-ev-sw=""]) { display: none; }
102
+ .rp-job .ev-dr-hd [data-ev-sw=""] { display: none; }
@@ -0,0 +1,156 @@
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).
3
+ *
4
+ * One table of everything that repeats: Routine, What it does, When, Next, and a switch that pauses it. Groups: Waits for you (one ✓),
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.
8
+ *
9
+ * READS GET /api/workspaces, then per product GET /api/report-setups/routine?ws and GET /api/autonomy?ws; once GET /api/refresh and
10
+ * GET /api/schedules?all=1. Every product is read: Routine has no product choice (slice 1).
11
+ * 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 ✓ of Waits for you → /api/report-setups/confirm | move; Undo in the log →
13
+ * POST /api/autonomy/undo. Nothing here runs a routine or sends anything. */
14
+ import { pmGet, pmPost } from './http.js';
15
+ import { mountNav } from './cozy-nav.js';
16
+ import { mountLivePill } from './cozy-live-pill.js';
17
+ import * as VW from './cozy-viewer.js';
18
+ import * as POP from './cozy-popup.js';
19
+ import { KINDS, routineRows, routineGroups, didLine } from './cozy-routine-model.js';
20
+ import { atOf } from './cozy-evmodel.js';
21
+ import { openReport, openJob } from './cozy-routine-pop.js';
22
+
23
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
24
+ const svg = (d, n = 18) => `<svg viewBox="0 0 24 24" width="${n}" height="${n}" aria-hidden="true"><path d="${d}"/></svg>`;
25
+ const I = {
26
+ reports: 'M4 20V10M10 20V4M16 20v-8M22 20H2', reads: 'M2.5 12s3.5-6 9.5-6 9.5 6 9.5 6-3.5 6-9.5 6-9.5-6-9.5-6zM12 9.5a2.5 2.5 0 1 0 0 5a2.5 2.5 0 1 0 0-5',
27
+ jobs: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z', tasks: 'M5 5h14v14H5zM8.5 12.5l2.5 2.5 4.5-5',
28
+ check: 'M5 12.5l4.5 4.5L19 7.5', chev: 'M9 6l6 6-6 6', undo: 'M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3',
29
+ };
30
+ const KIND_KEY = 'pmos.routine.kind';
31
+ const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* a private window */ } } };
32
+ 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(), read: false, err: '' };
33
+ const $ = (id) => document.getElementById(id);
34
+ const toast = (t) => { const el = $('toast'); if (!el) return; el.textContent = t; el.classList.add('on'); clearTimeout(toast.t); toast.t = setTimeout(() => el.classList.remove('on'), 4200); };
35
+ const say = (t) => { const el = $('rtMsg'); if (el) el.textContent = t || ''; };
36
+ const enc = encodeURIComponent;
37
+
38
+ mountNav('routine', document, {});
39
+ mountLivePill(document);
40
+
41
+ async function load() {
42
+ const w = await pmGet('/api/workspaces').catch(() => null);
43
+ S.ws = w && Array.isArray(w.workspaces) ? w.workspaces.map((x) => ({ id: x.id, name: x.label || x.name || x.id })) : [];
44
+ const per = await Promise.all(S.ws.map((x) => Promise.all([pmGet('/api/report-setups/routine?ws=' + enc(x.id)).catch(() => null), pmGet('/api/autonomy?ws=' + enc(x.id)).catch(() => null)])));
45
+ const [rf, sc] = await Promise.all([pmGet('/api/refresh').catch(() => null), pmGet('/api/schedules?all=1').catch(() => null)]);
46
+ S.reports = []; S.done = [];
47
+ per.forEach(([r, a], i) => {
48
+ const x = S.ws[i];
49
+ if (r && r.ok) for (const row of r.reports || []) S.reports.push({ ...row, ws: x.id, wsName: x.name });
50
+ if (a && a.ok) for (const d of a.done || []) S.done.push({ ...d, ws: x.id });
51
+ });
52
+ S.done.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')));
53
+ S.refresh = rf && rf.ok && Array.isArray(rf.rows) ? rf.rows : [];
54
+ S.tasks = sc && Array.isArray(sc.schedules) ? sc.schedules : [];
55
+ S.err = !w ? 'PMOS is not answering. The table shows again when it is back.' : '';
56
+ S.read = true;
57
+ draw();
58
+ }
59
+
60
+ function kindsHtml() {
61
+ return KINDS.map(([k, l]) => `<button type="button" data-kind="${k}" aria-pressed="${S.kind === k}">${esc(l)}</button>`).join('');
62
+ }
63
+ function rowHtml(r) {
64
+ const busy = S.busy.has(r.key);
65
+ const end = r.wait ? `<button type="button" class="rt-yes" data-yes="${esc(r.key)}" aria-label="${esc(r.wait.label + ': ' + r.name)}" title="${esc(r.wait.label)}"${busy ? ' disabled' : ''}>${svg(I.check, 14)}</button>`
66
+ : r.on === null ? '<span></span>'
67
+ : `<button type="button" class="rt-sw" role="switch" aria-checked="${r.on}" data-sw="${esc(r.key)}" aria-label="${esc(r.name + (r.on ? ': on. Press to pause it' : ': paused. Press to start it again'))}" title="${r.on ? 'On' : 'Paused'}"${busy ? ' disabled' : ''}></button>`;
68
+ const next = r.wait ? `<span class="w">${esc(r.next)}</span>` : r.late ? `<span class="w">${esc(r.next)}</span>` : esc(r.next);
69
+ 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)}">`
70
+ + `<span class="ic" role="cell">${svg(I[r.kind], 17)}</span><span class="n" role="cell" title="${esc(r.name)}">${esc(r.name)}</span>`
71
+ + `<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>`
72
+ + `<span class="c" role="cell">${next}</span><span role="cell" class="e">${end}</span></div>`;
73
+ }
74
+ function draw() {
75
+ $('rtKinds').innerHTML = kindsHtml();
76
+ const D = didLine(S.done);
77
+ $('rtDid').innerHTML = D ? `<button type="button" class="rt-did" data-did aria-label="${esc(D.text + ' Open the full log')}"><b aria-hidden="true">✦</b><span>${esc(D.text)} <em>${esc(D.sub)}</em></span>${svg(I.chev, 14)}</button>` : '';
78
+ if (!S.read) return;
79
+ S.rows = routineRows({ reports: S.reports, refresh: S.refresh, tasks: S.tasks, many: new Set(S.reports.map((r) => r.ws)).size > 1 });
80
+ const G = routineGroups(S.rows, S.kind);
81
+ const f = document.activeElement && document.activeElement.closest && document.activeElement.closest('[data-key],[data-sw],[data-yes]');
82
+ const fk = f ? (f.dataset.key || f.dataset.sw || f.dataset.yes) + (f.dataset.sw ? ':sw' : f.dataset.yes ? ':yes' : '') : '';
83
+ $('rtTable').innerHTML = S.err ? `<p class="rt-quiet">${esc(S.err)}</p>`
84
+ : !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>`
85
+ : `<div class="rt-tbl" 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="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>`
86
+ + G.map((g) => `<div class="rt-r rt-g" role="row"><div role="rowheader">${esc(g.title)}</div></div>` + g.rows.map(rowHtml).join('')).join('') + '</div>'
87
+ + '<p class="rt-note">Everything that repeats, in one table. Press a row to open it. The switch pauses it.</p>';
88
+ 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(); }
89
+ }
90
+
91
+ const rowOf = (k) => S.rows.find((r) => r.key === k);
92
+ const reportOf = (r) => S.reports.find((x) => x.ws === r.ws && x.id === r.id);
93
+ const said = (x, ok) => (x && x.ok !== false && !(x && x.error) ? ok : 'Nothing changed: ' + ((x && x.error) || 'the server did not answer') + '.');
94
+ async function press(key, fn) {
95
+ if (S.busy.has(key)) return;
96
+ S.busy.add(key); draw();
97
+ try { say(await fn()); } finally { S.busy.delete(key); }
98
+ await load();
99
+ }
100
+ function flip(r) {
101
+ return press(r.key, async () => {
102
+ const on = !r.on;
103
+ if (r.kind === 'reports') return said(await pmPost('/api/report-setups/' + (on ? 'resume' : 'pause'), { ws: r.ws || undefined, id: r.id }), r.name + (on ? ' is on.' : ' is paused. PMOS does not draft it until you turn it on.'));
104
+ if (r.kind === 'tasks') return said(await pmPost('/api/schedules/update', { id: r.id, enabled: on }), r.name + (on ? ' runs on its schedule again.' : ' is paused.'));
105
+ return said(await pmPost('/api/refresh/source', { id: r.id, on }), r.name + (on ? ' is on.' : ' is paused. PMOS does not run it on its own.'));
106
+ });
107
+ }
108
+ function yes(r) {
109
+ const rep = reportOf(r); if (!rep || !rep.act) return;
110
+ return press(r.key, async () => (rep.act.act === 'move'
111
+ ? said(await pmPost('/api/report-setups/move', { ws: r.ws || undefined, id: r.id, to: rep.act.to }), 'Moved ' + r.name + ' to ' + rep.act.toName + '. It drafts there from now on.')
112
+ : said(await pmPost('/api/report-setups/confirm', { ws: r.ws || undefined, id: r.id }), 'Started ' + r.name + '. Its drafts follow the definition as it is.')));
113
+ }
114
+ const H = { VW, http: { pmGet, pmPost }, reload: () => load(), toast };
115
+ function open(r) {
116
+ if (r.kind === 'reports') { const rep = reportOf(r); if (rep) openReport(rep, H); return; }
117
+ openJob(r, H);
118
+ }
119
+
120
+ /* PMOS did, the full log: newest first, each with what it did, why, when, and Undo (POST /api/autonomy/undo) */
121
+ 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>`
122
+ + `<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>`;
123
+ function openLog() {
124
+ VW.open({ id: 'routine:did', kind: 'PMOS did', title: 'PMOS did', icon: 'spark', pop: { id: 'routine-did', kind: 'routine', title: 'What PMOS did' },
125
+ render: (b) => {
126
+ b.innerHTML = logHtml();
127
+ b.addEventListener('click', async (e) => {
128
+ const u = e.target.closest('[data-undo]'); if (!u || u.disabled) return;
129
+ u.disabled = true;
130
+ const x = await pmPost('/api/autonomy/undo', { ws: u.dataset.ws || undefined, ref: u.dataset.undo }).catch(() => null);
131
+ if (!x || !x.ok) { u.disabled = false; toast((x && x.error) || 'It could not be undone. Nothing changed.'); return; }
132
+ toast('Undone.'); await load(); if (b.isConnected) b.innerHTML = logHtml();
133
+ });
134
+ } });
135
+ }
136
+
137
+ document.addEventListener('click', (e) => {
138
+ const k = e.target.closest('[data-kind]');
139
+ if (k) { S.kind = k.dataset.kind; store.set(KIND_KEY, S.kind); draw(); return; }
140
+ if (e.target.closest('[data-did]')) { openLog(); return; }
141
+ if (e.target.closest('#rtAdd')) { import('./page-chat.js').then((M) => (window.innerWidth > 760 ? POP.openCos(M.cosTarget('Routine')) : M.openCos({ here: 'Routine' }))); return; }
142
+ const s = e.target.closest('[data-sw]'); if (s) { const r = rowOf(s.dataset.sw); if (r && !s.disabled) flip(r); return; }
143
+ const y = e.target.closest('[data-yes]'); if (y) { const r = rowOf(y.dataset.yes); if (r && !y.disabled) yes(r); return; }
144
+ const row = e.target.closest('[data-key]'); if (row && $('rtTable').contains(row)) { const r = rowOf(row.dataset.key); if (r) open(r); }
145
+ });
146
+ document.addEventListener('keydown', (e) => {
147
+ if (e.key !== 'Enter' && e.key !== ' ') return;
148
+ const row = e.target.closest && e.target.closest('[data-key]');
149
+ if (!row || e.target !== row) return;
150
+ e.preventDefault(); const r = rowOf(row.dataset.key); if (r) open(r);
151
+ });
152
+ document.addEventListener('visibilitychange', () => { if (!document.hidden) load(); });
153
+ document.addEventListener('cz:chat-turn', () => load()); // PMOS changed something from the chat: the table shows it
154
+ setInterval(() => { if (!document.hidden && !POP.isOpen()) load(); }, 60000);
155
+ draw();
156
+ load();