opencode-windows-scheduler 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +61 -1
  2. package/LICENSE +21 -21
  3. package/README.md +26 -4
  4. package/ROADMAP-STRATEGY.md +43 -24
  5. package/ROADMAP.md +549 -31
  6. package/dist/core/dry-run.d.ts +41 -0
  7. package/dist/core/dry-run.d.ts.map +1 -1
  8. package/dist/core/dry-run.js +165 -16
  9. package/dist/core/file-watcher.d.ts.map +1 -1
  10. package/dist/core/file-watcher.js +53 -10
  11. package/dist/core/git-trigger.d.ts +80 -0
  12. package/dist/core/git-trigger.d.ts.map +1 -0
  13. package/dist/core/git-trigger.js +294 -0
  14. package/dist/core/glob.d.ts +38 -0
  15. package/dist/core/glob.d.ts.map +1 -0
  16. package/dist/core/glob.js +233 -0
  17. package/dist/core/matrix.d.ts.map +1 -1
  18. package/dist/core/matrix.js +48 -22
  19. package/dist/core/ps-wrapper.d.ts.map +1 -1
  20. package/dist/core/ps-wrapper.js +7 -0
  21. package/dist/core/schedule-gate.js +55 -30
  22. package/dist/core/schedule-v2.d.ts +29 -1
  23. package/dist/core/schedule-v2.d.ts.map +1 -1
  24. package/dist/core/schedule-v2.js +107 -17
  25. package/dist/core/scheduler/types.d.ts +7 -1
  26. package/dist/core/scheduler/types.d.ts.map +1 -1
  27. package/dist/core/scheduler/windows.d.ts +6 -2
  28. package/dist/core/scheduler/windows.d.ts.map +1 -1
  29. package/dist/core/scheduler/windows.js +25 -10
  30. package/dist/core/telegram.d.ts.map +1 -1
  31. package/dist/core/telegram.js +13 -10
  32. package/dist/core/wrappers/bash.d.ts.map +1 -1
  33. package/dist/core/wrappers/bash.js +4 -0
  34. package/dist/db/git-state-repo.d.ts +16 -0
  35. package/dist/db/git-state-repo.d.ts.map +1 -0
  36. package/dist/db/git-state-repo.js +38 -0
  37. package/dist/db/schema.d.ts +1 -1
  38. package/dist/db/schema.d.ts.map +1 -1
  39. package/dist/db/schema.js +8 -0
  40. package/dist/i18n.d.ts +52 -0
  41. package/dist/i18n.d.ts.map +1 -0
  42. package/dist/i18n.js +292 -0
  43. package/dist/index.d.ts +50 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1020 -197
  46. package/dist/notifications.d.ts.map +1 -1
  47. package/dist/notifications.js +74 -40
  48. package/dist/rpc.d.ts +238 -2
  49. package/dist/rpc.d.ts.map +1 -1
  50. package/dist/rpc.js +79 -2
  51. package/dist/server.d.ts.map +1 -1
  52. package/dist/server.js +89 -48
  53. package/dist/settings.d.ts +3 -0
  54. package/dist/settings.d.ts.map +1 -1
  55. package/dist/settings.js +20 -8
  56. package/dist/task-transfer.d.ts +43 -3
  57. package/dist/task-transfer.d.ts.map +1 -1
  58. package/dist/task-transfer.js +94 -6
  59. package/dist/templates.d.ts +1 -1
  60. package/dist/templates.d.ts.map +1 -1
  61. package/dist/types.d.ts +11 -0
  62. package/dist/types.d.ts.map +1 -1
  63. package/dist/types.js +32 -0
  64. package/docs/ARCHITECTURE.md +37 -1
  65. package/docs/FEATURES.md +70 -0
  66. package/docs/README.ru.md +19 -3
  67. package/gui-experimental.cjs +9 -4
  68. package/locales/en.json +695 -0
  69. package/locales/ru.json +695 -0
  70. package/package.json +9 -3
  71. package/scripts/test-locale.mjs +44 -0
  72. package/src/core/dry-run.ts +244 -19
  73. package/src/core/file-watcher.ts +65 -10
  74. package/src/core/git-trigger.ts +373 -0
  75. package/src/core/glob.ts +226 -0
  76. package/src/core/matrix.ts +52 -26
  77. package/src/core/ps-wrapper.ts +7 -0
  78. package/src/core/schedule-gate.ts +67 -33
  79. package/src/core/schedule-v2.ts +152 -17
  80. package/src/core/scheduler/types.ts +7 -1
  81. package/src/core/scheduler/windows.ts +25 -10
  82. package/src/core/telegram.ts +16 -10
  83. package/src/core/wrappers/bash.ts +4 -0
  84. package/src/db/git-state-repo.ts +62 -0
  85. package/src/db/schema.ts +8 -0
  86. package/src/gui.tsx +772 -456
  87. package/src/i18n.ts +339 -0
  88. package/src/index.ts +1274 -212
  89. package/src/notifications.ts +83 -42
  90. package/src/rpc.ts +79 -2
  91. package/src/server.ts +89 -48
  92. package/src/settings.ts +38 -10
  93. package/src/task-transfer.ts +148 -5
  94. package/src/templates.ts +1 -1
  95. package/src/types.ts +37 -0
