opencode-windows-scheduler 0.0.0-stage → 1.1.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.
Files changed (183) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/CROSS_PLATFORM.md +113 -0
  3. package/LICENSE +21 -0
  4. package/README.md +173 -2
  5. package/README.ru.md +131 -0
  6. package/ROADMAP-STRATEGY.md +217 -0
  7. package/ROADMAP.md +90 -0
  8. package/dist/core/analytics.d.ts +119 -0
  9. package/dist/core/analytics.d.ts.map +1 -0
  10. package/dist/core/analytics.js +265 -0
  11. package/dist/core/cron-to-schtasks.d.ts +20 -0
  12. package/dist/core/cron-to-schtasks.d.ts.map +1 -0
  13. package/dist/core/cron-to-schtasks.js +233 -0
  14. package/dist/core/dry-run.d.ts +44 -0
  15. package/dist/core/dry-run.d.ts.map +1 -0
  16. package/dist/core/dry-run.js +252 -0
  17. package/dist/core/file-watcher.d.ts +31 -0
  18. package/dist/core/file-watcher.d.ts.map +1 -0
  19. package/dist/core/file-watcher.js +128 -0
  20. package/dist/core/lock.d.ts +43 -0
  21. package/dist/core/lock.d.ts.map +1 -0
  22. package/dist/core/lock.js +118 -0
  23. package/dist/core/matrix.d.ts +167 -0
  24. package/dist/core/matrix.d.ts.map +1 -0
  25. package/dist/core/matrix.js +687 -0
  26. package/dist/core/ps-wrapper.d.ts +60 -0
  27. package/dist/core/ps-wrapper.d.ts.map +1 -0
  28. package/dist/core/ps-wrapper.js +538 -0
  29. package/dist/core/record-history.d.ts +14 -0
  30. package/dist/core/record-history.d.ts.map +1 -0
  31. package/dist/core/record-history.js +360 -0
  32. package/dist/core/retention.d.ts +29 -0
  33. package/dist/core/retention.d.ts.map +1 -0
  34. package/dist/core/retention.js +98 -0
  35. package/dist/core/scheduler/index.d.ts +20 -0
  36. package/dist/core/scheduler/index.d.ts.map +1 -0
  37. package/dist/core/scheduler/index.js +32 -0
  38. package/dist/core/scheduler/linux.d.ts +32 -0
  39. package/dist/core/scheduler/linux.d.ts.map +1 -0
  40. package/dist/core/scheduler/linux.js +115 -0
  41. package/dist/core/scheduler/logs.d.ts +11 -0
  42. package/dist/core/scheduler/logs.d.ts.map +1 -0
  43. package/dist/core/scheduler/logs.js +34 -0
  44. package/dist/core/scheduler/mac.d.ts +39 -0
  45. package/dist/core/scheduler/mac.d.ts.map +1 -0
  46. package/dist/core/scheduler/mac.js +175 -0
  47. package/dist/core/scheduler/posix.d.ts +40 -0
  48. package/dist/core/scheduler/posix.d.ts.map +1 -0
  49. package/dist/core/scheduler/posix.js +86 -0
  50. package/dist/core/scheduler/registry.d.ts +36 -0
  51. package/dist/core/scheduler/registry.d.ts.map +1 -0
  52. package/dist/core/scheduler/registry.js +56 -0
  53. package/dist/core/scheduler/types.d.ts +63 -0
  54. package/dist/core/scheduler/types.d.ts.map +1 -0
  55. package/dist/core/scheduler/types.js +1 -0
  56. package/dist/core/scheduler/windows.d.ts +47 -0
  57. package/dist/core/scheduler/windows.d.ts.map +1 -0
  58. package/dist/core/scheduler/windows.js +375 -0
  59. package/dist/core/wrappers/bash.d.ts +58 -0
  60. package/dist/core/wrappers/bash.d.ts.map +1 -0
  61. package/dist/core/wrappers/bash.js +223 -0
  62. package/dist/db/history-repo.d.ts +102 -0
  63. package/dist/db/history-repo.d.ts.map +1 -0
  64. package/dist/db/history-repo.js +215 -0
  65. package/dist/db/index.d.ts +47 -0
  66. package/dist/db/index.d.ts.map +1 -0
  67. package/dist/db/index.js +120 -0
  68. package/dist/db/metrics-repo.d.ts +43 -0
  69. package/dist/db/metrics-repo.d.ts.map +1 -0
  70. package/dist/db/metrics-repo.js +95 -0
  71. package/dist/db/migrate.d.ts +24 -0
  72. package/dist/db/migrate.d.ts.map +1 -0
  73. package/dist/db/migrate.js +237 -0
  74. package/dist/db/recovery.d.ts +11 -0
  75. package/dist/db/recovery.d.ts.map +1 -0
  76. package/dist/db/recovery.js +38 -0
  77. package/dist/db/schema.d.ts +24 -0
  78. package/dist/db/schema.d.ts.map +1 -0
  79. package/dist/db/schema.js +97 -0
  80. package/dist/db/settings-repo.d.ts +8 -0
  81. package/dist/db/settings-repo.d.ts.map +1 -0
  82. package/dist/db/settings-repo.js +27 -0
  83. package/dist/db/tasks-repo.d.ts +26 -0
  84. package/dist/db/tasks-repo.d.ts.map +1 -0
  85. package/dist/db/tasks-repo.js +120 -0
  86. package/dist/db/templates-repo.d.ts +17 -0
  87. package/dist/db/templates-repo.d.ts.map +1 -0
  88. package/dist/db/templates-repo.js +57 -0
  89. package/dist/history.d.ts +53 -0
  90. package/dist/history.d.ts.map +1 -0
  91. package/dist/history.js +57 -0
  92. package/dist/index.d.ts +156 -0
  93. package/dist/index.d.ts.map +1 -0
  94. package/dist/index.js +2159 -0
  95. package/dist/notifications.d.ts +45 -0
  96. package/dist/notifications.d.ts.map +1 -0
  97. package/dist/notifications.js +135 -0
  98. package/dist/rpc.d.ts +2186 -0
  99. package/dist/rpc.d.ts.map +1 -0
  100. package/dist/rpc.js +924 -0
  101. package/dist/schtasks.d.ts +32 -0
  102. package/dist/schtasks.d.ts.map +1 -0
  103. package/dist/schtasks.js +45 -0
  104. package/dist/server.d.ts +106 -0
  105. package/dist/server.d.ts.map +1 -0
  106. package/dist/server.js +1668 -0
  107. package/dist/settings.d.ts +66 -0
  108. package/dist/settings.d.ts.map +1 -0
  109. package/dist/settings.js +137 -0
  110. package/dist/shared/jobs-view.d.ts +21 -0
  111. package/dist/shared/jobs-view.d.ts.map +1 -0
  112. package/dist/shared/jobs-view.js +28 -0
  113. package/dist/skill.d.ts +15 -0
  114. package/dist/skill.d.ts.map +1 -0
  115. package/dist/skill.js +93 -0
  116. package/dist/task-transfer.d.ts +176 -0
  117. package/dist/task-transfer.d.ts.map +1 -0
  118. package/dist/task-transfer.js +442 -0
  119. package/dist/templates.d.ts +57 -0
  120. package/dist/templates.d.ts.map +1 -0
  121. package/dist/templates.js +16 -0
  122. package/dist/types.d.ts +78 -0
  123. package/dist/types.d.ts.map +1 -0
  124. package/dist/types.js +88 -0
  125. package/dist/version.d.ts +8 -0
  126. package/dist/version.d.ts.map +1 -0
  127. package/dist/version.js +27 -0
  128. package/dist/workspaces.d.ts +55 -0
  129. package/dist/workspaces.d.ts.map +1 -0
  130. package/dist/workspaces.js +183 -0
  131. package/docs/ARCHITECTURE.md +314 -0
  132. package/docs/FEATURES.md +300 -0
  133. package/docs/MIGRATION.md +266 -0
  134. package/docs/dashboard.png +0 -0
  135. package/gui-experimental.cjs +2 -0
  136. package/index.js +1 -0
  137. package/package.json +94 -4
  138. package/scripts/demo-dashboard.mjs +199 -0
  139. package/skills/scheduled-job-best-practices/SKILL.md +155 -0
  140. package/skills/scheduled-job-best-practices/references/recipes.md +123 -0
  141. package/src/core/analytics.ts +378 -0
  142. package/src/core/cron-to-schtasks.ts +269 -0
  143. package/src/core/dry-run.ts +315 -0
  144. package/src/core/file-watcher.ts +171 -0
  145. package/src/core/lock.ts +134 -0
  146. package/src/core/matrix.ts +907 -0
  147. package/src/core/ps-wrapper.ts +572 -0
  148. package/src/core/record-history.ts +493 -0
  149. package/src/core/retention.ts +141 -0
  150. package/src/core/scheduler/index.ts +44 -0
  151. package/src/core/scheduler/linux.ts +125 -0
  152. package/src/core/scheduler/logs.ts +37 -0
  153. package/src/core/scheduler/mac.ts +222 -0
  154. package/src/core/scheduler/posix.ts +111 -0
  155. package/src/core/scheduler/registry.ts +93 -0
  156. package/src/core/scheduler/types.ts +67 -0
  157. package/src/core/scheduler/windows.ts +469 -0
  158. package/src/core/wrappers/bash.ts +282 -0
  159. package/src/db/history-repo.ts +396 -0
  160. package/src/db/index.ts +166 -0
  161. package/src/db/metrics-repo.ts +158 -0
  162. package/src/db/migrate.ts +322 -0
  163. package/src/db/recovery.ts +46 -0
  164. package/src/db/schema.ts +109 -0
  165. package/src/db/settings-repo.ts +31 -0
  166. package/src/db/tasks-repo.ts +162 -0
  167. package/src/db/templates-repo.ts +77 -0
  168. package/src/gui.tsx +2868 -0
  169. package/src/history.ts +107 -0
  170. package/src/index.ts +2768 -0
  171. package/src/notifications.ts +174 -0
  172. package/src/rpc.ts +999 -0
  173. package/src/schtasks.ts +75 -0
  174. package/src/server.ts +1879 -0
  175. package/src/settings.ts +228 -0
  176. package/src/shared/jobs-view.ts +38 -0
  177. package/src/skill.ts +113 -0
  178. package/src/task-transfer.ts +648 -0
  179. package/src/templates.ts +67 -0
  180. package/src/tui.tsx +46 -0
  181. package/src/types.ts +145 -0
  182. package/src/version.ts +27 -0
  183. package/src/workspaces.ts +236 -0
