@crewx/cron 0.1.10-rc.19 → 0.1.10-rc.190

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/dist/cli.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ export declare const CRON_RUNTIME_LIFECYCLE_MANAGED = "CRON_RUNTIME_LIFECYCLE_MANAGED";
3
+ export declare function formatDisplayTimestamp(date: Date): string;
2
4
  export declare function main(inputArgs?: string[]): Promise<void>;
3
- //# sourceMappingURL=cli.d.ts.map
5
+
package/dist/cli.js CHANGED
@@ -1,93 +1,6 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.main = main;
38
- const fs = __importStar(require("fs"));
39
- const path = __importStar(require("path"));
40
- let PKG_VERSION = 'unknown';
41
- try {
42
- const _pkgPath = fs.existsSync(path.join(__dirname, 'package.json'))
43
- ? path.join(__dirname, 'package.json')
44
- : path.join(__dirname, '..', 'package.json');
45
- const _pkg = JSON.parse(fs.readFileSync(_pkgPath, 'utf-8'));
46
- if (_pkg?.version)
47
- PKG_VERSION = String(_pkg.version);
48
- }
49
- catch { }
50
- async function loadTracer() {
51
- try {
52
- return await Promise.resolve().then(() => __importStar(require('@crewx/shared/skill-tracer')));
53
- }
54
- catch {
55
- return null;
56
- }
57
- }
58
- const engine_1 = require("./src/engine");
59
- function getOpt(args, long, short) {
60
- for (let i = 0; i < args.length; i++) {
61
- const a = args[i];
62
- if (!a)
63
- continue;
64
- if (a === long || (short && a === short)) {
65
- return args[i + 1];
66
- }
67
- if (a.startsWith(long + '=')) {
68
- return a.slice(long.length + 1);
69
- }
70
- if (short && a.startsWith(short + '=')) {
71
- return a.slice(short.length + 1);
72
- }
73
- }
74
- return undefined;
75
- }
76
- function hasFlag(args, long, short) {
77
- return args.includes(long) || (short ? args.includes(short) : false);
78
- }
79
- function showDetailedUsage() {
80
- const skillMd = path.join(__dirname, '..', 'SKILL.md');
81
- if (fs.existsSync(skillMd)) {
82
- process.stdout.write(fs.readFileSync(skillMd, 'utf-8'));
83
- }
84
- else {
85
- console.log('No SKILL.md found. Use --help for usage.');
86
- }
87
- }
88
- function printUsage() {
89
- console.log(`
90
- @crewx/cron@${PKG_VERSION} - Cron-based task scheduler for AI agents
2
+ "use strict";var w=exports&&exports.__createBinding||(Object.create?(function(t,n,s,o){if(o===void 0)o=s;var e=Object.getOwnPropertyDescriptor(n,s);if(!e||("get"in e?!n.__esModule:e.writable||e.configurable)){e={enumerable:true,get:function(){return n[s]}}}Object.defineProperty(t,o,e)}):(function(t,n,s,o){if(o===void 0)o=s;t[o]=n[s]}));var S=exports&&exports.__setModuleDefault||(Object.create?(function(t,n){Object.defineProperty(t,"default",{enumerable:true,value:n})}):function(t,n){t["default"]=n});var p=exports&&exports.__importStar||(function(){var t=function(n){t=Object.getOwnPropertyNames||function(s){var o=[];for(var e in s)if(Object.prototype.hasOwnProperty.call(s,e))o[o.length]=e;return o};return t(n)};return function(n){if(n&&n.__esModule)return n;var s={};if(n!=null){for(var o=t(n),e=0;e<o.length;e++)if(o[e]!=="default")w(s,n,o[e])}S(s,n);return s}})();Object.defineProperty(exports,"__esModule",{value:true});exports.CRON_RUNTIME_LIFECYCLE_MANAGED=void 0;exports.formatDisplayTimestamp=m;exports.main=b;const f=p(require("fs"));const h=p(require("path"));let _="unknown";try{const t=f.existsSync(h.join(__dirname,"package.json"))?h.join(__dirname,"package.json"):h.join(__dirname,"..","package.json");const n=JSON.parse(f.readFileSync(t,"utf-8"));if(n?.version)_=String(n.version)}catch{}async function C(){try{return await Promise.resolve().then(()=>p(require("@crewx/shared/skill-tracer")))}catch{return null}}const a=require("./src/engine");exports.CRON_RUNTIME_LIFECYCLE_MANAGED="CRON_RUNTIME_LIFECYCLE_MANAGED";function $(t){const n=new Error(`${exports.CRON_RUNTIME_LIFECYCLE_MANAGED}: cron ${t} is managed by the CrewX server runtime; start the server instead`);n.code=exports.CRON_RUNTIME_LIFECYCLE_MANAGED;return n}function i(t,n,s){for(let o=0;o<t.length;o++){const e=t[o];if(!e)continue;if(e===n||s&&e===s){return t[o+1]}if(e.startsWith(n+"=")){return e.slice(n.length+1)}if(s&&e.startsWith(s+"=")){return e.slice(s.length+1)}}return void 0}function d(t,n,s){return t.includes(n)||(s?t.includes(s):false)}function E(){const t=h.join(__dirname,"..","SKILL.md");if(f.existsSync(t)){process.stdout.write(f.readFileSync(t,"utf-8"))}else{console.log("No SKILL.md found. Use --help for usage.")}}function m(t){const n=t.toISOString();return`${n.slice(0,10)} ${n.slice(11,19)} UTC`}function v(){console.log(`
3
+ @crewx/cron@${_} - Cron-based task scheduler for AI agents
91
4
 
92
5
  Usage:
93
6
  cron <command> [options]
@@ -117,323 +30,7 @@ Examples:
117
30
  cron start
118
31
 
119
32
  For detailed usage guide: cron usage
120
- `);
121
- }
122
- async function main(inputArgs) {
123
- const args = inputArgs ?? process.argv.slice(2);
124
- const command = args[0];
125
- if (args.length > 0 && command !== 'daemon') {
126
- (0, engine_1.logUsage)(args.join(' '));
127
- }
128
- if (hasFlag(args, '--version')) {
129
- console.log(PKG_VERSION);
130
- return;
131
- }
132
- if (!command || command === 'help' || hasFlag(args, '--help', '-h')) {
133
- printUsage();
134
- return;
135
- }
136
- switch (command) {
137
- case 'usage': {
138
- showDetailedUsage();
139
- break;
140
- }
141
- case 'add': {
142
- const positional = [];
143
- for (let i = 1; i < args.length; i++) {
144
- const arg = args[i];
145
- if (!arg)
146
- continue;
147
- if (arg.startsWith('-')) {
148
- if (['--name', '-n', '--mode', '-m', '--timezone', '-t', '--dir', '-d', '--timeout'].includes(arg)) {
149
- i++;
150
- }
151
- continue;
152
- }
153
- positional.push(arg);
154
- }
155
- if (positional.length < 2) {
156
- console.error('Usage: cron add <schedule> <command> [--name <name>] [--mode <mode>]');
157
- process.exit(1);
158
- }
159
- const cronExpr = positional[0];
160
- const cmd = positional.slice(1).join(' ');
161
- const subArgs = args.slice(1);
162
- (0, engine_1.ensureDaemonRunning)();
163
- const schedule = (0, engine_1.addSchedule)(cronExpr, cmd, {
164
- name: getOpt(subArgs, '--name', '-n'),
165
- mode: getOpt(subArgs, '--mode', '-m'),
166
- timezone: getOpt(subArgs, '--timezone', '-t'),
167
- dir: getOpt(subArgs, '--dir', '-d'),
168
- timeout: getOpt(subArgs, '--timeout'),
169
- allowConcurrent: hasFlag(subArgs, '--allow-concurrent'),
170
- });
171
- console.log(`Schedule created: ${schedule.id}`);
172
- console.log(`Cron: ${cronExpr} (${(0, engine_1.describeCron)(cronExpr)})`);
173
- console.log(`Command: ${cmd}`);
174
- console.log(`Mode: ${schedule.mode}`);
175
- if (schedule.timezone)
176
- console.log(`Timezone: ${schedule.timezone}`);
177
- if (schedule.next_run)
178
- console.log(`Next run: ${new Date(schedule.next_run).toLocaleString()}`);
179
- break;
180
- }
181
- case 'list':
182
- case 'ls': {
183
- const jsonOutput = hasFlag(args, '--json');
184
- (0, engine_1.ensureDaemonRunning)();
185
- const schedules = (0, engine_1.loadSchedules)();
186
- if (jsonOutput) {
187
- console.log(JSON.stringify(schedules, null, 2));
188
- return;
189
- }
190
- if (schedules.length === 0) {
191
- console.log('No schedules found.');
192
- return;
193
- }
194
- console.log(`\nSchedules (${schedules.length}):\n`);
195
- console.log('| ID | Name | Cron | Status | Command |');
196
- console.log('|--------|----------------|-------------|--------|----------------------------|');
197
- for (const s of schedules) {
198
- const status = s.enabled ? 'ON ' : 'OFF';
199
- const name = (s.name ?? '-').substring(0, 14).padEnd(14);
200
- const cron = s.cron.substring(0, 11).padEnd(11);
201
- const cmd = s.command.substring(0, 26).padEnd(26);
202
- console.log(`| ${s.id} | ${name} | ${cron} | ${status} | ${cmd} |`);
203
- }
204
- console.log('');
205
- break;
206
- }
207
- case 'remove':
208
- case 'rm': {
209
- const id = args[1];
210
- if (!id) {
211
- console.error('Usage: cron remove <id>');
212
- process.exit(1);
213
- }
214
- (0, engine_1.ensureDaemonRunning)();
215
- try {
216
- const removed = (0, engine_1.removeSchedule)(id);
217
- console.log(`Removed schedule: ${id}`);
218
- console.log(`Cron: ${removed.cron}`);
219
- console.log(`Command: ${removed.command}`);
220
- }
221
- catch (e) {
222
- const err = e;
223
- console.error(err.message);
224
- process.exit(1);
225
- }
226
- break;
227
- }
228
- case 'enable': {
229
- const id = args[1];
230
- if (!id) {
231
- console.error('Usage: cron enable <id>');
232
- process.exit(1);
233
- }
234
- (0, engine_1.ensureDaemonRunning)();
235
- try {
236
- (0, engine_1.enableSchedule)(id);
237
- console.log(`Enabled schedule: ${id}`);
238
- }
239
- catch (e) {
240
- const err = e;
241
- console.error(err.message);
242
- process.exit(1);
243
- }
244
- break;
245
- }
246
- case 'disable': {
247
- const id = args[1];
248
- if (!id) {
249
- console.error('Usage: cron disable <id>');
250
- process.exit(1);
251
- }
252
- (0, engine_1.ensureDaemonRunning)();
253
- try {
254
- (0, engine_1.disableSchedule)(id);
255
- console.log(`Disabled schedule: ${id}`);
256
- }
257
- catch (e) {
258
- const err = e;
259
- console.error(err.message);
260
- process.exit(1);
261
- }
262
- break;
263
- }
264
- case 'update': {
265
- const id = args[1];
266
- if (!id) {
267
- console.error('Usage: cron update <id> [--cron <expr>] [--command <cmd>] [--name <name>]');
268
- process.exit(1);
269
- }
270
- const subArgs = args.slice(1);
271
- (0, engine_1.ensureDaemonRunning)();
272
- try {
273
- const updateOpts = {
274
- cron: getOpt(subArgs, '--cron', '-c'),
275
- command: getOpt(subArgs, '--command', '-C'),
276
- name: getOpt(subArgs, '--name', '-n'),
277
- mode: getOpt(subArgs, '--mode', '-m'),
278
- timezone: getOpt(subArgs, '--timezone', '-t'),
279
- working_directory: getOpt(subArgs, '--dir', '-d'),
280
- timeout_ms: getOpt(subArgs, '--timeout') ? parseInt(getOpt(subArgs, '--timeout'), 10) : undefined,
281
- allow_concurrent: hasFlag(subArgs, '--allow-concurrent') ? true : hasFlag(subArgs, '--no-allow-concurrent') ? false : undefined,
282
- };
283
- const { schedule, changes } = (0, engine_1.updateSchedule)(id, updateOpts);
284
- if (changes.length === 0) {
285
- console.log('No changes specified. Use --cron, --command, --name, etc.');
286
- process.exit(1);
287
- }
288
- console.log(`Updated schedule: ${id}`);
289
- changes.forEach(c => console.log(` ${c}`));
290
- if (schedule.next_run) {
291
- console.log(`Next run: ${new Date(schedule.next_run).toLocaleString()}`);
292
- }
293
- }
294
- catch (e) {
295
- const err = e;
296
- console.error(err.message);
297
- process.exit(1);
298
- }
299
- break;
300
- }
301
- case 'info': {
302
- const id = args[1];
303
- if (!id) {
304
- console.error('Usage: cron info <id>');
305
- process.exit(1);
306
- }
307
- const jsonOutput = hasFlag(args, '--json');
308
- (0, engine_1.ensureDaemonRunning)();
309
- const schedules = (0, engine_1.loadSchedules)();
310
- const schedule = schedules.find(s => s.id === id);
311
- if (!schedule) {
312
- console.error(`Schedule not found: ${id}`);
313
- process.exit(1);
314
- }
315
- if (jsonOutput) {
316
- console.log(JSON.stringify(schedule, null, 2));
317
- return;
318
- }
319
- console.log(`\nSchedule: ${schedule.id}`);
320
- console.log('─'.repeat(40));
321
- console.log(`Name: ${schedule.name ?? '-'}`);
322
- console.log(`Cron: ${schedule.cron} (${(0, engine_1.describeCron)(schedule.cron)})`);
323
- console.log(`Command: ${schedule.command}`);
324
- console.log(`Mode: ${schedule.mode}`);
325
- console.log(`Status: ${schedule.enabled ? 'Enabled' : 'Disabled'}`);
326
- console.log(`Timezone: ${schedule.timezone ?? 'Local'}`);
327
- console.log(`Working Dir: ${schedule.working_directory ?? 'Project root'}`);
328
- console.log(`Timeout: ${schedule.timeout_ms / 1000}s`);
329
- console.log(`Allow Concurrent: ${schedule.allow_concurrent ? 'Yes' : 'No'}`);
330
- console.log('─'.repeat(40));
331
- console.log(`Created: ${new Date(schedule.created_at).toLocaleString()}`);
332
- console.log(`Updated: ${new Date(schedule.updated_at).toLocaleString()}`);
333
- console.log(`Last Run: ${schedule.last_run ? new Date(schedule.last_run).toLocaleString() : 'Never'}`);
334
- console.log(`Next Run: ${schedule.next_run ? new Date(schedule.next_run).toLocaleString() : 'Unknown'}`);
335
- console.log(`Run Count: ${schedule.run_count ?? 0}`);
336
- console.log('');
337
- break;
338
- }
339
- case 'run': {
340
- const id = args[1];
341
- if (!id) {
342
- console.error('Usage: cron run <id>');
343
- process.exit(1);
344
- }
345
- (0, engine_1.ensureDaemonRunning)();
346
- const schedules = (0, engine_1.loadSchedules)();
347
- const schedule = schedules.find(s => s.id === id);
348
- if (!schedule) {
349
- console.error(`Schedule not found: ${id}`);
350
- process.exit(1);
351
- }
352
- console.log(`Running schedule: ${id}`);
353
- const result = await (0, engine_1.executeSchedule)(schedule);
354
- console.log(`Result: ${result.success ? 'Success' : 'Failed'}`);
355
- if (result.error)
356
- console.log(`Error: ${result.error}`);
357
- break;
358
- }
359
- case 'start': {
360
- if ((0, engine_1.isDaemonRunning)()) {
361
- const status = (0, engine_1.getDaemonStatus)();
362
- console.error(`Daemon already running (PID: ${status.pid ?? 'unknown'})`);
363
- process.exit(1);
364
- }
365
- try {
366
- const pid = (0, engine_1.startDaemon)();
367
- console.log(`Cron daemon started (PID: ${pid})`);
368
- console.log(`PID file: ${engine_1.DATA_PATHS.PID_FILE}`);
369
- }
370
- catch (e) {
371
- const err = e;
372
- console.error('Failed to start daemon:', err.message);
373
- process.exit(1);
374
- }
375
- break;
376
- }
377
- case 'stop': {
378
- try {
379
- const stopped = (0, engine_1.stopDaemon)();
380
- if (!stopped) {
381
- console.error('Daemon not running');
382
- process.exit(1);
383
- }
384
- console.log('Cron daemon stopped');
385
- }
386
- catch (e) {
387
- const err = e;
388
- console.error('Failed to stop daemon:', err.message);
389
- process.exit(1);
390
- }
391
- break;
392
- }
393
- case 'status': {
394
- const jsonOutput = hasFlag(args, '--json');
395
- const status = (0, engine_1.getDaemonStatus)();
396
- if (jsonOutput) {
397
- console.log(JSON.stringify(status, null, 2));
398
- return;
399
- }
400
- if (status.running && status.pid) {
401
- console.log(`Daemon is running (PID: ${status.pid})`);
402
- if (status.started_at) {
403
- console.log(`Started: ${new Date(status.started_at).toLocaleString()}`);
404
- }
405
- }
406
- else {
407
- console.log('Daemon is not running');
408
- }
409
- console.log(`Schedules: ${status.schedules.enabled}/${status.schedules.total} enabled`);
410
- break;
411
- }
412
- case 'daemon': {
413
- if (hasFlag(args, '--foreground')) {
414
- (0, engine_1.runDaemonForeground)();
415
- }
416
- else {
417
- console.log('Use "cron start" to start the daemon');
418
- }
419
- break;
420
- }
421
- default: {
422
- console.error(`Unknown command: ${command}`);
423
- printUsage();
424
- process.exit(1);
425
- }
426
- }
427
- }
428
- if (require.main === module) {
429
- const _args = process.argv.slice(2);
430
- const _isDaemonForeground = _args[0] === 'daemon' && _args.includes('--foreground');
431
- (_isDaemonForeground ? Promise.resolve(null) : loadTracer()).then(tracer => {
432
- const opts = tracer ? { skillVersion: tracer.getOwnSkillVersion(__dirname) } : {};
433
- return tracer ? tracer.run('crewx/cron', () => main(), opts) : main();
434
- }).catch((e) => {
435
- console.error(e.message);
436
- process.exit(1);
437
- });
438
- }
439
- //# sourceMappingURL=cli.js.map
33
+ `)}async function b(t){const n=t??process.argv.slice(2);const s=n[0];if(d(n,"--version")){console.log(_);return}if(!s||s==="help"||d(n,"--help","-h")){v();return}switch(s){case"usage":{E();break}case"add":{const o=[];for(let u=1;u<n.length;u++){const g=n[u];if(!g)continue;if(g.startsWith("-")){if(["--name","-n","--mode","-m","--timezone","-t","--dir","-d","--timeout","--model","--provider"].includes(g)){u++}continue}o.push(g)}if(o.length<2){console.error("Usage: cron add <schedule> <command> [--name <name>] [--mode <mode>] [--model <model>] [--provider <provider>]");process.exit(1)}const e=o[0];const c=o.slice(1).join(" ");const r=n.slice(1);const l=(0,a.addSchedule)(e,c,{name:i(r,"--name","-n"),mode:i(r,"--mode","-m"),timezone:i(r,"--timezone","-t"),dir:i(r,"--dir","-d"),timeout:i(r,"--timeout"),allowConcurrent:d(r,"--allow-concurrent"),model:i(r,"--model"),provider:i(r,"--provider")});console.log(`Schedule created: ${l.id}`);console.log(`Cron: ${e} (${(0,a.describeCron)(e)})`);console.log(`Command: ${c}`);console.log(`Mode: ${l.mode}`);if(l.model)console.log(`Model: ${l.model}`);if(l.provider)console.log(`Provider: ${l.provider}`);if(l.timezone)console.log(`Timezone: ${l.timezone}`);if(l.next_run)console.log(`Next run: ${m(new Date(l.next_run))}`);break}case"list":case"ls":{const o=d(n,"--json");const e=(0,a.loadSchedules)();if(o){console.log(JSON.stringify(e,null,2));return}if(e.length===0){console.log("No schedules found.");return}console.log(`
34
+ Schedules (${e.length}):
35
+ `);console.log("| ID | Name | Cron | Status | Command |");console.log("|--------|----------------|-------------|--------|----------------------------|");for(const c of e){const r=c.enabled?"ON ":"OFF";const l=(c.name??"-").substring(0,14).padEnd(14);const u=c.cron.substring(0,11).padEnd(11);const g=c.command.substring(0,26).padEnd(26);console.log(`| ${c.id} | ${l} | ${u} | ${r} | ${g} |`)}console.log("");break}case"remove":case"rm":{const o=n[1];if(!o){console.error("Usage: cron remove <id>");process.exit(1)}try{const e=(0,a.removeSchedule)(o);console.log(`Removed schedule: ${o}`);console.log(`Cron: ${e.cron}`);console.log(`Command: ${e.command}`)}catch(e){const c=e;console.error(c.message);process.exit(1)}break}case"enable":{const o=n[1];if(!o){console.error("Usage: cron enable <id>");process.exit(1)}try{(0,a.enableSchedule)(o);console.log(`Enabled schedule: ${o}`)}catch(e){const c=e;console.error(c.message);process.exit(1)}break}case"disable":{const o=n[1];if(!o){console.error("Usage: cron disable <id>");process.exit(1)}try{(0,a.disableSchedule)(o);console.log(`Disabled schedule: ${o}`)}catch(e){const c=e;console.error(c.message);process.exit(1)}break}case"update":{const o=n[1];if(!o){console.error("Usage: cron update <id> [--cron <expr>] [--command <cmd>] [--name <name>] [--model <model>] [--clear-model] [--provider <provider>] [--clear-provider]");process.exit(1)}const e=n.slice(1);try{const c={cron:i(e,"--cron","-c"),command:i(e,"--command","-C"),name:i(e,"--name","-n"),mode:i(e,"--mode","-m"),timezone:i(e,"--timezone","-t"),working_directory:i(e,"--dir","-d"),timeout_ms:i(e,"--timeout")?parseInt(i(e,"--timeout"),10):void 0,allow_concurrent:d(e,"--allow-concurrent")?true:d(e,"--no-allow-concurrent")?false:void 0,model:d(e,"--clear-model")?null:i(e,"--model"),provider:d(e,"--clear-provider")?null:i(e,"--provider")};const{schedule:r,changes:l}=(0,a.updateSchedule)(o,c);if(l.length===0){console.log("No changes specified. Use --cron, --command, --name, etc.");process.exit(1)}console.log(`Updated schedule: ${o}`);l.forEach(u=>console.log(` ${u}`));if(r.next_run){console.log(`Next run: ${m(new Date(r.next_run))}`)}}catch(c){const r=c;console.error(r.message);process.exit(1)}break}case"info":{const o=n[1];if(!o){console.error("Usage: cron info <id>");process.exit(1)}const e=d(n,"--json");const c=(0,a.loadSchedules)();const r=c.find(l=>l.id===o);if(!r){console.error(`Schedule not found: ${o}`);process.exit(1)}if(e){console.log(JSON.stringify(r,null,2));return}console.log(`
36
+ Schedule: ${r.id}`);console.log("\u2500".repeat(40));console.log(`Name: ${r.name??"-"}`);console.log(`Cron: ${r.cron} (${(0,a.describeCron)(r.cron)})`);console.log(`Command: ${r.command}`);console.log(`Mode: ${r.mode}`);console.log(`Model: ${r.model??"(agent default)"}`);console.log(`Provider: ${r.provider??"(agent default)"}`);console.log(`Status: ${r.enabled?"Enabled":"Disabled"}`);console.log(`Timezone: ${r.timezone??"Local"}`);console.log(`Working Dir: ${r.working_directory??"Project root"}`);console.log(`Timeout: ${r.timeout_ms/1e3}s`);console.log(`Allow Concurrent: ${r.allow_concurrent?"Yes":"No"}`);console.log("\u2500".repeat(40));console.log(`Created: ${m(new Date(r.created_at))}`);console.log(`Updated: ${m(new Date(r.updated_at))}`);console.log(`Last Run: ${r.last_run?m(new Date(r.last_run)):"Never"}`);console.log(`Next Run: ${r.next_run?m(new Date(r.next_run)):"Unknown"}`);console.log(`Run Count: ${r.run_count??0}`);console.log("");break}case"run":{const o=n[1];if(!o){console.error("Usage: cron run <id>");process.exit(1)}const e=(0,a.loadSchedules)();const c=e.find(u=>u.id===o);if(!c){console.error(`Schedule not found: ${o}`);process.exit(1)}console.log(`Running schedule: ${o}`);const r=await(0,a.executeSchedule)(c,{trigger:"cron_manual"});if(r.status==="blocked"){console.error("A desktop update is draining active work; cannot start a new schedule run right now.");process.exit(1)}if(r.status==="conflict"){console.error(`Schedule already running (task: ${r.runningTaskId})`);process.exit(1)}console.log(`Task started: ${r.taskId}`);const l=await r.done;console.log(`Result: ${l.success?"Success":"Failed"}`);if(l.error)console.log(`Error: ${l.error}`);break}case"start":{throw $(s)}case"stop":{throw $(s)}case"status":{const o=d(n,"--json");const e=(0,a.getDaemonStatus)();if(o){console.log(JSON.stringify(e,null,2));return}if(e.running&&e.pid){console.log(`Daemon is running (PID: ${e.pid})`);if(e.started_at){console.log(`Started: ${m(new Date(e.started_at))}`)}}else{console.log("Daemon is not running")}console.log(`Schedules: ${e.schedules.enabled}/${e.schedules.total} enabled`);break}case"daemon":{if(d(n,"--foreground")){(0,a.runDaemonForeground)()}else{throw $(s)}break}default:{console.error(`Unknown command: ${s}`);v();process.exit(1)}}}if(require.main===module){const t=process.argv.slice(2);const n=t[0]==="daemon"&&t.includes("--foreground");(n?Promise.resolve(null):C()).then(s=>{const o=s?{skillVersion:s.getOwnSkillVersion(__dirname)}:{};return s?s.run("crewx/cron",()=>b(),o):b()}).catch(s=>{console.error(s.message);process.exit(1)})}
@@ -0,0 +1,14 @@
1
+ import type { ExecutionMode } from './types';
2
+ export interface BuiltinScheduleDef {
3
+ builtin_id: string;
4
+ name: string;
5
+ cron: string;
6
+ mode: ExecutionMode;
7
+ buildCommand: () => string;
8
+ }
9
+ export declare function getProjectRoot(): string;
10
+ export declare function getBuiltinMemoryCliPath(): string;
11
+ export declare const BUILTIN_SCHEDULES: BuiltinScheduleDef[];
12
+ export declare function findBuiltinByName(name: string | null | undefined): BuiltinScheduleDef | undefined;
13
+ export declare function findBuiltinById(builtinId: string): BuiltinScheduleDef | undefined;
14
+
@@ -0,0 +1 @@
1
+ "use strict";var o=exports&&exports.__createBinding||(Object.create?(function(t,e,r,n){if(n===void 0)n=r;var i=Object.getOwnPropertyDescriptor(e,r);if(!i||("get"in i?!e.__esModule:i.writable||i.configurable)){i={enumerable:true,get:function(){return e[r]}}}Object.defineProperty(t,n,i)}):(function(t,e,r,n){if(n===void 0)n=r;t[n]=e[r]}));var a=exports&&exports.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:true,value:e})}):function(t,e){t["default"]=e});var f=exports&&exports.__importStar||(function(){var t=function(e){t=Object.getOwnPropertyNames||function(r){var n=[];for(var i in r)if(Object.prototype.hasOwnProperty.call(r,i))n[n.length]=i;return n};return t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null){for(var n=t(e),i=0;i<n.length;i++)if(n[i]!=="default")o(r,e,n[i])}a(r,e);return r}})();Object.defineProperty(exports,"__esModule",{value:true});exports.BUILTIN_SCHEDULES=void 0;exports.getProjectRoot=u;exports.getBuiltinMemoryCliPath=c;exports.findBuiltinByName=_;exports.findBuiltinById=s;const l=require("child_process");const d=f(require("path"));function u(){try{return(0,l.execSync)("git rev-parse --show-toplevel",{encoding:"utf8"}).trim()}catch{return process.cwd()}}function c(){return d.join(u(),"packages","built-in","memory","dist","cli.js")}exports.BUILTIN_SCHEDULES=[{builtin_id:"memory-debounce",name:"memory-debounce",cron:"*/1 * * * *",mode:"command",buildCommand:()=>`node ${c()} summarize-dirty`}];function _(t){if(!t)return void 0;return exports.BUILTIN_SCHEDULES.find(e=>e.name===t)}function s(t){return exports.BUILTIN_SCHEDULES.find(e=>e.builtin_id===t)}
@@ -1,23 +1,46 @@
1
- import type { Schedule, ExecutionMode, ExecuteResult, DaemonStatus, UpdateOptions } from './types';
2
- export type { Schedule, ExecutionMode, ExecuteResult, DaemonStatus, UpdateOptions };
1
+ import { spawn } from 'child_process';
2
+ import { CronStoreError } from './types';
3
+ import type { Schedule, ExecutionMode, ExecuteResult, ExecuteScheduleOptions, ExecuteScheduleOutcome, DaemonStatus, UpdateOptions, StartDaemonResult, CronStoreErrorCode, ScheduleStore, ScheduleStoreLock, ScheduleStoreUpdate, ClaimOccurrenceOptions, ClaimOccurrenceResult, RecordFinishedOptions, RecordStartedOptions } from './types';
4
+ import { BUILTIN_SCHEDULES, getProjectRoot } from './builtins';
5
+ import type { BuiltinScheduleDef } from './builtins';
6
+ export type { Schedule, ExecutionMode, ExecuteResult, ExecuteScheduleOptions, ExecuteScheduleOutcome, DaemonStatus, UpdateOptions, StartDaemonResult, CronStoreErrorCode, ScheduleStore, ScheduleStoreLock, ScheduleStoreUpdate, ClaimOccurrenceOptions, ClaimOccurrenceResult, RecordFinishedOptions, RecordStartedOptions, };
7
+ export { CronStoreError };
8
+ export type { BuiltinScheduleDef };
9
+ export { BUILTIN_SCHEDULES, getProjectRoot };
3
10
  export declare function getLocalTimestamp(): string;
