@goodandready/dsh-cron 0.3.47 → 0.3.49
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/README.md +2 -2
- package/lib/client.css +2 -0
- package/lib/client.js +42 -8
- package/lib/cron-tool.js +5 -1
- package/lib/git-diff.js +17 -5
- package/lib/index.js +3 -0
- package/lib/path-safety.js +76 -0
- package/lib/routes/api-actions.js +2 -0
- package/lib/routes/api-collection.js +1 -0
- package/lib/routes/api-import-export.js +3 -2
- package/lib/routes/api-item.js +17 -9
- package/lib/routes/api.js +1 -1
- package/lib/runtimes/runner-external.js +28 -15
- package/lib/settings.js +1 -1
- package/lib/store/store.js +15 -28
- package/lib/wake-triggers.js +3 -49
- package/lib/watcher.js +2 -33
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -417,7 +417,7 @@ Developer-facing, no behaviour change. `parseScheduleExpression` was split into
|
|
|
417
417
|
- **Self-Healing Runbooks & Auto-Diagnosis**: Failed tasks automatically execute an optional compensatory `selfHealingCommand` (e.g. system service restart or temp cleanup). Model failures can trigger `autoDiagnose: true` to append an instant root-cause diagnosis.
|
|
418
418
|
- **Web UI Archive & Pipeline Visualization**: Interactive archive drawer with pagination and full log viewing; visual indicators for `➜ onSuccess` and `↳ onFailure` task connections.
|
|
419
419
|
- **Shell & Disk Pre-flight Gate Hardening**: Supports both `command` and `shell` types with fail-closed semantics for invalid syntax, unknown types, or inspection failures. Disk space checks support exact path and threshold syntax (e.g. `/:10%`, `/data:500MB`).
|
|
420
|
-
- **Complete Reliability Field Persistence**: HTTP POST task creation/editing and `
|
|
420
|
+
- **Complete Reliability Field Persistence**: HTTP POST task creation/editing and the `cron` tool (`action: 'create' | 'update'`) fully preserve and store all 13 reliability and session configuration fields (`agentPreset`, `targetSessionId`, `targetSessionReset`, `onSuccess`, `onFailure`, `heartbeatIntervalSeconds`, `gracePeriodSeconds`, `preflightType`, `preflightTarget`, `priority`, `concurrencyGroup`, `selfHealingCommand`, `autoDiagnose`, `fallbackProvider`, `fallbackModel`, `silentRule`, `inspectOnFailure`).
|
|
421
421
|
|
|
422
422
|
---
|
|
423
423
|
|
|
@@ -638,7 +638,7 @@ Save LLM tokens and API quotas on watcher tasks by dynamically slowing down exec
|
|
|
638
638
|
|
|
639
639
|
### 🔄 Session Resumption & GUI Session Naming (#346, GH #9, #354, GH #10, Added in v0.3.8, Patched in v0.3.9)
|
|
640
640
|
|
|
641
|
-
- **HTTP API `sessionTitle` Persistence (v0.3.10, #354, GH #10, PR #11)**: Tasks created or updated via HTTP endpoints (`POST /dsh-cron/tasks` and `POST /dsh-cron/api/tasks`) now reliably forward and persist `sessionTitle` into the task store and runner, mirroring the
|
|
641
|
+
- **HTTP API `sessionTitle` Persistence (v0.3.10, #354, GH #10, PR #11)**: Tasks created or updated via HTTP endpoints (`POST /dsh-cron/tasks` and `POST /dsh-cron/api/tasks`) now reliably forward and persist `sessionTitle` into the task store and runner, mirroring the `cron` tool and PATCH pathways.
|
|
642
642
|
|
|
643
643
|
- **Universal Host Resumption (`resumeSessionId`)**: DeepSeek Harness host `0.2.0-rc.2+` specifies `readonly resumeSessionId: SessionId` on `agents.resume()`. The runner now passes both `resumeSessionId` and `sessionId`, guaranteeing seamless session resumption across all DSH core versions without falling back to recreating sessions that already exist.
|
|
644
644
|
- **Enhanced Diagnostics on Failure**: When an existing session cannot be resumed, `dsh-cron` logs an actionable warning and, if recreating the session fails, surfaces the underlying resume error in the task run output.
|
package/lib/client.css
CHANGED
|
@@ -140,6 +140,8 @@
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
.dsh-cron-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); overflow-y: auto; padding: 24px 48px 32px; z-index: 100; box-sizing: border-box; }
|
|
143
|
+
.dsh-cron-shell-overlay { position: fixed; inset: 0; z-index: 9999; overflow: auto; background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); box-sizing: border-box; }
|
|
144
|
+
.dsh-cron-shell-overlay-inner { max-width: 1100px; margin: 0 auto; padding: 16px; box-sizing: border-box; }
|
|
143
145
|
.dsh-cron-container { max-width: 960px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; padding: 8px 0 32px; box-sizing: border-box; }
|
|
144
146
|
|
|
145
147
|
.dsh-cron-top-bar { display: flex; align-items: center; gap: 12px; }
|
package/lib/client.js
CHANGED
|
@@ -308,6 +308,11 @@ return () => listeners.delete(fn);
|
|
|
308
308
|
}
|
|
309
309
|
};
|
|
310
310
|
}
|
|
311
|
+
function optionalService(ctx, name) {try {if (ctx && typeof ctx.get === 'function') return ctx.get(name);
|
|
312
|
+
} catch (err) {/* the host does not expose this optional service */
|
|
313
|
+
}
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
311
316
|
async function openSession(ctx, sessionId) {if (!sessionId) return false;
|
|
312
317
|
const getSessions = () => (ctx && typeof ctx.get === 'function' ? ctx.get('sessions') : (ctx && ctx.sessions));
|
|
313
318
|
let sessions = getSessions();
|
|
@@ -766,7 +771,7 @@ const [isOpen, setIsOpen] = React.useState(toggle && typeof toggle.isOpen === 'f
|
|
|
766
771
|
React.useEffect(() => {if (!toggle || typeof toggle.subscribe !== 'function') return;
|
|
767
772
|
return toggle.subscribe((val) => setIsOpen(val));
|
|
768
773
|
}, [toggle]);
|
|
769
|
-
if (!isOpen) return null;
|
|
774
|
+
if (!isOpen && props.pinned !== true) return null;
|
|
770
775
|
const [tab, setTab] = React.useState('all');
|
|
771
776
|
const [query, setQuery] = React.useState('');
|
|
772
777
|
const [filterType, setFilterType] = React.useState('');
|
|
@@ -2694,6 +2699,7 @@ if (state.root !== undefined && state.root.isConnected) state.root.remove();
|
|
|
2694
2699
|
state.root = undefined;
|
|
2695
2700
|
};
|
|
2696
2701
|
}
|
|
2702
|
+
let shellOverlayActive = false;
|
|
2697
2703
|
function mountCronScreen(ctx, toggle) {if (typeof document === 'undefined') return () => {};
|
|
2698
2704
|
let root;
|
|
2699
2705
|
let container;
|
|
@@ -2707,10 +2713,9 @@ container = undefined;
|
|
|
2707
2713
|
const ensure = () => {if (!toggle.isOpen()) {teardownPanel();
|
|
2708
2714
|
return;
|
|
2709
2715
|
}
|
|
2710
|
-
if (
|
|
2716
|
+
if (shellOverlayActive) {teardownPanel();
|
|
2711
2717
|
return;
|
|
2712
2718
|
}
|
|
2713
|
-
}
|
|
2714
2719
|
if (container !== undefined && container.isConnected) return;
|
|
2715
2720
|
const column = document.querySelector(COLUMN_SELECTOR);
|
|
2716
2721
|
if (column === null) return;
|
|
@@ -2733,7 +2738,8 @@ teardownPanel();
|
|
|
2733
2738
|
};
|
|
2734
2739
|
const onOtherActivate = (event) => {if (event.detail !== PANEL && toggle.isOpen()) toggle.set(false);
|
|
2735
2740
|
};
|
|
2736
|
-
const onOutsideClick = (event) => {if (
|
|
2741
|
+
const onOutsideClick = (event) => {if (shellOverlayActive) return;
|
|
2742
|
+
if (!toggle.isOpen()) return;
|
|
2737
2743
|
if (!shouldDismissPanel(event.target)) return;
|
|
2738
2744
|
toggle.set(false);
|
|
2739
2745
|
};
|
|
@@ -2787,19 +2793,47 @@ const cardSlot = cardOk ? 'settings.plugin.item' : undefined;
|
|
|
2787
2793
|
const chipSlot = chipOk ? 'conversation.session.header.utilities' : undefined;
|
|
2788
2794
|
function CronNavIcon(props) {
|
|
2789
2795
|
const size = (props && props.size) || 16;
|
|
2790
|
-
return _h('span', {className: 'dsh-cron-nav-icon','data-dsh-cron-entry': '','data-dsh-plugin': 'dsh-cron',style: { width: size, height: size },dangerouslySetInnerHTML: { __html: ICON_TIMER }
|
|
2796
|
+
return _h('span', {className: 'dsh-cron-nav-icon','data-dsh-cron-entry': '','data-dsh-plugin': 'dsh-cron',style: { width: size, height: size },onClick: () => toggle.set(true),dangerouslySetInnerHTML: { __html: ICON_TIMER }
|
|
2791
2797
|
});
|
|
2792
2798
|
}
|
|
2793
2799
|
const navOk = registerIntoMount(ctx, 'sidebar.panellist', {name: 'sidebar.panellist',id: 'dsh-cron',order: 12,label: () => translate('sidebar.label'),locale: NS,}, CronNavIcon);
|
|
2794
|
-
function CronMainPage(props) {
|
|
2795
|
-
return _h(ErrorBoundary, null, _h(CronScreen, {...props,ctx: props.ctx || ctx,toggle: props.toggle || toggle,t: translate,onClose: () => {
|
|
2800
|
+
function CronMainPage(props) {if (shellOverlayActive) return null;
|
|
2801
|
+
return _h(ErrorBoundary, null, _h(CronScreen, {...props,ctx: props.ctx || ctx,toggle: props.toggle || toggle,t: translate,onClose: () => {
|
|
2802
|
+
const layoutService = optionalService(ctx, 'layout');
|
|
2803
|
+
if (layoutService && typeof layoutService.selectPanel === 'function') {layoutService.selectPanel(null);
|
|
2796
2804
|
}
|
|
2797
2805
|
toggle.set(false);
|
|
2798
2806
|
}
|
|
2799
2807
|
}));
|
|
2800
2808
|
}
|
|
2801
2809
|
const mainOk = registerIntoMount(ctx, 'main', {name: 'main',key: 'dsh-cron',locale: NS,inject: () => ({ ctx, toggle }),}, CronMainPage);
|
|
2802
|
-
|
|
2810
|
+
function CronShellOverlay() {
|
|
2811
|
+
const [open, setOpen] = React.useState(toggle.isOpen());
|
|
2812
|
+
React.useEffect(() => {shellOverlayActive = true;
|
|
2813
|
+
const off = toggle.subscribe(setOpen);
|
|
2814
|
+
setOpen(toggle.isOpen());
|
|
2815
|
+
return () => {shellOverlayActive = false;
|
|
2816
|
+
off();
|
|
2817
|
+
};
|
|
2818
|
+
}, []);
|
|
2819
|
+
if (!open) return null;
|
|
2820
|
+
return _h('div', {className: 'dsh-cron-shell-overlay','data-dsh-plugin': 'dsh-cron',[VIEW_ATTR]: '',}, _h('div', { className: 'dsh-cron-shell-overlay-inner' },_h(ErrorBoundary, null, _h(CronScreen, {ctx,toggle,pinned: true,t: translate,onClose: () => {
|
|
2821
|
+
const layoutService = optionalService(ctx, 'layout');
|
|
2822
|
+
if (layoutService && typeof layoutService.selectPanel === 'function') {layoutService.selectPanel(null);
|
|
2823
|
+
}
|
|
2824
|
+
toggle.set(false);
|
|
2825
|
+
},}))));
|
|
2826
|
+
}
|
|
2827
|
+
const isDesktopShell = (() => {try {if (typeof location === 'undefined') return false;
|
|
2828
|
+
if (location.protocol === 'dsh-app:') return true;
|
|
2829
|
+
return String(location.host || '').toLowerCase() === 'app';
|
|
2830
|
+
} catch (err) {
|
|
2831
|
+
return false;
|
|
2832
|
+
}
|
|
2833
|
+
})();
|
|
2834
|
+
if (isDesktopShell) {registerIntoMount(ctx, 'shell.overlay', {name: 'shell.overlay',id: PLUGIN_ID,order: 900,locale: NS,inject: () => ({ ctx, toggle }),}, CronShellOverlay);
|
|
2835
|
+
}
|
|
2836
|
+
const layout = optionalService(ctx, 'layout');
|
|
2803
2837
|
if (layout && typeof layout.selectPanel === 'function') {toggle.subscribe((isOpen) => {if (isOpen) {layout.selectPanel('dsh-cron');
|
|
2804
2838
|
} else if (layout.panelInfo && typeof layout.panelInfo.getSnapshot === 'function') {if (layout.panelInfo.getSnapshot()?.activePanelId === 'dsh-cron') {layout.selectPanel(null);
|
|
2805
2839
|
}
|
package/lib/cron-tool.js
CHANGED
|
@@ -414,7 +414,9 @@ export async function executeCronTool(store, scheduler, args = {}) {
|
|
|
414
414
|
};
|
|
415
415
|
}
|
|
416
416
|
try {
|
|
417
|
-
|
|
417
|
+
const created = executeCreateTask(store, scheduler, args);
|
|
418
|
+
await store.flushAsync();
|
|
419
|
+
return created;
|
|
418
420
|
} catch (err) {
|
|
419
421
|
return { success: false, message: err.message };
|
|
420
422
|
}
|
|
@@ -467,6 +469,7 @@ export async function executeCronTool(store, scheduler, args = {}) {
|
|
|
467
469
|
allowCodeSwitch: confirmCodeSwitch === true,
|
|
468
470
|
});
|
|
469
471
|
if (!result.ok) return { success: false, message: result.error };
|
|
472
|
+
await store.flushAsync();
|
|
470
473
|
return {
|
|
471
474
|
success: true,
|
|
472
475
|
message: `Task "${result.task.title}" updated (${result.task.scheduleText || result.task.schedule}). Changed: ${describeTaskPatch(result.task, result.patch)}`,
|
|
@@ -503,6 +506,7 @@ export async function executeCronTool(store, scheduler, args = {}) {
|
|
|
503
506
|
if (isConfigOwned(store.get(args.id))) return { success: false, message: configOwnedMessage(args.id) };
|
|
504
507
|
scheduler.pauseTask(args.id);
|
|
505
508
|
const ok = store.delete(args.id);
|
|
509
|
+
if (ok) await store.flushAsync();
|
|
506
510
|
return { success: ok, message: ok ? 'Task deleted' : 'Task not found' };
|
|
507
511
|
}
|
|
508
512
|
|
package/lib/git-diff.js
CHANGED
|
@@ -15,6 +15,18 @@ const execFileAsync = promisify(execFile);
|
|
|
15
15
|
|
|
16
16
|
export const MAX_DIFF_SIZE = 256 * 1024; // 256 KiB safety ceiling
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Normalizes CRLF to LF so a captured diff is byte-stable across platforms.
|
|
20
|
+
* `git diff` emits CRLF on Windows checkouts with `core.autocrlf=true`, and a
|
|
21
|
+
* stored CRLF patch no longer applies on a POSIX host (and vice versa).
|
|
22
|
+
*
|
|
23
|
+
* @param {string} value
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export function normalizeEol(value) {
|
|
27
|
+
return typeof value === 'string' ? value.replace(/\r\n/g, '\n') : value;
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
/**
|
|
19
31
|
* Checks if a given directory is inside a git working tree.
|
|
20
32
|
*
|
|
@@ -110,7 +122,7 @@ export async function captureGitDiff(cwd, { maxSize = MAX_DIFF_SIZE } = {}) {
|
|
|
110
122
|
try {
|
|
111
123
|
// 1. Check if there are any changes
|
|
112
124
|
const { stdout: statusOut } = await execFileAsync('git', ['status', '--porcelain'], { cwd, timeout: 5000 });
|
|
113
|
-
const cleanStatus = statusOut.trim();
|
|
125
|
+
const cleanStatus = normalizeEol(statusOut).trim();
|
|
114
126
|
if (!cleanStatus) {
|
|
115
127
|
return { hasChanges: false, stat: '', diff: '', files: [], summary: { filesCount: 0, insertions: 0, deletions: 0 } };
|
|
116
128
|
}
|
|
@@ -121,12 +133,12 @@ export async function captureGitDiff(cwd, { maxSize = MAX_DIFF_SIZE } = {}) {
|
|
|
121
133
|
let stat = '';
|
|
122
134
|
try {
|
|
123
135
|
const { stdout: statOut } = await execFileAsync('git', ['diff', '--stat', 'HEAD'], { cwd, timeout: 5000 });
|
|
124
|
-
stat = statOut.trim();
|
|
136
|
+
stat = normalizeEol(statOut).trim();
|
|
125
137
|
} catch {
|
|
126
138
|
// Fallback without HEAD (e.g. unborn branch)
|
|
127
139
|
try {
|
|
128
140
|
const { stdout: statOut } = await execFileAsync('git', ['diff', '--stat'], { cwd, timeout: 5000 });
|
|
129
|
-
stat = statOut.trim();
|
|
141
|
+
stat = normalizeEol(statOut).trim();
|
|
130
142
|
} catch {
|
|
131
143
|
stat = `${files.length} file(s) changed`;
|
|
132
144
|
}
|
|
@@ -141,11 +153,11 @@ export async function captureGitDiff(cwd, { maxSize = MAX_DIFF_SIZE } = {}) {
|
|
|
141
153
|
let rawDiff = '';
|
|
142
154
|
try {
|
|
143
155
|
const { stdout: diffOut } = await execFileAsync('git', ['diff', 'HEAD'], { cwd, timeout: 8000, maxBuffer: 10 * 1024 * 1024 });
|
|
144
|
-
rawDiff = diffOut;
|
|
156
|
+
rawDiff = normalizeEol(diffOut);
|
|
145
157
|
} catch {
|
|
146
158
|
try {
|
|
147
159
|
const { stdout: diffOut } = await execFileAsync('git', ['diff'], { cwd, timeout: 8000, maxBuffer: 10 * 1024 * 1024 });
|
|
148
|
-
rawDiff = diffOut;
|
|
160
|
+
rawDiff = normalizeEol(diffOut);
|
|
149
161
|
} catch (err) {
|
|
150
162
|
rawDiff = `[Diff unavailable: ${err.message}]`;
|
|
151
163
|
}
|
package/lib/index.js
CHANGED
|
@@ -218,6 +218,9 @@ export function apply(ctx, rawConfig) {
|
|
|
218
218
|
try {
|
|
219
219
|
const configJobs = Array.isArray(config && config.jobs) ? config.jobs : [];
|
|
220
220
|
const summary = applyConfigSync({ store, scheduler, entries: configJobs, log: logger });
|
|
221
|
+
// Config-owned tasks are re-synced on every boot, but the first successful
|
|
222
|
+
// sync must reach disk before the scheduler starts arming timers.
|
|
223
|
+
store.flushSync();
|
|
221
224
|
logger.info('[dsh-cron] config jobs synced: ' + JSON.stringify(summary));
|
|
222
225
|
} catch (err) {
|
|
223
226
|
logger.error('[dsh-cron] config job sync failed:', err.message);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for "is this path safe to touch?" checks.
|
|
3
|
+
*
|
|
4
|
+
* File watchers (`lib/watcher.js`) and wake triggers (`lib/wake-triggers.js`)
|
|
5
|
+
* used to keep two drifting copies of the disallowed-root list: one compared
|
|
6
|
+
* only exact matches (so `/etc/ssh` slipped through), the other compared
|
|
7
|
+
* subtrees but only after `path.resolve()`, so POSIX roots never matched on a
|
|
8
|
+
* Windows host (`/etc` becomes `C:\etc`). Both now delegate here.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
|
|
13
|
+
/** Sensitive locations, written POSIX-style and compared case-insensitively. */
|
|
14
|
+
export const DISALLOWED_ROOTS = Object.freeze([
|
|
15
|
+
'/proc',
|
|
16
|
+
'/sys',
|
|
17
|
+
'/dev',
|
|
18
|
+
'/etc',
|
|
19
|
+
'/boot',
|
|
20
|
+
'/run',
|
|
21
|
+
'/var/run',
|
|
22
|
+
'c:/windows',
|
|
23
|
+
'c:/windows/system32',
|
|
24
|
+
'c:/program files',
|
|
25
|
+
'c:/program files (x86)',
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
function normalize(value) {
|
|
29
|
+
return String(value).split('\\').join('/').replace(/\/+$/, '').toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function matchesDisallowedRoot(candidate) {
|
|
33
|
+
for (const root of DISALLOWED_ROOTS) {
|
|
34
|
+
if (candidate === root || candidate.startsWith(root + '/')) return root;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Validates that a path does not target a sensitive system location or a
|
|
41
|
+
* filesystem root.
|
|
42
|
+
*
|
|
43
|
+
* Both the path as written and its resolved form are compared, so a POSIX-style
|
|
44
|
+
* input is rejected on Windows too, and a Windows-style input is rejected
|
|
45
|
+
* regardless of the current drive.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} targetPath
|
|
48
|
+
* @param {string} [label] — prefix used in error messages ("Path", "Watched path").
|
|
49
|
+
* @returns {{ safe: boolean, resolved?: string, error?: string }}
|
|
50
|
+
*/
|
|
51
|
+
export function isSafePath(targetPath, label = 'Path') {
|
|
52
|
+
if (!targetPath || typeof targetPath !== 'string') {
|
|
53
|
+
return { safe: false, error: 'Path must be a non-empty string' };
|
|
54
|
+
}
|
|
55
|
+
const trimmed = targetPath.trim();
|
|
56
|
+
if (!trimmed) {
|
|
57
|
+
return { safe: false, error: 'Path must be a non-empty string' };
|
|
58
|
+
}
|
|
59
|
+
if (trimmed.indexOf('\0') !== -1) {
|
|
60
|
+
return { safe: false, error: 'Path must not contain null bytes' };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (matchesDisallowedRoot(normalize(trimmed))) {
|
|
64
|
+
return { safe: false, error: `${label} "${targetPath}" targets a disallowed system location` };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const resolved = path.resolve(trimmed);
|
|
68
|
+
if (resolved === path.parse(resolved).root) {
|
|
69
|
+
return { safe: false, error: `${label} "${resolved}" is a filesystem root` };
|
|
70
|
+
}
|
|
71
|
+
if (matchesDisallowedRoot(normalize(resolved))) {
|
|
72
|
+
return { safe: false, error: `${label} "${resolved}" targets a disallowed system location` };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { safe: true, resolved };
|
|
76
|
+
}
|
|
@@ -166,6 +166,7 @@ export async function handleItemPost({ store, scheduler, req, res, url, id, acti
|
|
|
166
166
|
try {
|
|
167
167
|
rollbackPromptVersion(task, targetVersion);
|
|
168
168
|
store.set(task);
|
|
169
|
+
await store.flushAsync();
|
|
169
170
|
sendJson(res, 200, {
|
|
170
171
|
ok: true,
|
|
171
172
|
task: redactTaskSecrets(task),
|
|
@@ -304,6 +305,7 @@ export async function handleItemPost({ store, scheduler, req, res, url, id, acti
|
|
|
304
305
|
const copy = buildDuplicateTask(source, { id: randomUUID() });
|
|
305
306
|
try {
|
|
306
307
|
store.set(copy);
|
|
308
|
+
await store.flushAsync();
|
|
307
309
|
} catch (err) {
|
|
308
310
|
sendJson(res, 500, { ok: false, error: 'Failed to persist duplicate task: ' + err.message });
|
|
309
311
|
return true;
|
|
@@ -131,6 +131,7 @@ export async function createOrUpdateTask({ store, scheduler, req, res, apiToken,
|
|
|
131
131
|
let task;
|
|
132
132
|
try {
|
|
133
133
|
task = store.set(buildTaskRecord(store, body, taskType, parsed));
|
|
134
|
+
await store.flushAsync();
|
|
134
135
|
} catch (err) {
|
|
135
136
|
sendJson(res, 500, { ok: false, error: 'Failed to persist task: ' + err.message });
|
|
136
137
|
return;
|
|
@@ -90,7 +90,7 @@ export async function handleTaskImport({ store, scheduler, req, res }) {
|
|
|
90
90
|
});
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
const applied = applyImportPlan({ store, scheduler, plan });
|
|
93
|
+
const applied = await applyImportPlan({ store, scheduler, plan });
|
|
94
94
|
if (applied.error) {
|
|
95
95
|
sendJson(res, 500, { ok: false, error: applied.error });
|
|
96
96
|
return;
|
|
@@ -110,7 +110,7 @@ export async function handleTaskImport({ store, scheduler, req, res }) {
|
|
|
110
110
|
* "paused" does not stop an already-armed croner job. A failed write rolls the
|
|
111
111
|
* store back so a partial import cannot survive.
|
|
112
112
|
*/
|
|
113
|
-
export function applyImportPlan({ store, scheduler, plan }) {
|
|
113
|
+
export async function applyImportPlan({ store, scheduler, plan }) {
|
|
114
114
|
const imported = [];
|
|
115
115
|
const rollback = [];
|
|
116
116
|
const disarm = [];
|
|
@@ -130,6 +130,7 @@ export function applyImportPlan({ store, scheduler, plan }) {
|
|
|
130
130
|
rollback.push({ id: replaced.id, previous: before });
|
|
131
131
|
disarm.push(replaced.id);
|
|
132
132
|
}
|
|
133
|
+
await store.flushAsync();
|
|
133
134
|
} catch (writeErr) {
|
|
134
135
|
for (const entry of rollback.reverse()) {
|
|
135
136
|
try {
|
package/lib/routes/api-item.js
CHANGED
|
@@ -124,7 +124,7 @@ export async function handleTaskItem({ store, scheduler, req, res, url, id, acti
|
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
if (req.method === 'DELETE' || (req.method === 'POST' && action === 'delete')) {
|
|
127
|
-
deleteTask({ store, scheduler, res, id });
|
|
127
|
+
await deleteTask({ store, scheduler, res, id });
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
sendJson(res, 405, NOT_ALLOWED);
|
|
@@ -144,13 +144,20 @@ export async function patchTask({ store, scheduler, req, res, id }) {
|
|
|
144
144
|
}
|
|
145
145
|
const { body, error } = await readBody(req, res);
|
|
146
146
|
if (error) return;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
let result;
|
|
148
|
+
try {
|
|
149
|
+
result = applyTaskPatch({
|
|
150
|
+
store,
|
|
151
|
+
scheduler,
|
|
152
|
+
id,
|
|
153
|
+
body,
|
|
154
|
+
allowCodeSwitch: req.headers[SCRIPT_CONFIRM_HEADER] === 'script',
|
|
155
|
+
});
|
|
156
|
+
if (result.ok) await store.flushAsync();
|
|
157
|
+
} catch (err) {
|
|
158
|
+
sendJson(res, 500, { ok: false, error: 'Failed to persist task patch: ' + err.message });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
154
161
|
if (!result.ok) {
|
|
155
162
|
const status = result.status || (result.notFound ? 404 : (result.needsConfirmation ? 403 : 400));
|
|
156
163
|
const error = result.needsConfirmation
|
|
@@ -167,7 +174,7 @@ export async function patchTask({ store, scheduler, req, res, id }) {
|
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
|
|
170
|
-
export function deleteTask({ store, scheduler, res, id }) {
|
|
177
|
+
export async function deleteTask({ store, scheduler, res, id }) {
|
|
171
178
|
const current = store.get(id);
|
|
172
179
|
if (current && current.managedBy === MANAGED_BY_CONFIG) {
|
|
173
180
|
refuseConfigOwned(res, id);
|
|
@@ -181,6 +188,7 @@ export function deleteTask({ store, scheduler, res, id }) {
|
|
|
181
188
|
}
|
|
182
189
|
try {
|
|
183
190
|
store.delete(id);
|
|
191
|
+
await store.flushAsync();
|
|
184
192
|
} catch (err) {
|
|
185
193
|
sendJson(res, 500, { ok: false, error: 'Failed to delete task: ' + err.message });
|
|
186
194
|
return;
|
package/lib/routes/api.js
CHANGED
|
@@ -168,7 +168,7 @@ export async function handleExternalTaskRequest({ store, scheduler, req, res, ur
|
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
170
170
|
if (req.method === 'DELETE' && !action) {
|
|
171
|
-
deleteTask({ store, scheduler, res, id });
|
|
171
|
+
await deleteTask({ store, scheduler, res, id });
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
sendJson(res, 405, NOT_ALLOWED);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { logStreamer } from '../log-streamer.js';
|
|
2
2
|
import { logger } from '../logger.js';
|
|
3
3
|
import { bestEffort } from '../best-effort.js';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
4
5
|
import {
|
|
5
6
|
buildInvocation,
|
|
6
7
|
} from './runtimes.js';
|
|
@@ -30,14 +31,24 @@ export function terminateProcessTree(child, sig = 'SIGTERM', { isPosix = process
|
|
|
30
31
|
if (isPosix && child.pid) {
|
|
31
32
|
bestEffort('kill-posix-pid', () => process.kill(-child.pid, sig));
|
|
32
33
|
} else if (child.pid) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
if (execFn) {
|
|
35
|
+
bestEffort('exec-taskkill', () => execFn(`taskkill /pid ${child.pid} /T /F`));
|
|
36
|
+
bestEffort('child-kill', () => child.kill(sig));
|
|
37
|
+
} else {
|
|
38
|
+
// Spawning taskkill with an argv array avoids cmd.exe quoting rules.
|
|
39
|
+
// Do NOT call child.kill() here: terminating cmd.exe first detaches the
|
|
40
|
+
// grandchildren, and taskkill can no longer find the process tree (#452).
|
|
41
|
+
bestEffort('spawn-taskkill', () => {
|
|
42
|
+
const killer = spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
|
|
43
|
+
windowsHide: true,
|
|
44
|
+
stdio: 'ignore',
|
|
45
|
+
});
|
|
46
|
+
killer.on('error', (err) => {
|
|
47
|
+
logger.warn('[dsh-cron] taskkill failed, falling back to child.kill:', err.message);
|
|
48
|
+
bestEffort('child-kill-fallback', () => child.kill(sig));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
41
52
|
}
|
|
42
53
|
});
|
|
43
54
|
}
|
|
@@ -192,12 +203,7 @@ export async function runExternal(task, runtime, signal, execOptions = {}, { ctx
|
|
|
192
203
|
let forceKillTimer = null;
|
|
193
204
|
|
|
194
205
|
const killProcessTree = (sig = 'SIGTERM') => {
|
|
195
|
-
terminateProcessTree(child, sig, {
|
|
196
|
-
isPosix,
|
|
197
|
-
execFn: (cmd) => {
|
|
198
|
-
bestEffort('exec-cmd', () => exec(cmd, { windowsHide: true }, () => {}));
|
|
199
|
-
}
|
|
200
|
-
});
|
|
206
|
+
terminateProcessTree(child, sig, { isPosix });
|
|
201
207
|
};
|
|
202
208
|
|
|
203
209
|
const cleanupTimers = () => {
|
|
@@ -258,7 +264,14 @@ export async function runExternal(task, runtime, signal, execOptions = {}, { ctx
|
|
|
258
264
|
}
|
|
259
265
|
const shellPath = isPosix ? (process.env.SHELL || '/bin/bash') : (process.env.ComSpec || 'cmd.exe');
|
|
260
266
|
const shellArgs = isPosix ? ['-c', command] : ['/d', '/s', '/c', command];
|
|
261
|
-
|
|
267
|
+
// The command is already a fully formed shell line. Letting Node quote it
|
|
268
|
+
// again corrupts embedded double quotes on Windows (cmd sees the escaped
|
|
269
|
+
// quote as a literal and cuts the argument), so pass argv verbatim there.
|
|
270
|
+
child = spawn(shellPath, shellArgs, {
|
|
271
|
+
...options,
|
|
272
|
+
windowsHide: true,
|
|
273
|
+
windowsVerbatimArguments: !isPosix,
|
|
274
|
+
});
|
|
262
275
|
}
|
|
263
276
|
|
|
264
277
|
child.stdout.on('data', (chunk) => {
|
package/lib/settings.js
CHANGED
|
@@ -158,7 +158,7 @@ export function sanitizeSettingsPayload(body) {
|
|
|
158
158
|
delete payload[key];
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
for (const key of ['botTokenRef', '
|
|
161
|
+
for (const key of ['botTokenRef', 'giteaTokenRef']) {
|
|
162
162
|
if (key in payload && typeof payload[key] === 'string' && payload[key].trim()) {
|
|
163
163
|
const refCheck = credentialRefStatus(payload[key]);
|
|
164
164
|
if (!refCheck.ok) {
|
package/lib/store/store.js
CHANGED
|
@@ -152,6 +152,15 @@ export class TaskStore {
|
|
|
152
152
|
return saveAsync(this);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Durability point for user-facing mutations. `set()`/`delete()` only mark
|
|
157
|
+
* the store dirty and coalesce writes; HTTP and tool handlers await this so a
|
|
158
|
+
* disk failure still becomes an error response instead of a silent 200.
|
|
159
|
+
*/
|
|
160
|
+
async flushAsync() {
|
|
161
|
+
return saveAsync(this);
|
|
162
|
+
}
|
|
163
|
+
|
|
155
164
|
async _writeStoreStream(filePath, data, version) {
|
|
156
165
|
return writeStoreStream(this, filePath, data, version);
|
|
157
166
|
}
|
|
@@ -300,13 +309,10 @@ export class TaskStore {
|
|
|
300
309
|
}
|
|
301
310
|
}
|
|
302
311
|
this.tasks.set(id, record);
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
else this.tasks.delete(id);
|
|
308
|
-
throw err;
|
|
309
|
-
}
|
|
312
|
+
// Persist through the debounced async writer: a synchronous full-store
|
|
313
|
+
// rewrite here blocked the event loop on every mutation (#451). Durability
|
|
314
|
+
// points are `flushSync()` and the lifecycle hook on plugin unload.
|
|
315
|
+
this.scheduleSave(0);
|
|
310
316
|
return record;
|
|
311
317
|
}
|
|
312
318
|
|
|
@@ -317,25 +323,13 @@ export class TaskStore {
|
|
|
317
323
|
return null;
|
|
318
324
|
}
|
|
319
325
|
const now = Date.now();
|
|
320
|
-
const prevPing = task.lastPingAt;
|
|
321
|
-
const prevAlerted = task.heartbeatAlerted;
|
|
322
|
-
const prevUpdated = task.updatedAt;
|
|
323
|
-
const prevStatus = task.lastStatus;
|
|
324
326
|
task.lastPingAt = now;
|
|
325
327
|
task.heartbeatAlerted = false;
|
|
326
328
|
task.updatedAt = now;
|
|
327
329
|
if (task.lastStatus === 'missed') {
|
|
328
330
|
task.lastStatus = 'active';
|
|
329
331
|
}
|
|
330
|
-
|
|
331
|
-
this.save();
|
|
332
|
-
} catch (err) {
|
|
333
|
-
task.lastPingAt = prevPing;
|
|
334
|
-
task.heartbeatAlerted = prevAlerted;
|
|
335
|
-
task.updatedAt = prevUpdated;
|
|
336
|
-
task.lastStatus = prevStatus;
|
|
337
|
-
throw err;
|
|
338
|
-
}
|
|
332
|
+
this.scheduleSave(0);
|
|
339
333
|
const interval = (task.heartbeatIntervalSeconds || 0) + (task.gracePeriodSeconds || 300);
|
|
340
334
|
return {
|
|
341
335
|
ok: true,
|
|
@@ -352,16 +346,9 @@ export class TaskStore {
|
|
|
352
346
|
}
|
|
353
347
|
const existing = this.tasks.get(id);
|
|
354
348
|
if (!existing) return false;
|
|
355
|
-
const existingHistory = this.history.get(id);
|
|
356
349
|
this.tasks.delete(id);
|
|
357
350
|
this.history.delete(id);
|
|
358
|
-
|
|
359
|
-
this.save();
|
|
360
|
-
} catch (err) {
|
|
361
|
-
this.tasks.set(id, existing);
|
|
362
|
-
if (existingHistory) this.history.set(id, existingHistory);
|
|
363
|
-
throw err;
|
|
364
|
-
}
|
|
351
|
+
this.scheduleSave(0);
|
|
365
352
|
return true;
|
|
366
353
|
}
|
|
367
354
|
|
package/lib/wake-triggers.js
CHANGED
|
@@ -2,60 +2,14 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { logger } from './logger.js';
|
|
4
4
|
import { bestEffort } from './best-effort.js';
|
|
5
|
-
|
|
6
|
-
const DISALLOWED_ROOTS = [
|
|
7
|
-
'/proc',
|
|
8
|
-
'/sys',
|
|
9
|
-
'/dev',
|
|
10
|
-
'/etc',
|
|
11
|
-
'/boot',
|
|
12
|
-
'/run',
|
|
13
|
-
'/var/run',
|
|
14
|
-
'c:\\windows',
|
|
15
|
-
'c:\\windows\\system32',
|
|
16
|
-
'c:\\program files',
|
|
17
|
-
'c:\\program files (x86)',
|
|
18
|
-
];
|
|
5
|
+
import { isSafePath } from './path-safety.js';
|
|
19
6
|
|
|
20
7
|
/**
|
|
21
8
|
* Validates that a path does not target sensitive system locations or escape root.
|
|
9
|
+
* Kept as a named export because the task schema and tests refer to it.
|
|
22
10
|
*/
|
|
23
11
|
export function isSafeWakePath(targetPath) {
|
|
24
|
-
|
|
25
|
-
return { safe: false, error: 'Path must be a non-empty string' };
|
|
26
|
-
}
|
|
27
|
-
const trimmed = targetPath.trim();
|
|
28
|
-
if (trimmed.indexOf('\0') !== -1) {
|
|
29
|
-
return { safe: false, error: 'Path must not contain null bytes' };
|
|
30
|
-
}
|
|
31
|
-
const rawLower = trimmed.toLowerCase().split('\\').join('/');
|
|
32
|
-
if (
|
|
33
|
-
rawLower === 'c:' ||
|
|
34
|
-
rawLower === 'c:/' ||
|
|
35
|
-
rawLower.startsWith('c:/windows') ||
|
|
36
|
-
rawLower.startsWith('c:/program files')
|
|
37
|
-
) {
|
|
38
|
-
return { safe: false, error: `Path "${targetPath}" targets a disallowed system location` };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const resolved = path.resolve(trimmed);
|
|
42
|
-
|
|
43
|
-
// Filesystem root check ('/' on POSIX, 'C:\' on Windows)
|
|
44
|
-
if (resolved === path.parse(resolved).root) {
|
|
45
|
-
return { safe: false, error: `Path "${resolved}" is a filesystem root` };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const lower = resolved.toLowerCase().split('\\').join('/');
|
|
49
|
-
|
|
50
|
-
for (const root of DISALLOWED_ROOTS) {
|
|
51
|
-
const normRoot = root.toLowerCase().split('\\').join('/');
|
|
52
|
-
const rootWithSlash = normRoot.endsWith('/') ? normRoot : normRoot + '/';
|
|
53
|
-
if (lower === normRoot || lower.startsWith(rootWithSlash)) {
|
|
54
|
-
return { safe: false, error: `Path "${resolved}" targets a disallowed system location` };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return { safe: true, resolved };
|
|
12
|
+
return isSafePath(targetPath);
|
|
59
13
|
}
|
|
60
14
|
|
|
61
15
|
/**
|
package/lib/watcher.js
CHANGED
|
@@ -2,22 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { logger } from './logger.js';
|
|
4
4
|
import { bestEffort } from './best-effort.js';
|
|
5
|
-
|
|
6
|
-
const DISALLOWED_ROOTS = [
|
|
7
|
-
'/',
|
|
8
|
-
'/proc',
|
|
9
|
-
'/sys',
|
|
10
|
-
'/dev',
|
|
11
|
-
'/etc',
|
|
12
|
-
'/boot',
|
|
13
|
-
'/run',
|
|
14
|
-
'/var/run',
|
|
15
|
-
'c:\\',
|
|
16
|
-
'c:\\windows',
|
|
17
|
-
'c:\\windows\\system32',
|
|
18
|
-
'c:\\program files',
|
|
19
|
-
'c:\\program files (x86)',
|
|
20
|
-
];
|
|
5
|
+
import { isSafePath as isSafeTargetPath } from './path-safety.js';
|
|
21
6
|
|
|
22
7
|
/**
|
|
23
8
|
* FileSystemWatcherManager handles fs.watch instances for tasks configured with fileWatch (#327).
|
|
@@ -32,23 +17,7 @@ export class FileSystemWatcherManager {
|
|
|
32
17
|
}
|
|
33
18
|
|
|
34
19
|
isSafePath(targetPath) {
|
|
35
|
-
|
|
36
|
-
return { safe: false, error: 'Path must be a non-empty string' };
|
|
37
|
-
}
|
|
38
|
-
const resolved = path.resolve(targetPath.trim());
|
|
39
|
-
const lower = resolved.toLowerCase();
|
|
40
|
-
|
|
41
|
-
for (const root of DISALLOWED_ROOTS) {
|
|
42
|
-
if (lower === root || lower === root.replace(/\\/g, '/')) {
|
|
43
|
-
return { safe: false, error: `Watched path "${resolved}" is a disallowed system root directory` };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (resolved === path.parse(resolved).root) {
|
|
48
|
-
return { safe: false, error: `Watched path "${resolved}" is a filesystem root` };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return { safe: true, resolved };
|
|
20
|
+
return isSafeTargetPath(targetPath, 'Watched path');
|
|
52
21
|
}
|
|
53
22
|
|
|
54
23
|
matchPattern(filename, pattern) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-cron",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.49",
|
|
4
4
|
"packageManager": "pnpm@10.33.2",
|
|
5
5
|
"description": "Background automation runner for DSH: isolated agent runs, script/HTTP/SSH/Docker runtimes, cost guard, notifications, heartbeats.",
|
|
6
6
|
"type": "module",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"build:client": "node scripts/build-client.mjs",
|
|
27
27
|
"pretest": "node scripts/build-client.mjs",
|
|
28
28
|
"preflight": "node scripts/ci-preflight.mjs",
|
|
29
|
+
"check:client-inject": "node scripts/check-client-inject.mjs",
|
|
29
30
|
"test:engine": "node scripts/test-engines.mjs",
|
|
30
31
|
"build:client:check": "node scripts/build-client.mjs --check"
|
|
31
32
|
},
|
|
@@ -61,9 +62,10 @@
|
|
|
61
62
|
"dshReleases": {
|
|
62
63
|
"0.2.1-rc.2": "compatible",
|
|
63
64
|
"0.2.1-rc.3": "compatible",
|
|
64
|
-
"0.2.1-rc.4": "compatible"
|
|
65
|
+
"0.2.1-rc.4": "compatible",
|
|
66
|
+
"0.2.2-rc.3": "compatible"
|
|
65
67
|
},
|
|
66
|
-
"dsh": ">=0.2.1-rc.2 <0.2.
|
|
68
|
+
"dsh": ">=0.2.1-rc.2 <0.2.3-0"
|
|
67
69
|
}
|
|
68
70
|
},
|
|
69
71
|
"dependencies": {
|