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.
- package/CHANGELOG.md +154 -2
- package/CROSS_PLATFORM.md +19 -0
- package/README.md +54 -9
- package/ROADMAP-STRATEGY.md +23 -20
- package/ROADMAP.md +140 -143
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +351 -0
- package/dist/core/dlq-api.d.ts +44 -0
- package/dist/core/dlq-api.d.ts.map +1 -0
- package/dist/core/dlq-api.js +68 -0
- package/dist/core/dry-run.d.ts.map +1 -1
- package/dist/core/dry-run.js +18 -1
- 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 +61 -4
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +213 -26
- 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/one-shot.d.ts +5 -1
- package/dist/core/one-shot.d.ts.map +1 -1
- package/dist/core/one-shot.js +33 -8
- package/dist/core/opencode-cli.d.ts +28 -0
- package/dist/core/opencode-cli.d.ts.map +1 -0
- package/dist/core/opencode-cli.js +74 -0
- package/dist/core/opencode-models.d.ts +62 -0
- package/dist/core/opencode-models.d.ts.map +1 -0
- package/dist/core/opencode-models.js +277 -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 +261 -63
- package/dist/core/record-history.d.ts +15 -0
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +183 -58
- package/dist/core/router/dispatch.d.ts +36 -0
- package/dist/core/router/dispatch.d.ts.map +1 -0
- package/dist/core/router/dispatch.js +59 -0
- package/dist/core/router/escalation.d.ts +47 -0
- package/dist/core/router/escalation.d.ts.map +1 -0
- package/dist/core/router/escalation.js +87 -0
- package/dist/core/router/planner.d.ts +53 -0
- package/dist/core/router/planner.d.ts.map +1 -0
- package/dist/core/router/planner.js +113 -0
- package/dist/core/router/rules.d.ts +46 -0
- package/dist/core/router/rules.d.ts.map +1 -0
- package/dist/core/router/rules.js +91 -0
- package/dist/core/run-panel-api.d.ts +94 -0
- package/dist/core/run-panel-api.d.ts.map +1 -0
- package/dist/core/run-panel-api.js +169 -0
- package/dist/core/schedule-gate.js +5 -1
- package/dist/core/schedule-v2.d.ts +34 -0
- package/dist/core/schedule-v2.d.ts.map +1 -1
- package/dist/core/schedule-v2.js +91 -5
- package/dist/core/scheduler/at-fallback.d.ts +55 -2
- package/dist/core/scheduler/at-fallback.d.ts.map +1 -1
- package/dist/core/scheduler/at-fallback.js +135 -5
- package/dist/core/scheduler/linux.d.ts +18 -2
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +63 -20
- 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/posix.d.ts.map +1 -1
- package/dist/core/scheduler/posix.js +25 -1
- package/dist/core/scheduler/registry.d.ts +11 -0
- package/dist/core/scheduler/registry.d.ts.map +1 -1
- package/dist/core/scheduler/registry.js +83 -21
- package/dist/core/scheduler/run-now.d.ts +16 -0
- package/dist/core/scheduler/run-now.d.ts.map +1 -0
- package/dist/core/scheduler/run-now.js +28 -0
- 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 +125 -28
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +18 -11
- package/dist/core/structured-log.d.ts +7 -1
- package/dist/core/structured-log.d.ts.map +1 -1
- package/dist/core/task-name.d.ts +24 -0
- package/dist/core/task-name.d.ts.map +1 -0
- package/dist/core/task-name.js +40 -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 +17 -0
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +224 -28
- package/dist/db/capability-repo.d.ts +124 -0
- package/dist/db/capability-repo.d.ts.map +1 -0
- package/dist/db/capability-repo.js +267 -0
- package/dist/db/history-repo.d.ts +46 -5
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +107 -25
- package/dist/db/index.d.ts +4 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +39 -1
- package/dist/db/metrics-repo.js +2 -2
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +3 -1
- package/dist/db/recovery.d.ts.map +1 -1
- package/dist/db/recovery.js +5 -4
- package/dist/db/run-context.d.ts +103 -0
- package/dist/db/run-context.d.ts.map +1 -0
- package/dist/db/run-context.js +224 -0
- package/dist/db/run-dlq.d.ts +100 -0
- package/dist/db/run-dlq.d.ts.map +1 -0
- package/dist/db/run-dlq.js +191 -0
- 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 +10 -2
- package/dist/db/run-resume.d.ts.map +1 -1
- package/dist/db/run-resume.js +39 -13
- package/dist/db/runs-repo.d.ts +32 -7
- package/dist/db/runs-repo.d.ts.map +1 -1
- package/dist/db/runs-repo.js +50 -11
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +216 -3
- package/dist/db/settings-repo.d.ts +11 -0
- package/dist/db/settings-repo.d.ts.map +1 -1
- package/dist/db/settings-repo.js +25 -0
- package/dist/db/step-idempotency.d.ts +51 -0
- package/dist/db/step-idempotency.d.ts.map +1 -0
- package/dist/db/step-idempotency.js +136 -0
- 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 +140 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +480 -18
- 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 +924 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +352 -0
- package/dist/server.d.ts +46 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +172 -53
- 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/dist/types.d.ts.map +1 -1
- package/dist/types.js +7 -0
- package/dist/workspaces.d.ts +25 -3
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +43 -8
- package/docs/ARCHITECTURE.md +498 -58
- package/docs/COMPATIBILITY.md +2 -2
- package/docs/CONCEPT.md +185 -91
- package/docs/CROSS_PLATFORM.ru.md +20 -0
- package/docs/CROSS_PLATFORM.zh.md +18 -0
- package/docs/EXECUTION-LOOP.md +211 -0
- 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 +44 -5
- package/docs/README.zh.md +46 -6
- package/docs/SAFETY.md +142 -0
- package/docs/SAVINGS.md +29 -0
- package/docs/SAVINGS.ru.md +29 -0
- package/docs/SAVINGS.zh.md +18 -0
- package/gui-experimental.cjs +9 -8
- package/locales/en.json +84 -1
- package/locales/ru.json +84 -1
- package/locales/zh.json +84 -1
- package/opencode.pipeline.yaml +35 -0
- package/package.json +46 -2
- package/scripts/audit-bundle.mjs +215 -0
- package/scripts/test-home.mjs +83 -0
- package/src/cli.ts +412 -0
- package/src/core/dlq-api.ts +98 -0
- package/src/core/dry-run.ts +27 -3
- 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 +244 -30
- 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/one-shot.ts +36 -8
- package/src/core/opencode-cli.ts +103 -0
- package/src/core/opencode-models.ts +315 -0
- 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 +274 -64
- package/src/core/record-history.ts +229 -104
- package/src/core/router/dispatch.ts +94 -0
- package/src/core/router/escalation.ts +129 -0
- package/src/core/router/planner.ts +166 -0
- package/src/core/router/rules.ts +115 -0
- package/src/core/run-panel-api.ts +262 -0
- package/src/core/schedule-gate.ts +7 -3
- package/src/core/schedule-v2.ts +114 -5
- package/src/core/scheduler/at-fallback.ts +190 -5
- package/src/core/scheduler/linux.ts +72 -21
- package/src/core/scheduler/logs.ts +2 -2
- package/src/core/scheduler/mac.ts +174 -14
- package/src/core/scheduler/posix.ts +20 -1
- package/src/core/scheduler/registry.ts +107 -26
- package/src/core/scheduler/run-now.ts +32 -0
- package/src/core/scheduler/windows.ts +19 -15
- package/src/core/secrets.ts +131 -31
- package/src/core/session.ts +23 -10
- package/src/core/structured-log.ts +22 -5
- package/src/core/task-name.ts +67 -0
- 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 +239 -27
- package/src/db/capability-repo.ts +402 -0
- package/src/db/history-repo.ts +151 -22
- package/src/db/index.ts +37 -1
- package/src/db/metrics-repo.ts +2 -2
- package/src/db/migrate.ts +3 -1
- package/src/db/recovery.ts +5 -4
- package/src/db/run-context.ts +370 -0
- package/src/db/run-dlq.ts +310 -0
- package/src/db/run-journal.ts +100 -13
- package/src/db/run-resume.ts +65 -13
- package/src/db/runs-repo.ts +66 -13
- package/src/db/schema.ts +218 -3
- package/src/db/settings-repo.ts +31 -0
- package/src/db/step-idempotency.ts +185 -0
- package/src/gui.tsx +692 -13
- package/src/history.ts +1 -1
- package/src/i18n.ts +12 -4
- package/src/index.ts +648 -8
- package/src/notifications.ts +38 -8
- package/src/profiles.ts +26 -4
- package/src/rpc.ts +379 -0
- package/src/server.ts +206 -54
- package/src/settings.ts +5 -5
- package/src/shared/jobs-view.ts +3 -1
- package/src/task-transfer.ts +31 -0
- package/src/types.ts +9 -0
- package/src/workspaces.ts +58 -9
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
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GUI/RPC-фасад над dead-letter queue (Спринт 36.6).
|
|
3
|
+
*
|
|
4
|
+
* Тонкий слой между `src/db/run-dlq.ts` и RPC: приводит вход от GUI к
|
|
5
|
+
* безопасным значениям (статус, лимит), не даёт панике БД выйти наружу и
|
|
6
|
+
* возвращает единый `{ success, error }`-контракт. Логика очереди (идемпотентный
|
|
7
|
+
* enqueue, retry через reopenRun, discard) остаётся в БД-слое.
|
|
8
|
+
*
|
|
9
|
+
* Retry здесь только готовит шаг к повторному выполнению: переоткрывает запуск,
|
|
10
|
+
* переводит шаг в `running` и закрывает запись DLQ. Сам обработчик шага
|
|
11
|
+
* запускает resume (Спринт 36.7), поэтому фасад не притворяется, что шаг уже
|
|
12
|
+
* выполнен.
|
|
13
|
+
*/
|
|
14
|
+
import {
|
|
15
|
+
countDeadLetters,
|
|
16
|
+
discardDeadLetter,
|
|
17
|
+
listDeadLetters,
|
|
18
|
+
retryDeadLetter,
|
|
19
|
+
type DlqEntry,
|
|
20
|
+
type DlqStatus,
|
|
21
|
+
} from "../db/run-dlq.js";
|
|
22
|
+
|
|
23
|
+
/** Фильтр списка: конкретный статус или все записи. */
|
|
24
|
+
export type DlqFilter = DlqStatus | "all";
|
|
25
|
+
|
|
26
|
+
export interface DlqListResult {
|
|
27
|
+
success: boolean;
|
|
28
|
+
entries: DlqEntry[];
|
|
29
|
+
/** Сколько записей открыто (для бейджа в заголовке панели). */
|
|
30
|
+
open: number;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface DlqActionResult {
|
|
35
|
+
success: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
entry?: DlqEntry;
|
|
38
|
+
runId?: string;
|
|
39
|
+
stepName?: string;
|
|
40
|
+
/** true, если retry переоткрыл упавший запуск. */
|
|
41
|
+
runReopened?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function errorText(err: unknown): string {
|
|
45
|
+
return err instanceof Error ? err.message : String(err);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Неизвестный статус трактуем как `open`: безопасный дефолт очереди. */
|
|
49
|
+
export function normalizeDlqFilter(value: unknown): DlqFilter {
|
|
50
|
+
return value === "all" || value === "retried" || value === "discarded" || value === "open"
|
|
51
|
+
? value
|
|
52
|
+
: "open";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeLimit(value: unknown, fallback = 100): number {
|
|
56
|
+
const num = Math.floor(Number(value));
|
|
57
|
+
if (!Number.isFinite(num) || num < 1) return fallback;
|
|
58
|
+
return Math.min(num, 500);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Список записей DLQ и счётчик открытых. */
|
|
62
|
+
export function listDlq(options: { status?: unknown; limit?: unknown } = {}): DlqListResult {
|
|
63
|
+
try {
|
|
64
|
+
const status = normalizeDlqFilter(options.status);
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
entries: listDeadLetters({ status, limit: normalizeLimit(options.limit) }),
|
|
68
|
+
open: countDeadLetters("open"),
|
|
69
|
+
};
|
|
70
|
+
} catch (err) {
|
|
71
|
+
return { success: false, entries: [], open: 0, error: errorText(err) };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Ручной retry: готовит шаг к выполнению и закрывает запись DLQ. */
|
|
76
|
+
export function retryDlq(id: string): DlqActionResult {
|
|
77
|
+
try {
|
|
78
|
+
const result = retryDeadLetter(id);
|
|
79
|
+
return {
|
|
80
|
+
success: true,
|
|
81
|
+
entry: result.entry,
|
|
82
|
+
runId: result.run.id,
|
|
83
|
+
stepName: result.step.stepName,
|
|
84
|
+
runReopened: result.runReopened,
|
|
85
|
+
};
|
|
86
|
+
} catch (err) {
|
|
87
|
+
return { success: false, error: errorText(err) };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Осознанный отказ от повтора: запись закрывается, шаг остаётся failed. */
|
|
92
|
+
export function discardDlq(id: string, resolution = "discarded"): DlqActionResult {
|
|
93
|
+
try {
|
|
94
|
+
return { success: true, entry: discardDeadLetter(id, resolution) };
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return { success: false, error: errorText(err) };
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/core/dry-run.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { loadTaskDefinitions } from "../task-transfer.js";
|
|
|
10
10
|
import { getHistory } from "../db/history-repo.js";
|
|
11
11
|
import { getWorkspace } from "../workspaces.js";
|
|
12
12
|
import { expandMatrixTask } from "./matrix.js";
|
|
13
|
-
import { nextRun, activeWindowState } from "./schedule-v2.js";
|
|
13
|
+
import { nextRun, activeWindowState, assessCronWindowFeasibility, windowFeasibilityReasonText } from "./schedule-v2.js";
|
|
14
14
|
import { checkGitTrigger } from "./git-trigger.js";
|
|
15
15
|
import { t } from "../i18n.js";
|
|
16
16
|
import type { TaskDefinition } from "../task-transfer.js";
|
|
@@ -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
|
});
|
|
@@ -283,6 +283,30 @@ async function describeTrigger(opts: DescribeTriggerOptions): Promise<DryRunTrig
|
|
|
283
283
|
}),
|
|
284
284
|
);
|
|
285
285
|
}
|
|
286
|
+
|
|
287
|
+
// P2-24: даже если сейчас окно откроется, cron может никогда в него не
|
|
288
|
+
// попадать (например, daily 09:00 при окне 22:00–06:00). Предупреждаем
|
|
289
|
+
// заранее — иначе задача молча не выполняется из-за лимита переноса 12 ч.
|
|
290
|
+
if ((def.triggerType ?? "cron") === "cron" && def.schedule) {
|
|
291
|
+
const feasibility = assessCronWindowFeasibility(
|
|
292
|
+
def.schedule,
|
|
293
|
+
{
|
|
294
|
+
notBefore: def.notBefore ?? undefined,
|
|
295
|
+
notAfter: def.notAfter ?? undefined,
|
|
296
|
+
days: def.activeDays ?? undefined,
|
|
297
|
+
timeZone: def.timezone ?? undefined,
|
|
298
|
+
},
|
|
299
|
+
policy,
|
|
300
|
+
);
|
|
301
|
+
if (!feasibility.feasible) {
|
|
302
|
+
warnings.push(
|
|
303
|
+
t("dryRun.window.unreachable", {
|
|
304
|
+
cron: def.schedule,
|
|
305
|
+
reason: windowFeasibilityReasonText(feasibility.reason),
|
|
306
|
+
}),
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
286
310
|
}
|
|
287
311
|
|
|
288
312
|
return base;
|
|
@@ -385,7 +409,7 @@ export async function simulatePipeline(taskName: string): Promise<DryRunReport>
|
|
|
385
409
|
t("dryRun.matrix.parent", { name: def.name, count: clones.length }),
|
|
386
410
|
);
|
|
387
411
|
for (const clone of clones) units.push({ def: clone, matrixParent: def.name });
|
|
388
|
-
} catch (err:
|
|
412
|
+
} catch (err: unknown) {
|
|
389
413
|
const list = warningsPerTask.get(def.name.toLowerCase()) ?? [];
|
|
390
414
|
list.push(
|
|
391
415
|
t("dryRun.matrix.expandError", {
|