@moxxy/cli 0.46.0 → 0.47.1
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/bin.js +271 -101
- package/dist/skills/scheduling.md +3 -1
- package/package.json +2 -2
package/dist/bin.js
CHANGED
|
@@ -16,7 +16,7 @@ import { readFile, rm, mkdtemp, writeFile, mkdir, open, readdir, unlink, link, r
|
|
|
16
16
|
import { setTimeout as setTimeout$1 } from 'timers/promises';
|
|
17
17
|
import { styleText, promisify, stripVTControlCharacters } from 'util';
|
|
18
18
|
import * as readline from 'readline/promises';
|
|
19
|
-
import { isValidCron,
|
|
19
|
+
import { isValidCron, isValidTimeZone, firstFireBetween, nextFireTime } from '@moxxy/sdk/cron';
|
|
20
20
|
import { createServer } from 'http';
|
|
21
21
|
import net2, { connect } from 'net';
|
|
22
22
|
import { Worker } from 'worker_threads';
|
|
@@ -25640,7 +25640,16 @@ var init_skill_sync = __esm({
|
|
|
25640
25640
|
});
|
|
25641
25641
|
function cronBaseline(entry) {
|
|
25642
25642
|
const baseline = entry.lastRunAt ?? entry.createdAt;
|
|
25643
|
-
|
|
25643
|
+
const windowOpen = entry.startAt !== void 0 ? Math.ceil(entry.startAt / 6e4) * 6e4 - 6e4 : baseline;
|
|
25644
|
+
return Math.max(baseline, entry.timingChangedAt ?? baseline, entry.lastStartedAt ?? baseline, entry.lastSkippedAt ?? baseline, windowOpen);
|
|
25645
|
+
}
|
|
25646
|
+
function isWindowOver(entry, now) {
|
|
25647
|
+
if (entry.endAt === void 0)
|
|
25648
|
+
return false;
|
|
25649
|
+
if (now > entry.endAt + WINDOW_END_GRACE_MS)
|
|
25650
|
+
return true;
|
|
25651
|
+
const next = nextCronFire(entry);
|
|
25652
|
+
return next !== null && next.getTime() > entry.endAt;
|
|
25644
25653
|
}
|
|
25645
25654
|
function nextCronFire(entry) {
|
|
25646
25655
|
if (!entry.cron)
|
|
@@ -25666,16 +25675,19 @@ function isDue(entry, now) {
|
|
|
25666
25675
|
}
|
|
25667
25676
|
if (!entry.cron)
|
|
25668
25677
|
return false;
|
|
25678
|
+
if (isWindowOver(entry, now))
|
|
25679
|
+
return false;
|
|
25669
25680
|
const next = nextCronFire(entry);
|
|
25670
25681
|
if (!next)
|
|
25671
25682
|
return false;
|
|
25672
25683
|
return next.getTime() <= now;
|
|
25673
25684
|
}
|
|
25674
|
-
var nextFireCache, NEXT_FIRE_CACHE_MAX, SchedulerPoller;
|
|
25685
|
+
var WINDOW_END_GRACE_MS, nextFireCache, NEXT_FIRE_CACHE_MAX, SchedulerPoller;
|
|
25675
25686
|
var init_poller = __esm({
|
|
25676
25687
|
"../plugin-scheduler/dist/poller.js"() {
|
|
25677
25688
|
init_runner();
|
|
25678
25689
|
init_skill_sync();
|
|
25690
|
+
WINDOW_END_GRACE_MS = 5 * 6e4;
|
|
25679
25691
|
nextFireCache = /* @__PURE__ */ new Map();
|
|
25680
25692
|
NEXT_FIRE_CACHE_MAX = 4096;
|
|
25681
25693
|
SchedulerPoller = class _SchedulerPoller {
|
|
@@ -25767,6 +25779,10 @@ var init_poller = __esm({
|
|
|
25767
25779
|
for (const entry of schedules) {
|
|
25768
25780
|
let due;
|
|
25769
25781
|
try {
|
|
25782
|
+
if (entry.enabled && isWindowOver(entry, now)) {
|
|
25783
|
+
await this.opts.store.update(entry.id, { enabled: false });
|
|
25784
|
+
continue;
|
|
25785
|
+
}
|
|
25770
25786
|
due = isDue(entry, now);
|
|
25771
25787
|
} catch (err) {
|
|
25772
25788
|
const log2 = this.opts.logger;
|
|
@@ -25889,10 +25905,68 @@ function repairWorkflowDate(entry, now) {
|
|
|
25889
25905
|
migratedAt: now
|
|
25890
25906
|
});
|
|
25891
25907
|
}
|
|
25908
|
+
function reconcileSkillRows(schedules, wanted) {
|
|
25909
|
+
let added = 0;
|
|
25910
|
+
let removed = 0;
|
|
25911
|
+
let updated = 0;
|
|
25912
|
+
const next = [];
|
|
25913
|
+
const keptSkillNames = /* @__PURE__ */ new Set();
|
|
25914
|
+
for (const s of schedules) {
|
|
25915
|
+
if (s.source === "skill" && s.skillName) {
|
|
25916
|
+
if (!wanted.has(s.skillName) || keptSkillNames.has(s.skillName)) {
|
|
25917
|
+
if (isVisibleSchedule(s))
|
|
25918
|
+
removed += 1;
|
|
25919
|
+
continue;
|
|
25920
|
+
}
|
|
25921
|
+
keptSkillNames.add(s.skillName);
|
|
25922
|
+
}
|
|
25923
|
+
next.push(s);
|
|
25924
|
+
}
|
|
25925
|
+
const posInNext = /* @__PURE__ */ new Map();
|
|
25926
|
+
for (let i2 = 0; i2 < next.length; i2 += 1) {
|
|
25927
|
+
const s = next[i2];
|
|
25928
|
+
assertDefined(s, "loop index i is within next.length");
|
|
25929
|
+
if (s.source === "skill" && s.skillName && !posInNext.has(s.skillName)) {
|
|
25930
|
+
posInNext.set(s.skillName, i2);
|
|
25931
|
+
}
|
|
25932
|
+
}
|
|
25933
|
+
for (const [skillName, draft] of wanted) {
|
|
25934
|
+
const idx = posInNext.get(skillName);
|
|
25935
|
+
if (idx === void 0) {
|
|
25936
|
+
next.push(scheduleEntrySchema.parse({
|
|
25937
|
+
...draft,
|
|
25938
|
+
id: ulid(),
|
|
25939
|
+
createdAt: Date.now(),
|
|
25940
|
+
enabled: draft.enabled ?? true,
|
|
25941
|
+
source: draft.source ?? "skill"
|
|
25942
|
+
}));
|
|
25943
|
+
added += 1;
|
|
25944
|
+
continue;
|
|
25945
|
+
}
|
|
25946
|
+
const current2 = next[idx];
|
|
25947
|
+
assertDefined(current2, "posInNext holds an in-bounds index into next");
|
|
25948
|
+
if (!isVisibleSchedule(current2))
|
|
25949
|
+
continue;
|
|
25950
|
+
const patch = {
|
|
25951
|
+
prompt: draft.prompt,
|
|
25952
|
+
...draft.cron ? { cron: draft.cron } : { cron: void 0 },
|
|
25953
|
+
...draft.runAt !== void 0 ? { runAt: draft.runAt } : { runAt: void 0 },
|
|
25954
|
+
...draft.timeZone ? { timeZone: draft.timeZone } : { timeZone: void 0 },
|
|
25955
|
+
...draft.channel ? { channel: draft.channel } : { channel: void 0 },
|
|
25956
|
+
enabled: draft.enabled ?? true
|
|
25957
|
+
};
|
|
25958
|
+
const changed = current2.prompt !== patch.prompt || current2.cron !== patch.cron || current2.runAt !== patch.runAt || current2.timeZone !== patch.timeZone || current2.channel !== patch.channel || current2.enabled !== patch.enabled;
|
|
25959
|
+
if (changed) {
|
|
25960
|
+
next[idx] = scheduleEntrySchema.parse({ ...current2, ...patch });
|
|
25961
|
+
updated += 1;
|
|
25962
|
+
}
|
|
25963
|
+
}
|
|
25964
|
+
return { next, added, removed, updated };
|
|
25965
|
+
}
|
|
25892
25966
|
function isVisibleSchedule(entry) {
|
|
25893
25967
|
return entry.deletedAt === void 0;
|
|
25894
25968
|
}
|
|
25895
|
-
var scheduleSourceSchema, scheduleEntrySchema, fileSchema, ScheduleStore;
|
|
25969
|
+
var scheduleSourceSchema, scheduleEntrySchema, fileSchema, ScheduleStore, sameRows, countsOf;
|
|
25896
25970
|
var init_store2 = __esm({
|
|
25897
25971
|
"../plugin-scheduler/dist/store.js"() {
|
|
25898
25972
|
init_node();
|
|
@@ -25904,6 +25978,11 @@ var init_store2 = __esm({
|
|
|
25904
25978
|
cron: z.string().optional(),
|
|
25905
25979
|
/** Epoch ms for one-shot schedules. Cleared once fired. */
|
|
25906
25980
|
runAt: z.number().int().optional(),
|
|
25981
|
+
/** Epoch ms: a cron schedule does not fire before this instant. */
|
|
25982
|
+
startAt: z.number().int().optional(),
|
|
25983
|
+
/** Epoch ms: a cron schedule fires at most up to this instant (inclusive),
|
|
25984
|
+
* then turns itself off. */
|
|
25985
|
+
endAt: z.number().int().optional(),
|
|
25907
25986
|
/** IANA timezone for cron interpretation. Default = system local. */
|
|
25908
25987
|
timeZone: z.string().optional(),
|
|
25909
25988
|
/** Soft hint for delivery target — e.g. "telegram", "inbox". The
|
|
@@ -25979,6 +26058,9 @@ var init_store2 = __esm({
|
|
|
25979
26058
|
this.store = createJsonFileStore({
|
|
25980
26059
|
file,
|
|
25981
26060
|
itemsKey: "schedules",
|
|
26061
|
+
// The desktop, `moxxy schedule` and every runner each hold their own
|
|
26062
|
+
// ScheduleStore on this file; each must see the others' changes.
|
|
26063
|
+
sharedWithOtherProcesses: true,
|
|
25982
26064
|
load: async (raw) => {
|
|
25983
26065
|
if (raw === null)
|
|
25984
26066
|
return [];
|
|
@@ -26025,7 +26107,7 @@ var init_store2 = __esm({
|
|
|
26025
26107
|
}
|
|
26026
26108
|
});
|
|
26027
26109
|
}
|
|
26028
|
-
/** Force a re-read on the next access
|
|
26110
|
+
/** Force a re-read on the next access (every access re-reads already; kept for callers). */
|
|
26029
26111
|
invalidate() {
|
|
26030
26112
|
this.store.invalidate();
|
|
26031
26113
|
}
|
|
@@ -26106,65 +26188,16 @@ var init_store2 = __esm({
|
|
|
26106
26188
|
* unchanged. Manual/workflow rows are never touched.
|
|
26107
26189
|
*/
|
|
26108
26190
|
async reconcileSkillSchedules(wanted) {
|
|
26109
|
-
|
|
26110
|
-
|
|
26111
|
-
|
|
26191
|
+
const current2 = await this.store.read();
|
|
26192
|
+
const preview = reconcileSkillRows(current2, wanted);
|
|
26193
|
+
if (sameRows(preview.next, current2))
|
|
26194
|
+
return countsOf(preview);
|
|
26195
|
+
let result = preview;
|
|
26112
26196
|
await this.store.mutate((schedules) => {
|
|
26113
|
-
|
|
26114
|
-
|
|
26115
|
-
for (const s of schedules) {
|
|
26116
|
-
if (s.source === "skill" && s.skillName) {
|
|
26117
|
-
if (!wanted.has(s.skillName) || keptSkillNames.has(s.skillName)) {
|
|
26118
|
-
if (isVisibleSchedule(s))
|
|
26119
|
-
removed += 1;
|
|
26120
|
-
continue;
|
|
26121
|
-
}
|
|
26122
|
-
keptSkillNames.add(s.skillName);
|
|
26123
|
-
}
|
|
26124
|
-
next.push(s);
|
|
26125
|
-
}
|
|
26126
|
-
const posInNext = /* @__PURE__ */ new Map();
|
|
26127
|
-
for (let i2 = 0; i2 < next.length; i2 += 1) {
|
|
26128
|
-
const s = next[i2];
|
|
26129
|
-
assertDefined(s, "loop index i is within next.length");
|
|
26130
|
-
if (s.source === "skill" && s.skillName && !posInNext.has(s.skillName)) {
|
|
26131
|
-
posInNext.set(s.skillName, i2);
|
|
26132
|
-
}
|
|
26133
|
-
}
|
|
26134
|
-
for (const [skillName, draft] of wanted) {
|
|
26135
|
-
const idx = posInNext.get(skillName);
|
|
26136
|
-
if (idx === void 0) {
|
|
26137
|
-
next.push(scheduleEntrySchema.parse({
|
|
26138
|
-
...draft,
|
|
26139
|
-
id: ulid(),
|
|
26140
|
-
createdAt: Date.now(),
|
|
26141
|
-
enabled: draft.enabled ?? true,
|
|
26142
|
-
source: draft.source ?? "skill"
|
|
26143
|
-
}));
|
|
26144
|
-
added += 1;
|
|
26145
|
-
continue;
|
|
26146
|
-
}
|
|
26147
|
-
const current2 = next[idx];
|
|
26148
|
-
assertDefined(current2, "posInNext holds an in-bounds index into next");
|
|
26149
|
-
if (!isVisibleSchedule(current2))
|
|
26150
|
-
continue;
|
|
26151
|
-
const patch = {
|
|
26152
|
-
prompt: draft.prompt,
|
|
26153
|
-
...draft.cron ? { cron: draft.cron } : { cron: void 0 },
|
|
26154
|
-
...draft.runAt !== void 0 ? { runAt: draft.runAt } : { runAt: void 0 },
|
|
26155
|
-
...draft.timeZone ? { timeZone: draft.timeZone } : { timeZone: void 0 },
|
|
26156
|
-
...draft.channel ? { channel: draft.channel } : { channel: void 0 },
|
|
26157
|
-
enabled: draft.enabled ?? true
|
|
26158
|
-
};
|
|
26159
|
-
const changed = current2.prompt !== patch.prompt || current2.cron !== patch.cron || current2.runAt !== patch.runAt || current2.timeZone !== patch.timeZone || current2.channel !== patch.channel || current2.enabled !== patch.enabled;
|
|
26160
|
-
if (changed) {
|
|
26161
|
-
next[idx] = scheduleEntrySchema.parse({ ...current2, ...patch });
|
|
26162
|
-
updated += 1;
|
|
26163
|
-
}
|
|
26164
|
-
}
|
|
26165
|
-
return next;
|
|
26197
|
+
result = reconcileSkillRows(schedules, wanted);
|
|
26198
|
+
return result.next;
|
|
26166
26199
|
});
|
|
26167
|
-
return
|
|
26200
|
+
return countsOf(result);
|
|
26168
26201
|
}
|
|
26169
26202
|
/**
|
|
26170
26203
|
* Replace every `source='skill'` schedule for the given `skillName`
|
|
@@ -26229,13 +26262,94 @@ var init_store2 = __esm({
|
|
|
26229
26262
|
await this.store.mutate((entries) => entries.map((entry) => repairWorkflowDate(entry, this.now())));
|
|
26230
26263
|
}
|
|
26231
26264
|
};
|
|
26265
|
+
sameRows = (a2, b3) => a2.length === b3.length && a2.every((row, i2) => row === b3[i2]);
|
|
26266
|
+
countsOf = ({ added, removed, updated }) => ({ added, removed, updated });
|
|
26267
|
+
}
|
|
26268
|
+
});
|
|
26269
|
+
function windowShapeProblem(draft, names = TOOL_FIELD_NAMES) {
|
|
26270
|
+
if (draft.startAt === void 0 && draft.endAt === void 0)
|
|
26271
|
+
return null;
|
|
26272
|
+
if (draft.cron === void 0)
|
|
26273
|
+
return `${names.startAt} and ${names.endAt} only work with ${names.cron}`;
|
|
26274
|
+
if (draft.startAt !== void 0 && draft.endAt !== void 0 && draft.endAt <= draft.startAt) {
|
|
26275
|
+
return `${names.endAt} must be later than ${names.startAt}`;
|
|
26276
|
+
}
|
|
26277
|
+
return null;
|
|
26278
|
+
}
|
|
26279
|
+
function windowEndedProblem(endAt, now) {
|
|
26280
|
+
if (endAt === void 0 || endAt > now)
|
|
26281
|
+
return null;
|
|
26282
|
+
return `this time window already ended at ${new Date(endAt).toISOString()}`;
|
|
26283
|
+
}
|
|
26284
|
+
function windowEmptyProblem(draft, now) {
|
|
26285
|
+
if (draft.cron === void 0 || draft.endAt === void 0)
|
|
26286
|
+
return null;
|
|
26287
|
+
const from = Math.max(draft.startAt ?? now, now);
|
|
26288
|
+
if (firstFireBetween(draft.cron, from, draft.endAt, draft.timeZone))
|
|
26289
|
+
return null;
|
|
26290
|
+
return `no run of this schedule falls inside its time window, which ends at ${new Date(draft.endAt).toISOString()}`;
|
|
26291
|
+
}
|
|
26292
|
+
var TOOL_FIELD_NAMES;
|
|
26293
|
+
var init_window = __esm({
|
|
26294
|
+
"../plugin-scheduler/dist/window.js"() {
|
|
26295
|
+
TOOL_FIELD_NAMES = {
|
|
26296
|
+
cron: "`cron`",
|
|
26297
|
+
startAt: "`startAt`",
|
|
26298
|
+
endAt: "`endAt`"
|
|
26299
|
+
};
|
|
26300
|
+
}
|
|
26301
|
+
});
|
|
26302
|
+
function scheduleShapeProblem(draft, names = TOOL_FIELD_NAMES2) {
|
|
26303
|
+
if (draft.name.length === 0)
|
|
26304
|
+
return "name is required";
|
|
26305
|
+
if (draft.name.length > SCHEDULE_NAME_MAX)
|
|
26306
|
+
return `name must be at most ${SCHEDULE_NAME_MAX} characters`;
|
|
26307
|
+
if (!SCHEDULE_NAME_PATTERN.test(draft.name))
|
|
26308
|
+
return "name must be slug-like (letters, digits, hyphens)";
|
|
26309
|
+
if (draft.prompt.trim() === "")
|
|
26310
|
+
return "prompt is required";
|
|
26311
|
+
if (draft.cron === void 0 && draft.runAt === void 0)
|
|
26312
|
+
return `provide either ${names.cron} or ${names.runAt}`;
|
|
26313
|
+
if (draft.cron !== void 0 && draft.runAt !== void 0) {
|
|
26314
|
+
return `provide either ${names.cron} or ${names.runAt}, not both`;
|
|
26315
|
+
}
|
|
26316
|
+
if (draft.cron !== void 0 && !isValidCron(draft.cron))
|
|
26317
|
+
return `invalid cron expression "${draft.cron}"`;
|
|
26318
|
+
if (draft.timeZone !== void 0 && !isValidTimeZone(draft.timeZone)) {
|
|
26319
|
+
return `invalid ${names.timeZone} "${draft.timeZone}" (must be an IANA zone or "local")`;
|
|
26320
|
+
}
|
|
26321
|
+
return windowShapeProblem(draft, names);
|
|
26322
|
+
}
|
|
26323
|
+
function scheduleTimingProblem(draft, now) {
|
|
26324
|
+
if (draft.runAt !== void 0 && draft.runAt < now - ONE_SHOT_GRACE_MS) {
|
|
26325
|
+
return `this moment already passed at ${new Date(draft.runAt).toISOString()}`;
|
|
26326
|
+
}
|
|
26327
|
+
return windowEndedProblem(draft.endAt, now) ?? windowEmptyProblem(draft, now);
|
|
26328
|
+
}
|
|
26329
|
+
function scheduleDraftProblem(draft, now, names = TOOL_FIELD_NAMES2) {
|
|
26330
|
+
return scheduleShapeProblem(draft, names) ?? scheduleTimingProblem(draft, now);
|
|
26331
|
+
}
|
|
26332
|
+
var TOOL_FIELD_NAMES2, SCHEDULE_NAME_PATTERN, SCHEDULE_NAME_MAX, ONE_SHOT_GRACE_MS;
|
|
26333
|
+
var init_draft = __esm({
|
|
26334
|
+
"../plugin-scheduler/dist/draft.js"() {
|
|
26335
|
+
init_window();
|
|
26336
|
+
TOOL_FIELD_NAMES2 = {
|
|
26337
|
+
cron: "`cron`",
|
|
26338
|
+
runAt: "`runAt`",
|
|
26339
|
+
startAt: "`startAt`",
|
|
26340
|
+
endAt: "`endAt`",
|
|
26341
|
+
timeZone: "timeZone"
|
|
26342
|
+
};
|
|
26343
|
+
SCHEDULE_NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/i;
|
|
26344
|
+
SCHEDULE_NAME_MAX = 120;
|
|
26345
|
+
ONE_SHOT_GRACE_MS = 6e4;
|
|
26232
26346
|
}
|
|
26233
26347
|
});
|
|
26234
26348
|
function describeScheduleEntry(entry) {
|
|
26235
26349
|
let nextFireAt = null;
|
|
26236
26350
|
if (entry.cron) {
|
|
26237
26351
|
const next = nextCronFire(entry);
|
|
26238
|
-
nextFireAt = next ? next.getTime() : null;
|
|
26352
|
+
nextFireAt = next && (entry.endAt === void 0 || next.getTime() <= entry.endAt) ? next.getTime() : null;
|
|
26239
26353
|
} else if (entry.runAt && entry.enabled) {
|
|
26240
26354
|
nextFireAt = entry.runAt;
|
|
26241
26355
|
}
|
|
@@ -26245,6 +26359,8 @@ function describeScheduleEntry(entry) {
|
|
|
26245
26359
|
enabled: entry.enabled,
|
|
26246
26360
|
cron: entry.cron ?? null,
|
|
26247
26361
|
runAt: entry.runAt ?? null,
|
|
26362
|
+
startAt: entry.startAt ?? null,
|
|
26363
|
+
endAt: entry.endAt ?? null,
|
|
26248
26364
|
timeZone: entry.timeZone ?? null,
|
|
26249
26365
|
channel: entry.channel ?? null,
|
|
26250
26366
|
model: entry.model ?? null,
|
|
@@ -26270,7 +26386,7 @@ function buildSchedulerTools(deps) {
|
|
|
26270
26386
|
return [
|
|
26271
26387
|
defineTool({
|
|
26272
26388
|
name: "schedule_create",
|
|
26273
|
-
description:
|
|
26389
|
+
description: 'Create a scheduled prompt with exactly one trigger. For a recurring schedule, set `cron` and omit `runAt` entirely. For a one-shot schedule, set `runAt` and omit `cron` entirely. Never send an empty placeholder for the unused trigger. To limit a recurring schedule to a time window ("every 30 min from 23:00 to 07:00"), set `cron` plus `startAt` and/or `endAt`; it stops by itself after `endAt`. The prompt runs in an isolated session at fire time; the final assistant message is appended to the user\'s inbox. Cron uses 5-field POSIX syntax in the user\'s local timezone (override via `timeZone`). For Telegram or other delivery, write the prompt to call the right send tool itself (e.g. "...then call telegram_send_message with the summary").',
|
|
26274
26390
|
inputSchema: scheduleCreateInputSchema,
|
|
26275
26391
|
permission: { action: "prompt" },
|
|
26276
26392
|
isolation: {
|
|
@@ -26281,19 +26397,27 @@ function buildSchedulerTools(deps) {
|
|
|
26281
26397
|
}
|
|
26282
26398
|
},
|
|
26283
26399
|
handler: async (input) => {
|
|
26284
|
-
const runAt =
|
|
26285
|
-
|
|
26286
|
-
|
|
26287
|
-
|
|
26288
|
-
if (input.timeZone !== void 0 && !isValidTimeZone(input.timeZone)) {
|
|
26289
|
-
throw new Error(`invalid timeZone "${input.timeZone}" (must be an IANA zone or "local")`);
|
|
26290
|
-
}
|
|
26291
|
-
const created = await store.create({
|
|
26400
|
+
const runAt = toEpochMs(input.runAt);
|
|
26401
|
+
const startAt = toEpochMs(input.startAt);
|
|
26402
|
+
const endAt = toEpochMs(input.endAt);
|
|
26403
|
+
const draft = {
|
|
26292
26404
|
name: input.name,
|
|
26293
26405
|
prompt: input.prompt,
|
|
26294
26406
|
...input.cron ? { cron: input.cron } : {},
|
|
26295
26407
|
...runAt !== void 0 ? { runAt } : {},
|
|
26296
|
-
...
|
|
26408
|
+
...startAt !== void 0 ? { startAt } : {},
|
|
26409
|
+
...endAt !== void 0 ? { endAt } : {},
|
|
26410
|
+
...input.timeZone ? { timeZone: input.timeZone } : {}
|
|
26411
|
+
};
|
|
26412
|
+
const shape2 = scheduleShapeProblem(draft);
|
|
26413
|
+
if (shape2)
|
|
26414
|
+
throw new Error(shape2);
|
|
26415
|
+
const timing = scheduleTimingProblem(draft, Date.now());
|
|
26416
|
+
if (timing) {
|
|
26417
|
+
throw new Error(`${timing}; ask the user for a new time instead of creating a schedule that never runs`);
|
|
26418
|
+
}
|
|
26419
|
+
const created = await store.create({
|
|
26420
|
+
...draft,
|
|
26297
26421
|
...input.channel ? { channel: input.channel } : {},
|
|
26298
26422
|
...input.model ? { model: input.model } : {},
|
|
26299
26423
|
// Bind to a target session (where the run fires + displays). An explicit
|
|
@@ -26441,33 +26565,46 @@ function buildSchedulerTools(deps) {
|
|
|
26441
26565
|
})
|
|
26442
26566
|
];
|
|
26443
26567
|
}
|
|
26444
|
-
var SCHEDULES_STORE_GLOB, blankStringToUndefined, optionalText,
|
|
26568
|
+
var SCHEDULES_STORE_GLOB, blankStringToUndefined, optionalText, optionalTimestamp, toEpochMs, scheduleCreateInputSchema;
|
|
26445
26569
|
var init_tools3 = __esm({
|
|
26446
26570
|
"../plugin-scheduler/dist/tools.js"() {
|
|
26571
|
+
init_draft();
|
|
26447
26572
|
init_poller();
|
|
26448
26573
|
init_runner();
|
|
26574
|
+
init_window();
|
|
26449
26575
|
SCHEDULES_STORE_GLOB = "~/.moxxy/schedules.json*";
|
|
26450
26576
|
blankStringToUndefined = (value2) => typeof value2 === "string" && value2.trim() === "" ? void 0 : value2;
|
|
26451
26577
|
optionalText = z$1.preprocess(blankStringToUndefined, z$1.string().min(1).optional());
|
|
26452
|
-
|
|
26578
|
+
optionalTimestamp = (field, description) => z$1.preprocess(blankStringToUndefined, z$1.union([
|
|
26453
26579
|
z$1.number().int(),
|
|
26454
26580
|
z$1.string().refine((value2) => !Number.isNaN(Date.parse(value2)), {
|
|
26455
|
-
message:
|
|
26581
|
+
message: `${field} must be an ISO timestamp or epoch-ms`
|
|
26456
26582
|
})
|
|
26457
|
-
]).optional());
|
|
26583
|
+
]).optional()).describe(description);
|
|
26584
|
+
toEpochMs = (value2) => typeof value2 === "string" ? Date.parse(value2) : value2;
|
|
26458
26585
|
scheduleCreateInputSchema = z$1.object({
|
|
26459
|
-
name: z$1.string().min(1).max(
|
|
26586
|
+
name: z$1.string().min(1).max(SCHEDULE_NAME_MAX).regex(SCHEDULE_NAME_PATTERN, "name must be slug-like (letters, digits, hyphens)"),
|
|
26460
26587
|
prompt: z$1.string().min(1),
|
|
26461
26588
|
channel: optionalText,
|
|
26462
26589
|
model: optionalText,
|
|
26463
26590
|
targetSessionId: optionalText.describe("Session id to fire this schedule in (where its run executes + displays). Defaults to the session that created the schedule."),
|
|
26464
|
-
cron: optionalText,
|
|
26465
|
-
runAt:
|
|
26591
|
+
cron: optionalText.describe('Recurring trigger: 5-field POSIX cron, e.g. "*/30 * * * *". Omit when using runAt.'),
|
|
26592
|
+
runAt: optionalTimestamp("runAt", "One-shot trigger: the single moment to run (ISO timestamp or epoch-ms). Omit when using cron."),
|
|
26593
|
+
startAt: optionalTimestamp("startAt", "Only with cron: the recurring schedule does not run before this moment (ISO timestamp or epoch-ms)."),
|
|
26594
|
+
endAt: optionalTimestamp("endAt", "Only with cron: the last moment the recurring schedule may run (inclusive); after it the schedule turns itself off (ISO timestamp or epoch-ms)."),
|
|
26466
26595
|
timeZone: optionalText
|
|
26467
26596
|
}).refine((value2) => value2.cron !== void 0 || value2.runAt !== void 0, {
|
|
26468
26597
|
message: "provide either `cron` or `runAt`"
|
|
26469
26598
|
}).refine((value2) => !(value2.cron !== void 0 && value2.runAt !== void 0), {
|
|
26470
|
-
message: "provide either `cron` or `runAt`, not both"
|
|
26599
|
+
message: "provide either `cron` or `runAt`, not both. For a recurring schedule limited to a time window, send `cron` with `startAt` and/or `endAt` and omit `runAt`."
|
|
26600
|
+
}).superRefine((value2, ctx) => {
|
|
26601
|
+
const problem = windowShapeProblem({
|
|
26602
|
+
cron: value2.cron,
|
|
26603
|
+
startAt: toEpochMs(value2.startAt),
|
|
26604
|
+
endAt: toEpochMs(value2.endAt)
|
|
26605
|
+
});
|
|
26606
|
+
if (problem)
|
|
26607
|
+
ctx.addIssue({ code: z$1.ZodIssueCode.custom, message: problem, path: ["endAt"] });
|
|
26471
26608
|
});
|
|
26472
26609
|
}
|
|
26473
26610
|
});
|
|
@@ -26550,6 +26687,8 @@ var init_dist7 = __esm({
|
|
|
26550
26687
|
init_skill_sync();
|
|
26551
26688
|
init_store2();
|
|
26552
26689
|
init_tools3();
|
|
26690
|
+
init_window();
|
|
26691
|
+
init_draft();
|
|
26553
26692
|
}
|
|
26554
26693
|
});
|
|
26555
26694
|
function isLoopbackHost(host) {
|
|
@@ -85899,7 +86038,7 @@ function extractYamlBlock(s) {
|
|
|
85899
86038
|
return (fence ? fence[1] : s).trim();
|
|
85900
86039
|
}
|
|
85901
86040
|
var DEFAULT_MAX_TOKENS, MAX_DRAFT_BYTES;
|
|
85902
|
-
var
|
|
86041
|
+
var init_draft2 = __esm({
|
|
85903
86042
|
"../plugin-workflows/dist/draft.js"() {
|
|
85904
86043
|
init_schema2();
|
|
85905
86044
|
DEFAULT_MAX_TOKENS = 4096;
|
|
@@ -86211,7 +86350,7 @@ function validateTool(deps) {
|
|
|
86211
86350
|
var WORKFLOWS_PLUGIN_NAME, PLUGIN_ID2, WORKFLOW_DIR_GLOBS;
|
|
86212
86351
|
var init_tools6 = __esm({
|
|
86213
86352
|
"../plugin-workflows/dist/tools.js"() {
|
|
86214
|
-
|
|
86353
|
+
init_draft2();
|
|
86215
86354
|
init_engine2();
|
|
86216
86355
|
init_schema2();
|
|
86217
86356
|
init_format2();
|
|
@@ -86544,7 +86683,7 @@ var init_dist28 = __esm({
|
|
|
86544
86683
|
init_dag();
|
|
86545
86684
|
init_engine2();
|
|
86546
86685
|
init_run_store();
|
|
86547
|
-
|
|
86686
|
+
init_draft2();
|
|
86548
86687
|
init_tools6();
|
|
86549
86688
|
init_command();
|
|
86550
86689
|
init_plugin2();
|
|
@@ -98260,7 +98399,8 @@ var init_agent_cli2 = __esm({
|
|
|
98260
98399
|
posix: "curl -fsSL https://chatgpt.com/codex/install.sh | sh",
|
|
98261
98400
|
windows: "irm https://chatgpt.com/codex/install.ps1 | iex"
|
|
98262
98401
|
},
|
|
98263
|
-
|
|
98402
|
+
// install.ps1 puts it in %LOCALAPPDATA%\Programs\OpenAI\Codex\bin.
|
|
98403
|
+
installDirs: [".local/bin", "AppData/Local/Programs/OpenAI/Codex/bin"],
|
|
98264
98404
|
// The installer otherwise offers to start Codex and to remove other installs.
|
|
98265
98405
|
installEnv: { CODEX_NON_INTERACTIVE: "1" },
|
|
98266
98406
|
windowsShim: { entry: "node_modules/@openai/codex/bin/codex.js", runs: "node", native: codexWindowsPrograms }
|
|
@@ -100658,7 +100798,9 @@ var init_help = __esm({
|
|
|
100658
100798
|
rows: [
|
|
100659
100799
|
["--channel <name>", "soft hint, e.g. 'telegram' (prompt calls the matching send tool)"],
|
|
100660
100800
|
["--model <id>", "override the active model just for this schedule"],
|
|
100661
|
-
["--timezone <zone>", "IANA zone for cron interpretation (default: system local)"]
|
|
100801
|
+
["--timezone <zone>", "IANA zone for cron interpretation (default: system local)"],
|
|
100802
|
+
["--from <iso>", "with --cron: do not run before this moment"],
|
|
100803
|
+
["--until <iso>", "with --cron: last moment to run, then the schedule turns itself off"]
|
|
100662
100804
|
]
|
|
100663
100805
|
}
|
|
100664
100806
|
],
|
|
@@ -100895,13 +101037,18 @@ var init_setup_cmd = __esm({
|
|
|
100895
101037
|
// src/commands/schedule/format.ts
|
|
100896
101038
|
function fmtNext(entry) {
|
|
100897
101039
|
if (entry.cron) {
|
|
100898
|
-
const
|
|
100899
|
-
|
|
100900
|
-
return
|
|
101040
|
+
const { nextFireIso } = describeScheduleEntry(entry);
|
|
101041
|
+
if (typeof nextFireIso === "string") return nextFireIso;
|
|
101042
|
+
return entry.endAt !== void 0 ? "(window ended)" : "(never \u2014 invalid)";
|
|
100901
101043
|
}
|
|
100902
101044
|
if (entry.runAt && entry.enabled) return new Date(entry.runAt).toISOString();
|
|
100903
101045
|
return "(done)";
|
|
100904
101046
|
}
|
|
101047
|
+
function fmtWindow(entry) {
|
|
101048
|
+
const from = entry.startAt !== void 0 ? ` from ${new Date(entry.startAt).toISOString()}` : "";
|
|
101049
|
+
const until = entry.endAt !== void 0 ? ` until ${new Date(entry.endAt).toISOString()}` : "";
|
|
101050
|
+
return from + until;
|
|
101051
|
+
}
|
|
100905
101052
|
function flag(argv, key) {
|
|
100906
101053
|
const v = argv.flags[key];
|
|
100907
101054
|
return typeof v === "string" ? v : void 0;
|
|
@@ -100929,7 +101076,7 @@ async function listSchedules(store) {
|
|
|
100929
101076
|
for (const s of all) {
|
|
100930
101077
|
const status = s.enabled ? "on" : "off";
|
|
100931
101078
|
const src = s.source === "skill" ? `skill:${s.skillName}` : "manual";
|
|
100932
|
-
const trig = s.cron ? `cron "${s.cron}"` : `at ${new Date(s.runAt).toISOString()}`;
|
|
101079
|
+
const trig = s.cron ? `cron "${s.cron}"${fmtWindow(s)}` : `at ${new Date(s.runAt).toISOString()}`;
|
|
100933
101080
|
process.stdout.write(
|
|
100934
101081
|
`${colors.bold(s.name.padEnd(nameCol))} ${colors.dim(status)} ${colors.dim(trig)}
|
|
100935
101082
|
${" ".repeat(nameCol + 2)}${colors.dim(`id ${s.id} \xB7 ${src} \xB7 next ${fmtNext(s)}`)}
|
|
@@ -100946,14 +101093,10 @@ async function addSchedule(store, argv) {
|
|
|
100946
101093
|
const at = flag(argv, "at");
|
|
100947
101094
|
if (!name || !prompt || !cron && !at) {
|
|
100948
101095
|
process.stderr.write(
|
|
100949
|
-
colors.red("missing required args") + '\n usage: moxxy schedule add <name> --cron "<expr>" --prompt "<text>"\n moxxy schedule add <name> --at "<iso>" --prompt "<text>"\n'
|
|
101096
|
+
colors.red("missing required args") + '\n usage: moxxy schedule add <name> --cron "<expr>" --prompt "<text>"\n moxxy schedule add <name> --cron "<expr>" --from "<iso>" --until "<iso>" --prompt "<text>"\n moxxy schedule add <name> --at "<iso>" --prompt "<text>"\n'
|
|
100950
101097
|
);
|
|
100951
101098
|
return 2;
|
|
100952
101099
|
}
|
|
100953
|
-
if (cron && !isValidCron(cron)) {
|
|
100954
|
-
process.stderr.write(colors.red(`invalid cron expression: "${cron}"`) + "\n");
|
|
100955
|
-
return 2;
|
|
100956
|
-
}
|
|
100957
101100
|
const runAt = at ? parseIsoAt(at) : void 0;
|
|
100958
101101
|
if (at && runAt === void 0) {
|
|
100959
101102
|
process.stderr.write(
|
|
@@ -100961,17 +101104,27 @@ async function addSchedule(store, argv) {
|
|
|
100961
101104
|
);
|
|
100962
101105
|
return 2;
|
|
100963
101106
|
}
|
|
100964
|
-
|
|
100965
|
-
|
|
100966
|
-
|
|
100967
|
-
|
|
101107
|
+
const window2 = parseWindow(argv);
|
|
101108
|
+
if (typeof window2 === "string") {
|
|
101109
|
+
process.stderr.write(colors.red(window2) + "\n");
|
|
101110
|
+
return 2;
|
|
100968
101111
|
}
|
|
100969
|
-
const
|
|
101112
|
+
const draft = {
|
|
100970
101113
|
name,
|
|
100971
101114
|
prompt,
|
|
100972
101115
|
...cron ? { cron } : {},
|
|
100973
101116
|
...runAt !== void 0 ? { runAt } : {},
|
|
100974
|
-
...
|
|
101117
|
+
...window2.startAt !== void 0 ? { startAt: window2.startAt } : {},
|
|
101118
|
+
...window2.endAt !== void 0 ? { endAt: window2.endAt } : {},
|
|
101119
|
+
...flag(argv, "timezone") ? { timeZone: flag(argv, "timezone") } : {}
|
|
101120
|
+
};
|
|
101121
|
+
const problem = scheduleDraftProblem(draft, Date.now(), CLI_FLAG_NAMES);
|
|
101122
|
+
if (problem) {
|
|
101123
|
+
process.stderr.write(colors.red(problem) + "\n");
|
|
101124
|
+
return 2;
|
|
101125
|
+
}
|
|
101126
|
+
const created = await store.create({
|
|
101127
|
+
...draft,
|
|
100975
101128
|
...flag(argv, "channel") ? { channel: flag(argv, "channel") } : {},
|
|
100976
101129
|
...flag(argv, "model") ? { model: flag(argv, "model") } : {}
|
|
100977
101130
|
});
|
|
@@ -100982,6 +101135,15 @@ async function addSchedule(store, argv) {
|
|
|
100982
101135
|
);
|
|
100983
101136
|
return 0;
|
|
100984
101137
|
}
|
|
101138
|
+
function parseWindow(argv) {
|
|
101139
|
+
const from = flag(argv, "from");
|
|
101140
|
+
const until = flag(argv, "until");
|
|
101141
|
+
const startAt = from !== void 0 ? parseIsoAt(from) : void 0;
|
|
101142
|
+
if (from !== void 0 && startAt === void 0) return `invalid --from timestamp: "${from}"`;
|
|
101143
|
+
const endAt = until !== void 0 ? parseIsoAt(until) : void 0;
|
|
101144
|
+
if (until !== void 0 && endAt === void 0) return `invalid --until timestamp: "${until}"`;
|
|
101145
|
+
return { ...startAt !== void 0 ? { startAt } : {}, ...endAt !== void 0 ? { endAt } : {} };
|
|
101146
|
+
}
|
|
100985
101147
|
async function removeSchedule(store, argv) {
|
|
100986
101148
|
const id = argv.positional[1];
|
|
100987
101149
|
if (!id) {
|
|
@@ -101052,6 +101214,7 @@ async function runScheduleNow(argv) {
|
|
|
101052
101214
|
await closeSession(session, persistence);
|
|
101053
101215
|
}
|
|
101054
101216
|
}
|
|
101217
|
+
var CLI_FLAG_NAMES;
|
|
101055
101218
|
var init_handlers2 = __esm({
|
|
101056
101219
|
async "src/commands/schedule/handlers.ts"() {
|
|
101057
101220
|
init_dist7();
|
|
@@ -101059,6 +101222,13 @@ var init_handlers2 = __esm({
|
|
|
101059
101222
|
await init_setup();
|
|
101060
101223
|
init_close_session();
|
|
101061
101224
|
init_format3();
|
|
101225
|
+
CLI_FLAG_NAMES = {
|
|
101226
|
+
cron: "--cron",
|
|
101227
|
+
runAt: "--at",
|
|
101228
|
+
startAt: "--from",
|
|
101229
|
+
endAt: "--until",
|
|
101230
|
+
timeZone: "--timezone"
|
|
101231
|
+
};
|
|
101062
101232
|
}
|
|
101063
101233
|
});
|
|
101064
101234
|
|
|
@@ -34,6 +34,8 @@ Use this skill when the user wants a prompt to fire automatically — recurring
|
|
|
34
34
|
- "Every 15 minutes" → cron `*/15 * * * *`
|
|
35
35
|
- "In one hour" → `runAt: <epoch-ms now + 3_600_000>` (or ISO timestamp)
|
|
36
36
|
- "Tomorrow at 10" → `runAt: <ISO timestamp>` in the user's local zone
|
|
37
|
+
- "Every 30 minutes from 23:00 tonight until 07:00, then stop" → cron `*/30 * * * *` + `startAt: <ISO 23:00>` + `endAt: <ISO 07:00>`. Never put the start time in `runAt` next to `cron` — the call is rejected. The schedule turns itself off after `endAt`. If the window the user names is already over, say so and ask for new dates.
|
|
38
|
+
- A `runAt` more than a minute in the past is rejected too: say the time has passed and ask for a new one instead of guessing. So is a window no run of the cron falls inside: propose a longer window or a shorter step.
|
|
37
39
|
|
|
38
40
|
2. **Pick the schedule name** — slug-like (`morning-briefing`, `weekly-standup`). The user-facing name; appears in the inbox filename.
|
|
39
41
|
|
|
@@ -43,7 +45,7 @@ Use this skill when the user wants a prompt to fire automatically — recurring
|
|
|
43
45
|
- "Remind me about <X>. Call `telegram_send_message` with a short reminder."
|
|
44
46
|
- "Check the CI status of <repo>; if a build failed, call `discord_send_message` with the failing job and a one-line cause."
|
|
45
47
|
|
|
46
|
-
4. **Call `schedule_create`** with `{ name, prompt, cron | runAt, channel?, model? }`. The tool returns `nextFireIso` so you can confirm the schedule will fire when expected.
|
|
48
|
+
4. **Call `schedule_create`** with `{ name, prompt, cron | runAt, startAt?, endAt?, channel?, model? }`. The tool returns `nextFireIso` so you can confirm the schedule will fire when expected.
|
|
47
49
|
|
|
48
50
|
5. **Confirm to the user** — name, next fire time, where output goes. Offer to fire it once with `schedule_run_now` for a smoke test.
|
|
49
51
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moxxy/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"description": "moxxy command-line agent: TUI, one-shot prompts, setup, services, and API-key or installed-CLI subscription providers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"moxxy",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"undici": "^8.12.2",
|
|
51
51
|
"zod": "^4.6.6",
|
|
52
|
-
"@moxxy/sdk": "0.
|
|
52
|
+
"@moxxy/sdk": "0.47.1"
|
|
53
53
|
},
|
|
54
54
|
"optionalDependencies": {
|
|
55
55
|
"@napi-rs/keyring": "^2.1.0"
|