agent-steward 0.0.4 → 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.
- package/CHANGELOG.md +134 -2
- package/CROSS_PLATFORM.md +19 -0
- package/README.md +52 -7
- package/ROADMAP-STRATEGY.md +21 -18
- package/ROADMAP.md +140 -159
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +351 -0
- 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/gate-integrity.d.ts +35 -0
- package/dist/core/gate-integrity.d.ts.map +1 -0
- package/dist/core/gate-integrity.js +132 -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/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.map +1 -1
- package/dist/core/matrix.js +75 -15
- package/dist/core/mission.d.ts +83 -0
- package/dist/core/mission.d.ts.map +1 -0
- package/dist/core/mission.js +334 -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 +64 -0
- package/dist/core/pipeline-map.d.ts +46 -0
- package/dist/core/pipeline-map.d.ts.map +1 -0
- package/dist/core/pipeline-map.js +196 -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 +19 -2
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +250 -62
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +130 -29
- package/dist/core/router/rules.d.ts.map +1 -1
- package/dist/core/router/rules.js +6 -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/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/structured-log.d.ts +7 -1
- package/dist/core/structured-log.d.ts.map +1 -1
- 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 +17 -0
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +175 -24
- 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 +38 -5
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +88 -25
- package/dist/db/metrics-repo.js +2 -2
- package/dist/db/recovery.d.ts.map +1 -1
- package/dist/db/recovery.js +5 -4
- 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 +22 -6
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +63 -2
- package/dist/history.d.ts +1 -1
- package/dist/history.d.ts.map +1 -1
- 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 +136 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +378 -14
- package/dist/notifications.d.ts +22 -0
- package/dist/notifications.d.ts.map +1 -1
- package/dist/notifications.js +36 -8
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +25 -4
- package/dist/rpc.d.ts +246 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +117 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +77 -18
- package/dist/settings.d.ts +2 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +3 -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 +16 -0
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +16 -0
- package/docs/ARCHITECTURE.md +281 -65
- 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 +22 -7
- package/docs/FEATURES.md +65 -4
- package/docs/FEATURES.zh.md +52 -4
- package/docs/MIGRATION.md +2 -2
- package/docs/PIPELINE.md +293 -0
- package/docs/README.ru.md +42 -3
- package/docs/README.zh.md +43 -3
- package/docs/SAFETY.md +23 -3
- package/gui-experimental.cjs +9 -8
- package/locales/en.json +17 -1
- package/locales/ru.json +17 -1
- package/locales/zh.json +17 -1
- package/opencode.pipeline.yaml +35 -0
- package/package.json +23 -4
- package/scripts/test-home.mjs +83 -0
- package/src/cli.ts +412 -0
- package/src/core/dry-run.ts +2 -2
- package/src/core/execution.ts +538 -0
- package/src/core/file-watcher.ts +2 -2
- package/src/core/gate-integrity.ts +160 -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/lock.ts +178 -37
- package/src/core/matrix.ts +95 -50
- package/src/core/mission.ts +485 -0
- package/src/core/native-notify.ts +1 -1
- package/src/core/pipeline-apply.ts +158 -0
- package/src/core/pipeline-io.ts +79 -0
- package/src/core/pipeline-map.ts +264 -0
- package/src/core/pipeline-spec.ts +775 -0
- package/src/core/ps-wrapper.ts +263 -63
- package/src/core/record-history.ts +164 -77
- package/src/core/router/rules.ts +6 -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 +2 -2
- 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 +8 -8
- package/src/core/structured-log.ts +22 -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/worktree-run.ts +199 -0
- package/src/core/worktree.ts +600 -0
- package/src/core/wrappers/bash.ts +190 -23
- package/src/db/capability-repo.ts +127 -10
- package/src/db/history-repo.ts +129 -22
- package/src/db/metrics-repo.ts +2 -2
- package/src/db/recovery.ts +5 -4
- package/src/db/run-journal.ts +100 -13
- package/src/db/run-resume.ts +17 -1
- package/src/db/runs-repo.ts +36 -6
- package/src/db/schema.ts +65 -2
- package/src/gui.tsx +177 -13
- package/src/history.ts +1 -1
- package/src/i18n.ts +12 -4
- package/src/index.ts +524 -4
- package/src/notifications.ts +38 -8
- package/src/profiles.ts +26 -4
- package/src/rpc.ts +128 -0
- package/src/server.ts +94 -18
- package/src/settings.ts +5 -5
- package/src/shared/jobs-view.ts +3 -1
- package/src/task-transfer.ts +31 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { parseDocument } from "yaml";
|
|
3
|
+
import {
|
|
4
|
+
validatePipelineSpec,
|
|
5
|
+
type PipelineIssue,
|
|
6
|
+
type PipelineSpec,
|
|
7
|
+
type PipelineValidationResult,
|
|
8
|
+
} from "./pipeline-spec.js";
|
|
9
|
+
|
|
10
|
+
/** Результат разбора YAML: спека возвращается только при успешной валидации. */
|
|
11
|
+
export interface PipelineParseResult extends PipelineValidationResult {
|
|
12
|
+
spec?: PipelineSpec;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const MAX_YAML_BYTES = 1024 * 1024;
|
|
16
|
+
const MAX_ALIAS_COUNT = 100;
|
|
17
|
+
|
|
18
|
+
function issueMessage(err: unknown): string {
|
|
19
|
+
return err instanceof Error ? err.message : String(err);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Разбирает YAML-текст в `PipelineSpec` и сразу валидирует его.
|
|
24
|
+
* Функция не бросает: синтаксические и смысловые ошибки возвращаются в `errors`.
|
|
25
|
+
*/
|
|
26
|
+
export function parsePipelineYaml(source: string): PipelineParseResult {
|
|
27
|
+
const errors: PipelineIssue[] = [];
|
|
28
|
+
const warnings: PipelineIssue[] = [];
|
|
29
|
+
|
|
30
|
+
if (source.length > MAX_YAML_BYTES) {
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
errors: [{ path: "$", message: `YAML больше ${MAX_YAML_BYTES} байт` }],
|
|
34
|
+
warnings,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let data: unknown;
|
|
39
|
+
try {
|
|
40
|
+
const doc = parseDocument(source, {
|
|
41
|
+
prettyErrors: true,
|
|
42
|
+
uniqueKeys: true,
|
|
43
|
+
strict: true,
|
|
44
|
+
});
|
|
45
|
+
if (doc.errors.length > 0) {
|
|
46
|
+
for (const err of doc.errors) {
|
|
47
|
+
errors.push({ path: "$", message: err.message });
|
|
48
|
+
}
|
|
49
|
+
return { ok: false, errors, warnings };
|
|
50
|
+
}
|
|
51
|
+
data = doc.toJS({ maxAliasCount: MAX_ALIAS_COUNT });
|
|
52
|
+
} catch (err) {
|
|
53
|
+
return {
|
|
54
|
+
ok: false,
|
|
55
|
+
errors: [{ path: "$", message: issueMessage(err) }],
|
|
56
|
+
warnings,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const result = validatePipelineSpec(data);
|
|
61
|
+
if (!result.ok) return result;
|
|
62
|
+
|
|
63
|
+
return { ...result, spec: data as PipelineSpec };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Читает YAML-файл и валидирует его. Ошибки ввода-вывода также попадают в `errors`. */
|
|
67
|
+
export async function loadPipelineFile(filePath: string): Promise<PipelineParseResult> {
|
|
68
|
+
let source: string;
|
|
69
|
+
try {
|
|
70
|
+
source = await readFile(filePath, "utf8");
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
errors: [{ path: filePath, message: `Не удалось прочитать файл: ${issueMessage(err)}` }],
|
|
75
|
+
warnings: [],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return parsePipelineYaml(source);
|
|
79
|
+
}
|
|
@@ -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
|
+
}
|