@crewx/cron 0.1.2 → 0.1.4
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/SKILL.md +349 -0
- package/package.json +5 -3
package/SKILL.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cron
|
|
3
|
+
description: Cron Scheduler skill for CrewX - Schedule and execute crewx/shell commands automatically using cron expressions.
|
|
4
|
+
version: 1.1.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Cron Scheduler Skill
|
|
8
|
+
|
|
9
|
+
> **Phase**: 1 (MVP)
|
|
10
|
+
|
|
11
|
+
Schedule and execute CrewX commands automatically using cron expressions.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The Cron Scheduler skill allows you to schedule `crewx q` (query), `crewx x` (execute), or raw shell commands to run automatically at specified intervals. It runs as a background daemon that checks schedules every minute and executes matching commands.
|
|
16
|
+
|
|
17
|
+
The daemon is managed by **PM2** (Process Manager 2), providing robust process management with automatic restarts, log management, and cross-platform compatibility.
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Navigate to skill directory
|
|
23
|
+
cd skills/cron
|
|
24
|
+
|
|
25
|
+
# Install dependencies (includes PM2)
|
|
26
|
+
npm install
|
|
27
|
+
|
|
28
|
+
# Add a schedule (daily at 9:00 AM)
|
|
29
|
+
node cron.js add "0 9 * * *" "@crewx_claude_dev Daily code review"
|
|
30
|
+
|
|
31
|
+
# Start the daemon (uses PM2)
|
|
32
|
+
node cron.js start
|
|
33
|
+
|
|
34
|
+
# Check status
|
|
35
|
+
node cron.js status
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Prerequisites
|
|
39
|
+
|
|
40
|
+
This skill requires **PM2** (Process Manager 2) for daemon management. PM2 is included in the package dependencies and will be installed automatically when you run `npm install`.
|
|
41
|
+
|
|
42
|
+
If you need to install PM2 globally:
|
|
43
|
+
```bash
|
|
44
|
+
npm install -g pm2
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Commands
|
|
48
|
+
|
|
49
|
+
### Schedule Management
|
|
50
|
+
|
|
51
|
+
| Command | Description |
|
|
52
|
+
|---------|-------------|
|
|
53
|
+
| `add <cron> <command>` | Add a new schedule |
|
|
54
|
+
| `list` | List all schedules |
|
|
55
|
+
| `update <id>` | Update a schedule |
|
|
56
|
+
| `remove <id>` | Remove a schedule |
|
|
57
|
+
| `enable <id>` | Enable a schedule |
|
|
58
|
+
| `disable <id>` | Disable a schedule |
|
|
59
|
+
| `info <id>` | Show schedule details |
|
|
60
|
+
| `run <id>` | Run a schedule immediately (testing) |
|
|
61
|
+
|
|
62
|
+
### Daemon Management
|
|
63
|
+
|
|
64
|
+
| Command | Description |
|
|
65
|
+
|---------|-------------|
|
|
66
|
+
| `start` | Start the cron daemon |
|
|
67
|
+
| `stop` | Stop the cron daemon |
|
|
68
|
+
| `status` | Check daemon status |
|
|
69
|
+
|
|
70
|
+
## Usage Examples
|
|
71
|
+
|
|
72
|
+
### Basic Scheduling
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Daily code review at 9:00 AM
|
|
76
|
+
node cron.js add "0 9 * * *" "@crewx_claude_dev Daily code review" --name "Daily Review"
|
|
77
|
+
|
|
78
|
+
# Weekly report every Friday at 5:00 PM
|
|
79
|
+
node cron.js add "0 17 * * 5" "@crewx_gemini_dev Generate weekly report" --name "Weekly Report"
|
|
80
|
+
|
|
81
|
+
# Every hour on weekdays
|
|
82
|
+
node cron.js add "0 * * * 1-5" "@claude Check for new issues"
|
|
83
|
+
|
|
84
|
+
# Run a shell command
|
|
85
|
+
node cron.js add "*/5 * * * *" "echo hello >> /tmp/cron.log" --mode command --name "Hello Log"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Options
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
node cron.js add "0 9 * * *" "@agent command" \
|
|
92
|
+
--name "My Schedule" # Human-readable name
|
|
93
|
+
--mode query # "query", "execute", or "command" (default: execute)
|
|
94
|
+
--timezone "Asia/Seoul" # IANA timezone
|
|
95
|
+
--dir "/path/to/project" # Working directory
|
|
96
|
+
--timeout 300000 # Timeout in ms (default: 600000 = 10min)
|
|
97
|
+
--allow-concurrent # Allow overlapping executions
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Managing Schedules
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# List all schedules
|
|
104
|
+
node cron.js list
|
|
105
|
+
|
|
106
|
+
# Show schedule details
|
|
107
|
+
node cron.js info abc123
|
|
108
|
+
|
|
109
|
+
# Update a schedule (no need to remove and add again!)
|
|
110
|
+
node cron.js update abc123 --cron="0 10 * * *" # Change cron expression
|
|
111
|
+
node cron.js update abc123 --command="@agent new" # Change command
|
|
112
|
+
node cron.js update abc123 --name="New Name" # Change name
|
|
113
|
+
node cron.js update abc123 --cron="30 8 * * *" --name="Morning Task" # Multiple changes
|
|
114
|
+
|
|
115
|
+
# Disable/enable a schedule
|
|
116
|
+
node cron.js disable abc123
|
|
117
|
+
node cron.js enable abc123
|
|
118
|
+
|
|
119
|
+
# Remove a schedule
|
|
120
|
+
node cron.js remove abc123
|
|
121
|
+
|
|
122
|
+
# Test run a schedule immediately
|
|
123
|
+
node cron.js run abc123
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Update Options
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
node cron.js update <id> \
|
|
130
|
+
--cron "0 9 * * *" # New cron expression
|
|
131
|
+
--command "@agent task" # New command
|
|
132
|
+
--name "New Name" # New name
|
|
133
|
+
--mode query # "query", "execute", or "command"
|
|
134
|
+
--timezone "Asia/Seoul" # IANA timezone
|
|
135
|
+
--dir "/path/to/project" # Working directory
|
|
136
|
+
--timeout 300000 # Timeout in ms
|
|
137
|
+
--allow-concurrent # Allow overlapping executions
|
|
138
|
+
--no-allow-concurrent # Disallow overlapping executions
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Daemon Control
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Start daemon in background (via PM2)
|
|
145
|
+
node cron.js start
|
|
146
|
+
|
|
147
|
+
# Check if daemon is running
|
|
148
|
+
node cron.js status
|
|
149
|
+
|
|
150
|
+
# Stop daemon (via PM2)
|
|
151
|
+
node cron.js stop
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The daemon is managed by **PM2**, which provides:
|
|
155
|
+
- Automatic restarts on crashes
|
|
156
|
+
- Log management
|
|
157
|
+
- Process monitoring
|
|
158
|
+
- Cross-platform compatibility
|
|
159
|
+
|
|
160
|
+
### Auto-Start Behavior
|
|
161
|
+
|
|
162
|
+
User commands like `add`, `list`, `run`, `enable`, `disable`, `update`, and `info` will automatically start the daemon if it is not running:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
⚡ cron 데몬이 꺼져 있어서 자동 시작합니다...
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
You can also use PM2 commands directly:
|
|
169
|
+
```bash
|
|
170
|
+
# View PM2 process list
|
|
171
|
+
pm2 list
|
|
172
|
+
|
|
173
|
+
# View daemon logs
|
|
174
|
+
pm2 logs cron-daemon
|
|
175
|
+
|
|
176
|
+
# Monitor daemon
|
|
177
|
+
pm2 monit
|
|
178
|
+
|
|
179
|
+
# Restart daemon
|
|
180
|
+
pm2 restart cron-daemon
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Cron Expression Format
|
|
184
|
+
|
|
185
|
+
Standard 5-field cron format: `minute hour day month weekday`
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
┌───────────── minute (0 - 59)
|
|
189
|
+
│ ┌───────────── hour (0 - 23)
|
|
190
|
+
│ │ ┌───────────── day of month (1 - 31)
|
|
191
|
+
│ │ │ ┌───────────── month (1 - 12)
|
|
192
|
+
│ │ │ │ ┌───────────── day of week (0 - 6, Sunday = 0)
|
|
193
|
+
│ │ │ │ │
|
|
194
|
+
* * * * *
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Special Characters
|
|
198
|
+
|
|
199
|
+
| Character | Description | Example |
|
|
200
|
+
|-----------|-------------|---------|
|
|
201
|
+
| `*` | Any value | `* * * * *` (every minute) |
|
|
202
|
+
| `*/n` | Every n | `*/5 * * * *` (every 5 minutes) |
|
|
203
|
+
| `a-b` | Range | `0 9-17 * * *` (9 AM to 5 PM) |
|
|
204
|
+
| `a,b,c` | List | `0 9,12,18 * * *` (9 AM, 12 PM, 6 PM) |
|
|
205
|
+
|
|
206
|
+
### Common Patterns
|
|
207
|
+
|
|
208
|
+
| Expression | Description |
|
|
209
|
+
|------------|-------------|
|
|
210
|
+
| `0 9 * * *` | Every day at 9:00 AM |
|
|
211
|
+
| `0 9 * * 1-5` | Weekdays at 9:00 AM |
|
|
212
|
+
| `0 */2 * * *` | Every 2 hours |
|
|
213
|
+
| `*/30 * * * *` | Every 30 minutes |
|
|
214
|
+
| `0 0 * * 0` | Every Sunday at midnight |
|
|
215
|
+
| `0 0 1 * *` | First day of every month |
|
|
216
|
+
|
|
217
|
+
## File Structure
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
skills/cron/
|
|
221
|
+
├── cron.js # Main CLI + daemon
|
|
222
|
+
├── ecosystem.config.js # PM2 configuration
|
|
223
|
+
├── package.json # Dependencies
|
|
224
|
+
├── SKILL.md # This documentation
|
|
225
|
+
├── .cron-data.json # Schedule data (auto-created)
|
|
226
|
+
└── .daemon.log # Daemon log file (auto-created)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Timezone Support
|
|
230
|
+
|
|
231
|
+
Specify timezone using IANA format:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Schedule for Asia/Seoul timezone
|
|
235
|
+
node cron.js add "0 9 * * *" "@agent task" --timezone "Asia/Seoul"
|
|
236
|
+
|
|
237
|
+
# Schedule for US Pacific time
|
|
238
|
+
node cron.js add "0 9 * * *" "@agent task" --timezone "America/Los_Angeles"
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
If no timezone is specified, local system time is used.
|
|
242
|
+
|
|
243
|
+
## Concurrent Execution Prevention
|
|
244
|
+
|
|
245
|
+
By default, a schedule will not start a new execution if the previous one is still running. This prevents overlap when commands take longer than expected.
|
|
246
|
+
|
|
247
|
+
To allow concurrent executions:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
node cron.js add "* * * * *" "@agent task" --allow-concurrent
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Cross-Platform Compatibility
|
|
254
|
+
|
|
255
|
+
This skill supports Windows, macOS, and Linux:
|
|
256
|
+
|
|
257
|
+
- **Windows**: Uses `windowsHide: true` to prevent console popups, `taskkill` for process termination
|
|
258
|
+
- **Unix/macOS**: Uses standard SIGTERM signals
|
|
259
|
+
|
|
260
|
+
## Troubleshooting
|
|
261
|
+
|
|
262
|
+
### Daemon won't start
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# Check if already running
|
|
266
|
+
node cron.js status
|
|
267
|
+
|
|
268
|
+
# Or check PM2 directly
|
|
269
|
+
pm2 list
|
|
270
|
+
|
|
271
|
+
# If stale process exists, stop first
|
|
272
|
+
node cron.js stop
|
|
273
|
+
node cron.js start
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Check daemon logs
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# View daemon logs via PM2
|
|
280
|
+
pm2 logs cron-daemon
|
|
281
|
+
|
|
282
|
+
# Or view log file directly
|
|
283
|
+
tail -f skills/cron/.daemon.log
|
|
284
|
+
|
|
285
|
+
# View PM2 process info
|
|
286
|
+
pm2 show cron-daemon
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Schedule not executing
|
|
290
|
+
|
|
291
|
+
1. Check if daemon is running: `node cron.js status` or `pm2 list`
|
|
292
|
+
2. Verify schedule is enabled: `node cron.js info <id>`
|
|
293
|
+
3. Check cron expression is correct
|
|
294
|
+
4. Test manually: `node cron.js run <id>`
|
|
295
|
+
5. Check daemon logs: `pm2 logs cron-daemon`
|
|
296
|
+
|
|
297
|
+
### PM2 not found
|
|
298
|
+
|
|
299
|
+
If you get "pm2 command not found", ensure PM2 is installed:
|
|
300
|
+
```bash
|
|
301
|
+
npm install # Installs PM2 locally in node_modules
|
|
302
|
+
# Or install globally
|
|
303
|
+
npm install -g pm2
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Security Note
|
|
307
|
+
|
|
308
|
+
Do not include sensitive information directly in commands. Use environment variables instead:
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
# Bad - API key exposed in schedule
|
|
312
|
+
node cron.js add "0 9 * * *" "@agent API_KEY=secret task"
|
|
313
|
+
|
|
314
|
+
# Good - Use environment variables
|
|
315
|
+
export API_KEY=secret
|
|
316
|
+
node cron.js add "0 9 * * *" "@agent task using env"
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## API Reference
|
|
320
|
+
|
|
321
|
+
### Schedule Object
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
interface Schedule {
|
|
325
|
+
id: string; // 6-character unique ID
|
|
326
|
+
cron: string; // Cron expression (5 fields)
|
|
327
|
+
command: string; // CrewX command to execute
|
|
328
|
+
mode: "query" | "execute" | "command"; // Execution mode
|
|
329
|
+
enabled: boolean; // Whether schedule is active
|
|
330
|
+
name?: string; // Human-readable name
|
|
331
|
+
working_directory?: string; // Execution directory
|
|
332
|
+
timezone?: string; // IANA timezone
|
|
333
|
+
timeout_ms?: number; // Timeout (default: 600000)
|
|
334
|
+
allow_concurrent?: boolean; // Allow overlapping runs
|
|
335
|
+
created_at: string; // ISO 8601 timestamp
|
|
336
|
+
updated_at: string; // ISO 8601 timestamp
|
|
337
|
+
last_run?: string; // Last execution time
|
|
338
|
+
next_run?: string; // Next scheduled time
|
|
339
|
+
run_count?: number; // Total execution count
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Future Enhancements (Phase 2+)
|
|
344
|
+
|
|
345
|
+
- Execution history with detailed logs
|
|
346
|
+
- Integration with CrewX TracingService
|
|
347
|
+
- Web UI for schedule management
|
|
348
|
+
- Notification on failure
|
|
349
|
+
- Retry logic for failed executions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewx/cron",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Cron Scheduler for CrewX - Schedule and execute crewx commands automatically",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/src/engine.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"bin": { "cron": "./dist/cli.js" },
|
|
15
|
-
"files": ["dist"],
|
|
15
|
+
"files": ["dist", "SKILL.md"],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc",
|
|
18
18
|
"dev": "ts-node cli.ts",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"keywords": ["crewx", "cron", "scheduler", "automation"],
|
|
22
22
|
"license": "MIT",
|
|
23
|
-
"dependencies": {
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@crewx/shared": "0.0.3"
|
|
25
|
+
},
|
|
24
26
|
"devDependencies": {
|
|
25
27
|
"@types/node": "^20.0.0",
|
|
26
28
|
"ts-node": "^10.9.0",
|