package/src/server.ts CHANGED
@@ -22,6 +22,7 @@ import { appendStructuredLog, readStructuredLogs } from "./core/structured-log.j
22
22
  import { PROMETHEUS_CONTENT_TYPE, renderPrometheusMetrics } from "./core/prometheus.js";
23
23
  import { buildOtlpExport } from "./core/otel.js";
24
24
  import { readAuditLog, recordAudit } from "./core/audit.js";
25
+ import { getLocale, t } from "./i18n.js";
25
26
 
26
27
  /**
27
28
  * Локальный веб-дашборд (Спринт 5).
@@ -629,14 +630,14 @@ async function handleRequest(
629
630
  /^\/api\/dry-run\//.test(pathname) ||
630
631
  /^\/api\/matrix\//.test(pathname);
631
632
  if (knownGet && req.method !== "GET") {
632
- sendJson(res, 405, { error: "Method not allowed" });
633
+ sendJson(res, 405, { error: t("server.methodNotAllowed") });
633
634
  return;
634
635
  }
635
636
  const knownPost =
636
637
  /^\/api\/(run|delete|hooks|cancel-matrix)\//.test(pathname) ||
637
638
  pathname === "/api/matrix-cleanup";
638
639
  if (knownPost && req.method !== "POST") {
639
- sendJson(res, 405, { error: "Method not allowed" });
640
+ sendJson(res, 405, { error: t("server.methodNotAllowed") });
640
641
  return;
641
642
  }
642
643
 
@@ -737,7 +738,7 @@ async function handleRequest(
737
738
  const key = parentId.toLowerCase();
738
739
  const parent = tasks.find((t) => String(t.name).toLowerCase() === key);
739
740
  if (!parent) {
740
- sendJson(res, 404, { error: `Матрица "${parentId}" не найдена.` });
741
+ sendJson(res, 404, { error: t("server.matrixNotFound", { parentId }) });
741
742
  return;
742
743
  }
743
744
  const clones = tasks
@@ -1034,8 +1035,11 @@ async function handleRequest(
1034
1035
  const key = taskName.toLowerCase();
1035
1036
  const task = tasks.find((item) => String(item.name).toLowerCase() === key);
1036
1037
  if (!task) {
1037
- logHook(404, "rejected", `Задача "${taskName}" не найдена.`, bodyResult.body.length);
1038
- sendJson(res, 404, { success: false, error: `Задача "${taskName}" не найдена.` });
1038
+ logHook(404, "rejected", t("server.hookTaskMissing", { task: taskName }), bodyResult.body.length);
1039
+ sendJson(res, 404, {
1040
+ success: false,
1041
+ error: t("server.taskNotFound", { task: taskName }),
1042
+ });
1039
1043
  return;
1040
1044
  }
1041
1045
 
@@ -1204,7 +1208,7 @@ async function handleRequest(
1204
1208
 
1205
1209
  // Любой неизвестный путь — строго JSON, чтобы клиент не пытался
1206
1210
  // разобрать HTML/картинку как JSON.
1207
- sendJson(res, 404, { error: "Not found" });
1211
+ sendJson(res, 404, { error: t("server.notFound") });
1208
1212
  } catch (err: any) {
1209
1213
  const message = err instanceof Error ? err.message : String(err);
1210
1214
  console.error(`[windows-scheduler] Ошибка обработки запроса ${req.url}: ${message}`);
@@ -1321,11 +1325,11 @@ async function collectTasksWithMetrics(deps: DashboardDeps) {
1321
1325
  */
