agent-steward 0.0.2 → 0.0.4
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 +45 -2
- package/CROSS_PLATFORM.md +11 -9
- package/README.md +11 -10
- package/ROADMAP-STRATEGY.md +93 -44
- package/ROADMAP.md +148 -1017
- package/dist/core/cron-to-schtasks.d.ts +0 -8
- package/dist/core/cron-to-schtasks.d.ts.map +1 -1
- package/dist/core/cron-to-schtasks.js +11 -86
- 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 +19 -2
- package/dist/core/file-watcher.js +9 -9
- package/dist/core/git-trigger.js +4 -4
- package/dist/core/lock.d.ts +20 -4
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +99 -26
- package/dist/core/one-shot.d.ts +31 -5
- package/dist/core/one-shot.d.ts.map +1 -1
- package/dist/core/one-shot.js +78 -10
- 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/otel.js +2 -2
- package/dist/core/ps-wrapper.d.ts +1 -1
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +66 -36
- 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 +78 -54
- 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 +85 -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 +36 -2
- package/dist/core/schedule-v2.d.ts.map +1 -1
- package/dist/core/schedule-v2.js +98 -12
- package/dist/core/scheduler/at-fallback.d.ts +95 -0
- package/dist/core/scheduler/at-fallback.d.ts.map +1 -0
- package/dist/core/scheduler/at-fallback.js +200 -0
- package/dist/core/scheduler/linux.d.ts +13 -2
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +67 -13
- package/dist/core/scheduler/mac.d.ts +14 -8
- package/dist/core/scheduler/mac.d.ts.map +1 -1
- package/dist/core/scheduler/mac.js +71 -22
- package/dist/core/scheduler/posix.d.ts.map +1 -1
- package/dist/core/scheduler/posix.js +37 -2
- package/dist/core/scheduler/registry.d.ts +13 -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 +16 -3
- package/dist/core/scheduler/windows.d.ts.map +1 -1
- package/dist/core/scheduler/windows.js +249 -96
- package/dist/core/secrets.d.ts.map +1 -1
- package/dist/core/secrets.js +127 -30
- package/dist/core/self-analysis.js +55 -55
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +18 -11
- package/dist/core/summary.js +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/triage-chain.js +1 -1
- package/dist/core/triage-worker.js +2 -2
- package/dist/core/triage.js +1 -1
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +82 -37
- package/dist/db/capability-repo.d.ts +83 -0
- package/dist/db/capability-repo.d.ts.map +1 -0
- package/dist/db/capability-repo.js +182 -0
- package/dist/db/history-repo.d.ts +8 -0
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +19 -0
- package/dist/db/index.d.ts +6 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +48 -2
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +3 -1
- 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 +60 -0
- package/dist/db/run-journal.d.ts.map +1 -0
- package/dist/db/run-journal.js +143 -0
- package/dist/db/run-resume.d.ts +51 -0
- package/dist/db/run-resume.d.ts.map +1 -0
- package/dist/db/run-resume.js +156 -0
- package/dist/db/runs-repo.d.ts +128 -0
- package/dist/db/runs-repo.d.ts.map +1 -0
- package/dist/db/runs-repo.js +342 -0
- package/dist/db/schema.d.ts +16 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +342 -35
- 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/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +168 -40
- package/dist/notifications.js +18 -18
- package/dist/profiles.d.ts +7 -3
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +85 -7
- package/dist/rpc.d.ts +787 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +324 -0
- package/dist/server.d.ts +33 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +115 -54
- package/dist/shared/jobs-view.d.ts.map +1 -1
- package/dist/skill.js +1 -1
- package/dist/task-transfer.d.ts +1 -1
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +14 -10
- package/dist/types.d.ts +20 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +44 -9
- package/dist/workspaces.d.ts +25 -3
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +44 -9
- package/docs/ARCHITECTURE.md +335 -9
- package/docs/COMPATIBILITY.md +10 -6
- package/docs/CONCEPT.md +183 -91
- package/docs/CROSS_PLATFORM.ru.md +11 -9
- package/docs/CROSS_PLATFORM.zh.md +11 -9
- package/docs/EXECUTION-LOOP.md +196 -0
- package/docs/FAQ.md +2 -2
- package/docs/FAQ.ru.md +2 -2
- package/docs/FAQ.zh.md +2 -2
- package/docs/FEATURES.md +5 -4
- package/docs/FEATURES.zh.md +5 -4
- package/docs/MIGRATION.md +34 -26
- package/docs/README.ru.md +27 -8
- package/docs/README.zh.md +11 -10
- package/docs/SAFETY.md +122 -0
- package/docs/SAVINGS.md +29 -0
- package/docs/SAVINGS.ru.md +29 -0
- package/docs/SAVINGS.zh.md +18 -0
- package/docs/V1-V2-COMPATIBILITY-PLAN.md +6 -6
- package/gui-experimental.cjs +8 -8
- package/index.js +1 -0
- package/locales/en.json +68 -0
- package/locales/ru.json +68 -0
- package/locales/zh.json +68 -0
- package/package.json +57 -11
- package/scripts/audit-bundle.mjs +215 -0
- package/src/core/analytics.ts +2 -2
- package/src/core/audit.ts +17 -17
- package/src/core/cron-to-schtasks.ts +14 -93
- package/src/core/dlq-api.ts +98 -0
- package/src/core/dry-run.ts +51 -27
- package/src/core/file-watcher.ts +17 -17
- package/src/core/git-trigger.ts +9 -9
- package/src/core/glob.ts +1 -1
- package/src/core/local-ai.ts +2 -2
- package/src/core/lock.ts +104 -31
- package/src/core/matrix.ts +31 -31
- package/src/core/native-notify.ts +2 -2
- package/src/core/one-shot.ts +91 -13
- package/src/core/opencode-cli.ts +103 -0
- package/src/core/opencode-models.ts +315 -0
- package/src/core/otel.ts +4 -4
- package/src/core/permissions.ts +5 -5
- package/src/core/prometheus.ts +17 -17
- package/src/core/ps-wrapper.ts +68 -38
- package/src/core/record-history.ts +114 -76
- package/src/core/retention.ts +3 -3
- 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 +109 -0
- package/src/core/run-panel-api.ts +262 -0
- package/src/core/savings.ts +1 -1
- package/src/core/schedule-gate.ts +17 -13
- package/src/core/schedule-v2.ts +138 -29
- package/src/core/scheduler/at-fallback.ts +298 -0
- package/src/core/scheduler/index.ts +3 -3
- package/src/core/scheduler/linux.ts +92 -19
- package/src/core/scheduler/logs.ts +1 -1
- package/src/core/scheduler/mac.ts +112 -60
- package/src/core/scheduler/posix.ts +35 -2
- package/src/core/scheduler/registry.ts +109 -26
- package/src/core/scheduler/run-now.ts +32 -0
- package/src/core/scheduler/windows.ts +295 -125
- package/src/core/secrets.ts +139 -39
- package/src/core/self-analysis.ts +61 -61
- package/src/core/session.ts +26 -13
- package/src/core/structured-log.ts +3 -3
- package/src/core/summary.ts +25 -25
- package/src/core/task-name.ts +67 -0
- package/src/core/telegram.ts +16 -16
- package/src/core/triage-chain.ts +4 -4
- package/src/core/triage-compare.ts +8 -8
- package/src/core/triage-rules.ts +4 -4
- package/src/core/triage-shadow.ts +7 -7
- package/src/core/triage-worker.ts +6 -6
- package/src/core/triage.ts +23 -23
- package/src/core/watch-paths.ts +1 -1
- package/src/core/wrappers/bash.ts +90 -45
- package/src/db/capability-repo.ts +285 -0
- package/src/db/git-state-repo.ts +1 -1
- package/src/db/history-repo.ts +44 -22
- package/src/db/index.ts +53 -7
- package/src/db/metrics-repo.ts +10 -10
- package/src/db/migrate.ts +13 -11
- package/src/db/recovery.ts +3 -3
- package/src/db/run-context.ts +370 -0
- package/src/db/run-dlq.ts +310 -0
- package/src/db/run-journal.ts +212 -0
- package/src/db/run-resume.ts +256 -0
- package/src/db/runs-repo.ts +504 -0
- package/src/db/schema.ts +357 -44
- package/src/db/settings-repo.ts +33 -2
- package/src/db/step-idempotency.ts +185 -0
- package/src/db/tasks-repo.ts +10 -10
- package/src/db/templates-repo.ts +7 -7
- package/src/gui.tsx +516 -1
- package/src/history.ts +4 -4
- package/src/i18n.ts +7 -7
- package/src/index.ts +465 -308
- package/src/integrations.ts +6 -6
- package/src/notifications.ts +76 -76
- package/src/profiles.ts +98 -7
- package/src/rpc.ts +347 -1
- package/src/schtasks.ts +2 -2
- package/src/server.ts +155 -78
- package/src/settings.ts +44 -44
- package/src/shared/jobs-view.ts +60 -60
- package/src/skill.ts +1 -1
- package/src/task-transfer.ts +58 -56
- package/src/templates.ts +1 -1
- package/src/types.ts +54 -10
- package/src/workspaces.ts +73 -24
- package/dist/core/self-analysis.test.d.ts +0 -2
- package/dist/core/self-analysis.test.d.ts.map +0 -1
- package/dist/core/self-analysis.test.js +0 -219
- package/dist/gui-experimental.cjs +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { runTaskNow } from "./scheduler/run-now.js";
|
|
4
5
|
import { createSchedulerBackend } from "./scheduler/index.js";
|
|
5
6
|
import { notifyTaskCompletion } from "../notifications.js";
|
|
6
|
-
import { finishRun,
|
|
7
|
-
import {
|
|
7
|
+
import { finishRun, getLatestHistoryByTask, recordRun, startRun } from "../db/history-repo.js";
|
|
8
|
+
import { deleteSetting, decrementCounterSetting } from "../db/settings-repo.js";
|
|
8
9
|
import { getTask, listTasks } from "../db/tasks-repo.js";
|
|
9
10
|
import { rotateSessionIfNeeded } from "./session.js";
|
|
10
11
|
import type { TaskDefinition } from "../task-transfer.js";
|
|
@@ -16,7 +17,12 @@ import {
|
|
|
16
17
|
|
|
17
18
|
type Status = "success" | "error" | "timeout";
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
/** Префикс ключа настроек со счётчиком повторов конкретной задачи. */
|
|
21
|
+
const RETRY_STATE_PREFIX = "retry_state:";
|
|
22
|
+
|
|
23
|
+
function retryStateKey(taskName: string): string {
|
|
24
|
+
return `${RETRY_STATE_PREFIX}${taskName.toLowerCase()}`;
|
|
25
|
+
}
|
|
20
26
|
|
|
21
27
|
/** Сколько последних строк лога сканировать при поиске токенов/стоимости. */
|
|
22
28
|
const LOG_TAIL_LINES = 500;
|
|
@@ -41,24 +47,24 @@ export interface UsageInfo {
|
|
|
41
47
|
costUsd?: number;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
const USAGE_PREFIX =
|
|
50
|
+
const USAGE_PREFIX = "^\\s*(?:\\[.*?\\]\\s*)?";
|
|
45
51
|
const TOKEN_PATTERNS: RegExp[] = [
|
|
46
|
-
new RegExp(USAGE_PREFIX +
|
|
47
|
-
new RegExp(USAGE_PREFIX +
|
|
52
|
+
new RegExp(USAGE_PREFIX + "(?:tokens?|token\\s+usage|usage)\\s*[:=]\\s*([0-9][0-9.,]*)\\s*([kKmM])?\\b", "i"),
|
|
53
|
+
new RegExp(USAGE_PREFIX + "(?:input|output|total)\\s+tokens?\\s*[:=]?\\s*([0-9][0-9.,]*)\\s*([kKmM])?\\b", "i"),
|
|
48
54
|
];
|
|
49
55
|
const COST_PATTERNS: RegExp[] = [
|
|
50
|
-
new RegExp(USAGE_PREFIX +
|
|
51
|
-
new RegExp(USAGE_PREFIX +
|
|
56
|
+
new RegExp(USAGE_PREFIX + "(?:cost|total\\s+cost)\\s*[:=]?\\s*\\$\\s*([0-9]+(?:[.,][0-9]+)?)", "i"),
|
|
57
|
+
new RegExp(USAGE_PREFIX + "(?:cost|total\\s+cost)\\s*[:=]\\s*([0-9]+(?:[.,][0-9]+)?)\\s*(?:usd|\\$)", "i"),
|
|
52
58
|
];
|
|
53
59
|
|
|
54
60
|
function parseUsageValue(raw: string, suffix?: string): number | undefined {
|
|
55
|
-
const value = parseFloat(raw.replace(
|
|
61
|
+
const value = parseFloat(raw.replace(",", "."));
|
|
56
62
|
if (!Number.isFinite(value)) return undefined;
|
|
57
63
|
let mult = 1;
|
|
58
64
|
if (suffix) {
|
|
59
65
|
const s = suffix.toLowerCase();
|
|
60
|
-
if (s ===
|
|
61
|
-
else if (s ===
|
|
66
|
+
if (s === "k") mult = 1000;
|
|
67
|
+
else if (s === "m") mult = 1000000;
|
|
62
68
|
}
|
|
63
69
|
return Math.round(value * mult);
|
|
64
70
|
}
|
|
@@ -94,7 +100,7 @@ export function parseUsageFromLog(logFile: string): UsageInfo {
|
|
|
94
100
|
for (const pattern of COST_PATTERNS) {
|
|
95
101
|
const m = text.match(pattern);
|
|
96
102
|
if (m) {
|
|
97
|
-
result.costUsd = parseFloat(m[1].replace(
|
|
103
|
+
result.costUsd = parseFloat(m[1].replace(",", "."));
|
|
98
104
|
break;
|
|
99
105
|
}
|
|
100
106
|
}
|
|
@@ -124,37 +130,24 @@ async function loadRetryConfig(taskName: string): Promise<{ count: number; delay
|
|
|
124
130
|
*/
|
|
125
131
|
async function triggerTask(taskName: string): Promise<boolean> {
|
|
126
132
|
try {
|
|
127
|
-
await
|
|
133
|
+
await runTaskNow(taskName);
|
|
128
134
|
return true;
|
|
129
135
|
} catch (err: any) {
|
|
130
136
|
console.error(
|
|
131
|
-
`[
|
|
137
|
+
`[agent-steward] Не удалось запустить задачу цепочки "${taskName}": ${
|
|
132
138
|
err instanceof Error ? err.message : String(err)
|
|
133
|
-
}
|
|
139
|
+
}`,
|
|
134
140
|
);
|
|
135
141
|
return false;
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async function writeRetryState(state: RetryState): Promise<void> {
|
|
148
|
-
setSetting(RETRY_STATE_KEY, state);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async function clearRetryState(taskName: string): Promise<void> {
|
|
152
|
-
const state = await loadRetryState();
|
|
153
|
-
const key = Object.keys(state).find((k) => k.toLowerCase() === taskName.toLowerCase());
|
|
154
|
-
if (!key) return;
|
|
155
|
-
delete state[key];
|
|
156
|
-
await writeRetryState(state);
|
|
157
|
-
}
|
|
145
|
+
/*
|
|
146
|
+
* P2-30: раньше счётчики повторов лежали одним JSON-объектом в настройках.
|
|
147
|
+
* Каждое завершение задачи — отдельный процесс record-history, поэтому
|
|
148
|
+
* параллельные завершения перезаписывали map и теряли декременты. Теперь
|
|
149
|
+
* на задачу отдельный ключ и атомарный UPDATE ... RETURNING.
|
|
150
|
+
*/
|
|
158
151
|
|
|
159
152
|
/**
|
|
160
153
|
* Планирует повторный запуск упавшей задачи.
|
|
@@ -169,21 +162,15 @@ async function scheduleRetry(taskName: string): Promise<boolean> {
|
|
|
169
162
|
const { count, delay } = await loadRetryConfig(taskName);
|
|
170
163
|
if (count <= 0) return false;
|
|
171
164
|
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const remaining = Object.prototype.hasOwnProperty.call(state, key)
|
|
175
|
-
? Number(state[key]) || 0
|
|
176
|
-
: count;
|
|
165
|
+
const key = retryStateKey(taskName);
|
|
166
|
+
const remaining = decrementCounterSetting(key, count);
|
|
177
167
|
|
|
178
|
-
if (remaining
|
|
179
|
-
|
|
180
|
-
console.log(`[
|
|
168
|
+
if (remaining === null) {
|
|
169
|
+
deleteSetting(key);
|
|
170
|
+
console.log(`[agent-steward] Повторы для "${taskName}" исчерпаны.`);
|
|
181
171
|
return false;
|
|
182
172
|
}
|
|
183
173
|
|
|
184
|
-
state[key] = remaining - 1;
|
|
185
|
-
await writeRetryState(state);
|
|
186
|
-
|
|
187
174
|
const script = process.argv[1];
|
|
188
175
|
if (!script) return false;
|
|
189
176
|
|
|
@@ -197,15 +184,15 @@ async function scheduleRetry(taskName: string): Promise<boolean> {
|
|
|
197
184
|
child.unref();
|
|
198
185
|
|
|
199
186
|
console.log(
|
|
200
|
-
`[
|
|
201
|
-
`(осталось повторов: ${remaining
|
|
187
|
+
`[agent-steward] Задача "${taskName}" будет повторена через ${delay} с ` +
|
|
188
|
+
`(осталось повторов: ${remaining}).`,
|
|
202
189
|
);
|
|
203
190
|
return true;
|
|
204
191
|
} catch (err: any) {
|
|
205
192
|
console.error(
|
|
206
|
-
`[
|
|
193
|
+
`[agent-steward] Не удалось запланировать повтор "${taskName}": ${
|
|
207
194
|
err instanceof Error ? err.message : String(err)
|
|
208
|
-
}
|
|
195
|
+
}`,
|
|
209
196
|
);
|
|
210
197
|
return false;
|
|
211
198
|
}
|
|
@@ -221,13 +208,13 @@ async function runRetry(taskName: string, delaySec: number): Promise<void> {
|
|
|
221
208
|
await new Promise<void>((resolve) => setTimeout(resolve, delay * 1000));
|
|
222
209
|
|
|
223
210
|
try {
|
|
224
|
-
await
|
|
225
|
-
console.log(`[
|
|
211
|
+
await runTaskNow(taskName);
|
|
212
|
+
console.log(`[agent-steward] Повторный запуск задачи "${taskName}".`);
|
|
226
213
|
} catch (err: any) {
|
|
227
214
|
console.error(
|
|
228
|
-
`[
|
|
215
|
+
`[agent-steward] Повторный запуск "${taskName}" не удался: ${
|
|
229
216
|
err instanceof Error ? err.message : String(err)
|
|
230
|
-
}
|
|
217
|
+
}`,
|
|
231
218
|
);
|
|
232
219
|
}
|
|
233
220
|
}
|
|
@@ -245,7 +232,7 @@ async function runRetry(taskName: string, delaySec: number): Promise<void> {
|
|
|
245
232
|
export function selectDependentsToTrigger(
|
|
246
233
|
completedTask: string,
|
|
247
234
|
definitions: TaskDefinition[],
|
|
248
|
-
history: HistoryRecord[]
|
|
235
|
+
history: HistoryRecord[],
|
|
249
236
|
): string[] {
|
|
250
237
|
const key = (value: string) => value.trim().toLowerCase();
|
|
251
238
|
|
|
@@ -278,9 +265,9 @@ export function selectDependentsToTrigger(
|
|
|
278
265
|
const depDefinition = defsByKey.get(key(dep));
|
|
279
266
|
const clones = depDefinition?.matrix
|
|
280
267
|
? definitions.filter(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
268
|
+
(item) =>
|
|
269
|
+
item.matrixParentId && key(item.matrixParentId) === key(dep),
|
|
270
|
+
)
|
|
284
271
|
: [];
|
|
285
272
|
const requiredNames = clones.length > 0 ? clones.map((c) => c.name) : [dep];
|
|
286
273
|
|
|
@@ -318,7 +305,7 @@ export function selectDependentsToTrigger(
|
|
|
318
305
|
priorityByTask.set(key(definition.name), Number(definition.priority) || 5);
|
|
319
306
|
}
|
|
320
307
|
return toTrigger.sort(
|
|
321
|
-
(a, b) => (priorityByTask.get(key(b)) ?? 5) - (priorityByTask.get(key(a)) ?? 5)
|
|
308
|
+
(a, b) => (priorityByTask.get(key(b)) ?? 5) - (priorityByTask.get(key(a)) ?? 5),
|
|
322
309
|
);
|
|
323
310
|
}
|
|
324
311
|
|
|
@@ -352,7 +339,7 @@ async function main() {
|
|
|
352
339
|
return Number.isFinite(num) && num > 0 ? num : undefined;
|
|
353
340
|
};
|
|
354
341
|
const parseHookStatus = (
|
|
355
|
-
value?: string
|
|
342
|
+
value?: string,
|
|
356
343
|
): "success" | "error" | "skipped" | undefined => {
|
|
357
344
|
if (!value || value === "-") return undefined;
|
|
358
345
|
if (value === "success" || value === "error" || value === "skipped") return value;
|
|
@@ -375,7 +362,7 @@ async function main() {
|
|
|
375
362
|
startedAt,
|
|
376
363
|
definition?.workspaceId ?? null,
|
|
377
364
|
definition?.allowedTools ?? null,
|
|
378
|
-
definition?.deniedTools ?? null
|
|
365
|
+
definition?.deniedTools ?? null,
|
|
379
366
|
);
|
|
380
367
|
console.log(String(runId));
|
|
381
368
|
return;
|
|
@@ -433,11 +420,11 @@ async function main() {
|
|
|
433
420
|
costResolved,
|
|
434
421
|
model,
|
|
435
422
|
preFlightStatus,
|
|
436
|
-
postFlightStatus
|
|
423
|
+
postFlightStatus,
|
|
437
424
|
);
|
|
438
425
|
if (!completed) {
|
|
439
426
|
console.error(
|
|
440
|
-
`[
|
|
427
|
+
`[agent-steward] record-history: запись #${runId} уже завершена или не найдена.`,
|
|
441
428
|
);
|
|
442
429
|
return;
|
|
443
430
|
}
|
|
@@ -491,12 +478,57 @@ async function main() {
|
|
|
491
478
|
new Date().toISOString(),
|
|
492
479
|
definition?.workspaceId ?? null,
|
|
493
480
|
definition?.allowedTools ?? null,
|
|
494
|
-
definition?.deniedTools ?? null
|
|
481
|
+
definition?.deniedTools ?? null,
|
|
495
482
|
);
|
|
496
483
|
|
|
497
484
|
await handleCompletion(taskName, st, chainTarget, error, durationMs, tokens, costUsd);
|
|
498
485
|
}
|
|
499
486
|
|
|
487
|
+
/** Зависимости для тестируемой очистки one-shot (P2-27). */
|
|
488
|
+
export interface OneShotCleanupDeps {
|
|
489
|
+
platform?: NodeJS.Platform;
|
|
490
|
+
getDefinition?: (name: string) => TaskDefinition | undefined;
|
|
491
|
+
deleteTask?: (name: string) => Promise<void>;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Удаляет отработавшую ONCE-задачу из Планировщика Windows.
|
|
496
|
+
*
|
|
497
|
+
* `schtasks /create ... /z` должен был делать это сам, но на Win10/11
|
|
498
|
+
* возвращает «The task XML is missing a required element ... EndBoundary»
|
|
499
|
+
* и задача вообще не создаётся. Поэтому чистим после запуска вручную.
|
|
500
|
+
* На Linux/macOS очистка не нужна: `at` и launchd убирают one-shot сами.
|
|
501
|
+
*/
|
|
502
|
+
export async function cleanupWindowsOneShotTask(
|
|
503
|
+
taskName: string,
|
|
504
|
+
deps: OneShotCleanupDeps = {},
|
|
505
|
+
): Promise<boolean> {
|
|
506
|
+
const platform = deps.platform ?? process.platform;
|
|
507
|
+
if (platform !== "win32") return false;
|
|
508
|
+
|
|
509
|
+
const getDefinition = deps.getDefinition ?? getTask;
|
|
510
|
+
const definition = getDefinition(taskName);
|
|
511
|
+
if (!definition || definition.triggerType !== "once") return false;
|
|
512
|
+
|
|
513
|
+
const deleteTask =
|
|
514
|
+
deps.deleteTask ??
|
|
515
|
+
((name: string) => createSchedulerBackend().deleteTask(name));
|
|
516
|
+
try {
|
|
517
|
+
await deleteTask(taskName);
|
|
518
|
+
console.log(
|
|
519
|
+
`[agent-steward] One-shot "${taskName}": задача удалена из Планировщика Windows.`,
|
|
520
|
+
);
|
|
521
|
+
return true;
|
|
522
|
+
} catch (err: any) {
|
|
523
|
+
console.warn(
|
|
524
|
+
`[agent-steward] One-shot "${taskName}": не удалось удалить задачу из Планировщика Windows: ${
|
|
525
|
+
err instanceof Error ? err.message : String(err)
|
|
526
|
+
}`,
|
|
527
|
+
);
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
500
532
|
/**
|
|
501
533
|
* Общая пост-обработка завершённого запуска: уведомление, цепочки задач,
|
|
502
534
|
* DAG-зависимости и повторы. Используется и legacy-режимом, и --finish.
|
|
@@ -508,7 +540,7 @@ async function handleCompletion(
|
|
|
508
540
|
error: string | null,
|
|
509
541
|
durationMs: number,
|
|
510
542
|
tokens?: number | null,
|
|
511
|
-
costUsd?: number | null
|
|
543
|
+
costUsd?: number | null,
|
|
512
544
|
): Promise<void> {
|
|
513
545
|
// Уведомление о завершении (webhook). Ошибки отправки логируются внутри
|
|
514
546
|
// и не влияют на историю, цепочки и повторы.
|
|
@@ -516,6 +548,11 @@ async function handleCompletion(
|
|
|
516
548
|
asyncTriage: true,
|
|
517
549
|
});
|
|
518
550
|
|
|
551
|
+
// P2-27: Windows не удаляет ONCE-задачи сам, а флаг schtasks `/z` на
|
|
552
|
+
// практике ломает создание задачи («task XML ... EndBoundary»).
|
|
553
|
+
// Поэтому снимаем отработавшую one-shot задачу из Планировщика здесь.
|
|
554
|
+
await cleanupWindowsOneShotTask(taskName);
|
|
555
|
+
|
|
519
556
|
// Matrix (Спринт 15): клон завершился — двигаем sequential-цепочку или
|
|
520
557
|
// очередь concurrency-лимита (Спринт 17), а когда все клоны готовы —
|
|
521
558
|
// фиксируем агрегат и запускаем matrix-complete.
|
|
@@ -526,17 +563,17 @@ async function handleCompletion(
|
|
|
526
563
|
console.log(
|
|
527
564
|
`[matrix] ${taskName}: ошибка обработки матрицы: ${
|
|
528
565
|
err instanceof Error ? err.message : String(err)
|
|
529
|
-
}
|
|
566
|
+
}`,
|
|
530
567
|
);
|
|
531
568
|
}
|
|
532
569
|
|
|
533
570
|
if (st === "success") {
|
|
534
571
|
// Успешный запуск сбрасывает счётчик повторов.
|
|
535
|
-
await
|
|
572
|
+
await deleteSetting(retryStateKey(taskName));
|
|
536
573
|
if (chainTarget) {
|
|
537
574
|
const started = await triggerTask(chainTarget);
|
|
538
575
|
if (started) {
|
|
539
|
-
console.log(`[
|
|
576
|
+
console.log(`[agent-steward] Запущена следующая задача в цепочке: ${chainTarget}`);
|
|
540
577
|
}
|
|
541
578
|
}
|
|
542
579
|
|
|
@@ -544,22 +581,23 @@ async function handleCompletion(
|
|
|
544
581
|
// зависимостей. Запускаем только если ВСЕ зависимости уже успешны и
|
|
545
582
|
// зависимая задача ещё не запускалась после их завершения.
|
|
546
583
|
try {
|
|
547
|
-
|
|
584
|
+
// P2-29: по одной последней записи на задачу, а не «последние 200 строк».
|
|
585
|
+
const history = getLatestHistoryByTask() as HistoryRecord[];
|
|
548
586
|
const definitions = listTasks();
|
|
549
587
|
const dependents = selectDependentsToTrigger(taskName, definitions, history);
|
|
550
588
|
for (const dependent of dependents) {
|
|
551
589
|
const started = await triggerTask(dependent);
|
|
552
590
|
if (started) {
|
|
553
591
|
console.log(
|
|
554
|
-
`[
|
|
592
|
+
`[agent-steward] DAG: все зависимости выполнены, запущена задача "${dependent}".`,
|
|
555
593
|
);
|
|
556
594
|
}
|
|
557
595
|
}
|
|
558
596
|
} catch (err: any) {
|
|
559
597
|
console.error(
|
|
560
|
-
`[
|
|
598
|
+
`[agent-steward] DAG: не удалось запустить зависимые задачи: ${
|
|
561
599
|
err instanceof Error ? err.message : String(err)
|
|
562
|
-
}
|
|
600
|
+
}`,
|
|
563
601
|
);
|
|
564
602
|
}
|
|
565
603
|
} else {
|
|
@@ -569,7 +607,7 @@ async function handleCompletion(
|
|
|
569
607
|
if (!retryScheduled && chainTarget) {
|
|
570
608
|
const started = await triggerTask(chainTarget);
|
|
571
609
|
if (started) {
|
|
572
|
-
console.log(`[
|
|
610
|
+
console.log(`[agent-steward] Запущена компенсирующая задача: ${chainTarget}`);
|
|
573
611
|
}
|
|
574
612
|
}
|
|
575
613
|
}
|
|
@@ -580,9 +618,9 @@ async function handleCompletion(
|
|
|
580
618
|
await rotateSessionIfNeeded(taskName);
|
|
581
619
|
} catch (err: any) {
|
|
582
620
|
console.warn(
|
|
583
|
-
`[
|
|
621
|
+
`[agent-steward] Не удалось обновить состояние сессии "${taskName}": ${
|
|
584
622
|
err instanceof Error ? err.message : String(err)
|
|
585
|
-
}
|
|
623
|
+
}`,
|
|
586
624
|
);
|
|
587
625
|
}
|
|
588
626
|
}
|
|
@@ -606,9 +644,9 @@ function isDirectInvocation(): boolean {
|
|
|
606
644
|
if (isDirectInvocation()) {
|
|
607
645
|
main().catch((err) => {
|
|
608
646
|
console.error(
|
|
609
|
-
`[
|
|
647
|
+
`[agent-steward] record-history: не удалось записать результат запуска: ${
|
|
610
648
|
err instanceof Error ? err.message : String(err)
|
|
611
|
-
}
|
|
649
|
+
}`,
|
|
612
650
|
);
|
|
613
651
|
process.exit(1);
|
|
614
652
|
});
|
package/src/core/retention.ts
CHANGED
|
@@ -52,7 +52,7 @@ function normalizeOverride(value: unknown): number | undefined {
|
|
|
52
52
|
|
|
53
53
|
function effectiveLimits(
|
|
54
54
|
settings: HistorySettings,
|
|
55
|
-
overrides: RetentionOverrides
|
|
55
|
+
overrides: RetentionOverrides,
|
|
56
56
|
): { retentionDays: number; maxRecords: number } {
|
|
57
57
|
return {
|
|
58
58
|
retentionDays:
|
|
@@ -67,7 +67,7 @@ function effectiveLimits(
|
|
|
67
67
|
* `cleanup_history` заодно настраивает ретеншн.
|
|
68
68
|
*/
|
|
69
69
|
export async function runHistoryRetention(
|
|
70
|
-
overrides: RetentionOverrides = {}
|
|
70
|
+
overrides: RetentionOverrides = {},
|
|
71
71
|
): Promise<RetentionReport> {
|
|
72
72
|
const settings = await loadSettings();
|
|
73
73
|
const base = settings.history ?? defaultHistorySettings();
|
|
@@ -127,7 +127,7 @@ export async function runHistoryRetention(
|
|
|
127
127
|
* `force` игнорирует интервал (используется в тестах).
|
|
128
128
|
*/
|
|
129
129
|
export async function maybeRunHistoryRetention(
|
|
130
|
-
force = false
|
|
130
|
+
force = false,
|
|
131
131
|
): Promise<RetentionReport | undefined> {
|
|
132
132
|
const settings = await loadSettings();
|
|
133
133
|
const history = settings.history ?? defaultHistorySettings();
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Сборка маршрута шага из слоёв 1–2 (Спринт 36.5.d).
|
|
3
|
+
*
|
|
4
|
+
* Слой 1 отвечает мгновенно по таблице правил, слой 2 — по Capability Map.
|
|
5
|
+
* Модель здесь не участвует: `routeStep` не импортирует planner и ничего не
|
|
6
|
+
* декомпозирует, поэтому известный тип задачи обходится в 0 токенов.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { decideCapabilityRoute } from "../../db/capability-repo.js";
|
|
10
|
+
import type { CapabilityDecision, CapabilityThresholds } from "../../db/capability-repo.js";
|
|
11
|
+
import { normalizeTaskType, routeStaticStep } from "./rules.js";
|
|
12
|
+
import type { RouterExecutor, RouterTransport } from "./rules.js";
|
|
13
|
+
|
|
14
|
+
/** Откуда взято решение о маршруте. */
|
|
15
|
+
export type RouteSource = "static" | "capability";
|
|
16
|
+
|
|
17
|
+
/** Куда направляется шаг: исполнение или ручной разбор. */
|
|
18
|
+
export type RouteTarget = "local" | "cloud" | "review" | "explore";
|
|
19
|
+
|
|
20
|
+
/** Готовый маршрут шага. */
|
|
21
|
+
export interface StepRoute {
|
|
22
|
+
/** Нормализованный тип задачи. */
|
|
23
|
+
taskType: string;
|
|
24
|
+
/** Кто исполняет шаг либо почему шаг уходит человеку. */
|
|
25
|
+
target: RouteTarget;
|
|
26
|
+
/** Транспорт; `null` для `review`/`explore`, где исполнения пока нет. */
|
|
27
|
+
transport: RouterTransport | null;
|
|
28
|
+
/** Исполнитель; `null` для `review`/`explore`. */
|
|
29
|
+
executor: RouterExecutor | null;
|
|
30
|
+
/** Слой, принявший решение. */
|
|
31
|
+
source: RouteSource;
|
|
32
|
+
/** Стабильный код причины: `static-rule` либо решение Capability Map. */
|
|
33
|
+
reason: string;
|
|
34
|
+
/** Решение слоя 2, если он участвовал. */
|
|
35
|
+
decision?: CapabilityDecision;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Строит маршрут для типа задачи: статическое правило, затем Capability Map.
|
|
40
|
+
* Пустой тип — ошибка, а не молчаливый `explore`: маршрутизировать нечего.
|
|
41
|
+
*/
|
|
42
|
+
export function routeStep(
|
|
43
|
+
taskType: string,
|
|
44
|
+
thresholds: CapabilityThresholds = {},
|
|
45
|
+
): StepRoute {
|
|
46
|
+
const key = normalizeTaskType(taskType);
|
|
47
|
+
if (key === "") {
|
|
48
|
+
throw new Error("Пустой тип задачи: маршрутизация невозможна.");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const rule = routeStaticStep(key);
|
|
52
|
+
if (rule !== undefined) {
|
|
53
|
+
return {
|
|
54
|
+
taskType: key,
|
|
55
|
+
target: rule.executor,
|
|
56
|
+
transport: rule.transport,
|
|
57
|
+
executor: rule.executor,
|
|
58
|
+
source: "static",
|
|
59
|
+
reason: "static-rule",
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const decision = decideCapabilityRoute(key, thresholds);
|
|
64
|
+
const target: RouteTarget = decision.target;
|
|
65
|
+
return {
|
|
66
|
+
taskType: key,
|
|
67
|
+
target,
|
|
68
|
+
transport: transportForTarget(target),
|
|
69
|
+
executor: executorForTarget(target),
|
|
70
|
+
source: "capability",
|
|
71
|
+
reason: decision.reason,
|
|
72
|
+
decision,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function transportForTarget(target: RouteTarget): RouterTransport | null {
|
|
77
|
+
if (target === "cloud") {
|
|
78
|
+
return "cloud";
|
|
79
|
+
}
|
|
80
|
+
if (target === "local") {
|
|
81
|
+
return "direct";
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function executorForTarget(target: RouteTarget): RouterExecutor | null {
|
|
87
|
+
if (target === "cloud") {
|
|
88
|
+
return "cloud";
|
|
89
|
+
}
|
|
90
|
+
if (target === "local") {
|
|
91
|
+
return "local";
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Эскалация после провала Quality Gate (Спринт 36.5.d).
|
|
3
|
+
*
|
|
4
|
+
* Правило детерминированное и не обращается ни к БД, ни к модели, ни к сети:
|
|
5
|
+
* провал на локальном исполнителе ведёт в облако, провал в облаке — на ручной
|
|
6
|
+
* review, провал review означает, что автоматических уровней больше нет.
|
|
7
|
+
* Решение принимается по одному флагу `passed`, поэтому его можно вызывать
|
|
8
|
+
* в горячем пути без затрат токенов.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Уровень исполнения, на котором сработал Quality Gate. */
|
|
12
|
+
export type GateTarget = "local" | "cloud" | "review";
|
|
13
|
+
|
|
14
|
+
/** Что делать после проверки гейта. */
|
|
15
|
+
export type EscalationAction =
|
|
16
|
+
| "accept"
|
|
17
|
+
| "escalate-cloud"
|
|
18
|
+
| "escalate-review"
|
|
19
|
+
| "blocked";
|
|
20
|
+
|
|
21
|
+
/** Результат Quality Gate, который видит роутер. */
|
|
22
|
+
export interface GateResult {
|
|
23
|
+
/** Прошёл ли шаг проверку. */
|
|
24
|
+
passed: boolean;
|
|
25
|
+
/** Свободное пояснение для журнала и уведомлений. */
|
|
26
|
+
reason?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Решение об эскалации с текущего уровня. */
|
|
30
|
+
export interface EscalationDecision {
|
|
31
|
+
/** Уровень, на котором гейт сработал. */
|
|
32
|
+
from: GateTarget;
|
|
33
|
+
/** Куда переходим (при `accept` совпадает с `from`). */
|
|
34
|
+
next: GateTarget;
|
|
35
|
+
action: EscalationAction;
|
|
36
|
+
/** Почему принято решение: стабильный код, а не текст ошибки. */
|
|
37
|
+
reason: "gate-passed" | "local-failed" | "cloud-failed" | "review-failed";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Следующий уровень эскалации или `null`, если уровни закончились. */
|
|
41
|
+
const NEXT_TARGET: Readonly<Record<GateTarget, GateTarget | null>> = Object.freeze(
|
|
42
|
+
{
|
|
43
|
+
local: "cloud",
|
|
44
|
+
cloud: "review",
|
|
45
|
+
review: null,
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
/** Сколько автоматических эскалаций допускает цепочка local → cloud → review. */
|
|
50
|
+
export const MAX_ESCALATION_STEPS = 2;
|
|
51
|
+
|
|
52
|
+
function assertTarget(target: GateTarget): void {
|
|
53
|
+
if (!Object.prototype.hasOwnProperty.call(NEXT_TARGET, target)) {
|
|
54
|
+
throw new Error(`Неизвестный уровень гейта: ${String(target)}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function assertGate(gate: GateResult): void {
|
|
59
|
+
if (gate === null || typeof gate !== "object") {
|
|
60
|
+
throw new Error("Результат Quality Gate должен быть объектом.");
|
|
61
|
+
}
|
|
62
|
+
if (typeof gate.passed !== "boolean") {
|
|
63
|
+
throw new Error("Результат Quality Gate должен содержать boolean (passed).");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Следующий уровень эскалации; `null` — автоматических уровней больше нет. */
|
|
68
|
+
export function nextGateTarget(current: GateTarget): GateTarget | null {
|
|
69
|
+
assertTarget(current);
|
|
70
|
+
return NEXT_TARGET[current];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Исчерпаны ли автоматические уровни для текущего исполнителя. */
|
|
74
|
+
export function isEscalationExhausted(current: GateTarget): boolean {
|
|
75
|
+
return nextGateTarget(current) === null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Решает, что делать после гейта: принять результат или подняться на уровень
|
|
80
|
+
* выше. Модель здесь не вызывается — только таблица переходов.
|
|
81
|
+
*/
|
|
82
|
+
export function escalateAfterGate(
|
|
83
|
+
current: GateTarget,
|
|
84
|
+
gate: GateResult,
|
|
85
|
+
): EscalationDecision {
|
|
86
|
+
assertTarget(current);
|
|
87
|
+
assertGate(gate);
|
|
88
|
+
if (gate.passed) {
|
|
89
|
+
return { from: current, next: current, action: "accept", reason: "gate-passed" };
|
|
90
|
+
}
|
|
91
|
+
const next = NEXT_TARGET[current];
|
|
92
|
+
if (next === null) {
|
|
93
|
+
return {
|
|
94
|
+
from: current,
|
|
95
|
+
next: current,
|
|
96
|
+
action: "blocked",
|
|
97
|
+
reason: "review-failed",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (next === "cloud") {
|
|
101
|
+
return {
|
|
102
|
+
from: current,
|
|
103
|
+
next,
|
|
104
|
+
action: "escalate-cloud",
|
|
105
|
+
reason: "local-failed",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
from: current,
|
|
110
|
+
next,
|
|
111
|
+
action: "escalate-review",
|
|
112
|
+
reason: "cloud-failed",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Полная цепочка уровней, которые предстоит пройти начиная с текущего
|
|
118
|
+
* (включая его). Полезно для dry-run и объяснения решения оператору.
|
|
119
|
+
*/
|
|
120
|
+
export function escalationChain(current: GateTarget): GateTarget[] {
|
|
121
|
+
assertTarget(current);
|
|
122
|
+
const chain: GateTarget[] = [];
|
|
123
|
+
let target: GateTarget | null = current;
|
|
124
|
+
while (target !== null) {
|
|
125
|
+
chain.push(target);
|
|
126
|
+
target = NEXT_TARGET[target];
|
|
127
|
+
}
|
|
128
|
+
return chain;
|
|
129
|
+
}
|