agent-steward 0.0.3 → 0.0.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.
Files changed (287) hide show
  1. package/CHANGELOG.md +154 -2
  2. package/CROSS_PLATFORM.md +19 -0
  3. package/README.md +54 -9
  4. package/ROADMAP-STRATEGY.md +23 -20
  5. package/ROADMAP.md +140 -143
  6. package/dist/cli.d.ts +3 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +351 -0
  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 +18 -1
  14. package/dist/core/execution.d.ts +203 -0
  15. package/dist/core/execution.d.ts.map +1 -0
  16. package/dist/core/execution.js +309 -0
  17. package/dist/core/gate-integrity.d.ts +35 -0
  18. package/dist/core/gate-integrity.d.ts.map +1 -0
  19. package/dist/core/gate-integrity.js +132 -0
  20. package/dist/core/git-trigger.d.ts.map +1 -1
  21. package/dist/core/git-trigger.js +14 -2
  22. package/dist/core/guard-run.d.ts +4 -0
  23. package/dist/core/guard-run.d.ts.map +1 -0
  24. package/dist/core/guard-run.js +101 -0
  25. package/dist/core/guard.d.ts +52 -0
  26. package/dist/core/guard.d.ts.map +1 -0
  27. package/dist/core/guard.js +362 -0
  28. package/dist/core/lock.d.ts +61 -4
  29. package/dist/core/lock.d.ts.map +1 -1
  30. package/dist/core/lock.js +213 -26
  31. package/dist/core/matrix.d.ts.map +1 -1
  32. package/dist/core/matrix.js +75 -15
  33. package/dist/core/mission.d.ts +83 -0
  34. package/dist/core/mission.d.ts.map +1 -0
  35. package/dist/core/mission.js +334 -0
  36. package/dist/core/one-shot.d.ts +5 -1
  37. package/dist/core/one-shot.d.ts.map +1 -1
  38. package/dist/core/one-shot.js +33 -8
  39. package/dist/core/opencode-cli.d.ts +28 -0
  40. package/dist/core/opencode-cli.d.ts.map +1 -0
  41. package/dist/core/opencode-cli.js +74 -0
  42. package/dist/core/opencode-models.d.ts +62 -0
  43. package/dist/core/opencode-models.d.ts.map +1 -0
  44. package/dist/core/opencode-models.js +277 -0
  45. package/dist/core/pipeline-apply.d.ts +38 -0
  46. package/dist/core/pipeline-apply.d.ts.map +1 -0
  47. package/dist/core/pipeline-apply.js +117 -0
  48. package/dist/core/pipeline-io.d.ts +13 -0
  49. package/dist/core/pipeline-io.d.ts.map +1 -0
  50. package/dist/core/pipeline-io.js +64 -0
  51. package/dist/core/pipeline-map.d.ts +46 -0
  52. package/dist/core/pipeline-map.d.ts.map +1 -0
  53. package/dist/core/pipeline-map.js +196 -0
  54. package/dist/core/pipeline-spec.d.ts +109 -0
  55. package/dist/core/pipeline-spec.d.ts.map +1 -0
  56. package/dist/core/pipeline-spec.js +554 -0
  57. package/dist/core/ps-wrapper.d.ts +19 -2
  58. package/dist/core/ps-wrapper.d.ts.map +1 -1
  59. package/dist/core/ps-wrapper.js +261 -63
  60. package/dist/core/record-history.d.ts +15 -0
  61. package/dist/core/record-history.d.ts.map +1 -1
  62. package/dist/core/record-history.js +183 -58
  63. package/dist/core/router/dispatch.d.ts +36 -0
  64. package/dist/core/router/dispatch.d.ts.map +1 -0
  65. package/dist/core/router/dispatch.js +59 -0
  66. package/dist/core/router/escalation.d.ts +47 -0
  67. package/dist/core/router/escalation.d.ts.map +1 -0
  68. package/dist/core/router/escalation.js +87 -0
  69. package/dist/core/router/planner.d.ts +53 -0
  70. package/dist/core/router/planner.d.ts.map +1 -0
  71. package/dist/core/router/planner.js +113 -0
  72. package/dist/core/router/rules.d.ts +46 -0
  73. package/dist/core/router/rules.d.ts.map +1 -0
  74. package/dist/core/router/rules.js +91 -0
  75. package/dist/core/run-panel-api.d.ts +94 -0
  76. package/dist/core/run-panel-api.d.ts.map +1 -0
  77. package/dist/core/run-panel-api.js +169 -0
  78. package/dist/core/schedule-gate.js +5 -1
  79. package/dist/core/schedule-v2.d.ts +34 -0
  80. package/dist/core/schedule-v2.d.ts.map +1 -1
  81. package/dist/core/schedule-v2.js +91 -5
  82. package/dist/core/scheduler/at-fallback.d.ts +55 -2
  83. package/dist/core/scheduler/at-fallback.d.ts.map +1 -1
  84. package/dist/core/scheduler/at-fallback.js +135 -5
  85. package/dist/core/scheduler/linux.d.ts +18 -2
  86. package/dist/core/scheduler/linux.d.ts.map +1 -1
  87. package/dist/core/scheduler/linux.js +63 -20
  88. package/dist/core/scheduler/mac.d.ts +44 -2
  89. package/dist/core/scheduler/mac.d.ts.map +1 -1
  90. package/dist/core/scheduler/mac.js +126 -15
  91. package/dist/core/scheduler/posix.d.ts.map +1 -1
  92. package/dist/core/scheduler/posix.js +25 -1
  93. package/dist/core/scheduler/registry.d.ts +11 -0
  94. package/dist/core/scheduler/registry.d.ts.map +1 -1
  95. package/dist/core/scheduler/registry.js +83 -21
  96. package/dist/core/scheduler/run-now.d.ts +16 -0
  97. package/dist/core/scheduler/run-now.d.ts.map +1 -0
  98. package/dist/core/scheduler/run-now.js +28 -0
  99. package/dist/core/scheduler/windows.d.ts.map +1 -1
  100. package/dist/core/scheduler/windows.js +15 -12
  101. package/dist/core/secrets.d.ts.map +1 -1
  102. package/dist/core/secrets.js +125 -28
  103. package/dist/core/session.d.ts.map +1 -1
  104. package/dist/core/session.js +18 -11
  105. package/dist/core/structured-log.d.ts +7 -1
  106. package/dist/core/structured-log.d.ts.map +1 -1
  107. package/dist/core/task-name.d.ts +24 -0
  108. package/dist/core/task-name.d.ts.map +1 -0
  109. package/dist/core/task-name.js +40 -0
  110. package/dist/core/worktree-run.d.ts +4 -0
  111. package/dist/core/worktree-run.d.ts.map +1 -0
  112. package/dist/core/worktree-run.js +164 -0
  113. package/dist/core/worktree.d.ts +115 -0
  114. package/dist/core/worktree.d.ts.map +1 -0
  115. package/dist/core/worktree.js +462 -0
  116. package/dist/core/wrappers/bash.d.ts +17 -0
  117. package/dist/core/wrappers/bash.d.ts.map +1 -1
  118. package/dist/core/wrappers/bash.js +224 -28
  119. package/dist/db/capability-repo.d.ts +124 -0
  120. package/dist/db/capability-repo.d.ts.map +1 -0
  121. package/dist/db/capability-repo.js +267 -0
  122. package/dist/db/history-repo.d.ts +46 -5
  123. package/dist/db/history-repo.d.ts.map +1 -1
  124. package/dist/db/history-repo.js +107 -25
  125. package/dist/db/index.d.ts +4 -0
  126. package/dist/db/index.d.ts.map +1 -1
  127. package/dist/db/index.js +39 -1
  128. package/dist/db/metrics-repo.js +2 -2
  129. package/dist/db/migrate.d.ts.map +1 -1
  130. package/dist/db/migrate.js +3 -1
  131. package/dist/db/recovery.d.ts.map +1 -1
  132. package/dist/db/recovery.js +5 -4
  133. package/dist/db/run-context.d.ts +103 -0
  134. package/dist/db/run-context.d.ts.map +1 -0
  135. package/dist/db/run-context.js +224 -0
  136. package/dist/db/run-dlq.d.ts +100 -0
  137. package/dist/db/run-dlq.d.ts.map +1 -0
  138. package/dist/db/run-dlq.js +191 -0
  139. package/dist/db/run-journal.d.ts +33 -5
  140. package/dist/db/run-journal.d.ts.map +1 -1
  141. package/dist/db/run-journal.js +78 -14
  142. package/dist/db/run-resume.d.ts +10 -2
  143. package/dist/db/run-resume.d.ts.map +1 -1
  144. package/dist/db/run-resume.js +39 -13
  145. package/dist/db/runs-repo.d.ts +32 -7
  146. package/dist/db/runs-repo.d.ts.map +1 -1
  147. package/dist/db/runs-repo.js +50 -11
  148. package/dist/db/schema.d.ts +2 -2
  149. package/dist/db/schema.d.ts.map +1 -1
  150. package/dist/db/schema.js +216 -3
  151. package/dist/db/settings-repo.d.ts +11 -0
  152. package/dist/db/settings-repo.d.ts.map +1 -1
  153. package/dist/db/settings-repo.js +25 -0
  154. package/dist/db/step-idempotency.d.ts +51 -0
  155. package/dist/db/step-idempotency.d.ts.map +1 -0
  156. package/dist/db/step-idempotency.js +136 -0
  157. package/dist/history.d.ts +1 -1
  158. package/dist/history.d.ts.map +1 -1
  159. package/dist/i18n.d.ts +5 -0
  160. package/dist/i18n.d.ts.map +1 -1
  161. package/dist/i18n.js +11 -4
  162. package/dist/index.d.ts +140 -6
  163. package/dist/index.d.ts.map +1 -1
  164. package/dist/index.js +480 -18
  165. package/dist/notifications.d.ts +22 -0
  166. package/dist/notifications.d.ts.map +1 -1
  167. package/dist/notifications.js +36 -8
  168. package/dist/profiles.d.ts.map +1 -1
  169. package/dist/profiles.js +25 -4
  170. package/dist/rpc.d.ts +924 -0
  171. package/dist/rpc.d.ts.map +1 -1
  172. package/dist/rpc.js +352 -0
  173. package/dist/server.d.ts +46 -0
  174. package/dist/server.d.ts.map +1 -1
  175. package/dist/server.js +172 -53
  176. package/dist/settings.d.ts +2 -2
  177. package/dist/settings.d.ts.map +1 -1
  178. package/dist/settings.js +3 -3
  179. package/dist/shared/jobs-view.d.ts +1 -1
  180. package/dist/shared/jobs-view.d.ts.map +1 -1
  181. package/dist/shared/jobs-view.js +2 -0
  182. package/dist/task-transfer.d.ts +16 -0
  183. package/dist/task-transfer.d.ts.map +1 -1
  184. package/dist/task-transfer.js +16 -0
  185. package/dist/types.d.ts.map +1 -1
  186. package/dist/types.js +7 -0
  187. package/dist/workspaces.d.ts +25 -3
  188. package/dist/workspaces.d.ts.map +1 -1
  189. package/dist/workspaces.js +43 -8
  190. package/docs/ARCHITECTURE.md +498 -58
  191. package/docs/COMPATIBILITY.md +2 -2
  192. package/docs/CONCEPT.md +185 -91
  193. package/docs/CROSS_PLATFORM.ru.md +20 -0
  194. package/docs/CROSS_PLATFORM.zh.md +18 -0
  195. package/docs/EXECUTION-LOOP.md +211 -0
  196. package/docs/FEATURES.md +65 -4
  197. package/docs/FEATURES.zh.md +52 -4
  198. package/docs/MIGRATION.md +2 -2
  199. package/docs/PIPELINE.md +293 -0
  200. package/docs/README.ru.md +44 -5
  201. package/docs/README.zh.md +46 -6
  202. package/docs/SAFETY.md +142 -0
  203. package/docs/SAVINGS.md +29 -0
  204. package/docs/SAVINGS.ru.md +29 -0
  205. package/docs/SAVINGS.zh.md +18 -0
  206. package/gui-experimental.cjs +9 -8
  207. package/locales/en.json +84 -1
  208. package/locales/ru.json +84 -1
  209. package/locales/zh.json +84 -1
  210. package/opencode.pipeline.yaml +35 -0
  211. package/package.json +46 -2
  212. package/scripts/audit-bundle.mjs +215 -0
  213. package/scripts/test-home.mjs +83 -0
  214. package/src/cli.ts +412 -0
  215. package/src/core/dlq-api.ts +98 -0
  216. package/src/core/dry-run.ts +27 -3
  217. package/src/core/execution.ts +538 -0
  218. package/src/core/file-watcher.ts +2 -2
  219. package/src/core/gate-integrity.ts +160 -0
  220. package/src/core/git-trigger.ts +18 -5
  221. package/src/core/guard-run.ts +119 -0
  222. package/src/core/guard.ts +431 -0
  223. package/src/core/lock.ts +244 -30
  224. package/src/core/matrix.ts +95 -50
  225. package/src/core/mission.ts +485 -0
  226. package/src/core/native-notify.ts +1 -1
  227. package/src/core/one-shot.ts +36 -8
  228. package/src/core/opencode-cli.ts +103 -0
  229. package/src/core/opencode-models.ts +315 -0
  230. package/src/core/pipeline-apply.ts +158 -0
  231. package/src/core/pipeline-io.ts +79 -0
  232. package/src/core/pipeline-map.ts +264 -0
  233. package/src/core/pipeline-spec.ts +775 -0
  234. package/src/core/ps-wrapper.ts +274 -64
  235. package/src/core/record-history.ts +229 -104
  236. package/src/core/router/dispatch.ts +94 -0
  237. package/src/core/router/escalation.ts +129 -0
  238. package/src/core/router/planner.ts +166 -0
  239. package/src/core/router/rules.ts +115 -0
  240. package/src/core/run-panel-api.ts +262 -0
  241. package/src/core/schedule-gate.ts +7 -3
  242. package/src/core/schedule-v2.ts +114 -5
  243. package/src/core/scheduler/at-fallback.ts +190 -5
  244. package/src/core/scheduler/linux.ts +72 -21
  245. package/src/core/scheduler/logs.ts +2 -2
  246. package/src/core/scheduler/mac.ts +174 -14
  247. package/src/core/scheduler/posix.ts +20 -1
  248. package/src/core/scheduler/registry.ts +107 -26
  249. package/src/core/scheduler/run-now.ts +32 -0
  250. package/src/core/scheduler/windows.ts +19 -15
  251. package/src/core/secrets.ts +131 -31
  252. package/src/core/session.ts +23 -10
  253. package/src/core/structured-log.ts +22 -5
  254. package/src/core/task-name.ts +67 -0
  255. package/src/core/telegram.ts +2 -2
  256. package/src/core/triage-worker.ts +7 -7
  257. package/src/core/triage.ts +2 -2
  258. package/src/core/worktree-run.ts +199 -0
  259. package/src/core/worktree.ts +600 -0
  260. package/src/core/wrappers/bash.ts +239 -27
  261. package/src/db/capability-repo.ts +402 -0
  262. package/src/db/history-repo.ts +151 -22
  263. package/src/db/index.ts +37 -1
  264. package/src/db/metrics-repo.ts +2 -2
  265. package/src/db/migrate.ts +3 -1
  266. package/src/db/recovery.ts +5 -4
  267. package/src/db/run-context.ts +370 -0
  268. package/src/db/run-dlq.ts +310 -0
  269. package/src/db/run-journal.ts +100 -13
  270. package/src/db/run-resume.ts +65 -13
  271. package/src/db/runs-repo.ts +66 -13
  272. package/src/db/schema.ts +218 -3
  273. package/src/db/settings-repo.ts +31 -0
  274. package/src/db/step-idempotency.ts +185 -0
  275. package/src/gui.tsx +692 -13
  276. package/src/history.ts +1 -1
  277. package/src/i18n.ts +12 -4
  278. package/src/index.ts +648 -8
  279. package/src/notifications.ts +38 -8
  280. package/src/profiles.ts +26 -4
  281. package/src/rpc.ts +379 -0
  282. package/src/server.ts +206 -54
  283. package/src/settings.ts +5 -5
  284. package/src/shared/jobs-view.ts +3 -1
  285. package/src/task-transfer.ts +31 -0
  286. package/src/types.ts +9 -0
  287. package/src/workspaces.ts +58 -9
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Спринт 32 (Pipeline-as-code, 0.0.5): маппинг `PipelineSpec` → `TaskDefinition[]`.
3
+ *
4
+ * Модуль чистый: не читает БД и не трогает планировщик. Всё, что требует
5
+ * состояния (разрешение имён workspace в id), передаётся через опции.
6
+ * Маркеры `pipelineName` / `pipelineStepId` сохраняются в definition_json,
7
+ * чтобы идемпотентный apply мог отличать шаги pipeline от «чужих» задач.
8
+ */
9
+ import type { MatrixConfig, TaskDefinition } from "../task-transfer.js";
10
+ import {
11
+ PIPELINE_VERSION,
12
+ pipelineStepTaskName,
13
+ type PipelineMatrix,
14
+ type PipelineSpec,
15
+ type PipelineStep,
16
+ type PipelineTrigger,
17
+ type PipelineWindowPolicy,
18
+ } from "./pipeline-spec.js";
19
+
20
+ export interface PipelineMapOptions {
21
+ /**
22
+ * Разрешение имени workspace в id. Если не задано, значения
23
+ * `matrix.workspaces` считаются уже id. Apply передаёт резолвер из БД.
24
+ */
25
+ resolveWorkspaceId?: (nameOrId: string) => string | undefined;
26
+ }
27
+
28
+ export interface PipelineTaskMapping {
29
+ tasks: TaskDefinition[];
30
+ warnings: string[];
31
+ }
32
+
33
+ /**
34
+ * Преобразует провалидированный pipeline в определения задач.
35
+ *
36
+ * Правила:
37
+ * - `trigger: dag` → задача без собственного триггера (`triggerType: "file"`),
38
+ * как матричные родители: её запускает только DAG-движок по `dependsOn`;
39
+ * - `needs` → `dependsOn` с именами задач (`<pipeline> <step>`);
40
+ * - `defaults` наследуются шагом;
41
+ * - матрица `workspaces` переносится в `matrix.workspaceIds`.
42
+ */
43
+ export function pipelineSpecToTasks(
44
+ spec: PipelineSpec,
45
+ options: PipelineMapOptions = {},
46
+ ): PipelineTaskMapping {
47
+ const defaults = spec.defaults ?? {};
48
+ const warnings: string[] = [];
49
+
50
+ const nameByStep = new Map<string, string>();
51
+ for (const step of spec.steps) {
52
+ const explicit = step.name?.trim();
53
+ nameByStep.set(
54
+ step.id.toLowerCase(),
55
+ explicit || pipelineStepTaskName(spec.name, step.id),
56
+ );
57
+ }
58
+
59
+ const tasks = spec.steps.map((step) => {
60
+ const trigger = step.trigger ?? defaults.trigger ?? "cron";
61
+ const scheduleValue = step.schedule ?? defaults.schedule ?? "";
62
+ const schedule = trigger === "cron" ? scheduleValue : "";
63
+
64
+ const dependsOn = step.needs?.length
65
+ ? step.needs.map((need) => nameByStep.get(need.toLowerCase())!)
66
+ : undefined;
67
+
68
+ const task: TaskDefinition = {
69
+ name: nameByStep.get(step.id.toLowerCase())!,
70
+ schedule,
71
+ prompt: step.prompt,
72
+ // TaskDefinition не знает "dag": ручной триггер "file" не регистрирует
73
+ // cron, задачу запускает DAG-движок после успеха зависимостей.
74
+ triggerType: trigger === "dag" ? "file" : trigger,
75
+ ...(dependsOn ? { dependsOn } : {}),
76
+ ...(step.qualityGate !== undefined ? { qualityGate: step.qualityGate } : {}),
77
+ ...(step.beforeScript !== undefined ? { beforeScript: step.beforeScript } : {}),
78
+ ...(step.afterScript !== undefined ? { afterScript: step.afterScript } : {}),
79
+ ...(step.guards !== undefined ? { guards: step.guards } : {}),
80
+ ...(step.model !== undefined || defaults.model !== undefined
81
+ ? { model: step.model ?? defaults.model }
82
+ : {}),
83
+ ...(step.priority !== undefined || defaults.priority !== undefined
84
+ ? { priority: step.priority ?? defaults.priority }
85
+ : {}),
86
+ ...(step.timeoutSeconds !== undefined || defaults.timeoutSeconds !== undefined
87
+ ? { timeoutSeconds: step.timeoutSeconds ?? defaults.timeoutSeconds }
88
+ : {}),
89
+ ...(step.workingDirectory !== undefined || defaults.workingDirectory !== undefined
90
+ ? { workingDirectory: step.workingDirectory ?? defaults.workingDirectory }
91
+ : {}),
92
+ ...(step.workspaceId !== undefined ? { workspaceId: step.workspaceId } : {}),
93
+ ...(step.retryCount !== undefined || defaults.retryCount !== undefined
94
+ ? { retryCount: step.retryCount ?? defaults.retryCount }
95
+ : {}),
96
+ ...(step.retryDelay !== undefined || defaults.retryDelay !== undefined
97
+ ? { retryDelay: step.retryDelay ?? defaults.retryDelay }
98
+ : {}),
99
+ ...(step.allowedTools !== undefined || defaults.allowedTools !== undefined
100
+ ? { allowedTools: step.allowedTools ?? defaults.allowedTools }
101
+ : {}),
102
+ ...(step.deniedTools !== undefined || defaults.deniedTools !== undefined
103
+ ? { deniedTools: step.deniedTools ?? defaults.deniedTools }
104
+ : {}),
105
+ ...(step.timezone !== undefined || defaults.timezone !== undefined
106
+ ? { timezone: step.timezone ?? defaults.timezone }
107
+ : {}),
108
+ ...(step.notBefore !== undefined ? { notBefore: step.notBefore } : {}),
109
+ ...(step.notAfter !== undefined ? { notAfter: step.notAfter } : {}),
110
+ ...(step.activeDays !== undefined ? { activeDays: step.activeDays } : {}),
111
+ ...(step.windowPolicy !== undefined ? { windowPolicy: step.windowPolicy } : {}),
112
+ ...(trigger === "once" && step.runAt !== undefined ? { runAt: step.runAt } : {}),
113
+ ...(step.matrix ? { matrix: mapMatrix(step.matrix, options, warnings) } : {}),
114
+ pipelineName: spec.name,
115
+ pipelineStepId: step.id,
116
+ };
117
+ return task;
118
+ });
119
+
120
+ return { tasks, warnings };
121
+ }
122
+
123
+ function mapMatrix(
124
+ matrix: PipelineMatrix,
125
+ options: PipelineMapOptions,
126
+ warnings: string[],
127
+ ): MatrixConfig {
128
+ const workspaceIds = matrix.workspaces.map((raw) => {
129
+ const value = raw.trim();
130
+ const resolved = options.resolveWorkspaceId?.(value);
131
+ if (options.resolveWorkspaceId && !resolved) {
132
+ warnings.push(`workspace «${value}» не найден — шаг будет отклонён при apply.`);
133
+ return value;
134
+ }
135
+ return resolved ?? value;
136
+ });
137
+ return {
138
+ workspaceIds,
139
+ ...(matrix.strategy ? { strategy: matrix.strategy } : {}),
140
+ ...(matrix.failureMode ? { failureMode: matrix.failureMode } : {}),
141
+ ...(matrix.aggregation ? { aggregation: matrix.aggregation } : {}),
142
+ ...(matrix.concurrency !== undefined ? { concurrency: matrix.concurrency } : {}),
143
+ ...(matrix.createAggregator !== undefined
144
+ ? { createAggregator: matrix.createAggregator }
145
+ : {}),
146
+ };
147
+ }
148
+
149
+ export interface PipelineExportResult {
150
+ spec: PipelineSpec;
151
+ warnings: string[];
152
+ }
153
+
154
+ /**
155
+ * Обратный маппинг: задачи одного pipeline из БД → `PipelineSpec` для export.
156
+ *
157
+ * Восстанавливает `needs` по `dependsOn`, `matrix.workspaces` по
158
+ * `matrix.workspaceIds`, trigger по `triggerType`. Шаг `dag` неотличим от
159
+ * ручного `file`-шага с зависимостями, поэтому восстанавливается эвристикой:
160
+ * `file`, без cron и watchPath, но с `dependsOn` → `dag`.
161
+ */
162
+ export function tasksToPipelineSpec(
163
+ tasks: TaskDefinition[],
164
+ pipelineName: string,
165
+ ): PipelineExportResult {
166
+ const warnings: string[] = [];
167
+ const own = tasks.filter(
168
+ (task) =>
169
+ task.pipelineName?.toLowerCase() === pipelineName.toLowerCase() &&
170
+ Boolean(task.pipelineStepId),
171
+ );
172
+
173
+ const stepIdByTaskName = new Map<string, string>();
174
+ for (const task of own) {
175
+ const key = task.name.trim().toLowerCase();
176
+ if (key && !stepIdByTaskName.has(key)) {
177
+ stepIdByTaskName.set(key, task.pipelineStepId!);
178
+ }
179
+ }
180
+
181
+ const steps: PipelineStep[] = own.map((task) => {
182
+ const stepId = task.pipelineStepId!;
183
+ const trigger = inferTrigger(task);
184
+ const needs = task.dependsOn
185
+ ?.map((dep) => {
186
+ const id = stepIdByTaskName.get(dep.trim().toLowerCase());
187
+ if (!id) {
188
+ warnings.push(
189
+ `Шаг «${stepId}»: зависимость «${dep}» не входит в pipeline и опущена.`,
190
+ );
191
+ }
192
+ return id;
193
+ })
194
+ .filter((value): value is string => Boolean(value));
195
+
196
+ const defaultName = pipelineStepTaskName(pipelineName, stepId);
197
+ const step: PipelineStep = {
198
+ id: stepId,
199
+ ...(task.name.trim() !== defaultName ? { name: task.name } : {}),
200
+ prompt: task.prompt,
201
+ ...(needs?.length ? { needs } : {}),
202
+ ...(trigger === "cron" && task.schedule ? { schedule: task.schedule } : {}),
203
+ ...(trigger !== "cron" ? { trigger } : {}),
204
+ ...(trigger === "once" && task.runAt !== undefined ? { runAt: task.runAt } : {}),
205
+ ...(task.model !== undefined ? { model: task.model } : {}),
206
+ ...(task.priority !== undefined ? { priority: task.priority } : {}),
207
+ ...(task.timeoutSeconds !== undefined ? { timeoutSeconds: task.timeoutSeconds } : {}),
208
+ ...(task.workingDirectory !== undefined
209
+ ? { workingDirectory: task.workingDirectory }
210
+ : {}),
211
+ ...(task.workspaceId !== undefined ? { workspaceId: task.workspaceId } : {}),
212
+ ...(task.retryCount !== undefined ? { retryCount: task.retryCount } : {}),
213
+ ...(task.retryDelay !== undefined ? { retryDelay: task.retryDelay } : {}),
214
+ ...(task.qualityGate !== undefined ? { qualityGate: task.qualityGate } : {}),
215
+ ...(task.beforeScript !== undefined ? { beforeScript: task.beforeScript } : {}),
216
+ ...(task.afterScript !== undefined ? { afterScript: task.afterScript } : {}),
217
+ ...(task.guards !== undefined ? { guards: task.guards } : {}),
218
+ ...(task.allowedTools !== undefined ? { allowedTools: task.allowedTools } : {}),
219
+ ...(task.deniedTools !== undefined ? { deniedTools: task.deniedTools } : {}),
220
+ ...(task.matrix
221
+ ? {
222
+ matrix: {
223
+ workspaces: task.matrix.workspaceIds,
224
+ ...(task.matrix.strategy ? { strategy: task.matrix.strategy } : {}),
225
+ ...(task.matrix.failureMode ? { failureMode: task.matrix.failureMode } : {}),
226
+ ...(task.matrix.aggregation ? { aggregation: task.matrix.aggregation } : {}),
227
+ ...(task.matrix.concurrency !== undefined
228
+ ? { concurrency: task.matrix.concurrency }
229
+ : {}),
230
+ ...(task.matrix.createAggregator !== undefined
231
+ ? { createAggregator: task.matrix.createAggregator }
232
+ : {}),
233
+ },
234
+ }
235
+ : {}),
236
+ ...(task.timezone !== undefined ? { timezone: task.timezone } : {}),
237
+ ...(task.notBefore !== undefined ? { notBefore: task.notBefore } : {}),
238
+ ...(task.notAfter !== undefined ? { notAfter: task.notAfter } : {}),
239
+ ...(task.activeDays !== undefined ? { activeDays: task.activeDays } : {}),
240
+ ...(task.windowPolicy !== undefined
241
+ ? { windowPolicy: task.windowPolicy }
242
+ : {}),
243
+ };
244
+ return step;
245
+ });
246
+
247
+ return {
248
+ spec: { version: PIPELINE_VERSION, name: pipelineName, steps },
249
+ warnings,
250
+ };
251
+ }
252
+
253
+ function inferTrigger(task: TaskDefinition): PipelineTrigger {
254
+ const trigger = task.triggerType ?? "cron";
255
+ if (
256
+ trigger === "file" &&
257
+ !task.schedule &&
258
+ !task.watchPath &&
259
+ Boolean(task.dependsOn?.length)
260
+ ) {
261
+ return "dag";
262
+ }
263
+ return trigger;
264
+ }