4
- export declare function logUsage(...args: string[]): void;
5
- export declare function getProjectRoot(): string;
11
+ export declare function logUsage(dirOrMessage?: string, ...args: string[]): void;
12
+ export declare function acquireWorkspaceLock(workspacePath: string, timeout?: number): ScheduleStoreLock;
13
+ export declare function releaseWorkspaceLock(owner: ScheduleStoreLock): boolean;
14
+ export declare function migrateLegacyMemoryDebounceSchedule(workspacePath?: string): void;
6
15
  export declare function normalizeMode(mode: string): ExecutionMode;
16
+ export declare function createScheduleStore(workspacePath?: string): ScheduleStore;
7
17
  export declare function loadSchedules(dir?: string): Schedule[];
8
18
  export declare function saveSchedules(schedules: Schedule[], dir?: string): void;
9
- export declare function acquireLock(timeout?: number): Promise<boolean>;
10
- export declare function releaseLock(): void;
19
+ export declare function getRemovedBuiltins(dir?: string): string[];
20
+ export declare function seedBuiltinSchedules(dir?: string): string[];
21
+ export declare function acquireLock(timeout?: number, dir?: string): Promise<boolean>;
22
+ export declare function releaseLock(dir?: string): void;
23
+ export declare function releaseRunLock(scheduleId: string, leaseId: string, dir?: string): boolean;
11
24
  export declare function shouldRunNow(cronExpr: string, now: Date, timezone?: string | null): boolean;
