opencode-windows-scheduler 1.3.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 +47 -1
- package/README.md +11 -5
- package/ROADMAP-STRATEGY.md +45 -26
- package/ROADMAP.md +279 -35
- package/dist/core/audit.d.ts +68 -0
- package/dist/core/audit.d.ts.map +1 -0
- package/dist/core/audit.js +206 -0
- 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/secrets.d.ts +57 -0
- package/dist/core/secrets.d.ts.map +1 -0
- package/dist/core/secrets.js +331 -0
- package/dist/core/structured-log.d.ts.map +1 -1
- package/dist/core/structured-log.js +9 -0
- 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 +23 -0
- package/dist/index.d.ts +68 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +589 -45
- package/dist/rpc.d.ts +623 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +219 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +67 -0
- package/dist/settings.d.ts +16 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +29 -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/dist/workspaces.d.ts +8 -2
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +21 -4
- package/docs/ARCHITECTURE.md +14 -5
- package/docs/FEATURES.md +80 -1
- package/docs/README.ru.md +15 -5
- package/gui-experimental.cjs +9 -4
- package/package.json +8 -3
- package/src/core/audit.ts +291 -0
- 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/secrets.ts +385 -0
- package/src/core/structured-log.ts +9 -0
- package/src/core/wrappers/bash.ts +4 -0
- package/src/db/git-state-repo.ts +62 -0
- package/src/db/schema.ts +23 -0
- package/src/gui.tsx +548 -4
- package/src/index.ts +790 -47
- package/src/rpc.ts +230 -0
- package/src/server.ts +67 -0
- package/src/settings.ts +51 -0
- package/src/task-transfer.ts +124 -5
- package/src/templates.ts +1 -1
- package/src/workspaces.ts +22 -4
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;
|
|
@@ -441,6 +488,41 @@ const NotificationSettingsSchema = {
|
|
|
441
488
|
},
|
|
442
489
|
required: ["include", "exclude"],
|
|
443
490
|
},
|
|
491
|
+
telegram: {
|
|
492
|
+
type: "object" as const,
|
|
493
|
+
properties: {
|
|
494
|
+
enabled: { type: "boolean" },
|
|
495
|
+
botToken: { type: "string" },
|
|
496
|
+
chatId: { type: "string" },
|
|
497
|
+
parseMode: {
|
|
498
|
+
type: "string",
|
|
499
|
+
enum: ["", "HTML", "Markdown", "MarkdownV2"],
|
|
500
|
+
},
|
|
501
|
+
disableNotification: { type: "boolean" },
|
|
502
|
+
messageThreadId: { type: ["number", "null"] },
|
|
503
|
+
includeDashboardLink: { type: "boolean" },
|
|
504
|
+
apiBase: { type: "string" },
|
|
505
|
+
},
|
|
506
|
+
required: ["enabled"],
|
|
507
|
+
},
|
|
508
|
+
native: {
|
|
509
|
+
type: "object" as const,
|
|
510
|
+
properties: {
|
|
511
|
+
enabled: { type: "boolean" },
|
|
512
|
+
sound: { type: "boolean" },
|
|
513
|
+
},
|
|
514
|
+
required: ["enabled"],
|
|
515
|
+
},
|
|
516
|
+
quietHours: {
|
|
517
|
+
type: "object" as const,
|
|
518
|
+
properties: {
|
|
519
|
+
enabled: { type: "boolean" },
|
|
520
|
+
from: { type: "string" },
|
|
521
|
+
to: { type: "string" },
|
|
522
|
+
},
|
|
523
|
+
required: ["enabled", "from", "to"],
|
|
524
|
+
},
|
|
525
|
+
dashboardUrl: { type: "string" },
|
|
444
526
|
matrix: {
|
|
445
527
|
type: "object" as const,
|
|
446
528
|
properties: {
|
|
@@ -477,6 +559,17 @@ const HistorySettingsSchema = {
|
|
|
477
559
|
required: ["retentionDays", "maxRecords"],
|
|
478
560
|
} as const;
|
|
479
561
|
|
|
562
|
+
/** Журнал аудита (Спринт 26). */
|
|
563
|
+
const AuditSettingsSchema = {
|
|
564
|
+
type: "object" as const,
|
|
565
|
+
properties: {
|
|
566
|
+
enabled: { type: "boolean" },
|
|
567
|
+
retentionDays: { type: "number" },
|
|
568
|
+
maxRecords: { type: "number" },
|
|
569
|
+
},
|
|
570
|
+
required: ["enabled", "retentionDays", "maxRecords"],
|
|
571
|
+
} as const;
|
|
572
|
+
|
|
480
573
|
const GetSettingsOutput = {
|
|
481
574
|
type: "object" as const,
|
|
482
575
|
properties: {
|
|
@@ -484,6 +577,7 @@ const GetSettingsOutput = {
|
|
|
484
577
|
winterMode: { type: "boolean" },
|
|
485
578
|
notifications: NotificationSettingsSchema,
|
|
486
579
|
history: HistorySettingsSchema,
|
|
580
|
+
audit: AuditSettingsSchema,
|
|
487
581
|
},
|
|
488
582
|
required: ["maxConcurrent", "winterMode", "notifications"],
|
|
489
583
|
} as const;
|
|
@@ -495,6 +589,7 @@ const SaveSettingsInput = {
|
|
|
495
589
|
winterMode: { type: "boolean" },
|
|
496
590
|
notifications: NotificationSettingsSchema,
|
|
497
591
|
history: HistorySettingsSchema,
|
|
592
|
+
audit: AuditSettingsSchema,
|
|
498
593
|
},
|
|
499
594
|
additionalProperties: false,
|
|
500
595
|
} as const;
|
|
@@ -507,6 +602,7 @@ const SaveSettingsOutput = {
|
|
|
507
602
|
winterMode: { type: "boolean" },
|
|
508
603
|
notifications: NotificationSettingsSchema,
|
|
509
604
|
history: HistorySettingsSchema,
|
|
605
|
+
audit: AuditSettingsSchema,
|
|
510
606
|
},
|
|
511
607
|
required: ["success", "maxConcurrent", "winterMode", "notifications"],
|
|
512
608
|
} as const;
|
|
@@ -591,6 +687,110 @@ const SendDigestOutput = {
|
|
|
591
687
|
required: ["success", "message"],
|
|
592
688
|
} as const;
|
|
593
689
|
|
|
690
|
+
/** Секрет: имя и маскированный превью, значение никогда не возвращается. */
|
|
691
|
+
const SecretItem = {
|
|
692
|
+
type: "object" as const,
|
|
693
|
+
properties: {
|
|
694
|
+
name: { type: "string" },
|
|
695
|
+
preview: { type: "string" },
|
|
696
|
+
updatedAt: { type: "string" },
|
|
697
|
+
},
|
|
698
|
+
required: ["name", "preview"],
|
|
699
|
+
} as const;
|
|
700
|
+
|
|
701
|
+
const ListSecretsInput = {
|
|
702
|
+
type: "object" as const,
|
|
703
|
+
properties: {},
|
|
704
|
+
additionalProperties: false,
|
|
705
|
+
} as const;
|
|
706
|
+
|
|
707
|
+
const ListSecretsOutput = {
|
|
708
|
+
type: "object" as const,
|
|
709
|
+
properties: {
|
|
710
|
+
success: { type: "boolean" },
|
|
711
|
+
secrets: { type: "array", items: SecretItem },
|
|
712
|
+
},
|
|
713
|
+
required: ["success", "secrets"],
|
|
714
|
+
} as const;
|
|
715
|
+
|
|
716
|
+
const SaveSecretInput = {
|
|
717
|
+
type: "object" as const,
|
|
718
|
+
properties: {
|
|
719
|
+
name: { type: "string" },
|
|
720
|
+
value: { type: "string" },
|
|
721
|
+
},
|
|
722
|
+
required: ["name", "value"],
|
|
723
|
+
additionalProperties: false,
|
|
724
|
+
} as const;
|
|
725
|
+
|
|
726
|
+
const SaveSecretOutput = {
|
|
727
|
+
type: "object" as const,
|
|
728
|
+
properties: {
|
|
729
|
+
success: { type: "boolean" },
|
|
730
|
+
message: { type: "string" },
|
|
731
|
+
secret: SecretItem,
|
|
732
|
+
},
|
|
733
|
+
required: ["success"],
|
|
734
|
+
} as const;
|
|
735
|
+
|
|
736
|
+
const DeleteSecretInput = {
|
|
737
|
+
type: "object" as const,
|
|
738
|
+
properties: {
|
|
739
|
+
name: { type: "string" },
|
|
740
|
+
},
|
|
741
|
+
required: ["name"],
|
|
742
|
+
additionalProperties: false,
|
|
743
|
+
} as const;
|
|
744
|
+
|
|
745
|
+
const DeleteSecretOutput = {
|
|
746
|
+
type: "object" as const,
|
|
747
|
+
properties: {
|
|
748
|
+
success: { type: "boolean" },
|
|
749
|
+
message: { type: "string" },
|
|
750
|
+
},
|
|
751
|
+
required: ["success", "message"],
|
|
752
|
+
} as const;
|
|
753
|
+
|
|
754
|
+
/** Запись журнала аудита (Спринт 26). */
|
|
755
|
+
const AuditRecordSchema = {
|
|
756
|
+
type: "object" as const,
|
|
757
|
+
properties: {
|
|
758
|
+
id: { type: "number" },
|
|
759
|
+
ts: { type: "string" },
|
|
760
|
+
action: { type: "string" },
|
|
761
|
+
targetType: { type: ["string", "null"] },
|
|
762
|
+
target: { type: ["string", "null"] },
|
|
763
|
+
actor: { type: "string" },
|
|
764
|
+
source: { type: ["string", "null"] },
|
|
765
|
+
details: {},
|
|
766
|
+
remote: { type: ["string", "null"] },
|
|
767
|
+
},
|
|
768
|
+
required: ["id", "ts", "action", "actor"],
|
|
769
|
+
} as const;
|
|
770
|
+
|
|
771
|
+
const GetAuditInput = {
|
|
772
|
+
type: "object" as const,
|
|
773
|
+
properties: {
|
|
774
|
+
action: { type: "string" },
|
|
775
|
+
target: { type: "string" },
|
|
776
|
+
actor: { type: "string" },
|
|
777
|
+
since: { type: "string" },
|
|
778
|
+
until: { type: "string" },
|
|
779
|
+
limit: { type: "number" },
|
|
780
|
+
},
|
|
781
|
+
additionalProperties: false,
|
|
782
|
+
} as const;
|
|
783
|
+
|
|
784
|
+
const GetAuditOutput = {
|
|
785
|
+
type: "object" as const,
|
|
786
|
+
properties: {
|
|
787
|
+
success: { type: "boolean" },
|
|
788
|
+
records: { type: "array", items: AuditRecordSchema },
|
|
789
|
+
total: { type: "number" },
|
|
790
|
+
},
|
|
791
|
+
required: ["success", "records", "total"],
|
|
792
|
+
} as const;
|
|
793
|
+
|
|
594
794
|
const TemplateItem = {
|
|
595
795
|
type: "object" as const,
|
|
596
796
|
properties: {
|
|
@@ -615,6 +815,16 @@ const TemplateItem = {
|
|
|
615
815
|
triggerType: { type: "string" },
|
|
616
816
|
mcpEvent: McpEventSchema,
|
|
617
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" },
|
|
618
828
|
workspaceId: { type: "string" },
|
|
619
829
|
workingDirectory: { type: "string" },
|
|
620
830
|
/** Белый список инструментов задачи (role-scoped, metadata-only). */
|
|
@@ -768,6 +978,22 @@ const UpdateTaskInput = {
|
|
|
768
978
|
notBefore: { type: "string" },
|
|
769
979
|
/** Конец окна запуска "HH:MM". Пустая строка — сбросить окно. */
|
|
770
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" },
|
|
771
997
|
},
|
|
772
998
|
required: ["name"],
|
|
773
999
|
} as const;
|
|
@@ -1230,6 +1456,10 @@ export const SchedulerRpc = Rpc.define({
|
|
|
1230
1456
|
input: SendDigestInput,
|
|
1231
1457
|
output: SendDigestOutput,
|
|
1232
1458
|
},
|
|
1459
|
+
list_secrets: { input: ListSecretsInput, output: ListSecretsOutput },
|
|
1460
|
+
save_secret: { input: SaveSecretInput, output: SaveSecretOutput },
|
|
1461
|
+
delete_secret: { input: DeleteSecretInput, output: DeleteSecretOutput },
|
|
1462
|
+
get_audit: { input: GetAuditInput, output: GetAuditOutput },
|
|
1233
1463
|
},
|
|
1234
1464
|
events: {},
|
|
1235
1465
|
});
|
package/src/server.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
import { appendStructuredLog, readStructuredLogs } from "./core/structured-log.js";
|
|
22
22
|
import { PROMETHEUS_CONTENT_TYPE, renderPrometheusMetrics } from "./core/prometheus.js";
|
|
23
23
|
import { buildOtlpExport } from "./core/otel.js";
|
|
24
|
+
import { readAuditLog, recordAudit } from "./core/audit.js";
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Локальный веб-дашборд (Спринт 5).
|
|
@@ -621,6 +622,7 @@ async function handleRequest(
|
|
|
621
622
|
pathname === "/api/history/export" ||
|
|
622
623
|
pathname === "/api/export-db" ||
|
|
623
624
|
pathname === "/api/workspaces" ||
|
|
625
|
+
pathname === "/api/audit" ||
|
|
624
626
|
pathname === "/api/health" ||
|
|
625
627
|
pathname === "/api/logs" ||
|
|
626
628
|
pathname === "/metrics" ||
|
|
@@ -935,6 +937,27 @@ async function handleRequest(
|
|
|
935
937
|
return;
|
|
936
938
|
}
|
|
937
939
|
|
|
940
|
+
// Журнал аудита (Спринт 26): GET /api/audit?action=…&actor=…&limit=…
|
|
941
|
+
if (req.method === "GET" && pathname === "/api/audit") {
|
|
942
|
+
try {
|
|
943
|
+
const limitRaw = Number(url.searchParams.get("limit"));
|
|
944
|
+
const result = readAuditLog({
|
|
945
|
+
action: url.searchParams.get("action") ?? undefined,
|
|
946
|
+
target: url.searchParams.get("target") ?? undefined,
|
|
947
|
+
actor: url.searchParams.get("actor") ?? undefined,
|
|
948
|
+
since: url.searchParams.get("since") ?? undefined,
|
|
949
|
+
until: url.searchParams.get("until") ?? undefined,
|
|
950
|
+
limit: Number.isFinite(limitRaw) ? limitRaw : undefined,
|
|
951
|
+
});
|
|
952
|
+
sendJson(res, 200, { success: true, ...result });
|
|
953
|
+
} catch (err: any) {
|
|
954
|
+
sendJson(res, 500, {
|
|
955
|
+
error: err instanceof Error ? err.message : String(err),
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
|
|
938
961
|
// Входящий webhook-триггер (Спринт 22): POST /api/hooks/:task?token=…
|
|
939
962
|
const hookMatch = req.method === "POST" && pathname.match(/^\/api\/hooks\/(.+)$/);
|
|
940
963
|
if (hookMatch) {
|
|
@@ -1022,6 +1045,15 @@ async function handleRequest(
|
|
|
1022
1045
|
? `Задача "${task.name}" уже выполняется.`
|
|
1023
1046
|
: `Задача "${task.name}" запущена по webhook.`;
|
|
1024
1047
|
logHook(202, "accepted", undefined, bodyResult.body.length);
|
|
1048
|
+
recordAudit({
|
|
1049
|
+
action: "task.run",
|
|
1050
|
+
targetType: "task",
|
|
1051
|
+
target: task.name,
|
|
1052
|
+
actor: "http",
|
|
1053
|
+
source: "POST /api/hooks/:name",
|
|
1054
|
+
remote,
|
|
1055
|
+
details: { trigger: "hook" },
|
|
1056
|
+
});
|
|
1025
1057
|
sendJson(res, 202, {
|
|
1026
1058
|
success: true,
|
|
1027
1059
|
task: task.name,
|
|
@@ -1046,6 +1078,15 @@ async function handleRequest(
|
|
|
1046
1078
|
}
|
|
1047
1079
|
try {
|
|
1048
1080
|
const result = await deps.runTask(name);
|
|
1081
|
+
recordAudit({
|
|
1082
|
+
action: "task.run",
|
|
1083
|
+
targetType: "task",
|
|
1084
|
+
target: name,
|
|
1085
|
+
actor: "http",
|
|
1086
|
+
source: "POST /api/run/:name",
|
|
1087
|
+
remote: req.socket.remoteAddress ?? null,
|
|
1088
|
+
details: { alreadyRunning: Boolean(result?.alreadyRunning) },
|
|
1089
|
+
});
|
|
1049
1090
|
sendJson(res, 200, {
|
|
1050
1091
|
success: true,
|
|
1051
1092
|
message: result?.alreadyRunning
|
|
@@ -1076,6 +1117,15 @@ async function handleRequest(
|
|
|
1076
1117
|
}
|
|
1077
1118
|
try {
|
|
1078
1119
|
const result = await deps.cancelMatrix(name);
|
|
1120
|
+
recordAudit({
|
|
1121
|
+
action: "matrix.cancel",
|
|
1122
|
+
targetType: "matrix",
|
|
1123
|
+
target: name,
|
|
1124
|
+
actor: "http",
|
|
1125
|
+
source: "POST /api/cancel-matrix/:name",
|
|
1126
|
+
remote: req.socket.remoteAddress ?? null,
|
|
1127
|
+
details: { cancelled: result.cancelled },
|
|
1128
|
+
});
|
|
1079
1129
|
sendJson(res, 200, {
|
|
1080
1130
|
success: true,
|
|
1081
1131
|
message: result.message,
|
|
@@ -1098,6 +1148,15 @@ async function handleRequest(
|
|
|
1098
1148
|
}
|
|
1099
1149
|
try {
|
|
1100
1150
|
const removed = await deps.cleanupMatrixOrphans();
|
|
1151
|
+
recordAudit({
|
|
1152
|
+
action: "matrix.cleanup",
|
|
1153
|
+
targetType: "matrix",
|
|
1154
|
+
target: "orphans",
|
|
1155
|
+
actor: "http",
|
|
1156
|
+
source: "POST /api/matrix-cleanup",
|
|
1157
|
+
remote: req.socket.remoteAddress ?? null,
|
|
1158
|
+
details: { removed: removed.length },
|
|
1159
|
+
});
|
|
1101
1160
|
sendJson(res, 200, {
|
|
1102
1161
|
success: true,
|
|
1103
1162
|
removed,
|
|
@@ -1125,6 +1184,14 @@ async function handleRequest(
|
|
|
1125
1184
|
}
|
|
1126
1185
|
try {
|
|
1127
1186
|
await deps.deleteTask(name);
|
|
1187
|
+
recordAudit({
|
|
1188
|
+
action: "task.delete",
|
|
1189
|
+
targetType: "task",
|
|
1190
|
+
target: name,
|
|
1191
|
+
actor: "http",
|
|
1192
|
+
source: "POST /api/delete/:name",
|
|
1193
|
+
remote: req.socket.remoteAddress ?? null,
|
|
1194
|
+
});
|
|
1128
1195
|
sendJson(res, 200, { success: true, message: `Задача "${name}" удалена.` });
|
|
1129
1196
|
} catch (err: any) {
|
|
1130
1197
|
sendJson(res, 500, {
|
package/src/settings.ts
CHANGED
|
@@ -178,6 +178,16 @@ export interface IntegrationSettings {
|
|
|
178
178
|
hooks: HookSettings;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/** Настройки журнала аудита (Спринт 26). */
|
|
182
|
+
export interface AuditSettings {
|
|
183
|
+
/** Вести журнал мутаций. */
|
|
184
|
+
enabled: boolean;
|
|
185
|
+
/** Сколько дней хранить записи; 0 — без ограничения по времени. */
|
|
186
|
+
retentionDays: number;
|
|
187
|
+
/** Максимум записей; старые удаляются первыми. */
|
|
188
|
+
maxRecords: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
181
191
|
/**
|
|
182
192
|
* Глобальные настройки плагина, которые меняются из GUI.
|
|
183
193
|
* Хранятся в settings.json рядом с tasks.json / history.json.
|
|
@@ -193,6 +203,8 @@ export interface SchedulerSettings {
|
|
|
193
203
|
history: HistorySettings;
|
|
194
204
|
/** Внешние интеграции: входящие webhook-триггеры. */
|
|
195
205
|
integrations: IntegrationSettings;
|
|
206
|
+
/** Журнал аудита мутаций (Спринт 26). */
|
|
207
|
+
audit: AuditSettings;
|
|
196
208
|
}
|
|
197
209
|
|
|
198
210
|
export const SETTINGS_FILE = path.join(PLUGIN_DIR, "settings.json");
|
|
@@ -213,6 +225,38 @@ export const DEFAULT_HOOK_TIMESTAMP_TOLERANCE_SECONDS = 300;
|
|
|
213
225
|
const MAX_HOOK_BODY_BYTES = 5 * 1024 * 1024;
|
|
214
226
|
const MAX_HOOK_CREDENTIAL_LENGTH = 512;
|
|
215
227
|
|
|
228
|
+
/** Аудит (Спринт 26): включён, 90 дней и не больше 10 000 записей. */
|
|
229
|
+
export const DEFAULT_AUDIT_RETENTION_DAYS = 90;
|
|
230
|
+
export const DEFAULT_AUDIT_MAX_RECORDS = 10_000;
|
|
231
|
+
|
|
232
|
+
/** Значения аудита по умолчанию. */
|
|
233
|
+
export function defaultAuditSettings(): AuditSettings {
|
|
234
|
+
return {
|
|
235
|
+
enabled: true,
|
|
236
|
+
retentionDays: DEFAULT_AUDIT_RETENTION_DAYS,
|
|
237
|
+
maxRecords: DEFAULT_AUDIT_MAX_RECORDS,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Приводит настройки аудита к безопасному виду. */
|
|
242
|
+
function normalizeAuditSettings(
|
|
243
|
+
value: unknown,
|
|
244
|
+
fallback: AuditSettings
|
|
245
|
+
): AuditSettings {
|
|
246
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
247
|
+
return { ...fallback };
|
|
248
|
+
}
|
|
249
|
+
const raw = value as Partial<AuditSettings>;
|
|
250
|
+
return {
|
|
251
|
+
enabled: typeof raw.enabled === "boolean" ? raw.enabled : fallback.enabled,
|
|
252
|
+
retentionDays: normalizeRetentionLimit(
|
|
253
|
+
raw.retentionDays,
|
|
254
|
+
fallback.retentionDays
|
|
255
|
+
),
|
|
256
|
+
maxRecords: normalizeRetentionLimit(raw.maxRecords, fallback.maxRecords),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
216
260
|
/** Значения интеграций по умолчанию: хуки выключены, подпись обязательна. */
|
|
217
261
|
export function defaultIntegrations(): IntegrationSettings {
|
|
218
262
|
return {
|
|
@@ -636,6 +680,7 @@ export async function loadSettings(): Promise<SchedulerSettings> {
|
|
|
636
680
|
const fallbackNotifications = defaultNotifications();
|
|
637
681
|
const fallbackHistory = defaultHistorySettings();
|
|
638
682
|
const fallbackIntegrations = defaultIntegrations();
|
|
683
|
+
const fallbackAudit = defaultAuditSettings();
|
|
639
684
|
try {
|
|
640
685
|
const raw = await fs.readFile(SETTINGS_FILE, "utf8");
|
|
641
686
|
const parsed = JSON.parse(raw) as Partial<SchedulerSettings> | null;
|
|
@@ -657,6 +702,7 @@ export async function loadSettings(): Promise<SchedulerSettings> {
|
|
|
657
702
|
parsed?.integrations,
|
|
658
703
|
fallbackIntegrations
|
|
659
704
|
),
|
|
705
|
+
audit: normalizeAuditSettings(parsed?.audit, fallbackAudit),
|
|
660
706
|
};
|
|
661
707
|
} catch {
|
|
662
708
|
return {
|
|
@@ -665,6 +711,7 @@ export async function loadSettings(): Promise<SchedulerSettings> {
|
|
|
665
711
|
notifications: fallbackNotifications,
|
|
666
712
|
history: fallbackHistory,
|
|
667
713
|
integrations: fallbackIntegrations,
|
|
714
|
+
audit: fallbackAudit,
|
|
668
715
|
};
|
|
669
716
|
}
|
|
670
717
|
}
|
|
@@ -695,6 +742,10 @@ export async function saveSettings(
|
|
|
695
742
|
patch.integrations !== undefined
|
|
696
743
|
? normalizeIntegrations(patch.integrations, current.integrations)
|
|
697
744
|
: current.integrations,
|
|
745
|
+
audit:
|
|
746
|
+
patch.audit !== undefined
|
|
747
|
+
? normalizeAuditSettings(patch.audit, current.audit)
|
|
748
|
+
: current.audit,
|
|
698
749
|
};
|
|
699
750
|
|
|
700
751
|
// Удобство: при включении хуков без явных учётных данных генерируем их,
|