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
package/src/cli.ts
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI agent-steward (Спринт 32, Pipeline-as-code).
|
|
4
|
+
*
|
|
5
|
+
* Команды:
|
|
6
|
+
* agent-steward pipeline validate <file> [--json]
|
|
7
|
+
* agent-steward pipeline apply <file> [--dry-run] [--json]
|
|
8
|
+
* agent-steward pipeline export --pipeline <name> [--out <file>]
|
|
9
|
+
*
|
|
10
|
+
* Exit-коды: 0 — успех, 1 — ошибки валидации/применения, 2 — неверные аргументы.
|
|
11
|
+
*/
|
|
12
|
+
import { writeFileSync } from "node:fs";
|
|
13
|
+
import { stringify } from "yaml";
|
|
14
|
+
import { closeDb, initDb } from "./db/index.js";
|
|
15
|
+
import { listTasks } from "./db/tasks-repo.js";
|
|
16
|
+
import { loadPipelineFile } from "./core/pipeline-io.js";
|
|
17
|
+
import { executePipelineApply, planPipelineApply } from "./core/pipeline-apply.js";
|
|
18
|
+
import { tasksToPipelineSpec } from "./core/pipeline-map.js";
|
|
19
|
+
import { saveTaskDefinition, type TaskDefinition } from "./task-transfer.js";
|
|
20
|
+
import { listWorkspaces } from "./workspaces.js";
|
|
21
|
+
import { runMission, type MissionSpec } from "./core/mission.js";
|
|
22
|
+
|
|
23
|
+
const USAGE = `agent-steward — планировщик agent jobs
|
|
24
|
+
|
|
25
|
+
Использование:
|
|
26
|
+
agent-steward pipeline validate <file> [--json]
|
|
27
|
+
agent-steward pipeline apply <file> [--dry-run] [--json]
|
|
28
|
+
agent-steward pipeline export --pipeline <name> [--out <file>]
|
|
29
|
+
|
|
30
|
+
Команды:
|
|
31
|
+
validate проверить opencode.pipeline.yaml, не меняя задачи
|
|
32
|
+
apply создать/обновить задачи из файла (идемпотентно)
|
|
33
|
+
export выгрузить задачи pipeline из БД обратно в YAML
|
|
34
|
+
|
|
35
|
+
Опции:
|
|
36
|
+
--json машинный вывод
|
|
37
|
+
--dry-run показать план apply без изменений
|
|
38
|
+
--pipeline имя pipeline для export
|
|
39
|
+
--out файл для export (по умолчанию stdout)
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
interface PrintedIssue {
|
|
43
|
+
path: string;
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function printIssueList(label: string, issues: PrintedIssue[]): void {
|
|
48
|
+
if (issues.length === 0) return;
|
|
49
|
+
console.error(label);
|
|
50
|
+
for (const issue of issues) {
|
|
51
|
+
console.error(` - ${issue.path}: ${issue.message}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function requireFile(args: string[]): string {
|
|
56
|
+
const file = args.find((arg) => !arg.startsWith("--"));
|
|
57
|
+
if (!file) {
|
|
58
|
+
console.error("Не указан файл pipeline.\n");
|
|
59
|
+
console.error(USAGE);
|
|
60
|
+
process.exit(2);
|
|
61
|
+
}
|
|
62
|
+
return file;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function flagValue(args: string[], name: string): string | undefined {
|
|
66
|
+
const index = args.indexOf(name);
|
|
67
|
+
if (index === -1) return undefined;
|
|
68
|
+
const value = args[index + 1];
|
|
69
|
+
if (!value || value.startsWith("--")) {
|
|
70
|
+
console.error(`Опция ${name} требует значение.`);
|
|
71
|
+
process.exit(2);
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function workspaceResolver(): (value: string) => string | undefined {
|
|
77
|
+
const workspaces = listWorkspaces();
|
|
78
|
+
const byId = new Map(workspaces.map((ws) => [ws.id.toLowerCase(), ws.id]));
|
|
79
|
+
const byName = new Map(workspaces.map((ws) => [ws.name.trim().toLowerCase(), ws.id]));
|
|
80
|
+
return (value) => {
|
|
81
|
+
const key = value.trim().toLowerCase();
|
|
82
|
+
return byId.get(key) ?? byName.get(key);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Создаёт задачу через общий путь schedulerCreateTask и сохраняет определение. */
|
|
87
|
+
async function persistDefinition(def: TaskDefinition): Promise<void> {
|
|
88
|
+
const { schedulerCreateTask } = await import("./index.js");
|
|
89
|
+
await schedulerCreateTask(
|
|
90
|
+
def.name,
|
|
91
|
+
def.schedule,
|
|
92
|
+
def.prompt,
|
|
93
|
+
def.timeoutSeconds,
|
|
94
|
+
def.workingDirectory,
|
|
95
|
+
def.retryCount,
|
|
96
|
+
def.retryDelay,
|
|
97
|
+
def.qualityGate,
|
|
98
|
+
def.nextTaskOnSuccess,
|
|
99
|
+
def.nextTaskOnError,
|
|
100
|
+
def.triggerType,
|
|
101
|
+
def.watchPath,
|
|
102
|
+
def.dependsOn,
|
|
103
|
+
def.model,
|
|
104
|
+
def.priority,
|
|
105
|
+
def.beforeScript,
|
|
106
|
+
def.afterScript,
|
|
107
|
+
def.mcpEvent,
|
|
108
|
+
def.workspaceId,
|
|
109
|
+
def.allowedTools,
|
|
110
|
+
def.deniedTools,
|
|
111
|
+
def.matrix,
|
|
112
|
+
def.matrixParentId,
|
|
113
|
+
"create",
|
|
114
|
+
def.timezone,
|
|
115
|
+
def.notBefore,
|
|
116
|
+
def.notAfter,
|
|
117
|
+
def.pausedUntil,
|
|
118
|
+
def.runAt,
|
|
119
|
+
def.session,
|
|
120
|
+
def.sessionId,
|
|
121
|
+
def.sessionMaxRuns,
|
|
122
|
+
{
|
|
123
|
+
activeDays: def.activeDays,
|
|
124
|
+
windowPolicy: def.windowPolicy,
|
|
125
|
+
watchGlobs: def.watchGlobs,
|
|
126
|
+
watchIgnore: def.watchIgnore,
|
|
127
|
+
gitBranch: def.gitBranch,
|
|
128
|
+
gitPaths: def.gitPaths,
|
|
129
|
+
gitIgnore: def.gitIgnore,
|
|
130
|
+
gitPollSeconds: def.gitPollSeconds,
|
|
131
|
+
},
|
|
132
|
+
def.runWhenLoggedOff,
|
|
133
|
+
def.paused,
|
|
134
|
+
def.legacyShell,
|
|
135
|
+
);
|
|
136
|
+
await saveTaskDefinition(def);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function runValidate(args: string[]): Promise<number> {
|
|
140
|
+
const file = requireFile(args);
|
|
141
|
+
const json = args.includes("--json");
|
|
142
|
+
const result = await loadPipelineFile(file);
|
|
143
|
+
|
|
144
|
+
if (json) {
|
|
145
|
+
console.log(
|
|
146
|
+
JSON.stringify(
|
|
147
|
+
{
|
|
148
|
+
ok: result.ok,
|
|
149
|
+
errors: result.errors,
|
|
150
|
+
warnings: result.warnings,
|
|
151
|
+
steps: result.spec?.steps.length ?? 0,
|
|
152
|
+
},
|
|
153
|
+
null,
|
|
154
|
+
2,
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
printIssueList("Ошибки:", result.errors);
|
|
159
|
+
printIssueList("Предупреждения:", result.warnings);
|
|
160
|
+
if (result.ok && result.spec) {
|
|
161
|
+
console.log(
|
|
162
|
+
`OK: «${result.spec.name}», шагов: ${result.spec.steps.length}`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return result.ok ? 0 : 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function runExport(args: string[]): Promise<number> {
|
|
171
|
+
const pipelineName = flagValue(args, "--pipeline");
|
|
172
|
+
if (!pipelineName) {
|
|
173
|
+
console.error("Для export укажите --pipeline <name>.\n");
|
|
174
|
+
console.error(USAGE);
|
|
175
|
+
return 2;
|
|
176
|
+
}
|
|
177
|
+
const out = flagValue(args, "--out");
|
|
178
|
+
|
|
179
|
+
initDb();
|
|
180
|
+
try {
|
|
181
|
+
const exported = tasksToPipelineSpec(listTasks(), pipelineName);
|
|
182
|
+
if (exported.spec.steps.length === 0) {
|
|
183
|
+
console.error(`Pipeline «${pipelineName}» не найден в БД.`);
|
|
184
|
+
return 1;
|
|
185
|
+
}
|
|
186
|
+
for (const warning of exported.warnings) console.error(`Предупреждение: ${warning}`);
|
|
187
|
+
const yaml = stringify(exported.spec, { lineWidth: 0 });
|
|
188
|
+
if (out) {
|
|
189
|
+
writeFileSync(out, yaml, "utf8");
|
|
190
|
+
console.log(`Записано: ${out} (шагов: ${exported.spec.steps.length})`);
|
|
191
|
+
} else {
|
|
192
|
+
process.stdout.write(yaml);
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
} finally {
|
|
196
|
+
closeDb();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function runApply(args: string[]): Promise<number> {
|
|
201
|
+
const file = requireFile(args);
|
|
202
|
+
const dryRun = args.includes("--dry-run");
|
|
203
|
+
const json = args.includes("--json");
|
|
204
|
+
|
|
205
|
+
const parsed = await loadPipelineFile(file);
|
|
206
|
+
if (!parsed.ok || !parsed.spec) {
|
|
207
|
+
printIssueList("Ошибки:", parsed.errors);
|
|
208
|
+
printIssueList("Предупреждения:", parsed.warnings);
|
|
209
|
+
return 1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
initDb();
|
|
213
|
+
try {
|
|
214
|
+
const plan = planPipelineApply(parsed.spec, listTasks(), {
|
|
215
|
+
resolveWorkspaceId: workspaceResolver(),
|
|
216
|
+
});
|
|
217
|
+
for (const warning of plan.warnings) console.error(`Предупреждение: ${warning}`);
|
|
218
|
+
|
|
219
|
+
if (!dryRun) {
|
|
220
|
+
await executePipelineApply(plan, {
|
|
221
|
+
create: persistDefinition,
|
|
222
|
+
update: persistDefinition,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const summary = {
|
|
227
|
+
pipeline: parsed.spec.name,
|
|
228
|
+
dryRun,
|
|
229
|
+
creates: plan.creates.map((task) => task.name),
|
|
230
|
+
updates: plan.updates.map((entry) => entry.task.name),
|
|
231
|
+
unchanged: plan.unchanged.map((task) => task.name),
|
|
232
|
+
stale: plan.stale.map((task) => task.name),
|
|
233
|
+
};
|
|
234
|
+
if (json) {
|
|
235
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
236
|
+
} else {
|
|
237
|
+
const verb = dryRun ? "Будет создано" : "Создано";
|
|
238
|
+
console.log(`${verb}: ${summary.creates.length}`);
|
|
239
|
+
console.log(`Обновлено: ${summary.updates.length}`);
|
|
240
|
+
console.log(`Без изменений: ${summary.unchanged.length}`);
|
|
241
|
+
if (summary.stale.length > 0) {
|
|
242
|
+
console.log(`Устаревшие (не удалены): ${summary.stale.join(", ")}`);
|
|
243
|
+
}
|
|
244
|
+
for (const name of summary.creates) console.log(` + ${name}`);
|
|
245
|
+
for (const name of summary.updates) console.log(` ~ ${name}`);
|
|
246
|
+
}
|
|
247
|
+
return 0;
|
|
248
|
+
} catch (err) {
|
|
249
|
+
console.error(`Ошибка apply: ${err instanceof Error ? err.message : String(err)}`);
|
|
250
|
+
return 1;
|
|
251
|
+
} finally {
|
|
252
|
+
closeDb();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function listFlag(args: string[], name: string): string[] | undefined {
|
|
257
|
+
const value = flagValue(args, name);
|
|
258
|
+
if (value === undefined) return undefined;
|
|
259
|
+
const list = value
|
|
260
|
+
.split(",")
|
|
261
|
+
.map((item) => item.trim())
|
|
262
|
+
.filter(Boolean);
|
|
263
|
+
return list.length > 0 ? list : undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* AB-8.2: `agent-steward run <prompt>` — ad-hoc миссия без регистрации в ОС.
|
|
268
|
+
* Проходит тот же runtime, что и задачи: план → маршрут → GATE → ledger.
|
|
269
|
+
*/
|
|
270
|
+
async function runAdHoc(args: string[]): Promise<number> {
|
|
271
|
+
const valueFlags = new Set([
|
|
272
|
+
"--cwd",
|
|
273
|
+
"--gate",
|
|
274
|
+
"--task-type",
|
|
275
|
+
"--model",
|
|
276
|
+
"--timeout",
|
|
277
|
+
"--policy",
|
|
278
|
+
"--allow-tools",
|
|
279
|
+
"--deny-tools",
|
|
280
|
+
"--session",
|
|
281
|
+
"--session-id",
|
|
282
|
+
"--name",
|
|
283
|
+
]);
|
|
284
|
+
let prompt: string | undefined;
|
|
285
|
+
for (let index = 0; index < args.length; index++) {
|
|
286
|
+
const arg = args[index];
|
|
287
|
+
if (arg.startsWith("--")) {
|
|
288
|
+
if (valueFlags.has(arg)) index++;
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
prompt = arg;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
if (!prompt?.trim()) {
|
|
295
|
+
console.error(
|
|
296
|
+
"agent-steward run <prompt> [--cwd <dir>] [--gate <cmd>] [--task-type <type>] " +
|
|
297
|
+
"[--model <model>] [--timeout <sec>] [--policy hybrid|secure|legacy] " +
|
|
298
|
+
"[--allow-tools a,b] [--deny-tools a,b] [--session new|reuse|last] " +
|
|
299
|
+
"[--session-id ses_...] [--name <name>] [--dry-run] [--json]",
|
|
300
|
+
);
|
|
301
|
+
return 2;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const json = args.includes("--json");
|
|
305
|
+
const timeoutRaw = flagValue(args, "--timeout");
|
|
306
|
+
const timeoutSeconds = timeoutRaw === undefined ? undefined : Number(timeoutRaw);
|
|
307
|
+
if (timeoutSeconds !== undefined && (!Number.isInteger(timeoutSeconds) || timeoutSeconds <= 0)) {
|
|
308
|
+
console.error("--timeout должен быть целым положительным числом секунд.");
|
|
309
|
+
return 2;
|
|
310
|
+
}
|
|
311
|
+
const policyRaw = flagValue(args, "--policy");
|
|
312
|
+
if (policyRaw && !["hybrid", "secure", "legacy"].includes(policyRaw)) {
|
|
313
|
+
console.error("--policy должен быть hybrid, secure или legacy.");
|
|
314
|
+
return 2;
|
|
315
|
+
}
|
|
316
|
+
const sessionRaw = flagValue(args, "--session");
|
|
317
|
+
if (sessionRaw && !["new", "reuse", "last"].includes(sessionRaw)) {
|
|
318
|
+
console.error("--session должен быть new, reuse или last.");
|
|
319
|
+
return 2;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const spec: MissionSpec = {
|
|
323
|
+
prompt,
|
|
324
|
+
cwd: flagValue(args, "--cwd"),
|
|
325
|
+
taskName: flagValue(args, "--name"),
|
|
326
|
+
taskType: flagValue(args, "--task-type"),
|
|
327
|
+
model: flagValue(args, "--model"),
|
|
328
|
+
session: sessionRaw as MissionSpec["session"],
|
|
329
|
+
sessionId: flagValue(args, "--session-id"),
|
|
330
|
+
timeoutSeconds,
|
|
331
|
+
gate: flagValue(args, "--gate"),
|
|
332
|
+
gateTimeoutSeconds: undefined,
|
|
333
|
+
policy: policyRaw as MissionSpec["policy"],
|
|
334
|
+
allowedTools: listFlag(args, "--allow-tools"),
|
|
335
|
+
deniedTools: listFlag(args, "--deny-tools"),
|
|
336
|
+
dryRun: args.includes("--dry-run"),
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
initDb();
|
|
340
|
+
try {
|
|
341
|
+
const result = await runMission(spec);
|
|
342
|
+
if (json) {
|
|
343
|
+
console.log(
|
|
344
|
+
JSON.stringify(
|
|
345
|
+
{
|
|
346
|
+
success: result.success,
|
|
347
|
+
dryRun: result.dryRun,
|
|
348
|
+
runId: result.runId,
|
|
349
|
+
status: result.status,
|
|
350
|
+
description: result.description,
|
|
351
|
+
error: result.error,
|
|
352
|
+
logFile: result.logFile,
|
|
353
|
+
steps: result.steps,
|
|
354
|
+
},
|
|
355
|
+
null,
|
|
356
|
+
2,
|
|
357
|
+
),
|
|
358
|
+
);
|
|
359
|
+
} else {
|
|
360
|
+
console.log(result.description);
|
|
361
|
+
for (const step of result.steps) {
|
|
362
|
+
console.log(` ${step.stepName}: ${step.status} (attempt ${step.attempt})`);
|
|
363
|
+
}
|
|
364
|
+
if (result.error) console.error(`Ошибка: ${result.error}`);
|
|
365
|
+
if (result.logFile) console.log(`Лог: ${result.logFile}`);
|
|
366
|
+
if (result.runId) console.log(`Запуск: ${result.runId}`);
|
|
367
|
+
}
|
|
368
|
+
return result.success ? 0 : 1;
|
|
369
|
+
} catch (err) {
|
|
370
|
+
console.error(`Ошибка миссии: ${err instanceof Error ? err.message : String(err)}`);
|
|
371
|
+
return 1;
|
|
372
|
+
} finally {
|
|
373
|
+
closeDb();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async function main(argv: string[]): Promise<number> {
|
|
378
|
+
const [group, command, ...rest] = argv;
|
|
379
|
+
if (group === "--help" || group === "-h" || group === "help" || !group) {
|
|
380
|
+
console.log(USAGE);
|
|
381
|
+
return group ? 0 : 2;
|
|
382
|
+
}
|
|
383
|
+
if (group === "run") {
|
|
384
|
+
return runAdHoc([command, ...rest].filter((value): value is string => Boolean(value)));
|
|
385
|
+
}
|
|
386
|
+
if (group !== "pipeline") {
|
|
387
|
+
console.error(`Неизвестная команда «${group}».\n`);
|
|
388
|
+
console.error(USAGE);
|
|
389
|
+
return 2;
|
|
390
|
+
}
|
|
391
|
+
switch (command) {
|
|
392
|
+
case "validate":
|
|
393
|
+
return runValidate(rest);
|
|
394
|
+
case "apply":
|
|
395
|
+
return runApply(rest);
|
|
396
|
+
case "export":
|
|
397
|
+
return runExport(rest);
|
|
398
|
+
default:
|
|
399
|
+
console.error(`Неизвестная команда pipeline «${command ?? ""}».\n`);
|
|
400
|
+
console.error(USAGE);
|
|
401
|
+
return 2;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
main(process.argv.slice(2))
|
|
406
|
+
.then((code) => {
|
|
407
|
+
process.exitCode = code;
|
|
408
|
+
})
|
|
409
|
+
.catch((err) => {
|
|
410
|
+
console.error(`Ошибка: ${err instanceof Error ? err.message : String(err)}`);
|
|
411
|
+
process.exitCode = 1;
|
|
412
|
+
});
|
package/src/core/dry-run.ts
CHANGED
|
@@ -183,7 +183,7 @@ async function describeTrigger(opts: DescribeTriggerOptions): Promise<DryRunTrig
|
|
|
183
183
|
t("dryRun.git.branchMismatch", { branch: def.gitBranch ?? "" }),
|
|
184
184
|
);
|
|
185
185
|
}
|
|
186
|
-
} catch (err:
|
|
186
|
+
} catch (err: unknown) {
|
|
187
187
|
base.explanation = t("dryRun.git.checkError", {
|
|
188
188
|
error: err instanceof Error ? err.message : String(err),
|
|
189
189
|
});
|
|
@@ -409,7 +409,7 @@ export async function simulatePipeline(taskName: string): Promise<DryRunReport>
|
|
|
409
409
|
t("dryRun.matrix.parent", { name: def.name, count: clones.length }),
|
|
410
410
|
);
|
|
411
411
|
for (const clone of clones) units.push({ def: clone, matrixParent: def.name });
|
|
412
|
-
} catch (err:
|
|
412
|
+
} catch (err: unknown) {
|
|
413
413
|
const list = warningsPerTask.get(def.name.toLowerCase()) ?? [];
|
|
414
414
|
list.push(
|
|
415
415
|
t("dryRun.matrix.expandError", {
|