@goodandready/dsh-cron 0.3.43 → 0.3.44

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 (42) hide show
  1. package/lib/client.js +998 -3987
  2. package/lib/llm-ask.js +2 -1
  3. package/lib/routes/api-actions.js +36 -6
  4. package/lib/routes/api-item.js +1 -1
  5. package/lib/routes/api-webhook.js +2 -4
  6. package/lib/runtimes/runner-external.js +2 -3
  7. package/lib/runtimes/runner-session.js +385 -0
  8. package/lib/runtimes/runner-turn.js +255 -0
  9. package/lib/runtimes/runner.js +43 -616
  10. package/lib/scheduler/scheduler-execution.js +4 -1
  11. package/lib/scheduler/scheduler-lifecycle.js +65 -0
  12. package/lib/scheduler/scheduler-parser.js +261 -0
  13. package/lib/scheduler/scheduler.js +13 -319
  14. package/lib/store/store-archive.js +195 -0
  15. package/lib/store/store-io.js +331 -0
  16. package/lib/store/store-loader.js +165 -0
  17. package/lib/store/store-migration.js +38 -0
  18. package/lib/store/store-settings.js +126 -0
  19. package/lib/store/store-stats.js +55 -0
  20. package/lib/store/store.js +75 -888
  21. package/package.json +8 -6
  22. package/lib/client-src/00-open.js +0 -63
  23. package/lib/client-src/10-locales.js +0 -540
  24. package/lib/client-src/20-styles.js +0 -64
  25. package/lib/client-src/30-utils.js +0 -372
  26. package/lib/client-src/40-delivery-settings.js +0 -96
  27. package/lib/client-src/45-dag-graph-view.js +0 -287
  28. package/lib/client-src/46-live-logs-modal.js +0 -108
  29. package/lib/client-src/47-analytics-digest-modal.js +0 -166
  30. package/lib/client-src/48-timeline-heatmap-view.js +0 -176
  31. package/lib/client-src/50-cron-screen-state.js +0 -457
  32. package/lib/client-src/52-cron-screen-actions.js +0 -330
  33. package/lib/client-src/53-cron-screen-modal-actions.js +0 -677
  34. package/lib/client-src/54-cron-screen-analytics-actions.js +0 -68
  35. package/lib/client-src/55-cron-screen-view.js +0 -378
  36. package/lib/client-src/60-modal-task-form-head.js +0 -581
  37. package/lib/client-src/62-modal-task-form-tail.js +0 -563
  38. package/lib/client-src/65-modal-dialogs.js +0 -350
  39. package/lib/client-src/70-settings-card.js +0 -453
  40. package/lib/client-src/75-quick-action-bar.js +0 -146
  41. package/lib/client-src/80-sidebar-jobs.js +0 -200
  42. package/lib/client-src/90-close.js +0 -219
