agent-steward 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +309 -2
- package/CROSS_PLATFORM.md +19 -0
- package/README.md +55 -8
- package/ROADMAP-STRATEGY.md +22 -19
- package/ROADMAP.md +230 -159
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +356 -0
- package/dist/core/analytics.d.ts +6 -0
- package/dist/core/analytics.d.ts.map +1 -1
- package/dist/core/analytics.js +20 -3
- package/dist/core/audit.d.ts +6 -0
- package/dist/core/audit.d.ts.map +1 -1
- package/dist/core/audit.js +24 -0
- package/dist/core/budget.d.ts +118 -0
- package/dist/core/budget.d.ts.map +1 -0
- package/dist/core/budget.js +206 -0
- package/dist/core/cron-to-schtasks.d.ts.map +1 -1
- package/dist/core/cron-to-schtasks.js +38 -0
- package/dist/core/dry-run.d.ts +26 -1
- package/dist/core/dry-run.d.ts.map +1 -1
- package/dist/core/dry-run.js +199 -8
- package/dist/core/execution.d.ts +203 -0
- package/dist/core/execution.d.ts.map +1 -0
- package/dist/core/execution.js +309 -0
- package/dist/core/feedback.d.ts +192 -0
- package/dist/core/feedback.d.ts.map +1 -0
- package/dist/core/feedback.js +426 -0
- package/dist/core/gate-integrity.d.ts +71 -0
- package/dist/core/gate-integrity.d.ts.map +1 -0
- package/dist/core/gate-integrity.js +275 -0
- package/dist/core/git-trigger.d.ts.map +1 -1
- package/dist/core/git-trigger.js +14 -2
- package/dist/core/guard-run.d.ts +4 -0
- package/dist/core/guard-run.d.ts.map +1 -0
- package/dist/core/guard-run.js +101 -0
- package/dist/core/guard.d.ts +52 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +362 -0
- package/dist/core/local-ai.d.ts.map +1 -1
- package/dist/core/local-ai.js +7 -3
- package/dist/core/lock.d.ts +41 -0
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +141 -29
- package/dist/core/matrix.d.ts +8 -0
- package/dist/core/matrix.d.ts.map +1 -1
- package/dist/core/matrix.js +132 -17
- package/dist/core/mission.d.ts +103 -0
- package/dist/core/mission.d.ts.map +1 -0
- package/dist/core/mission.js +374 -0
- package/dist/core/opencode-models.d.ts +2 -2
- package/dist/core/opencode-models.d.ts.map +1 -1
- package/dist/core/opencode-models.js +28 -21
- package/dist/core/opencode-usage.d.ts +35 -0
- package/dist/core/opencode-usage.d.ts.map +1 -0
- package/dist/core/opencode-usage.js +132 -0
- package/dist/core/pipeline-apply.d.ts +38 -0
- package/dist/core/pipeline-apply.d.ts.map +1 -0
- package/dist/core/pipeline-apply.js +117 -0
- package/dist/core/pipeline-io.d.ts +13 -0
- package/dist/core/pipeline-io.d.ts.map +1 -0
- package/dist/core/pipeline-io.js +78 -0
- package/dist/core/pipeline-map.d.ts +52 -0
- package/dist/core/pipeline-map.d.ts.map +1 -0
- package/dist/core/pipeline-map.js +208 -0
- package/dist/core/pipeline-spec.d.ts +109 -0
- package/dist/core/pipeline-spec.d.ts.map +1 -0
- package/dist/core/pipeline-spec.js +554 -0
- package/dist/core/ps-wrapper.d.ts +27 -2
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +424 -65
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +206 -33
- package/dist/core/router/rules.d.ts.map +1 -1
- package/dist/core/router/rules.js +6 -0
- package/dist/core/run-mode.d.ts +12 -0
- package/dist/core/run-mode.d.ts.map +1 -0
- package/dist/core/run-mode.js +17 -0
- package/dist/core/scheduler/linux.d.ts +8 -1
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +34 -9
- package/dist/core/scheduler/logs.d.ts +4 -0
- package/dist/core/scheduler/logs.d.ts.map +1 -1
- package/dist/core/scheduler/logs.js +25 -1
- package/dist/core/scheduler/mac.d.ts +44 -2
- package/dist/core/scheduler/mac.d.ts.map +1 -1
- package/dist/core/scheduler/mac.js +126 -15
- package/dist/core/scheduler/windows.d.ts.map +1 -1
- package/dist/core/scheduler/windows.js +15 -12
- package/dist/core/secrets.d.ts.map +1 -1
- package/dist/core/secrets.js +18 -8
- package/dist/core/self-analysis.d.ts +32 -2
- package/dist/core/self-analysis.d.ts.map +1 -1
- package/dist/core/self-analysis.js +38 -27
- package/dist/core/shutdown.d.ts +33 -2
- package/dist/core/shutdown.d.ts.map +1 -1
- package/dist/core/shutdown.js +58 -2
- package/dist/core/structured-log.d.ts +37 -1
- package/dist/core/structured-log.d.ts.map +1 -1
- package/dist/core/structured-log.js +37 -0
- package/dist/core/usage-surface.d.ts +25 -0
- package/dist/core/usage-surface.d.ts.map +1 -0
- package/dist/core/usage-surface.js +41 -0
- package/dist/core/worktree-run.d.ts +4 -0
- package/dist/core/worktree-run.d.ts.map +1 -0
- package/dist/core/worktree-run.js +164 -0
- package/dist/core/worktree.d.ts +115 -0
- package/dist/core/worktree.d.ts.map +1 -0
- package/dist/core/worktree.js +462 -0
- package/dist/core/wrappers/bash.d.ts +19 -0
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +230 -27
- package/dist/db/capability-repo.d.ts +43 -2
- package/dist/db/capability-repo.d.ts.map +1 -1
- package/dist/db/capability-repo.js +96 -11
- package/dist/db/history-repo.d.ts +70 -5
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +170 -29
- package/dist/db/metrics-repo.d.ts +20 -2
- package/dist/db/metrics-repo.d.ts.map +1 -1
- package/dist/db/metrics-repo.js +35 -13
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +37 -17
- package/dist/db/recovery.d.ts +3 -1
- package/dist/db/recovery.d.ts.map +1 -1
- package/dist/db/recovery.js +11 -5
- package/dist/db/run-journal.d.ts +33 -5
- package/dist/db/run-journal.d.ts.map +1 -1
- package/dist/db/run-journal.js +78 -14
- package/dist/db/run-resume.d.ts +5 -0
- package/dist/db/run-resume.d.ts.map +1 -1
- package/dist/db/run-resume.js +9 -2
- package/dist/db/runs-repo.d.ts +19 -2
- package/dist/db/runs-repo.d.ts.map +1 -1
- package/dist/db/runs-repo.js +91 -60
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +132 -2
- package/dist/db/templates-repo.d.ts +2 -2
- package/dist/db/templates-repo.d.ts.map +1 -1
- package/dist/db/templates-repo.js +5 -3
- package/dist/history.d.ts +7 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +4 -2
- package/dist/hook-output.d.ts +2 -0
- package/dist/hook-output.d.ts.map +1 -0
- package/dist/hook-output.js +31 -0
- package/dist/i18n.d.ts +5 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +11 -4
- package/dist/index.d.ts +375 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1344 -192
- package/dist/notifications.d.ts +53 -2
- package/dist/notifications.d.ts.map +1 -1
- package/dist/notifications.js +168 -21
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +82 -10
- package/dist/rpc.d.ts +354 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +145 -0
- package/dist/server.d.ts +32 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +154 -30
- package/dist/settings.d.ts +44 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +85 -3
- package/dist/shared/jobs-view.d.ts +1 -1
- package/dist/shared/jobs-view.d.ts.map +1 -1
- package/dist/shared/jobs-view.js +2 -0
- package/dist/task-transfer.d.ts +21 -0
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +64 -3
- package/dist/templates.d.ts +2 -2
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +3 -3
- package/dist/types.d.ts +22 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +34 -11
- package/docs/ARCHITECTURE.md +319 -66
- package/docs/COMPATIBILITY.md +2 -2
- package/docs/CONCEPT.md +18 -4
- package/docs/CROSS_PLATFORM.ru.md +20 -0
- package/docs/CROSS_PLATFORM.zh.md +18 -0
- package/docs/EXECUTION-LOOP.md +28 -10
- package/docs/FEATURES.md +129 -7
- package/docs/FEATURES.zh.md +97 -6
- package/docs/MIGRATION.md +2 -2
- package/docs/PIPELINE.md +293 -0
- package/docs/QA-A2-GUI-TUI.md +205 -0
- package/docs/README.ru.md +43 -4
- package/docs/README.zh.md +44 -4
- package/docs/SAFETY.md +23 -3
- package/gui-experimental.cjs +9 -8
- package/locales/en.json +58 -3
- package/locales/ru.json +58 -3
- package/locales/zh.json +58 -3
- package/opencode.pipeline.yaml +35 -0
- package/package.json +36 -4
- package/scripts/check-eslint-baseline.mjs +139 -0
- package/scripts/gen-test-plan-counters.mjs +117 -0
- package/scripts/github-ci-fetch.ps1 +37 -0
- package/scripts/pl-commit.ps1 +112 -0
- package/scripts/qa-a2-commit.ps1 +104 -0
- package/scripts/test-home.mjs +107 -0
- package/skills/scheduled-job-best-practices/SKILL.md +95 -1
- package/skills/scheduled-job-best-practices/references/recipes.md +139 -0
- package/src/cli.ts +417 -0
- package/src/core/analytics.ts +27 -4
- package/src/core/audit.ts +25 -0
- package/src/core/budget.ts +340 -0
- package/src/core/cron-to-schtasks.ts +42 -0
- package/src/core/dry-run.ts +235 -12
- package/src/core/execution.ts +538 -0
- package/src/core/feedback.ts +582 -0
- package/src/core/file-watcher.ts +2 -2
- package/src/core/gate-integrity.ts +330 -0
- package/src/core/git-trigger.ts +18 -5
- package/src/core/guard-run.ts +119 -0
- package/src/core/guard.ts +431 -0
- package/src/core/local-ai.ts +7 -3
- package/src/core/lock.ts +178 -37
- package/src/core/matrix.ts +158 -52
- package/src/core/mission.ts +531 -0
- package/src/core/native-notify.ts +1 -1
- package/src/core/opencode-models.ts +30 -21
- package/src/core/opencode-usage.ts +182 -0
- package/src/core/pipeline-apply.ts +158 -0
- package/src/core/pipeline-io.ts +96 -0
- package/src/core/pipeline-map.ts +283 -0
- package/src/core/pipeline-spec.ts +775 -0
- package/src/core/ps-wrapper.ts +435 -66
- package/src/core/record-history.ts +258 -81
- package/src/core/router/rules.ts +6 -0
- package/src/core/run-mode.ts +19 -0
- package/src/core/schedule-gate.ts +1 -1
- package/src/core/scheduler/at-fallback.ts +1 -1
- package/src/core/scheduler/linux.ts +40 -11
- package/src/core/scheduler/logs.ts +34 -3
- package/src/core/scheduler/mac.ts +174 -14
- package/src/core/scheduler/registry.ts +2 -2
- package/src/core/scheduler/windows.ts +19 -15
- package/src/core/secrets.ts +26 -19
- package/src/core/self-analysis.ts +75 -29
- package/src/core/shutdown.ts +90 -4
- package/src/core/structured-log.ts +89 -5
- package/src/core/telegram.ts +2 -2
- package/src/core/triage-worker.ts +7 -7
- package/src/core/triage.ts +2 -2
- package/src/core/usage-surface.ts +70 -0
- package/src/core/worktree-run.ts +199 -0
- package/src/core/worktree.ts +600 -0
- package/src/core/wrappers/bash.ts +248 -26
- package/src/db/capability-repo.ts +127 -10
- package/src/db/history-repo.ts +281 -40
- package/src/db/metrics-repo.ts +40 -13
- package/src/db/migrate.ts +57 -32
- package/src/db/recovery.ts +12 -5
- package/src/db/run-journal.ts +100 -13
- package/src/db/run-resume.ts +17 -1
- package/src/db/runs-repo.ts +147 -65
- package/src/db/schema.ts +134 -2
- package/src/db/templates-repo.ts +5 -3
- package/src/gui.tsx +438 -18
- package/src/history.ts +11 -4
- package/src/hook-output.ts +39 -0
- package/src/i18n.ts +12 -4
- package/src/index.ts +1902 -320
- package/src/notifications.ts +227 -47
- package/src/profiles.ts +88 -10
- package/src/rpc.ts +158 -0
- package/src/server.ts +201 -41
- package/src/settings.ts +125 -5
- package/src/shared/jobs-view.ts +3 -1
- package/src/task-transfer.ts +90 -6
- package/src/templates.ts +3 -3
- package/src/types.ts +23 -2
- package/src/workspaces.ts +37 -14
|
@@ -0,0 +1,283 @@
|
|
|
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
|
+
* QA-P3.2: проверка, что конвейер действительно существует в наборе задач.
|
|
156
|
+
* `tasksToPipelineSpec` всегда возвращает spec (в т.ч. с нулём шагов), поэтому
|
|
157
|
+
* «не найден» должен определяться здесь, а не по `!result.spec`.
|
|
158
|
+
*/
|
|
159
|
+
export function pipelineExportLookupError(
|
|
160
|
+
tasks: TaskDefinition[],
|
|
161
|
+
pipelineName: string,
|
|
162
|
+
): string | null {
|
|
163
|
+
const hasSteps = tasks.some(
|
|
164
|
+
(task) =>
|
|
165
|
+
task.pipelineName?.toLowerCase() === pipelineName.toLowerCase() &&
|
|
166
|
+
Boolean(task.pipelineStepId),
|
|
167
|
+
);
|
|
168
|
+
return hasSteps
|
|
169
|
+
? null
|
|
170
|
+
: `Конвейер "${pipelineName}" не найден (не найдены задачи с pipelineName=${pipelineName} и pipelineStepId).`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Обратный маппинг: задачи одного pipeline из БД → `PipelineSpec` для export.
|
|
175
|
+
*
|
|
176
|
+
* Восстанавливает `needs` по `dependsOn`, `matrix.workspaces` по
|
|
177
|
+
* `matrix.workspaceIds`, trigger по `triggerType`. Шаг `dag` неотличим от
|
|
178
|
+
* ручного `file`-шага с зависимостями, поэтому восстанавливается эвристикой:
|
|
179
|
+
* `file`, без cron и watchPath, но с `dependsOn` → `dag`.
|
|
180
|
+
*/
|
|
181
|
+
export function tasksToPipelineSpec(
|
|
182
|
+
tasks: TaskDefinition[],
|
|
183
|
+
pipelineName: string,
|
|
184
|
+
): PipelineExportResult {
|
|
185
|
+
const warnings: string[] = [];
|
|
186
|
+
const own = tasks.filter(
|
|
187
|
+
(task) =>
|
|
188
|
+
task.pipelineName?.toLowerCase() === pipelineName.toLowerCase() &&
|
|
189
|
+
Boolean(task.pipelineStepId),
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const stepIdByTaskName = new Map<string, string>();
|
|
193
|
+
for (const task of own) {
|
|
194
|
+
const key = task.name.trim().toLowerCase();
|
|
195
|
+
if (key && !stepIdByTaskName.has(key)) {
|
|
196
|
+
stepIdByTaskName.set(key, task.pipelineStepId!);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const steps: PipelineStep[] = own.map((task) => {
|
|
201
|
+
const stepId = task.pipelineStepId!;
|
|
202
|
+
const trigger = inferTrigger(task);
|
|
203
|
+
const needs = task.dependsOn
|
|
204
|
+
?.map((dep) => {
|
|
205
|
+
const id = stepIdByTaskName.get(dep.trim().toLowerCase());
|
|
206
|
+
if (!id) {
|
|
207
|
+
warnings.push(
|
|
208
|
+
`Шаг «${stepId}»: зависимость «${dep}» не входит в pipeline и опущена.`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return id;
|
|
212
|
+
})
|
|
213
|
+
.filter((value): value is string => Boolean(value));
|
|
214
|
+
|
|
215
|
+
const defaultName = pipelineStepTaskName(pipelineName, stepId);
|
|
216
|
+
const step: PipelineStep = {
|
|
217
|
+
id: stepId,
|
|
218
|
+
...(task.name.trim() !== defaultName ? { name: task.name } : {}),
|
|
219
|
+
prompt: task.prompt,
|
|
220
|
+
...(needs?.length ? { needs } : {}),
|
|
221
|
+
...(trigger === "cron" && task.schedule ? { schedule: task.schedule } : {}),
|
|
222
|
+
...(trigger !== "cron" ? { trigger } : {}),
|
|
223
|
+
...(trigger === "once" && task.runAt !== undefined ? { runAt: task.runAt } : {}),
|
|
224
|
+
...(task.model !== undefined ? { model: task.model } : {}),
|
|
225
|
+
...(task.priority !== undefined ? { priority: task.priority } : {}),
|
|
226
|
+
...(task.timeoutSeconds !== undefined ? { timeoutSeconds: task.timeoutSeconds } : {}),
|
|
227
|
+
...(task.workingDirectory !== undefined
|
|
228
|
+
? { workingDirectory: task.workingDirectory }
|
|
229
|
+
: {}),
|
|
230
|
+
...(task.workspaceId !== undefined ? { workspaceId: task.workspaceId } : {}),
|
|
231
|
+
...(task.retryCount !== undefined ? { retryCount: task.retryCount } : {}),
|
|
232
|
+
...(task.retryDelay !== undefined ? { retryDelay: task.retryDelay } : {}),
|
|
233
|
+
...(task.qualityGate !== undefined ? { qualityGate: task.qualityGate } : {}),
|
|
234
|
+
...(task.beforeScript !== undefined ? { beforeScript: task.beforeScript } : {}),
|
|
235
|
+
...(task.afterScript !== undefined ? { afterScript: task.afterScript } : {}),
|
|
236
|
+
...(task.guards !== undefined ? { guards: task.guards } : {}),
|
|
237
|
+
...(task.allowedTools !== undefined ? { allowedTools: task.allowedTools } : {}),
|
|
238
|
+
...(task.deniedTools !== undefined ? { deniedTools: task.deniedTools } : {}),
|
|
239
|
+
...(task.matrix
|
|
240
|
+
? {
|
|
241
|
+
matrix: {
|
|
242
|
+
workspaces: task.matrix.workspaceIds,
|
|
243
|
+
...(task.matrix.strategy ? { strategy: task.matrix.strategy } : {}),
|
|
244
|
+
...(task.matrix.failureMode ? { failureMode: task.matrix.failureMode } : {}),
|
|
245
|
+
...(task.matrix.aggregation ? { aggregation: task.matrix.aggregation } : {}),
|
|
246
|
+
...(task.matrix.concurrency !== undefined
|
|
247
|
+
? { concurrency: task.matrix.concurrency }
|
|
248
|
+
: {}),
|
|
249
|
+
...(task.matrix.createAggregator !== undefined
|
|
250
|
+
? { createAggregator: task.matrix.createAggregator }
|
|
251
|
+
: {}),
|
|
252
|
+
},
|
|
253
|
+
}
|
|
254
|
+
: {}),
|
|
255
|
+
...(task.timezone !== undefined ? { timezone: task.timezone } : {}),
|
|
256
|
+
...(task.notBefore !== undefined ? { notBefore: task.notBefore } : {}),
|
|
257
|
+
...(task.notAfter !== undefined ? { notAfter: task.notAfter } : {}),
|
|
258
|
+
...(task.activeDays !== undefined ? { activeDays: task.activeDays } : {}),
|
|
259
|
+
...(task.windowPolicy !== undefined
|
|
260
|
+
? { windowPolicy: task.windowPolicy }
|
|
261
|
+
: {}),
|
|
262
|
+
};
|
|
263
|
+
return step;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
spec: { version: PIPELINE_VERSION, name: pipelineName, steps },
|
|
268
|
+
warnings,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function inferTrigger(task: TaskDefinition): PipelineTrigger {
|
|
273
|
+
const trigger = task.triggerType ?? "cron";
|
|
274
|
+
if (
|
|
275
|
+
trigger === "file" &&
|
|
276
|
+
!task.schedule &&
|
|
277
|
+
!task.watchPath &&
|
|
278
|
+
Boolean(task.dependsOn?.length)
|
|
279
|
+
) {
|
|
280
|
+
return "dag";
|
|
281
|
+
}
|
|
282
|
+
return trigger;
|
|
283
|
+
}
|