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/src/ci/trace-bundle.ts
CHANGED
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
openCodeConversation,
|
|
49
49
|
parseClaudeSession,
|
|
50
50
|
type ToolCall,
|
|
51
|
+
type Turn,
|
|
51
52
|
withoutContent,
|
|
52
53
|
} from "./trace-transcripts";
|
|
53
54
|
|
|
@@ -148,6 +149,16 @@ export interface TraceAttemptInput {
|
|
|
148
149
|
// or results, the finish reason, the response model and the times. Used
|
|
149
150
|
// only when neither text is present.
|
|
150
151
|
transcriptMetadata?: Conversation;
|
|
152
|
+
// steps/evidence.<step>.attempt<n>.request.json, the plan frozen at spawn
|
|
153
|
+
// (#511): its route and its file time. The only file an attempt still
|
|
154
|
+
// running when the job was cancelled has written, so the only proof it ran.
|
|
155
|
+
started?: AttemptStart;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface AttemptStart {
|
|
159
|
+
atMs?: number;
|
|
160
|
+
model?: string;
|
|
161
|
+
provider?: string;
|
|
151
162
|
}
|
|
152
163
|
|
|
153
164
|
export interface TraceStepInput {
|
|
@@ -409,7 +420,33 @@ interface AttemptFacts {
|
|
|
409
420
|
end?: number;
|
|
410
421
|
}
|
|
411
422
|
|
|
412
|
-
|
|
423
|
+
// An attempt with a frozen plan that nothing shows settled: the job ended
|
|
424
|
+
// while it ran. Missing evidence alone is not enough: the engine races its
|
|
425
|
+
// evidence write against a 100 ms timer and swallows a failure
|
|
426
|
+
// (src/execution/harness.ts runAdmittedAttempt), so a settled attempt can
|
|
427
|
+
// have none. `settled` is what else proves it: a step status of ok or failed
|
|
428
|
+
// (pipeline.ts stamps every step "unsettled" until it settles), or a later
|
|
429
|
+
// attempt. A transcript or capture is no proof: the harness copies a
|
|
430
|
+
// cancelled attempt's session too.
|
|
431
|
+
const UNSETTLED = "unsettled";
|
|
432
|
+
|
|
433
|
+
function attemptFacts(
|
|
434
|
+
attempt: TraceAttemptInput,
|
|
435
|
+
settled: boolean,
|
|
436
|
+
): AttemptFacts {
|
|
437
|
+
const facts = settledFacts(attempt.evidence);
|
|
438
|
+
const started = attempt.started;
|
|
439
|
+
if (started === undefined) return facts;
|
|
440
|
+
facts.model ??= started.model;
|
|
441
|
+
facts.provider ??= started.provider;
|
|
442
|
+
facts.start ??= started.atMs;
|
|
443
|
+
if (attempt.evidence === undefined && !settled) {
|
|
444
|
+
facts.completion = UNSETTLED;
|
|
445
|
+
}
|
|
446
|
+
return facts;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function settledFacts(evidence: unknown): AttemptFacts {
|
|
413
450
|
if (!isRecord(evidence)) return {};
|
|
414
451
|
const identity = isRecord(evidence.identity) ? evidence.identity : {};
|
|
415
452
|
const route = isRecord(identity.route) ? identity.route : {};
|
|
@@ -653,7 +690,12 @@ function build(
|
|
|
653
690
|
const attempts = [...step.attempts].sort((a, b) => a.attempt - b.attempt);
|
|
654
691
|
const finalAttempt = attempts.at(-1)?.attempt;
|
|
655
692
|
for (const attempt of attempts) {
|
|
656
|
-
const facts = attemptFacts(
|
|
693
|
+
const facts = attemptFacts(
|
|
694
|
+
attempt,
|
|
695
|
+
meta?.status === "ok" ||
|
|
696
|
+
meta?.status === "failed" ||
|
|
697
|
+
attempt.attempt !== finalAttempt,
|
|
698
|
+
);
|
|
657
699
|
const known = content ? undefined : views.get(attempt);
|
|
658
700
|
const parsed: ParsedAttempt =
|
|
659
701
|
known === undefined ? parseAttempt(attempt) : { conversation: known };
|
|
@@ -665,8 +707,146 @@ function build(
|
|
|
665
707
|
if (chatWindow.start === undefined) {
|
|
666
708
|
widen(chatWindow, conversation.startMs, conversation.endMs);
|
|
667
709
|
}
|
|
668
|
-
|
|
710
|
+
// It ran until the job stopped, as far as anything recorded says.
|
|
711
|
+
if (facts.completion === UNSETTLED) widen(chatWindow, run.endedAtMs);
|
|
669
712
|
const model = facts.model ?? str(meta?.model);
|
|
713
|
+
const cause = modelCause(meta, model);
|
|
714
|
+
const failed =
|
|
715
|
+
facts.completion !== undefined &&
|
|
716
|
+
facts.completion !== "success" &&
|
|
717
|
+
facts.completion !== "completed";
|
|
718
|
+
const turns = conversation.turns ?? [];
|
|
719
|
+
if (turns.length > 0) {
|
|
720
|
+
// #511: one generation per model turn, under an attempt span that is
|
|
721
|
+
// no generation itself, so a backend neither counts the attempt's
|
|
722
|
+
// usage twice nor reads its whole length as one model call.
|
|
723
|
+
const attrs = new Attributes(content, budget);
|
|
724
|
+
attrs.text("crysk.step.name", step.name);
|
|
725
|
+
attrs.number("crysk.attempt.number", attempt.attempt);
|
|
726
|
+
attrs.text("crysk.attempt.status", facts.completion);
|
|
727
|
+
attrs.text("crysk.attempt.cause", cause);
|
|
728
|
+
if (facts.usage !== undefined)
|
|
729
|
+
attrs.flatten("crysk.usage", facts.usage);
|
|
730
|
+
if (attempt.evidence !== undefined) {
|
|
731
|
+
attrs.flatten("crysk.attempt", attempt.evidence);
|
|
732
|
+
}
|
|
733
|
+
const turnIds = turns.map((_, index) =>
|
|
734
|
+
id(`turn:${step.name}:${attempt.attempt}:${index}`),
|
|
735
|
+
);
|
|
736
|
+
const toolSpans = conversation.tools.map((call, index) => {
|
|
737
|
+
const owner = call.turn === undefined ? undefined : turns[call.turn];
|
|
738
|
+
return toolSpan(call, {
|
|
739
|
+
traceId,
|
|
740
|
+
spanId: id(`tool:${step.name}:${attempt.attempt}:${index}`),
|
|
741
|
+
parentSpanId:
|
|
742
|
+
call.turn === undefined ? chatId : (turnIds[call.turn] ?? chatId),
|
|
743
|
+
content,
|
|
744
|
+
...(budget === undefined ? {} : { budget }),
|
|
745
|
+
fallbackMs: owner?.startMs ?? chatWindow.start ?? run.startedAtMs,
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
const container: OtlpSpan = {
|
|
749
|
+
traceId,
|
|
750
|
+
spanId: chatId,
|
|
751
|
+
parentSpanId: stepId,
|
|
752
|
+
name: spanName("attempt", `${step.name}#${attempt.attempt}`),
|
|
753
|
+
kind: SPAN_KIND_INTERNAL,
|
|
754
|
+
startTimeUnixNano: "",
|
|
755
|
+
endTimeUnixNano: "",
|
|
756
|
+
attributes: attrs.list,
|
|
757
|
+
status: failed
|
|
758
|
+
? withMessage(
|
|
759
|
+
STATUS_ERROR,
|
|
760
|
+
content ? (cause ?? facts.completion) : undefined,
|
|
761
|
+
)
|
|
762
|
+
: {
|
|
763
|
+
code: facts.completion === undefined ? STATUS_UNSET : STATUS_OK,
|
|
764
|
+
},
|
|
765
|
+
};
|
|
766
|
+
stepSpans.push(container);
|
|
767
|
+
const input = content ? chatInput(step, conversation) : [];
|
|
768
|
+
turns.forEach((turn, index) => {
|
|
769
|
+
const own = toolSpans.filter(
|
|
770
|
+
(_, at) => conversation.tools[at]?.turn === index,
|
|
771
|
+
);
|
|
772
|
+
const window: Window = {};
|
|
773
|
+
widen(window, turn.startMs, turn.endMs);
|
|
774
|
+
// A turn still being written has no end of its own: its last tool
|
|
775
|
+
// call is the last thing it did.
|
|
776
|
+
if (turn.endMs === undefined) {
|
|
777
|
+
for (const span of own) {
|
|
778
|
+
widen(window, undefined, Number(span.endTimeUnixNano) / 1e6);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
widen(chatWindow, window.start, window.end);
|
|
782
|
+
const turnAttrs = new Attributes(content, budget);
|
|
783
|
+
turnAttrs.text("gen_ai.operation.name", "chat");
|
|
784
|
+
turnAttrs.text("gen_ai.provider.name", facts.provider);
|
|
785
|
+
turnAttrs.text("gen_ai.request.model", model);
|
|
786
|
+
turnAttrs.text("gen_ai.response.model", turn.model ?? model);
|
|
787
|
+
if (turn.finishReason !== undefined) {
|
|
788
|
+
turnAttrs.words("gen_ai.response.finish_reasons", [
|
|
789
|
+
turn.finishReason,
|
|
790
|
+
]);
|
|
791
|
+
}
|
|
792
|
+
writeTurnUsage(turnAttrs, turn);
|
|
793
|
+
turnAttrs.text("crysk.step.name", step.name);
|
|
794
|
+
turnAttrs.number("crysk.attempt.number", attempt.attempt);
|
|
795
|
+
turnAttrs.number("crysk.turn.number", index + 1);
|
|
796
|
+
if (content) {
|
|
797
|
+
// The prompt once, on the turn that read it; each turn's answer on
|
|
798
|
+
// its own span. Repeating the history on every turn would grow
|
|
799
|
+
// with the square of the turns.
|
|
800
|
+
if (index === 0) writeChatInput(turnAttrs, step, input);
|
|
801
|
+
if (turn.message !== undefined) {
|
|
802
|
+
turnAttrs.contentJson("gen_ai.output.messages", [turn.message]);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const span: OtlpSpan = {
|
|
806
|
+
traceId,
|
|
807
|
+
spanId: turnIds[index] ?? chatId,
|
|
808
|
+
parentSpanId: chatId,
|
|
809
|
+
name: spanName("chat", model),
|
|
810
|
+
kind: SPAN_KIND_CLIENT,
|
|
811
|
+
startTimeUnixNano: "",
|
|
812
|
+
endTimeUnixNano: "",
|
|
813
|
+
attributes: turnAttrs.list,
|
|
814
|
+
status: {
|
|
815
|
+
code:
|
|
816
|
+
turn.isError === true
|
|
817
|
+
? STATUS_ERROR
|
|
818
|
+
: turn.finishReason !== undefined
|
|
819
|
+
? STATUS_OK
|
|
820
|
+
: STATUS_UNSET,
|
|
821
|
+
},
|
|
822
|
+
};
|
|
823
|
+
pending.push({ span, window });
|
|
824
|
+
stepSpans.push(span, ...own);
|
|
825
|
+
});
|
|
826
|
+
stepSpans.push(
|
|
827
|
+
...toolSpans.filter((_, at) => {
|
|
828
|
+
const owner = conversation.tools[at]?.turn;
|
|
829
|
+
return owner === undefined || turnIds[owner] === undefined;
|
|
830
|
+
}),
|
|
831
|
+
);
|
|
832
|
+
for (const span of toolSpans) {
|
|
833
|
+
widen(
|
|
834
|
+
chatWindow,
|
|
835
|
+
Number(span.startTimeUnixNano) / 1e6,
|
|
836
|
+
Number(span.endTimeUnixNano) / 1e6,
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
pending.push({ span: container, window: chatWindow });
|
|
840
|
+
widen(stepWindow, chatWindow.start, chatWindow.end);
|
|
841
|
+
if (content) {
|
|
842
|
+
transcripts.push(...transcriptsOf(step.name, attempt, parsed, model));
|
|
843
|
+
}
|
|
844
|
+
if (known === undefined && attempt.openCodeCapture !== undefined) {
|
|
845
|
+
settle?.();
|
|
846
|
+
}
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
const attrs = new Attributes(content, budget);
|
|
670
850
|
attrs.text("gen_ai.operation.name", "chat");
|
|
671
851
|
attrs.text("gen_ai.provider.name", facts.provider);
|
|
672
852
|
attrs.text("gen_ai.request.model", model);
|
|
@@ -680,7 +860,6 @@ function build(
|
|
|
680
860
|
attrs.text("crysk.step.name", step.name);
|
|
681
861
|
attrs.number("crysk.attempt.number", attempt.attempt);
|
|
682
862
|
attrs.text("crysk.attempt.status", facts.completion);
|
|
683
|
-
const cause = modelCause(meta, model);
|
|
684
863
|
attrs.text("crysk.attempt.cause", cause);
|
|
685
864
|
if (attempt.evidence !== undefined) {
|
|
686
865
|
attrs.flatten("crysk.attempt", attempt.evidence);
|
|
@@ -708,10 +887,6 @@ function build(
|
|
|
708
887
|
Number(span.endTimeUnixNano) / 1e6,
|
|
709
888
|
);
|
|
710
889
|
}
|
|
711
|
-
const failed =
|
|
712
|
-
facts.completion !== undefined &&
|
|
713
|
-
facts.completion !== "success" &&
|
|
714
|
-
facts.completion !== "completed";
|
|
715
890
|
const chat: OtlpSpan = {
|
|
716
891
|
traceId,
|
|
717
892
|
spanId: chatId,
|
|
@@ -857,25 +1032,7 @@ function writeChatContent(
|
|
|
857
1032
|
conversation: Conversation,
|
|
858
1033
|
context: { final: boolean; completion?: string },
|
|
859
1034
|
): void {
|
|
860
|
-
|
|
861
|
-
attrs.contentJson("gen_ai.system_instructions", [
|
|
862
|
-
{ type: "text", content: step.systemPrompt },
|
|
863
|
-
]);
|
|
864
|
-
}
|
|
865
|
-
const input: ChatMessage[] =
|
|
866
|
-
conversation.input.length > 0
|
|
867
|
-
? conversation.input
|
|
868
|
-
: step.promptBody !== undefined
|
|
869
|
-
? [
|
|
870
|
-
{
|
|
871
|
-
role: "user",
|
|
872
|
-
parts: [{ type: "text", content: step.promptBody }],
|
|
873
|
-
},
|
|
874
|
-
]
|
|
875
|
-
: [];
|
|
876
|
-
if (input.length > 0) {
|
|
877
|
-
attrs.contentJson("gen_ai.input.messages", input);
|
|
878
|
-
}
|
|
1035
|
+
writeChatInput(attrs, step, chatInput(step, conversation));
|
|
879
1036
|
// Without a transcript, the final attempt's output file is what it answered.
|
|
880
1037
|
const output: ChatMessage[] =
|
|
881
1038
|
conversation.output.length > 0
|
|
@@ -897,6 +1054,53 @@ function writeChatContent(
|
|
|
897
1054
|
}
|
|
898
1055
|
}
|
|
899
1056
|
|
|
1057
|
+
// What the model was asked: the transcript's user messages, else the step's
|
|
1058
|
+
// rendered body.
|
|
1059
|
+
function chatInput(
|
|
1060
|
+
step: TraceStepInput,
|
|
1061
|
+
conversation: Conversation,
|
|
1062
|
+
): ChatMessage[] {
|
|
1063
|
+
if (conversation.input.length > 0) return conversation.input;
|
|
1064
|
+
return step.promptBody === undefined
|
|
1065
|
+
? []
|
|
1066
|
+
: [{ role: "user", parts: [{ type: "text", content: step.promptBody }] }];
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
function writeChatInput(
|
|
1070
|
+
attrs: Attributes,
|
|
1071
|
+
step: TraceStepInput,
|
|
1072
|
+
input: ChatMessage[],
|
|
1073
|
+
): void {
|
|
1074
|
+
if (step.systemPrompt !== undefined) {
|
|
1075
|
+
attrs.contentJson("gen_ai.system_instructions", [
|
|
1076
|
+
{ type: "text", content: step.systemPrompt },
|
|
1077
|
+
]);
|
|
1078
|
+
}
|
|
1079
|
+
if (input.length > 0) {
|
|
1080
|
+
attrs.contentJson("gen_ai.input.messages", input);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// A turn's usage in the conventions' totals: input with its cache, output
|
|
1085
|
+
// with its reasoning (OpenCode's leaves are disjoint, as the engine's are).
|
|
1086
|
+
function writeTurnUsage(attrs: Attributes, turn: Turn): void {
|
|
1087
|
+
attrs.number(
|
|
1088
|
+
"gen_ai.usage.input_tokens",
|
|
1089
|
+
sumKnown(turn.inputTokens, turn.cacheReadTokens, turn.cacheWriteTokens),
|
|
1090
|
+
);
|
|
1091
|
+
attrs.number(
|
|
1092
|
+
"gen_ai.usage.output_tokens",
|
|
1093
|
+
sumKnown(turn.outputTokens, turn.reasoningTokens),
|
|
1094
|
+
);
|
|
1095
|
+
attrs.number("gen_ai.usage.cache_read.input_tokens", turn.cacheReadTokens);
|
|
1096
|
+
attrs.number(
|
|
1097
|
+
"gen_ai.usage.cache_creation.input_tokens",
|
|
1098
|
+
turn.cacheWriteTokens,
|
|
1099
|
+
);
|
|
1100
|
+
attrs.number("gen_ai.usage.reasoning.output_tokens", turn.reasoningTokens);
|
|
1101
|
+
attrs.number("gen_ai.usage.cost", turn.costUsd);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
900
1104
|
function toolSpan(
|
|
901
1105
|
call: ToolCall,
|
|
902
1106
|
context: {
|
|
@@ -41,6 +41,28 @@ export interface ToolCall {
|
|
|
41
41
|
isError?: boolean;
|
|
42
42
|
startMs?: number;
|
|
43
43
|
endMs?: number;
|
|
44
|
+
// The index in Conversation.turns of the model turn that made this call.
|
|
45
|
+
turn?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// One model call of an agent loop (#511): an OpenCode attempt is dozens of
|
|
49
|
+
// these, one assistant message each, and each message records its own times,
|
|
50
|
+
// tokens and cost. Token counts are OpenCode's disjoint leaves.
|
|
51
|
+
export interface Turn {
|
|
52
|
+
startMs?: number;
|
|
53
|
+
endMs?: number;
|
|
54
|
+
// The model the provider says answered this turn.
|
|
55
|
+
model?: string;
|
|
56
|
+
finishReason?: string;
|
|
57
|
+
isError?: boolean;
|
|
58
|
+
inputTokens?: number;
|
|
59
|
+
outputTokens?: number;
|
|
60
|
+
reasoningTokens?: number;
|
|
61
|
+
cacheReadTokens?: number;
|
|
62
|
+
cacheWriteTokens?: number;
|
|
63
|
+
costUsd?: number;
|
|
64
|
+
// What the turn answered. Content only: withoutContent drops it.
|
|
65
|
+
message?: ChatMessage;
|
|
44
66
|
}
|
|
45
67
|
|
|
46
68
|
export interface Conversation {
|
|
@@ -53,6 +75,8 @@ export interface Conversation {
|
|
|
53
75
|
finishReason?: string;
|
|
54
76
|
startMs?: number;
|
|
55
77
|
endMs?: number;
|
|
78
|
+
// The model turns, when the transcript records each one (OpenCode).
|
|
79
|
+
turns?: Turn[];
|
|
56
80
|
}
|
|
57
81
|
|
|
58
82
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -112,6 +136,11 @@ export function withoutContent(conversation: Conversation): Conversation {
|
|
|
112
136
|
tools: conversation.tools.map(
|
|
113
137
|
({ arguments: _a, result: _r, ...call }) => call,
|
|
114
138
|
),
|
|
139
|
+
...(conversation.turns === undefined
|
|
140
|
+
? {}
|
|
141
|
+
: {
|
|
142
|
+
turns: conversation.turns.map(({ message: _m, ...turn }) => turn),
|
|
143
|
+
}),
|
|
115
144
|
};
|
|
116
145
|
}
|
|
117
146
|
|
|
@@ -370,6 +399,9 @@ export function openCodeConversation(capture: unknown): Conversation {
|
|
|
370
399
|
}
|
|
371
400
|
if (info.role !== "assistant") continue;
|
|
372
401
|
const message: ChatMessage = { role: "assistant", parts: [] };
|
|
402
|
+
const turn = openCodeTurn(info);
|
|
403
|
+
const turnIndex = conversation.turns?.length ?? 0;
|
|
404
|
+
conversation.turns = [...(conversation.turns ?? []), turn];
|
|
373
405
|
const model = nonEmpty(info.modelID);
|
|
374
406
|
if (model !== undefined) conversation.responseModel = model;
|
|
375
407
|
const finish = nonEmpty(info.finish);
|
|
@@ -390,6 +422,7 @@ export function openCodeConversation(capture: unknown): Conversation {
|
|
|
390
422
|
...(id === undefined ? {} : { id }),
|
|
391
423
|
name: part.tool,
|
|
392
424
|
...(state.input === undefined ? {} : { arguments: state.input }),
|
|
425
|
+
turn: turnIndex,
|
|
393
426
|
};
|
|
394
427
|
const result = nonEmpty(state.output) ?? nonEmpty(state.error);
|
|
395
428
|
if (result !== undefined) call.result = result;
|
|
@@ -410,6 +443,38 @@ export function openCodeConversation(capture: unknown): Conversation {
|
|
|
410
443
|
}
|
|
411
444
|
}
|
|
412
445
|
conversation.output.push(message);
|
|
446
|
+
if (message.parts.length > 0) turn.message = message;
|
|
413
447
|
}
|
|
414
448
|
return conversation;
|
|
415
449
|
}
|
|
450
|
+
|
|
451
|
+
function count(value: unknown): number | undefined {
|
|
452
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0
|
|
453
|
+
? value
|
|
454
|
+
: undefined;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// An assistant message's own record: `time.created`/`completed` in epoch ms,
|
|
458
|
+
// `tokens` {input, output, reasoning, cache: {read, write}} and `cost` in USD.
|
|
459
|
+
// A message still being written has no `completed` time.
|
|
460
|
+
function openCodeTurn(info: Record<string, unknown>): Turn {
|
|
461
|
+
const time = isRecord(info.time) ? info.time : {};
|
|
462
|
+
const tokens = isRecord(info.tokens) ? info.tokens : {};
|
|
463
|
+
const cache = isRecord(tokens.cache) ? tokens.cache : {};
|
|
464
|
+
const leaves: Array<[keyof Turn, unknown]> = [
|
|
465
|
+
["startMs", timeOf(time.created)],
|
|
466
|
+
["endMs", timeOf(time.completed)],
|
|
467
|
+
["model", nonEmpty(info.modelID)],
|
|
468
|
+
["finishReason", nonEmpty(info.finish)],
|
|
469
|
+
["inputTokens", count(tokens.input)],
|
|
470
|
+
["outputTokens", count(tokens.output)],
|
|
471
|
+
["reasoningTokens", count(tokens.reasoning)],
|
|
472
|
+
["cacheReadTokens", count(cache.read)],
|
|
473
|
+
["cacheWriteTokens", count(cache.write)],
|
|
474
|
+
["costUsd", count(info.cost)],
|
|
475
|
+
];
|
|
476
|
+
const turn: Record<string, unknown> = {};
|
|
477
|
+
for (const [key, value] of leaves) if (value !== undefined) turn[key] = value;
|
|
478
|
+
if (info.error !== undefined && info.error !== null) turn.isError = true;
|
|
479
|
+
return turn as Turn;
|
|
480
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Public API surface; the deep-review lab consumes exactly these exports.
|
|
3
3
|
|
|
4
4
|
export const ENGINE_NAME = "pr-hero";
|
|
5
|
-
export const ENGINE_VERSION = "0.5.
|
|
5
|
+
export const ENGINE_VERSION = "0.5.1";
|
|
6
6
|
|
|
7
7
|
// errors and git/refs used to reach this surface only through re-exports in
|
|
8
8
|
// review/preflight.ts; they are exported directly now that those re-exports
|
|
@@ -352,6 +352,7 @@ export async function evaluateCiAdmissionGate(input: {
|
|
|
352
352
|
verdict: admissionVerdict,
|
|
353
353
|
admission: admissionContext,
|
|
354
354
|
ciMode: input.ciMode,
|
|
355
|
+
platformConnected: process.env.CRYSK_PLATFORM_CONNECTED === "true",
|
|
355
356
|
});
|
|
356
357
|
const exitCode = await publishCiSkip({
|
|
357
358
|
operatorRoot,
|
|
@@ -394,6 +395,7 @@ export async function evaluateCiAdmissionGate(input: {
|
|
|
394
395
|
verdict: admissionVerdict,
|
|
395
396
|
admission: admissionContext,
|
|
396
397
|
ciMode: input.ciMode,
|
|
398
|
+
platformConnected: process.env.CRYSK_PLATFORM_CONNECTED === "true",
|
|
397
399
|
});
|
|
398
400
|
const exitCode = await publishCiSkip({
|
|
399
401
|
operatorRoot,
|
package/src/pr/discovery.ts
CHANGED
|
@@ -138,6 +138,11 @@ export interface PrDiscoveryResult {
|
|
|
138
138
|
}
|
|
139
139
|
| undefined;
|
|
140
140
|
diffStat: DiffStat;
|
|
141
|
+
// The whole PR range's stat, filtered by the same rules as `diffStat`
|
|
142
|
+
// (merge-base..head, no path restriction). Equal to `diffStat` when discovery
|
|
143
|
+
// read the whole range; the plan divides the two to price a narrowed run
|
|
144
|
+
// (cryskai/platform#12).
|
|
145
|
+
prDiffStat: DiffStat;
|
|
141
146
|
sizeGate: SizeGateVerdict;
|
|
142
147
|
}
|
|
143
148
|
|
|
@@ -426,6 +431,18 @@ export async function resolvePrDiscovery(params: {
|
|
|
426
431
|
}));
|
|
427
432
|
}
|
|
428
433
|
|
|
434
|
+
const prDiffStat =
|
|
435
|
+
discoveryIsPrRange && !skipDiscovery
|
|
436
|
+
? diffStat
|
|
437
|
+
: (
|
|
438
|
+
await computeDiffStatAndSizeGate({
|
|
439
|
+
runGit: git.runGit,
|
|
440
|
+
range: `${diffFromSha}..${headSha}`,
|
|
441
|
+
pathArgs: [],
|
|
442
|
+
gateConfig,
|
|
443
|
+
})
|
|
444
|
+
).diffStat;
|
|
445
|
+
|
|
429
446
|
return {
|
|
430
447
|
prepared,
|
|
431
448
|
skipDiscovery,
|
|
@@ -439,6 +456,7 @@ export async function resolvePrDiscovery(params: {
|
|
|
439
456
|
adjudicationQueue: adjudicationSubjects,
|
|
440
457
|
phaseB,
|
|
441
458
|
diffStat,
|
|
459
|
+
prDiffStat,
|
|
442
460
|
sizeGate,
|
|
443
461
|
};
|
|
444
462
|
}
|
package/src/pr/plan.ts
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { recordPendingCreatedAt, recordReviewing } from "#ci/cli-record";
|
|
24
24
|
import { planCiBudgetSkip } from "#ci/gates";
|
|
25
25
|
import { actionsRunUrl } from "#ci/outcome";
|
|
26
|
+
import { readPlatformEstimate, runCostEstimate } from "#ci/platform-estimate";
|
|
26
27
|
import {
|
|
27
28
|
countFreeRouteSteps,
|
|
28
29
|
type FreeRouteBilling,
|
|
@@ -112,6 +113,8 @@ export async function resolvePrPlanAndConfirm(params: {
|
|
|
112
113
|
diffFromSha: string;
|
|
113
114
|
diffPath: string;
|
|
114
115
|
diffStat: DiffStat;
|
|
116
|
+
// The whole PR range's stat under the same filters (discovery's prDiffStat).
|
|
117
|
+
prDiffStat: DiffStat;
|
|
115
118
|
droppedPaths: string[];
|
|
116
119
|
sizeGate: SizeGateVerdict;
|
|
117
120
|
sizeGateConfirmed: boolean;
|
|
@@ -135,6 +138,8 @@ export async function resolvePrPlanAndConfirm(params: {
|
|
|
135
138
|
ciAdmissionLedger: CiAdmissionLedgerState | null;
|
|
136
139
|
skipDiscovery: boolean;
|
|
137
140
|
hunterCount: number;
|
|
141
|
+
// Hunters a full review of the whole PR runs (fullReviewHunterCount).
|
|
142
|
+
fullHunterCount: number;
|
|
138
143
|
parityFires: boolean;
|
|
139
144
|
verifyQueue: ReturnType<typeof buildPhaseBQueue>["queued"];
|
|
140
145
|
prepared: PreparedDiscovery;
|
|
@@ -144,7 +149,18 @@ export async function resolvePrPlanAndConfirm(params: {
|
|
|
144
149
|
params.verifyQueue.length,
|
|
145
150
|
maxVerificationSteps,
|
|
146
151
|
);
|
|
147
|
-
|
|
152
|
+
// cryskai/platform#12: in a platform run the platform's estimate, priced from
|
|
153
|
+
// the setup's models and its recent reviews, replaces the band, which prices
|
|
154
|
+
// every model as Claude. The platform prices the whole pull request, so a run
|
|
155
|
+
// that covers less of it (a re-review whose discovery reads only the commits
|
|
156
|
+
// or paths since the last review, or one that hunts nothing new) scales it by
|
|
157
|
+
// the share of a full review it does, which the band measures
|
|
158
|
+
// (runCostEstimate). Without a platform estimate (standalone, or nothing
|
|
159
|
+
// priceable) the band decides.
|
|
160
|
+
const platformEstimate = params.isCi
|
|
161
|
+
? readPlatformEstimate(process.env)
|
|
162
|
+
: undefined;
|
|
163
|
+
const band = estimateCost(
|
|
148
164
|
params.diffStat,
|
|
149
165
|
params.hunterCount,
|
|
150
166
|
params.summary.enabled && !params.skipDiscovery,
|
|
@@ -152,6 +168,23 @@ export async function resolvePrPlanAndConfirm(params: {
|
|
|
152
168
|
queuedVerification,
|
|
153
169
|
!params.skipDiscovery,
|
|
154
170
|
);
|
|
171
|
+
// discoveryPaths is null only when the hunters read the full PR range.
|
|
172
|
+
const narrowed =
|
|
173
|
+
params.skipDiscovery || params.prepared.discoveryPaths !== null;
|
|
174
|
+
const estimate = runCostEstimate(
|
|
175
|
+
platformEstimate,
|
|
176
|
+
band,
|
|
177
|
+
narrowed && platformEstimate !== undefined
|
|
178
|
+
? estimateCost(
|
|
179
|
+
params.prDiffStat,
|
|
180
|
+
params.fullHunterCount,
|
|
181
|
+
params.summary.enabled,
|
|
182
|
+
params.options.scout,
|
|
183
|
+
queuedVerification,
|
|
184
|
+
true,
|
|
185
|
+
)
|
|
186
|
+
: undefined,
|
|
187
|
+
);
|
|
155
188
|
// 7b(CI) — the budget gate, immediately after the estimate it reads and
|
|
156
189
|
// BEFORE the plan card/confirm/"committed to spending" commit-status
|
|
157
190
|
// block below: spec 3.1 ("Review MUST halt before agent spawning") is
|
|
@@ -186,6 +219,7 @@ export async function resolvePrPlanAndConfirm(params: {
|
|
|
186
219
|
prNumber: params.prNumber,
|
|
187
220
|
force: params.options.force,
|
|
188
221
|
ciMode: params.ciMode,
|
|
222
|
+
platformConnected: process.env.CRYSK_PLATFORM_CONNECTED === "true",
|
|
189
223
|
});
|
|
190
224
|
if (budgetPlan !== null) {
|
|
191
225
|
await settleCiGateSkip(
|
package/src/pr/review-pr.ts
CHANGED
|
@@ -101,6 +101,7 @@ import {
|
|
|
101
101
|
pipelineSummarizerInput,
|
|
102
102
|
} from "#review/route-preflight";
|
|
103
103
|
import {
|
|
104
|
+
fullReviewHunterCount,
|
|
104
105
|
prepareRunnerForRoute,
|
|
105
106
|
resolveParityFires,
|
|
106
107
|
validateGotchas,
|
|
@@ -308,6 +309,7 @@ export async function reviewPr(
|
|
|
308
309
|
options,
|
|
309
310
|
loaded,
|
|
310
311
|
config,
|
|
312
|
+
summary,
|
|
311
313
|
isCi,
|
|
312
314
|
operatorRoot,
|
|
313
315
|
claudeRun,
|
|
@@ -565,6 +567,7 @@ export async function reviewPr(
|
|
|
565
567
|
adjudicationQueue,
|
|
566
568
|
phaseB,
|
|
567
569
|
diffStat,
|
|
570
|
+
prDiffStat,
|
|
568
571
|
sizeGate,
|
|
569
572
|
} = discovery;
|
|
570
573
|
|
|
@@ -585,6 +588,7 @@ export async function reviewPr(
|
|
|
585
588
|
maxChangedLines: gateConfig.maxChangedLines,
|
|
586
589
|
maxChangedFiles: gateConfig.maxChangedFiles,
|
|
587
590
|
ciMode,
|
|
591
|
+
platformConnected: process.env.CRYSK_PLATFORM_CONNECTED === "true",
|
|
588
592
|
});
|
|
589
593
|
if (sizePlan !== null) {
|
|
590
594
|
await settleCiGateSkip(
|
|
@@ -682,6 +686,11 @@ export async function reviewPr(
|
|
|
682
686
|
parityFires,
|
|
683
687
|
});
|
|
684
688
|
const hunterCount = activeHunters.length;
|
|
689
|
+
const fullHunterCount = fullReviewHunterCount(
|
|
690
|
+
spec.agents,
|
|
691
|
+
anchorPatch,
|
|
692
|
+
config.parity_trigger_paths,
|
|
693
|
+
);
|
|
685
694
|
// See resolvePrPlanAndConfirm (src/pr/plan.ts) for the full rationale —
|
|
686
695
|
// the CI budget gate, route/capability resolution, the plan card, the
|
|
687
696
|
// interactive confirm, and the "committed to spending" commit-status
|
|
@@ -698,6 +707,7 @@ export async function reviewPr(
|
|
|
698
707
|
diffFromSha,
|
|
699
708
|
diffPath,
|
|
700
709
|
diffStat,
|
|
710
|
+
prDiffStat,
|
|
701
711
|
droppedPaths: effectiveDiff.droppedPaths,
|
|
702
712
|
sizeGate,
|
|
703
713
|
sizeGateConfirmed,
|
|
@@ -716,6 +726,7 @@ export async function reviewPr(
|
|
|
716
726
|
ciAdmissionLedger,
|
|
717
727
|
skipDiscovery,
|
|
718
728
|
hunterCount,
|
|
729
|
+
fullHunterCount,
|
|
719
730
|
parityFires,
|
|
720
731
|
verifyQueue,
|
|
721
732
|
prepared,
|