@@ -0,0 +1,45 @@
1
+ /** Статус завершения задачи, который приходит из record-history. */
2
+ export type NotificationStatus = "success" | "error" | "timeout" | string;
3
+ /** Содержимое уведомления. */
4
+ export interface NotificationPayload {
5
+ taskName: string;
6
+ status: NotificationStatus;
7
+ durationMs: number;
8
+ error?: string | null;
9
+ }
10
+ /** Человекочитаемая длительность: 2300 мс → «2.3s». */
11
+ export declare function formatDuration(durationMs: number): string;
12
+ /**
13
+ * Формат сообщения:
14
+ * ✅ Задача "Тест" выполнена (2.3s)
15
+ * ❌ Задача "Тест" упала (2.3s): Quality Gate провален
16
+ */
17
+ export declare function formatNotificationMessage(payload: NotificationPayload): string;
18
+ /**
19
+ * Отправляет POST на webhook.
20
+ *
21
+ * Тело совместимо одновременно с Discord (`content`) и Slack (`text`).
22
+ * Бросает исключение только для диагностики — вызывающий код обязан
23
+ * перехватить его, чтобы уведомление не ломало задачу.
24
+ */
25
+ export declare function sendWebhook(url: string, message: string): Promise<void>;
26
+ /**
27
+ * Уведомляет о завершении задачи во все включённые каналы.
28
+ *
29
+ * Правила:
30
+ * - `notifications.enabled === false` — ничего не делает;
31
+ * - `onlyOnError === true` — успешные запуски пропускаются;
32
+ * - ошибки отправки только логируются, наружу не выбрасываются.
33
+ */
34
+ export declare function notifyTaskCompletion(taskName: string, status: NotificationStatus, durationMs: number, error?: string | null): Promise<void>;
35
+ /**
36
+ * Отправляет тестовое сообщение в webhook (кнопка «🧪 Тестовое уведомление»).
37
+ *
38
+ * В отличие от notifyTaskCompletion, результат возвращается пользователю:
39
+ * при тесте важно увидеть причину ошибки.
40
+ */
41
+ export declare function sendTestNotification(): Promise<{
42
+ success: boolean;
43
+ message: string;
44
+ }>;
45
+ //# sourceMappingURL=notifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../src/notifications.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1E,8BAA8B;AAC9B,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAKD,uDAAuD;AACvD,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAU9E;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwC7E;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,kBAAkB,EAC1B,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CA0BD"}
@@ -0,0 +1,135 @@
1
+ import { loadSettings } from "./settings.js";
2
+ /** Таймаут HTTP-запроса: уведомление не должно подвешивать обёртку задачи. */
3
+ const REQUEST_TIMEOUT_MS = 10000;
4
+ /** Человекочитаемая длительность: 2300 мс → «2.3s». */
5
+ export function formatDuration(durationMs) {
6
+ const seconds = Math.max(0, Number(durationMs) || 0) / 1000;
7
+ return `${seconds.toFixed(1)}s`;
8
+ }
9
+ /**
10
+ * Формат сообщения:
11
+ * ✅ Задача "Тест" выполнена (2.3s)
12
+ * ❌ Задача "Тест" упала (2.3s): Quality Gate провален
13
+ */
14
+ export function formatNotificationMessage(payload) {
15
+ const { taskName, status, durationMs, error } = payload;
16
+ const duration = formatDuration(durationMs);
17
+ if (status === "success") {
18
+ return `✅ Задача "${taskName}" выполнена (${duration})`;
19
+ }
20
+ const reason = typeof error === "string" && error.trim() ? `: ${error.trim()}` : "";
21
+ return `❌ Задача "${taskName}" упала (${duration})${reason}`;
22
+ }
23
+ /**
24
+ * Отправляет POST на webhook.
25
+ *
26
+ * Тело совместимо одновременно с Discord (`content`) и Slack (`text`).
27
+ * Бросает исключение только для диагностики — вызывающий код обязан
28
+ * перехватить его, чтобы уведомление не ломало задачу.
29
+ */
30
+ export async function sendWebhook(url, message) {
31
+ const trimmed = (url ?? "").trim();
32
+ if (!trimmed) {
33
+ throw new Error("URL вебхука не задан.");
34
+ }
35
+ let parsed;
36
+ try {
37
+ parsed = new URL(trimmed);
38
+ }
39
+ catch {
40
+ throw new Error("Некорректный URL вебхука.");
41
+ }
42
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
43
+ throw new Error("Вебхук поддерживает только http:// или https://.");
44
+ }
45
+ const controller = new AbortController();
46
+ const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
47
+ try {
48
+ const response = await fetch(parsed, {
49
+ method: "POST",
50
+ headers: { "Content-Type": "application/json" },
51
+ body: JSON.stringify({ content: message, text: message }),
52
+ signal: controller.signal,
53
+ });
54
+ if (!response.ok) {
55
+ const body = await response.text().catch(() => "");
56
+ throw new Error(`HTTP ${response.status}${body ? `: ${body.slice(0, 200)}` : ""}`);
57
+ }
58
+ }
59
+ catch (err) {
60
+ if (err?.name === "AbortError") {
61
+ throw new Error(`Таймаут запроса (${REQUEST_TIMEOUT_MS / 1000} с).`);
62
+ }
63
+ throw err instanceof Error ? err : new Error(String(err));
64
+ }
65
+ finally {
66
+ clearTimeout(timer);
67
+ }
68
+ }
69
+ /**
70
+ * Уведомляет о завершении задачи во все включённые каналы.
71
+ *
72
+ * Правила:
73
+ * - `notifications.enabled === false` — ничего не делает;
74
+ * - `onlyOnError === true` — успешные запуски пропускаются;
75
+ * - ошибки отправки только логируются, наружу не выбрасываются.
76
+ */
77
+ export async function notifyTaskCompletion(taskName, status, durationMs, error) {
78
+ try {
79
+ const settings = await loadSettings();
80
+ const config = settings.notifications;
81
+ if (!config?.enabled)
82
+ return;
83
+ if (config.onlyOnError && status === "success")
84
+ return;
85
+ const message = formatNotificationMessage({
86
+ taskName,
87
+ status,
88
+ durationMs,
89
+ error,
90
+ });
91
+ const webhook = config.webhook;
92
+ if (webhook?.enabled && webhook.url.trim()) {
93
+ try {
94
+ await sendWebhook(webhook.url, message);
95
+ console.log(`[windows-scheduler] Уведомление отправлено в webhook: ${message}`);
96
+ }
97
+ catch (err) {
98
+ console.error(`[windows-scheduler] Не удалось отправить webhook-уведомление: ${err instanceof Error ? err.message : String(err)}`);
99
+ }
100
+ }
101
+ }
102
+ catch (err) {
103
+ // Уведомление не должно ломать запись истории и саму задачу.
104
+ console.error(`[windows-scheduler] Ошибка подготовки уведомления: ${err instanceof Error ? err.message : String(err)}`);
105
+ }
106
+ }
107
+ /**
108
+ * Отправляет тестовое сообщение в webhook (кнопка «🧪 Тестовое уведомление»).
109
+ *
110
+ * В отличие от notifyTaskCompletion, результат возвращается пользователю:
111
+ * при тесте важно увидеть причину ошибки.
112
+ */
113
+ export async function sendTestNotification() {
114
+ try {
115
+ const settings = await loadSettings();
116
+ const webhook = settings.notifications?.webhook;
117
+ if (!webhook?.enabled) {
118
+ return {
119
+ success: false,
120
+ message: "Webhook выключен. Включите канал и укажите URL.",
121
+ };
122
+ }
123
+ if (!webhook.url.trim()) {
124
+ return { success: false, message: "Не задан URL вебхука." };
125
+ }
126
+ await sendWebhook(webhook.url, "🧪 Тестовое уведомление от OpenCode Scheduler — webhook настроен корректно.");
127
+ return { success: true, message: "Тестовое уведомление отправлено." };
128
+ }
129
+ catch (err) {
130
+ return {
131
+ success: false,
132
+ message: err instanceof Error ? err.message : String(err),
133
+ };
134
+ }
135
+ }