agent-steward 0.0.2 → 0.0.4

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 (263) hide show
  1. package/CHANGELOG.md +45 -2
  2. package/CROSS_PLATFORM.md +11 -9
  3. package/README.md +11 -10
  4. package/ROADMAP-STRATEGY.md +93 -44
  5. package/ROADMAP.md +148 -1017
  6. package/dist/core/cron-to-schtasks.d.ts +0 -8
  7. package/dist/core/cron-to-schtasks.d.ts.map +1 -1
  8. package/dist/core/cron-to-schtasks.js +11 -86
  9. package/dist/core/dlq-api.d.ts +44 -0
  10. package/dist/core/dlq-api.d.ts.map +1 -0
  11. package/dist/core/dlq-api.js +68 -0
  12. package/dist/core/dry-run.d.ts.map +1 -1
  13. package/dist/core/dry-run.js +19 -2
  14. package/dist/core/file-watcher.js +9 -9
  15. package/dist/core/git-trigger.js +4 -4
  16. package/dist/core/lock.d.ts +20 -4
  17. package/dist/core/lock.d.ts.map +1 -1
  18. package/dist/core/lock.js +99 -26
  19. package/dist/core/one-shot.d.ts +31 -5
  20. package/dist/core/one-shot.d.ts.map +1 -1
  21. package/dist/core/one-shot.js +78 -10
  22. package/dist/core/opencode-cli.d.ts +28 -0
  23. package/dist/core/opencode-cli.d.ts.map +1 -0
  24. package/dist/core/opencode-cli.js +74 -0
  25. package/dist/core/opencode-models.d.ts +62 -0
  26. package/dist/core/opencode-models.d.ts.map +1 -0
  27. package/dist/core/opencode-models.js +277 -0
  28. package/dist/core/otel.js +2 -2
  29. package/dist/core/ps-wrapper.d.ts +1 -1
  30. package/dist/core/ps-wrapper.d.ts.map +1 -1
  31. package/dist/core/ps-wrapper.js +66 -36
  32. package/dist/core/record-history.d.ts +15 -0
  33. package/dist/core/record-history.d.ts.map +1 -1
  34. package/dist/core/record-history.js +78 -54
  35. package/dist/core/router/dispatch.d.ts +36 -0
  36. package/dist/core/router/dispatch.d.ts.map +1 -0
  37. package/dist/core/router/dispatch.js +59 -0
  38. package/dist/core/router/escalation.d.ts +47 -0
  39. package/dist/core/router/escalation.d.ts.map +1 -0
  40. package/dist/core/router/escalation.js +87 -0
  41. package/dist/core/router/planner.d.ts +53 -0
  42. package/dist/core/router/planner.d.ts.map +1 -0
  43. package/dist/core/router/planner.js +113 -0
  44. package/dist/core/router/rules.d.ts +46 -0
  45. package/dist/core/router/rules.d.ts.map +1 -0
  46. package/dist/core/router/rules.js +85 -0
  47. package/dist/core/run-panel-api.d.ts +94 -0
  48. package/dist/core/run-panel-api.d.ts.map +1 -0
  49. package/dist/core/run-panel-api.js +169 -0
  50. package/dist/core/schedule-gate.js +5 -1
  51. package/dist/core/schedule-v2.d.ts +36 -2
  52. package/dist/core/schedule-v2.d.ts.map +1 -1
  53. package/dist/core/schedule-v2.js +98 -12
  54. package/dist/core/scheduler/at-fallback.d.ts +95 -0
  55. package/dist/core/scheduler/at-fallback.d.ts.map +1 -0
  56. package/dist/core/scheduler/at-fallback.js +200 -0
  57. package/dist/core/scheduler/linux.d.ts +13 -2
  58. package/dist/core/scheduler/linux.d.ts.map +1 -1
  59. package/dist/core/scheduler/linux.js +67 -13
  60. package/dist/core/scheduler/mac.d.ts +14 -8
  61. package/dist/core/scheduler/mac.d.ts.map +1 -1
  62. package/dist/core/scheduler/mac.js +71 -22
  63. package/dist/core/scheduler/posix.d.ts.map +1 -1
  64. package/dist/core/scheduler/posix.js +37 -2
  65. package/dist/core/scheduler/registry.d.ts +13 -0
  66. package/dist/core/scheduler/registry.d.ts.map +1 -1
  67. package/dist/core/scheduler/registry.js +83 -21
  68. package/dist/core/scheduler/run-now.d.ts +16 -0
  69. package/dist/core/scheduler/run-now.d.ts.map +1 -0
  70. package/dist/core/scheduler/run-now.js +28 -0
  71. package/dist/core/scheduler/windows.d.ts +16 -3
  72. package/dist/core/scheduler/windows.d.ts.map +1 -1
  73. package/dist/core/scheduler/windows.js +249 -96
  74. package/dist/core/secrets.d.ts.map +1 -1
  75. package/dist/core/secrets.js +127 -30
  76. package/dist/core/self-analysis.js +55 -55
  77. package/dist/core/session.d.ts.map +1 -1
  78. package/dist/core/session.js +18 -11
  79. package/dist/core/summary.js +1 -1
  80. package/dist/core/task-name.d.ts +24 -0
  81. package/dist/core/task-name.d.ts.map +1 -0
  82. package/dist/core/task-name.js +40 -0
  83. package/dist/core/triage-chain.js +1 -1
  84. package/dist/core/triage-worker.js +2 -2
  85. package/dist/core/triage.js +1 -1
  86. package/dist/core/wrappers/bash.d.ts.map +1 -1
  87. package/dist/core/wrappers/bash.js +82 -37
  88. package/dist/db/capability-repo.d.ts +83 -0
  89. package/dist/db/capability-repo.d.ts.map +1 -0
  90. package/dist/db/capability-repo.js +182 -0
  91. package/dist/db/history-repo.d.ts +8 -0
  92. package/dist/db/history-repo.d.ts.map +1 -1
  93. package/dist/db/history-repo.js +19 -0
  94. package/dist/db/index.d.ts +6 -0
  95. package/dist/db/index.d.ts.map +1 -1
  96. package/dist/db/index.js +48 -2
  97. package/dist/db/migrate.d.ts.map +1 -1
  98. package/dist/db/migrate.js +3 -1
  99. package/dist/db/run-context.d.ts +103 -0
  100. package/dist/db/run-context.d.ts.map +1 -0
  101. package/dist/db/run-context.js +224 -0
  102. package/dist/db/run-dlq.d.ts +100 -0
  103. package/dist/db/run-dlq.d.ts.map +1 -0
  104. package/dist/db/run-dlq.js +191 -0
  105. package/dist/db/run-journal.d.ts +60 -0
  106. package/dist/db/run-journal.d.ts.map +1 -0
  107. package/dist/db/run-journal.js +143 -0
  108. package/dist/db/run-resume.d.ts +51 -0
  109. package/dist/db/run-resume.d.ts.map +1 -0
  110. package/dist/db/run-resume.js +156 -0
  111. package/dist/db/runs-repo.d.ts +128 -0
  112. package/dist/db/runs-repo.d.ts.map +1 -0
  113. package/dist/db/runs-repo.js +342 -0
  114. package/dist/db/schema.d.ts +16 -2
  115. package/dist/db/schema.d.ts.map +1 -1
  116. package/dist/db/schema.js +342 -35
  117. package/dist/db/settings-repo.d.ts +11 -0
  118. package/dist/db/settings-repo.d.ts.map +1 -1
  119. package/dist/db/settings-repo.js +25 -0
  120. package/dist/db/step-idempotency.d.ts +51 -0
  121. package/dist/db/step-idempotency.d.ts.map +1 -0
  122. package/dist/db/step-idempotency.js +136 -0
  123. package/dist/index.d.ts +5 -5
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +168 -40
  126. package/dist/notifications.js +18 -18
  127. package/dist/profiles.d.ts +7 -3
  128. package/dist/profiles.d.ts.map +1 -1
  129. package/dist/profiles.js +85 -7
  130. package/dist/rpc.d.ts +787 -0
  131. package/dist/rpc.d.ts.map +1 -1
  132. package/dist/rpc.js +324 -0
  133. package/dist/server.d.ts +33 -2
  134. package/dist/server.d.ts.map +1 -1
  135. package/dist/server.js +115 -54
  136. package/dist/shared/jobs-view.d.ts.map +1 -1
  137. package/dist/skill.js +1 -1
  138. package/dist/task-transfer.d.ts +1 -1
  139. package/dist/task-transfer.d.ts.map +1 -1
  140. package/dist/task-transfer.js +14 -10
  141. package/dist/types.d.ts +20 -4
  142. package/dist/types.d.ts.map +1 -1
  143. package/dist/types.js +44 -9
  144. package/dist/workspaces.d.ts +25 -3
  145. package/dist/workspaces.d.ts.map +1 -1
  146. package/dist/workspaces.js +44 -9
  147. package/docs/ARCHITECTURE.md +335 -9
  148. package/docs/COMPATIBILITY.md +10 -6
  149. package/docs/CONCEPT.md +183 -91
  150. package/docs/CROSS_PLATFORM.ru.md +11 -9
  151. package/docs/CROSS_PLATFORM.zh.md +11 -9
  152. package/docs/EXECUTION-LOOP.md +196 -0
  153. package/docs/FAQ.md +2 -2
  154. package/docs/FAQ.ru.md +2 -2
  155. package/docs/FAQ.zh.md +2 -2
  156. package/docs/FEATURES.md +5 -4
  157. package/docs/FEATURES.zh.md +5 -4
  158. package/docs/MIGRATION.md +34 -26
  159. package/docs/README.ru.md +27 -8
  160. package/docs/README.zh.md +11 -10
  161. package/docs/SAFETY.md +122 -0
  162. package/docs/SAVINGS.md +29 -0
  163. package/docs/SAVINGS.ru.md +29 -0
  164. package/docs/SAVINGS.zh.md +18 -0
  165. package/docs/V1-V2-COMPATIBILITY-PLAN.md +6 -6
  166. package/gui-experimental.cjs +8 -8
  167. package/index.js +1 -0
  168. package/locales/en.json +68 -0
  169. package/locales/ru.json +68 -0
  170. package/locales/zh.json +68 -0
  171. package/package.json +57 -11
  172. package/scripts/audit-bundle.mjs +215 -0
  173. package/src/core/analytics.ts +2 -2
  174. package/src/core/audit.ts +17 -17
  175. package/src/core/cron-to-schtasks.ts +14 -93
  176. package/src/core/dlq-api.ts +98 -0
  177. package/src/core/dry-run.ts +51 -27
  178. package/src/core/file-watcher.ts +17 -17
  179. package/src/core/git-trigger.ts +9 -9
  180. package/src/core/glob.ts +1 -1
  181. package/src/core/local-ai.ts +2 -2
  182. package/src/core/lock.ts +104 -31
  183. package/src/core/matrix.ts +31 -31
  184. package/src/core/native-notify.ts +2 -2
  185. package/src/core/one-shot.ts +91 -13
  186. package/src/core/opencode-cli.ts +103 -0
  187. package/src/core/opencode-models.ts +315 -0
  188. package/src/core/otel.ts +4 -4
  189. package/src/core/permissions.ts +5 -5
  190. package/src/core/prometheus.ts +17 -17
  191. package/src/core/ps-wrapper.ts +68 -38
  192. package/src/core/record-history.ts +114 -76
  193. package/src/core/retention.ts +3 -3
  194. package/src/core/router/dispatch.ts +94 -0
  195. package/src/core/router/escalation.ts +129 -0
  196. package/src/core/router/planner.ts +166 -0
  197. package/src/core/router/rules.ts +109 -0
  198. package/src/core/run-panel-api.ts +262 -0
  199. package/src/core/savings.ts +1 -1
  200. package/src/core/schedule-gate.ts +17 -13
  201. package/src/core/schedule-v2.ts +138 -29
  202. package/src/core/scheduler/at-fallback.ts +298 -0
  203. package/src/core/scheduler/index.ts +3 -3
  204. package/src/core/scheduler/linux.ts +92 -19
  205. package/src/core/scheduler/logs.ts +1 -1
  206. package/src/core/scheduler/mac.ts +112 -60
  207. package/src/core/scheduler/posix.ts +35 -2
  208. package/src/core/scheduler/registry.ts +109 -26
  209. package/src/core/scheduler/run-now.ts +32 -0
  210. package/src/core/scheduler/windows.ts +295 -125
  211. package/src/core/secrets.ts +139 -39
  212. package/src/core/self-analysis.ts +61 -61
  213. package/src/core/session.ts +26 -13
  214. package/src/core/structured-log.ts +3 -3
  215. package/src/core/summary.ts +25 -25
  216. package/src/core/task-name.ts +67 -0
  217. package/src/core/telegram.ts +16 -16
  218. package/src/core/triage-chain.ts +4 -4
  219. package/src/core/triage-compare.ts +8 -8
  220. package/src/core/triage-rules.ts +4 -4
  221. package/src/core/triage-shadow.ts +7 -7
  222. package/src/core/triage-worker.ts +6 -6
  223. package/src/core/triage.ts +23 -23
  224. package/src/core/watch-paths.ts +1 -1
  225. package/src/core/wrappers/bash.ts +90 -45
  226. package/src/db/capability-repo.ts +285 -0
  227. package/src/db/git-state-repo.ts +1 -1
  228. package/src/db/history-repo.ts +44 -22
  229. package/src/db/index.ts +53 -7
  230. package/src/db/metrics-repo.ts +10 -10
  231. package/src/db/migrate.ts +13 -11
  232. package/src/db/recovery.ts +3 -3
  233. package/src/db/run-context.ts +370 -0
  234. package/src/db/run-dlq.ts +310 -0
  235. package/src/db/run-journal.ts +212 -0
  236. package/src/db/run-resume.ts +256 -0
  237. package/src/db/runs-repo.ts +504 -0
  238. package/src/db/schema.ts +357 -44
  239. package/src/db/settings-repo.ts +33 -2
  240. package/src/db/step-idempotency.ts +185 -0
  241. package/src/db/tasks-repo.ts +10 -10
  242. package/src/db/templates-repo.ts +7 -7
  243. package/src/gui.tsx +516 -1
  244. package/src/history.ts +4 -4
  245. package/src/i18n.ts +7 -7
  246. package/src/index.ts +465 -308
  247. package/src/integrations.ts +6 -6
  248. package/src/notifications.ts +76 -76
  249. package/src/profiles.ts +98 -7
  250. package/src/rpc.ts +347 -1
  251. package/src/schtasks.ts +2 -2
  252. package/src/server.ts +155 -78
  253. package/src/settings.ts +44 -44
  254. package/src/shared/jobs-view.ts +60 -60
  255. package/src/skill.ts +1 -1
  256. package/src/task-transfer.ts +58 -56
  257. package/src/templates.ts +1 -1
  258. package/src/types.ts +54 -10
  259. package/src/workspaces.ts +73 -24
  260. package/dist/core/self-analysis.test.d.ts +0 -2
  261. package/dist/core/self-analysis.test.d.ts.map +0 -1
  262. package/dist/core/self-analysis.test.js +0 -219
  263. package/dist/gui-experimental.cjs +0 -1
