clud-bug 0.7.0-rc.2 → 0.7.0-rc.21
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/README.md +20 -0
- package/data/canonical-v1.json +37 -0
- package/dist/cli/configure-github.d.ts +58 -0
- package/dist/cli/configure-github.d.ts.map +1 -0
- package/dist/cli/configure-github.js +242 -0
- package/dist/cli/configure-github.js.map +1 -0
- package/dist/cli/hooks.d.ts +51 -0
- package/dist/cli/hooks.d.ts.map +1 -0
- package/dist/cli/hooks.js +138 -0
- package/dist/cli/hooks.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +949 -35
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/post-check-run.d.ts +16 -0
- package/dist/cli/post-check-run.d.ts.map +1 -0
- package/dist/cli/post-check-run.js +93 -0
- package/dist/cli/post-check-run.js.map +1 -0
- package/dist/cli/review-prompt.d.ts +43 -0
- package/dist/cli/review-prompt.d.ts.map +1 -0
- package/dist/cli/review-prompt.js +287 -0
- package/dist/cli/review-prompt.js.map +1 -0
- package/dist/cli/skills.d.ts +7 -0
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +42 -2
- package/dist/cli/skills.js.map +1 -1
- package/dist/cli/update-notifier.d.ts +17 -0
- package/dist/cli/update-notifier.d.ts.map +1 -0
- package/dist/cli/update-notifier.js +88 -0
- package/dist/cli/update-notifier.js.map +1 -0
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +60 -11
- package/dist/cli/update.js.map +1 -1
- package/dist/core/auto-resolve.d.ts +235 -0
- package/dist/core/auto-resolve.d.ts.map +1 -0
- package/dist/core/auto-resolve.js +293 -0
- package/dist/core/auto-resolve.js.map +1 -0
- package/dist/core/budget-plan.d.ts +125 -0
- package/dist/core/budget-plan.d.ts.map +1 -0
- package/dist/core/budget-plan.js +211 -0
- package/dist/core/budget-plan.js.map +1 -0
- package/dist/core/check-verdict.d.ts +31 -0
- package/dist/core/check-verdict.d.ts.map +1 -0
- package/dist/core/check-verdict.js +66 -0
- package/dist/core/check-verdict.js.map +1 -0
- package/dist/core/configure-github.d.ts +179 -0
- package/dist/core/configure-github.d.ts.map +1 -0
- package/dist/core/configure-github.js +289 -0
- package/dist/core/configure-github.js.map +1 -0
- package/dist/core/design.d.ts +37 -0
- package/dist/core/design.d.ts.map +1 -0
- package/dist/core/design.js +47 -0
- package/dist/core/design.js.map +1 -0
- package/dist/core/diff-findings.d.ts +96 -0
- package/dist/core/diff-findings.d.ts.map +1 -0
- package/dist/core/diff-findings.js +261 -0
- package/dist/core/diff-findings.js.map +1 -0
- package/dist/core/formal-review.d.ts +79 -0
- package/dist/core/formal-review.d.ts.map +1 -0
- package/dist/core/formal-review.js +71 -0
- package/dist/core/formal-review.js.map +1 -0
- package/dist/core/index.d.ts +15 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +53 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/inline-threads.d.ts +160 -0
- package/dist/core/inline-threads.d.ts.map +1 -0
- package/dist/core/inline-threads.js +369 -0
- package/dist/core/inline-threads.js.map +1 -0
- package/dist/core/multi-pass-aggregate.d.ts +161 -0
- package/dist/core/multi-pass-aggregate.d.ts.map +1 -0
- package/dist/core/multi-pass-aggregate.js +457 -0
- package/dist/core/multi-pass-aggregate.js.map +1 -0
- package/dist/core/plan-review.d.ts +57 -0
- package/dist/core/plan-review.d.ts.map +1 -0
- package/dist/core/plan-review.js +77 -0
- package/dist/core/plan-review.js.map +1 -0
- package/dist/core/prompt-builder.d.ts +18 -0
- package/dist/core/prompt-builder.d.ts.map +1 -1
- package/dist/core/prompt-builder.js +24 -2
- package/dist/core/prompt-builder.js.map +1 -1
- package/dist/core/render.d.ts.map +1 -1
- package/dist/core/render.js +1 -19
- package/dist/core/render.js.map +1 -1
- package/dist/core/resolve-verifier.d.ts +53 -0
- package/dist/core/resolve-verifier.d.ts.map +1 -0
- package/dist/core/resolve-verifier.js +204 -0
- package/dist/core/resolve-verifier.js.map +1 -0
- package/dist/core/review-context.d.ts +39 -0
- package/dist/core/review-context.d.ts.map +1 -0
- package/dist/core/review-context.js +99 -0
- package/dist/core/review-context.js.map +1 -0
- package/dist/core/review-plan.d.ts +219 -0
- package/dist/core/review-plan.d.ts.map +1 -0
- package/dist/core/review-plan.js +274 -0
- package/dist/core/review-plan.js.map +1 -0
- package/dist/core/review-writeback.d.ts +74 -0
- package/dist/core/review-writeback.d.ts.map +1 -1
- package/dist/core/review-writeback.js +71 -4
- package/dist/core/review-writeback.js.map +1 -1
- package/dist/core/skills.d.ts +25 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +100 -4
- package/dist/core/skills.js.map +1 -1
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +4 -0
- package/dist/core/version.js.map +1 -0
- package/package.json +11 -5
- package/src/cli/configure-github.ts +329 -0
- package/src/cli/hooks.ts +155 -0
- package/src/cli/index.ts +6 -0
- package/src/cli/main.ts +1031 -37
- package/src/cli/post-check-run.ts +115 -0
- package/src/cli/review-prompt.ts +355 -0
- package/src/cli/skills.ts +42 -2
- package/src/cli/update-notifier.ts +100 -0
- package/src/cli/update.ts +60 -11
- package/src/core/auto-resolve.ts +488 -0
- package/src/core/budget-plan.ts +324 -0
- package/src/core/check-verdict.ts +93 -0
- package/src/core/configure-github.ts +497 -0
- package/src/core/design.ts +73 -0
- package/src/core/diff-findings.ts +323 -0
- package/src/core/formal-review.ts +168 -0
- package/src/core/index.ts +188 -0
- package/src/core/inline-threads.ts +471 -0
- package/src/core/multi-pass-aggregate.ts +591 -0
- package/src/core/plan-review.ts +136 -0
- package/src/core/prompt-builder.ts +44 -2
- package/src/core/render.ts +10 -16
- package/src/core/resolve-verifier.ts +254 -0
- package/src/core/review-context.ts +106 -0
- package/src/core/review-plan.ts +485 -0
- package/src/core/review-writeback.ts +161 -4
- package/src/core/skills.ts +128 -5
- package/src/core/version.ts +3 -0
- package/templates/clud-bug-review.md.tmpl +115 -0
- package/templates/skills/design/design-system-consistency.md +41 -0
- package/templates/skills/design/frontend-a11y.md +41 -0
- package/templates/skills/design/visual-polish.md +41 -0
- package/templates/workflow-py.yml.tmpl +92 -2
- package/templates/workflow-ts.yml.tmpl +92 -2
- package/templates/workflow.yml.tmpl +173 -2
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import type { ResolvedReviewPasses } from './review-plan.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Layer 1 cost gate — pre-flight estimator for multi-pass review.
|
|
5
|
+
*
|
|
6
|
+
* D.2.5 introduces a cost multiplier — a 3-pass review of a 5-skill catalog
|
|
7
|
+
* is 15 AI calls instead of 5. Without a gate, a misconfigured `reviewPasses`
|
|
8
|
+
* block can quietly burn through the AI Gateway budget on a single PR. This
|
|
9
|
+
* module decides BEFORE any AI call whether the review is cheap enough to
|
|
10
|
+
* run, and if not, returns a structured "deny" verdict the orchestrator
|
|
11
|
+
* surfaces as a friendly comment.
|
|
12
|
+
*
|
|
13
|
+
* Two layers, only the first lands in D.2.5:
|
|
14
|
+
*
|
|
15
|
+
* - Layer 1 (this module): per-PR estimate. Sums `skill_loads × pass_count`
|
|
16
|
+
* to produce an `estimatedCalls` count and an `estimatedCostUsd`
|
|
17
|
+
* ceiling. If `estimatedCostUsd > cap`, we deny.
|
|
18
|
+
*
|
|
19
|
+
* - Layer 2 (D.4 — NOT in this module): per-install rolling spend. Reads
|
|
20
|
+
* `INSTALLS:{id}.spend_usd_30d` from Redis. D.4 wires the actual gating;
|
|
21
|
+
* here we just stub the interface.
|
|
22
|
+
*
|
|
23
|
+
* The gate is BEST-EFFORT, intentionally pessimistic. We over-estimate cost
|
|
24
|
+
* (worst-case tokens × highest-tier model) because the alternative is the
|
|
25
|
+
* customer eating a surprise bill. A 20% over-estimate that occasionally
|
|
26
|
+
* causes a "we paused; raise the cap" comment is the right failure mode.
|
|
27
|
+
*
|
|
28
|
+
* Until D.4 wires real per-install budgets, this module always returns
|
|
29
|
+
* `{ verdict: 'allow' }`. The implementation is intentionally complete so
|
|
30
|
+
* D.4 can flip a single switch without changing the orchestrator surface.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Constants — worst-case cost ceilings
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Rough USD-per-call ceiling across the model tiers we route to.
|
|
39
|
+
*
|
|
40
|
+
* Numbers are deliberately over-stated — we'd rather deny a borderline
|
|
41
|
+
* review than blow past a billing cap. Reconciled monthly from the AI
|
|
42
|
+
* Gateway dashboard; the D.4 billing module replaces this with live data.
|
|
43
|
+
*
|
|
44
|
+
* Picking the max(model) across the roles array keeps the math local — we
|
|
45
|
+
* don't need per-pass attribution for the estimate, only for billing
|
|
46
|
+
* reconciliation later.
|
|
47
|
+
*/
|
|
48
|
+
const MODEL_CEILING_USD: Record<string, number> = {
|
|
49
|
+
'anthropic/claude-haiku-4.5': 0.02,
|
|
50
|
+
'anthropic/claude-sonnet-4.6': 0.08,
|
|
51
|
+
'anthropic/claude-opus-4.6': 0.4,
|
|
52
|
+
'anthropic/claude-opus-4.7': 0.5,
|
|
53
|
+
'openai/gpt-5': 0.4,
|
|
54
|
+
'openai/gpt-5.2': 0.04,
|
|
55
|
+
'google/gemini-3-flash': 0.02,
|
|
56
|
+
'google/gemini-3.1-pro-preview': 0.3,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Fallback ceiling for unknown model slugs. Conservative. */
|
|
60
|
+
const DEFAULT_PER_CALL_USD = 0.5;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Default per-PR cap. Real number lives in `env.REVIEW_SPEND_CAP_USD` once
|
|
64
|
+
* D.4 wires that env var — for now this is the hard-coded ceiling.
|
|
65
|
+
*
|
|
66
|
+
* $5 = a 3-pass review across 10 expensive skills (~30 calls × $0.15 avg).
|
|
67
|
+
* Anything above that is almost certainly a misconfigured `reviewPasses`.
|
|
68
|
+
*/
|
|
69
|
+
export const DEFAULT_PER_PR_CAP_USD = 5.0;
|
|
70
|
+
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Public types
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
export interface BudgetEstimateInput {
|
|
76
|
+
/** Resolved per-skill config — one entry per skill in the catalog. */
|
|
77
|
+
resolved: ResolvedReviewPasses[];
|
|
78
|
+
/** Model slugs the orchestrator plans to route to, in pass order. */
|
|
79
|
+
roleModels: string[];
|
|
80
|
+
/**
|
|
81
|
+
* Optional per-PR USD cap override. Defaults to `DEFAULT_PER_PR_CAP_USD`.
|
|
82
|
+
* D.4 wires per-install caps via `INSTALLS:{id}.spend_cap_usd`.
|
|
83
|
+
*/
|
|
84
|
+
perPrCapUsd?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Installation flag — `billing === 'exempt'` orgs bypass the cap entirely.
|
|
87
|
+
* D.4 reads this from the install record. For D.2.5, the orchestrator
|
|
88
|
+
* passes the env-allowlist result here.
|
|
89
|
+
*/
|
|
90
|
+
billingExempt?: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface BudgetEstimate {
|
|
94
|
+
/** Total AI calls = sum(skill_count × pass_count). */
|
|
95
|
+
estimatedCalls: number;
|
|
96
|
+
/** Worst-case cost in USD across all planned calls. */
|
|
97
|
+
estimatedCostUsd: number;
|
|
98
|
+
/** Per-call ceiling used (max across the role models). */
|
|
99
|
+
perCallCeilingUsd: number;
|
|
100
|
+
/** The cap the estimate was checked against. */
|
|
101
|
+
capUsd: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type BudgetVerdict =
|
|
105
|
+
| {
|
|
106
|
+
verdict: 'allow';
|
|
107
|
+
estimate: BudgetEstimate;
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
verdict: 'deny';
|
|
111
|
+
estimate: BudgetEstimate;
|
|
112
|
+
/** Friendly reason for the orchestrator's "we paused this review" comment. */
|
|
113
|
+
reason: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Estimator
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns the per-call USD ceiling — max across the role models.
|
|
122
|
+
*/
|
|
123
|
+
export function perCallCeiling(models: string[]): number {
|
|
124
|
+
if (models.length === 0) return DEFAULT_PER_CALL_USD;
|
|
125
|
+
let max = 0;
|
|
126
|
+
for (const m of models) {
|
|
127
|
+
const c = MODEL_CEILING_USD[m] ?? DEFAULT_PER_CALL_USD;
|
|
128
|
+
if (c > max) max = c;
|
|
129
|
+
}
|
|
130
|
+
return max;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Layer-1 cost gate. Decides whether the planned passes fit under the cap.
|
|
135
|
+
*
|
|
136
|
+
* Behavior matrix:
|
|
137
|
+
* billingExempt = true → allow (skip cap entirely)
|
|
138
|
+
* estimatedCostUsd > cap → deny + friendly reason
|
|
139
|
+
* estimatedCostUsd <= cap → allow
|
|
140
|
+
* resolved.length === 0 → allow (single-pass D.2.0 path)
|
|
141
|
+
*
|
|
142
|
+
* Until D.4 wires real per-install spending, callers see allow on every
|
|
143
|
+
* normal path — the deny branch only fires on truly absurd estimates.
|
|
144
|
+
*/
|
|
145
|
+
export function estimateBudget(input: BudgetEstimateInput): BudgetVerdict {
|
|
146
|
+
const cap = input.perPrCapUsd ?? DEFAULT_PER_PR_CAP_USD;
|
|
147
|
+
const ceiling = perCallCeiling(input.roleModels);
|
|
148
|
+
// The orchestrator (runMultiPass) sends all skills in a SINGLE prompt
|
|
149
|
+
// each pass and loops only the max skill's count times. Real call count
|
|
150
|
+
// is max(counts), not sum(counts). Summing over-estimates linearly with
|
|
151
|
+
// catalog size, making multi-pass unreachable for medium+ skill sets.
|
|
152
|
+
const calls = input.resolved.length === 0
|
|
153
|
+
? 0
|
|
154
|
+
: input.resolved.reduce((max, r) => Math.max(max, r.count), 0);
|
|
155
|
+
const cost = calls * ceiling;
|
|
156
|
+
|
|
157
|
+
const estimate: BudgetEstimate = {
|
|
158
|
+
estimatedCalls: calls,
|
|
159
|
+
estimatedCostUsd: cost,
|
|
160
|
+
perCallCeilingUsd: ceiling,
|
|
161
|
+
capUsd: cap,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (input.billingExempt) {
|
|
165
|
+
return { verdict: 'allow', estimate };
|
|
166
|
+
}
|
|
167
|
+
if (cost > cap) {
|
|
168
|
+
return {
|
|
169
|
+
verdict: 'deny',
|
|
170
|
+
estimate,
|
|
171
|
+
reason: friendlyDenyReason({ cost, cap, calls, ceiling }),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return { verdict: 'allow', estimate };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function friendlyDenyReason(args: {
|
|
178
|
+
cost: number;
|
|
179
|
+
cap: number;
|
|
180
|
+
calls: number;
|
|
181
|
+
ceiling: number;
|
|
182
|
+
}): string {
|
|
183
|
+
return [
|
|
184
|
+
`clud-bug paused this review — estimated cost \`$${args.cost.toFixed(2)}\``,
|
|
185
|
+
`exceeds the per-PR cap of \`$${args.cap.toFixed(2)}\`.`,
|
|
186
|
+
`(${args.calls} planned AI call${args.calls === 1 ? '' : 's'} ×`,
|
|
187
|
+
`worst-case \`$${args.ceiling.toFixed(2)}\` per call.)`,
|
|
188
|
+
'Lower `reviewPasses.count` in `.claude/skills/.clud-bug.json` and re-trigger.',
|
|
189
|
+
].join(' ');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Exposed for tests + future D.4 wiring. Lets callers register a cost
|
|
194
|
+
* ceiling for a newly-routed model without editing this module.
|
|
195
|
+
*/
|
|
196
|
+
export function __setModelCeilingForTests(
|
|
197
|
+
model: string,
|
|
198
|
+
usd: number | null,
|
|
199
|
+
): void {
|
|
200
|
+
if (usd === null) {
|
|
201
|
+
delete MODEL_CEILING_USD[model];
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
MODEL_CEILING_USD[model] = usd;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// D.2.6 — auto-resolve verifier cost surface
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Per-call ceiling for the D.2.6 fix-verifier. Each verifier call is small —
|
|
213
|
+
* ~500 token I/O at Sonnet rates — so a more aggressive ceiling makes sense
|
|
214
|
+
* vs the main-review per-call ceiling. We over-state by ~2x to keep the
|
|
215
|
+
* "$0.10 per PR with 5 findings × 3 fix-pushes" plan budget honest.
|
|
216
|
+
*
|
|
217
|
+
* Sonnet 4.6 at $3/$15 per million tokens × 500 token I/O ≈ $0.005;
|
|
218
|
+
* we use $0.01 as the gate ceiling so a borderline-overbudget verifier doesn't
|
|
219
|
+
* silently silently flip the install over the cap.
|
|
220
|
+
*/
|
|
221
|
+
const VERIFIER_PER_CALL_CEILING_USD = 0.01;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Default per-PR budget for D.2.6 verifier calls. The spec calls $0.10 the
|
|
225
|
+
* "5 findings × 3 fix-pushes" ceiling; we use 2x that as the cap so a
|
|
226
|
+
* sufficiently-large PR (20 threads × 3 fix-pushes = 60 calls) still fits.
|
|
227
|
+
*
|
|
228
|
+
* D.4 will plumb per-install caps; for D.2.6 we use a single repo-wide
|
|
229
|
+
* default. Installs in BILLING_EXEMPT_ORGS bypass this entirely.
|
|
230
|
+
*/
|
|
231
|
+
export const DEFAULT_VERIFIER_PER_PR_CAP_USD = 0.6;
|
|
232
|
+
|
|
233
|
+
export interface VerifierBudgetInput {
|
|
234
|
+
/** Number of open threads we plan to verify on this fix-push. */
|
|
235
|
+
threadCount: number;
|
|
236
|
+
/**
|
|
237
|
+
* Pass count from D.2.5 multi-pass — we call the verifier once per pass
|
|
238
|
+
* per thread (see resolve-verifier integration doc). Defaults to 1
|
|
239
|
+
* for single-pass installs.
|
|
240
|
+
*/
|
|
241
|
+
passesPerThread?: number;
|
|
242
|
+
/**
|
|
243
|
+
* Optional per-PR cap override. Defaults to DEFAULT_VERIFIER_PER_PR_CAP_USD.
|
|
244
|
+
*/
|
|
245
|
+
perPrCapUsd?: number;
|
|
246
|
+
/** BILLING_EXEMPT installs bypass the cap. */
|
|
247
|
+
billingExempt?: boolean;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface VerifierBudgetEstimate {
|
|
251
|
+
/** Total verifier AI calls = threadCount × passesPerThread. */
|
|
252
|
+
estimatedCalls: number;
|
|
253
|
+
/** Worst-case cost. */
|
|
254
|
+
estimatedCostUsd: number;
|
|
255
|
+
/** Per-call ceiling used. */
|
|
256
|
+
perCallCeilingUsd: number;
|
|
257
|
+
/** Cap checked against. */
|
|
258
|
+
capUsd: number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export type VerifierBudgetVerdict =
|
|
262
|
+
| { verdict: 'allow'; estimate: VerifierBudgetEstimate }
|
|
263
|
+
| {
|
|
264
|
+
verdict: 'deny';
|
|
265
|
+
estimate: VerifierBudgetEstimate;
|
|
266
|
+
/** Friendly reason for the orchestrator's "skipped: verifier-budget" log. */
|
|
267
|
+
reason: string;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Pre-flight gate for the D.2.6 fix-verifier. Called once per fix-push,
|
|
272
|
+
* BEFORE any verifier call runs. If denied, the orchestrator emits
|
|
273
|
+
* `skipped: budget` for the entire auto-resolve cycle and routes the
|
|
274
|
+
* threads through the heuristic fallback (see auto-resolve).
|
|
275
|
+
*
|
|
276
|
+
* Behavior:
|
|
277
|
+
* billingExempt = true → allow (bypass cap)
|
|
278
|
+
* estimated > cap → deny
|
|
279
|
+
* threadCount === 0 → allow with 0 calls (no-op fix-push, no threads to verify)
|
|
280
|
+
* otherwise → allow
|
|
281
|
+
*/
|
|
282
|
+
export function estimateVerifierBudget(
|
|
283
|
+
input: VerifierBudgetInput,
|
|
284
|
+
): VerifierBudgetVerdict {
|
|
285
|
+
const cap = input.perPrCapUsd ?? DEFAULT_VERIFIER_PER_PR_CAP_USD;
|
|
286
|
+
const passes = input.passesPerThread ?? 1;
|
|
287
|
+
const calls = input.threadCount * Math.max(1, passes);
|
|
288
|
+
const cost = calls * VERIFIER_PER_CALL_CEILING_USD;
|
|
289
|
+
|
|
290
|
+
const estimate: VerifierBudgetEstimate = {
|
|
291
|
+
estimatedCalls: calls,
|
|
292
|
+
estimatedCostUsd: cost,
|
|
293
|
+
perCallCeilingUsd: VERIFIER_PER_CALL_CEILING_USD,
|
|
294
|
+
capUsd: cap,
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
if (input.billingExempt) {
|
|
298
|
+
return { verdict: 'allow', estimate };
|
|
299
|
+
}
|
|
300
|
+
if (cost > cap) {
|
|
301
|
+
return {
|
|
302
|
+
verdict: 'deny',
|
|
303
|
+
estimate,
|
|
304
|
+
reason: friendlyVerifierDenyReason({ cost, cap, calls }),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return { verdict: 'allow', estimate };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function friendlyVerifierDenyReason(args: {
|
|
311
|
+
cost: number;
|
|
312
|
+
cap: number;
|
|
313
|
+
calls: number;
|
|
314
|
+
}): string {
|
|
315
|
+
return [
|
|
316
|
+
`clud-bug paused D.2.6 fix-verification — estimated cost`,
|
|
317
|
+
`\`$${args.cost.toFixed(2)}\` exceeds the per-PR cap of`,
|
|
318
|
+
`\`$${args.cap.toFixed(2)}\`. (${args.calls} planned verifier call${args.calls === 1 ? '' : 's'} ×`,
|
|
319
|
+
`worst-case \`$${VERIFIER_PER_CALL_CEILING_USD.toFixed(2)}\` per call.)`,
|
|
320
|
+
'Lower `autoResolve.max_threads_per_fix_push` in',
|
|
321
|
+
'`.claude/skills/.clud-bug.json` or set `autoResolve.mode = "heuristic"`',
|
|
322
|
+
'to opt out of verified-mode for this install.',
|
|
323
|
+
].join(' ');
|
|
324
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Merge-gate verdict → GitHub check-run conclusion (H3). Shared, pure brain so
|
|
2
|
+
// every surface that posts the `clud-bug-review` check derives the same
|
|
3
|
+
// conclusion from a review outcome.
|
|
4
|
+
//
|
|
5
|
+
// The check name is HARD-CODED `clud-bug-review` everywhere — consumers attach
|
|
6
|
+
// branch-protection rules by that exact string (see clud-bug-app/lib/check-runs.ts).
|
|
7
|
+
//
|
|
8
|
+
// CONCLUSION MODEL for the local + Action surfaces (this module):
|
|
9
|
+
// clean → success (review ran, no critical findings)
|
|
10
|
+
// critical + strict → failure (BLOCKS merge — fix the criticals)
|
|
11
|
+
// critical + !strict → neutral (advisory; does not block)
|
|
12
|
+
// failed → neutral (couldn't run; never blocks — add signal, not outages)
|
|
13
|
+
//
|
|
14
|
+
// This intentionally differs from the HOSTED bot, whose check is success-on-run
|
|
15
|
+
// and whose strict-mode block is a separate `request_changes` formal review. In
|
|
16
|
+
// local/Action mode there is no formal review, so the check IS the gate — its
|
|
17
|
+
// conclusion reflects the findings directly.
|
|
18
|
+
|
|
19
|
+
/** The check name MUST match consumer branch-protection rules. Do not rename. */
|
|
20
|
+
export const CLUD_BUG_CHECK_NAME = 'clud-bug-review';
|
|
21
|
+
|
|
22
|
+
/** Outcome of a review, as the posting surface sees it. */
|
|
23
|
+
export type ReviewVerdict = 'clean' | 'critical' | 'failed';
|
|
24
|
+
|
|
25
|
+
/** The narrowed check-run conclusion set we emit. */
|
|
26
|
+
export type CheckConclusion = 'success' | 'neutral' | 'failure';
|
|
27
|
+
|
|
28
|
+
/** Which surface attested the review (drives the title + trust note). */
|
|
29
|
+
export type CheckSource = 'local' | 'ci';
|
|
30
|
+
|
|
31
|
+
export interface DerivedCheck {
|
|
32
|
+
conclusion: CheckConclusion;
|
|
33
|
+
title: string;
|
|
34
|
+
summary: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface DeriveCheckInput {
|
|
38
|
+
verdict: ReviewVerdict;
|
|
39
|
+
/** `.clud-bug.json` strictMode at the BASE ref. Default false (advisory). */
|
|
40
|
+
strictMode?: boolean;
|
|
41
|
+
/** Number of critical findings (for the title). */
|
|
42
|
+
criticalCount?: number;
|
|
43
|
+
/** 'local' (self-attested in-session) or 'ci' (Action). Default 'ci'. */
|
|
44
|
+
source?: CheckSource;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Derive the `clud-bug-review` check conclusion + title/summary from a review
|
|
49
|
+
* verdict. Pure. A `local` source appends a self-attested trust note so a
|
|
50
|
+
* reviewer can tell an in-session attestation from an independent CI check.
|
|
51
|
+
*/
|
|
52
|
+
export function deriveCheck(input: DeriveCheckInput): DerivedCheck {
|
|
53
|
+
const { verdict, strictMode = false, criticalCount = 0, source = 'ci' } = input;
|
|
54
|
+
const selfAttested =
|
|
55
|
+
source === 'local'
|
|
56
|
+
? ' (self-attested by a local max-mode review in the author’s session — not an independent CI check)'
|
|
57
|
+
: '';
|
|
58
|
+
|
|
59
|
+
let conclusion: CheckConclusion;
|
|
60
|
+
let title: string;
|
|
61
|
+
let summary: string;
|
|
62
|
+
|
|
63
|
+
if (verdict === 'clean') {
|
|
64
|
+
conclusion = 'success';
|
|
65
|
+
title = 'clud-bug review — clean';
|
|
66
|
+
summary = `No critical findings.${selfAttested}`;
|
|
67
|
+
} else if (verdict === 'critical') {
|
|
68
|
+
const n = criticalCount > 0 ? `${criticalCount} ` : '';
|
|
69
|
+
if (strictMode) {
|
|
70
|
+
conclusion = 'failure';
|
|
71
|
+
title = `clud-bug review — ${n}critical (blocking)`;
|
|
72
|
+
summary = `${n}critical finding(s); strict mode blocks merge until they are resolved.${selfAttested}`;
|
|
73
|
+
} else {
|
|
74
|
+
conclusion = 'neutral';
|
|
75
|
+
title = `clud-bug review — ${n}critical (advisory)`;
|
|
76
|
+
summary = `${n}critical finding(s); advisory only (strict mode off) — does not block merge.${selfAttested}`;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
// failed — never block on our own inability to run.
|
|
80
|
+
conclusion = 'neutral';
|
|
81
|
+
title = 'clud-bug review — could not run';
|
|
82
|
+
summary = `The review could not complete; the PR is not blocked. Re-run to retry.${selfAttested}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { conclusion, title, summary };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Normalize a free-form verdict string (CLI input) to a `ReviewVerdict`. */
|
|
89
|
+
export function normalizeVerdict(raw: string | undefined): ReviewVerdict {
|
|
90
|
+
if (raw === 'clean' || raw === 'critical' || raw === 'failed') return raw;
|
|
91
|
+
// Unknown/empty → 'failed' (safe: neutral check, never a false-green).
|
|
92
|
+
return 'failed';
|
|
93
|
+
}
|