12
25
  export declare function describeCron(cronExpr: string): string;
13
26
  export declare function calculateNextRun(cronExpr: string, timezone?: string | null): string | null;
14
- export declare function isDaemonRunning(dir?: string): boolean;
15
- export declare function startDaemon(dir?: string): number;
16
- export declare function stopDaemon(dir?: string): boolean;
17
- export declare function ensureDaemonRunning(dir?: string): void;
27
+ type DaemonProcessProbe = {
28
+ isAlive: (pid: number) => boolean | 'unknown';
29
+ getCommandLine: (pid: number) => string | null;
30
+ spawnImpl?: typeof spawn;
31
+ };
32
+ export declare function isDaemonRunning(dir?: string, probe?: DaemonProcessProbe): boolean;
33
+ export declare function startDaemon(dir?: string, probe?: DaemonProcessProbe): number;
34
+ export declare function stopDaemon(dir?: string, probe?: DaemonProcessProbe): boolean;
35
+ export declare function startDaemonSafe(dir?: string, probe?: DaemonProcessProbe): StartDaemonResult;
36
+ export declare function ensureDaemonRunning(dir?: string, probe?: DaemonProcessProbe): void;
18
37
  export declare function getDaemonStatus(dir?: string): DaemonStatus;
19
- export declare function executeSchedule(schedule: Schedule, dir?: string): Promise<ExecuteResult>;
38
+ export declare function executeSchedule(schedule: Schedule, options?: ExecuteScheduleOptions): Promise<ExecuteScheduleOutcome>;
39
+ export declare function getLocalMinuteKey(now: Date, timezone?: string | null): string;
40
+ export declare function buildOccurrenceKey(cronExpression: string, scheduledMinute: string): string;
20
41
  export declare function daemonTick(dir?: string): Promise<void>;
