agent-steward 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +309 -2
- package/CROSS_PLATFORM.md +19 -0
- package/README.md +55 -8
- package/ROADMAP-STRATEGY.md +22 -19
- package/ROADMAP.md +230 -159
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +356 -0
- package/dist/core/analytics.d.ts +6 -0
- package/dist/core/analytics.d.ts.map +1 -1
- package/dist/core/analytics.js +20 -3
- package/dist/core/audit.d.ts +6 -0
- package/dist/core/audit.d.ts.map +1 -1
- package/dist/core/audit.js +24 -0
- package/dist/core/budget.d.ts +118 -0
- package/dist/core/budget.d.ts.map +1 -0
- package/dist/core/budget.js +206 -0
- package/dist/core/cron-to-schtasks.d.ts.map +1 -1
- package/dist/core/cron-to-schtasks.js +38 -0
- package/dist/core/dry-run.d.ts +26 -1
- package/dist/core/dry-run.d.ts.map +1 -1
- package/dist/core/dry-run.js +199 -8
- package/dist/core/execution.d.ts +203 -0
- package/dist/core/execution.d.ts.map +1 -0
- package/dist/core/execution.js +309 -0
- package/dist/core/feedback.d.ts +192 -0
- package/dist/core/feedback.d.ts.map +1 -0
- package/dist/core/feedback.js +426 -0
- package/dist/core/gate-integrity.d.ts +71 -0
- package/dist/core/gate-integrity.d.ts.map +1 -0
- package/dist/core/gate-integrity.js +275 -0
- package/dist/core/git-trigger.d.ts.map +1 -1
- package/dist/core/git-trigger.js +14 -2
- package/dist/core/guard-run.d.ts +4 -0
- package/dist/core/guard-run.d.ts.map +1 -0
- package/dist/core/guard-run.js +101 -0
- package/dist/core/guard.d.ts +52 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +362 -0
- package/dist/core/local-ai.d.ts.map +1 -1
- package/dist/core/local-ai.js +7 -3
- package/dist/core/lock.d.ts +41 -0
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +141 -29
- package/dist/core/matrix.d.ts +8 -0
- package/dist/core/matrix.d.ts.map +1 -1
- package/dist/core/matrix.js +132 -17
- package/dist/core/mission.d.ts +103 -0
- package/dist/core/mission.d.ts.map +1 -0
- package/dist/core/mission.js +374 -0
- package/dist/core/opencode-models.d.ts +2 -2
- package/dist/core/opencode-models.d.ts.map +1 -1
- package/dist/core/opencode-models.js +28 -21
- package/dist/core/opencode-usage.d.ts +35 -0
- package/dist/core/opencode-usage.d.ts.map +1 -0
- package/dist/core/opencode-usage.js +132 -0
- package/dist/core/pipeline-apply.d.ts +38 -0
- package/dist/core/pipeline-apply.d.ts.map +1 -0
- package/dist/core/pipeline-apply.js +117 -0
- package/dist/core/pipeline-io.d.ts +13 -0
- package/dist/core/pipeline-io.d.ts.map +1 -0
- package/dist/core/pipeline-io.js +78 -0
- package/dist/core/pipeline-map.d.ts +52 -0
- package/dist/core/pipeline-map.d.ts.map +1 -0
- package/dist/core/pipeline-map.js +208 -0
- package/dist/core/pipeline-spec.d.ts +109 -0
- package/dist/core/pipeline-spec.d.ts.map +1 -0
- package/dist/core/pipeline-spec.js +554 -0
- package/dist/core/ps-wrapper.d.ts +27 -2
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +424 -65
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +206 -33
- package/dist/core/router/rules.d.ts.map +1 -1
- package/dist/core/router/rules.js +6 -0
- package/dist/core/run-mode.d.ts +12 -0
- package/dist/core/run-mode.d.ts.map +1 -0
- package/dist/core/run-mode.js +17 -0
- package/dist/core/scheduler/linux.d.ts +8 -1
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +34 -9
- package/dist/core/scheduler/logs.d.ts +4 -0
- package/dist/core/scheduler/logs.d.ts.map +1 -1
- package/dist/core/scheduler/logs.js +25 -1
- package/dist/core/scheduler/mac.d.ts +44 -2
- package/dist/core/scheduler/mac.d.ts.map +1 -1
- package/dist/core/scheduler/mac.js +126 -15
- package/dist/core/scheduler/windows.d.ts.map +1 -1
- package/dist/core/scheduler/windows.js +15 -12
- package/dist/core/secrets.d.ts.map +1 -1
- package/dist/core/secrets.js +18 -8
- package/dist/core/self-analysis.d.ts +32 -2
- package/dist/core/self-analysis.d.ts.map +1 -1
- package/dist/core/self-analysis.js +38 -27
- package/dist/core/shutdown.d.ts +33 -2
- package/dist/core/shutdown.d.ts.map +1 -1
- package/dist/core/shutdown.js +58 -2
- package/dist/core/structured-log.d.ts +37 -1
- package/dist/core/structured-log.d.ts.map +1 -1
- package/dist/core/structured-log.js +37 -0
- package/dist/core/usage-surface.d.ts +25 -0
- package/dist/core/usage-surface.d.ts.map +1 -0
- package/dist/core/usage-surface.js +41 -0
- package/dist/core/worktree-run.d.ts +4 -0
- package/dist/core/worktree-run.d.ts.map +1 -0
- package/dist/core/worktree-run.js +164 -0
- package/dist/core/worktree.d.ts +115 -0
- package/dist/core/worktree.d.ts.map +1 -0
- package/dist/core/worktree.js +462 -0
- package/dist/core/wrappers/bash.d.ts +19 -0
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +230 -27
- package/dist/db/capability-repo.d.ts +43 -2
- package/dist/db/capability-repo.d.ts.map +1 -1
- package/dist/db/capability-repo.js +96 -11
- package/dist/db/history-repo.d.ts +70 -5
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +170 -29
- package/dist/db/metrics-repo.d.ts +20 -2
- package/dist/db/metrics-repo.d.ts.map +1 -1
- package/dist/db/metrics-repo.js +35 -13
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +37 -17
- package/dist/db/recovery.d.ts +3 -1
- package/dist/db/recovery.d.ts.map +1 -1
- package/dist/db/recovery.js +11 -5
- package/dist/db/run-journal.d.ts +33 -5
- package/dist/db/run-journal.d.ts.map +1 -1
- package/dist/db/run-journal.js +78 -14
- package/dist/db/run-resume.d.ts +5 -0
- package/dist/db/run-resume.d.ts.map +1 -1
- package/dist/db/run-resume.js +9 -2
- package/dist/db/runs-repo.d.ts +19 -2
- package/dist/db/runs-repo.d.ts.map +1 -1
- package/dist/db/runs-repo.js +91 -60
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +132 -2
- package/dist/db/templates-repo.d.ts +2 -2
- package/dist/db/templates-repo.d.ts.map +1 -1
- package/dist/db/templates-repo.js +5 -3
- package/dist/history.d.ts +7 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +4 -2
- package/dist/hook-output.d.ts +2 -0
- package/dist/hook-output.d.ts.map +1 -0
- package/dist/hook-output.js +31 -0
- package/dist/i18n.d.ts +5 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +11 -4
- package/dist/index.d.ts +375 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1344 -192
- package/dist/notifications.d.ts +53 -2
- package/dist/notifications.d.ts.map +1 -1
- package/dist/notifications.js +168 -21
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +82 -10
- package/dist/rpc.d.ts +354 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +145 -0
- package/dist/server.d.ts +32 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +154 -30
- package/dist/settings.d.ts +44 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +85 -3
- package/dist/shared/jobs-view.d.ts +1 -1
- package/dist/shared/jobs-view.d.ts.map +1 -1
- package/dist/shared/jobs-view.js +2 -0
- package/dist/task-transfer.d.ts +21 -0
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +64 -3
- package/dist/templates.d.ts +2 -2
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +3 -3
- package/dist/types.d.ts +22 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +34 -11
- package/docs/ARCHITECTURE.md +319 -66
- package/docs/COMPATIBILITY.md +2 -2
- package/docs/CONCEPT.md +18 -4
- package/docs/CROSS_PLATFORM.ru.md +20 -0
- package/docs/CROSS_PLATFORM.zh.md +18 -0
- package/docs/EXECUTION-LOOP.md +28 -10
- package/docs/FEATURES.md +129 -7
- package/docs/FEATURES.zh.md +97 -6
- package/docs/MIGRATION.md +2 -2
- package/docs/PIPELINE.md +293 -0
- package/docs/QA-A2-GUI-TUI.md +205 -0
- package/docs/README.ru.md +43 -4
- package/docs/README.zh.md +44 -4
- package/docs/SAFETY.md +23 -3
- package/gui-experimental.cjs +9 -8
- package/locales/en.json +58 -3
- package/locales/ru.json +58 -3
- package/locales/zh.json +58 -3
- package/opencode.pipeline.yaml +35 -0
- package/package.json +36 -4
- package/scripts/check-eslint-baseline.mjs +139 -0
- package/scripts/gen-test-plan-counters.mjs +117 -0
- package/scripts/github-ci-fetch.ps1 +37 -0
- package/scripts/pl-commit.ps1 +112 -0
- package/scripts/qa-a2-commit.ps1 +104 -0
- package/scripts/test-home.mjs +107 -0
- package/skills/scheduled-job-best-practices/SKILL.md +95 -1
- package/skills/scheduled-job-best-practices/references/recipes.md +139 -0
- package/src/cli.ts +417 -0
- package/src/core/analytics.ts +27 -4
- package/src/core/audit.ts +25 -0
- package/src/core/budget.ts +340 -0
- package/src/core/cron-to-schtasks.ts +42 -0
- package/src/core/dry-run.ts +235 -12
- package/src/core/execution.ts +538 -0
- package/src/core/feedback.ts +582 -0
- package/src/core/file-watcher.ts +2 -2
- package/src/core/gate-integrity.ts +330 -0
- package/src/core/git-trigger.ts +18 -5
- package/src/core/guard-run.ts +119 -0
- package/src/core/guard.ts +431 -0
- package/src/core/local-ai.ts +7 -3
- package/src/core/lock.ts +178 -37
- package/src/core/matrix.ts +158 -52
- package/src/core/mission.ts +531 -0
- package/src/core/native-notify.ts +1 -1
- package/src/core/opencode-models.ts +30 -21
- package/src/core/opencode-usage.ts +182 -0
- package/src/core/pipeline-apply.ts +158 -0
- package/src/core/pipeline-io.ts +96 -0
- package/src/core/pipeline-map.ts +283 -0
- package/src/core/pipeline-spec.ts +775 -0
- package/src/core/ps-wrapper.ts +435 -66
- package/src/core/record-history.ts +258 -81
- package/src/core/router/rules.ts +6 -0
- package/src/core/run-mode.ts +19 -0
- package/src/core/schedule-gate.ts +1 -1
- package/src/core/scheduler/at-fallback.ts +1 -1
- package/src/core/scheduler/linux.ts +40 -11
- package/src/core/scheduler/logs.ts +34 -3
- package/src/core/scheduler/mac.ts +174 -14
- package/src/core/scheduler/registry.ts +2 -2
- package/src/core/scheduler/windows.ts +19 -15
- package/src/core/secrets.ts +26 -19
- package/src/core/self-analysis.ts +75 -29
- package/src/core/shutdown.ts +90 -4
- package/src/core/structured-log.ts +89 -5
- package/src/core/telegram.ts +2 -2
- package/src/core/triage-worker.ts +7 -7
- package/src/core/triage.ts +2 -2
- package/src/core/usage-surface.ts +70 -0
- package/src/core/worktree-run.ts +199 -0
- package/src/core/worktree.ts +600 -0
- package/src/core/wrappers/bash.ts +248 -26
- package/src/db/capability-repo.ts +127 -10
- package/src/db/history-repo.ts +281 -40
- package/src/db/metrics-repo.ts +40 -13
- package/src/db/migrate.ts +57 -32
- package/src/db/recovery.ts +12 -5
- package/src/db/run-journal.ts +100 -13
- package/src/db/run-resume.ts +17 -1
- package/src/db/runs-repo.ts +147 -65
- package/src/db/schema.ts +134 -2
- package/src/db/templates-repo.ts +5 -3
- package/src/gui.tsx +438 -18
- package/src/history.ts +11 -4
- package/src/hook-output.ts +39 -0
- package/src/i18n.ts +12 -4
- package/src/index.ts +1902 -320
- package/src/notifications.ts +227 -47
- package/src/profiles.ts +88 -10
- package/src/rpc.ts +158 -0
- package/src/server.ts +201 -41
- package/src/settings.ts +125 -5
- package/src/shared/jobs-view.ts +3 -1
- package/src/task-transfer.ts +90 -6
- package/src/templates.ts +3 -3
- package/src/types.ts +23 -2
- package/src/workspaces.ts +37 -14
|
@@ -31,13 +31,33 @@ export const MIN_RUNS_FOR_DECISION = 3;
|
|
|
31
31
|
/** Сколько последних исходов хранить (1 — гейт пройден, 0 — провал). */
|
|
32
32
|
export const RECENT_RUNS_LIMIT = 10;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* B13: полураспад веса исхода в последних прогонах. Исход давностью
|
|
36
|
+
* `SUCCESS_HALF_LIFE_RUNS` прогонов весит вдвое меньше свежего.
|
|
37
|
+
*/
|
|
38
|
+
export const SUCCESS_HALF_LIFE_RUNS = 8;
|
|
39
|
+
|
|
40
|
+
/** B13: доля затухающего success rate в итоговой надёжности. */
|
|
41
|
+
export const DECAY_WEIGHT = 0.7;
|
|
42
|
+
|
|
43
|
+
/** B13: доля first-pass rate в итоговой надёжности. */
|
|
44
|
+
export const FIRST_PASS_WEIGHT = 0.3;
|
|
45
|
+
|
|
34
46
|
export interface CapabilityRecord {
|
|
35
47
|
taskType: string;
|
|
36
48
|
/** Исполнитель, который последним обрабатывал тип задачи. */
|
|
37
49
|
model: string;
|
|
38
50
|
runsTotal: number;
|
|
39
51
|
runsPassed: number;
|
|
52
|
+
/** B13: сколько успехов получено с первой попытки. */
|
|
53
|
+
firstPassCount: number;
|
|
54
|
+
/** B13: first_pass_count / runs_total. */
|
|
55
|
+
firstPassRate: number;
|
|
40
56
|
successRate: number;
|
|
57
|
+
/** B13: success rate последних прогонов с экспоненциальным затуханием. */
|
|
58
|
+
decayedSuccessRate: number;
|
|
59
|
+
/** B13: 0.7 * decayedSuccessRate + 0.3 * firstPassRate — вход маршрутизации. */
|
|
60
|
+
effectiveSuccessRate: number;
|
|
41
61
|
avgCostUsd: number;
|
|
42
62
|
avgTimeMs: number;
|
|
43
63
|
/** Последние исходы, старые слева, новые справа, максимум 10. */
|
|
@@ -53,6 +73,10 @@ export interface CapabilityOutcome {
|
|
|
53
73
|
passed: boolean;
|
|
54
74
|
costUsd?: number;
|
|
55
75
|
timeMs?: number;
|
|
76
|
+
/** B13: число попыток до исхода (1 — с первой). */
|
|
77
|
+
attempts?: number;
|
|
78
|
+
/** B13: явный признак first-pass; по умолчанию passed && attempts <= 1. */
|
|
79
|
+
firstPass?: boolean;
|
|
56
80
|
}
|
|
57
81
|
|
|
58
82
|
export interface CapabilityThresholds {
|
|
@@ -67,6 +91,12 @@ export interface CapabilityDecision {
|
|
|
67
91
|
/** Машиночитаемая причина: no-data | local-reliable | escalate | review. */
|
|
68
92
|
reason: "no-data" | "local-reliable" | "escalate" | "review";
|
|
69
93
|
successRate: number;
|
|
94
|
+
/** B13: надёжность с учётом затухания и first-pass, по ней принимается решение. */
|
|
95
|
+
effectiveSuccessRate: number;
|
|
96
|
+
/** B13: затухающий success rate последних прогонов. */
|
|
97
|
+
decayedSuccessRate: number;
|
|
98
|
+
/** B13: доля успехов с первой попытки. */
|
|
99
|
+
firstPassRate: number;
|
|
70
100
|
runsTotal: number;
|
|
71
101
|
capability: CapabilityRecord | null;
|
|
72
102
|
}
|
|
@@ -91,6 +121,14 @@ function requireNonNegative(value: number, field: string): number {
|
|
|
91
121
|
return value;
|
|
92
122
|
}
|
|
93
123
|
|
|
124
|
+
/** B13: номер попытки — целое ≥ 1. */
|
|
125
|
+
function requireAttempts(value: number): number {
|
|
126
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
127
|
+
throw new Error(`Некорректное значение attempts: ожидалось целое ≥ 1, получено ${value}.`);
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
|
|
94
132
|
function parseRecentRuns(raw: unknown): number[] {
|
|
95
133
|
if (typeof raw !== "string" || raw.trim() === "") {
|
|
96
134
|
return [];
|
|
@@ -109,18 +147,64 @@ function parseRecentRuns(raw: unknown): number[] {
|
|
|
109
147
|
}
|
|
110
148
|
}
|
|
111
149
|
|
|
150
|
+
/**
|
|
151
|
+
* B13: экспоненциально взвешенный success rate последних исходов.
|
|
152
|
+
*
|
|
153
|
+
* Свежий исход весит 1, исход давностью `halfLife` прогонов — 0.5.
|
|
154
|
+
* Так старые успехи не перевешивают свежие провалы, а `last_10_runs`
|
|
155
|
+
* участвует в решении, а не только хранится для отчёта.
|
|
156
|
+
*/
|
|
157
|
+
export function decayedSuccessRate(
|
|
158
|
+
runs: number[],
|
|
159
|
+
halfLife: number = SUCCESS_HALF_LIFE_RUNS,
|
|
160
|
+
): number {
|
|
161
|
+
const recent = runs
|
|
162
|
+
.filter((value) => value === 0 || value === 1)
|
|
163
|
+
.slice(-RECENT_RUNS_LIMIT);
|
|
164
|
+
if (recent.length === 0) return 0;
|
|
165
|
+
const hl = Number.isFinite(halfLife) && halfLife > 0 ? halfLife : SUCCESS_HALF_LIFE_RUNS;
|
|
166
|
+
let weighted = 0;
|
|
167
|
+
let weights = 0;
|
|
168
|
+
recent.forEach((value, index) => {
|
|
169
|
+
const age = recent.length - 1 - index;
|
|
170
|
+
const weight = Math.pow(0.5, age / hl);
|
|
171
|
+
weighted += weight * value;
|
|
172
|
+
weights += weight;
|
|
173
|
+
});
|
|
174
|
+
return weights > 0 ? weighted / weights : 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** B13: надёжность для маршрутизации — затухание плюс успех с первой попытки. */
|
|
178
|
+
export function effectiveReliability(decayedRate: number, firstPassRate: number): number {
|
|
179
|
+
const decayed = Math.min(1, Math.max(0, decayedRate));
|
|
180
|
+
const firstPass = Math.min(1, Math.max(0, firstPassRate));
|
|
181
|
+
return DECAY_WEIGHT * decayed + FIRST_PASS_WEIGHT * firstPass;
|
|
182
|
+
}
|
|
183
|
+
|
|
112
184
|
function rowToRecord(row: Record<string, unknown>): CapabilityRecord {
|
|
113
185
|
const runsTotal = Number(row.runs_total) || 0;
|
|
114
186
|
const runsPassed = Number(row.runs_passed) || 0;
|
|
187
|
+
const successRate =
|
|
188
|
+
Number(row.success_rate) || (runsTotal > 0 ? runsPassed / runsTotal : 0);
|
|
189
|
+
const firstPassCount = Number(row.first_pass_count) || 0;
|
|
190
|
+
const firstPassRate =
|
|
191
|
+
runsTotal > 0 ? Math.min(1, firstPassCount / runsTotal) : 0;
|
|
192
|
+
const last10Runs = parseRecentRuns(row.last_10_runs);
|
|
193
|
+
const decayed =
|
|
194
|
+
last10Runs.length > 0 ? decayedSuccessRate(last10Runs) : successRate;
|
|
115
195
|
return {
|
|
116
196
|
taskType: String(row.task_type),
|
|
117
197
|
model: String(row.model ?? DEFAULT_MODEL),
|
|
118
198
|
runsTotal,
|
|
119
199
|
runsPassed,
|
|
120
|
-
|
|
200
|
+
firstPassCount,
|
|
201
|
+
firstPassRate,
|
|
202
|
+
successRate,
|
|
203
|
+
decayedSuccessRate: decayed,
|
|
204
|
+
effectiveSuccessRate: effectiveReliability(decayed, firstPassRate),
|
|
121
205
|
avgCostUsd: Number(row.avg_cost_usd) || 0,
|
|
122
206
|
avgTimeMs: Number(row.avg_time_ms) || 0,
|
|
123
|
-
last10Runs
|
|
207
|
+
last10Runs,
|
|
124
208
|
createdAt: String(row.created_at),
|
|
125
209
|
updatedAt: String(row.updated_at),
|
|
126
210
|
};
|
|
@@ -159,6 +243,16 @@ export function recordCapabilityOutcome(outcome: CapabilityOutcome): CapabilityR
|
|
|
159
243
|
const time = outcome.timeMs === undefined ? 0 : requireNonNegative(outcome.timeMs, "timeMs");
|
|
160
244
|
const model = (outcome.model ?? DEFAULT_MODEL).trim() || DEFAULT_MODEL;
|
|
161
245
|
const passed = outcome.passed ? 1 : 0;
|
|
246
|
+
const attempts = outcome.attempts === undefined ? undefined : requireAttempts(outcome.attempts);
|
|
247
|
+
if (outcome.firstPass !== undefined && typeof outcome.firstPass !== "boolean") {
|
|
248
|
+
throw new Error("Признак firstPass должен быть boolean.");
|
|
249
|
+
}
|
|
250
|
+
// B13: без явного признака успех считается первым, если попытка одна
|
|
251
|
+
// (или число попыток не передано — обратная совместимость).
|
|
252
|
+
const firstPass =
|
|
253
|
+
passed === 1 &&
|
|
254
|
+
(outcome.firstPass ?? (attempts === undefined || attempts === 1));
|
|
255
|
+
const firstPassIncrement = firstPass ? 1 : 0;
|
|
162
256
|
|
|
163
257
|
return withTransaction(() => {
|
|
164
258
|
const db = getDb();
|
|
@@ -167,13 +261,14 @@ export function recordCapabilityOutcome(outcome: CapabilityOutcome): CapabilityR
|
|
|
167
261
|
if (!existing) {
|
|
168
262
|
db.prepare(
|
|
169
263
|
`INSERT INTO capability_map (
|
|
170
|
-
task_type, model, runs_total, runs_passed, success_rate,
|
|
264
|
+
task_type, model, runs_total, runs_passed, first_pass_count, success_rate,
|
|
171
265
|
avg_cost_usd, avg_time_ms, last_10_runs, created_at, updated_at
|
|
172
|
-
) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, ?)`,
|
|
266
|
+
) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
173
267
|
).run(
|
|
174
268
|
key,
|
|
175
269
|
model,
|
|
176
270
|
passed,
|
|
271
|
+
firstPassIncrement,
|
|
177
272
|
passed,
|
|
178
273
|
cost,
|
|
179
274
|
time,
|
|
@@ -189,13 +284,16 @@ export function recordCapabilityOutcome(outcome: CapabilityOutcome): CapabilityR
|
|
|
189
284
|
const recent = [...existing.last10Runs, passed].slice(-RECENT_RUNS_LIMIT);
|
|
190
285
|
db.prepare(
|
|
191
286
|
`UPDATE capability_map
|
|
192
|
-
SET model = ?, runs_total = ?, runs_passed = ?,
|
|
193
|
-
|
|
287
|
+
SET model = ?, runs_total = ?, runs_passed = ?,
|
|
288
|
+
first_pass_count = COALESCE(first_pass_count, 0) + ?,
|
|
289
|
+
success_rate = ?, avg_cost_usd = ?, avg_time_ms = ?,
|
|
290
|
+
last_10_runs = ?, updated_at = ?
|
|
194
291
|
WHERE task_type = ?`,
|
|
195
292
|
).run(
|
|
196
293
|
model,
|
|
197
294
|
runsTotal,
|
|
198
295
|
runsPassed,
|
|
296
|
+
firstPassIncrement,
|
|
199
297
|
runsPassed / runsTotal,
|
|
200
298
|
avgCost,
|
|
201
299
|
avgTime,
|
|
@@ -215,9 +313,13 @@ export function recordCapabilityOutcome(outcome: CapabilityOutcome): CapabilityR
|
|
|
215
313
|
/**
|
|
216
314
|
* Решение слоя 2 по порогам (0 токенов).
|
|
217
315
|
*
|
|
316
|
+
* Пороги применяются к `effectiveSuccessRate` — 0.7 затухающего success rate
|
|
317
|
+
* последних прогонов плюс 0.3 first-pass rate (B13), а не к кумулятивному
|
|
318
|
+
* success rate. Поэтому старые успехи не перевешивают свежие провалы.
|
|
319
|
+
*
|
|
218
320
|
* - данных меньше `minRuns` → `explore` (решает слой 3);
|
|
219
|
-
* - `
|
|
220
|
-
* - `
|
|
321
|
+
* - `effectiveSuccessRate ≥ 0.85` → `local`;
|
|
322
|
+
* - `effectiveSuccessRate ≤ 0.30` → `cloud` (эскалация);
|
|
221
323
|
* - между порогами → `review` (нужен человек или облачный ревьюер).
|
|
222
324
|
*/
|
|
223
325
|
export function decideCapabilityRoute(
|
|
@@ -233,34 +335,46 @@ export function decideCapabilityRoute(
|
|
|
233
335
|
}
|
|
234
336
|
|
|
235
337
|
const capability = getCapability(key);
|
|
338
|
+
const effectiveSuccessRate = capability?.effectiveSuccessRate ?? 0;
|
|
339
|
+
const decayedSuccessRate = capability?.decayedSuccessRate ?? 0;
|
|
340
|
+
const firstPassRate = capability?.firstPassRate ?? 0;
|
|
236
341
|
if (!capability || capability.runsTotal < minRuns) {
|
|
237
342
|
return {
|
|
238
343
|
taskType: key,
|
|
239
344
|
target: "explore",
|
|
240
345
|
reason: "no-data",
|
|
241
346
|
successRate: capability?.successRate ?? 0,
|
|
347
|
+
effectiveSuccessRate,
|
|
348
|
+
decayedSuccessRate,
|
|
349
|
+
firstPassRate,
|
|
242
350
|
runsTotal: capability?.runsTotal ?? 0,
|
|
243
351
|
capability,
|
|
244
352
|
};
|
|
245
353
|
}
|
|
246
354
|
|
|
247
|
-
if (
|
|
355
|
+
if (effectiveSuccessRate >= localSuccess) {
|
|
248
356
|
return {
|
|
249
357
|
taskType: key,
|
|
250
358
|
target: "local",
|
|
251
359
|
reason: "local-reliable",
|
|
252
360
|
successRate: capability.successRate,
|
|
361
|
+
effectiveSuccessRate,
|
|
362
|
+
decayedSuccessRate,
|
|
363
|
+
firstPassRate,
|
|
253
364
|
runsTotal: capability.runsTotal,
|
|
254
365
|
capability,
|
|
255
366
|
};
|
|
256
367
|
}
|
|
257
368
|
|
|
258
|
-
if (
|
|
369
|
+
if (effectiveSuccessRate <= cloudFailure) {
|
|
259
370
|
return {
|
|
260
371
|
taskType: key,
|
|
261
372
|
target: "cloud",
|
|
262
373
|
reason: "escalate",
|
|
263
374
|
successRate: capability.successRate,
|
|
375
|
+
effectiveSuccessRate,
|
|
376
|
+
decayedSuccessRate,
|
|
377
|
+
firstPassRate,
|
|
264
378
|
runsTotal: capability.runsTotal,
|
|
265
379
|
capability,
|
|
266
380
|
};
|
|
@@ -271,6 +385,9 @@ export function decideCapabilityRoute(
|
|
|
271
385
|
target: "review",
|
|
272
386
|
reason: "review",
|
|
273
387
|
successRate: capability.successRate,
|
|
388
|
+
effectiveSuccessRate,
|
|
389
|
+
decayedSuccessRate,
|
|
390
|
+
firstPassRate,
|
|
274
391
|
runsTotal: capability.runsTotal,
|
|
275
392
|
capability,
|
|
276
393
|
};
|