package/src/profiles.ts CHANGED
@@ -32,22 +32,113 @@ export interface ProfileInfo {
32
32
  /**
33
33
  * Базовая директория плагина (до профилей).
34
34
  *
35
- * Windows: %APPDATA%\opencode\windows-scheduler.
36
- * macOS/Linux: $XDG_CONFIG_HOME/opencode/windows-scheduler или
37
- * ~/.config/opencode/windows-scheduler.
35
+ * Windows: %APPDATA%\opencode\agent-steward.
36
+ * macOS/Linux: $XDG_CONFIG_HOME/opencode/agent-steward или
37
+ * ~/.config/opencode/agent-steward.
38
38
  * OPENCODE_SCHEDULER_HOME переопределяет всё (тесты, кастомные установки).
39
+ *
40
+ * При первом запуске после переименования данные из исторической
41
+ * .../opencode/windows-scheduler копируются в новую директорию (legacy
42
+ * остаётся на месте как резервная копия).
39
43
  */
40
44
  export function getBasePluginDir(): string {
41
45
  const custom = process.env.OPENCODE_SCHEDULER_HOME?.trim();
42
46
  if (custom) return path.resolve(custom);
43
47
 
48
+ const root = path.join(pluginConfigRoot(), "opencode");
49
+ const target = path.join(root, "agent-steward");
50
+ const legacy = path.join(root, "windows-scheduler");
51
+
52
+ if (fs.existsSync(target) || !fs.existsSync(legacy)) return target;
53
+
54
+ try {
55
+ migrateLegacyBaseDir(legacy, target);
56
+ return target;
57
+ } catch (error) {
58
+ // Не теряем доступ к данным: продолжаем работать в старой директории.
59
+ console.error(
60
+ `[agent-steward] Не удалось перенести данные из "${legacy}" в "${target}": ${
61
+ error instanceof Error ? error.message : String(error)
62
+ }. Использую старую директорию.`,
63
+ );
64
+ return legacy;
65
+ }
66
+ }
67
+
68
+ /** Корень конфигурации пользователя (без .../opencode). */
69
+ function pluginConfigRoot(): string {
44
70
  if (process.platform === "win32") {
45
- const base = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
46
- return path.join(base, "opencode", "windows-scheduler");
71
+ return process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
47
72
  }
73
+ return process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
74
+ }
75
+
76
+ const MIGRATION_MARKER = ".migrated-from-windows-scheduler";
77
+
78
+ /** Расширения текстовых файлов, в которых могут быть абсолютные пути. */
79
+ const PATH_REWRITE_EXTENSIONS = new Set([
80
+ ".json",
81
+ ".cmd",
82
+ ".sh",
83
+ ".bash",
84
+ ".ps1",
85
+ ".txt",
86
+ ]);
87
+
88
+ /**
89
+ * Копирует legacy-директорию в новую и переписывает в текстовых файлах
90
+ * абсолютные пути старой директории на новую. Копия делается во временную
91
+ * директорию и переименовывается атомарно, чтобы не оставить половину данных.
92
+ */
93
+ function migrateLegacyBaseDir(legacy: string, target: string): void {
94
+ const temp = `${target}.migrating-${process.pid}`;
95
+ fs.rmSync(temp, { recursive: true, force: true });
96
+ fs.cpSync(legacy, temp, { recursive: true });
97
+
98
+ rewriteAbsolutePaths(temp, legacy, target);
99
+ fs.writeFileSync(
100
+ path.join(temp, MIGRATION_MARKER),
101
+ `${new Date().toISOString()}\n`,
102
+ "utf8",
103
+ );
104
+
105
+ try {
106
+ fs.renameSync(temp, target);
107
+ } catch (error) {
108
+ fs.rmSync(temp, { recursive: true, force: true });
109
+ // Параллельный процесс мог успеть создать target — это не ошибка.
110
+ if (fs.existsSync(target)) return;
111
+ throw error;
112
+ }
113
+ }
114
+
115
+ function rewriteAbsolutePaths(root: string, from: string, to: string): void {
116
+ const variants = [
117
+ from,
118
+ from.replace(/\\/g, "/"),
119
+ from.replace(/\\/g, "\\\\"),
120
+ ].filter((value, index, all) => value && all.indexOf(value) === index);
121
+
122
+ const walk = (dir: string): void => {
123
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
124
+ const full = path.join(dir, entry.name);
125
+ if (entry.isDirectory()) {
126
+ walk(full);
127
+ continue;
128
+ }
129
+ if (!PATH_REWRITE_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) {
130
+ continue;
131
+ }
132
+ const text = fs.readFileSync(full, "utf8");
133
+ let next = text;
134
+ for (const variant of variants) {
135
+ next = next.split(variant).join(variant.includes("\\\\") ? to.replace(/\\/g, "\\\\") : variant.includes("/") ? to.replace(/\\/g, "/") : to);
136
+ }
137
+ if (next !== text) fs.writeFileSync(full, next, "utf8");
138
+ }
139
+ };
48
140
 
49
- const configHome = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
50
- return path.join(configHome, "opencode", "windows-scheduler");
141
+ walk(root);
51
142
  }
