opencode-windows-scheduler 1.5.2 → 1.5.5
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 +107 -2
- package/CROSS_PLATFORM.md +107 -71
- package/LICENSE +21 -21
- package/README.md +74 -26
- package/ROADMAP-STRATEGY.md +11 -4
- package/ROADMAP.md +322 -112
- package/dist/core/analytics.d.ts +3 -0
- package/dist/core/analytics.d.ts.map +1 -1
- package/dist/core/analytics.js +4 -0
- package/dist/core/audit.d.ts +2 -1
- package/dist/core/audit.d.ts.map +1 -1
- package/dist/core/audit.js +32 -1
- package/dist/core/cron-to-schtasks.d.ts.map +1 -1
- package/dist/core/cron-to-schtasks.js +21 -4
- package/dist/core/file-watcher.d.ts.map +1 -1
- package/dist/core/file-watcher.js +16 -1
- package/dist/core/git-trigger.d.ts +4 -2
- package/dist/core/git-trigger.d.ts.map +1 -1
- package/dist/core/git-trigger.js +34 -16
- package/dist/core/local-ai.d.ts +52 -0
- package/dist/core/local-ai.d.ts.map +1 -0
- package/dist/core/local-ai.js +119 -0
- package/dist/core/lock.d.ts +14 -0
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +81 -4
- package/dist/core/matrix.d.ts.map +1 -1
- package/dist/core/matrix.js +3 -2
- package/dist/core/native-notify.d.ts.map +1 -1
- package/dist/core/native-notify.js +3 -0
- package/dist/core/one-shot.d.ts +7 -1
- package/dist/core/one-shot.d.ts.map +1 -1
- package/dist/core/one-shot.js +15 -2
- package/dist/core/permissions.d.ts +69 -0
- package/dist/core/permissions.d.ts.map +1 -0
- package/dist/core/permissions.js +143 -0
- package/dist/core/ps-wrapper.d.ts +9 -30
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +477 -108
- package/dist/core/record-history.d.ts +11 -0
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +106 -4
- package/dist/core/savings.d.ts +70 -0
- package/dist/core/savings.d.ts.map +1 -0
- package/dist/core/savings.js +87 -0
- package/dist/core/schedule-gate.js +7 -3
- package/dist/core/schedule-v2.js +1 -1
- package/dist/core/scheduler/index.d.ts +13 -1
- package/dist/core/scheduler/index.d.ts.map +1 -1
- package/dist/core/scheduler/index.js +35 -4
- package/dist/core/scheduler/linux.d.ts +4 -1
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +53 -20
- package/dist/core/scheduler/mac.d.ts +2 -1
- package/dist/core/scheduler/mac.d.ts.map +1 -1
- package/dist/core/scheduler/mac.js +24 -6
- package/dist/core/scheduler/posix.d.ts +1 -1
- package/dist/core/scheduler/posix.d.ts.map +1 -1
- package/dist/core/scheduler/posix.js +2 -2
- package/dist/core/scheduler/registry.d.ts +3 -2
- package/dist/core/scheduler/registry.d.ts.map +1 -1
- package/dist/core/scheduler/registry.js +6 -5
- package/dist/core/scheduler/windows.d.ts +49 -1
- package/dist/core/scheduler/windows.d.ts.map +1 -1
- package/dist/core/scheduler/windows.js +219 -34
- package/dist/core/secrets.d.ts +5 -3
- package/dist/core/secrets.d.ts.map +1 -1
- package/dist/core/secrets.js +86 -8
- package/dist/core/self-analysis.d.ts +117 -0
- package/dist/core/self-analysis.d.ts.map +1 -0
- package/dist/core/self-analysis.js +539 -0
- package/dist/core/session.d.ts +11 -3
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +34 -5
- package/dist/core/shutdown.d.ts +26 -0
- package/dist/core/shutdown.d.ts.map +1 -0
- package/dist/core/shutdown.js +49 -0
- package/dist/core/summary.d.ts +69 -0
- package/dist/core/summary.d.ts.map +1 -0
- package/dist/core/summary.js +250 -0
- package/dist/core/telegram.d.ts +10 -0
- package/dist/core/telegram.d.ts.map +1 -1
- package/dist/core/telegram.js +228 -47
- package/dist/core/triage-chain.d.ts +40 -0
- package/dist/core/triage-chain.d.ts.map +1 -0
- package/dist/core/triage-chain.js +80 -0
- package/dist/core/triage-compare.d.ts +68 -0
- package/dist/core/triage-compare.d.ts.map +1 -0
- package/dist/core/triage-compare.js +184 -0
- package/dist/core/triage-rules.d.ts +23 -0
- package/dist/core/triage-rules.d.ts.map +1 -0
- package/dist/core/triage-rules.js +196 -0
- package/dist/core/triage-shadow.d.ts +91 -0
- package/dist/core/triage-shadow.d.ts.map +1 -0
- package/dist/core/triage-shadow.js +160 -0
- package/dist/core/triage-worker.d.ts +55 -0
- package/dist/core/triage-worker.d.ts.map +1 -0
- package/dist/core/triage-worker.js +314 -0
- package/dist/core/triage.d.ts +76 -0
- package/dist/core/triage.d.ts.map +1 -0
- package/dist/core/triage.js +271 -0
- package/dist/core/watch-paths.d.ts +6 -0
- package/dist/core/watch-paths.d.ts.map +1 -0
- package/dist/core/watch-paths.js +62 -0
- package/dist/core/wrappers/bash.d.ts +15 -3
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +153 -120
- package/dist/db/history-repo.d.ts +1 -1
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +29 -14
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +31 -0
- package/dist/history.d.ts +2 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +3 -3
- package/dist/i18n.d.ts +25 -2
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +75 -10
- package/dist/index.d.ts +66 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +527 -68
- package/dist/integrations.d.ts +9 -1
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +34 -6
- package/dist/notifications.d.ts +30 -2
- package/dist/notifications.d.ts.map +1 -1
- package/dist/notifications.js +289 -10
- package/dist/profiles.d.ts +1 -1
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +21 -3
- package/dist/rpc.d.ts +401 -5
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +138 -5
- package/dist/server.d.ts +20 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +136 -14
- package/dist/settings.d.ts +167 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +322 -3
- package/dist/task-transfer.d.ts +8 -1
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +2 -2
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +23 -5
- package/dist/workspaces.d.ts +9 -0
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +25 -0
- package/docs/ARCHITECTURE.md +48 -28
- package/docs/CONCEPT.md +230 -0
- package/docs/CROSS_PLATFORM.ru.md +150 -0
- package/docs/CROSS_PLATFORM.zh.md +146 -0
- package/docs/FAQ.md +52 -0
- package/docs/FAQ.ru.md +53 -0
- package/docs/FAQ.zh.md +43 -0
- package/docs/FEATURES.md +141 -44
- package/docs/FEATURES.zh.md +655 -0
- package/docs/LOCAL-AI.md +300 -0
- package/docs/MIGRATION.md +17 -0
- package/docs/README.ru.md +22 -16
- package/docs/README.zh.md +286 -0
- package/docs/SAVINGS.md +61 -0
- package/docs/SAVINGS.ru.md +60 -0
- package/docs/SAVINGS.zh.md +52 -0
- package/docs/ZH-LOCALE-PLAN.md +324 -0
- package/docs/spikes/local-model-structured-output.md +81 -0
- package/docs/spikes/ollama-qwen3-4b-smoke.json +28 -0
- package/docs/spikes/ollama-qwen3-4b.json +163 -0
- package/gui-experimental.cjs +8 -8
- package/locales/en.json +85 -0
- package/locales/ru.json +85 -0
- package/locales/zh.json +780 -0
- package/package.json +31 -7
- package/scripts/bench-local.mjs +321 -0
- package/scripts/check-zh-locale.mjs +218 -0
- package/scripts/run-tests.mjs +236 -0
- package/scripts/spike-local-structured.mjs +182 -0
- package/scripts/test-locale.mjs +4 -3
- package/skills/scheduled-job-best-practices/SKILL.md +6 -3
- package/skills/scheduled-job-best-practices/references/recipes.md +40 -0
- package/src/core/analytics.ts +10 -0
- package/src/core/audit.ts +39 -1
- package/src/core/cron-to-schtasks.ts +23 -4
- package/src/core/file-watcher.ts +20 -1
- package/src/core/git-trigger.ts +34 -16
- package/src/core/local-ai.ts +173 -0
- package/src/core/lock.ts +88 -3
- package/src/core/matrix.ts +5 -1
- package/src/core/native-notify.ts +3 -0
- package/src/core/one-shot.ts +18 -2
- package/src/core/permissions.ts +200 -0
- package/src/core/ps-wrapper.ts +492 -108
- package/src/core/record-history.ts +111 -4
- package/src/core/savings.ts +150 -0
- package/src/core/schedule-gate.ts +9 -3
- package/src/core/schedule-v2.ts +1 -1
- package/src/core/scheduler/index.ts +41 -3
- package/src/core/scheduler/linux.ts +67 -22
- package/src/core/scheduler/mac.ts +24 -7
- package/src/core/scheduler/posix.ts +2 -2
- package/src/core/scheduler/registry.ts +7 -5
- package/src/core/scheduler/windows.ts +237 -32
- package/src/core/secrets.ts +101 -7
- package/src/core/self-analysis.ts +744 -0
- package/src/core/session.ts +40 -5
- package/src/core/shutdown.ts +69 -0
- package/src/core/summary.ts +318 -0
- package/src/core/telegram.ts +266 -55
- package/src/core/triage-chain.ts +125 -0
- package/src/core/triage-compare.ts +277 -0
- package/src/core/triage-rules.ts +238 -0
- package/src/core/triage-shadow.ts +240 -0
- package/src/core/triage-worker.ts +344 -0
- package/src/core/triage.ts +366 -0
- package/src/core/watch-paths.ts +70 -0
- package/src/core/wrappers/bash.ts +181 -138
- package/src/db/history-repo.ts +31 -18
- package/src/db/schema.ts +31 -0
- package/src/gui.tsx +551 -14
- package/src/history.ts +7 -3
- package/src/i18n.ts +87 -13
- package/src/index.ts +649 -71
- package/src/integrations.ts +50 -6
- package/src/notifications.ts +468 -5
- package/src/profiles.ts +21 -3
- package/src/rpc.ts +143 -5
- package/src/server.ts +135 -16
- package/src/settings.ts +582 -5
- package/src/task-transfer.ts +10 -3
- package/src/types.ts +24 -5
- package/src/workspaces.ts +22 -0
package/src/rpc.ts
CHANGED
|
@@ -57,6 +57,8 @@ const TaskItem = {
|
|
|
57
57
|
properties: {
|
|
58
58
|
name: { type: "string" },
|
|
59
59
|
schedule: { type: "string" },
|
|
60
|
+
/** Hotfix 1.5.3.1: лимит времени задачи в секундах (null - по умолчанию). */
|
|
61
|
+
timeoutSeconds: { type: ["number", "null"] },
|
|
60
62
|
status: { type: "string" },
|
|
61
63
|
nextRun: { type: ["string", "null"] },
|
|
62
64
|
/** LLM-модель задачи (null — модель OpenCode по умолчанию). */
|
|
@@ -241,9 +243,9 @@ const CreateTaskInput = {
|
|
|
241
243
|
workspaceId: { type: "string" },
|
|
242
244
|
/** Рабочая директория задачи (по умолчанию — папка проекта). */
|
|
243
245
|
workingDirectory: { type: "string" },
|
|
244
|
-
/** Белый список инструментов задачи (role-scoped,
|
|
246
|
+
/** Белый список инструментов задачи (role-scoped, enforced through OPENCODE_CONFIG_CONTENT). Пустой массив запрещён. */
|
|
245
247
|
allowedTools: { type: "array", items: { type: "string" } },
|
|
246
|
-
/** Чёрный список инструментов задачи (приоритет над allowedTools).
|
|
248
|
+
/** Чёрный список инструментов задачи (приоритет над allowedTools и политикой). Enforced. */
|
|
247
249
|
deniedTools: { type: "array", items: { type: "string" } },
|
|
248
250
|
/** Matrix (fan-out): раскладывает задачу-шаблон на клоны по workspace. */
|
|
249
251
|
matrix: MatrixSchema,
|
|
@@ -543,6 +545,62 @@ const NotificationSettingsSchema = {
|
|
|
543
545
|
},
|
|
544
546
|
required: ["enabled", "frequency", "time"],
|
|
545
547
|
},
|
|
548
|
+
triage: {
|
|
549
|
+
type: "object" as const,
|
|
550
|
+
properties: {
|
|
551
|
+
mode: { type: "string", enum: ["off", "rules", "llm", "auto"] },
|
|
552
|
+
baseUrl: { type: "string" },
|
|
553
|
+
model: { type: "string" },
|
|
554
|
+
timeoutMs: { type: "number" },
|
|
555
|
+
fallback: { type: "string", enum: ["rules", "notify", "skip"] },
|
|
556
|
+
confidenceThreshold: { type: "number" },
|
|
557
|
+
rules: {
|
|
558
|
+
type: "array",
|
|
559
|
+
items: {
|
|
560
|
+
type: "object" as const,
|
|
561
|
+
properties: {
|
|
562
|
+
id: { type: "string" },
|
|
563
|
+
field: {
|
|
564
|
+
type: "string",
|
|
565
|
+
enum: ["status", "task", "error", "cost"],
|
|
566
|
+
},
|
|
567
|
+
operator: {
|
|
568
|
+
type: "string",
|
|
569
|
+
enum: ["equals", "contains", "regex", "gt", "lt", "gte", "lte"],
|
|
570
|
+
},
|
|
571
|
+
value: { type: ["string", "number"] },
|
|
572
|
+
category: {
|
|
573
|
+
type: "string",
|
|
574
|
+
enum: ["quality", "timeout", "permission", "network", "unknown"],
|
|
575
|
+
},
|
|
576
|
+
severity: { type: "string", enum: ["low", "medium", "high"] },
|
|
577
|
+
confidence: { type: "number" },
|
|
578
|
+
action: { type: "string", enum: ["notify", "skip"] },
|
|
579
|
+
reason: { type: "string" },
|
|
580
|
+
priority: { type: "number" },
|
|
581
|
+
},
|
|
582
|
+
required: ["field", "operator", "value"],
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
shadow: {
|
|
586
|
+
type: "object" as const,
|
|
587
|
+
properties: {
|
|
588
|
+
enabled: { type: "boolean" },
|
|
589
|
+
days: { type: "number" },
|
|
590
|
+
startedAt: { type: ["string", "null"] },
|
|
591
|
+
},
|
|
592
|
+
required: ["enabled", "days", "startedAt"],
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
required: [
|
|
596
|
+
"mode",
|
|
597
|
+
"baseUrl",
|
|
598
|
+
"model",
|
|
599
|
+
"timeoutMs",
|
|
600
|
+
"fallback",
|
|
601
|
+
"confidenceThreshold",
|
|
602
|
+
],
|
|
603
|
+
},
|
|
546
604
|
},
|
|
547
605
|
required: ["enabled", "onlyOnError"],
|
|
548
606
|
} as const;
|
|
@@ -570,15 +628,29 @@ const AuditSettingsSchema = {
|
|
|
570
628
|
required: ["enabled", "retentionDays", "maxRecords"],
|
|
571
629
|
} as const;
|
|
572
630
|
|
|
631
|
+
/** Политика прав фоновых задач (Спринт 32). */
|
|
632
|
+
const PermissionSettingsSchema = {
|
|
633
|
+
type: "object" as const,
|
|
634
|
+
properties: {
|
|
635
|
+
defaultPolicy: {
|
|
636
|
+
type: "string",
|
|
637
|
+
enum: ["hybrid", "secure", "legacy"],
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
required: ["defaultPolicy"],
|
|
641
|
+
} as const;
|
|
642
|
+
|
|
573
643
|
const GetSettingsOutput = {
|
|
574
644
|
type: "object" as const,
|
|
575
645
|
properties: {
|
|
576
646
|
maxConcurrent: { type: "number" },
|
|
577
|
-
locale: { type: "string", enum: ["ru", "en"] },
|
|
647
|
+
locale: { type: "string", enum: ["auto", "ru", "en", "zh"] },
|
|
648
|
+
uiLocale: { type: "string", enum: ["ru", "en", "zh"] },
|
|
578
649
|
winterMode: { type: "boolean" },
|
|
579
650
|
notifications: NotificationSettingsSchema,
|
|
580
651
|
history: HistorySettingsSchema,
|
|
581
652
|
audit: AuditSettingsSchema,
|
|
653
|
+
permissions: PermissionSettingsSchema,
|
|
582
654
|
},
|
|
583
655
|
required: ["maxConcurrent", "locale", "winterMode", "notifications"],
|
|
584
656
|
} as const;
|
|
@@ -588,11 +660,13 @@ const SaveSettingsInput = {
|
|
|
588
660
|
properties: {
|
|
589
661
|
maxConcurrent: { type: "number" },
|
|
590
662
|
/** Язык интерфейса (Спринт 28): ru по умолчанию, en — опционально. */
|
|
591
|
-
locale: { type: "string", enum: ["ru", "en"] },
|
|
663
|
+
locale: { type: "string", enum: ["auto", "ru", "en", "zh"] },
|
|
664
|
+
uiLocale: { type: "string", enum: ["ru", "en", "zh"] },
|
|
592
665
|
winterMode: { type: "boolean" },
|
|
593
666
|
notifications: NotificationSettingsSchema,
|
|
594
667
|
history: HistorySettingsSchema,
|
|
595
668
|
audit: AuditSettingsSchema,
|
|
669
|
+
permissions: PermissionSettingsSchema,
|
|
596
670
|
},
|
|
597
671
|
additionalProperties: false,
|
|
598
672
|
} as const;
|
|
@@ -602,11 +676,13 @@ const SaveSettingsOutput = {
|
|
|
602
676
|
properties: {
|
|
603
677
|
success: { type: "boolean" },
|
|
604
678
|
maxConcurrent: { type: "number" },
|
|
605
|
-
locale: { type: "string", enum: ["ru", "en"] },
|
|
679
|
+
locale: { type: "string", enum: ["auto", "ru", "en", "zh"] },
|
|
680
|
+
uiLocale: { type: "string", enum: ["ru", "en", "zh"] },
|
|
606
681
|
winterMode: { type: "boolean" },
|
|
607
682
|
notifications: NotificationSettingsSchema,
|
|
608
683
|
history: HistorySettingsSchema,
|
|
609
684
|
audit: AuditSettingsSchema,
|
|
685
|
+
permissions: PermissionSettingsSchema,
|
|
610
686
|
},
|
|
611
687
|
required: ["success", "maxConcurrent", "locale", "winterMode", "notifications"],
|
|
612
688
|
} as const;
|
|
@@ -660,6 +736,34 @@ const GetAnalyticsOutput = {
|
|
|
660
736
|
required: ["success", "report"],
|
|
661
737
|
} as const;
|
|
662
738
|
|
|
739
|
+
const SelfAnalysisInput = {
|
|
740
|
+
type: "object" as const,
|
|
741
|
+
properties: {
|
|
742
|
+
/** Окно анализа в днях (по умолчанию 14, максимум 365). */
|
|
743
|
+
days: { type: "number" },
|
|
744
|
+
/** Сколько строк в топах (по умолчанию 10). */
|
|
745
|
+
topLimit: { type: "number" },
|
|
746
|
+
/** Включить обнаружение аномалий (по умолчанию true). */
|
|
747
|
+
includeAnomalies: { type: "boolean" },
|
|
748
|
+
/** Включить анализ трендов (по умолчанию true). */
|
|
749
|
+
includeTrends: { type: "boolean" },
|
|
750
|
+
/** Включить рекомендации (по умолчанию true). */
|
|
751
|
+
includeRecommendations: { type: "boolean" },
|
|
752
|
+
},
|
|
753
|
+
additionalProperties: false,
|
|
754
|
+
} as const;
|
|
755
|
+
|
|
756
|
+
const SelfAnalysisOutput = {
|
|
757
|
+
type: "object" as const,
|
|
758
|
+
properties: {
|
|
759
|
+
success: { type: "boolean" },
|
|
760
|
+
// null при ошибке: report формируется только при success=true.
|
|
761
|
+
report: { type: ["object", "null"] as const },
|
|
762
|
+
error: { type: "string" },
|
|
763
|
+
},
|
|
764
|
+
required: ["success", "report"],
|
|
765
|
+
} as const;
|
|
766
|
+
|
|
663
767
|
const TestNotificationInput = {
|
|
664
768
|
type: "object" as const,
|
|
665
769
|
properties: {},
|
|
@@ -795,6 +899,35 @@ const GetAuditOutput = {
|
|
|
795
899
|
required: ["success", "records", "total"],
|
|
796
900
|
} as const;
|
|
797
901
|
|
|
902
|
+
/** Сравнение триажа «до/после» (Спринт 31.5). */
|
|
903
|
+
const CompareTriageInput = {
|
|
904
|
+
type: "object" as const,
|
|
905
|
+
properties: {
|
|
906
|
+
taskName: { type: "string" },
|
|
907
|
+
status: { type: "string" },
|
|
908
|
+
error: { type: ["string", "null"] },
|
|
909
|
+
durationMs: { type: "number" },
|
|
910
|
+
tokens: { type: "number" },
|
|
911
|
+
costUsd: { type: "number" },
|
|
912
|
+
before: { type: ["object", "null"] },
|
|
913
|
+
after: { type: ["object", "null"] },
|
|
914
|
+
dedupCount: { type: "number" },
|
|
915
|
+
},
|
|
916
|
+
required: ["taskName", "status"],
|
|
917
|
+
additionalProperties: false,
|
|
918
|
+
} as const;
|
|
919
|
+
|
|
920
|
+
const CompareTriageOutput = {
|
|
921
|
+
type: "object" as const,
|
|
922
|
+
properties: {
|
|
923
|
+
success: { type: "boolean" },
|
|
924
|
+
result: { type: "object" },
|
|
925
|
+
error: { type: "string" },
|
|
926
|
+
},
|
|
927
|
+
required: ["success", "result"],
|
|
928
|
+
additionalProperties: false,
|
|
929
|
+
} as const;
|
|
930
|
+
|
|
798
931
|
const TemplateItem = {
|
|
799
932
|
type: "object" as const,
|
|
800
933
|
properties: {
|
|
@@ -1432,6 +1565,7 @@ export const SchedulerRpc = Rpc.define({
|
|
|
1432
1565
|
},
|
|
1433
1566
|
cleanup_history: { input: CleanupHistoryInput, output: CleanupHistoryOutput },
|
|
1434
1567
|
get_analytics: { input: GetAnalyticsInput, output: GetAnalyticsOutput },
|
|
1568
|
+
self_analysis: { input: SelfAnalysisInput, output: SelfAnalysisOutput },
|
|
1435
1569
|
expand_matrix_preview: {
|
|
1436
1570
|
input: ExpandMatrixPreviewInput,
|
|
1437
1571
|
output: ExpandMatrixPreviewOutput,
|
|
@@ -1464,6 +1598,10 @@ export const SchedulerRpc = Rpc.define({
|
|
|
1464
1598
|
save_secret: { input: SaveSecretInput, output: SaveSecretOutput },
|
|
1465
1599
|
delete_secret: { input: DeleteSecretInput, output: DeleteSecretOutput },
|
|
1466
1600
|
get_audit: { input: GetAuditInput, output: GetAuditOutput },
|
|
1601
|
+
compare_triage: {
|
|
1602
|
+
input: CompareTriageInput,
|
|
1603
|
+
output: CompareTriageOutput,
|
|
1604
|
+
},
|
|
1467
1605
|
},
|
|
1468
1606
|
events: {},
|
|
1469
1607
|
});
|
package/src/server.ts
CHANGED
|
@@ -46,9 +46,18 @@ const IS_WINDOWS = process.platform === "win32";
|
|
|
46
46
|
/**
|
|
47
47
|
* Имена процессов, которые считаем «зомби» от прошлых запусков плагина.
|
|
48
48
|
* На Windows процессы называются node.exe / bun.exe, на POSIX — node / bun.
|
|
49
|
+
* Ayrıca принимаем versioned-бинарники (node22, bun1.2 и т.п.) —
|
|
50
|
+
* они нормализуются в normalizeProcessName перед проверкой.
|
|
49
51
|
*/
|
|
50
52
|
const ZOMBIE_IMAGE_NAMES = new Set(["node", "nodejs", "node.exe", "bun", "bun.exe"]);
|
|
51
53
|
|
|
54
|
+
/** Нормализует имя процесса: node22 → node, bun1.2 → bun, остальные без изменений. */
|
|
55
|
+
function normalizeProcessName(name: string): string {
|
|
56
|
+
if (/^node\d+(\.\d+)*$/i.test(name)) return "node";
|
|
57
|
+
if (/^bun\d+(\.\d+)*$/i.test(name)) return "bun";
|
|
58
|
+
return name;
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
/** Маркер-заголовок: по нему узнаём «свой» дашборд, уже слушающий порт. */
|
|
53
62
|
const DASHBOARD_HEADER = "x-plugin-dashboard";
|
|
54
63
|
const DASHBOARD_MARKER = "opencode-windows-scheduler";
|
|
@@ -262,6 +271,79 @@ export function getDashboardPort(): number | null {
|
|
|
262
271
|
return running?.port ?? null;
|
|
263
272
|
}
|
|
264
273
|
|
|
274
|
+
/** Локальные имена, которым разрешено обращаться к дашборду. */
|
|
275
|
+
const LOCAL_HOSTNAMES = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Извлекает hostname из значения заголовка Host/Origin.
|
|
279
|
+
* Понимает `http://host:port`, `host:port`, `[::1]:port`, userinfo.
|
|
280
|
+
*/
|
|
281
|
+
function parseLocalHostname(value: string | undefined): string | undefined {
|
|
282
|
+
if (!value) return undefined;
|
|
283
|
+
let raw = value.trim();
|
|
284
|
+
if (!raw) return undefined;
|
|
285
|
+
// Отбрасываем схему и userinfo.
|
|
286
|
+
raw = raw.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "");
|
|
287
|
+
const at = raw.lastIndexOf("@");
|
|
288
|
+
if (at >= 0) raw = raw.slice(at + 1);
|
|
289
|
+
// Путь/query в Origin не входят, но на всякий случай отрезаем.
|
|
290
|
+
raw = raw.split(/[/?#]/)[0];
|
|
291
|
+
if (raw.startsWith("[")) {
|
|
292
|
+
const end = raw.indexOf("]");
|
|
293
|
+
if (end > 0) return raw.slice(0, end + 1).toLowerCase();
|
|
294
|
+
}
|
|
295
|
+
const colon = raw.lastIndexOf(":");
|
|
296
|
+
const host = (colon > 0 ? raw.slice(0, colon) : raw).replace(/\.$/, "");
|
|
297
|
+
return host.toLowerCase();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Проверяет, что запрос к дашборду исходит из доверенного источника,
|
|
302
|
+
* чтобы защититься от CSRF и DNS-ребиндинга.
|
|
303
|
+
*
|
|
304
|
+
* Правила:
|
|
305
|
+
* - при наличии Origin он ОБЯЗАН быть локальным — проверка Host при этом
|
|
306
|
+
* не спасает, потому что Host всегда равен адресату запроса;
|
|
307
|
+
* - без Origin (не-браузерный клиент, curl, свои fetch) требуется локальный Host —
|
|
308
|
+
* это защита от DNS-rebinding;
|
|
309
|
+
* - Origin: null, чужие схемы и чужие хосты отклоняются;
|
|
310
|
+
* - X-Scheduler-Client — только дополнительное подтверждение: он не обходит
|
|
311
|
+
* проверку Origin и не превращает внешний запрос в доверенный.
|
|
312
|
+
*/
|
|
313
|
+
export function isDashboardRequestTrusted(req: http.IncomingMessage): boolean {
|
|
314
|
+
const headers = req.headers ?? {};
|
|
315
|
+
|
|
316
|
+
const origin = typeof headers.origin === "string" ? headers.origin : undefined;
|
|
317
|
+
if (origin !== undefined) {
|
|
318
|
+
// "null" (sandbox/file://) и любые не-localhost Origin — не доверяем.
|
|
319
|
+
// X-Scheduler-Client НЕ обходит эту проверку: заголовок можно подделать
|
|
320
|
+
// через CORS с ошибкой в конфиге или XSS на странице дашборда.
|
|
321
|
+
const originHost = parseLocalHostname(origin);
|
|
322
|
+
const localOrigin = Boolean(originHost && LOCAL_HOSTNAMES.has(originHost));
|
|
323
|
+
if (!localOrigin) return false;
|
|
324
|
+
// Локальный Origin — доверяем; X-Scheduler-Client — дополнительное подтверждение.
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Origin отсутствует — не браузерный cross-origin запрос. Проверяем Host,
|
|
329
|
+
// чтобы запрос не пришёл через DNS-rebinding на чужое имя.
|
|
330
|
+
const hostHost = parseLocalHostname(typeof headers.host === "string" ? headers.host : undefined);
|
|
331
|
+
const localHost = Boolean(hostHost && LOCAL_HOSTNAMES.has(hostHost));
|
|
332
|
+
if (!localHost) return false;
|
|
333
|
+
// Без Origin, но локальный Host — доверяем; X-Scheduler-Client — бонус.
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Путь защищён проверкой источника: весь /api/*, кроме /api/hooks/*
|
|
339
|
+
* (hooks аутентифицируются HMAC и должны принимать внешние вызовы).
|
|
340
|
+
*/
|
|
341
|
+
export function needsDashboardSourceCheck(pathname: string): boolean {
|
|
342
|
+
if (!/^\/api(?:\/|$)/.test(pathname)) return false;
|
|
343
|
+
if (pathname === "/api/hooks" || pathname.startsWith("/api/hooks/")) return false;
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
|
|
265
347
|
/**
|
|
266
348
|
* Запускает сервер на первом свободном порту.
|
|
267
349
|
* Если порт занят не нашим дашбордом, сначала пытается снять зомби-процесс
|
|
@@ -362,7 +444,8 @@ async function tryFreeZombiePort(port: number): Promise<boolean> {
|
|
|
362
444
|
const info = await getProcessInfo(pid);
|
|
363
445
|
if (!info) continue;
|
|
364
446
|
|
|
365
|
-
|
|
447
|
+
const normName = normalizeProcessName(info.name.toLowerCase());
|
|
448
|
+
if (!ZOMBIE_IMAGE_NAMES.has(normName)) {
|
|
366
449
|
console.warn(
|
|
367
450
|
`[windows-scheduler] Порт ${port} занят процессом ${info.name} (PID ${pid}) — не трогаем, пробуем другой порт.`
|
|
368
451
|
);
|
|
@@ -648,6 +731,18 @@ async function handleRequest(
|
|
|
648
731
|
return;
|
|
649
732
|
}
|
|
650
733
|
|
|
734
|
+
// --- CSRF / DNS-rebinding защита для всего /api/* (кроме /api/hooks) --- //
|
|
735
|
+
// Требуем либо кастомный заголовок X-Scheduler-Client (браузер не отправит
|
|
736
|
+
// его межсайтово без ответа на preflight, которого сервер не даёт),
|
|
737
|
+
// либо локальный Origin, либо (для не-браузерных клиентов) локальный Host.
|
|
738
|
+
// GET-запросы защищены тоже: иначе DNS-rebinding позволяет прочитать
|
|
739
|
+
// /api/export-db (вся SQLite-база), историю, аудит и настройки.
|
|
740
|
+
// POST /api/hooks остаётся без этой проверки: он защищён HMAC отдельно.
|
|
741
|
+
if (needsDashboardSourceCheck(pathname) && !isDashboardRequestTrusted(req)) {
|
|
742
|
+
sendJson(res, 403, { error: "Запрос не прошёл проверку источника (CSRF/DNS-rebinding)." });
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
|
|
651
746
|
// Статический HTML-файл — страница дашборда.
|
|
652
747
|
if (req.method === "GET" && (pathname === "/" || pathname === "/index.html")) {
|
|
653
748
|
send(res, 200, "text/html; charset=utf-8", renderPage());
|
|
@@ -793,7 +888,7 @@ async function handleRequest(
|
|
|
793
888
|
tasks: [],
|
|
794
889
|
totals: { estimatedDurationSec: null, estimatedCostUsd: null, estimatedTokens: null },
|
|
795
890
|
warnings: [],
|
|
796
|
-
error:
|
|
891
|
+
error: sanitizeError(err),
|
|
797
892
|
});
|
|
798
893
|
}
|
|
799
894
|
return;
|
|
@@ -930,9 +1025,7 @@ async function handleRequest(
|
|
|
930
1025
|
);
|
|
931
1026
|
} catch (err: any) {
|
|
932
1027
|
sendJson(res, 500, {
|
|
933
|
-
error: `Не удалось экспортировать БД: ${
|
|
934
|
-
err instanceof Error ? err.message : String(err)
|
|
935
|
-
}`,
|
|
1028
|
+
error: `Не удалось экспортировать БД: ${sanitizeError(err)}`,
|
|
936
1029
|
});
|
|
937
1030
|
}
|
|
938
1031
|
return;
|
|
@@ -953,7 +1046,7 @@ async function handleRequest(
|
|
|
953
1046
|
sendJson(res, 200, { success: true, ...result });
|
|
954
1047
|
} catch (err: any) {
|
|
955
1048
|
sendJson(res, 500, {
|
|
956
|
-
error:
|
|
1049
|
+
error: sanitizeError(err),
|
|
957
1050
|
});
|
|
958
1051
|
}
|
|
959
1052
|
return;
|
|
@@ -1029,7 +1122,7 @@ async function handleRequest(
|
|
|
1029
1122
|
} catch (err: any) {
|
|
1030
1123
|
const message = err instanceof Error ? err.message : String(err);
|
|
1031
1124
|
logHook(500, "rejected", `Не удалось получить список задач: ${message}`, bodyResult.body.length);
|
|
1032
|
-
sendJson(res, 500, { success: false, error:
|
|
1125
|
+
sendJson(res, 500, { success: false, error: sanitizeError(err) });
|
|
1033
1126
|
return;
|
|
1034
1127
|
}
|
|
1035
1128
|
const key = taskName.toLowerCase();
|
|
@@ -1067,7 +1160,7 @@ async function handleRequest(
|
|
|
1067
1160
|
} catch (err: any) {
|
|
1068
1161
|
const message = err instanceof Error ? err.message : String(err);
|
|
1069
1162
|
logHook(500, "rejected", message, bodyResult.body.length);
|
|
1070
|
-
sendJson(res, 500, { success: false, error:
|
|
1163
|
+
sendJson(res, 500, { success: false, error: sanitizeError(err) });
|
|
1071
1164
|
}
|
|
1072
1165
|
return;
|
|
1073
1166
|
}
|
|
@@ -1100,7 +1193,7 @@ async function handleRequest(
|
|
|
1100
1193
|
} catch (err: any) {
|
|
1101
1194
|
sendJson(res, 500, {
|
|
1102
1195
|
success: false,
|
|
1103
|
-
error:
|
|
1196
|
+
error: sanitizeError(err),
|
|
1104
1197
|
});
|
|
1105
1198
|
}
|
|
1106
1199
|
return;
|
|
@@ -1138,7 +1231,7 @@ async function handleRequest(
|
|
|
1138
1231
|
} catch (err: any) {
|
|
1139
1232
|
sendJson(res, 500, {
|
|
1140
1233
|
success: false,
|
|
1141
|
-
error:
|
|
1234
|
+
error: sanitizeError(err),
|
|
1142
1235
|
});
|
|
1143
1236
|
}
|
|
1144
1237
|
return;
|
|
@@ -1172,7 +1265,7 @@ async function handleRequest(
|
|
|
1172
1265
|
} catch (err: any) {
|
|
1173
1266
|
sendJson(res, 500, {
|
|
1174
1267
|
success: false,
|
|
1175
|
-
error:
|
|
1268
|
+
error: sanitizeError(err),
|
|
1176
1269
|
});
|
|
1177
1270
|
}
|
|
1178
1271
|
return;
|
|
@@ -1200,7 +1293,7 @@ async function handleRequest(
|
|
|
1200
1293
|
} catch (err: any) {
|
|
1201
1294
|
sendJson(res, 500, {
|
|
1202
1295
|
success: false,
|
|
1203
|
-
error:
|
|
1296
|
+
error: sanitizeError(err),
|
|
1204
1297
|
});
|
|
1205
1298
|
}
|
|
1206
1299
|
return;
|
|
@@ -1216,7 +1309,7 @@ async function handleRequest(
|
|
|
1216
1309
|
res.destroy();
|
|
1217
1310
|
return;
|
|
1218
1311
|
}
|
|
1219
|
-
sendJson(res, 500, { error:
|
|
1312
|
+
sendJson(res, 500, { error: sanitizeError(err) });
|
|
1220
1313
|
}
|
|
1221
1314
|
}
|
|
1222
1315
|
|
|
@@ -1231,6 +1324,17 @@ function sendJson(res: http.ServerResponse, status: number, payload: unknown): v
|
|
|
1231
1324
|
send(res, status, JSON_TYPE, JSON.stringify(payload));
|
|
1232
1325
|
}
|
|
1233
1326
|
|
|
1327
|
+
/** Санитизирует сообщение об ошибке для клиентского ответа.
|
|
1328
|
+
* Подробности стека/пути/токенов не утекают наружу — пишем только в лог. */
|
|
1329
|
+
function sanitizeError(err: any): string {
|
|
1330
|
+
if (err instanceof Error) {
|
|
1331
|
+
const msg = err.message;
|
|
1332
|
+
// Убираем внутренние пути и стеки
|
|
1333
|
+
return msg.replace(/[A-Z]:\\/g, "").replace(/\\/g, "/").replace(/\s+at\s+/g, " ").slice(0, 300);
|
|
1334
|
+
}
|
|
1335
|
+
return String(err).slice(0, 300);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1234
1338
|
/** Отправляет ответ с телом и закрывает соединение. */
|
|
1235
1339
|
function send(res: http.ServerResponse, status: number, contentType: string, body: string): void {
|
|
1236
1340
|
res.writeHead(status, {
|
|
@@ -1861,6 +1965,16 @@ function renderPage(): string {
|
|
|
1861
1965
|
}
|
|
1862
1966
|
|
|
1863
1967
|
var t = an.totals;
|
|
1968
|
+
var savings = an.savings || null;
|
|
1969
|
+
var savingsChip = '';
|
|
1970
|
+
if (savings && savings.savedUsd > 0) {
|
|
1971
|
+
var savingsTip = 'Оценка: ' + Number(savings.runs) + ' запусков, ' +
|
|
1972
|
+
Number(savings.tokens || 0).toLocaleString('ru-RU') + ' токенов без записанной стоимости, ' +
|
|
1973
|
+
'по эталонной цене $' + Number(savings.referenceCostPer1kTokensUsd || 0) + ' за 1k токенов.';
|
|
1974
|
+
savingsChip = '<span title="' + esc(savingsTip) + '">Сэкономлено: <b>' +
|
|
1975
|
+
money(savings.savedUsd) + '</b> <span class="an-partial">оценка</span> <a href="' +
|
|
1976
|
+
esc(savings.methodologyUrl) + '" target="_blank" rel="noopener noreferrer">методика</a></span>';
|
|
1977
|
+
}
|
|
1864
1978
|
kpis.innerHTML =
|
|
1865
1979
|
'<span>Запусков: <b>' + t.total + '</b></span>' +
|
|
1866
1980
|
'<span>Успех: <b class="an-rate ' + rateClass(t.successRate) + '">' + t.successRate + '%</b>' +
|
|
@@ -1868,6 +1982,7 @@ function renderPage(): string {
|
|
|
1868
1982
|
'<span>Ср. длительность: <b>' + durationText(t.avgDurationMs) + '</b></span>' +
|
|
1869
1983
|
'<span>Токены: <b>' + Number(t.tokens || 0).toLocaleString('ru-RU') + '</b></span>' +
|
|
1870
1984
|
'<span>Стоимость: <b>' + money(t.costUsd) + '</b></span>' +
|
|
1985
|
+
savingsChip +
|
|
1871
1986
|
'<span>Окно: <b>' + an.windowDays + ' дн.</b></span>';
|
|
1872
1987
|
|
|
1873
1988
|
var daily = an.daily || [];
|
|
@@ -2229,7 +2344,7 @@ function renderPage(): string {
|
|
|
2229
2344
|
function taskRow(t, isClone, cloneCount, expanded) {
|
|
2230
2345
|
var sessionBadge = t.session === 'reuse' || t.session === 'last'
|
|
2231
2346
|
? '<span title="' + (t.session === 'reuse'
|
|
2232
|
-
? 'Переиспользуемая сессия OpenCode' + (t.sessionId ? ': ' + t.sessionId : '')
|
|
2347
|
+
? 'Переиспользуемая сессия OpenCode' + (t.sessionId ? ': ' + esc(t.sessionId) : '')
|
|
2233
2348
|
: 'Продолжение последней сессии OpenCode (--continue)') +
|
|
2234
2349
|
'" style="margin-left:6px;padding:1px 6px;border-radius:999px;border:1px solid #30d158;color:#30d158;font-size:11px">' +
|
|
2235
2350
|
(t.session === 'reuse' ? '⟳ сессия' : '↪ продолжение') + '</span>'
|
|
@@ -2278,6 +2393,10 @@ function renderPage(): string {
|
|
|
2278
2393
|
'</tr>';
|
|
2279
2394
|
}
|
|
2280
2395
|
|
|
2396
|
+
// Заголовок, подтверждающий, что запрос отправлен самим дашбордом.
|
|
2397
|
+
// Без него кросс-сайтовый fetch не пройдёт (нужен CORS-preflight, которого нет).
|
|
2398
|
+
var CLIENT_HEADERS = { 'X-Scheduler-Client': 'dashboard' };
|
|
2399
|
+
|
|
2281
2400
|
// Устойчивая загрузка: антивирусы иногда блокируют отдельные URL
|
|
2282
2401
|
// (например, /api/metrics) статусом 499 и картинкой вместо JSON.
|
|
2283
2402
|
// Один сбой не должен ломать весь дашборд.
|
|
@@ -2384,7 +2503,7 @@ function renderPage(): string {
|
|
|
2384
2503
|
if (act === 'cleanup-orphans') {
|
|
2385
2504
|
btn.disabled = true;
|
|
2386
2505
|
try {
|
|
2387
|
-
var cleanRes = await fetch('/api/matrix-cleanup', { method: 'POST', cache: 'no-store' });
|
|
2506
|
+
var cleanRes = await fetch('/api/matrix-cleanup', { method: 'POST', cache: 'no-store', headers: CLIENT_HEADERS });
|
|
2388
2507
|
var cleanData = await readJson(cleanRes);
|
|
2389
2508
|
toast(cleanData.success ? (cleanData.message || 'Готово') : (cleanData.error || 'Ошибка очистки'), cleanData.success ? 'ok2' : 'err2');
|
|
2390
2509
|
} catch (err) {
|
|
@@ -2431,7 +2550,7 @@ function renderPage(): string {
|
|
|
2431
2550
|
btn.disabled = false;
|
|
2432
2551
|
return;
|
|
2433
2552
|
}
|
|
2434
|
-
var res = await fetch(url, { method: 'POST', cache: 'no-store' });
|
|
2553
|
+
var res = await fetch(url, { method: 'POST', cache: 'no-store', headers: CLIENT_HEADERS });
|
|
2435
2554
|
var data = await readJson(res);
|
|
2436
2555
|
if (data.success) {
|
|
2437
2556
|
toast(data.message || 'Готово', 'ok2');
|