42
+ export { createCronRuntime, CRON_RUNTIME_PROCESS_LEASE_FILENAME, } from './runtime';
43
+ export type { CronRuntimeAdmissionContext, CronRuntimeBeforeExecutorAdmission, CronRuntime, CronRuntimeExecutor, CronRuntimeFenceResult, CronRuntimeFenceToken, CronRuntimeOptions, CronRuntimeProcessLeaseProvider, CronRuntimeScheduleResult, CronRuntimeScheduleResultStatus, CronRuntimeRole, CronRuntimeShouldRunNow, CronRuntimeSnapshot, CronRuntimeStatus, CronRuntimeStopResult, CronRuntimeTickResult, CronRuntimeTickSkipReason, CronRuntimeTestHooks, CronRuntimeWorkspace, CronRuntimeWorkspaceState, CronRuntimeWorkspaceStatus, CronRuntimeWorkspaceTickResult, CronRuntimeStoreFactory, } from './runtime';
21
44
  export declare function runDaemonForeground(dir?: string): void;
22
45
  export declare function addSchedule(cron: string, command: string, options: {
23
46
  name?: string;
@@ -26,6 +49,8 @@ export declare function addSchedule(cron: string, command: string, options: {
26
49
  dir?: string;
27
50
  timeout?: string;
28
51
  allowConcurrent?: boolean;
52
+ model?: string;
53
+ provider?: string;
29
54
  }, dataDir?: string): Schedule;
30
55
  export declare function removeSchedule(id: string, dir?: string): Schedule;
31
56
  export declare function enableSchedule(id: string, dir?: string): Schedule;
@@ -38,7 +63,9 @@ export declare const DATA_PATHS: {
38
63
  DATA_DIR: string;
39
64
  SCHEDULES_FILE: string;
40
65
  LOG_FILE: string;
66
+ LOCK_FILE: string;
41
67
  USAGE_LOG_FILE: string;
42
68
  PID_FILE: string;
69
+ BUILTINS_META_FILE: string;
43
70
  };
44
- //# sourceMappingURL=engine.d.ts.map
71
+