52
143
 
53
144
  /** Нормализует имя профиля: нижний регистр, только [a-z0-9_-]. */
package/src/rpc.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Rpc } from "@opencode/plugin/rpc"
1
+ import { Rpc } from "@opencode/plugin/rpc";
2
2
 
3
3
  /**
4
4
  * Общее определение RPC-контракта между серверной частью плагина (src/index.ts)
@@ -899,6 +899,251 @@ const GetAuditOutput = {
899
899
  required: ["success", "records", "total"],
900
900
  } as const;
901
901
 
902
+ /** Запись dead-letter queue (Спринт 36.6). */
903
+ const DlqEntrySchema = {
904
+ type: "object" as const,
905
+ properties: {
906
+ id: { type: "string" },
907
+ runId: { type: "string" },
908
+ stepName: { type: "string" },
909
+ status: { type: "string" },
910
+ reason: { type: ["string", "null"] },
911
+ error: { type: ["string", "null"] },
912
+ attempts: { type: "number" },
913
+ createdAt: { type: "string" },
914
+ updatedAt: { type: "string" },
915
+ resolvedAt: { type: ["string", "null"] },
916
+ resolution: { type: ["string", "null"] },
917
+ },
918
+ required: [
919
+ "id",
920
+ "runId",
921
+ "stepName",
922
+ "status",
923
+ "reason",
924
+ "error",
925
+ "attempts",
926
+ "createdAt",
927
+ "updatedAt",
928
+ "resolvedAt",
929
+ "resolution",
930
+ ],
931
+ } as const;
932
+
933
+ const ListDlqInput = {
934
+ type: "object" as const,
935
+ properties: {
936
+ /** open (по умолчанию) | retried | discarded | all. */
937
+ status: { type: "string" },
938
+ /** Сколько записей вернуть (по умолчанию 100, максимум 500). */
939
+ limit: { type: "number" },
940
+ },
941
+ additionalProperties: false,
942
+ } as const;
943
+
944
+ const ListDlqOutput = {
945
+ type: "object" as const,
946
+ properties: {
947
+ success: { type: "boolean" },
948
+ entries: { type: "array", items: DlqEntrySchema },
949
+ open: { type: "number" },
950
+ error: { type: "string" },
951
+ },
952
+ required: ["success", "entries", "open"],
953
+ additionalProperties: false,
954
+ } as const;
955
+
956
+ const RetryDlqInput = {
957
+ type: "object" as const,
958
+ properties: {
959
+ id: { type: "string" },
960
+ },
961
+ required: ["id"],
962
+ additionalProperties: false,
963
+ } as const;
964
+
965
+ const RetryDlqOutput = {
966
+ type: "object" as const,
967
+ properties: {
968
+ success: { type: "boolean" },
969
+ error: { type: "string" },
970
+ entry: DlqEntrySchema,
971
+ runId: { type: "string" },
972
+ stepName: { type: "string" },
973
+ runReopened: { type: "boolean" },
974
+ },
975
+ required: ["success"],
976
+ additionalProperties: false,
977
+ } as const;
978
+
979
+ const DiscardDlqInput = {
980
+ type: "object" as const,
981
+ properties: {
982
+ id: { type: "string" },
983
+ /** Причина отказа для журнала (по умолчанию discarded). */
984
+ resolution: { type: "string" },
985
+ },
986
+ required: ["id"],
987
+ additionalProperties: false,
988
+ } as const;
989
+
990
+ const DiscardDlqOutput = {
991
+ type: "object" as const,
992
+ properties: {
993
+ success: { type: "boolean" },
994
+ error: { type: "string" },
995
+ entry: DlqEntrySchema,
996
+ },
997
+ required: ["success"],
998
+ additionalProperties: false,
999
+ } as const;
1000
+
1001
+ /** Шаг durable-запуска для панели (Спринт 36.8). */
1002
+ const RunPanelStepSchema = {
1003
+ type: "object" as const,
1004
+ properties: {
1005
+ stepName: { type: "string" },
1006
+ position: { type: "number" },
1007
+ status: { type: "string" },
1008
+ attempt: { type: "number" },
1009
+ error: { type: ["string", "null"] },
1010
+ anchor: { type: "string" },
1011
+ },
1012
+ required: ["stepName", "position", "status", "attempt", "error", "anchor"],
1013
+ } as const;
1014
+
1015
+ /** Вставка контекста в истории запуска. */
1016
+ const RunPanelInjectionSchema = {
1017
+ type: "object" as const,
1018
+ properties: {
1019
+ id: { type: "string" },
1020
+ kind: { type: "string" },
1021
+ content: { type: "string" },
1022
+ contentLength: { type: "number" },
1023
+ author: { type: "string" },
1024
+ createdAt: { type: "string" },
1025
+ consumedAt: { type: ["string", "null"] },
1026
+ consumedByStep: { type: ["string", "null"] },
1027
+ },
1028
+ required: [
1029
+ "id",
1030
+ "kind",
1031
+ "content",
1032
+ "contentLength",
1033
+ "author",
1034
+ "createdAt",
1035
+ "consumedAt",
1036
+ "consumedByStep",
1037
+ ],
1038
+ } as const;
1039
+
1040
+ /** Durable-запуск в панели паузы/resume. */
1041
+ const RunPanelRunSchema = {
1042
+ type: "object" as const,
1043
+ properties: {
1044
+ id: { type: "string" },
1045
+ taskName: { type: "string" },
1046
+ status: { type: "string" },
1047
+ createdAt: { type: "string" },
1048
+ startedAt: { type: ["string", "null"] },
1049
+ finishedAt: { type: ["string", "null"] },
1050
+ error: { type: ["string", "null"] },
1051
+ steps: { type: "array", items: RunPanelStepSchema },
1052
+ currentStep: { type: ["object", "null"], properties: RunPanelStepSchema.properties },
1053
+ doneSteps: { type: "number" },
1054
+ totalSteps: { type: "number" },
1055
+ injections: { type: "array", items: RunPanelInjectionSchema },
1056
+ pendingInjections: { type: "number" },
1057
+ },
1058
+ required: [
1059
+ "id",
1060
+ "taskName",
1061
+ "status",
1062
+ "createdAt",
1063
+ "startedAt",
1064
+ "finishedAt",
1065
+ "error",
1066
+ "steps",
1067
+ "currentStep",
1068
+ "doneSteps",
1069
+ "totalSteps",
1070
+ "injections",
1071
+ "pendingInjections",
1072
+ ],
1073
+ } as const;
1074
+
1075
+ const ListDurableRunsInput = {
1076
+ type: "object" as const,
1077
+ properties: {
1078
+ /** active (по умолчанию) | all | pending | running | paused | passed | failed | cancelled. */
1079
+ filter: { type: "string" },
1080
+ /** Сколько запусков вернуть (по умолчанию 20, максимум 100). */
1081
+ limit: { type: "number" },
1082
+ },
1083
+ additionalProperties: false,
1084
+ } as const;
1085
+
1086
+ const ListDurableRunsOutput = {
1087
+ type: "object" as const,
1088
+ properties: {
1089
+ success: { type: "boolean" },
1090
+ runs: { type: "array", items: RunPanelRunSchema },
1091
+ active: { type: "number" },
1092
+ error: { type: "string" },
1093
+ },
1094
+ required: ["success", "runs", "active"],
1095
+ additionalProperties: false,
1096
+ } as const;
1097
+
1098
+ const PauseDurableRunInput = {
1099
+ type: "object" as const,
1100
+ properties: {
1101
+ runId: { type: "string" },
1102
+ /** Явный шаг-получатель; по умолчанию первый незавершённый. */
1103
+ stepName: { type: "string" },
1104
+ /** Комментарий, который получит шаг при resume. */
1105
+ comment: { type: "string" },
1106
+ /** Автор комментария (по умолчанию local-user). */
1107
+ author: { type: "string" },
1108
+ },
1109
+ required: ["runId"],
1110
+ additionalProperties: false,
1111
+ } as const;
1112
+
1113
+ const PauseDurableRunOutput = {
1114
+ type: "object" as const,
1115
+ properties: {
1116
+ success: { type: "boolean" },
1117
+ error: { type: "string" },
1118
+ run: RunPanelRunSchema,
1119
+ stepName: { type: ["string", "null"] },
1120
+ },
1121
+ required: ["success"],
1122
+ additionalProperties: false,
1123
+ } as const;
1124
+
1125
+ const ResumeDurableRunInput = {
1126
+ type: "object" as const,
1127
+ properties: {
1128
+ runId: { type: "string" },
1129
+ },
1130
+ required: ["runId"],
1131
+ additionalProperties: false,
1132
+ } as const;
1133
+
1134
+ const ResumeDurableRunOutput = {
1135
+ type: "object" as const,
1136
+ properties: {
1137
+ success: { type: "boolean" },
1138
+ error: { type: "string" },
1139
+ run: RunPanelRunSchema,
1140
+ stepName: { type: ["string", "null"] },
1141
+ prepared: { type: "boolean" },
1142
+ },
1143
+ required: ["success"],
1144
+ additionalProperties: false,
1145
+ } as const;
1146
+
902
1147
  /** Сравнение триажа «до/после» (Спринт 31.5). */
