create-pmos 0.609.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.
- package/package.json +69 -27
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/board-columns-test.js +2 -1
- package/workspace/board-deliveries-test.js +2 -1
- package/workspace/board-programs-test.js +9 -5
- package/workspace/board-publish-ui-test.js +2 -1
- package/workspace/board-shared-ui-test.js +2 -1
- package/workspace/board-workflows-test.js +2 -1
- package/workspace/briefing-premium-adddoc-test.js +2 -1
- package/workspace/briefing-premium-board-test.js +10 -9
- package/workspace/briefing-premium-doc-edit-test.js +2 -1
- package/workspace/briefing-premium-initiative-test.js +7 -6
- package/workspace/briefing-premium-insights-test.js +12 -11
- package/workspace/briefing-premium-products-test.js +4 -2
- package/workspace/briefing-premium-sources-test.js +1 -1
- package/workspace/briefing-premium-test.js +6 -5
- package/workspace/briefing-premium-work-test.js +1 -1
- package/workspace/calm-timeline-test.js +2 -1
- package/workspace/changelog.json +68 -0
- package/workspace/core-docs-workflow-test.js +2 -1
- package/workspace/ev-everywhere-test.js +11 -10
- package/workspace/guide/home.md +2 -2
- package/workspace/guide/index.md +4 -0
- package/workspace/guide/layout.md +92 -11
- package/workspace/guide/programs.md +16 -2
- package/workspace/guide/routine.md +50 -0
- package/workspace/guide/scheduled-tasks-and-cli.md +1 -1
- package/workspace/guide/settings-and-switches.md +1 -1
- package/workspace/home-other-product-test.js +2 -1
- package/workspace/home-railcard-test.js +2 -1
- package/workspace/impact-screens-test.js +3 -1
- package/workspace/ini-workflow-test.js +2 -1
- package/workspace/lib/beside-page.js +15 -0
- package/workspace/lib/classic-board.js +15 -0
- package/workspace/lib/events-place.js +216 -0
- package/workspace/lib/library-items.js +78 -0
- package/workspace/lib/notes.js +6 -1
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-events-place.js +166 -0
- package/workspace/lib/routes-library.js +89 -0
- package/workspace/lib/routes-pop-work.js +39 -0
- package/workspace/lib/routes-report-setups.js +20 -0
- package/workspace/lib/routes-today-log.js +48 -0
- package/workspace/lib/routine-reports.js +52 -0
- package/workspace/lib/today-log.js +131 -0
- package/workspace/live-pill-round-test.js +11 -9
- package/workspace/metric-drafts-ui-test.js +3 -1
- package/workspace/milestone-pins-test.js +2 -1
- package/workspace/milestone-suggest-test.js +3 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/panels-test.js +6 -4
- package/workspace/premium-board-actions-test.js +3 -1
- package/workspace/premium-chat-context-test.js +6 -6
- package/workspace/premium-chat-line-test.js +1 -1
- package/workspace/premium-chat-notes-test.js +1 -1
- package/workspace/premium-core-doc-issue-test.js +2 -1
- package/workspace/premium-rec-tab-test.js +2 -1
- package/workspace/premium-vw-backlog-test.js +3 -1
- package/workspace/premium-vw-cal-test.js +1 -1
- package/workspace/premium-vw-doc-test.js +2 -1
- package/workspace/premium-vw-item-test.js +3 -1
- package/workspace/premium-vw-jira-test.js +3 -1
- package/workspace/product-lane-test.js +2 -1
- package/workspace/program-charter-test.js +3 -1
- package/workspace/program-leave-test.js +3 -1
- package/workspace/program-order-test.js +2 -1
- package/workspace/program-panel-test.js +5 -3
- package/workspace/public/pm/bd-ini-panel.js +75 -8
- package/workspace/public/pm/bd-prog-panel.js +55 -8
- package/workspace/public/pm/bd-scroll.js +4 -2
- package/workspace/public/pm/bd-work.css +130 -0
- package/workspace/public/pm/bd-work.js +356 -0
- package/workspace/public/pm/cozy-board.css +3 -0
- package/workspace/public/pm/cozy-ev.css +52 -0
- package/workspace/public/pm/cozy-events-view.js +142 -0
- package/workspace/public/pm/cozy-events.css +107 -0
- package/workspace/public/pm/cozy-events.js +210 -0
- package/workspace/public/pm/cozy-evmodel.js +1 -1
- package/workspace/public/pm/cozy-library.css +36 -0
- package/workspace/public/pm/cozy-live-pill.js +3 -1
- package/workspace/public/pm/cozy-nav.js +70 -7
- package/workspace/public/pm/cozy-panels.js +1 -1
- package/workspace/public/pm/cozy-pick.css +3 -0
- package/workspace/public/pm/cozy-pick.js +6 -2
- package/workspace/public/pm/cozy-pop-work.css +165 -0
- package/workspace/public/pm/cozy-pop-work.js +427 -0
- package/workspace/public/pm/cozy-popup.css +113 -0
- package/workspace/public/pm/cozy-popup.js +408 -0
- package/workspace/public/pm/cozy-routine-model.js +111 -0
- package/workspace/public/pm/cozy-routine-pop.js +196 -0
- package/workspace/public/pm/cozy-routine.css +102 -0
- package/workspace/public/pm/cozy-routine.js +156 -0
- package/workspace/public/pm/cozy-schedwork.js +6 -5
- package/workspace/public/pm/cozy-settings.js +10 -1
- package/workspace/public/pm/cozy-today-app.js +236 -0
- package/workspace/public/pm/cozy-today-model.js +176 -0
- package/workspace/public/pm/cozy-today-page.css +100 -0
- package/workspace/public/pm/cozy-today-view.js +76 -0
- package/workspace/public/pm/cozy-viewer.js +66 -18
- package/workspace/public/pm/home-app.js +29 -6
- package/workspace/public/pm/home-ini.js +39 -7
- package/workspace/public/pm/library-model.js +69 -0
- package/workspace/public/pm/library-open.js +34 -0
- package/workspace/public/pm/page-chat.js +16 -4
- package/workspace/public/pm/pop-sessions.js +65 -0
- package/workspace/public/pm/pop-work-model.js +335 -0
- package/workspace/public/pm/premium-board.js +137 -11
- package/workspace/public/pm/premium-insights.js +14 -2
- package/workspace/public/pm/premium-library.js +122 -0
- package/workspace/public/pm/premium-shell.js +1 -1
- package/workspace/public/premium-board.html +1 -0
- package/workspace/public/premium-events.html +42 -0
- package/workspace/public/premium-library.html +31 -0
- package/workspace/public/premium-routine.html +31 -0
- package/workspace/public/today.html +50 -0
- package/workspace/ready-dash-ui-test.js +3 -1
- package/workspace/rename-test.js +2 -1
- package/workspace/run-tests.js +4 -1
- package/workspace/server.js +3 -2
- package/workspace/sort-order-test.js +2 -1
- package/workspace/split-merge-ui-test.js +3 -1
- package/workspace/stage-card-tasks-test.js +5 -3
- package/workspace/stage-card-test.js +2 -1
- package/workspace/task-card-test.js +2 -1
- package/workspace/task-delete-test.js +3 -1
- package/workspace/task-links-test.js +4 -2
- package/workspace/task-milestones-test.js +4 -2
- package/workspace/task-plans-test.js +3 -1
- package/workspace/task-press-test.js +3 -1
- package/workspace/task-views-test.js +10 -8
- package/workspace/test-lists/events-place.json +11 -0
- package/workspace/test-lists/library-place.json +9 -0
- package/workspace/test-lists/one-popup.json +9 -0
- package/workspace/test-lists/pop-work.json +9 -0
- package/workspace/test-lists/routine-place.json +9 -0
- package/workspace/test-lists/today-log.json +9 -0
- package/workspace/test-lists/work-view.json +9 -0
- package/workspace/timeline-holds-test.js +3 -1
- package/workspace/tk-tasks-test.js +3 -1
- package/workspace/viewer-trail-test.js +1 -1
- package/workspace/workflows-setup-test.js +1 -1
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/* pm/cozy-popup.js — the one popup (slice 2 of the six-place navigation; boards 3, 7 and 23 on Exploring 2, page "Navigation: Today, Work,
|
|
2
|
+
* Goals, Events, Library, Routine"; build plan /mnt/project-files/nav-structure/build-plan.md).
|
|
3
|
+
*
|
|
4
|
+
* One way to open work: a popup that covers almost the whole page, with a thin dimmed edge of the page around it. The thing is on the left, in
|
|
5
|
+
* the page's own Viewer (cozy-viewer.js lifts #czViewer into the popup, so every page's selectors still find it). Ask PMOS is on the right,
|
|
6
|
+
* already about that thing. Esc, × or a press on the edge closes it. The phone keeps today's layout (cozy-viewer.js never pops on a phone).
|
|
7
|
+
* The grip between the two sides resizes them: each side keeps a smallest width (the work 480 px, the chat 360 px), and PMOS remembers the
|
|
8
|
+
* chat's width (localStorage 'cz-pop-chat'). Double-click or Home resets it; ← and → move it 24 px. The chat's top bar hides the chat, and the
|
|
9
|
+
* work takes the full width; "Ask PMOS" at the top right brings it back.
|
|
10
|
+
* The chat's title is the session chooser: the newest sessions with the work each is about and its state (PMOS is working, Waits for you, or
|
|
11
|
+
* when it was last used), New session (about the work on the left), and All sessions (the full list on the chat side with a search box; the
|
|
12
|
+
* popup stays; ← goes back to the session you were in). Press one and the chat changes to it; the work on the left stays.
|
|
13
|
+
* Each live session has a stop button. One press ends it, with no question: "Session ended" shows with Undo for a few seconds, and only then
|
|
14
|
+
* is POST /api/session/remove sent. The session moves to Earlier at once. An ended chat opens again from Earlier; writing in it makes it live.
|
|
15
|
+
* The chat icon (window.czOpenChat, the rail of slice 1) opens the popup on the session that waits for you, or the newest. Left: the work that
|
|
16
|
+
* session is about; when it is about no work, the full list of sessions. Ask PMOS is not a page.
|
|
17
|
+
*
|
|
18
|
+
* A page opens a thing in the popup with cozy-viewer.js open({ …, pop: about }), about = { id, kind, title, ws } (the chat opens about it),
|
|
19
|
+
* { keep: true, … } (the page already put its chat on it: Home), { session: row }, or { target } (a chat target of home-chat.js).
|
|
20
|
+
* openWork({ about, open() }) does the same for a page whose opener does not know the popup (Intelligence opens premium-vw-item.js).
|
|
21
|
+
* useChat(provider) the page's own chat goes in the popup (Home: #hmChat, so there is never a second chat on the page). provider:
|
|
22
|
+
* { el, open(target), current() → target, focus(), sessionTarget?(row) → target }. Without it, page-chat.js's chat is used.
|
|
23
|
+
* setTitles(fn) fn(initiativeId) → its name, for the work a session is about. setOpener(fn) fn(initiativeId, row) opens it on the left.
|
|
24
|
+
* openChat() the chat icon. openCos(target) the chief-of-staff chat (search's "Ask PMOS: …"). chatTo(target) changes the chat.
|
|
25
|
+
* Reads GET /api/sessions while it shows (every 6 s). Writes only on a press: End (after its Undo moment). The look is cozy-popup.css. */
|
|
26
|
+
import * as VW from './cozy-viewer.js';
|
|
27
|
+
import { pmGet, pmPost } from './http.js';
|
|
28
|
+
import { sessionRows, pickSession, recent, nextKey } from './pop-sessions.js';
|
|
29
|
+
|
|
30
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
31
|
+
const svg = (d, w = 18) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24"><path d="${d}"/></svg>`;
|
|
32
|
+
const I = {
|
|
33
|
+
chat: 'M5 6.5A2.5 2.5 0 0 1 7.5 4h9A2.5 2.5 0 0 1 19 6.5v7a2.5 2.5 0 0 1-2.5 2.5H11l-4 3.5V16h.5A2.5 2.5 0 0 1 5 13.5z',
|
|
34
|
+
hide: 'M4 5h16v14H4zM14.5 5v14M9 10l2 2-2 2', close: 'M6 6l12 12M18 6L6 18', down: 'M7 10l5 5 5-5', back: 'M15 6l-6 6 6 6',
|
|
35
|
+
plus: 'M12 5v14M5 12h14', list: 'M5 7h14M5 12h14M5 17h14', find: 'M11 4.5a6.5 6.5 0 1 0 0 13a6.5 6.5 0 1 0 0-13M16 16l4 4', flag: 'M5 21V4h11l-2 4 2 4H5',
|
|
36
|
+
side: 'M3.5 5h17v14h-17zM12 5v14',
|
|
37
|
+
};
|
|
38
|
+
const CLAUDE = { key: 'claude', name: 'PMOS', initial: 'P' };
|
|
39
|
+
const MIN_WORK = 480, MIN_CHAT = 360, DEF_CHAT = 460, POLL = 6000, UNDO = 6000, CHOOSER = 5;
|
|
40
|
+
const store = {
|
|
41
|
+
get(k) { try { return localStorage.getItem(k); } catch { return null; } },
|
|
42
|
+
set(k, v) { try { if (v == null) localStorage.removeItem(k); else localStorage.setItem(k, String(v)); } catch { /* a private window */ } },
|
|
43
|
+
};
|
|
44
|
+
const isPhone = () => typeof innerWidth === 'number' && innerWidth <= 760;
|
|
45
|
+
const S = {
|
|
46
|
+
el: null, card: null, left: null, right: null, box: null, all: null, menu: null, toast: null, tools: null, title: null, st: null,
|
|
47
|
+
open: false, about: null, home: null, chat: null, back: null, raw: [], rows: { now: [], earlier: [], all: [] }, view: 'chat', q: '', prev: null,
|
|
48
|
+
ending: new Map(), timer: 0, toastT: 0, titles: null, opener: null, w: 0, seq: 0,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/* ── the page's hooks ── */
|
|
52
|
+
export function useChat(p) { S.home = p && p.el && typeof p.open === 'function' ? p : null; }
|
|
53
|
+
export function setTitles(fn) { S.titles = typeof fn === 'function' ? fn : null; }
|
|
54
|
+
export function setOpener(fn) { S.opener = typeof fn === 'function' ? fn : null; }
|
|
55
|
+
export const isOpen = () => S.open;
|
|
56
|
+
const pretty = (id) => String(id || '').replace(/[-_]+/g, ' ').replace(/^./, (c) => c.toUpperCase());
|
|
57
|
+
const titleOf = (id) => { try { return (S.titles && S.titles(id)) || pretty(id); } catch { return pretty(id); } };
|
|
58
|
+
|
|
59
|
+
/* ── the frame ── */
|
|
60
|
+
function sheet() {
|
|
61
|
+
if (document.getElementById('czPopCss')) return;
|
|
62
|
+
const l = document.createElement('link'); l.id = 'czPopCss'; l.rel = 'stylesheet';
|
|
63
|
+
try { l.href = new URL('./cozy-popup.css', import.meta.url).href; } catch { l.href = '/pm/cozy-popup.css'; }
|
|
64
|
+
document.head.appendChild(l);
|
|
65
|
+
}
|
|
66
|
+
const ib = (act, label, d) => `<button type="button" class="cz-pop-ib" data-pop="${act}" aria-label="${esc(label)}" title="${esc(label)}">${svg(d)}</button>`;
|
|
67
|
+
function frame() {
|
|
68
|
+
if (S.el) return;
|
|
69
|
+
sheet();
|
|
70
|
+
const el = document.createElement('div');
|
|
71
|
+
el.className = 'cz-pop'; el.hidden = true;
|
|
72
|
+
el.innerHTML = '<div class="cz-pop-sc" data-pop="close"></div>'
|
|
73
|
+
+ '<div class="cz-pop-card" role="dialog" aria-modal="true" aria-label="Work and Ask PMOS" tabindex="-1">'
|
|
74
|
+
+ '<div class="cz-pop-l"></div>'
|
|
75
|
+
+ '<div class="cz-pop-grip" role="separator" aria-orientation="vertical" tabindex="0" aria-label="Drag to change the width of the chat. Double-click to reset." title="Drag to change the width. Double-click to reset."><i></i></div>'
|
|
76
|
+
+ '<section class="cz-pop-r" aria-label="Ask PMOS">'
|
|
77
|
+
+ `<header class="cz-pop-hd"><span class="cz-pop-tile" aria-hidden="true">${svg(I.chat)}</span><div class="cz-pop-tw"></div>${ib('where', 'Open work beside the page', I.side)}${ib('hide', 'Hide the chat', I.hide)}${ib('close', 'Close', I.close)}</header>`
|
|
78
|
+
+ '<div class="cz-pop-chat"></div><div class="cz-pop-all" hidden></div><div class="cz-pop-toast" role="status" hidden></div></section>'
|
|
79
|
+
+ `<div class="cz-pop-tools" hidden><button type="button" class="cz-pop-ask" data-pop="ask" aria-label="Show Ask PMOS">${svg(I.chat, 16)}Ask PMOS</button>${ib('close', 'Close', I.close)}</div>`
|
|
80
|
+
+ '</div>';
|
|
81
|
+
document.body.appendChild(el);
|
|
82
|
+
Object.assign(S, { el, card: el.querySelector('.cz-pop-card'), left: el.querySelector('.cz-pop-l'), right: el.querySelector('.cz-pop-r'), box: el.querySelector('.cz-pop-chat'),
|
|
83
|
+
all: el.querySelector('.cz-pop-all'), toast: el.querySelector('.cz-pop-toast'), tools: el.querySelector('.cz-pop-tools'), title: el.querySelector('.cz-pop-tw') });
|
|
84
|
+
el.addEventListener('click', onClick);
|
|
85
|
+
el.addEventListener('input', (e) => { if (e.target.matches('[data-pop-q]')) { S.q = e.target.value; drawLists(); } });
|
|
86
|
+
grip(el.querySelector('.cz-pop-grip'));
|
|
87
|
+
addEventListener('resize', () => { if (S.open) width(S.w); });
|
|
88
|
+
}
|
|
89
|
+
/** The chat's width: within what leaves the work its least width. */
|
|
90
|
+
function width(px) {
|
|
91
|
+
if (!S.card) return;
|
|
92
|
+
const room = innerWidth - 40; // the card's inset is 20 px a side (cozy-popup.css), so its width is known before its sheet has loaded
|
|
93
|
+
const w = Math.max(MIN_CHAT, Math.min(Math.round(px || DEF_CHAT), room - MIN_WORK - 1));
|
|
94
|
+
S.w = w; S.card.style.setProperty('--pop-chat', w + 'px');
|
|
95
|
+
const g = S.el.querySelector('.cz-pop-grip'); g.setAttribute('aria-valuenow', String(w)); g.setAttribute('aria-valuemin', String(MIN_CHAT)); g.setAttribute('aria-valuemax', String(Math.max(MIN_CHAT, room - MIN_WORK - 1)));
|
|
96
|
+
}
|
|
97
|
+
function grip(g) {
|
|
98
|
+
g.addEventListener('pointerdown', (e) => {
|
|
99
|
+
if (e.button !== 0) return;
|
|
100
|
+
e.preventDefault(); g.setPointerCapture(e.pointerId); document.body.classList.add('cz-pop-drag');
|
|
101
|
+
const right = S.card.getBoundingClientRect().right;
|
|
102
|
+
const mv = (ev) => width(right - ev.clientX);
|
|
103
|
+
const up = () => { g.removeEventListener('pointermove', mv); g.removeEventListener('pointerup', up); g.removeEventListener('pointercancel', up); document.body.classList.remove('cz-pop-drag'); store.set('cz-pop-chat', S.w); };
|
|
104
|
+
g.addEventListener('pointermove', mv); g.addEventListener('pointerup', up); g.addEventListener('pointercancel', up);
|
|
105
|
+
});
|
|
106
|
+
g.addEventListener('dblclick', () => { store.set('cz-pop-chat', null); width(DEF_CHAT); });
|
|
107
|
+
g.addEventListener('keydown', (e) => {
|
|
108
|
+
const d = e.key === 'ArrowLeft' ? 24 : e.key === 'ArrowRight' ? -24 : 0;
|
|
109
|
+
if (d) { e.preventDefault(); width(S.w + d); store.set('cz-pop-chat', S.w); } else if (e.key === 'Home') { e.preventDefault(); store.set('cz-pop-chat', null); width(DEF_CHAT); }
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* ── open and close ── */
|
|
114
|
+
VW.popHook({ host: () => { frame(); return S.left; }, show });
|
|
115
|
+
VW.onChange((d) => { if (d && d.pop && d.shut && S.open) hide(); });
|
|
116
|
+
/** cozy-viewer.js calls this as an item goes into the popup. A popup already open keeps its chat: the work on the left changes, the chat stays. */
|
|
117
|
+
function show(pop) {
|
|
118
|
+
if (S.open) return;
|
|
119
|
+
frame();
|
|
120
|
+
S.open = true; S.view = 'chat'; S.q = ''; S.prev = null;
|
|
121
|
+
S.back = document.activeElement && document.activeElement !== document.body ? document.activeElement : null;
|
|
122
|
+
S.el.hidden = false; document.body.classList.add('cz-pop-on');
|
|
123
|
+
S.card.classList.remove('chat-off'); S.tools.hidden = true; S.all.hidden = true; closeMenu();
|
|
124
|
+
const p = pop && typeof pop === 'object' ? pop : {};
|
|
125
|
+
S.about = p.session ? (p.session.ini ? { id: p.session.ini, kind: 'initiative', title: p.session.work, ws: p.session.ws } : null) : p.id ? { id: p.id, kind: p.kind || 'initiative', title: p.title || '', ws: p.ws } : null;
|
|
126
|
+
width(parseInt(store.get('cz-pop-chat') || '', 10) || DEF_CHAT);
|
|
127
|
+
const want = p.keep ? null : p.target ? p.target : p.session ? null : S.about ? aboutTarget(S.about) : null;
|
|
128
|
+
drawWhere();
|
|
129
|
+
attach(want, p.session || null);
|
|
130
|
+
read();
|
|
131
|
+
tick();
|
|
132
|
+
setTimeout(() => { if (S.open && S.card && !S.card.contains(document.activeElement)) S.card.focus({ preventScroll: true }); }, 0);
|
|
133
|
+
}
|
|
134
|
+
function hide() {
|
|
135
|
+
S.open = false; clearTimeout(S.timer); closeMenu(); hideToast();
|
|
136
|
+
S.view = 'chat'; S.all.hidden = true; S.all.innerHTML = ''; S.right.classList.remove('all-on');
|
|
137
|
+
detach();
|
|
138
|
+
S.el.hidden = true; document.body.classList.remove('cz-pop-on');
|
|
139
|
+
const b = S.back; S.back = null;
|
|
140
|
+
if (b && b.isConnected) { try { b.focus({ preventScroll: true }); } catch { /* gone */ } }
|
|
141
|
+
}
|
|
142
|
+
/** Close the popup (×, the edge): the Viewer closes first, so an item with unsaved changes asks; its close hides the popup. */
|
|
143
|
+
/* ── where work opens: in this popup (the default) or beside the page (the panels). The ⧉ press in the header turns it over. ── */
|
|
144
|
+
const beside = () => store.get(VW.POP_WHERE) === 'beside';
|
|
145
|
+
function drawWhere() {
|
|
146
|
+
const b = S.card && S.card.querySelector('[data-pop="where"]'); if (!b) return;
|
|
147
|
+
const t = beside() ? 'Open work in this popup' : 'Open work beside the page';
|
|
148
|
+
b.setAttribute('aria-label', t); b.title = t; b.setAttribute('aria-pressed', String(beside()));
|
|
149
|
+
}
|
|
150
|
+
function where() {
|
|
151
|
+
if (beside()) { store.set(VW.POP_WHERE, null); drawWhere(); return; }
|
|
152
|
+
store.set(VW.POP_WHERE, 'beside');
|
|
153
|
+
const a = S.about; close();
|
|
154
|
+
if (a && a.id && a.kind === 'initiative') setTimeout(() => openIni(a.id, a), 0); // the same work, now beside the page
|
|
155
|
+
}
|
|
156
|
+
export function close() { if (VW.popOpen()) VW.closePop(); else if (S.open) hide(); }
|
|
157
|
+
|
|
158
|
+
/* ── the chat on the right ── */
|
|
159
|
+
let PC = null; // page-chat.js, read once
|
|
160
|
+
const pageChat = () => (PC = PC || import('./page-chat.js'));
|
|
161
|
+
async function provider() {
|
|
162
|
+
if (S.home) return S.home;
|
|
163
|
+
const M = await pageChat(), b = await M.box();
|
|
164
|
+
return { el: b.el, open: (t) => b.chat.open(t), current: () => (b.chat.current ? b.chat.current() : null), focus: () => b.chat.focus(), stop: () => b.chat.stop(), page: true };
|
|
165
|
+
}
|
|
166
|
+
/** The chat about a thing: page-chat.js's target (its conversation key is the one Home opens for it). */
|
|
167
|
+
function aboutTarget(a) {
|
|
168
|
+
if (!a) return null;
|
|
169
|
+
return { __about: a };
|
|
170
|
+
}
|
|
171
|
+
async function resolve(t) {
|
|
172
|
+
if (!t || !t.__about) return t;
|
|
173
|
+
const M = await pageChat(), a = t.__about;
|
|
174
|
+
return M.keyOf(a) ? M.targetOf(a, a.ws) : M.cosTarget(a.title || '', a.ws);
|
|
175
|
+
}
|
|
176
|
+
async function attach(want, row) {
|
|
177
|
+
const my = ++S.seq;
|
|
178
|
+
const P = await provider();
|
|
179
|
+
if (my !== S.seq || !S.open) return;
|
|
180
|
+
S.chat = P;
|
|
181
|
+
if (P.el.parentNode !== S.box) {
|
|
182
|
+
if (!P.page) S.restore = { parent: P.el.parentNode, next: P.el.nextSibling }; // the page's own chat goes back where it was
|
|
183
|
+
S.box.appendChild(P.el);
|
|
184
|
+
}
|
|
185
|
+
let t = want ? await resolve(want) : null;
|
|
186
|
+
if (!t && row) t = await rowTarget(row);
|
|
187
|
+
if (my !== S.seq || !S.open) return;
|
|
188
|
+
if (t) P.open(t); else if (P.page && !(P.current && P.current())) P.open((await pageChat()).cosTarget(''));
|
|
189
|
+
stateLine();
|
|
190
|
+
drawTitle();
|
|
191
|
+
}
|
|
192
|
+
function detach() {
|
|
193
|
+
S.seq++;
|
|
194
|
+
const P = S.chat; S.chat = null;
|
|
195
|
+
if (S.st) { S.st.remove(); S.st = null; }
|
|
196
|
+
if (!P) return;
|
|
197
|
+
if (P.page) { if (P.stop) P.stop(); P.el.remove(); return; }
|
|
198
|
+
const r = S.restore; S.restore = null;
|
|
199
|
+
if (r && r.parent) r.parent.insertBefore(P.el, r.next && r.next.parentNode === r.parent ? r.next : null);
|
|
200
|
+
}
|
|
201
|
+
/** A session's chat: its own conversation (a chat key), else its transcript (the session id). Home draws it its own way. */
|
|
202
|
+
async function rowTarget(r) {
|
|
203
|
+
if (S.home && typeof S.home.sessionTarget === 'function') { const t = S.home.sessionTarget(r); if (t) return t; }
|
|
204
|
+
if (r.key === 'chat:main') return (await pageChat()).cosTarget('', r.ws || undefined);
|
|
205
|
+
const base = { ws: r.ws || undefined, title: r.name, about: r.work, role: CLAUDE, rich: false, scope: { text: r.ini ? r.work : 'No work', icon: I.flag },
|
|
206
|
+
placeholder: 'Message PMOS', empty: 'Write to carry on with ' + r.name + '.' };
|
|
207
|
+
return r.key ? { ...base, key: r.key } : { ...base, sid: r.id };
|
|
208
|
+
}
|
|
209
|
+
/** Change the chat (page-chat.js openTarget while the popup shows, a session picked). The work on the left stays. */
|
|
210
|
+
export async function chatTo(t) {
|
|
211
|
+
if (!S.open) return false;
|
|
212
|
+
const P = S.chat || await provider();
|
|
213
|
+
const x = await resolve(t);
|
|
214
|
+
if (x) P.open(x);
|
|
215
|
+
S.view = 'chat'; S.all.hidden = true; S.right.classList.remove('all-on'); closeMenu(); drawTitle(); stateLine();
|
|
216
|
+
setTimeout(() => P.focus && P.focus(), 30);
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* ── the sessions ── */
|
|
221
|
+
async function read() {
|
|
222
|
+
const r = await pmGet('/api/sessions').catch(() => null);
|
|
223
|
+
if (!S.open) return;
|
|
224
|
+
if (r && Array.isArray(r.sessions)) { S.raw = r.sessions; S.rows = sessionRows(S.raw, { titleOf }); }
|
|
225
|
+
drawTitle(); stateLine(); drawLists();
|
|
226
|
+
}
|
|
227
|
+
function tick() { clearTimeout(S.timer); S.timer = setTimeout(async () => { if (!S.open) return; if (!document.hidden) await read(); tick(); }, POLL); }
|
|
228
|
+
/** The rows with the sessions ended in this moment of Undo moved to Earlier. */
|
|
229
|
+
function rows() {
|
|
230
|
+
const end = (r) => (S.ending.has(r.id) ? { ...r, live: false, state: '', word: 'Ended' } : r);
|
|
231
|
+
const all = S.rows.all.map(end);
|
|
232
|
+
return { now: all.filter((r) => r.live), earlier: all.filter((r) => !r.live), all: all.filter((r) => r.live).concat(all.filter((r) => !r.live)) };
|
|
233
|
+
}
|
|
234
|
+
const curRow = () => {
|
|
235
|
+
const t = S.chat && S.chat.current ? S.chat.current() : null; if (!t) return null;
|
|
236
|
+
return rows().all.find((r) => (t.key && r.key === t.key) || (!t.key && t.sid && r.id === t.sid)) || null;
|
|
237
|
+
};
|
|
238
|
+
function rowHtml(r, sel) {
|
|
239
|
+
return `<div class="cz-pop-sr${sel ? ' on' : ''}" data-sid="${esc(r.id)}"><i class="cz-pop-d ${r.state}" aria-hidden="true"></i>`
|
|
240
|
+
+ `<button type="button" class="cz-pop-go" data-sid="${esc(r.id)}" aria-label="${esc(r.name + ', ' + r.work + ', ' + r.word)}"><b>${esc(r.name)}</b><small>${esc(r.work)}</small></button>`
|
|
241
|
+
+ `<em class="${r.state}">${esc(r.word)}</em>`
|
|
242
|
+
+ (r.live ? `<button type="button" class="cz-pop-x" data-end="${esc(r.id)}" aria-label="${esc('End ' + r.name)}" title="End this session"><i></i></button>` : '<span></span>') + '</div>';
|
|
243
|
+
}
|
|
244
|
+
function drawTitle() {
|
|
245
|
+
if (!S.title || !S.open) return;
|
|
246
|
+
if (S.view === 'all') {
|
|
247
|
+
S.title.innerHTML = `<button type="button" class="cz-pop-ib" data-pop="unall" aria-label="Back to the session you were in" title="Back to the session you were in">${svg(I.back)}</button><b class="t-row">All sessions</b>`;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const r = curRow(), name = r ? r.name : 'Ask PMOS', on = !!S.menu;
|
|
251
|
+
S.title.innerHTML = `<button type="button" class="cz-pop-t" data-pop="pick" aria-haspopup="menu" aria-expanded="${on}" title="Change session" aria-label="${esc(name + '. Change session')}"><span>${esc(name)}</span>${svg(I.down, 16)}</button>`;
|
|
252
|
+
}
|
|
253
|
+
/** The chat's last line: the state of the session shown and End session (board 7). Nothing when it is not live and busy. */
|
|
254
|
+
function stateLine() {
|
|
255
|
+
const P = S.chat; if (!P || !S.open) return;
|
|
256
|
+
const foot = P.el.querySelector('.hm-foot');
|
|
257
|
+
if (!S.st) { S.st = document.createElement('div'); S.st.className = 'cz-pop-st'; S.st.setAttribute('role', 'status'); }
|
|
258
|
+
if (foot && S.st.nextSibling !== foot) foot.before(S.st);
|
|
259
|
+
const r = curRow();
|
|
260
|
+
if (!r || !r.live || !r.state) { S.st.hidden = true; S.st.innerHTML = ''; return; }
|
|
261
|
+
S.st.hidden = false; S.st.className = 'cz-pop-st ' + r.state;
|
|
262
|
+
S.st.innerHTML = `<i aria-hidden="true"></i>${esc(r.word)}<button type="button" data-end="${esc(r.id)}" aria-label="${esc('End ' + r.name)}"><b aria-hidden="true"></b>End session</button>`;
|
|
263
|
+
}
|
|
264
|
+
function openMenu() {
|
|
265
|
+
closeMenu();
|
|
266
|
+
const R = rows(), cur = curRow(), list = recent(R.all, CHOOSER);
|
|
267
|
+
const m = document.createElement('div');
|
|
268
|
+
m.className = 'cz-pop-m'; m.setAttribute('role', 'menu'); m.setAttribute('aria-label', 'Sessions'); m.dataset.escLayer = '1';
|
|
269
|
+
m.innerHTML = (list.length ? '<h6>Sessions</h6>' + list.map((r) => rowHtml(r, cur && cur.id === r.id)).join('') + '<hr>' : '')
|
|
270
|
+
+ `<button type="button" class="cz-pop-f" role="menuitem" data-pop="new">${svg(I.plus, 16)}New session</button>`
|
|
271
|
+
+ `<button type="button" class="cz-pop-f" role="menuitem" data-pop="all">${svg(I.list, 16)}All sessions<span>the full list</span></button>`;
|
|
272
|
+
S.right.appendChild(m); S.menu = m; drawTitle();
|
|
273
|
+
const f = m.querySelector('button'); if (f) f.focus();
|
|
274
|
+
setTimeout(() => document.addEventListener('pointerdown', away, true), 0);
|
|
275
|
+
}
|
|
276
|
+
function away(e) { if (S.menu && !S.menu.contains(e.target) && !e.target.closest('[data-pop="pick"]')) closeMenu(); }
|
|
277
|
+
function closeMenu() {
|
|
278
|
+
document.removeEventListener('pointerdown', away, true);
|
|
279
|
+
if (!S.menu) return;
|
|
280
|
+
S.menu.remove(); S.menu = null; drawTitle();
|
|
281
|
+
}
|
|
282
|
+
/** The full list: Now and Earlier, newest first, with a search box (board 23). */
|
|
283
|
+
function listHtml(where) {
|
|
284
|
+
const R = rows(), q = S.q.trim().toLowerCase(), cur = curRow();
|
|
285
|
+
const f = (r) => !q || (r.name + ' ' + r.work).toLowerCase().includes(q);
|
|
286
|
+
const now = R.now.filter(f), earlier = R.earlier.filter(f);
|
|
287
|
+
return `<div class="cz-pop-list" data-pop-list="${where}"><label class="cz-pop-s">${svg(I.find, 16)}<input type="search" data-pop-q placeholder="Find a session" aria-label="Find a session" value="${esc(S.q)}"></label><div class="cz-pop-scr">`
|
|
288
|
+
+ (now.length ? `<h6>Now · ${now.length}</h6><div class="cz-pop-c">${now.map((r) => rowHtml(r, cur && cur.id === r.id)).join('')}</div>` : '')
|
|
289
|
+
+ (earlier.length ? `<h6>Earlier</h6><div class="cz-pop-c">${earlier.map((r) => rowHtml(r, cur && cur.id === r.id)).join('')}</div>` : '')
|
|
290
|
+
+ (!now.length && !earlier.length ? `<p class="cz-pop-none">${q ? 'No session matches.' : 'No sessions yet. Write to PMOS to start one.'}</p>` : '')
|
|
291
|
+
+ `</div><button type="button" class="cz-pop-n" data-pop="new">${svg(I.plus, 16)}New session</button></div>`;
|
|
292
|
+
}
|
|
293
|
+
/** Draw the lists that show (the chat side's All sessions, the left side's list) again, keeping the search box's focus. */
|
|
294
|
+
function drawLists() {
|
|
295
|
+
const boxes = [];
|
|
296
|
+
if (S.view === 'all' && !S.all.hidden) boxes.push([S.all, 'right']);
|
|
297
|
+
const lb = VW.bodyOf('pop:sessions'); if (lb) boxes.push([lb, 'left']);
|
|
298
|
+
for (const [b, where] of boxes) {
|
|
299
|
+
const had = document.activeElement && b.contains(document.activeElement) && document.activeElement.matches('[data-pop-q]');
|
|
300
|
+
const at = had ? document.activeElement.selectionStart : 0;
|
|
301
|
+
const sc = b.querySelector('.cz-pop-scr'), top = sc ? sc.scrollTop : 0;
|
|
302
|
+
b.innerHTML = listHtml(where);
|
|
303
|
+
const s2 = b.querySelector('.cz-pop-scr'); if (s2) s2.scrollTop = top;
|
|
304
|
+
if (had) { const i = b.querySelector('[data-pop-q]'); i.focus(); try { i.setSelectionRange(at, at); } catch { /* search fields */ } }
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function showAll(on) {
|
|
308
|
+
S.view = on ? 'all' : 'chat'; closeMenu();
|
|
309
|
+
S.all.hidden = !on; S.right.classList.toggle('all-on', !!on);
|
|
310
|
+
if (on) { S.all.dataset.escLayer = '1'; S.all.innerHTML = listHtml('right'); const i = S.all.querySelector('[data-pop-q]'); if (i) i.focus(); read(); }
|
|
311
|
+
else { delete S.all.dataset.escLayer; S.all.innerHTML = ''; S.q = ''; if (S.chat && S.chat.focus) S.chat.focus(); }
|
|
312
|
+
drawTitle();
|
|
313
|
+
}
|
|
314
|
+
async function pick(id) {
|
|
315
|
+
const r = rows().all.find((x) => x.id === id); if (!r) return;
|
|
316
|
+
const t = await rowTarget(r);
|
|
317
|
+
await chatTo(t);
|
|
318
|
+
}
|
|
319
|
+
/** End a session: one press, no question; "Session ended" with Undo; the end is sent when the Undo moment has passed. */
|
|
320
|
+
function end(id) {
|
|
321
|
+
const r = rows().all.find((x) => x.id === id); if (!r || S.ending.has(id)) return;
|
|
322
|
+
const tm = setTimeout(async () => {
|
|
323
|
+
S.ending.delete(id);
|
|
324
|
+
const res = await pmPost('/api/session/remove', { id }).catch(() => null);
|
|
325
|
+
if (!(res && res.ok)) { if (S.open) showToast('“' + r.name + '” did not end: ' + ((res && res.error) || 'the server did not answer') + '.', null); }
|
|
326
|
+
if (S.open) read();
|
|
327
|
+
}, UNDO);
|
|
328
|
+
S.ending.set(id, tm);
|
|
329
|
+
showToast('Session ended', () => { clearTimeout(tm); S.ending.delete(id); redraw(); });
|
|
330
|
+
redraw();
|
|
331
|
+
}
|
|
332
|
+
function redraw() {
|
|
333
|
+
drawTitle(); stateLine(); drawLists();
|
|
334
|
+
if (S.menu) openMenu(); // the chooser shows the row in its new place
|
|
335
|
+
}
|
|
336
|
+
function showToast(text, undo) {
|
|
337
|
+
clearTimeout(S.toastT);
|
|
338
|
+
S.toast.innerHTML = `<span>${esc(text)}</span>` + (undo ? '<button type="button" data-pop="undo">Undo</button>' : '');
|
|
339
|
+
S.toast.hidden = false; S.toast._undo = undo;
|
|
340
|
+
S.toastT = setTimeout(hideToast, UNDO - 300);
|
|
341
|
+
}
|
|
342
|
+
function hideToast() { clearTimeout(S.toastT); if (S.toast) { S.toast.hidden = true; S.toast._undo = null; } }
|
|
343
|
+
async function newSession() {
|
|
344
|
+
const a = S.about, M = await pageChat();
|
|
345
|
+
let t;
|
|
346
|
+
if (a && M.keyOf(a)) {
|
|
347
|
+
const base = M.targetOf(a, a.ws);
|
|
348
|
+
t = { ...base, key: nextKey(base.key, S.raw), title: 'New session · ' + (a.title || 'this'), empty: 'A new session about ' + (a.title || 'this') + '. Say what it is for.' };
|
|
349
|
+
} else {
|
|
350
|
+
const d = new Date(), p = (x) => String(x).padStart(2, '0');
|
|
351
|
+
t = { key: 'chat:loose-' + d.getFullYear() + p(d.getMonth() + 1) + p(d.getDate()) + '-' + p(d.getHours()) + p(d.getMinutes()) + p(d.getSeconds()), title: 'New session', role: CLAUDE, rich: false,
|
|
352
|
+
scope: { text: 'No work', icon: I.flag }, placeholder: 'Message PMOS', empty: 'A new session. Say what it is for.' };
|
|
353
|
+
}
|
|
354
|
+
await chatTo(t);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function onClick(e) {
|
|
358
|
+
const end1 = e.target.closest('[data-end]'); if (end1) { e.preventDefault(); end(end1.dataset.end); return; }
|
|
359
|
+
const row = e.target.closest('[data-sid]'); if (row) { e.preventDefault(); pick(row.dataset.sid); return; }
|
|
360
|
+
const b = e.target.closest('[data-pop]'); if (!b) return;
|
|
361
|
+
const a = b.dataset.pop;
|
|
362
|
+
if (a === 'close') close();
|
|
363
|
+
else if (a === 'where') where();
|
|
364
|
+
else if (a === 'hide') { S.card.classList.add('chat-off'); S.tools.hidden = false; closeMenu(); const k = S.tools.querySelector('[data-pop="ask"]'); if (k) k.focus(); }
|
|
365
|
+
else if (a === 'ask') { S.card.classList.remove('chat-off'); S.tools.hidden = true; width(S.w); if (S.chat && S.chat.focus) S.chat.focus(); }
|
|
366
|
+
else if (a === 'pick') { if (S.menu) closeMenu(); else { openMenu(); read(); } }
|
|
367
|
+
else if (a === 'new') newSession();
|
|
368
|
+
else if (a === 'all') showAll(true);
|
|
369
|
+
else if (a === 'unall') showAll(false);
|
|
370
|
+
else if (a === 'undo') { const u = S.toast._undo; hideToast(); if (u) u(); }
|
|
371
|
+
}
|
|
372
|
+
// Esc: the chooser closes first, then All sessions goes back to the session; with neither, the Viewer's own Esc closes the popup
|
|
373
|
+
addEventListener('keydown', (e) => {
|
|
374
|
+
if (e.key !== 'Escape' || !S.open) return;
|
|
375
|
+
if (S.menu) { e.preventDefault(); e.stopImmediatePropagation(); closeMenu(); const t = S.title.querySelector('[data-pop="pick"]'); if (t) t.focus(); return; }
|
|
376
|
+
if (S.view === 'all') { e.preventDefault(); e.stopImmediatePropagation(); showAll(false); }
|
|
377
|
+
}, true);
|
|
378
|
+
|
|
379
|
+
/* ── the ways in ── */
|
|
380
|
+
const sessionsItem = (pop) => ({ pop: { ...pop, force: true }, id: 'pop:sessions', kind: 'Sessions', title: 'All sessions', icon: 'list', render: (b) => { b.innerHTML = listHtml('left'); } });
|
|
381
|
+
/** A page whose opener does not know the popup: the next Viewer open goes into the popup, with the chat about the thing. */
|
|
382
|
+
export function openWork({ about, open } = {}) {
|
|
383
|
+
if (!isPhone() && about) VW.popNext(about);
|
|
384
|
+
if (typeof open === 'function') open();
|
|
385
|
+
}
|
|
386
|
+
async function openIni(id, row) {
|
|
387
|
+
if (S.opener) { S.opener(id, row); return; }
|
|
388
|
+
const M = await import('./premium-vw-item.js');
|
|
389
|
+
M.openWorkItem({ kind: 'initiative', id, ws: (row && row.ws) || '', title: titleOf(id) });
|
|
390
|
+
}
|
|
391
|
+
/** The chat icon: the session that waits for you, else the newest. Left: its work, or the full list of sessions. */
|
|
392
|
+
export async function openChat() {
|
|
393
|
+
if (isPhone()) { const M = await pageChat(); return M.openCos({ here: '' }); }
|
|
394
|
+
const r = await pmGet('/api/sessions').catch(() => null);
|
|
395
|
+
const R = sessionRows(r && Array.isArray(r.sessions) ? r.sessions : [], { titleOf });
|
|
396
|
+
const row = pickSession(R.all);
|
|
397
|
+
if (S.open) { if (row) await pick(row.id); return true; }
|
|
398
|
+
VW.open(sessionsItem(row ? { session: row } : { target: (await pageChat()).cosTarget('') }));
|
|
399
|
+
if (row && row.ini) openIni(row.ini, row);
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
/** The chief-of-staff chat (search's "Ask PMOS: …", page-chat.js openCos): the popup with that chat and the list of sessions. */
|
|
403
|
+
export async function openCos(t) {
|
|
404
|
+
if (S.open) return chatTo(t);
|
|
405
|
+
VW.open(sessionsItem({ target: t }));
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
if (typeof window !== 'undefined') { window.czOpenChat = openChat; window.czPopup = { openChat, openCos, openWork, chatTo, close, isOpen, useChat, setTitles, setOpener }; }
|
|
@@ -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
|
+
}
|