opencode-windows-scheduler 1.4.0 → 1.5.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/CHANGELOG.md +24 -0
- package/README.md +2 -2
- package/ROADMAP-STRATEGY.md +43 -24
- package/ROADMAP.md +280 -31
- package/dist/core/dry-run.d.ts +31 -0
- package/dist/core/dry-run.d.ts.map +1 -1
- package/dist/core/dry-run.js +129 -1
- package/dist/core/file-watcher.d.ts.map +1 -1
- package/dist/core/file-watcher.js +53 -10
- package/dist/core/git-trigger.d.ts +80 -0
- package/dist/core/git-trigger.d.ts.map +1 -0
- package/dist/core/git-trigger.js +288 -0
- package/dist/core/glob.d.ts +38 -0
- package/dist/core/glob.d.ts.map +1 -0
- package/dist/core/glob.js +233 -0
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +7 -0
- package/dist/core/schedule-gate.js +55 -30
- package/dist/core/schedule-v2.d.ts +29 -1
- package/dist/core/schedule-v2.d.ts.map +1 -1
- package/dist/core/schedule-v2.js +81 -3
- package/dist/core/scheduler/types.d.ts +1 -1
- package/dist/core/scheduler/types.d.ts.map +1 -1
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +4 -0
- package/dist/db/git-state-repo.d.ts +16 -0
- package/dist/db/git-state-repo.d.ts.map +1 -0
- package/dist/db/git-state-repo.js +38 -0
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +8 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +247 -26
- package/dist/rpc.d.ts +223 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +73 -0
- package/dist/task-transfer.d.ts +30 -3
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +83 -6
- package/dist/templates.d.ts +1 -1
- package/dist/templates.d.ts.map +1 -1
- package/docs/ARCHITECTURE.md +1 -0
- package/docs/FEATURES.md +51 -0
- package/docs/README.ru.md +2 -2
- package/gui-experimental.cjs +9 -4
- package/package.json +6 -3
- package/src/core/dry-run.ts +188 -1
- package/src/core/file-watcher.ts +65 -10
- package/src/core/git-trigger.ts +367 -0
- package/src/core/glob.ts +226 -0
- package/src/core/ps-wrapper.ts +7 -0
- package/src/core/schedule-gate.ts +67 -33
- package/src/core/schedule-v2.ts +108 -3
- package/src/core/scheduler/types.ts +1 -1
- package/src/core/wrappers/bash.ts +4 -0
- package/src/db/git-state-repo.ts +62 -0
- package/src/db/schema.ts +8 -0
- package/src/gui.tsx +225 -4
- package/src/index.ts +338 -28
- package/src/rpc.ts +73 -0
- package/src/task-transfer.ts +124 -5
- package/src/templates.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import fs from "node:fs/promises";
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { LockManager } from "./core/lock.js";
|
|
9
9
|
import { LOCK_DIR, LOG_DIR, PLUGIN_DIR, sanitizeName } from "./types.js";
|
|
10
|
-
import { parseCron, buildScheduleGate, isValidIanaTimeZone, validateLaunchWindow, prevRun } from "./core/schedule-v2.js";
|
|
10
|
+
import { parseCron, buildScheduleGate, isValidIanaTimeZone, validateLaunchWindow, prevRun, normalizeActiveDays, activeWindowState, nextWindowOpenDelayMs } from "./core/schedule-v2.js";
|
|
11
11
|
import {
|
|
12
12
|
buildLaunchdOneShotCleanup,
|
|
13
13
|
normalizeOneShotRunAt,
|
|
@@ -65,6 +65,7 @@ import {
|
|
|
65
65
|
normalizePriority,
|
|
66
66
|
} from "./task-transfer.js";
|
|
67
67
|
import { FileWatchManager } from "./core/file-watcher.js";
|
|
68
|
+
import { GitTriggerManager } from "./core/git-trigger.js";
|
|
68
69
|
import type {
|
|
69
70
|
McpEventTrigger,
|
|
70
71
|
MatrixConfig,
|
|
@@ -320,10 +321,10 @@ export const scheduleTaskSchema = z.object({
|
|
|
320
321
|
.optional()
|
|
321
322
|
.describe("Compensation/rollback task started after a failed run."),
|
|
322
323
|
triggerType: z
|
|
323
|
-
.enum(["cron", "file", "mcp-event", "once"])
|
|
324
|
+
.enum(["cron", "file", "git", "mcp-event", "once"])
|
|
324
325
|
.optional()
|
|
325
326
|
.describe(
|
|
326
|
-
"Trigger type: cron (default), file, mcp-event or once (single run at runAt/delaySeconds)."
|
|
327
|
+
"Trigger type: cron (default), file, git (new commits in the task working directory), mcp-event or once (single run at runAt/delaySeconds)."
|
|
327
328
|
),
|
|
328
329
|
mcpEvent: z
|
|
329
330
|
.object({
|
|
@@ -341,6 +342,52 @@ export const scheduleTaskSchema = z.object({
|
|
|
341
342
|
.describe(
|
|
342
343
|
"File or directory to watch when triggerType is \"file\". Can be set here or later via update_task."
|
|
343
344
|
),
|
|
345
|
+
watchGlobs: z
|
|
346
|
+
.array(z.string())
|
|
347
|
+
.optional()
|
|
348
|
+
.describe(
|
|
349
|
+
"Glob masks that limit a file trigger, e.g. [\"**/*.md\", \"src/**\"]. Empty means any change under watchPath."
|
|
350
|
+
),
|
|
351
|
+
watchIgnore: z
|
|
352
|
+
.array(z.string())
|
|
353
|
+
.optional()
|
|
354
|
+
.describe(
|
|
355
|
+
"Glob masks excluded from a file trigger, e.g. [\"node_modules/**\", \"*.log\"]. Supports leading ! to re-include."
|
|
356
|
+
),
|
|
357
|
+
gitBranch: z
|
|
358
|
+
.string()
|
|
359
|
+
.optional()
|
|
360
|
+
.describe(
|
|
361
|
+
"Only for triggerType=git: branch name or glob (main, release/*, comma-separated). Empty means any branch."
|
|
362
|
+
),
|
|
363
|
+
gitPaths: z
|
|
364
|
+
.array(z.string())
|
|
365
|
+
.optional()
|
|
366
|
+
.describe(
|
|
367
|
+
"Only for triggerType=git: glob masks of changed files that must match to start the task (git diff --name-only)."
|
|
368
|
+
),
|
|
369
|
+
gitIgnore: z
|
|
370
|
+
.array(z.string())
|
|
371
|
+
.optional()
|
|
372
|
+
.describe("Only for triggerType=git: glob masks of changed files to ignore."),
|
|
373
|
+
gitPollSeconds: z
|
|
374
|
+
.number()
|
|
375
|
+
.int()
|
|
376
|
+
.min(5)
|
|
377
|
+
.optional()
|
|
378
|
+
.describe("Only for triggerType=git: polling interval in seconds (default 60, minimum 5)."),
|
|
379
|
+
activeDays: z
|
|
380
|
+
.array(z.number().int().min(0).max(6))
|
|
381
|
+
.optional()
|
|
382
|
+
.describe(
|
|
383
|
+
"Allowed weekdays 0=Sunday..6=Saturday for cron and event triggers. Empty or all seven means every day."
|
|
384
|
+
),
|
|
385
|
+
windowPolicy: z
|
|
386
|
+
.enum(["skip", "postpone", "run"])
|
|
387
|
+
.optional()
|
|
388
|
+
.describe(
|
|
389
|
+
"Behaviour outside the launch window / active days: postpone (default, wait for the next opening), skip or run anyway."
|
|
390
|
+
),
|
|
344
391
|
workingDirectory: z
|
|
345
392
|
.string()
|
|
346
393
|
.optional()
|
|
@@ -463,6 +510,42 @@ export const updateTaskSchema = z.object({
|
|
|
463
510
|
.string()
|
|
464
511
|
.optional()
|
|
465
512
|
.describe("New launch window end HH:MM. Empty string clears the window."),
|
|
513
|
+
activeDays: z
|
|
514
|
+
.array(z.number().int().min(0).max(6))
|
|
515
|
+
.optional()
|
|
516
|
+
.describe(
|
|
517
|
+
"New allowed weekdays 0=Sunday..6=Saturday. Empty array clears the restriction."
|
|
518
|
+
),
|
|
519
|
+
windowPolicy: z
|
|
520
|
+
.enum(["skip", "postpone", "run"])
|
|
521
|
+
.optional()
|
|
522
|
+
.describe("New behaviour outside the window: postpone (default), skip or run."),
|
|
523
|
+
watchGlobs: z
|
|
524
|
+
.array(z.string())
|
|
525
|
+
.optional()
|
|
526
|
+
.describe("New glob masks for a file trigger. Empty array clears them."),
|
|
527
|
+
watchIgnore: z
|
|
528
|
+
.array(z.string())
|
|
529
|
+
.optional()
|
|
530
|
+
.describe("New ignore masks for a file trigger. Empty array clears them."),
|
|
531
|
+
gitBranch: z
|
|
532
|
+
.string()
|
|
533
|
+
.optional()
|
|
534
|
+
.describe("New git branch filter (glob, comma-separated). Empty string clears it."),
|
|
535
|
+
gitPaths: z
|
|
536
|
+
.array(z.string())
|
|
537
|
+
.optional()
|
|
538
|
+
.describe("New changed-file masks for a git trigger. Empty array clears them."),
|
|
539
|
+
gitIgnore: z
|
|
540
|
+
.array(z.string())
|
|
541
|
+
.optional()
|
|
542
|
+
.describe("New ignored changed-file masks for a git trigger. Empty array clears them."),
|
|
543
|
+
gitPollSeconds: z
|
|
544
|
+
.number()
|
|
545
|
+
.int()
|
|
546
|
+
.min(5)
|
|
547
|
+
.optional()
|
|
548
|
+
.describe("New git polling interval in seconds."),
|
|
466
549
|
prompt: z
|
|
467
550
|
.string()
|
|
468
551
|
.optional()
|
|
@@ -500,7 +583,7 @@ export const updateTaskSchema = z.object({
|
|
|
500
583
|
.optional()
|
|
501
584
|
.describe("New error-chain task. Empty string clears it."),
|
|
502
585
|
triggerType: z
|
|
503
|
-
.enum(["cron", "file", "mcp-event", "once"])
|
|
586
|
+
.enum(["cron", "file", "git", "mcp-event", "once"])
|
|
504
587
|
.optional()
|
|
505
588
|
.describe("New trigger type."),
|
|
506
589
|
mcpEvent: z
|
|
@@ -899,6 +982,14 @@ const scheduleTaskExecute = wrapExecute<ScheduleArgs>(async (args) => {
|
|
|
899
982
|
notAfter,
|
|
900
983
|
session,
|
|
901
984
|
sessionMaxRuns,
|
|
985
|
+
activeDays,
|
|
986
|
+
windowPolicy,
|
|
987
|
+
watchGlobs,
|
|
988
|
+
watchIgnore,
|
|
989
|
+
gitBranch,
|
|
990
|
+
gitPaths,
|
|
991
|
+
gitIgnore,
|
|
992
|
+
gitPollSeconds,
|
|
902
993
|
} = args;
|
|
903
994
|
|
|
904
995
|
let effectiveRunAt: string | undefined;
|
|
@@ -952,7 +1043,17 @@ const scheduleTaskExecute = wrapExecute<ScheduleArgs>(async (args) => {
|
|
|
952
1043
|
effectiveRunAt,
|
|
953
1044
|
effectiveSession,
|
|
954
1045
|
effectiveSessionId,
|
|
955
|
-
sessionMaxRuns
|
|
1046
|
+
sessionMaxRuns,
|
|
1047
|
+
{
|
|
1048
|
+
activeDays,
|
|
1049
|
+
windowPolicy,
|
|
1050
|
+
watchGlobs,
|
|
1051
|
+
watchIgnore,
|
|
1052
|
+
gitBranch,
|
|
1053
|
+
gitPaths,
|
|
1054
|
+
gitIgnore,
|
|
1055
|
+
gitPollSeconds,
|
|
1056
|
+
}
|
|
956
1057
|
);
|
|
957
1058
|
} catch (err: any) {
|
|
958
1059
|
return {
|
|
@@ -965,7 +1066,7 @@ const scheduleTaskExecute = wrapExecute<ScheduleArgs>(async (args) => {
|
|
|
965
1066
|
|
|
966
1067
|
// Новый файловый триггер должен начать работать сразу, без перезапуска
|
|
967
1068
|
// OpenCode: пересобираем набор watcher-ов после создания задачи.
|
|
968
|
-
await
|
|
1069
|
+
await refreshTriggers();
|
|
969
1070
|
|
|
970
1071
|
const workspace = workspaceId ? getWorkspace(workspaceId) : undefined;
|
|
971
1072
|
const effectiveWorkdir =
|
|
@@ -1222,7 +1323,7 @@ const deleteTaskExecute = wrapExecute<DeleteArgs>(async (args) => {
|
|
|
1222
1323
|
try {
|
|
1223
1324
|
const { removed, existed } = await deleteTaskWithFamily(name);
|
|
1224
1325
|
// Убираем watcher удалённой задачи, не дожидаясь перезапуска плагина.
|
|
1225
|
-
await
|
|
1326
|
+
await refreshTriggers();
|
|
1226
1327
|
if (!existed && removed.length === 0) {
|
|
1227
1328
|
return {
|
|
1228
1329
|
content: JSON.stringify({
|
|
@@ -1424,6 +1525,34 @@ async function updateTaskFromInput(
|
|
|
1424
1525
|
};
|
|
1425
1526
|
}
|
|
1426
1527
|
|
|
1528
|
+
// Спринт 27: параметры триггеров сохраняются, если поле не передано.
|
|
1529
|
+
const mergeStringList = (
|
|
1530
|
+
next: string[] | undefined,
|
|
1531
|
+
prev: string[] | undefined
|
|
1532
|
+
): string[] | undefined => {
|
|
1533
|
+
if (next === undefined) return prev;
|
|
1534
|
+
const cleaned = next
|
|
1535
|
+
.filter((item): item is string => typeof item === "string")
|
|
1536
|
+
.map((item) => item.trim())
|
|
1537
|
+
.filter(Boolean);
|
|
1538
|
+
return cleaned.length > 0 ? cleaned : undefined;
|
|
1539
|
+
};
|
|
1540
|
+
const triggerExtras: TriggerExtras = {
|
|
1541
|
+
activeDays:
|
|
1542
|
+
input.activeDays === undefined
|
|
1543
|
+
? previous.activeDays
|
|
1544
|
+
: input.activeDays.length > 0
|
|
1545
|
+
? input.activeDays
|
|
1546
|
+
: undefined,
|
|
1547
|
+
windowPolicy: input.windowPolicy ?? previous.windowPolicy,
|
|
1548
|
+
watchGlobs: mergeStringList(input.watchGlobs, previous.watchGlobs),
|
|
1549
|
+
watchIgnore: mergeStringList(input.watchIgnore, previous.watchIgnore),
|
|
1550
|
+
gitBranch: clearableString(input.gitBranch, previous.gitBranch),
|
|
1551
|
+
gitPaths: mergeStringList(input.gitPaths, previous.gitPaths),
|
|
1552
|
+
gitIgnore: mergeStringList(input.gitIgnore, previous.gitIgnore),
|
|
1553
|
+
gitPollSeconds: input.gitPollSeconds ?? previous.gitPollSeconds,
|
|
1554
|
+
};
|
|
1555
|
+
|
|
1427
1556
|
try {
|
|
1428
1557
|
// Обновление = пересоздание в планировщике с сохранением старых значений.
|
|
1429
1558
|
await scheduler.deleteTask(name);
|
|
@@ -1461,7 +1590,8 @@ async function updateTaskFromInput(
|
|
|
1461
1590
|
runAt,
|
|
1462
1591
|
session,
|
|
1463
1592
|
sessionId,
|
|
1464
|
-
sessionMaxRuns
|
|
1593
|
+
sessionMaxRuns,
|
|
1594
|
+
triggerExtras
|
|
1465
1595
|
);
|
|
1466
1596
|
|
|
1467
1597
|
// Матрица отключена при обновлении — убираем клонов и агрегатор.
|
|
@@ -1471,7 +1601,7 @@ async function updateTaskFromInput(
|
|
|
1471
1601
|
|
|
1472
1602
|
// Пересоздание могло изменить triggerType/watchPath — сразу
|
|
1473
1603
|
// пересобираем набор файловых watcher-ов.
|
|
1474
|
-
await
|
|
1604
|
+
await refreshTriggers();
|
|
1475
1605
|
|
|
1476
1606
|
return { success: true, message: `Задача "${name}" обновлена.` };
|
|
1477
1607
|
} catch (err: any) {
|
|
@@ -2201,7 +2331,7 @@ const transferTasksExecute = wrapExecute<TransferArgs>(async (args) => {
|
|
|
2201
2331
|
errors.push(`${def.name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
2202
2332
|
}
|
|
2203
2333
|
}
|
|
2204
|
-
await
|
|
2334
|
+
await refreshTriggers();
|
|
2205
2335
|
return {
|
|
2206
2336
|
content: JSON.stringify({ success: errors.length === 0, imported, errors }),
|
|
2207
2337
|
};
|
|
@@ -2488,17 +2618,105 @@ function withRpcAudit<T extends Record<string, (...args: any[]) => any>>(handler
|
|
|
2488
2618
|
*/
|
|
2489
2619
|
let fileWatcherManager: FileWatchManager | null = null;
|
|
2490
2620
|
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2621
|
+
/**
|
|
2622
|
+
* Спринт 27: менеджер git-триггеров. Опрашивает HEAD задач с
|
|
2623
|
+
* triggerType === "git" и запускает их при новых подходящих коммитах.
|
|
2624
|
+
*/
|
|
2625
|
+
let gitTriggerManager: GitTriggerManager | null = null;
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* Приводит в актуальное состояние все событийные триггеры (файлы и git).
|
|
2629
|
+
* Вызывается после создания, изменения и удаления задачи.
|
|
2630
|
+
*/
|
|
2631
|
+
async function refreshTriggers(): Promise<void> {
|
|
2632
|
+
if (fileWatcherManager) {
|
|
2633
|
+
try {
|
|
2634
|
+
await fileWatcherManager.refresh();
|
|
2635
|
+
} catch (err: any) {
|
|
2636
|
+
console.error(
|
|
2637
|
+
`[windows-scheduler] Не удалось обновить файловые триггеры: ${
|
|
2638
|
+
err instanceof Error ? err.message : String(err)
|
|
2639
|
+
}`
|
|
2640
|
+
);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
if (gitTriggerManager) {
|
|
2644
|
+
try {
|
|
2645
|
+
await gitTriggerManager.refresh();
|
|
2646
|
+
} catch (err: any) {
|
|
2647
|
+
console.error(
|
|
2648
|
+
`[windows-scheduler] Не удалось обновить git-триггеры: ${
|
|
2649
|
+
err instanceof Error ? err.message : String(err)
|
|
2650
|
+
}`
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
/** Максимальная задержка переноса событийного запуска (12 часов). */
|
|
2657
|
+
const EVENT_POSTPONE_MAX_MS = 12 * 60 * 60 * 1000;
|
|
2658
|
+
|
|
2659
|
+
/**
|
|
2660
|
+
* Спринт 27: запуск задачи по событию (файл, git, MCP) с учётом окна запуска
|
|
2661
|
+
* и разрешённых дней недели. Вне окна: skip — пишем причину и выходим,
|
|
2662
|
+
* postpone — таймер до ближайшего открытия, run — запускаем сразу.
|
|
2663
|
+
*/
|
|
2664
|
+
async function scheduleEventRun(taskName: string, reason: string): Promise<void> {
|
|
2665
|
+
const definition = getTask(taskName);
|
|
2666
|
+
if (!definition) return;
|
|
2667
|
+
|
|
2668
|
+
const policy = definition.windowPolicy ?? "postpone";
|
|
2669
|
+
const options = {
|
|
2670
|
+
notBefore: definition.notBefore,
|
|
2671
|
+
notAfter: definition.notAfter,
|
|
2672
|
+
days: definition.activeDays,
|
|
2673
|
+
timeZone: definition.timezone,
|
|
2674
|
+
};
|
|
2675
|
+
const now = new Date();
|
|
2676
|
+
const state = activeWindowState(now, options);
|
|
2677
|
+
|
|
2678
|
+
if (state.active || policy === "run") {
|
|
2679
|
+
await runTaskEntry(taskName);
|
|
2680
|
+
console.log(
|
|
2681
|
+
`[windows-scheduler] Запуск задачи "${taskName}" (${reason}).`
|
|
2682
|
+
);
|
|
2683
|
+
return;
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
if (policy === "skip") {
|
|
2687
|
+
console.log(
|
|
2688
|
+
`[windows-scheduler] Задача "${taskName}" не запущена (${reason}): ${
|
|
2689
|
+
state.reason ?? "вне окна"
|
|
2690
|
+
} — политика skip.`
|
|
2500
2691
|
);
|
|
2692
|
+
return;
|
|
2501
2693
|
}
|
|
2694
|
+
|
|
2695
|
+
const delay = nextWindowOpenDelayMs(now, options);
|
|
2696
|
+
if (delay <= 0 || delay > EVENT_POSTPONE_MAX_MS) {
|
|
2697
|
+
console.log(
|
|
2698
|
+
`[windows-scheduler] Задача "${taskName}" не запущена (${reason}): ${
|
|
2699
|
+
state.reason ?? "вне окна"
|
|
2700
|
+
} — до открытия окна больше 12 ч.`
|
|
2701
|
+
);
|
|
2702
|
+
return;
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
console.log(
|
|
2706
|
+
`[windows-scheduler] Задача "${taskName}" (${reason}) отложена на ~${Math.round(
|
|
2707
|
+
delay / 60000
|
|
2708
|
+
)} мин: ${state.reason ?? "вне окна"}.`
|
|
2709
|
+
);
|
|
2710
|
+
const timer = setTimeout(() => {
|
|
2711
|
+
void scheduleEventRun(taskName, reason).catch((err: any) => {
|
|
2712
|
+
console.error(
|
|
2713
|
+
`[windows-scheduler] Не удалось запустить отложенную задачу "${taskName}": ${
|
|
2714
|
+
err instanceof Error ? err.message : String(err)
|
|
2715
|
+
}`
|
|
2716
|
+
);
|
|
2717
|
+
});
|
|
2718
|
+
}, delay);
|
|
2719
|
+
timer.unref?.();
|
|
2502
2720
|
}
|
|
2503
2721
|
|
|
2504
2722
|
export default Plugin.define({
|
|
@@ -2651,10 +2869,7 @@ export default Plugin.define({
|
|
|
2651
2869
|
// запускаются при изменении watchPath через chokidar (с дебаунсом).
|
|
2652
2870
|
fileWatcherManager = new FileWatchManager(async (taskName) => {
|
|
2653
2871
|
try {
|
|
2654
|
-
await
|
|
2655
|
-
console.log(
|
|
2656
|
-
`[windows-scheduler] Запуск задачи "${taskName}" по изменению отслеживаемого файла.`
|
|
2657
|
-
);
|
|
2872
|
+
await scheduleEventRun(taskName, "изменение отслеживаемого файла");
|
|
2658
2873
|
} catch (err: any) {
|
|
2659
2874
|
console.error(
|
|
2660
2875
|
`[windows-scheduler] Не удалось запустить задачу "${taskName}" по файловому триггеру: ${
|
|
@@ -2663,7 +2878,21 @@ export default Plugin.define({
|
|
|
2663
2878
|
);
|
|
2664
2879
|
}
|
|
2665
2880
|
});
|
|
2666
|
-
|
|
2881
|
+
|
|
2882
|
+
// Спринт 27: git-триггеры — опрос HEAD и запуск при новых коммитах,
|
|
2883
|
+
// затронувших подходящие файлы.
|
|
2884
|
+
gitTriggerManager = new GitTriggerManager(async (taskName, info) => {
|
|
2885
|
+
try {
|
|
2886
|
+
await scheduleEventRun(taskName, `новый коммит ${info.head?.slice(0, 7) ?? ""}`);
|
|
2887
|
+
} catch (err: any) {
|
|
2888
|
+
console.error(
|
|
2889
|
+
`[windows-scheduler] Не удалось запустить задачу "${taskName}" по git-триггеру: ${
|
|
2890
|
+
err instanceof Error ? err.message : String(err)
|
|
2891
|
+
}`
|
|
2892
|
+
);
|
|
2893
|
+
}
|
|
2894
|
+
});
|
|
2895
|
+
void refreshTriggers();
|
|
2667
2896
|
|
|
2668
2897
|
const registration = await ctx.tool.transform((editor) => {
|
|
2669
2898
|
// editor.add регистрирует новые инструменты плагина с codemode: true,
|
|
@@ -3067,7 +3296,7 @@ export default Plugin.define({
|
|
|
3067
3296
|
nextTaskOnSuccess?: string;
|
|
3068
3297
|
nextTaskOnError?: string;
|
|
3069
3298
|
dependsOn?: string[];
|
|
3070
|
-
triggerType?: "cron" | "file" | "mcp-event" | "once";
|
|
3299
|
+
triggerType?: "cron" | "file" | "git" | "mcp-event" | "once";
|
|
3071
3300
|
watchPath?: string;
|
|
3072
3301
|
workingDirectory?: string;
|
|
3073
3302
|
model?: string;
|
|
@@ -4008,6 +4237,21 @@ function resolveMatrixExtraConfig(
|
|
|
4008
4237
|
* Общая логика создания задачи: используется и schedule_task (инструмент),
|
|
4009
4238
|
* и create_task (RPC-метод для GUI).
|
|
4010
4239
|
*/
|
|
4240
|
+
/**
|
|
4241
|
+
* Спринт 27: дополнительные параметры триггеров (дни недели, политика окна,
|
|
4242
|
+
* glob-фильтры файловых триггеров и git-триггеры).
|
|
4243
|
+
*/
|
|
4244
|
+
export interface TriggerExtras {
|
|
4245
|
+
activeDays?: number[];
|
|
4246
|
+
windowPolicy?: "skip" | "postpone" | "run";
|
|
4247
|
+
watchGlobs?: string[];
|
|
4248
|
+
watchIgnore?: string[];
|
|
4249
|
+
gitBranch?: string;
|
|
4250
|
+
gitPaths?: string[];
|
|
4251
|
+
gitIgnore?: string[];
|
|
4252
|
+
gitPollSeconds?: number;
|
|
4253
|
+
}
|
|
4254
|
+
|
|
4011
4255
|
async function schedulerCreateTask(
|
|
4012
4256
|
name: string,
|
|
4013
4257
|
schedule: string,
|
|
@@ -4019,7 +4263,7 @@ async function schedulerCreateTask(
|
|
|
4019
4263
|
qualityGate?: string,
|
|
4020
4264
|
nextTaskOnSuccess?: string,
|
|
4021
4265
|
nextTaskOnError?: string,
|
|
4022
|
-
triggerType?: "cron" | "file" | "mcp-event" | "once",
|
|
4266
|
+
triggerType?: "cron" | "file" | "git" | "mcp-event" | "once",
|
|
4023
4267
|
watchPath?: string,
|
|
4024
4268
|
dependsOn?: string[],
|
|
4025
4269
|
model?: string,
|
|
@@ -4049,7 +4293,9 @@ async function schedulerCreateTask(
|
|
|
4049
4293
|
/** ID сессии для reuse (генерируется автоматически; пользователь не задаёт). */
|
|
4050
4294
|
sessionId?: string,
|
|
4051
4295
|
/** Сколько запусков переживает reuse-сессия до ротации (0/undefined — без ограничения). */
|
|
4052
|
-
sessionMaxRuns?: number
|
|
4296
|
+
sessionMaxRuns?: number,
|
|
4297
|
+
/** Спринт 27: дни недели, политика окна, glob- и git-фильтры. */
|
|
4298
|
+
triggerExtras?: TriggerExtras
|
|
4053
4299
|
): Promise<void> {
|
|
4054
4300
|
const normalizedModel = model?.trim() || undefined;
|
|
4055
4301
|
const normalizedPriority = normalizePriority(priority);
|
|
@@ -4059,6 +4305,35 @@ async function schedulerCreateTask(
|
|
|
4059
4305
|
const normalizedNotBefore = notBefore?.trim() || undefined;
|
|
4060
4306
|
const normalizedNotAfter = notAfter?.trim() || undefined;
|
|
4061
4307
|
const normalizedPausedUntil = pausedUntil?.trim() || undefined;
|
|
4308
|
+
// Спринт 27: дни недели, политика окна и glob/git-фильтры.
|
|
4309
|
+
const normalizeGlobList = (raw?: string[]): string[] | undefined => {
|
|
4310
|
+
if (!Array.isArray(raw)) return undefined;
|
|
4311
|
+
const cleaned = Array.from(
|
|
4312
|
+
new Set(
|
|
4313
|
+
raw
|
|
4314
|
+
.filter((item): item is string => typeof item === "string")
|
|
4315
|
+
.map((item) => item.trim())
|
|
4316
|
+
.filter(Boolean)
|
|
4317
|
+
)
|
|
4318
|
+
);
|
|
4319
|
+
return cleaned.length > 0 ? cleaned : undefined;
|
|
4320
|
+
};
|
|
4321
|
+
const normalizedActiveDays = normalizeActiveDays(triggerExtras?.activeDays);
|
|
4322
|
+
const normalizedWindowPolicy =
|
|
4323
|
+
triggerExtras?.windowPolicy === "skip" || triggerExtras?.windowPolicy === "run"
|
|
4324
|
+
? triggerExtras.windowPolicy
|
|
4325
|
+
: undefined;
|
|
4326
|
+
const normalizedWatchGlobs = normalizeGlobList(triggerExtras?.watchGlobs);
|
|
4327
|
+
const normalizedWatchIgnore = normalizeGlobList(triggerExtras?.watchIgnore);
|
|
4328
|
+
const normalizedGitBranch = triggerExtras?.gitBranch?.trim() || undefined;
|
|
4329
|
+
const normalizedGitPaths = normalizeGlobList(triggerExtras?.gitPaths);
|
|
4330
|
+
const normalizedGitIgnore = normalizeGlobList(triggerExtras?.gitIgnore);
|
|
4331
|
+
const normalizedGitPollSeconds =
|
|
4332
|
+
typeof triggerExtras?.gitPollSeconds === "number" &&
|
|
4333
|
+
Number.isFinite(triggerExtras.gitPollSeconds) &&
|
|
4334
|
+
triggerExtras.gitPollSeconds >= 5
|
|
4335
|
+
? Math.floor(triggerExtras.gitPollSeconds)
|
|
4336
|
+
: undefined;
|
|
4062
4337
|
const normalizedMcpEvent =
|
|
4063
4338
|
mcpEvent && mcpEvent.event?.trim()
|
|
4064
4339
|
? {
|
|
@@ -4169,6 +4444,22 @@ async function schedulerCreateTask(
|
|
|
4169
4444
|
if (effectiveTriggerType === "mcp-event" && !normalizedMcpEvent) {
|
|
4170
4445
|
throw new Error("Для MCP-триггера нужно указать имя события (mcpEvent.event).");
|
|
4171
4446
|
}
|
|
4447
|
+
// Спринт 27: git-триггеру нужен git-репозиторий в рабочей директории.
|
|
4448
|
+
if (effectiveTriggerType === "git") {
|
|
4449
|
+
const gitCwd = workspaceId?.trim()
|
|
4450
|
+
? getWorkspace(workspaceId.trim())?.path
|
|
4451
|
+
: workingDirectory?.trim() || projectDirectory || process.cwd();
|
|
4452
|
+
if (!gitCwd) {
|
|
4453
|
+
throw new Error(
|
|
4454
|
+
`Задача "${name}": для git-триггера нужна рабочая директория или workspace.`
|
|
4455
|
+
);
|
|
4456
|
+
}
|
|
4457
|
+
if (!readGitBranch(gitCwd)) {
|
|
4458
|
+
throw new Error(
|
|
4459
|
+
`Задача "${name}": git-триггер требует git-репозиторий в "${gitCwd}".`
|
|
4460
|
+
);
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4172
4463
|
// Валидируем cron-выражение до создания файлов. Для file/mcp-event
|
|
4173
4464
|
// расписание не используется вовсе.
|
|
4174
4465
|
if (effectiveTriggerType === "cron") {
|
|
@@ -4193,6 +4484,14 @@ async function schedulerCreateTask(
|
|
|
4193
4484
|
throw new Error(`Задача "${name}": ${windowError}`);
|
|
4194
4485
|
}
|
|
4195
4486
|
}
|
|
4487
|
+
// Спринт 27: окно и дни недели применимы и к событийным триггерам
|
|
4488
|
+
// (file/git/mcp-event/once) — проверяем корректность до создания задачи.
|
|
4489
|
+
if (effectiveTriggerType !== "cron") {
|
|
4490
|
+
const windowError = validateLaunchWindow(normalizedNotBefore, normalizedNotAfter);
|
|
4491
|
+
if (windowError) {
|
|
4492
|
+
throw new Error(`Задача "${name}": ${windowError}`);
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4196
4495
|
|
|
4197
4496
|
const sanitized = sanitizeName(name);
|
|
4198
4497
|
const lockFile = lockFilePath(sanitized);
|
|
@@ -4205,7 +4504,9 @@ async function schedulerCreateTask(
|
|
|
4205
4504
|
schedule,
|
|
4206
4505
|
normalizedTz,
|
|
4207
4506
|
normalizedNotBefore,
|
|
4208
|
-
normalizedNotAfter
|
|
4507
|
+
normalizedNotAfter,
|
|
4508
|
+
normalizedActiveDays,
|
|
4509
|
+
normalizedWindowPolicy
|
|
4209
4510
|
)
|
|
4210
4511
|
: undefined;
|
|
4211
4512
|
const wrapperGate = gate
|
|
@@ -4374,6 +4675,15 @@ async function schedulerCreateTask(
|
|
|
4374
4675
|
timezone: normalizedTz,
|
|
4375
4676
|
notBefore: normalizedNotBefore,
|
|
4376
4677
|
notAfter: normalizedNotAfter,
|
|
4678
|
+
// Спринт 27: дни недели, политика окна, glob- и git-фильтры.
|
|
4679
|
+
activeDays: normalizedActiveDays,
|
|
4680
|
+
windowPolicy: normalizedWindowPolicy,
|
|
4681
|
+
watchGlobs: normalizedWatchGlobs,
|
|
4682
|
+
watchIgnore: normalizedWatchIgnore,
|
|
4683
|
+
gitBranch: normalizedGitBranch,
|
|
4684
|
+
gitPaths: normalizedGitPaths,
|
|
4685
|
+
gitIgnore: normalizedGitIgnore,
|
|
4686
|
+
gitPollSeconds: normalizedGitPollSeconds,
|
|
4377
4687
|
pausedUntil: normalizedPausedUntil,
|
|
4378
4688
|
allowedTools: normalizedAllowedTools,
|
|
4379
4689
|
deniedTools: normalizedDeniedTools,
|
package/src/rpc.ts
CHANGED
|
@@ -101,6 +101,37 @@ const TaskItem = {
|
|
|
101
101
|
notBefore: { type: ["string", "null"] },
|
|
102
102
|
/** Конец окна запуска "HH:MM" (null — без окна). */
|
|
103
103
|
notAfter: { type: ["string", "null"] },
|
|
104
|
+
/** Спринт 27: разрешённые дни недели 0=Вс..6=Сб (null — все дни). */
|
|
105
|
+
activeDays: {
|
|
106
|
+
type: ["array", "null"],
|
|
107
|
+
items: { type: "number" },
|
|
108
|
+
},
|
|
109
|
+
/** Поведение вне окна: skip, postpone или run (null — postpone). */
|
|
110
|
+
windowPolicy: { type: ["string", "null"] },
|
|
111
|
+
/** Glob-маски файлового триггера (null — без ограничения). */
|
|
112
|
+
watchGlobs: {
|
|
113
|
+
type: ["array", "null"],
|
|
114
|
+
items: { type: "string" },
|
|
115
|
+
},
|
|
116
|
+
/** Glob-маски исключений файлового триггера. */
|
|
117
|
+
watchIgnore: {
|
|
118
|
+
type: ["array", "null"],
|
|
119
|
+
items: { type: "string" },
|
|
120
|
+
},
|
|
121
|
+
/** Git-триггер: фильтр ветки (glob, через запятую). */
|
|
122
|
+
gitBranch: { type: ["string", "null"] },
|
|
123
|
+
/** Git-триггер: маски путей, изменения в которых запускают задачу. */
|
|
124
|
+
gitPaths: {
|
|
125
|
+
type: ["array", "null"],
|
|
126
|
+
items: { type: "string" },
|
|
127
|
+
},
|
|
128
|
+
/** Git-триггер: маски игнорируемых путей. */
|
|
129
|
+
gitIgnore: {
|
|
130
|
+
type: ["array", "null"],
|
|
131
|
+
items: { type: "string" },
|
|
132
|
+
},
|
|
133
|
+
/** Git-триггер: период опроса в секундах (null — 60). */
|
|
134
|
+
gitPollSeconds: { type: ["number", "null"] },
|
|
104
135
|
/** Пауза до даты в ISO (null — автопродолжение не запланировано). */
|
|
105
136
|
pausedUntil: { type: ["string", "null"] },
|
|
106
137
|
/** Рабочая директория задачи (null — папка проекта по умолчанию). */
|
|
@@ -222,6 +253,22 @@ const CreateTaskInput = {
|
|
|
222
253
|
notBefore: { type: "string" },
|
|
223
254
|
/** Конец окна запуска "HH:MM"; может быть меньше notBefore (через полночь). */
|
|
224
255
|
notAfter: { type: "string" },
|
|
256
|
+
/** Спринт 27: разрешённые дни недели 0=Вс..6=Сб. Пусто — все дни. */
|
|
257
|
+
activeDays: { type: "array", items: { type: "number" } },
|
|
258
|
+
/** Поведение вне окна/дня: postpone (по умолчанию), skip или run. */
|
|
259
|
+
windowPolicy: { type: "string" },
|
|
260
|
+
/** Glob-маски файлового триггера (например, src/** и *.md). */
|
|
261
|
+
watchGlobs: { type: "array", items: { type: "string" } },
|
|
262
|
+
/** Glob-маски исключений файлового триггера. */
|
|
263
|
+
watchIgnore: { type: "array", items: { type: "string" } },
|
|
264
|
+
/** Git-триггер: ветка или glob (main, release/*), через запятую. */
|
|
265
|
+
gitBranch: { type: "string" },
|
|
266
|
+
/** Git-триггер: маски изменённых файлов, при которых задача запускается. */
|
|
267
|
+
gitPaths: { type: "array", items: { type: "string" } },
|
|
268
|
+
/** Git-триггер: маски изменённых файлов, которые игнорируются. */
|
|
269
|
+
gitIgnore: { type: "array", items: { type: "string" } },
|
|
270
|
+
/** Git-триггер: период опроса в секундах (минимум 5, по умолчанию 60). */
|
|
271
|
+
gitPollSeconds: { type: "number" },
|
|
225
272
|
},
|
|
226
273
|
required: ["name", "prompt"],
|
|
227
274
|
} as const;
|
|
@@ -768,6 +815,16 @@ const TemplateItem = {
|
|
|
768
815
|
triggerType: { type: "string" },
|
|
769
816
|
mcpEvent: McpEventSchema,
|
|
770
817
|
watchPath: { type: "string" },
|
|
818
|
+
/** Спринт 27: glob-маски и исключения файлового триггера. */
|
|
819
|
+
watchGlobs: { type: "array", items: { type: "string" } },
|
|
820
|
+
watchIgnore: { type: "array", items: { type: "string" } },
|
|
821
|
+
/** Спринт 27: git-триггер и дни/политика окна. */
|
|
822
|
+
gitBranch: { type: "string" },
|
|
823
|
+
gitPaths: { type: "array", items: { type: "string" } },
|
|
824
|
+
gitIgnore: { type: "array", items: { type: "string" } },
|
|
825
|
+
gitPollSeconds: { type: "number" },
|
|
826
|
+
activeDays: { type: "array", items: { type: "number" } },
|
|
827
|
+
windowPolicy: { type: "string" },
|
|
771
828
|
workspaceId: { type: "string" },
|
|
772
829
|
workingDirectory: { type: "string" },
|
|
773
830
|
/** Белый список инструментов задачи (role-scoped, metadata-only). */
|
|
@@ -921,6 +978,22 @@ const UpdateTaskInput = {
|
|
|
921
978
|
notBefore: { type: "string" },
|
|
922
979
|
/** Конец окна запуска "HH:MM". Пустая строка — сбросить окно. */
|
|
923
980
|
notAfter: { type: "string" },
|
|
981
|
+
/** Спринт 27: дни недели 0=Вс..6=Сб. Пустой массив — снять ограничение. */
|
|
982
|
+
activeDays: { type: "array", items: { type: "number" } },
|
|
983
|
+
/** Поведение вне окна: postpone (по умолчанию), skip или run. */
|
|
984
|
+
windowPolicy: { type: "string" },
|
|
985
|
+
/** Glob-маски файлового триггера. Пустой массив — снять ограничение. */
|
|
986
|
+
watchGlobs: { type: "array", items: { type: "string" } },
|
|
987
|
+
/** Glob-маски исключений файлового триггера. Пустой массив — очистить. */
|
|
988
|
+
watchIgnore: { type: "array", items: { type: "string" } },
|
|
989
|
+
/** Git-триггер: фильтр ветки (glob, через запятую). Пустая строка — сбросить. */
|
|
990
|
+
gitBranch: { type: "string" },
|
|
991
|
+
/** Git-триггер: маски путей. Пустой массив — сбросить. */
|
|
992
|
+
gitPaths: { type: "array", items: { type: "string" } },
|
|
993
|
+
/** Git-триггер: маски игнорируемых путей. Пустой массив — очистить. */
|
|
994
|
+
gitIgnore: { type: "array", items: { type: "string" } },
|
|
995
|
+
/** Git-триггер: период опроса в секундах (минимум 5). */
|
|
996
|
+
gitPollSeconds: { type: "number" },
|
|
924
997
|
},
|
|
925
998
|
required: ["name"],
|
|
926
999
|
} as const;
|