903
1148
  const CompareTriageInput = {
904
1149
  type: "object" as const,
@@ -928,6 +1173,85 @@ const CompareTriageOutput = {
928
1173
  additionalProperties: false,
929
1174
  } as const;
930
1175
 
1176
+ /** Отчёт shadow-режима триажа для GUI. */
1177
+ const GetShadowReportInput = {
1178
+ type: "object" as const,
1179
+ properties: {},
1180
+ additionalProperties: false,
1181
+ } as const;
1182
+
1183
+ const GetShadowReportOutput = {
1184
+ type: "object" as const,
1185
+ properties: {
1186
+ success: { type: "boolean" },
1187
+ active: { type: "boolean" },
1188
+ startedAt: { type: ["string", "null"] },
1189
+ days: { type: "number" },
1190
+ total: { type: "number" },
1191
+ skips: { type: "number" },
1192
+ wouldSuppress: { type: "number" },
1193
+ bySource: { type: "object" },
1194
+ persisted: { type: "boolean" },
1195
+ truncated: { type: "boolean" },
1196
+ decisions: { type: "array", items: { type: "object" } },
1197
+ },
1198
+ required: [
1199
+ "success",
1200
+ "active",
1201
+ "startedAt",
1202
+ "days",
1203
+ "total",
1204
+ "skips",
1205
+ "wouldSuppress",
1206
+ "bySource",
1207
+ "persisted",
1208
+ "truncated",
1209
+ "decisions",
1210
+ ],
1211
+ additionalProperties: false,
1212
+ } as const;
1213
+
1214
+ /** Сброс shadow-журнала триажа для GUI. */
1215
+ const ResetShadowReportInput = {
1216
+ type: "object" as const,
1217
+ properties: {},
1218
+ additionalProperties: false,
1219
+ } as const;
1220
+
1221
+ const ResetShadowReportOutput = {
1222
+ type: "object" as const,
1223
+ properties: {
1224
+ success: { type: "boolean" },
1225
+ },
1226
+ required: ["success"],
1227
+ additionalProperties: false,
1228
+ } as const;
1229
+
1230
+ /** Проверка связи с локальной моделью триажа (GUI). */
1231
+ const TestLocalAiInput = {
1232
+ type: "object" as const,
1233
+ properties: {
1234
+ mode: { type: "string" },
1235
+ baseUrl: { type: "string" },
1236
+ model: { type: "string" },
1237
+ timeoutMs: { type: "number" },
1238
+ fallback: { type: "string" },
1239
+ confidenceThreshold: { type: "number" },
1240
+ },
1241
+ additionalProperties: false,
1242
+ } as const;
1243
+
1244
+ const TestLocalAiOutput = {
1245
+ type: "object" as const,
1246
+ properties: {
1247
+ success: { type: "boolean" },
1248
+ localAi: { type: "object" },
1249
+ result: { type: "object" },
1250
+ },
1251
+ required: ["success", "localAi", "result"],
1252
+ additionalProperties: false,
1253
+ } as const;
1254
+
931
1255
  const TemplateItem = {
932
1256
  type: "object" as const,
933
1257
  properties: {
@@ -1538,6 +1862,10 @@ const DeleteProfileOutput = {
1538
1862
  } as const;
1539
1863
 
1540
1864
  export const SchedulerRpc = Rpc.define({
1865
+ // ВАЖНО: id RPC-канала совпадает с id плагина и должен оставаться
1866
+ // "opencode-windows-scheduler". GUI OpenCode строит URL
1867
+ // /api/rpc/<plugin-id>/<method>; если id разойдётся, все вызовы
1868
+ // вернут 400 "RPC is unavailable: opencode-windows-scheduler".
1541
1869
  id: "opencode-windows-scheduler",
1542
1870
  methods: {
1543
1871
  get_tasks: { input: GetTasksInput, output: GetTasksOutput },
@@ -1598,10 +1926,28 @@ export const SchedulerRpc = Rpc.define({
1598
1926
  save_secret: { input: SaveSecretInput, output: SaveSecretOutput },
1599
1927
  delete_secret: { input: DeleteSecretInput, output: DeleteSecretOutput },
1600
1928
  get_audit: { input: GetAuditInput, output: GetAuditOutput },
1929
+ list_dlq: { input: ListDlqInput, output: ListDlqOutput },
1930
+ retry_dlq: { input: RetryDlqInput, output: RetryDlqOutput },
1931
+ discard_dlq: { input: DiscardDlqInput, output: DiscardDlqOutput },
1932
+ list_durable_runs: { input: ListDurableRunsInput, output: ListDurableRunsOutput },
1933
+ pause_durable_run: { input: PauseDurableRunInput, output: PauseDurableRunOutput },
1934
+ resume_durable_run: { input: ResumeDurableRunInput, output: ResumeDurableRunOutput },
1601
1935
  compare_triage: {
1602
1936
  input: CompareTriageInput,
1603
1937
  output: CompareTriageOutput,
1604
1938
  },
1939
+ get_shadow_report: {
1940
+ input: GetShadowReportInput,
1941
+ output: GetShadowReportOutput,
1942
+ },
1943
+ reset_shadow_report: {
1944
+ input: ResetShadowReportInput,
1945
+ output: ResetShadowReportOutput,
1946
+ },
1947
+ test_local_ai: {
1948
+ input: TestLocalAiInput,
1949
+ output: TestLocalAiOutput,
1950
+ },
1605
1951
  },
1606
1952
  events: {},
1607
1953
  });
package/src/schtasks.ts CHANGED
@@ -28,7 +28,7 @@ const backend = new WindowsScheduler();
28
28
  export async function createTask(
29
29
  name: string,
30
30
  trCommand: string,
31
- scheduleFlags: string[]
31
+ scheduleFlags: string[],
32
32
  ): Promise<void> {
33
33
  const args = [
34
34
  "/create",
@@ -44,7 +44,7 @@ export async function createTask(
44
44
  throw new SchtasksError(
45
45
  `Не удалось создать задачу "${name}": ${result.stderr || result.stdout}`,
46
46
  result.code,
47
- result.stderr
47
+ result.stderr,
48
48
  );
49
49
  }
50
50
  }