crysk 0.5.0 → 0.5.1
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/package.json +1 -1
- package/src/assets.ts +1 -1
- package/src/ci/force-comment.ts +14 -1
- package/src/ci/gates.ts +64 -21
- package/src/ci/platform-estimate.ts +111 -0
- package/src/ci/platform-trace.ts +30 -0
- package/src/ci/platform.ts +30 -0
- package/src/ci/reporter.ts +14 -4
- package/src/ci/setup.ts +32 -0
- package/src/ci/trace-bundle.ts +231 -27
- package/src/ci/trace-transcripts.ts +65 -0
- package/src/index.ts +1 -1
- package/src/pr/ci-admission-gate.ts +2 -0
- package/src/pr/discovery.ts +18 -0
- package/src/pr/plan.ts +35 -1
- package/src/pr/review-pr.ts +11 -0
- package/src/pr/target.ts +52 -9
- package/src/review/report.ts +4 -0
- package/src/review/run.ts +16 -0
- package/src/ui/plan.ts +8 -3
- package/src/updater.ts +1 -1
package/package.json
CHANGED
package/src/assets.ts
CHANGED
package/src/ci/force-comment.ts
CHANGED
|
@@ -28,7 +28,20 @@ export function ciForceReviewDispatch(prNumber: number): string {
|
|
|
28
28
|
return `gh workflow run ${CI_FORCE_WORKFLOW_FILE} -f pr=${prNumber}`;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// `platformConnected`: the run came through the Crysk platform. Its workflow is
|
|
32
|
+
// the platform's stub, which listens for the `/crysk` spellings only and was
|
|
33
|
+
// never scaffolded here, so the legacy names, the force workflow and the
|
|
34
|
+
// re-scaffold do not apply there (cryskai/platform#12).
|
|
35
|
+
export function ciForceReviewHintLine(
|
|
36
|
+
prNumber: number,
|
|
37
|
+
platformConnected = false,
|
|
38
|
+
): string {
|
|
39
|
+
if (platformConnected) {
|
|
40
|
+
return (
|
|
41
|
+
`Comment \`${CI_REVIEW_COMMENT}\` on this pull request to run it anyway ` +
|
|
42
|
+
`(\`${CI_REVIEW_FULL_COMMENT}\` re-discovers the whole range).`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
32
45
|
return (
|
|
33
46
|
`Comment ${commandHint(CI_REVIEW_COMMENT)} on this pull request to run it ` +
|
|
34
47
|
`on GitHub Actions anyway (${commandHint(CI_REVIEW_FULL_COMMENT)} re-discovers the ` +
|
package/src/ci/gates.ts
CHANGED
|
@@ -190,7 +190,10 @@ function sizeLimitsText(maxLines: number, maxFiles: number): string {
|
|
|
190
190
|
return `${lines} / ${files}`;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
function buildSizeSkipComment(
|
|
193
|
+
function buildSizeSkipComment(
|
|
194
|
+
data: SkipSizeSummary,
|
|
195
|
+
platformConnected: boolean,
|
|
196
|
+
): string {
|
|
194
197
|
const lines = [
|
|
195
198
|
SKIP_SIZE_COMMENT_MARKER,
|
|
196
199
|
"## Crysk review skipped",
|
|
@@ -199,16 +202,28 @@ function buildSizeSkipComment(data: SkipSizeSummary): string {
|
|
|
199
202
|
`${data.changedFiles} file(s), exceeding the configured size gate ` +
|
|
200
203
|
`(${sizeLimitsText(data.maxChangedLines, data.maxChangedFiles)}).`,
|
|
201
204
|
"",
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
"
|
|
205
|
+
// A platform repository sets its limits in the dashboard, not as inputs.
|
|
206
|
+
platformConnected
|
|
207
|
+
? "Crysk did not run to avoid reviewing an unbounded diff. Split the " +
|
|
208
|
+
"PR or raise the size limits in the Crysk dashboard to change them " +
|
|
209
|
+
"for later pushes."
|
|
210
|
+
: "Crysk did not run to avoid reviewing an unbounded diff. Split the " +
|
|
211
|
+
"PR or raise `max-changed-lines` / `max-changed-files` to change the " +
|
|
212
|
+
"limit for later pushes.",
|
|
205
213
|
"",
|
|
206
|
-
ciForceReviewHintLine(data.prNumber),
|
|
214
|
+
ciForceReviewHintLine(data.prNumber, platformConnected),
|
|
207
215
|
];
|
|
208
216
|
return `${lines.join("\n")}\n`;
|
|
209
217
|
}
|
|
210
218
|
|
|
219
|
+
// What a platform repository can do about a budget skip (cryskai/platform#12):
|
|
220
|
+
// it has no `budget-usd` input to raise, and what a review costs is the model
|
|
221
|
+
// setup chosen in the dashboard.
|
|
222
|
+
const PLATFORM_BUDGET_SKIP_HINT =
|
|
223
|
+
"To change what reviews cost, change the model setup in the Crysk dashboard.";
|
|
224
|
+
|
|
211
225
|
function buildBudgetSkipComment(data: SkipBudgetSummary): string {
|
|
226
|
+
const platformConnected = data.platformConnected === true;
|
|
212
227
|
const lines = [
|
|
213
228
|
SKIP_BUDGET_COMMENT_MARKER,
|
|
214
229
|
"## Crysk review skipped",
|
|
@@ -216,10 +231,12 @@ function buildBudgetSkipComment(data: SkipBudgetSummary): string {
|
|
|
216
231
|
`⚠️ The estimated review cost (${usd(data.estimatedCostUsd)}) exceeds ` +
|
|
217
232
|
`the configured CI budget ceiling (${usd(data.budgetUsd)}).`,
|
|
218
233
|
"",
|
|
219
|
-
|
|
220
|
-
|
|
234
|
+
platformConnected
|
|
235
|
+
? PLATFORM_BUDGET_SKIP_HINT
|
|
236
|
+
: "Crysk did not run to stay within the configured `--budget-usd` " +
|
|
237
|
+
"ceiling.",
|
|
221
238
|
"",
|
|
222
|
-
ciForceReviewHintLine(data.prNumber),
|
|
239
|
+
ciForceReviewHintLine(data.prNumber, platformConnected),
|
|
223
240
|
];
|
|
224
241
|
return `${lines.join("\n")}\n`;
|
|
225
242
|
}
|
|
@@ -240,6 +257,9 @@ export interface CiSizeGateSkipInput {
|
|
|
240
257
|
// failed (size-gate.ts), but the summary/comment show both metrics.
|
|
241
258
|
maxChangedLines: number;
|
|
242
259
|
maxChangedFiles: number;
|
|
260
|
+
// The run came through the Crysk platform (CRYSK_PLATFORM_CONNECTED): the
|
|
261
|
+
// comment names only what applies to a platform repository.
|
|
262
|
+
platformConnected?: boolean;
|
|
243
263
|
}
|
|
244
264
|
|
|
245
265
|
// `null` means "nothing to publish": either this isn't a CI run, or the
|
|
@@ -254,8 +274,12 @@ export function ciSizeGateSkip(input: CiSizeGateSkipInput): CiGateSkip | null {
|
|
|
254
274
|
changedFiles: input.verdict.effectiveFiles,
|
|
255
275
|
maxChangedLines: input.maxChangedLines,
|
|
256
276
|
maxChangedFiles: input.maxChangedFiles,
|
|
277
|
+
...(input.platformConnected === true ? { platformConnected: true } : {}),
|
|
278
|
+
};
|
|
279
|
+
return {
|
|
280
|
+
comment: buildSizeSkipComment(summary, input.platformConnected === true),
|
|
281
|
+
summary,
|
|
257
282
|
};
|
|
258
|
-
return { comment: buildSizeSkipComment(summary), summary };
|
|
259
283
|
}
|
|
260
284
|
|
|
261
285
|
export interface CiBudgetGateSkipInput {
|
|
@@ -263,6 +287,9 @@ export interface CiBudgetGateSkipInput {
|
|
|
263
287
|
estimatedCostUsd: number;
|
|
264
288
|
budgetUsd: number;
|
|
265
289
|
prNumber: number;
|
|
290
|
+
// The run came through the Crysk platform (CRYSK_PLATFORM_CONNECTED): the
|
|
291
|
+
// skip names only what applies to a platform repository.
|
|
292
|
+
platformConnected?: boolean;
|
|
266
293
|
}
|
|
267
294
|
|
|
268
295
|
export function ciBudgetGateSkip(
|
|
@@ -275,6 +302,7 @@ export function ciBudgetGateSkip(
|
|
|
275
302
|
prNumber: input.prNumber,
|
|
276
303
|
estimatedCostUsd: input.estimatedCostUsd,
|
|
277
304
|
budgetUsd: input.budgetUsd,
|
|
305
|
+
...(input.platformConnected === true ? { platformConnected: true } : {}),
|
|
278
306
|
};
|
|
279
307
|
return { comment: buildBudgetSkipComment(summary), summary };
|
|
280
308
|
}
|
|
@@ -382,19 +410,19 @@ export type CiBillingMode = "subscription" | "metered";
|
|
|
382
410
|
// through that one decision — this CI gate is not that caller, and never
|
|
383
411
|
// should be.
|
|
384
412
|
//
|
|
385
|
-
// Optional `
|
|
413
|
+
// Optional `openCodeBillsMetered` is the OpenCode half of the same ceiling
|
|
386
414
|
// question — "could this run invoice?" — ORed beside the Anthropic env
|
|
387
415
|
// predicate, never folded into it. `envBillsMetered` stamps Claude CLI
|
|
388
416
|
// usage and must stay Anthropic-env-only. Omit the option (or leave it
|
|
389
|
-
// undefined/false) and this function stays env-only.
|
|
390
|
-
//
|
|
391
|
-
//
|
|
392
|
-
//
|
|
417
|
+
// undefined/false) and this function stays env-only. The caller derives it
|
|
418
|
+
// from the routes the run resolves (openCodeRoutesBillMetered, ci/setup.ts):
|
|
419
|
+
// an OpenCode provider bound to an API key can invoice; an auth file that only
|
|
420
|
+
// holds providers no model uses cannot (cryskai/platform#12).
|
|
393
421
|
export function deriveCiBillingMode(
|
|
394
422
|
env: Record<string, string | undefined>,
|
|
395
|
-
opts?: {
|
|
423
|
+
opts?: { openCodeBillsMetered?: boolean },
|
|
396
424
|
): CiBillingMode {
|
|
397
|
-
return envBillsMetered(env) || opts?.
|
|
425
|
+
return envBillsMetered(env) || opts?.openCodeBillsMetered === true
|
|
398
426
|
? "metered"
|
|
399
427
|
: "subscription";
|
|
400
428
|
}
|
|
@@ -655,6 +683,7 @@ const COVERAGE_REASON_LABEL: Record<
|
|
|
655
683
|
function buildCoverageSkipComment(
|
|
656
684
|
data: SkipCoverageSummary,
|
|
657
685
|
reason: CiReviewSkipReason,
|
|
686
|
+
platformConnected: boolean,
|
|
658
687
|
): string {
|
|
659
688
|
// A stop is a maintainer's decision, not a score: the score line would
|
|
660
689
|
// blame the push for a skip it did not cause.
|
|
@@ -677,7 +706,7 @@ function buildCoverageSkipComment(
|
|
|
677
706
|
"The existing review comment still describes the last head Crysk " +
|
|
678
707
|
"reviewed.",
|
|
679
708
|
"",
|
|
680
|
-
ciForceReviewHintLine(data.prNumber),
|
|
709
|
+
ciForceReviewHintLine(data.prNumber, platformConnected),
|
|
681
710
|
];
|
|
682
711
|
return `${lines.join("\n")}\n`;
|
|
683
712
|
}
|
|
@@ -686,7 +715,10 @@ function buildCoverageSkipComment(
|
|
|
686
715
|
// it by the repository's own rules, says what the gate does with the next pushes, and how to ask for more.
|
|
687
716
|
// Stage 2 #12: no review reads those pushes, so the gate holds a green instead of carrying it, and the
|
|
688
717
|
// override is how a human merges a head no review verified.
|
|
689
|
-
function buildManualRequiredComment(
|
|
718
|
+
function buildManualRequiredComment(
|
|
719
|
+
data: ManualRequiredSummary,
|
|
720
|
+
platformConnected: boolean,
|
|
721
|
+
): string {
|
|
690
722
|
const manualOnly = data.admissionReason === "manual-only-policy";
|
|
691
723
|
const rules = [
|
|
692
724
|
...(data.policyMode === undefined
|
|
@@ -720,7 +752,7 @@ function buildManualRequiredComment(data: ManualRequiredSummary): string {
|
|
|
720
752
|
"",
|
|
721
753
|
"The existing review comment still describes the last head Crysk reviewed.",
|
|
722
754
|
"",
|
|
723
|
-
`Want more review rounds? ${ciForceReviewHintLine(data.prNumber)}`,
|
|
755
|
+
`Want more review rounds? ${ciForceReviewHintLine(data.prNumber, platformConnected)}`,
|
|
724
756
|
];
|
|
725
757
|
return `${lines.join("\n")}\n`;
|
|
726
758
|
}
|
|
@@ -780,6 +812,8 @@ export function planCiReviewSkip(input: {
|
|
|
780
812
|
verdict: Extract<CiReviewAdmissionVerdict, { action: "skip" }>;
|
|
781
813
|
admission?: AdmissionContext;
|
|
782
814
|
ciMode: CiMode;
|
|
815
|
+
// The run came through the Crysk platform: the hint names only `/crysk review`.
|
|
816
|
+
platformConnected?: boolean;
|
|
783
817
|
}): CiGateSkipPlan {
|
|
784
818
|
const detail = ciReviewSkipDetail(input.verdict);
|
|
785
819
|
const summary: SkipCoverageSummary = {
|
|
@@ -794,7 +828,11 @@ export function planCiReviewSkip(input: {
|
|
|
794
828
|
...skipAdmissionSummaryFields(input.verdict, input.admission),
|
|
795
829
|
};
|
|
796
830
|
return {
|
|
797
|
-
comment: buildCoverageSkipComment(
|
|
831
|
+
comment: buildCoverageSkipComment(
|
|
832
|
+
summary,
|
|
833
|
+
input.verdict.reason,
|
|
834
|
+
input.platformConnected === true,
|
|
835
|
+
),
|
|
798
836
|
markerPrefix: SKIP_COVERAGE_COMMENT_MARKER,
|
|
799
837
|
summaryMarkdown: renderStepSummary(summary, input.ciMode),
|
|
800
838
|
outputs: ciGateSkipOutputs("skipped-coverage", 0),
|
|
@@ -806,6 +844,8 @@ export function planCiReviewManualRequired(input: {
|
|
|
806
844
|
verdict: Extract<CiReviewAdmissionVerdict, { action: "manual-required" }>;
|
|
807
845
|
admission?: AdmissionContext;
|
|
808
846
|
ciMode: CiMode;
|
|
847
|
+
// The run came through the Crysk platform: the hint names only `/crysk review`.
|
|
848
|
+
platformConnected?: boolean;
|
|
809
849
|
}): CiGateSkipPlan {
|
|
810
850
|
const detail = ciReviewManualRequiredDetail(input.verdict);
|
|
811
851
|
const summary: ManualRequiredSummary = {
|
|
@@ -822,7 +862,10 @@ export function planCiReviewManualRequired(input: {
|
|
|
822
862
|
...manualAdmissionSummaryFields(input.verdict, input.admission),
|
|
823
863
|
};
|
|
824
864
|
return {
|
|
825
|
-
comment: buildManualRequiredComment(
|
|
865
|
+
comment: buildManualRequiredComment(
|
|
866
|
+
summary,
|
|
867
|
+
input.platformConnected === true,
|
|
868
|
+
),
|
|
826
869
|
markerPrefix: MANUAL_REQUIRED_COMMENT_MARKER,
|
|
827
870
|
summaryMarkdown: renderStepSummary(summary, input.ciMode),
|
|
828
871
|
outputs: ciGateSkipOutputs("manual-required", 0),
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// The review cost the Crysk platform estimated for this run (cryskai/platform#12).
|
|
2
|
+
// The connect step asks for it with `X-Crysk-Capabilities: estimate` and hands it
|
|
3
|
+
// to the run step as `CRYSK_PLATFORM_ESTIMATE`, where the CI budget gate reads it
|
|
4
|
+
// instead of the engine's own band (cryskai/crysk#138): the platform knows the
|
|
5
|
+
// setup's models, their catalog prices and what its recent reviews cost; the
|
|
6
|
+
// band only knows the diff's size and prices every model as Claude.
|
|
7
|
+
//
|
|
8
|
+
// The platform already checked it, and the engine checks again: a value that is
|
|
9
|
+
// not a usable range is dropped, and the band decides, as without a platform.
|
|
10
|
+
|
|
11
|
+
export type PlatformEstimateBasis = "history" | "catalog";
|
|
12
|
+
|
|
13
|
+
export interface PlatformEstimate {
|
|
14
|
+
readonly usdLow: number;
|
|
15
|
+
readonly usdHigh: number;
|
|
16
|
+
// `history`: the setup's recent reviews scaled to this pull request.
|
|
17
|
+
// `catalog`: the catalog prices of the setup's models.
|
|
18
|
+
readonly basis: PlatformEstimateBasis;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const PLATFORM_ESTIMATE_CAPABILITY = "estimate";
|
|
22
|
+
|
|
23
|
+
const usable = (value: unknown): value is number =>
|
|
24
|
+
typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
25
|
+
|
|
26
|
+
// The `/runs/token` field, `{ usd_low, usd_high, basis }`, or undefined when it
|
|
27
|
+
// is absent or not a usable range.
|
|
28
|
+
export function parsePlatformEstimate(
|
|
29
|
+
value: unknown,
|
|
30
|
+
): PlatformEstimate | undefined {
|
|
31
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const {
|
|
35
|
+
usd_low: low,
|
|
36
|
+
usd_high: high,
|
|
37
|
+
basis,
|
|
38
|
+
} = value as Record<string, unknown>;
|
|
39
|
+
if (!usable(low) || !usable(high) || low > high) return undefined;
|
|
40
|
+
if (basis !== "history" && basis !== "catalog") return undefined;
|
|
41
|
+
return { usdLow: low, usdHigh: high, basis };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// What the connect step writes to its `estimate` output: one line of JSON in the
|
|
45
|
+
// response's own field names, numbers and an enum only.
|
|
46
|
+
export function serializePlatformEstimate(estimate: PlatformEstimate): string {
|
|
47
|
+
return JSON.stringify({
|
|
48
|
+
usd_low: estimate.usdLow,
|
|
49
|
+
usd_high: estimate.usdHigh,
|
|
50
|
+
basis: estimate.basis,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The run step's read of `CRYSK_PLATFORM_ESTIMATE`. Empty (a standalone run, an
|
|
55
|
+
// older platform, nothing priceable) or malformed reads as no estimate.
|
|
56
|
+
export function readPlatformEstimate(
|
|
57
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
58
|
+
): PlatformEstimate | undefined {
|
|
59
|
+
const text = env.CRYSK_PLATFORM_ESTIMATE;
|
|
60
|
+
if (text === undefined || text === "") return undefined;
|
|
61
|
+
try {
|
|
62
|
+
return parsePlatformEstimate(JSON.parse(text));
|
|
63
|
+
} catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The estimate as the plan and the CI budget gate read a cost band (report.ts's
|
|
69
|
+
// CostEstimate, structurally: this module imports nothing).
|
|
70
|
+
export function platformCostEstimate(estimate: PlatformEstimate): {
|
|
71
|
+
low: number;
|
|
72
|
+
high: number;
|
|
73
|
+
basis: string;
|
|
74
|
+
platform: PlatformEstimateBasis;
|
|
75
|
+
} {
|
|
76
|
+
return {
|
|
77
|
+
low: estimate.usdLow,
|
|
78
|
+
high: estimate.usdHigh,
|
|
79
|
+
basis:
|
|
80
|
+
estimate.basis === "history"
|
|
81
|
+
? "The Crysk platform's estimate, from this setup's recent reviews scaled to this pull request."
|
|
82
|
+
: "The Crysk platform's estimate, from the catalog prices of this setup's models.",
|
|
83
|
+
platform: estimate.basis,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The estimate the run gates and plans on. The platform prices the whole pull
|
|
88
|
+
// request from the setup's own models, before the engine knows how much of it
|
|
89
|
+
// this run reviews. A narrowed run (a re-review whose discovery reads only what
|
|
90
|
+
// changed since the last review, or one that only verifies earlier findings)
|
|
91
|
+
// passes `fullBand`, the band for a full review of the pull request: the
|
|
92
|
+
// platform's figure is scaled by the share of that work the run does
|
|
93
|
+
// (band / fullBand, at most 1). The band measures the share only; its prices,
|
|
94
|
+
// which treat every model as Claude, never replace the platform's. A full review
|
|
95
|
+
// uses the platform's figure; without one the band decides, as before.
|
|
96
|
+
export function runCostEstimate<Band extends { high: number }>(
|
|
97
|
+
platform: PlatformEstimate | undefined,
|
|
98
|
+
band: Band,
|
|
99
|
+
fullBand: { high: number } | undefined,
|
|
100
|
+
): Band | ReturnType<typeof platformCostEstimate> {
|
|
101
|
+
if (platform === undefined) return band;
|
|
102
|
+
const estimate = platformCostEstimate(platform);
|
|
103
|
+
if (fullBand === undefined || !(fullBand.high > 0)) return estimate;
|
|
104
|
+
const share = Math.min(1, Math.max(0, band.high / fullBand.high));
|
|
105
|
+
return {
|
|
106
|
+
...estimate,
|
|
107
|
+
low: estimate.low * share,
|
|
108
|
+
high: estimate.high * share,
|
|
109
|
+
basis: `${estimate.basis} Scaled to the ${Math.round(share * 100)}% of a full review this run does.`,
|
|
110
|
+
};
|
|
111
|
+
}
|
package/src/ci/platform-trace.ts
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
import { PLATFORM_API_URL } from "./platform";
|
|
43
43
|
import { decidePublication } from "./publish";
|
|
44
44
|
import {
|
|
45
|
+
type AttemptStart,
|
|
45
46
|
encodeTrace,
|
|
46
47
|
type TraceAttemptInput,
|
|
47
48
|
type TraceOutcome,
|
|
@@ -134,6 +135,7 @@ export function locateRunDir(
|
|
|
134
135
|
const EVIDENCE = /^evidence\.(.+)\.attempt(\d+)\.json$/;
|
|
135
136
|
const CAPTURE = /^evidence\.(.+)\.attempt(\d+)\.capture\.json$/;
|
|
136
137
|
const TRANSCRIPT = /^trace\.(.+)\.attempt(\d+)\.jsonl$/;
|
|
138
|
+
const REQUEST = /^evidence\.(.+)\.attempt(\d+)\.request\.json$/;
|
|
137
139
|
|
|
138
140
|
// Every step the run directory holds files for: pipeline.json's steps, and any
|
|
139
141
|
// step whose evidence or transcript exists without a pipeline row (a run that
|
|
@@ -185,6 +187,16 @@ export function readRunSteps(
|
|
|
185
187
|
}
|
|
186
188
|
continue;
|
|
187
189
|
}
|
|
190
|
+
// #511: the plan an attempt freezes at spawn, the one file a hunter still
|
|
191
|
+
// running at a cancel has written.
|
|
192
|
+
const request = REQUEST.exec(name);
|
|
193
|
+
if (request?.[1] !== undefined) {
|
|
194
|
+
const started = attemptStart(file);
|
|
195
|
+
if (started !== undefined) {
|
|
196
|
+
attemptOf(request[1], Number(request[2])).started = started;
|
|
197
|
+
}
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
188
200
|
const evidence = EVIDENCE.exec(name);
|
|
189
201
|
if (evidence?.[1] !== undefined) {
|
|
190
202
|
const parsed = readJson(file);
|
|
@@ -252,6 +264,24 @@ export function readRunSteps(
|
|
|
252
264
|
});
|
|
253
265
|
}
|
|
254
266
|
|
|
267
|
+
// What a frozen request plan says of its attempt: its route's model and
|
|
268
|
+
// provider, and the file's time as the spawn's.
|
|
269
|
+
function attemptStart(file: string): AttemptStart | undefined {
|
|
270
|
+
const plan = readJson(file);
|
|
271
|
+
if (!isRecord(plan)) return undefined;
|
|
272
|
+
const route = isRecord(plan.route) ? plan.route : {};
|
|
273
|
+
const started: AttemptStart = {};
|
|
274
|
+
const atMs = mtimeMs(file);
|
|
275
|
+
if (atMs !== undefined) started.atMs = atMs;
|
|
276
|
+
if (typeof route.modelSnapshot === "string" && route.modelSnapshot !== "") {
|
|
277
|
+
started.model = route.modelSnapshot;
|
|
278
|
+
}
|
|
279
|
+
if (typeof route.provider === "string" && route.provider !== "") {
|
|
280
|
+
started.provider = route.provider;
|
|
281
|
+
}
|
|
282
|
+
return started;
|
|
283
|
+
}
|
|
284
|
+
|
|
255
285
|
// An OpenCode capture's metadata: its conversation without content. The text
|
|
256
286
|
// and the parsed capture are dropped on return.
|
|
257
287
|
function captureMetadata(file: string): Conversation | undefined {
|
package/src/ci/platform.ts
CHANGED
|
@@ -21,6 +21,13 @@
|
|
|
21
21
|
|
|
22
22
|
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
23
23
|
import path from "node:path";
|
|
24
|
+
// A sibling with no imports of its own, so the builtins-only rule still holds.
|
|
25
|
+
import {
|
|
26
|
+
PLATFORM_ESTIMATE_CAPABILITY,
|
|
27
|
+
type PlatformEstimate,
|
|
28
|
+
parsePlatformEstimate,
|
|
29
|
+
serializePlatformEstimate,
|
|
30
|
+
} from "./platform-estimate";
|
|
24
31
|
|
|
25
32
|
export const PLATFORM_API_URL = "https://api.crysk.dev";
|
|
26
33
|
|
|
@@ -106,6 +113,8 @@ export type PlatformTokenResult =
|
|
|
106
113
|
// `full` or `metadata_only`; the connect step reads absence as metadata_only.
|
|
107
114
|
// `traceContent` is present, and true, only when the platform sent exactly
|
|
108
115
|
// `true`; the connect step reads absence as false.
|
|
116
|
+
// `estimate` is present only for the first connect step (refresh steps do not
|
|
117
|
+
// ask for one) and only when the platform sent a usable range.
|
|
109
118
|
| {
|
|
110
119
|
ok: true;
|
|
111
120
|
githubToken: string;
|
|
@@ -114,6 +123,7 @@ export type PlatformTokenResult =
|
|
|
114
123
|
dataMode?: PlatformDataMode;
|
|
115
124
|
traceContent?: true;
|
|
116
125
|
config?: PlatformConfig;
|
|
126
|
+
estimate?: PlatformEstimate;
|
|
117
127
|
}
|
|
118
128
|
// `message` names the HTTP status and the API's own `message` when there was
|
|
119
129
|
// one. It never carries a token.
|
|
@@ -235,6 +245,11 @@ export async function exchangePlatformToken(
|
|
|
235
245
|
headers: {
|
|
236
246
|
Authorization: `Bearer ${oidc}`,
|
|
237
247
|
"X-Crysk-Dispatch-Id": dispatchId,
|
|
248
|
+
// Only the first connect step asks: its estimate is the one the budget
|
|
249
|
+
// gate reads, and the platform records each estimate it sends.
|
|
250
|
+
...(deps.ignoreConfig === true
|
|
251
|
+
? {}
|
|
252
|
+
: { "X-Crysk-Capabilities": PLATFORM_ESTIMATE_CAPABILITY }),
|
|
238
253
|
},
|
|
239
254
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
240
255
|
});
|
|
@@ -252,6 +267,7 @@ export async function exchangePlatformToken(
|
|
|
252
267
|
data_mode?: unknown;
|
|
253
268
|
trace_content?: unknown;
|
|
254
269
|
config?: unknown;
|
|
270
|
+
estimate?: unknown;
|
|
255
271
|
};
|
|
256
272
|
const {
|
|
257
273
|
github_token: githubToken,
|
|
@@ -285,6 +301,12 @@ export async function exchangePlatformToken(
|
|
|
285
301
|
[...secrets, githubToken, runToken],
|
|
286
302
|
);
|
|
287
303
|
}
|
|
304
|
+
// An estimate is advice: one that does not parse is dropped and the
|
|
305
|
+
// engine's own band decides, never a failed exchange.
|
|
306
|
+
const estimate =
|
|
307
|
+
deps.ignoreConfig === true
|
|
308
|
+
? undefined
|
|
309
|
+
: parsePlatformEstimate(body.estimate);
|
|
288
310
|
return {
|
|
289
311
|
ok: true,
|
|
290
312
|
githubToken,
|
|
@@ -300,6 +322,7 @@ export async function exchangePlatformToken(
|
|
|
300
322
|
// an absent or malformed value sends metadata only.
|
|
301
323
|
...(body.trace_content === true ? { traceContent: true as const } : {}),
|
|
302
324
|
...(config.config === undefined ? {} : { config: config.config }),
|
|
325
|
+
...(estimate === undefined ? {} : { estimate }),
|
|
303
326
|
};
|
|
304
327
|
} catch (error) {
|
|
305
328
|
const detail = error instanceof Error ? error.message : String(error);
|
|
@@ -402,6 +425,13 @@ export async function runPlatformConnect(
|
|
|
402
425
|
if (result.githubActor !== undefined) {
|
|
403
426
|
deps.appendOutput(`github-actor=${result.githubActor}\n`);
|
|
404
427
|
}
|
|
428
|
+
// Not a secret: two validated numbers and a basis. The run step's budget
|
|
429
|
+
// gate reads it as CRYSK_PLATFORM_ESTIMATE in place of the engine's band.
|
|
430
|
+
if (result.estimate !== undefined) {
|
|
431
|
+
deps.appendOutput(
|
|
432
|
+
`estimate=${serializePlatformEstimate(result.estimate)}\n`,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
405
435
|
// Present only when there is configuration to apply: the setup step and the
|
|
406
436
|
// run step are gated on it, so a standalone run (no platform step, no
|
|
407
437
|
// output) and an empty config both skip everything.
|
package/src/ci/reporter.ts
CHANGED
|
@@ -150,6 +150,9 @@ interface CiSkipSizeSummary {
|
|
|
150
150
|
changedFiles: number;
|
|
151
151
|
maxChangedLines: number;
|
|
152
152
|
maxChangedFiles: number;
|
|
153
|
+
// A platform-connected run: the limits live in the Crysk dashboard, not in
|
|
154
|
+
// workflow inputs, so the summary says so like the comment does.
|
|
155
|
+
platformConnected?: true;
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
interface CiSkipBudgetSummary {
|
|
@@ -157,6 +160,8 @@ interface CiSkipBudgetSummary {
|
|
|
157
160
|
prNumber: number;
|
|
158
161
|
estimatedCostUsd: number;
|
|
159
162
|
budgetUsd: number;
|
|
163
|
+
// A platform repository has no `--budget-usd` to raise (cryskai/platform#12).
|
|
164
|
+
platformConnected?: true;
|
|
160
165
|
}
|
|
161
166
|
|
|
162
167
|
interface CiSkipExcludedSummary {
|
|
@@ -327,8 +332,11 @@ function skipSizeLines(data: CiSkipSizeSummary): string[] {
|
|
|
327
332
|
`| Changed lines | ${data.changedLines} (${sizeLimitText(data.maxChangedLines)}) |`,
|
|
328
333
|
`| Changed files | ${data.changedFiles} (${sizeLimitText(data.maxChangedFiles)}) |`,
|
|
329
334
|
"",
|
|
330
|
-
|
|
331
|
-
"
|
|
335
|
+
data.platformConnected === true
|
|
336
|
+
? "Crysk did not run to avoid reviewing an unbounded diff. Split the " +
|
|
337
|
+
"PR or raise the size limits in the Crysk dashboard."
|
|
338
|
+
: "Crysk did not run to avoid reviewing an unbounded diff. Split the " +
|
|
339
|
+
"PR or raise `max-changed-lines` / `max-changed-files`.",
|
|
332
340
|
];
|
|
333
341
|
}
|
|
334
342
|
|
|
@@ -342,8 +350,10 @@ function skipBudgetLines(data: CiSkipBudgetSummary): string[] {
|
|
|
342
350
|
"| --- | --- |",
|
|
343
351
|
`| Estimated cost | ${usd(data.estimatedCostUsd)} (budget ${usd(data.budgetUsd)}) |`,
|
|
344
352
|
"",
|
|
345
|
-
|
|
346
|
-
"
|
|
353
|
+
data.platformConnected === true
|
|
354
|
+
? "To change what reviews cost, change the model setup in the Crysk dashboard."
|
|
355
|
+
: "Crysk did not run to stay within the configured `--budget-usd` " +
|
|
356
|
+
"ceiling.",
|
|
347
357
|
];
|
|
348
358
|
}
|
|
349
359
|
|
package/src/ci/setup.ts
CHANGED
|
@@ -87,6 +87,7 @@ import {
|
|
|
87
87
|
import { CliError } from "../errors";
|
|
88
88
|
import { prheroLayout } from "../home-preflight";
|
|
89
89
|
import { parseIgnoreFile } from "../ignore-file";
|
|
90
|
+
import { credentialKindForRoute } from "../runner-authority";
|
|
90
91
|
import { resolveOpenCodeAuthPath } from "../security/credential-broker";
|
|
91
92
|
import {
|
|
92
93
|
type OpenCodeSecretManifestEntry,
|
|
@@ -852,6 +853,37 @@ export function openCodeProvidersOfModels(models: unknown): string[] {
|
|
|
852
853
|
return [...providers].sort();
|
|
853
854
|
}
|
|
854
855
|
|
|
856
|
+
// Whether an OpenCode route this run takes bills per token (cryskai/platform#12
|
|
857
|
+
// item 5): an auth file exists AND some OpenCode provider among the run's
|
|
858
|
+
// resolved routes, any step or fallback, binds an API key, by the same rule the
|
|
859
|
+
// run binds it with (credentialKindForRoute over the secret manifest's names, the
|
|
860
|
+
// provider literal without one). `providers` comes from the run's own route plan,
|
|
861
|
+
// so every source routing reads counts (`models`, `--model`, `--scout-model`, a
|
|
862
|
+
// spec model, a prompt's frontmatter, the engine's defaults). Undefined means the
|
|
863
|
+
// routes could not be resolved here: the auth file decides, the old rule, which
|
|
864
|
+
// keeps the ceiling. The file alone is not enough otherwise: it also exists for a
|
|
865
|
+
// ChatGPT subscription, after an earlier run on a runner whose HOME persists, or
|
|
866
|
+
// from a local `opencode auth login`. And no file means no credential for a
|
|
867
|
+
// per-token route, as before: a free `opencode/*` model stays unmetered.
|
|
868
|
+
export function openCodeRoutesBillMetered(input: {
|
|
869
|
+
providers: readonly string[] | undefined;
|
|
870
|
+
authFilePresent: boolean;
|
|
871
|
+
openCodeSecretNames: readonly string[] | undefined;
|
|
872
|
+
}): boolean {
|
|
873
|
+
if (!input.authFilePresent) return false;
|
|
874
|
+
if (input.providers === undefined) return true;
|
|
875
|
+
return input.providers.some(
|
|
876
|
+
(provider) =>
|
|
877
|
+
credentialKindForRoute(
|
|
878
|
+
"opencode",
|
|
879
|
+
provider,
|
|
880
|
+
{},
|
|
881
|
+
false,
|
|
882
|
+
input.openCodeSecretNames,
|
|
883
|
+
) === "provider_api_token",
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
|
|
855
887
|
interface OpenCodeAuthAssembly {
|
|
856
888
|
// provider id -> its auth.json record.
|
|
857
889
|
readonly records: Record<string, Record<string, unknown>>;
|