@goodandready/dsh-cron 0.1.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/LICENSE +21 -0
- package/README.md +45 -0
- package/cordis.patch.yml +4 -0
- package/docs/design/DESIGN.md +61 -0
- package/lib/client.js +442 -0
- package/lib/index.js +349 -0
- package/lib/runner.js +41 -0
- package/lib/scheduler.js +205 -0
- package/lib/store.js +139 -0
- package/package.json +91 -0
package/lib/store.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function getDefaultStorePath() {
|
|
5
|
+
const base = process.env.DSH_DATA_DIR || path.join(process.env.HOME || '.', '.dsh', 'data');
|
|
6
|
+
return path.join(base, 'cron', 'tasks.json');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class TaskStore {
|
|
10
|
+
constructor(filePath) {
|
|
11
|
+
this.filePath = filePath || getDefaultStorePath();
|
|
12
|
+
this.tasks = new Map();
|
|
13
|
+
this.history = new Map();
|
|
14
|
+
this.init();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
init() {
|
|
18
|
+
try {
|
|
19
|
+
const dir = path.dirname(this.filePath);
|
|
20
|
+
if (!fs.existsSync(dir)) {
|
|
21
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
if (fs.existsSync(this.filePath)) {
|
|
24
|
+
const raw = fs.readFileSync(this.filePath, 'utf-8');
|
|
25
|
+
const data = JSON.parse(raw);
|
|
26
|
+
if (Array.isArray(data.tasks)) {
|
|
27
|
+
for (const t of data.tasks) {
|
|
28
|
+
this.tasks.set(t.id, t);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (data.history && typeof data.history === 'object') {
|
|
32
|
+
for (const [k, v] of Object.entries(data.history)) {
|
|
33
|
+
this.history.set(k, Array.isArray(v) ? v : []);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error('[dsh-cron] store read error:', err.message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
save() {
|
|
43
|
+
try {
|
|
44
|
+
const dir = path.dirname(this.filePath);
|
|
45
|
+
if (!fs.existsSync(dir)) {
|
|
46
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
const data = {
|
|
49
|
+
version: 1,
|
|
50
|
+
updatedAt: new Date().toISOString(),
|
|
51
|
+
tasks: Array.from(this.tasks.values()),
|
|
52
|
+
history: Object.fromEntries(this.history.entries()),
|
|
53
|
+
};
|
|
54
|
+
const tmp = this.filePath + '.tmp.' + Date.now();
|
|
55
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2), 'utf-8');
|
|
56
|
+
fs.renameSync(tmp, this.filePath);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.error('[dsh-cron] store save error:', err.message);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
list(filter = {}) {
|
|
63
|
+
let all = Array.from(this.tasks.values());
|
|
64
|
+
if (filter.status && filter.status !== 'all') {
|
|
65
|
+
all = all.filter((t) => t.status === filter.status);
|
|
66
|
+
}
|
|
67
|
+
if (filter.query) {
|
|
68
|
+
const q = filter.query.toLowerCase();
|
|
69
|
+
all = all.filter((t) =>
|
|
70
|
+
(t.title && t.title.toLowerCase().includes(q)) ||
|
|
71
|
+
(t.prompt && t.prompt.toLowerCase().includes(q)) ||
|
|
72
|
+
(t.schedule && t.schedule.toLowerCase().includes(q))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return all.sort((a, b) => (b.createdAt || 0) - (a.createdAt || 0));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get(id) {
|
|
79
|
+
return this.tasks.get(id);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
set(task) {
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
const id = task.id || ('cron_' + Math.random().toString(36).slice(2, 9));
|
|
85
|
+
const record = {
|
|
86
|
+
id,
|
|
87
|
+
title: task.title || 'Новая задача',
|
|
88
|
+
schedule: task.schedule || '0 9 * * *',
|
|
89
|
+
scheduleText: task.scheduleText || task.schedule,
|
|
90
|
+
prompt: task.prompt || '',
|
|
91
|
+
type: task.type || 'prompt',
|
|
92
|
+
status: task.status || 'active',
|
|
93
|
+
delivery: task.delivery || 'current',
|
|
94
|
+
createdAt: task.createdAt || now,
|
|
95
|
+
updatedAt: now,
|
|
96
|
+
lastRunAt: task.lastRunAt || null,
|
|
97
|
+
lastStatus: task.lastStatus || null,
|
|
98
|
+
lastDurationMs: task.lastDurationMs || 0,
|
|
99
|
+
nextRunAt: task.nextRunAt || null,
|
|
100
|
+
};
|
|
101
|
+
this.tasks.set(id, record);
|
|
102
|
+
this.save();
|
|
103
|
+
return record;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
delete(id) {
|
|
107
|
+
const existed = this.tasks.delete(id);
|
|
108
|
+
this.history.delete(id);
|
|
109
|
+
if (existed) this.save();
|
|
110
|
+
return existed;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
recordRun(id, runInfo) {
|
|
114
|
+
const task = this.tasks.get(id);
|
|
115
|
+
if (!task) return;
|
|
116
|
+
task.lastRunAt = runInfo.at || Date.now();
|
|
117
|
+
task.lastStatus = runInfo.status || 'success';
|
|
118
|
+
task.lastDurationMs = runInfo.durationMs || 0;
|
|
119
|
+
task.updatedAt = Date.now();
|
|
120
|
+
|
|
121
|
+
const runs = this.history.get(id) || [];
|
|
122
|
+
runs.unshift({
|
|
123
|
+
id: 'run_' + Math.random().toString(36).slice(2, 9),
|
|
124
|
+
at: task.lastRunAt,
|
|
125
|
+
status: task.lastStatus,
|
|
126
|
+
durationMs: task.lastDurationMs,
|
|
127
|
+
output: (runInfo.output || '').slice(0, 4000),
|
|
128
|
+
error: runInfo.error ? String(runInfo.error).slice(0, 1000) : null,
|
|
129
|
+
});
|
|
130
|
+
if (runs.length > 50) runs.length = 50;
|
|
131
|
+
this.history.set(id, runs);
|
|
132
|
+
this.save();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
getHistory(id, limit = 20) {
|
|
136
|
+
const runs = this.history.get(id) || [];
|
|
137
|
+
return runs.slice(0, limit);
|
|
138
|
+
}
|
|
139
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@goodandready/dsh-cron",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scheduled cron tasks, background automation and agent execution for DeepSeek Harness.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/index.js",
|
|
9
|
+
"./client": "./lib/client.js",
|
|
10
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"lib/",
|
|
15
|
+
"cordis.patch.yml",
|
|
16
|
+
"README.md",
|
|
17
|
+
"docs/",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test test/*.test.mjs"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"dsh",
|
|
25
|
+
"dsh-plugin",
|
|
26
|
+
"cron",
|
|
27
|
+
"scheduler",
|
|
28
|
+
"automation",
|
|
29
|
+
"deepseek-harness"
|
|
30
|
+
],
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/GooDAnDReaDY/dsh-cron.git"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/GooDAnDReaDY/dsh-cron#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/GooDAnDReaDY/dsh-cron/issues"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"dsh": {
|
|
41
|
+
"bundle": {
|
|
42
|
+
"patch": "./cordis.patch.yml"
|
|
43
|
+
},
|
|
44
|
+
"client": {
|
|
45
|
+
"platform": "web",
|
|
46
|
+
"inject": [
|
|
47
|
+
"@deepseek-ai/dsh-client-runtime",
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"croner": "^9.1.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
57
|
+
"@deepseek-ai/dsh-agent": ">=0.1.0-rc.6 <0.1.1 || >=0.1.1-rc.1 <0.1.2 || >=0.1.2-alpha.1 <1.0.0",
|
|
58
|
+
"@deepseek-ai/dsh-llm": ">=0.1.0-rc.6 <0.1.1 || >=0.1.1-rc.1 <0.1.2 || >=0.1.2-alpha.1 <1.0.0",
|
|
59
|
+
"@deepseek-ai/dsh-session": ">=0.1.0-rc.6 <0.1.1 || >=0.1.1-rc.1 <0.1.2 || >=0.1.2-alpha.1 <1.0.0",
|
|
60
|
+
"@deepseek-ai/dsh-settings": ">=0.1.0-rc.6 <0.1.1 || >=0.1.1-rc.1 <0.1.2 || >=0.1.2-alpha.1 <1.0.0",
|
|
61
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.6 <0.1.1 || >=0.1.1-rc.1 <0.1.2 || >=0.1.2-alpha.1 <1.0.0",
|
|
62
|
+
"@deepseek-ai/schemastery": "^3.18.1"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"@deepseek-ai/cordis": {
|
|
66
|
+
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"@deepseek-ai/dsh-settings": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"@deepseek-ai/schemastery": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@deepseek-ai/dsh-agent": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"@deepseek-ai/dsh-session": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"@deepseek-ai/dsh-llm": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"@deepseek-ai/dsh-tools": {
|
|
84
|
+
"optional": true
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"registry": "https://registry.npmjs.org",
|
|
89
|
+
"access": "public"
|
|
90
|
+
}
|
|
91
|
+
}
|