@@ -1,200 +0,0 @@
1
- function buildSidebarJobRow(state, task) {
2
- const row = document.createElement('button');
3
- row.type = 'button';
4
- row.className = 'dsh-cron-sidebar-job';
5
- // A distinct attribute: the panel uses data-task-id, and the highlight
6
- // lookup must never pick a sidebar row instead of a task card.
7
- row.setAttribute('data-sidebar-task-id', task.id);
8
- row.setAttribute('aria-label', task.title || task.id);
9
-
10
- const title = document.createElement('span');
11
- title.className = 'dsh-cron-sidebar-job-title';
12
- title.textContent = task.title || task.id;
13
- row.appendChild(title);
14
-
15
- const meta = document.createElement('span');
16
- meta.className = 'dsh-cron-sidebar-job-meta';
17
- if (task.running) meta.textContent = T('list.runningNow');
18
- else if (task.nextRunAt) meta.textContent = new Date(task.nextRunAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
19
- else meta.textContent = task.scheduleText || task.schedule || '';
20
- row.appendChild(meta);
21
-
22
- if (task.running) row.classList.add('dsh-cron-pulse');
23
- row.addEventListener('click', (event) => {
24
- event.preventDefault();
25
- event.stopPropagation();
26
- state.openTaskSignal(task.id);
27
- if (!state.toggle.isOpen()) state.toggle.toggle();
28
- });
29
- return row;
30
- }
31
-
32
- function renderSidebarJobs(state, tasks) {
33
- const listEl = state.listEl;
34
- if (!listEl) return;
35
- listEl.innerHTML = '';
36
- if (!tasks.length) {
37
- const empty = document.createElement('div');
38
- empty.className = 'dsh-cron-sidebar-empty';
39
- empty.textContent = T('sidebar.noActiveJobs');
40
- listEl.appendChild(empty);
41
- return;
42
- }
43
- for (const task of tasks.slice(0, SIDEBAR_JOBS_MAX_ROWS)) listEl.appendChild(buildSidebarJobRow(state, task));
44
- if (tasks.length > SIDEBAR_JOBS_MAX_ROWS) {
45
- const more = document.createElement('div');
46
- more.className = 'dsh-cron-sidebar-more';
47
- more.textContent = T('sidebar.moreJobs', { count: tasks.length - SIDEBAR_JOBS_MAX_ROWS });
48
- listEl.appendChild(more);
49
- }
50
- }
51
-
52
- async function loadSidebarJobs(state) {
53
- try {
54
- const { res, data } = await fetchJsonWithTimeout('/dsh-cron/tasks?status=active');
55
- if (data && data.ok) renderSidebarJobs(state, data.tasks || []);
56
- } catch (err) {
57
- console.debug('[dsh-cron] load sidebar jobs failed', err);
58
- }
59
- }
60
-
61
- function applySidebarJobsOpen(state) {
62
- if (!state.root) return;
63
- state.root.dataset.open = state.open ? 'true' : 'false';
64
- if (state.headEl) state.headEl.setAttribute('aria-expanded', state.open ? 'true' : 'false');
65
- if (state.open) loadSidebarJobs(state);
66
- }
67
-
68
- function buildSidebarJobsRoot(state, label) {
69
- const root = document.createElement('div');
70
- root.className = 'dsh-cron-sidebar-jobs';
71
- root.setAttribute('data-dsh-plugin', 'dsh-cron');
72
- root.setAttribute('data-dsh-part', 'sidebar-jobs');
73
-
74
- const headEl = document.createElement('button');
75
- headEl.type = 'button';
76
- headEl.className = 'dsh-cron-sidebar-jobs-head';
77
- headEl.setAttribute('aria-expanded', state.open ? 'true' : 'false');
78
- headEl.textContent = label;
79
- headEl.addEventListener('click', (event) => {
80
- event.preventDefault();
81
- event.stopPropagation();
82
- state.open = !state.open;
83
- try { window.localStorage.setItem(SIDEBAR_JOBS_KEY, state.open ? '1' : '0'); } catch (err) { /* localStorage write failed */ }
84
- applySidebarJobsOpen(state);
85
- });
86
- root.appendChild(headEl);
87
-
88
- const listEl = document.createElement('div');
89
- listEl.className = 'dsh-cron-sidebar-jobs-list';
90
- root.appendChild(listEl);
91
-
92
- state.root = root;
93
- state.headEl = headEl;
94
- state.listEl = listEl;
95
- return root;
96
- }
97
-
98
- /** Keep the section mounted under the sidebar entry across re-renders. */
99
- function placeSidebarJobs(state, label) {
100
- const entry = document.querySelector('[' + ENTRY_ATTR + ']');
101
- if (sidebarJobsSeatIsCurrent(state, entry)) return;
102
- if (entry === null || entry.parentElement === null) return;
103
- if (state.root === undefined) {
104
- entry.insertAdjacentElement('afterend', buildSidebarJobsRoot(state, label));
105
- } else {
106
- entry.insertAdjacentElement('afterend', state.root);
107
- // Re-query the refs: the previous nodes may belong to a detached tree.
108
- state.root = document.querySelector('[data-dsh-part="sidebar-jobs"]') || state.root;
109
- state.listEl = state.root.querySelector('.dsh-cron-sidebar-jobs-list');
110
- state.headEl = state.root.querySelector('.dsh-cron-sidebar-jobs-head');
111
- }
112
- applySidebarJobsOpen(state);
113
- }
114
-
115
- /**
116
- * Collapsible list of active jobs under the sidebar entry (#34).
117
- *
118
- * Vanilla DOM like the entry itself: the sidebar is not a React root here.
119
- * Collapsed by default, state persisted, capped at a few rows with an
120
- * "and N more" line so a busy schedule cannot push the rest of the sidebar
121
- * off screen. Clicking a row opens the panel and highlights that task.
122
- */
123
- function mountSidebarJobs(toggle, label, openTaskSignal) {
124
- if (typeof document === 'undefined') return () => {};
125
- const state = { toggle, openTaskSignal, root: undefined, listEl: undefined, headEl: undefined, open: false };
126
- try { state.open = window.localStorage.getItem(SIDEBAR_JOBS_KEY) === '1'; } catch (err) { /* localStorage read failed */ }
127
-
128
- let rafPending = false;
129
- const schedulePlace = () => {
130
- if (sidebarJobsSeatIsCurrent(state, document.querySelector('[' + ENTRY_ATTR + ']'))) return;
131
- if (rafPending) return;
132
- rafPending = true;
133
- const scheduleFn = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (cb) => setTimeout(cb, 16);
134
- scheduleFn(() => {
135
- rafPending = false;
136
- placeSidebarJobs(state, label);
137
- });
138
- };
139
-
140
- const observer = new MutationObserver(schedulePlace);
141
- observer.observe(document.body, { childList: true, subtree: true });
142
- placeSidebarJobs(state, label);
143
- loadSidebarJobs(state);
144
- const fetchTimer = setInterval(() => {
145
- let isOpen = false;
146
- try { isOpen = window.localStorage.getItem(SIDEBAR_JOBS_KEY) === '1'; } catch (err) { /* localStorage poll failed */ }
147
- if (isOpen) loadSidebarJobs(state);
148
- }, 30000);
149
-
150
- return () => {
151
- observer.disconnect();
152
- clearInterval(fetchTimer);
153
- if (state.root !== undefined && state.root.isConnected) state.root.remove();
154
- state.root = undefined;
155
- };
156
- }
157
-
158
- function placeEntry(target, entry) {
159
- let anchor = target;
160
- let next = target.nextElementSibling;
161
- while (next !== null && next.tagName === 'BUTTON'
162
- && String(next.className).indexOf('sidebar-entry') >= 0) {
163
- anchor = next;
164
- next = next.nextElementSibling;
165
- }
166
- anchor.insertAdjacentElement('afterend', entry);
167
- }
168
-
169
- function mountSidebarEntry(toggle, label) {
170
- if (typeof document === 'undefined') return () => {};
171
- let entry;
172
- const tryPlace = () => {
173
- if (entry !== undefined && entry.isConnected) return;
174
- const target = nativeButton();
175
- if (target === undefined || target.parentElement === null) return;
176
- if (target.parentElement.querySelector('[' + ENTRY_ATTR + ']') !== null) return;
177
- entry = createEntry(target, toggle, label);
178
- placeEntry(target, entry);
179
- syncActive();
180
- };
181
-
182
- const syncActive = () => {
183
- if (entry === undefined) return;
184
- if (toggle.isOpen()) entry.dataset.active = 'true';
185
- else delete entry.dataset.active;
186
- };
187
-
188
- const observer = new MutationObserver(tryPlace);
189
- observer.observe(document.body, { childList: true, subtree: true });
190
- const unsubscribe = toggle.subscribe(syncActive);
191
- tryPlace();
192
-
193
- return () => {
194
- observer.disconnect();
195
- unsubscribe();
196
- if (entry !== undefined) entry.remove();
197
- entry = undefined;
198
- };
199
- }
200
-
@@ -1,219 +0,0 @@
1
- function mountCronScreen(ctx, toggle) {
2
- if (typeof document === 'undefined') return () => {};
3
- let root;
4
- let container;
5
-
6
- const teardownPanel = () => {
7
- if (root !== undefined) {
8
- try { root.unmount(); } catch (e) { /* ignore */ }
9
- root = undefined;
10
- }
11
- if (container !== undefined) {
12
- try { container.remove(); } catch (e) { /* ignore */ }
13
- container = undefined;
14
- }
15
- };
16
-
17
- const ensure = () => {
18
- if (!toggle.isOpen()) {
19
- teardownPanel();
20
- return;
21
- }
22
- if (container !== undefined && container.isConnected) return;
23
- const column = document.querySelector(COLUMN_SELECTOR);
24
- if (column === null) return;
25
- container = document.createElement('div');
26
- container.setAttribute(VIEW_ATTR, '');
27
- container.setAttribute('data-dsh-plugin', 'dsh-cron');
28
- column.appendChild(container);
29
- if (ReactDOM && typeof ReactDOM.createRoot === 'function') {
30
- root = ReactDOM.createRoot(container);
31
- root.render(React.createElement(ErrorBoundary, null, React.createElement(CronScreen, { ctx, toggle, onClose: () => toggle.set(false), t: translate })));
32
- } else if (ReactDOM && typeof ReactDOM.render === 'function') {
33
- ReactDOM.render(React.createElement(CronScreen, { ctx, toggle, onClose: () => toggle.set(false), t: translate }), container);
34
- }
35
- };
36
-
37
- const applyActive = () => {
38
- if (toggle.isOpen()) {
39
- // Repair a dropped stylesheet before the panel paints, so opening the
40
- // screen never shows an unstyled page (see startStyleSelfHeal).
41
- ensureStyles();
42
- document.documentElement.setAttribute(ACTIVE_ATTR, '');
43
- document.dispatchEvent(new CustomEvent(ACTIVATE_EVENT, { detail: PANEL }));
44
- ensure();
45
- } else {
46
- document.documentElement.removeAttribute(ACTIVE_ATTR);
47
- teardownPanel();
48
- }
49
- };
50
-
51
- const onOtherActivate = (event) => {
52
- if (event.detail !== PANEL && toggle.isOpen()) toggle.set(false);
53
- };
54
- const onOutsideClick = (event) => {
55
- if (!toggle.isOpen()) return;
56
- if (!shouldDismissPanel(event.target)) return;
57
- toggle.set(false);
58
- };
59
-
60
- const waitObserver = new MutationObserver(ensure);
61
- waitObserver.observe(document.body, { childList: true, subtree: true });
62
- document.addEventListener(ACTIVATE_EVENT, onOtherActivate);
63
- document.addEventListener('click', onOutsideClick, true);
64
- const unsubscribe = toggle.subscribe(applyActive);
65
- applyActive();
66
- ensure();
67
-
68
- return () => {
69
- waitObserver.disconnect();
70
- document.removeEventListener(ACTIVATE_EVENT, onOtherActivate);
71
- document.removeEventListener('click', onOutsideClick, true);
72
- unsubscribe();
73
- document.documentElement.removeAttribute(ACTIVE_ATTR);
74
- teardownPanel();
75
- };
76
- }
77
-
78
- /**
79
- * Register a card into a DSH mount point. Mount points are populated via
80
- * ctx.slots.inject(mount, cb) — a direct slots.register does not throw but
81
- * also never appears in the target surface (settings plugins tab, header),
82
- * so the inject contract is mandatory (#85).
83
- */
84
- function registerIntoMount(ctx, mountName, entry, component) {
85
- if (!ctx || !ctx.slots || typeof ctx.slots.inject !== 'function') return false;
86
- try {
87
- return !!ctx.slots.inject(mountName, () => {
88
- ctx.slots.register(entry, component);
89
- });
90
- } catch (err) {
91
- console.warn('[dsh-cron] slot injection skipped:', mountName, '-', err && err.message);
92
- return false;
93
- }
94
- }
95
-
96
- function apply(ctx) {
97
- const stopStyleSelfHeal = startStyleSelfHeal();
98
-
99
- // Register the English canonical strings; rebinding the translator lets
100
- // the translation plugin drive the active language at runtime (#87).
101
- // Own the dictionary as an effect: fiber dispose/HMR removes exactly this
102
- // registration, so a re-applied plugin registers again instead of throwing
103
- // "locale namespace ... already has locale ..." into a swallowed catch and
104
- // leaving the previously registered (stale) dictionary in place.
105
- try {
106
- if (ctx.locale && typeof ctx.locale.register === 'function' && typeof ctx.effect === 'function') {
107
- ctx.effect(() => ctx.locale.register(NS, STRINGS), 'dsh-cron: locale dictionaries');
108
- } else if (ctx.locale && typeof ctx.locale.register === 'function') {
109
- ctx.locale.register(NS, STRINGS);
110
- }
111
- } catch (e) {
112
- // A plain re-registration in the same session throws; the effect form above avoids it.
113
- }
114
- try {
115
- if (ctx.locale && typeof ctx.locale.bind === 'function') {
116
- translate = ctx.locale.bind(NS);
117
- }
118
- } catch (err) {
119
- /* locale bind unavailable, fallback to default translate */
120
- }
121
-
122
- const toggle = createToggle();
123
-
124
- // The settings card lives ONLY in the plugins settings tab (#102): no
125
- // top-level section fallback — the flat sidebar list is a shared core
126
- // resource, and the card slot is proven on current builds (#85).
127
- function SettingsCardWithBoundary(props) {
128
- return React.createElement(ErrorBoundary, null, CronSettingsCard(props));
129
- }
130
- // List seat (plugins.item): the seat the Plugins page renders as the plugin's own
131
- // page with its configuration. The label is a static string on purpose — it is
132
- // resolved while the page renders, and a locale lookup there would take the whole
133
- // client batch down with it.
134
- const itemOk = registerIntoMount(ctx, 'plugins.item', {
135
- name: 'plugins.item',
136
- id: ROW_ID,
137
- order: 60,
138
- label: () => 'Cron',
139
- locale: NS,
140
- inject: () => ({ ctx, toggle }),
141
- }, SettingsCardWithBoundary);
142
- if (!itemOk) {
143
- console.warn('[dsh-cron] plugins.item slot unavailable — plugin page card not registered');
144
- }
145
- // Row seat and the legacy settings.plugin.item seat stay as fallbacks
146
- // (#102: still no top-level section fallback).
147
- const rowOk = registerIntoMount(ctx, 'plugins.row.config', {
148
- name: 'plugins.row.config',
149
- key: ROW_CONFIG_KEY,
150
- locale: NS,
151
- inject: () => ({ ctx, toggle }),
152
- }, SettingsCardWithBoundary);
153
- const cardOk = registerIntoMount(ctx, 'settings.plugin.item', {
154
- name: 'settings.plugin.item',
155
- key: NS,
156
- locale: NS,
157
- inject: () => ({ ctx, toggle }),
158
- }, SettingsCardWithBoundary);
159
- if (!cardOk) {
160
- console.warn('[dsh-cron] settings.plugin.item slot unavailable — settings card not registered');
161
- }
162
-
163
- const chipOk = registerIntoMount(ctx, 'conversation.session.header.utilities', {
164
- name: 'conversation.session.header.utilities',
165
- id: PLUGIN_ID + '.chip',
166
- order: 27,
167
- locale: NS,
168
- inject: () => ({ ctx, toggle }),
169
- }, CronChip);
170
- const cardSlot = cardOk ? 'settings.plugin.item' : undefined;
171
- const chipSlot = chipOk ? 'conversation.session.header.utilities' : undefined;
172
-
173
- const barOk = registerIntoMount(ctx, 'conversation.session.header.actions', {
174
- name: 'conversation.session.header.actions',
175
- id: PLUGIN_ID + '.sessionBar',
176
- order: 28,
177
- locale: NS,
178
- inject: (slotProps) => ({ ctx, toggle, ...slotProps }),
179
- }, function QuickBarBoundary(props) {
180
- return React.createElement(ErrorBoundary, null, React.createElement(SessionQuickActionBar, props));
181
- });
182
- const barSlot = barOk ? 'conversation.session.header.actions' : undefined;
183
-
184
- function CronChip(props) {
185
- const visible = useHeaderVisibility('showChatHeaderButton');
186
- if (!visible) return null;
187
- const chipT = props.t || translate;
188
- return React.createElement('button', {
189
- type: 'button',
190
- 'data-dsh-plugin': 'dsh-cron',
191
- style: { background: 'none', border: 'none', color: 'var(--dsw-alias-label-secondary, #999)', cursor: 'pointer', padding: '4px', display: 'inline-flex', alignItems: 'center' },
192
- title: T_KEY(chipT, 'chip.title'),
193
- 'aria-label': T_KEY(chipT, 'chip.title'),
194
- onClick: () => toggle.toggle(),
195
- dangerouslySetInnerHTML: { __html: ICON_TIMER }
196
- });
197
- }
198
-
199
- ctx.effect(() => {
200
- const off = [
201
- mountSidebarEntry(toggle, translate('sidebar.label')),
202
- mountSidebarJobs(toggle, translate('sidebar.jobsTitle'), (taskId) => { pendingTaskHighlight = taskId; }),
203
- mountCronScreen(ctx, toggle)
204
- ];
205
- return () => { for (const dispose of off) dispose(); stopStyleSelfHeal(); };
206
- }, 'dsh-cron: client overlay');
207
-
208
- exports.slots = { card: cardSlot, chip: chipSlot, sessionBar: barSlot };
209
- module.exports.panelDismissRule = shouldDismissPanel;
210
- module.exports.sidebarJobsSeatIsCurrent = sidebarJobsSeatIsCurrent;
211
- module.exports.updateHeaderSettings = updateHeaderSettings;
212
- module.exports.useHeaderVisibility = useHeaderVisibility;
213
- module.exports.getHeaderSettings = () => currentHeaderSettings;
214
- }
215
-
216
- module.exports = { apply, inject: ['slots', 'locale'] };
217
- return module.exports;
218
- }
219
- })