1322
1326
  function renderPage(): string {
1323
1327
  return `<!DOCTYPE html>
1324
- <html lang="ru">
1328
+ <html lang="${getLocale()}">
1325
1329
  <head>
1326
1330
  <meta charset="utf-8">
1327
1331
  <meta name="viewport" content="width=device-width, initial-scale=1">
1328
- <title>${getSchedulerTitle()} — Веб-дашборд</title>
1332
+ <title>${getSchedulerTitle()} — ${t("app.dashboardTitle")}</title>
1329
1333
  <style>
1330
1334
  :root {
1331
1335
  color-scheme: dark;
@@ -1351,22 +1355,46 @@ function renderPage(): string {
1351
1355
  100% { transform: translateY(110vh) rotate(360deg); }
1352
1356
  }
1353
1357
  .wrap { position: relative; z-index: 1; max-width: 1740px; margin: 0 auto; padding: 28px 20px 60px; }
1354
- .table-scroll { overflow-x: auto; }
1355
- /* Подсказка о горизонтальном скролле: на широких экранах таблица влезает целиком. */
1356
- .scroll-hint { display: none; margin-top: 6px; font-size: 11px; color: var(--muted); }
1357
- @media (max-width: 1000px) { .scroll-hint { display: block; } }
1358
+ .table-scroll {
1359
+ overflow-x: auto;
1360
+ border: 1px solid var(--border);
1361
+ border-radius: 10px;
1362
+ scrollbar-width: thin;
1363
+ scrollbar-color: var(--border) transparent;
1364
+ }
1365
+ /* Полоса прокрутки всегда видна (в overlay-режиме её не замечают):
1366
+ подсказываем, что справа есть ещё колонки. */
1367
+ .table-scroll::-webkit-scrollbar { height: 10px; }
1368
+ .table-scroll::-webkit-scrollbar-track { background: transparent; }
1369
+ .table-scroll::-webkit-scrollbar-thumb {
1370
+ background: var(--border);
1371
+ border-radius: 6px;
1372
+ }
1373
+ .table-scroll::-webkit-scrollbar-thumb:hover { background: var(--muted); }
1374
+ /* Рамку и скругление держит контейнер: overflow:hidden на самой таблице
1375
+ ломает position:sticky у первой колонки. */
1376
+ /* Первая колонка (имя задачи) закреплена: при горизонтальной прокрутке
1377
+ видно, к какой задаче относятся остальные ячейки. */
1378
+ .table-scroll thead th:first-child,
1379
+ .table-scroll tbody td:first-child {
1380
+ position: sticky; left: 0; z-index: 2;
1381
+ background: var(--panel);
1382
+ box-shadow: 1px 0 0 var(--border);
1383
+ }
1384
+ .table-scroll thead th:first-child { background: var(--panel2); z-index: 3; }
1385
+ /* Подсказка о горизонтальном скролле: скрываем только на очень широких экранах. */
1386
+ .scroll-hint { margin-top: 6px; font-size: 11px; color: var(--muted); }
1387
+ @media (min-width: 1320px) { .scroll-hint { display: none; } }
1358
1388
  header { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
1359
1389
  h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: .2px; }
1360
1390
  .sub { margin-top: 5px; font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
1361
- .cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 22px; }
1362
- @media (min-width: 900px) { .cards { grid-template-columns: repeat(4, 1fr); } }
1363
- @media (min-width: 1200px) { .cards { grid-template-columns: repeat(7, 1fr); } }
1364
- @media (max-width: 520px) { .cards { grid-template-columns: repeat(2, 1fr); } }
1391
+ /* auto-fill: карточки одинаковой ширины, последний ряд не растягивается. */
1392
+ .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
1365
1393
  .card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
1366
1394
  .card .num { font-size: 26px; font-weight: 800; }
1367
1395
  .card .lbl { margin-top: 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
1368
1396
  .ok { color: var(--ok); } .err { color: var(--err); } .neu { color: var(--accent); } .run { color: var(--run); }
1369
- table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
1397
+ table { width: 100%; border-collapse: collapse; background: var(--panel); }
1370
1398
  th, td { padding: 9px 9px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
1371
1399
  th { background: var(--panel2); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }
1372
1400
  tr:last-child td { border-bottom: none; }
@@ -1396,18 +1424,23 @@ function renderPage(): string {
1396
1424
  .an-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
1397
1425
  .an-actions { display: flex; gap: 6px; }
1398
1426
  .an-actions .btn { padding: 3px 8px; font-size: 11px; }
1399
- .an-kpis { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
1427
+ .an-kpis { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
1400
1428
  .an-kpis b { color: var(--text); font-size: 14px; }
1401
- .an-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 6px 0 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
1429
+ .an-partial { font-size: 11px; color: var(--muted); }
1430
+ .an-chart { display: flex; align-items: flex-end; gap: 4px; height: 132px; padding: 6px 0 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
1402
1431
  /* min-width: подпись даты "MM-DD" не наезжает на соседнюю; на узком экране график скроллится. */
1403
1432
  .an-bar { flex: 1 1 0; min-width: 34px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; cursor: default; }
1404
1433
  .an-bar-fill { width: 100%; border-radius: 3px 3px 0 0; background: var(--accent); opacity: .85; }
1434
+ /* Значение над столбцом: график читается без наведения на tooltip. */
1435
+ .an-value { font-size: 9px; line-height: 1; color: var(--muted); margin-bottom: 2px; min-height: 9px; }
1405
1436
  .an-label { font-size: 9px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
1406
- .an-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 14px; }
1437
+ .an-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; margin-top: 14px; }
1407
1438
  .an-grid h3 { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
1408
- .an-table { width: 100%; border-collapse: collapse; font-size: 12px; }
1439
+ /* table-layout: fixed + ellipsis: длинные имена не рвутся посреди слова. */
1440
+ .an-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
1409
1441
  .an-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 3px 6px; border-bottom: 1px solid var(--border); }
1410
1442
  .an-table td { padding: 3px 6px; border-bottom: 1px solid var(--border); color: var(--text); }
1443
+ .an-table td:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1411
1444
  .an-table tr:last-child td { border-bottom: none; }
1412
1445
  .an-rate.okr { color: var(--ok); }
1413
1446
  .an-rate.midr { color: var(--run); }
@@ -1431,9 +1464,9 @@ function renderPage(): string {
1431
1464
  .graph-hint { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
1432
1465
  .graph-scroll { overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }
1433
1466
  .graph-canvas { position: relative; }
1434
- .graph-node { position: absolute; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 9px; background: var(--bg2); border: 1px solid var(--border); border-left: 3px solid var(--muted); border-radius: 8px; font-size: 12px; }
1435
- .graph-node .g-name { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1436
- .graph-node .g-meta { color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
1467
+ .graph-node { position: absolute; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 9px; background: var(--bg2); border: 1px solid var(--border); border-left: 3px solid var(--muted); border-radius: 8px; font-size: 12px; overflow: hidden; }
1468
+ .graph-node .g-name { max-width: 100%; color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1469
+ .graph-node .g-meta { max-width: 100%; color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
1437
1470
  .graph-node.okg { border-left-color: #3fb950; }
1438
1471
  .graph-node.errg { border-left-color: #ff3b30; }
1439
1472
  .graph-node.partg { border-left-color: #f5a623; }
@@ -1558,7 +1591,7 @@ function renderPage(): string {
1558
1591
  </div>
1559
1592
  </div>
1560
1593
  <div class="an-kpis" id="an-kpis"><span>Загрузка…</span></div>
1561
- <div class="an-chart" id="an-chart"></div>
1594
+ <div class="an-chart" id="an-chart" role="img" aria-label="Количество запусков по дням за период"></div>
1562
1595
  <div class="an-grid">
1563
1596
  <div><h3>Топ задач по стоимости</h3><div id="an-top"></div></div>
1564
1597
  <div><h3>Матрицы</h3><div id="an-matrices"></div></div>
@@ -1712,8 +1745,8 @@ function renderPage(): string {
1712
1745
  : 'var(--run)';
1713
1746
  return '<div class="matrix-badge" style="color:' + color + '" title="' + esc(s.message) + '">' +
1714
1747
  '📦 Matrix: ' + s.successCount + '/' + s.totalCount + ' успешных' +
1715
- (s.errorCount ? ' · ❌ ' + s.errorCount : '') +
1716
- (s.pendingCount ? ' · ⏳ ' + s.pendingCount : '') +
1748
+ (s.errorCount ? ' · ❌ ошибок: ' + s.errorCount : '') +
1749
+ (s.pendingCount ? ' · ⏳ в работе: ' + s.pendingCount : '') +
1717
1750
  '</div>';
1718
1751
  }
1719
1752
 
@@ -1766,7 +1799,7 @@ function renderPage(): string {
1766
1799
  '<span class="hist-time">' + esc(new Date(r.startedAt).toLocaleString('ru-RU')) + '</span>' +
1767
1800
  '<span class="hist-task">' + esc(r.taskName) + '</span>' +
1768
1801
  badge(r.status, null, true) +
1769
- '<span class="metrics">' + (r.durationMs != null ? r.durationMs + ' мс' : '—') + '</span>' +
1802
+ '<span class="metrics">' + durationText(r.durationMs) + '</span>' +
1770
1803
  (r.model ? '<span class="hist-model" title="Модель">🧠 ' + esc(r.model) + '</span>' : '') +
1771
1804
  (r.preFlightStatus && r.preFlightStatus !== 'skipped'
1772
1805
  ? '<span class="hist-hook ' + (r.preFlightStatus === 'success' ? 'okh' : 'errh') + '" title="Pre-flight: ' + esc(r.preFlightStatus) + '">⚡ pre: ' + (r.preFlightStatus === 'success' ? '✅' : '❌') + '</span>'
@@ -1795,15 +1828,21 @@ function renderPage(): string {
1795
1828
 
1796
1829
  function money(value) {
1797
1830
  var n = Number(value) || 0;
1798
- return '$' + n.toFixed(n >= 1 ? 2 : 4);
1831
+ return '$' + n.toFixed(n >= 0.01 ? 2 : 4);
1799
1832
  }
1800
1833
 
1801
1834
  function durationText(ms) {
1802
1835
  var n = Number(ms) || 0;
1803
1836
  if (n <= 0) return '—';
1804
- if (n < 1000) return n + ' мс';
1805
- if (n < 60000) return (n / 1000).toFixed(1) + ' с';
1806
- return Math.round(n / 60000) + ' мин';
1837
+ if (n < 1000) return Math.round(n) + ' мс';
1838
+ if (n < 60000) {
1839
+ // 46.0 с → «46 с», но 31.5 с остаётся «31.5 с».
1840
+ return (n / 1000).toFixed(1).replace(/\.0$/, '') + ' с';
1841
+ }
1842
+ var minutes = n / 60000;
1843
+ // До 10 минут показываем десятые (76125 мс → 1.3 мин), дальше — целые.
1844
+ if (minutes < 10) return minutes.toFixed(1).replace(/\.0$/, '') + ' мин';
1845
+ return Math.round(minutes) + ' мин';
1807
1846
  }
1808
1847
 
1809
1848
  function renderAnalytics(an) {
@@ -1824,12 +1863,12 @@ function renderPage(): string {
1824
1863
  var t = an.totals;
1825
1864
  kpis.innerHTML =
1826
1865
  '<span>Запусков: <b>' + t.total + '</b></span>' +
1827
- '<span>Успех: <b class="an-rate ' + rateClass(t.successRate) + '">' + t.successRate + '%</b></span>' +
1828
- '<span>Средняя длительность: <b>' + durationText(t.avgDurationMs) + '</b></span>' +
1866
+ '<span>Успех: <b class="an-rate ' + rateClass(t.successRate) + '">' + t.successRate + '%</b>' +
1867
+ (t.partial ? ' <span class="an-partial">· частично: ' + t.partial + '</span>' : '') + '</span>' +
1868
+ '<span>Ср. длительность: <b>' + durationText(t.avgDurationMs) + '</b></span>' +
1829
1869
  '<span>Токены: <b>' + Number(t.tokens || 0).toLocaleString('ru-RU') + '</b></span>' +
1830
1870
  '<span>Стоимость: <b>' + money(t.costUsd) + '</b></span>' +
1831
- '<span>Окно: <b>' + an.windowDays + ' дн.</b></span>' +
1832
- (t.partial ? '<span>Частично: <b>' + t.partial + '</b></span>' : '');
1871
+ '<span>Окно: <b>' + an.windowDays + ' дн.</b></span>';
1833
1872
 
1834
1873
  var daily = an.daily || [];
1835
1874
  var max = 1;
@@ -1839,11 +1878,13 @@ function renderPage(): string {
1839
1878
  var bars = '';
1840
1879
  for (var j = 0; j < daily.length; j++) {
1841
1880
  var d = daily[j];
1842
- var h = d.total > 0 ? Math.max(3, Math.round((d.total / max) * 92)) : 2;
1881
+ // 78% — оставляем место под значение и подпись даты внутри 132px.
1882
+ var h = d.total > 0 ? Math.max(3, Math.round((d.total / max) * 78)) : 2;
1843
1883
  var isPartialOnly = d.error === 0 && d.partial > 0;
1844
1884
  var color = d.total === 0 ? 'var(--border)' : (d.error > 0 ? 'var(--err)' : (isPartialOnly ? 'var(--run)' : 'var(--ok)'));
1845
1885
  var tip = d.date + ': всего ' + d.total + ', успех ' + d.success + ', ошибок ' + d.error + ', частично ' + d.partial + ', ' + money(d.costUsd);
1846
1886
  bars += '<div class="an-bar" title="' + esc(tip) + '">' +
1887
+ '<div class="an-value">' + (d.total > 0 ? d.total : '') + '</div>' +
1847
1888
  '<div class="an-bar-fill" style="height:' + h + '%' + ';background:' + esc(color) + '"></div>' +
1848
1889
  '<div class="an-label">' + esc(String(d.date).slice(5)) + '</div>' +
1849
1890
  '</div>';
@@ -1857,11 +1898,11 @@ function renderPage(): string {
1857
1898
  if (topRows.length === 0) {
1858
1899
  top.innerHTML = '<div class="empty" style="padding:10px">Нет запусков за период.</div>';
1859
1900
  } else {
1860
- var html = '<table class="an-table"><thead><tr><th scope="col">Задача</th><th scope="col">Запусков</th><th scope="col">Успех</th><th scope="col">Стоимость</th></tr></thead><tbody>';
1901
+ var html = '<table class="an-table"><thead><tr><th scope="col" style="width:46%">Задача</th><th scope="col" style="width:18%">Запусков</th><th scope="col" style="width:18%">Успех</th><th scope="col" style="width:18%">Стоимость</th></tr></thead><tbody>';
1861
1902
  for (var k = 0; k < topRows.length; k++) {
1862
1903
  var row = topRows[k];
1863
1904
  html += '<tr>' +
1864
- '<td>' + (row.isMatrixClone ? '↳ ' : '') + esc(row.taskName) + '</td>' +
1905
+ '<td title="' + esc(row.taskName) + '">' + (row.isMatrixClone ? '↳ ' : '') + esc(row.taskName) + '</td>' +
1865
1906
  '<td>' + row.total + '</td>' +
1866
1907
  '<td class="an-rate ' + rateClass(row.successRate) + '">' + row.successRate + '%</td>' +
1867
1908
  '<td>' + money(row.costUsd) + '</td>' +
@@ -1874,11 +1915,11 @@ function renderPage(): string {
1874
1915
  if (matrixRows.length === 0) {
1875
1916
  matrices.innerHTML = '<div class="empty" style="padding:10px">Матриц за период не запускалось.</div>';
1876
1917
  } else {
1877
- var mhtml = '<table class="an-table"><thead><tr><th scope="col">Матрица</th><th scope="col">Клонов</th><th scope="col">Запусков</th><th scope="col">Успех</th><th scope="col">Стоимость</th></tr></thead><tbody>';
1918
+ var mhtml = '<table class="an-table"><thead><tr><th scope="col" style="width:40%">Матрица</th><th scope="col" style="width:15%">Клонов</th><th scope="col" style="width:15%">Запусков</th><th scope="col" style="width:15%">Успех</th><th scope="col" style="width:15%">Стоимость</th></tr></thead><tbody>';
1878
1919
  for (var q = 0; q < matrixRows.length; q++) {
1879
1920
  var m = matrixRows[q];
1880
1921
  mhtml += '<tr>' +
1881
- '<td>📦 ' + esc(m.parentId) + '</td>' +
1922
+ '<td title="' + esc(m.parentId) + '">📦 ' + esc(m.parentId) + '</td>' +
1882
1923
  '<td>' + m.clones + '</td>' +
1883
1924
  '<td>' + m.total + '</td>' +
1884
1925
  '<td class="an-rate ' + rateClass(m.successRate) + '">' + m.successRate + '%</td>' +
@@ -1911,8 +1952,8 @@ function renderPage(): string {
1911
1952
  '<td class="wi-model">🧠 ' + esc(m.model) + '</td>' +
1912
1953
  '<td>' + m.totalRuns + '</td>' +
1913
1954
  '<td>' + Number(m.totalTokens || 0).toLocaleString('ru-RU') + '</td>' +
1914
- '<td>$' + Number(m.totalCost || 0).toFixed(4) + '</td>' +
1915
- '<td>' + (m.avgDuration != null ? m.avgDuration + ' мс' : '—') + '</td>' +
1955
+ '<td>' + money(m.totalCost) + '</td>' +
1956
+ '<td>' + durationText(m.avgDuration) + '</td>' +
1916
1957
  '<td>' + (m.successRate != null ? m.successRate + '%' : '—') + '</td>' +
1917
1958
  '</tr>';
1918
1959
  }
@@ -1927,12 +1968,12 @@ function renderPage(): string {
1927
1968
  }
1928
1969
  var parts = [];
1929
1970
  if (gpt) {
1930
- parts.push('Если бы все запуски выполнялись через <b>openai/gpt-4o</b>, это стоило бы ~<b>$' + Number(gpt.cost).toFixed(4) + '</b> (' + gpt.pricePerMillion + ' $/1M токенов).');
1971
+ parts.push('Если бы все запуски выполнялись через <b>openai/gpt-4o</b>, это стоило бы ~<b>' + money(gpt.cost) + '</b> (' + gpt.pricePerMillion + ' $/1M токенов).');
1931
1972
  }
1932
1973
  if (deepseek) {
1933
- parts.push('Если через <b>deepseek/deepseek-coder</b> — <b>$' + Number(deepseek.cost).toFixed(4) + '</b> (' + deepseek.pricePerMillion + ' $/1M токенов).');
1974
+ parts.push('Если через <b>deepseek/deepseek-coder</b> — <b>' + money(deepseek.cost) + '</b> (' + deepseek.pricePerMillion + ' $/1M токенов).');
1934
1975
  }
1935
- parts.push('Всего запусков: <b>' + totals.totalRuns + '</b>, токенов: <b>' + Number(totals.totalTokens || 0).toLocaleString('ru-RU') + '</b>, фактическая стоимость: <b>$' + Number(totals.totalCost || 0).toFixed(4) + '</b>.');
1976
+ parts.push('Всего запусков: <b>' + totals.totalRuns + '</b>, токенов: <b>' + Number(totals.totalTokens || 0).toLocaleString('ru-RU') + '</b>, фактическая стоимость: <b>' + money(totals.totalCost) + '</b>.');
1936
1977
  text.innerHTML = parts.join(' ');
1937
1978
  }
1938
1979
 
@@ -2447,7 +2488,7 @@ function renderPage(): string {
2447
2488
  if (t.estimatedDurationSec != null || t.estimatedTokens != null) {
2448
2489
  est = (t.estimatedDurationSec != null ? t.estimatedDurationSec + ' с' : '') +
2449
2490
  (t.estimatedTokens != null ? ' · ' + t.estimatedTokens + ' ток.' : '') +
2450
- (t.estimatedCostUsd != null ? ' · $' + Number(t.estimatedCostUsd).toFixed(4) : '');
2491
+ (t.estimatedCostUsd != null ? ' · ' + money(t.estimatedCostUsd) : '');
2451
2492
  }
2452
2493
  var ws = t.workspace ? '📦 ' + esc(t.workspace.name) : '—';
2453
2494
  var matrixParent = t.matrixParent ? '<div class="matrix-badge">↳ matrix ' + esc(t.matrixParent) + '</div>' : '';
@@ -2466,7 +2507,7 @@ function renderPage(): string {
2466
2507
  html += '<div class="metrics" style="margin-top:8px">Σ Оценка конвейера: ' +
2467
2508
  (totals.estimatedDurationSec != null ? totals.estimatedDurationSec + ' с · ' : '') +
2468
2509
  (totals.estimatedTokens != null ? totals.estimatedTokens + ' токенов · ' : '') +
2469
- (totals.estimatedCostUsd != null ? '~$' + Number(totals.estimatedCostUsd).toFixed(4) : '') + '</div>';
2510
+ (totals.estimatedCostUsd != null ? '~' + money(totals.estimatedCostUsd) : '') + '</div>';
2470
2511
  }
2471
2512
  if (body) body.innerHTML = html;
2472
2513
  } catch (err) {
package/src/settings.ts CHANGED
@@ -2,6 +2,7 @@ import crypto from "node:crypto";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { PLUGIN_DIR } from "./types.js";
5
+ import { DEFAULT_LOCALE, normalizeLocale, SUPPORTED_LOCALES, messageIn, t, type Locale } from "./i18n.js";
5
6
 
6
7
  /** Настройки webhook-уведомлений (Discord/Slack/generic). */
7
8
  export interface WebhookNotificationSettings {
@@ -195,6 +196,8 @@ export interface AuditSettings {
195
196
  export interface SchedulerSettings {
196
197
  /** Максимум одновременно выполняющихся задач. 0 — без ограничения. */
197
198
  maxConcurrent: number;
199
+ /** Язык интерфейса (Спринт 28): ru по умолчанию, en — опционально. */
200
+ locale: Locale;
198
201
  /** Зимняя тема оформления GUI (снежинки, морозные рамки, градиент). */
199
202
  winterMode: boolean;
200
203
  /** Уведомления о завершении задач. */
@@ -334,8 +337,8 @@ export function defaultNotifications(): NotificationSettings {
334
337
  retryDelayMs: DEFAULT_WEBHOOK_RETRY_DELAY_MS,
335
338
  },
336
339
  templates: {
337
- success: '✅ Задача "{task}" выполнена ({duration}){cost}',
338
- error: '❌ Задача "{task}" упала ({duration}){error}{cost}',
340
+ success: t("notify.task.success"),
341
+ error: t("notify.task.error"),
339
342
  },
340
343
  filters: { include: [], exclude: [] },
341
344
  telegram: {
@@ -448,6 +451,23 @@ function normalizeHttpBase(value: unknown, fallback: string): string {
448
451
  }
449
452
  }
450
453
 
454
+ /**
455
+ * Встроенный шаблон (ru или en) заменяется текущим переводом; пользовательский
456
+ * текст остаётся как есть. Иначе сохранённые при первой установке дефолты
457
+ * навсегда застывали бы на языке установки.
458
+ */
459
+ function localizedTemplate(
460
+ value: unknown,
461
+ key: string,
462
+ fallback: string
463
+ ): string {
464
+ const raw = typeof value === "string" && value.trim() ? value : fallback;
465
+ const builtin = SUPPORTED_LOCALES.some(
466
+ (locale) => messageIn(locale, key) === raw
467
+ );
468
+ return builtin ? t(key) : raw;
469
+ }
470
+
451
471
  /** Приводит настройки уведомлений к безопасному виду. */
452
472
  function normalizeNotifications(
453
473
  value: unknown,
@@ -533,14 +553,16 @@ function normalizeNotifications(
533
553
  ),
534
554
  },
535
555
  templates: {
536
- success:
537
- typeof rawTemplates?.success === "string" && rawTemplates.success.trim()
538
- ? rawTemplates.success
539
- : fallbackTemplates.success,
540
- error:
541
- typeof rawTemplates?.error === "string" && rawTemplates.error.trim()
542
- ? rawTemplates.error
543
- : fallbackTemplates.error,
556
+ success: localizedTemplate(
557
+ rawTemplates?.success,
558
+ "notify.task.success",
559
+ fallbackTemplates.success
560
+ ),
561
+ error: localizedTemplate(
562
+ rawTemplates?.error,
563
+ "notify.task.error",
564
+ fallbackTemplates.error
565
+ ),
544
566
  },
545
567
  filters: {
546
568
  include: normalizeNameList(rawFilters?.include, fallbackFilters.include),
@@ -689,6 +711,7 @@ export async function loadSettings(): Promise<SchedulerSettings> {
689
711
  parsed?.maxConcurrent,
690
712
  DEFAULT_MAX_CONCURRENT
691
713
  ),
714
+ locale: normalizeLocale(parsed?.locale, DEFAULT_LOCALE),
692
715
  winterMode: normalizeWinterMode(
693
716
  parsed?.winterMode,
694
717
  DEFAULT_WINTER_MODE
@@ -707,6 +730,7 @@ export async function loadSettings(): Promise<SchedulerSettings> {
707
730
  } catch {
708
731
  return {
709
732
  maxConcurrent: DEFAULT_MAX_CONCURRENT,
733
+ locale: DEFAULT_LOCALE,
710
734
  winterMode: DEFAULT_WINTER_MODE,
711
735
  notifications: fallbackNotifications,
712
736
  history: fallbackHistory,
@@ -726,6 +750,10 @@ export async function saveSettings(
726
750
  patch.maxConcurrent !== undefined
727
751
  ? normalizeMaxConcurrent(patch.maxConcurrent, current.maxConcurrent)
728
752
  : current.maxConcurrent,
753
+ locale:
754
+ patch.locale !== undefined
755
+ ? normalizeLocale(patch.locale, current.locale)
756
+ : current.locale,
729
757
  winterMode:
730
758
  patch.winterMode !== undefined
731
759
  ? normalizeWinterMode(patch.winterMode, current.winterMode)