@goodandready/dsh-cron 0.3.43 → 0.3.45

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,176 +0,0 @@
1
- /**
2
- * 24-Hour Schedule Timeline & Cost Heatmap Modal (#332, #333)
3
- * Visual schedule collision detection and weekly 7x24 token burn heatmap.
4
- * Complies with Audit #203 (0 raw rgba, 0 6-digit hex colors).
5
- */
6
- function renderTimelineHeatmapModal({
7
- isOpen,
8
- onClose,
9
- activeTab,
10
- onSelectTab,
11
- timelineData,
12
- heatmapData,
13
- isLoading,
14
- t
15
- }) {
16
- if (!isOpen) return null;
17
-
18
- const tab = activeTab || 'timeline';
19
- const timeline = timelineData || { buckets: [], totalRuns: 0, peakHoursCount: 0, maxConcurrent: 3 };
20
- const heatmap = heatmapData || { matrix: [], dayLabels: [], hourLabels: [], totalCostUsd: 0, totalTokens: 0, maxCostHour: 0 };
21
-
22
- return React.createElement('div', {
23
- className: 'dsh-cron-modal-overlay',
24
- onClick: onClose
25
- },
26
- React.createElement('div', {
27
- className: 'dsh-cron-modal',
28
- style: { maxWidth: '960px', width: '94vw', maxHeight: '88vh', display: 'flex', flexDirection: 'column', background: 'var(--dsw-alias-bg-base, #111)', color: 'var(--dsw-alias-label-primary, #ddd)', border: '1px solid var(--dsw-alias-border-l2, #333)', borderRadius: '8px' },
29
- role: 'dialog',
30
- 'aria-modal': 'true',
31
- onClick: (e) => e.stopPropagation()
32
- },
33
- // Header
34
- React.createElement('div', {
35
- style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '14px 18px', borderBottom: '1px solid var(--dsw-alias-border-l2, #333)', background: 'var(--dsw-alias-bg-layer-2, #111)' }
36
- },
37
- React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } },
38
- React.createElement('span', { style: { fontSize: '20px' } }, tab === 'timeline' ? '⏱' : '🔥'),
39
- React.createElement('div', null,
40
- React.createElement('div', { style: { fontWeight: '600', fontSize: '15px', color: 'var(--dsw-alias-label-primary, #fff)' } },
41
- tab === 'timeline' ? (T_KEY(t, 'timeline.modalTitle')) : (T_KEY(t, 'heatmap.modalTitle'))
42
- ),
43
- React.createElement('div', { style: { fontSize: '11.5px', color: 'var(--dsw-alias-label-secondary, #888)', marginTop: '2px' } },
44
- tab === 'timeline'
45
- ? (timeline.totalRuns + ' runs projected · ' + (timeline.peakHoursCount ? '⚠️ ' + timeline.peakHoursCount + ' peak hours' : '✓ balanced concurrency'))
46
- : ('$' + Number(heatmap.totalCostUsd || 0).toFixed(4) + ' USD · ' + Number(heatmap.totalTokens || 0).toLocaleString() + ' tokens')
47
- )
48
- )
49
- ),
50
- React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
51
- React.createElement('button', {
52
- type: 'button',
53
- className: 'dsh-cron-btn-secondary',
54
- style: { padding: '4px 12px', fontSize: '12px', fontWeight: tab === 'timeline' ? '600' : '400', background: tab === 'timeline' ? 'var(--dsw-alias-bg-layer-3, #222)' : 'transparent' },
55
- onClick: () => onSelectTab && onSelectTab('timeline')
56
- }, '⏱ ' + (T_KEY(t, 'timeline.tabTimeline'))),
57
- React.createElement('button', {
58
- type: 'button',
59
- className: 'dsh-cron-btn-secondary',
60
- style: { padding: '4px 12px', fontSize: '12px', fontWeight: tab === 'heatmap' ? '600' : '400', background: tab === 'heatmap' ? 'var(--dsw-alias-bg-layer-3, #222)' : 'transparent' },
61
- onClick: () => onSelectTab && onSelectTab('heatmap')
62
- }, '🔥 ' + (T_KEY(t, 'heatmap.tabHeatmap'))),
63
- React.createElement('button', {
64
- type: 'button',
65
- className: 'dsh-cron-icon-btn',
66
- onClick: onClose,
67
- style: { marginLeft: '8px' }
68
- }, React.createElement('span', null, '✕'))
69
- )
70
- ),
71
-
72
- // Content
73
- React.createElement('div', {
74
- style: { padding: '16px 18px', overflowY: 'auto', flex: 1, display: 'flex', flexDirection: 'column', gap: '14px' }
75
- },
76
- isLoading ? React.createElement('div', { style: { padding: '40px', textAlign: 'center', color: 'var(--dsw-alias-label-secondary, #888)' } }, 'Loading visualization data...') : (
77
- tab === 'timeline' ? (
78
- // 24H Timeline View
79
- React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
80
- React.createElement('div', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)', display: 'flex', justifyContent: 'space-between' } },
81
- React.createElement('span', null, T_KEY(t, 'timeline.legendDesc')),
82
- React.createElement('span', { style: { color: 'var(--dsh-cron-warning, #fa0)' } }, '⚠️ ' + (T_KEY(t, 'timeline.peakWarning')) + ' (' + timeline.maxConcurrent + ')')
83
- ),
84
- React.createElement('div', {
85
- style: { display: 'grid', gridTemplateColumns: 'repeat(12, 1fr)', gap: '8px', marginTop: '6px' }
86
- },
87
- (timeline.buckets || []).map((b) => {
88
- const isPeak = b.isPeak, hasRuns = b.count > 0;
89
- return React.createElement('div', {
90
- key: b.index,
91
- style: {
92
- background: isPeak ? 'color-mix(in srgb, var(--dsh-cron-danger, #e33) 12%, var(--dsw-alias-bg-layer-2, #111))' : (hasRuns ? 'var(--dsw-alias-bg-layer-2, #111)' : 'var(--dsw-alias-bg-base, #111)'),
93
- border: isPeak ? '1px solid var(--dsh-cron-danger, #e33)' : (hasRuns ? '1px solid var(--dsw-alias-border-l2, #333)' : '1px dashed var(--dsw-alias-border-l2, #222)'),
94
- borderRadius: '6px', padding: '8px', minHeight: '75px', display: 'flex', flexDirection: 'column', justifyContent: 'space-between'
95
- }
96
- },
97
- React.createElement('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: '11px' } },
98
- React.createElement('span', { style: { fontWeight: '600', color: isPeak ? 'var(--dsh-cron-danger, #e33)' : 'var(--dsw-alias-label-primary, #fff)' } }, b.label),
99
- hasRuns ? React.createElement('span', { style: { fontSize: '10px', padding: '1px 5px', borderRadius: '8px', background: isPeak ? 'var(--dsh-cron-danger, #e33)' : 'var(--dsw-alias-bg-layer-3, #222)', color: '#fff' } }, b.count) : null
100
- ),
101
- React.createElement('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '3px', marginTop: '4px' } },
102
- (b.runs || []).slice(0, 3).map((r, rIdx) => React.createElement('span', {
103
- key: rIdx, title: (r.title || r.taskId) + ' (' + r.time + ')',
104
- style: { fontSize: '9.5px', fontFamily: 'monospace', padding: '1px 4px', borderRadius: '3px', background: 'var(--dsw-alias-bg-base, #111)', border: '1px solid var(--dsw-alias-border-l2, #333)', maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }
105
- }, r.title || r.taskId))
106
- )
107
- );
108
- })
109
- )
110
- )
111
- ) : (
112
- // 7x24 Cost & Token Heatmap View
113
- React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
114
- React.createElement('div', { style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)', display: 'flex', justifyContent: 'space-between' } },
115
- React.createElement('span', null, T_KEY(t, 'heatmap.matrixDesc')),
116
- React.createElement('span', null, 'Max hour spend: $' + Number(heatmap.maxCostHour || 0).toFixed(4))
117
- ),
118
- React.createElement('div', {
119
- style: { overflowX: 'auto', paddingBottom: '8px' }
120
- },
121
- React.createElement('table', {
122
- style: { borderCollapse: 'collapse', width: '100%', minWidth: '700px', fontSize: '10.5px' }
123
- },
124
- React.createElement('thead', null,
125
- React.createElement('tr', null,
126
- React.createElement('th', { style: { padding: '4px 6px', textAlign: 'left', color: 'var(--dsw-alias-label-secondary, #888)' } }, 'Day'),
127
- Array.from({ length: 24 }, (_, hour) => React.createElement('th', {
128
- key: hour,
129
- style: { padding: '4px 2px', textAlign: 'center', color: 'var(--dsw-alias-label-secondary, #888)', fontWeight: '400' }
130
- }, String(hour).padStart(2, '0')))
131
- )
132
- ),
133
- React.createElement('tbody', null,
134
- (heatmap.matrix || []).map((row, dIdx) => React.createElement('tr', { key: dIdx },
135
- React.createElement('td', { style: { padding: '4px 6px', fontWeight: '600', color: 'var(--dsw-alias-label-primary, #ddd)' } }, (heatmap.dayLabels && heatmap.dayLabels[dIdx]) || 'Day'),
136
- row.map((cell, hIdx) => {
137
- const intensity = cell.costIntensity || 0;
138
- const hasSpend = cell.costUsd > 0;
139
- const bg = hasSpend
140
- ? 'color-mix(in srgb, var(--dsh-cron-primary, #4af) ' + Math.max(15, Math.round(intensity * 100)) + '%, transparent)'
141
- : 'transparent';
142
- return React.createElement('td', {
143
- key: hIdx,
144
- title: cell.dayLabel + ' ' + cell.hourLabel + ': $' + cell.costUsd + ' (' + cell.tokens.toLocaleString() + ' tokens, ' + cell.runs + ' runs)',
145
- style: {
146
- padding: '3px',
147
- textAlign: 'center',
148
- background: bg,
149
- border: '1px solid var(--dsw-alias-border-l2, #222)',
150
- cursor: hasSpend ? 'pointer' : 'default'
151
- }
152
- }, hasSpend ? React.createElement('span', { style: { fontSize: '9px', color: intensity > 0.5 ? '#fff' : 'var(--dsw-alias-label-primary, #ddd)' } }, '$' + (cell.costUsd >= 0.01 ? cell.costUsd.toFixed(2) : cell.costUsd.toFixed(3).slice(1))) : '·');
153
- })
154
- ))
155
- )
156
- )
157
- )
158
- )
159
- )
160
- )
161
- ),
162
-
163
- // Footer
164
- React.createElement('div', {
165
- style: { display: 'flex', justifyContent: 'flex-end', padding: '12px 18px', borderTop: '1px solid var(--dsw-alias-border-l2, #333)', background: 'var(--dsw-alias-bg-layer-2, #111)' }
166
- },
167
- React.createElement('button', {
168
- type: 'button',
169
- className: 'dsh-cron-btn-secondary',
170
- onClick: onClose,
171
- style: { padding: '6px 16px', fontSize: '12px' }
172
- }, T_KEY(t, 'chainGraph.close'))
173
- )
174
- )
175
- );
176
- }
@@ -1,457 +0,0 @@
1
- function CronScreen(props) {
2
- const { ctx, toggle, onClose } = props;
3
- const t = props.t || translate;
4
- const [isOpen, setIsOpen] = React.useState(toggle && typeof toggle.isOpen === 'function' ? toggle.isOpen() : true);
5
- React.useEffect(() => {
6
- if (!toggle || typeof toggle.subscribe !== 'function') return;
7
- return toggle.subscribe((val) => setIsOpen(val));
8
- }, [toggle]);
9
- if (!isOpen) return null;
10
- const [tab, setTab] = React.useState('all');
11
- const [query, setQuery] = React.useState('');
12
- // Facet filters (#40): applied client-side over the already-loaded list so
13
- // toggling them is instant and does not touch the polling request.
14
- const [filterType, setFilterType] = React.useState('');
15
- const [filterModel, setFilterModel] = React.useState('');
16
- const [filterChannel, setFilterChannel] = React.useState('');
17
- const [filtersOpen, setFiltersOpen] = React.useState(false);
18
- const [tasks, setTasks] = React.useState([]);
19
- const [recs, setRecs] = React.useState([]);
20
- const [loading, setLoading] = React.useState(false);
21
- const [fetchError, setFetchError] = React.useState(null);
22
- const [dropdownOpen, setDropdownOpen] = React.useState(false);
23
-
24
- // Export/import state (#42)
25
- const [transferBusy, setTransferBusy] = React.useState(false);
26
- const [importDoc, setImportDoc] = React.useState(null);
27
- const [importSummary, setImportSummary] = React.useState(null);
28
- const [importStrategy, setImportStrategy] = React.useState('skip');
29
- const importFileRef = React.useRef(null);
30
-
31
- // Manual / Edit modal state
32
- const [manualModalOpen, setManualModalOpen] = React.useState(false);
33
- const [formId, setFormId] = React.useState(null);
34
- const [formTitle, setFormTitle] = React.useState('');
35
- const [formSchedule, setFormSchedule] = React.useState('');
36
- const [formType, setFormType] = React.useState('llm');
37
- const [formPrompt, setFormPrompt] = React.useState('');
38
- const [formProvider, setFormProvider] = React.useState('');
39
- const [formModel, setFormModel] = React.useState('');
40
- const [formFallbackModel, setFormFallbackModel] = React.useState('');
41
- const [formSilentRule, setFormSilentRule] = React.useState('');
42
- const [formInspectOnFailure, setFormInspectOnFailure] = React.useState(false);
43
- const [formRequireApproval, setFormRequireApproval] = React.useState(false);
44
- const [formDelivery, setFormDelivery] = React.useState('isolated');
45
- const [selectedTaskMeta, setSelectedTaskMeta] = React.useState(null);
46
- const [modalTab, setModalTab] = React.useState('params');
47
- const [taskHistory, setTaskHistory] = React.useState([]);
48
- const [historyLoading, setHistoryLoading] = React.useState(false);
49
- const [retryingDeliveryId, setRetryingDeliveryId] = React.useState(null);
50
- const [formNotifyTelegram, setFormNotifyTelegram] = React.useState(false);
51
- const [formChannels, setFormChannels] = React.useState([]);
52
- const [formTemplate, setFormTemplate] = React.useState('');
53
- const [formOnlyOnFailure, setFormOnlyOnFailure] = React.useState(false);
54
- const [formTimeoutSeconds, setFormTimeoutSeconds] = React.useState(1800);
55
- const [formOverlapPolicy, setFormOverlapPolicy] = React.useState('skip');
56
- const [formKanbanMode, setFormKanbanMode] = React.useState('none');
57
- const [formOnSuccess, setFormOnSuccess] = React.useState('');
58
- const [formOnFailure, setFormOnFailure] = React.useState('');
59
- const [formDependsOn, setFormDependsOn] = React.useState('');
60
- const [formJoinPolicy, setFormJoinPolicy] = React.useState('all_success');
61
- const [formElseTask, setFormElseTask] = React.useState('');
62
- const [formAutoHeal, setFormAutoHeal] = React.useState(false);
63
- // Adaptive polling state (#329)
64
- const [formAdaptiveEnabled, setFormAdaptiveEnabled] = React.useState(false);
65
- const [formAdaptiveMinInterval, setFormAdaptiveMinInterval] = React.useState('5m');
66
- const [formAdaptiveMaxInterval, setFormAdaptiveMaxInterval] = React.useState('2h');
67
- const [formAdaptiveBackoffFactor, setFormAdaptiveBackoffFactor] = React.useState('1.5');
68
- const [formAdaptiveIdleThreshold, setFormAdaptiveIdleThreshold] = React.useState('3');
69
-
70
- // Live Logs state (#336)
71
- const [liveLogsModalOpen, setLiveLogsModalOpen] = React.useState(false);
72
- const [liveLogsTaskId, setLiveLogsTaskId] = React.useState('');
73
- const [liveLogsTaskTitle, setLiveLogsTaskTitle] = React.useState('');
74
- const [liveLogsLines, setLiveLogsLines] = React.useState([]);
75
- const [liveLogsStatus, setLiveLogsStatus] = React.useState('idle');
76
- const [liveLogsCompleted, setLiveLogsCompleted] = React.useState(false);
77
- const [liveLogsAutoScroll, setLiveLogsAutoScroll] = React.useState(true);
78
- const [chainGraphModalOpen, setChainGraphModalOpen] = React.useState(false);
79
- const [chainGraphData, setChainGraphData] = React.useState(null);
80
- const [chainGraphLoading, setChainGraphLoading] = React.useState(false);
81
- const [chainGraphRunId, setChainGraphRunId] = React.useState(null);
82
- // Analytics Digest state (#330, GH #8)
83
- const [digestOpen, setDigestOpen] = React.useState(false);
84
- const [digestData, setDigestData] = React.useState(null);
85
- const [digestMarkdown, setDigestMarkdown] = React.useState('');
86
- const [digestLoading, setDigestLoading] = React.useState(false);
87
- const [periodDays, setPeriodDays] = React.useState(7);
88
- const [sendStatus, setSendStatus] = React.useState(null);
89
-
90
- // Timeline & Cost Heatmap state (#332, #333, GH #8)
91
- const [timelineOpen, setTimelineOpen] = React.useState(false);
92
- const [timelineData, setTimelineData] = React.useState(null);
93
- const [heatmapData, setHeatmapData] = React.useState(null);
94
- const [timelineLoading, setTimelineLoading] = React.useState(false);
95
- const [timelineTab, setTimelineTab] = React.useState('timeline');
96
-
97
- const [formHeartbeatIntervalSeconds, setFormHeartbeatIntervalSeconds] = React.useState(0);
98
- const [formGracePeriodSeconds, setFormGracePeriodSeconds] = React.useState(300);
99
- const [formPreflightType, setFormPreflightType] = React.useState('none');
100
- const [formPreflightTarget, setFormPreflightTarget] = React.useState('');
101
- const [formPriority, setFormPriority] = React.useState(5);
102
- const [formConcurrencyGroup, setFormConcurrencyGroup] = React.useState('default');
103
- const [formWakeTriggerType, setFormWakeTriggerType] = React.useState('none');
104
- const [formWakeTriggerPath, setFormWakeTriggerPath] = React.useState('');
105
- const [formWakeTriggerMinCount, setFormWakeTriggerMinCount] = React.useState(1);
106
- const [formWakeTriggerConsume, setFormWakeTriggerConsume] = React.useState(true);
107
- const [formWorkWindowHours, setFormWorkWindowHours] = React.useState('');
108
- const [formWorkWindowPolicy, setFormWorkWindowPolicy] = React.useState('skip');
109
- const [formTimeBoxMinutes, setFormTimeBoxMinutes] = React.useState(0);
110
- const [formWriteScopes, setFormWriteScopes] = React.useState('');
111
- const [formInputHashPaths, setFormInputHashPaths] = React.useState('');
112
- const [formSkipIfUnchanged, setFormSkipIfUnchanged] = React.useState(false);
113
- const [formSelfHealingCommand, setFormSelfHealingCommand] = React.useState('');
114
- const [formAutoDiagnose, setFormAutoDiagnose] = React.useState(false);
115
- const [schedulePreviewRuns, setSchedulePreviewRuns] = React.useState(null);
116
- const [dryRunResult, setDryRunResult] = React.useState(null);
117
- const [archiveModalOpen, setArchiveModalOpen] = React.useState(false);
118
- const [archiveTask, setArchiveTask] = React.useState(null);
119
- const [archiveRuns, setArchiveRuns] = React.useState([]);
120
- const [archiveLoading, setArchiveLoading] = React.useState(false);
121
- const [archiveOffset, setArchiveOffset] = React.useState(0);
122
- const [archiveTotal, setArchiveTotal] = React.useState(0);
123
- const [formTimezone, setFormTimezone] = React.useState('');
124
- const [formMisfirePolicy, setFormMisfirePolicy] = React.useState('skip');
125
- const [formMaxRetries, setFormMaxRetries] = React.useState(0);
126
- const [formPermissionPreset, setFormPermissionPreset] = React.useState('default');
127
- const [formAgentPreset, setFormAgentPreset] = React.useState('');
128
- const [formSessionTitle, setFormSessionTitle] = React.useState('');
129
- const [formTargetSessionId, setFormTargetSessionId] = React.useState('');
130
- const [formTargetSessionReset, setFormTargetSessionReset] = React.useState('never');
131
- const [formEnv, setFormEnv] = React.useState('');
132
- const [formCwd, setFormCwd] = React.useState('');
133
- const [formWorkspaceId, setFormWorkspaceId] = React.useState('');
134
- const [formWorktree, setFormWorktree] = React.useState(false);
135
- const [formKeepWorktree, setFormKeepWorktree] = React.useState(false);
136
- const [formCaptureGitDiff, setFormCaptureGitDiff] = React.useState(false);
137
- const [formHttpMethod, setFormHttpMethod] = React.useState('GET');
138
- const [formHttpUrl, setFormHttpUrl] = React.useState('');
139
- const [formHttpHeaders, setFormHttpHeaders] = React.useState('');
140
- const [formHttpBody, setFormHttpBody] = React.useState('');
141
- const [formSshProfileId, setFormSshProfileId] = React.useState('');
142
- const [formSshTarget, setFormSshTarget] = React.useState('');
143
- const [formSshKeyPath, setFormSshKeyPath] = React.useState('');
144
- const [formDockerImage, setFormDockerImage] = React.useState('');
145
- const [formNodePath, setFormNodePath] = React.useState('');
146
- const [formPythonPath, setFormPythonPath] = React.useState('');
147
- const [formSkillName, setFormSkillName] = React.useState('');
148
- const [formWorkflowName, setFormWorkflowName] = React.useState('');
149
- const [stats, setStats] = React.useState(null);
150
-
151
- const initialFormSnapshotRef = React.useRef(null);
152
-
153
- const getFormSnapshot = () => JSON.stringify({
154
- title: String(formTitle || '').trim(),
155
- schedule: String(formSchedule || '').trim(),
156
- type: String(formType || 'llm'),
157
- prompt: String(formPrompt || '').trim(),
158
- provider: String(formProvider || ''),
159
- model: String(formModel || ''),
160
- fallbackModel: String(formFallbackModel || ''),
161
- silentRule: String(formSilentRule || ''),
162
- inspectOnFailure: Boolean(formInspectOnFailure),
163
- requireApproval: Boolean(formRequireApproval),
164
- delivery: String(formDelivery || 'isolated'),
165
- notifyTelegram: Boolean(formNotifyTelegram),
166
- channels: Array.isArray(formChannels) ? [...formChannels].sort() : [],
167
- template: String(formTemplate || '').trim(),
168
- onlyOnFailure: Boolean(formOnlyOnFailure),
169
- timeoutSeconds: Number(formTimeoutSeconds) || 1800,
170
- overlapPolicy: String(formOverlapPolicy || 'skip'),
171
- kanbanMode: String(formKanbanMode || 'none'),
172
- onSuccess: String(formOnSuccess || '').trim(),
173
- onFailure: String(formOnFailure || '').trim(),
174
- heartbeatIntervalSeconds: Number(formHeartbeatIntervalSeconds) || 0,
175
- gracePeriodSeconds: Number(formGracePeriodSeconds) || 300,
176
- preflightType: String(formPreflightType || 'none'),
177
- preflightTarget: String(formPreflightTarget || '').trim(),
178
- priority: Number(formPriority) || 5,
179
- concurrencyGroup: String(formConcurrencyGroup || 'default').trim(),
180
- selfHealingCommand: String(formSelfHealingCommand || '').trim(),
181
- autoDiagnose: Boolean(formAutoDiagnose),
182
- timezone: String(formTimezone || '').trim(),
183
- misfirePolicy: String(formMisfirePolicy || 'skip'),
184
- maxRetries: Number(formMaxRetries) || 0,
185
- permissionPreset: String(formPermissionPreset || 'default'),
186
- agentPreset: String(formAgentPreset || '').trim(),
187
- targetSessionId: String(formTargetSessionId || '').trim(),
188
- targetSessionReset: String(formTargetSessionReset || 'never'),
189
- env: String(formEnv || '').trim(),
190
- cwd: String(formCwd || '').trim(),
191
- workspaceId: String(formWorkspaceId || '').trim(),
192
- worktree: Boolean(formWorktree),
193
- keepWorktree: Boolean(formKeepWorktree),
194
- captureGitDiff: Boolean(formCaptureGitDiff),
195
- httpMethod: String(formHttpMethod || 'GET'),
196
- httpUrl: String(formHttpUrl || '').trim(),
197
- httpHttpHeaders: String(formHttpHeaders || '').trim(),
198
- httpBody: String(formHttpBody || '').trim(),
199
- sshProfileId: String(formSshProfileId || '').trim(),
200
- sshTarget: String(formSshTarget || '').trim(),
201
- sshKeyPath: String(formSshKeyPath || '').trim(),
202
- dockerImage: String(formDockerImage || '').trim(),
203
- nodePath: String(formNodePath || '').trim(),
204
- pythonPath: String(formPythonPath || '').trim(),
205
- skillName: String(formSkillName || '').trim(),
206
- workflowName: String(formWorkflowName || '').trim(),
207
- });
208
-
209
- const isFormDirty = () => {
210
- if (!manualModalOpen) return false;
211
- if (initialFormSnapshotRef.current !== null) {
212
- return getFormSnapshot() !== initialFormSnapshotRef.current;
213
- }
214
- return Boolean(formTitle.trim() || formPrompt.trim());
215
- };
216
-
217
- const closeManualModalWithConfirm = () => {
218
- if (isFormDirty()) {
219
- if (!confirm(T_KEY(t, 'modal.confirmDiscard') || 'Discard unsaved changes?')) {
220
- return;
221
- }
222
- }
223
- initialFormSnapshotRef.current = null;
224
- setManualModalOpen(false);
225
- };
226
-
227
- // Live execution indicator (#35): a light 1s tick only while some task
228
- // is actually running.
229
- const tasksRef = React.useRef([]);
230
- const [nowTick, setNowTick] = React.useState(0);
231
- React.useEffect(() => {
232
- tasksRef.current = tasks;
233
- }, [tasks]);
234
- React.useEffect(() => {
235
- const tick = setInterval(() => {
236
- if (tasksRef.current.some((t2) => t2.running)) setNowTick((v) => v + 1);
237
- }, 1000);
238
- return () => clearInterval(tick);
239
- }, []);
240
-
241
- // Settings modal state
242
- const [settingsModalOpen, setSettingsModalOpen] = React.useState(false);
243
- const [settingsBotToken, setSettingsBotToken] = React.useState('');
244
- const [settingsChatId, setSettingsChatId] = React.useState('');
245
- const [settingsNotifyGlobal, setSettingsNotifyGlobal] = React.useState(false);
246
- const [settingsOnlyOnFailureGlobal, setSettingsOnlyOnFailureGlobal] = React.useState(false);
247
- const [settingsKanbanUrl, setSettingsKanbanUrl] = React.useState('http://127.0.0.1:3000');
248
- const [settingsDelivery, setSettingsDelivery] = React.useState({});
249
- const [settingsSections, setSettingsSections] = React.useState({ channels: true });
250
- const [settingsHasDefault, setSettingsHasDefault] = React.useState(false);
251
- const [settingsHasCustomBotToken, setSettingsHasCustomBotToken] = React.useState(false);
252
- const [testStatus, setTestStatus] = React.useState(null);
253
-
254
- // DSH dialog state
255
- const [dshModalOpen, setDshModalOpen] = React.useState(false);
256
- const [dshPrompt, setDshPrompt] = React.useState('');
257
- const [dshLoading, setDshLoading] = React.useState(false);
258
-
259
- // Models list state
260
- const [providers, setProviders] = React.useState([]);
261
- const [models, setModels] = React.useState([]);
262
- const [defaultModelInfo, setDefaultModelInfo] = React.useState(null);
263
-
264
- React.useEffect(() => {
265
- const onKey = (e) => {
266
- if (e.key === 'Escape') {
267
- if (dropdownOpen) { setDropdownOpen(false); return; }
268
- if (manualModalOpen) { closeManualModalWithConfirm(); return; }
269
- if (settingsModalOpen) { setSettingsModalOpen(false); return; }
270
- if (dshModalOpen && !dshLoading) { setDshModalOpen(false); return; }
271
- if (onClose) onClose();
272
- else toggle.set(false);
273
- }
274
- };
275
- window.addEventListener('keydown', onKey);
276
- return () => window.removeEventListener('keydown', onKey);
277
- }, [manualModalOpen, settingsModalOpen, dshModalOpen, dropdownOpen, onClose]);
278
-
279
- /** #40: facet filtering happens client-side over the loaded list. */
280
- const visibleTasks = React.useMemo(() => { let list = tasks;
281
- if (filterType) list = list.filter((x) => (x.type || 'llm') === filterType);
282
- if (filterModel) list = list.filter((x) => String(x.model || '').split('/').pop() === filterModel);
283
- if (filterChannel) {
284
- list = list.filter((x) => {
285
- const channels = Array.isArray(x.channels) && x.channels.length
286
- ? x.channels
287
- : [x.notifyTelegram ? 'telegram' : null, (x.kanbanMode || 'none') !== 'none' ? 'kanban' : null].filter(Boolean);
288
- return channels.includes(filterChannel);
289
- });
290
- }
291
- return list;
292
- }, [tasks, filterType, filterModel, filterChannel]);
293
-
294
- const filterTypeOptions = React.useMemo(
295
- () => Array.from(new Set(tasks.map((x) => x.type || 'llm'))).sort(),
296
- [tasks]
297
- );
298
-
299
- const filterModelOptions = React.useMemo(
300
- () => Array.from(new Set(tasks.map((x) => String(x.model || '').split('/').pop()).filter(Boolean))).sort(),
301
- [tasks]
302
- );
303
-
304
- const resetFilters = () => {
305
- setFilterType('');
306
- setFilterModel('');
307
- setFilterChannel('');
308
- };
309
-
310
- /** #34: scroll to and flash the task the sidebar list asked for. */
311
- React.useEffect(() => {
312
- if (!pendingTaskHighlight || tasks.length === 0) return;
313
- const id = pendingTaskHighlight;
314
- pendingTaskHighlight = null;
315
- const node = document.querySelector('[data-task-id="' + id + '"]');
316
- if (!node) return;
317
- if (typeof node.scrollIntoView === 'function') node.scrollIntoView({ block: 'center' });
318
- node.classList.add('dsh-cron-task-highlight');
319
- setTimeout(() => { try { node.classList.remove('dsh-cron-task-highlight'); } catch (err) { /* node unmounted */ } }, 2500);
320
- }, [tasks]);
321
-
322
- const fetchGenRef = React.useRef(0);
323
-
324
- const fetchTasks = async () => {
325
- const gen = ++fetchGenRef.current;
326
- setLoading(true);
327
- setFetchError(null);
328
- const controller = (typeof AbortController !== 'undefined') ? new AbortController() : null;
329
- const timer = controller ? setTimeout(() => controller.abort(), 15000) : null;
330
- try {
331
- const res = await fetch('/dsh-cron/tasks?status=' + encodeURIComponent(tab) + '&query=' + encodeURIComponent(query), {
332
- signal: controller ? controller.signal : undefined,
333
- });
334
- const data = await res.json();
335
- if (gen !== fetchGenRef.current) return;
336
- if (data && data.ok !== false) {
337
- setTasks(data.tasks || []);
338
- setRecs(data.recommendations || []);
339
- setStats(data.stats || null);
340
- } else {
341
- setFetchError(data && data.error ? data.error : T_KEY(t, 'list.loadErrorPrefix'));
342
- }
343
- } catch (err) {
344
- if (gen !== fetchGenRef.current) return;
345
- console.error('[dsh-cron] fetch tasks error:', err);
346
- setFetchError(err.message || T_KEY(t, 'list.loadErrorPrefix'));
347
- } finally {
348
- if (timer) clearTimeout(timer);
349
- if (gen === fetchGenRef.current) {
350
- setLoading(false);
351
- }
352
- }
353
- };
354
-
355
- const loadModels = async (providerName) => {
356
- const controller = (typeof AbortController !== 'undefined') ? new AbortController() : null;
357
- const timer = controller ? setTimeout(() => controller.abort(), 15000) : null;
358
- try {
359
- const url = providerName ? '/dsh-cron/models?provider=' + encodeURIComponent(providerName) : '/dsh-cron/models';
360
- const res = await fetch(url, { signal: controller ? controller.signal : undefined });
361
- const data = await res.json();
362
- if (data && data.ok) {
363
- if (!providerName) {
364
- setProviders(data.providers || []);
365
- setDefaultModelInfo(data.defaultModel || data.current || null);
366
- if (data.defaultModel?.models) {
367
- setModels(data.defaultModel.models);
368
- }
369
- } else {
370
- setModels(data.models || []);
371
- }
372
- }
373
- } catch (err) {
374
- console.error('[dsh-cron] load models error:', err);
375
- } finally {
376
- if (timer) clearTimeout(timer);
377
- }
378
- };
379
-
380
- const lastEtagRef = React.useRef('');
381
-
382
- React.useEffect(() => {
383
- fetchTasks();
384
-
385
- let timerId = null;
386
- let isDestroyed = false;
387
- let pollController = null;
388
-
389
- const doPoll = () => {
390
- if (isDestroyed) return;
391
- const pollGen = ++fetchGenRef.current;
392
- const headers = {};
393
- if (lastEtagRef.current) headers['If-None-Match'] = lastEtagRef.current;
394
-
395
- if (pollController) pollController.abort();
396
- pollController = (typeof AbortController !== 'undefined') ? new AbortController() : null;
397
-
398
- const fetchOpts = { headers };
399
- if (pollController) fetchOpts.signal = pollController.signal;
400
-
401
- const pollTimer = pollController ? setTimeout(() => { try { pollController.abort(); } catch (abortErr) { void abortErr; } }, 15000) : null;
402
- fetch('/dsh-cron/tasks?status=' + encodeURIComponent(tab) + '&query=' + encodeURIComponent(query), fetchOpts)
403
- .then(res => {
404
- if (isDestroyed || pollGen !== fetchGenRef.current) return null;
405
- if (res.status === 304) {
406
- // Not modified: skip parsing JSON
407
- return null;
408
- }
409
- const etag = res.headers.get('ETag');
410
- if (etag) lastEtagRef.current = etag;
411
- return res.json();
412
- })
413
- .then(data => {
414
- if (isDestroyed || pollGen !== fetchGenRef.current) return;
415
- if (data && data.ok) {
416
- setTasks(data.tasks || []);
417
- setRecs(data.recommendations || []);
418
- setStats(data.stats || null);
419
- }
420
- })
421
- .catch(err => {
422
- if (err && err.name === 'AbortError') return;
423
- })
424
- .finally(() => {
425
- if (pollTimer) clearTimeout(pollTimer);
426
- if (isDestroyed) return;
427
- // Adaptive interval: 30s when tab is hidden, 8s when active (#134)
428
- const intervalMs = (typeof document !== 'undefined' && document.hidden) ? 30000 : 8000;
429
- timerId = setTimeout(doPoll, intervalMs);
430
- });
431
- };
432
-
433
- // Trigger immediate fetch when visibility returns
434
- const onVisibilityChange = () => {
435
- if (typeof document !== 'undefined' && !document.hidden) {
436
- if (timerId) clearTimeout(timerId);
437
- doPoll();
438
- }
439
- };
440
-
441
- if (typeof document !== 'undefined') {
442
- document.addEventListener('visibilitychange', onVisibilityChange);
443
- }
444
-
445
- timerId = setTimeout(doPoll, 8000);
446
-
447
- return () => {
448
- isDestroyed = true;
449
- if (timerId) clearTimeout(timerId);
450
- if (pollController) pollController.abort();
451
- if (typeof document !== 'undefined') {
452
- document.removeEventListener('visibilitychange', onVisibilityChange);
453
- }
454
- };
455
- }, [tab, query]);
456
- React.useEffect(() => { loadModels(); }, []);
457
-