crysk 0.5.0 → 0.6.0
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 +2 -1
- package/package.json +3 -2
- package/skills/crysk-ci-setup/assets/workflow.yml +3 -0
- package/src/asset-manifest.ts +11 -0
- package/src/assets.ts +1 -1
- package/src/ci/credential-refresh.ts +524 -0
- package/src/ci/crysk-secrets.ts +20 -6
- package/src/ci/force-comment.ts +14 -1
- package/src/ci/gates.ts +64 -21
- package/src/ci/outcome.ts +165 -15
- package/src/ci/platform-estimate.ts +111 -0
- package/src/ci/platform-trace.ts +30 -0
- package/src/ci/platform.ts +183 -5
- package/src/ci/reporter.ts +14 -4
- package/src/ci/setup.ts +96 -6
- package/src/ci/trace-bundle.ts +231 -27
- package/src/ci/trace-transcripts.ts +65 -0
- package/src/ci/trigger.ts +20 -4
- package/src/commands/ci-setup.ts +12 -3
- package/src/commands/doctor.ts +25 -23
- package/src/diversity/identity.ts +11 -1
- package/src/diversity/pipeline-integration.ts +19 -6
- package/src/doctor.ts +133 -4
- package/src/execution/contracts.ts +15 -3
- package/src/harness/materiality-judge.ts +153 -0
- package/src/harness/pipeline-plan.ts +133 -0
- package/src/harness/replay-rows.ts +172 -0
- package/src/harness/route-runner.ts +288 -0
- package/src/harness/single-step.ts +153 -0
- package/src/index.ts +1 -1
- package/src/model/catalog.ts +10 -7
- package/src/model/model-name.ts +14 -0
- package/src/model/profiles/claude.ts +34 -0
- package/src/model/profiles/openai.ts +44 -0
- package/src/model/profiles.ts +213 -0
- package/src/model/routing.ts +155 -50
- package/src/pr/ci-admission-gate.ts +2 -0
- package/src/pr/discovery.ts +18 -0
- package/src/pr/plan.ts +41 -2
- package/src/pr/review-pr.ts +43 -6
- package/src/pr/target.ts +67 -15
- package/src/production-runtime.ts +100 -13
- package/src/review/pipeline.ts +193 -58
- package/src/review/preflight.ts +91 -9
- package/src/review/prompt-set.ts +68 -0
- package/src/review/report.ts +4 -0
- package/src/review/review.ts +21 -11
- package/src/review/route-preflight.ts +117 -67
- package/src/review/run.ts +50 -4
- package/src/security/credential-broker.ts +21 -9
- package/src/security/oauth-providers.ts +101 -0
- package/src/transport-registry.ts +33 -0
- package/src/transports/opencode-sdk.ts +33 -1
- package/src/ui/config-edit.ts +9 -0
- package/src/ui/config.ts +1 -0
- package/src/ui/menu.ts +9 -2
- package/src/ui/plan.ts +8 -3
- package/src/updater.ts +21 -13
- package/src/wizard.ts +23 -0
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/ci/trigger.ts
CHANGED
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
// ignored comment costs seconds instead of a dependency install. A package
|
|
20
20
|
// import has no node_modules to resolve against yet, and a `#...` alias is no
|
|
21
21
|
// better: it resolves to a src module whose own imports reach packages. Keep
|
|
22
|
-
// every import here `node:` or `bun`, plus the import-free ../brand
|
|
23
|
-
// ./crysk-secrets (the CRYSK_* grammar, kept import-free for this step)
|
|
22
|
+
// every import here `node:` or `bun`, plus the import-free ../brand,
|
|
23
|
+
// ./crysk-secrets (the CRYSK_* grammar, kept import-free for this step) and the
|
|
24
|
+
// profile registry ../model/profiles.
|
|
24
25
|
|
|
25
26
|
import { randomBytes } from "node:crypto";
|
|
26
27
|
import {
|
|
@@ -33,6 +34,10 @@ import {
|
|
|
33
34
|
} from "node:fs";
|
|
34
35
|
import path from "node:path";
|
|
35
36
|
import { commandHint, isCommand, startsWithCommand } from "../brand";
|
|
37
|
+
// The profile registry: data modules with no runtime imports of their own
|
|
38
|
+
// (test/architecture/profile-registry.test.ts), so the builtins-only rule
|
|
39
|
+
// still holds.
|
|
40
|
+
import { profileRunsOnlyOnOpenCode } from "../model/profiles";
|
|
36
41
|
import {
|
|
37
42
|
type CryskSecretsParse,
|
|
38
43
|
cryskSecretsCarryCredential,
|
|
@@ -868,9 +873,20 @@ function lookupClass(decision: {
|
|
|
868
873
|
|
|
869
874
|
// The route the run would have used. The trigger has no models text, only
|
|
870
875
|
// whether the models in effect name OpenCode: the platform's, or else the
|
|
871
|
-
// `models` input's (action.yml's HAS_OPENCODE_ROUTING, D1).
|
|
876
|
+
// `models` input's (action.yml's HAS_OPENCODE_ROUTING, D1). With no platform
|
|
877
|
+
// answer, a `profile` input whose every route is OpenCode names OpenCode too,
|
|
878
|
+
// unless a `models` default sends every role elsewhere (STANDALONE_*).
|
|
872
879
|
function backendOf(deps: CiTriggerDeps): string {
|
|
873
|
-
|
|
880
|
+
if (deps.env.HAS_OPENCODE_ROUTING === "true") return "opencode";
|
|
881
|
+
// The platform answered (its person layer wins whole): the input is ignored.
|
|
882
|
+
if ((deps.env.PLATFORM_ROUTING_OPENCODE ?? "") !== "") return "claude";
|
|
883
|
+
if (
|
|
884
|
+
deps.env.STANDALONE_MODELS_DEFAULT !== "true" &&
|
|
885
|
+
profileRunsOnlyOnOpenCode(deps.env.STANDALONE_PROFILE)
|
|
886
|
+
) {
|
|
887
|
+
return "opencode";
|
|
888
|
+
}
|
|
889
|
+
return "claude";
|
|
874
890
|
}
|
|
875
891
|
|
|
876
892
|
// The run's PR number, or why there is none. `malformed` is kept apart from a
|
package/src/commands/ci-setup.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
appendIgnorePatterns,
|
|
20
20
|
ignorePatternsError,
|
|
21
21
|
OPENCODE_PROVIDERS_VARIABLE,
|
|
22
|
-
|
|
22
|
+
openCodeProvidersOfPerson,
|
|
23
23
|
runCiSetup,
|
|
24
24
|
writeRepoReviewConfig,
|
|
25
25
|
} from "#ci/setup";
|
|
@@ -186,6 +186,8 @@ interface WorkflowVariables {
|
|
|
186
186
|
readonly configLabel: string;
|
|
187
187
|
readonly hasModels: boolean;
|
|
188
188
|
readonly hasCredentials: boolean;
|
|
189
|
+
// The person's `profile` (openai-profile S6), set as vars.CRYSK_PROFILE.
|
|
190
|
+
readonly profile?: string;
|
|
189
191
|
// The OpenCode providers the models name, as secret tokens (DEEPSEEK), sorted.
|
|
190
192
|
readonly openCodeTokens: readonly string[];
|
|
191
193
|
}
|
|
@@ -202,8 +204,9 @@ async function readWorkflowVariables(
|
|
|
202
204
|
? `~/${path.relative(home, filePath)}`
|
|
203
205
|
: filePath;
|
|
204
206
|
// The judge is skipped and every fallback counts, the providers the setup step
|
|
205
|
-
// builds the auth file for (
|
|
206
|
-
|
|
207
|
+
// builds the auth file for (openCodeProvidersOfPerson): the models', and the
|
|
208
|
+
// profile's for the roles models does not set.
|
|
209
|
+
const providers = openCodeProvidersOfPerson(layer ?? {});
|
|
207
210
|
const unnamed = providers.filter(
|
|
208
211
|
(provider) => opencodeSecretToken(provider) === undefined,
|
|
209
212
|
);
|
|
@@ -229,6 +232,7 @@ async function readWorkflowVariables(
|
|
|
229
232
|
variables: {
|
|
230
233
|
configLabel,
|
|
231
234
|
hasModels: layer?.models !== undefined,
|
|
235
|
+
...(layer?.profile === undefined ? {} : { profile: layer.profile }),
|
|
232
236
|
hasCredentials: layer?.credentials !== undefined,
|
|
233
237
|
openCodeTokens,
|
|
234
238
|
},
|
|
@@ -247,6 +251,11 @@ export function workflowVariableCommands(
|
|
|
247
251
|
`$ gh variable set CRYSK_MODELS --body "$(jq -c .models ${variables.configLabel})"`,
|
|
248
252
|
);
|
|
249
253
|
}
|
|
254
|
+
if (variables.profile !== undefined) {
|
|
255
|
+
commands.push(
|
|
256
|
+
`$ gh variable set CRYSK_PROFILE --body ${variables.profile}`,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
250
259
|
if (variables.hasCredentials) {
|
|
251
260
|
commands.push(
|
|
252
261
|
`$ gh variable set CRYSK_CREDENTIALS --body "$(jq -c .credentials ${variables.configLabel})"`,
|
package/src/commands/doctor.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { resolveOptionalRepoRoot } from "#config/config";
|
|
3
|
+
import { routingNeedsOpenCode } from "#model/model-name";
|
|
4
4
|
import type { CliOptions } from "#review/preflight";
|
|
5
5
|
import { styleEnabled, terminalWidth } from "#ui/primitives";
|
|
6
6
|
import {
|
|
7
7
|
type DoctorCheckItem,
|
|
8
8
|
type DoctorReport,
|
|
9
9
|
evaluateDoctorReport,
|
|
10
|
+
loadDoctorRouting,
|
|
10
11
|
openCodeRoutingSdkCheck,
|
|
11
12
|
renderDoctorReport,
|
|
12
13
|
runDoctor,
|
|
@@ -38,41 +39,41 @@ export async function runDoctorCommand(input: {
|
|
|
38
39
|
// the loader share. Tests pass a version without resolving a package.
|
|
39
40
|
readSdkVersion?: () => Promise<string | undefined>;
|
|
40
41
|
}): Promise<{ report: DoctorReport; lines: string[] }> {
|
|
41
|
-
|
|
42
|
+
// Required unless the configuration loads and proves otherwise: a config
|
|
43
|
+
// that fails to load must not quietly excuse a missing Claude CLI.
|
|
44
|
+
const routing = await loadDoctorRouting({
|
|
45
|
+
home: input.home,
|
|
46
|
+
repoRoot: input.repoRoot,
|
|
47
|
+
configFlag: input.configFlag,
|
|
48
|
+
});
|
|
49
|
+
const { models, profile, claudeRequired } = routing;
|
|
42
50
|
let configCheck: DoctorCheckItem | undefined;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
51
|
+
if (routing.error !== undefined) {
|
|
52
|
+
configCheck = {
|
|
53
|
+
name: "config",
|
|
54
|
+
severity: "blocking",
|
|
55
|
+
message: `configuration failed to load: ${routing.error}`,
|
|
56
|
+
};
|
|
57
|
+
} else if (routing.warnings.length > 0) {
|
|
50
58
|
// A config that loads with warnings works today and will not after the
|
|
51
59
|
// key it uses is removed: degraded, with the warning as its message.
|
|
52
|
-
if (loaded.warnings.length > 0) {
|
|
53
|
-
configCheck = {
|
|
54
|
-
name: "config",
|
|
55
|
-
severity: "degraded",
|
|
56
|
-
message: loaded.warnings.join("\n"),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
60
|
configCheck = {
|
|
61
61
|
name: "config",
|
|
62
|
-
severity: "
|
|
63
|
-
message:
|
|
64
|
-
error instanceof Error ? error.message : String(error)
|
|
65
|
-
}`,
|
|
62
|
+
severity: "degraded",
|
|
63
|
+
message: routing.warnings.join("\n"),
|
|
66
64
|
};
|
|
67
65
|
}
|
|
68
66
|
const runDoctorFn = input.runDoctorFn ?? runDoctor;
|
|
69
67
|
const doctorReport = await runDoctorFn({
|
|
70
68
|
repoRoot: input.repoRoot,
|
|
71
69
|
cwd: input.repoRoot,
|
|
70
|
+
claudeRequired,
|
|
72
71
|
probeExactBindings: () =>
|
|
73
72
|
collectDoctorExactBindingReports({
|
|
74
73
|
workspaceRoot: input.workspaceRoot,
|
|
75
74
|
models,
|
|
75
|
+
claudeRequired,
|
|
76
|
+
profile,
|
|
76
77
|
}),
|
|
77
78
|
});
|
|
78
79
|
// Same home the command was given. The no-arg reader uses os.homedir().
|
|
@@ -82,9 +83,10 @@ export async function runDoctorCommand(input: {
|
|
|
82
83
|
readInstalledOpenCodeSdkVersion({
|
|
83
84
|
nodeModulesDir: prheroLayout(input.home).nodeModulesDir,
|
|
84
85
|
}));
|
|
85
|
-
const sdkCheck =
|
|
86
|
+
const sdkCheck = routingNeedsOpenCode(models, profile)
|
|
86
87
|
? openCodeRoutingSdkCheck({
|
|
87
88
|
models,
|
|
89
|
+
profile,
|
|
88
90
|
sdkVersion: await readSdkVersion(),
|
|
89
91
|
})
|
|
90
92
|
: undefined;
|
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { modelNameFromAlias } from "#model/model-name";
|
|
3
3
|
import {
|
|
4
4
|
agentStepKey,
|
|
5
|
+
type ResolvedModelRoute,
|
|
5
6
|
type ResolvedStepRoute,
|
|
6
7
|
resolveStepRoute,
|
|
7
8
|
} from "#model/routing";
|
|
@@ -26,6 +27,11 @@ export interface DiversityLeg {
|
|
|
26
27
|
readonly logicalModel: string;
|
|
27
28
|
readonly model: string;
|
|
28
29
|
readonly routeFingerprint: string;
|
|
30
|
+
// The route the leg resolved to, the one its routeFingerprint names. Not
|
|
31
|
+
// part of the plan payload (the fingerprint already is), so legIds and the
|
|
32
|
+
// plan fingerprint stay what they were. Provenance reads it when a step
|
|
33
|
+
// carries no executed route (S2).
|
|
34
|
+
readonly route: ResolvedModelRoute;
|
|
29
35
|
readonly executionKey: string;
|
|
30
36
|
readonly stepKey: string;
|
|
31
37
|
}
|
|
@@ -130,7 +136,10 @@ export function buildDiversityPlan(
|
|
|
130
136
|
const specialty = resolveSpecialty(agent);
|
|
131
137
|
for (const model of models) {
|
|
132
138
|
// A leg's model is internal: a bare alias or a full model name. Its
|
|
133
|
-
// own model
|
|
139
|
+
// own model is the step's spec model, which outranks `models`, the
|
|
140
|
+
// frontmatter and the profile in resolveStepChoices; only `--model`
|
|
141
|
+
// outranks it, and it is passed. So this is the route the run plan
|
|
142
|
+
// gives the leg's step, which assertDiversityLegRoutes checks (S2).
|
|
134
143
|
const parsed = { canonical: modelNameFromAlias(model).raw };
|
|
135
144
|
const provisionalKey = diversityLegAgentKey(
|
|
136
145
|
agent.key,
|
|
@@ -158,6 +167,7 @@ export function buildDiversityPlan(
|
|
|
158
167
|
logicalModel: model,
|
|
159
168
|
model: parsed.canonical,
|
|
160
169
|
routeFingerprint: stepRoute.routeFingerprint,
|
|
170
|
+
route: stepRoute.route,
|
|
161
171
|
executionKey,
|
|
162
172
|
stepKey,
|
|
163
173
|
});
|
|
@@ -245,6 +245,24 @@ export function recordDiversityHunterFailure(
|
|
|
245
245
|
return appendAttempt(ledger, attempt);
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
// The route an observation names. A step carries no executed route only on
|
|
249
|
+
// the no-plan path, which runs every step on the Claude CLI, so the leg's own
|
|
250
|
+
// resolved route stands in when it is a Claude one. A non-Claude leg there has
|
|
251
|
+
// no observed execution to name, and labelling it Anthropic (as this did
|
|
252
|
+
// before S2) or with a route nobody ran would both be false: refuse.
|
|
253
|
+
function provenanceRoute(
|
|
254
|
+
leg: DiversityLeg,
|
|
255
|
+
executedRoute: ResolvedModelRoute | undefined,
|
|
256
|
+
): ResolvedModelRoute {
|
|
257
|
+
if (executedRoute !== undefined) return executedRoute;
|
|
258
|
+
if (leg.route.backend !== "claude-code") {
|
|
259
|
+
throw new DiversityAdmissionError(
|
|
260
|
+
`no executed route for ${leg.route.backend} leg ${leg.legId}`,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
return leg.route;
|
|
264
|
+
}
|
|
265
|
+
|
|
248
266
|
export function recordDiversityHunterResult(
|
|
249
267
|
ledger: DiversityLedger,
|
|
250
268
|
plan: DiversityPlan,
|
|
@@ -290,12 +308,7 @@ export function recordDiversityHunterResult(
|
|
|
290
308
|
}
|
|
291
309
|
if (result.status !== "ok") return next;
|
|
292
310
|
const terminalAttemptId = `${resolvedLeg.legId}-a${totalAttempts}`;
|
|
293
|
-
const routeProvenance
|
|
294
|
-
backend: "claude-code",
|
|
295
|
-
provider: "anthropic",
|
|
296
|
-
modelFamily: resolvedLeg.model.split("/")[0] ?? "unknown",
|
|
297
|
-
modelSnapshot: resolvedLeg.model,
|
|
298
|
-
};
|
|
311
|
+
const routeProvenance = provenanceRoute(resolvedLeg, executedRoute);
|
|
299
312
|
const output = result.output as { findings?: DraftFinding[] } | undefined;
|
|
300
313
|
const findings = output?.findings ?? [];
|
|
301
314
|
for (const [index, finding] of findings.entries()) {
|