crysk 0.4.0 → 0.5.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 +26 -17
- package/config/models/anthropic.json +1 -1
- package/dist/SKILL-k4k0zn1w.md +143 -0
- package/dist/SKILL-vhb4c3vv.md +553 -0
- package/dist/SKILL-xpf6kmdw.md +74 -0
- package/dist/ci-admission-0ken6ehx.md +128 -0
- package/dist/cli.js +3056 -1623
- package/dist/index.js +1744 -938
- package/dist/opencode-ci-ac5zksdn.md +106 -0
- package/dist/workflow-4pkyck01.yml +160 -0
- package/package.json +1 -1
- package/prompts/default/PROVENANCE.md +1 -0
- package/skills/crysk/SKILL.md +16 -16
- package/skills/crysk-ci-setup/SKILL.md +41 -38
- package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
- package/skills/crysk-ci-setup/references/ci-admission.md +1 -1
- package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
- package/skills/crysk-loop/SKILL.md +1 -1
- package/src/asset-manifest.ts +0 -4
- package/src/assets.ts +1 -1
- package/src/ci/admission-ledger.ts +4 -0
- package/src/ci/classify-error.ts +21 -24
- package/src/ci/cli-record.ts +53 -1
- package/src/ci/crysk-secrets.ts +409 -0
- package/src/ci/gates.ts +22 -36
- package/src/ci/outcome.ts +421 -330
- package/src/ci/platform-config.ts +2 -2
- package/src/ci/platform-report.ts +274 -41
- package/src/ci/platform-trace.ts +551 -0
- package/src/ci/platform.ts +28 -12
- package/src/ci/publish.ts +19 -6
- package/src/ci/review-levels.ts +8 -7
- package/src/ci/run.ts +88 -0
- package/src/ci/setup.ts +453 -118
- package/src/ci/trace-bundle.ts +1282 -0
- package/src/ci/trace-transcripts.ts +415 -0
- package/src/ci/trigger.ts +176 -33
- package/src/cli.ts +11 -3
- package/src/commands/ci-setup-questions.ts +3 -3
- package/src/commands/ci-setup.ts +152 -6
- package/src/commands/config.ts +3 -0
- package/src/commands/doctor.ts +15 -6
- package/src/config/config.ts +16 -3
- package/src/diversity/clustering.ts +0 -1
- package/src/diversity/identity.ts +4 -5
- package/src/diversity/pipeline-integration.ts +1 -9
- package/src/doctor.ts +3 -3
- package/src/execution/attempt-evidence.ts +10 -5
- package/src/execution/claude-session-trace.ts +480 -0
- package/src/execution/contracts.ts +21 -4
- package/src/execution/harness.ts +105 -8
- package/src/execution/model-fallback.ts +239 -0
- package/src/execution/usage-normalized.ts +6 -4
- package/src/home-preflight.ts +1 -1
- package/src/index.ts +1 -1
- package/src/model/catalog.ts +13 -37
- package/src/model/free-discovery.ts +117 -8
- package/src/model/model-name.ts +404 -0
- package/src/model/provider-capabilities.ts +22 -7
- package/src/model/routing.ts +346 -467
- package/src/pr/admission.ts +18 -0
- package/src/pr/plan.ts +20 -4
- package/src/pr/preflight.ts +1 -1
- package/src/pr/publish-outcome.ts +1 -1
- package/src/pr/review-pr.ts +15 -1
- package/src/pr/target.ts +12 -3
- package/src/production-runtime.ts +760 -331
- package/src/review/pipeline.ts +277 -101
- package/src/review/preflight.ts +201 -294
- package/src/review/report.ts +26 -26
- package/src/review/review.ts +20 -3
- package/src/review/route-preflight.ts +79 -11
- package/src/review/run.ts +28 -6
- package/src/review/scout.ts +1 -1
- package/src/review/spec.ts +3 -3
- package/src/review/step-runner.ts +70 -1
- package/src/runner-authority.ts +127 -9
- package/src/security/binding-policy.ts +1 -2
- package/src/security/claude-credential.ts +355 -0
- package/src/security/credential-broker.ts +56 -40
- package/src/security/evidence-redaction.ts +179 -4
- package/src/security/opencode-secret-manifest.ts +114 -0
- package/src/security/redact.ts +45 -0
- package/src/system-tools.ts +48 -21
- package/src/transport-registry.ts +12 -2
- package/src/transports/claude-code-cli.ts +21 -2
- package/src/transports/opencode-sdk.ts +11 -9
- package/src/transports/opencode-server.ts +7 -10
- package/src/ui/config-edit.ts +9 -20
- package/src/ui/config.ts +32 -27
- package/src/ui/plan.ts +76 -47
- package/src/updater.ts +10 -7
- package/prompts/default/deep-review-lifecycle.md +0 -362
package/src/execution/harness.ts
CHANGED
|
@@ -37,6 +37,13 @@ import {
|
|
|
37
37
|
freezeAttemptEvidenceIdentity,
|
|
38
38
|
persistAttemptEvidence,
|
|
39
39
|
} from "./attempt-evidence";
|
|
40
|
+
import {
|
|
41
|
+
CLAUDE_TRACE_MISSES,
|
|
42
|
+
type ClaudeTraceMiss,
|
|
43
|
+
claudeSessionTracePath,
|
|
44
|
+
claudeTraceCaptureAnnotation,
|
|
45
|
+
copyRetainedClaudeSession,
|
|
46
|
+
} from "./claude-session-trace";
|
|
40
47
|
import {
|
|
41
48
|
BucketBreakerTrippedError,
|
|
42
49
|
ConcurrencyAdmissionAbortedError,
|
|
@@ -85,9 +92,9 @@ import {
|
|
|
85
92
|
FORMAT_RETRY_REMINDER,
|
|
86
93
|
settlementReceiptPath,
|
|
87
94
|
} from "./step-artifacts";
|
|
88
|
-
import type { NormalizedUsage } from "./usage-normalized";
|
|
89
95
|
import {
|
|
90
96
|
envBillsMetered,
|
|
97
|
+
type NormalizedUsage,
|
|
91
98
|
normalizeUnavailableUsage,
|
|
92
99
|
projectLegacyUsage,
|
|
93
100
|
sumNormalizedUsage,
|
|
@@ -417,12 +424,43 @@ function projectionWarningAnnotation(failureClass: string): string {
|
|
|
417
424
|
return `[pr-hero] credential projection unavailable (${failureClass}); child runs with operator environment`;
|
|
418
425
|
}
|
|
419
426
|
|
|
427
|
+
// Runs before the attempt returns, so before run() destroys the credential
|
|
428
|
+
// projection whose HOME holds the session file. A failed copy is only ever a
|
|
429
|
+
// warning: it cannot change how the attempt ended.
|
|
430
|
+
function copyClaudeSessionTrace(
|
|
431
|
+
step: StepSpec,
|
|
432
|
+
request: TransportRequest,
|
|
433
|
+
attempt: number,
|
|
434
|
+
): Promise<ClaudeTraceMiss | undefined> {
|
|
435
|
+
return copyRetainedClaudeSession(
|
|
436
|
+
request,
|
|
437
|
+
claudeSessionTracePath(step.outPath, step.name, attempt),
|
|
438
|
+
).catch((): ClaudeTraceMiss => "session trace write failed");
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async function withClaudeSessionTrace(
|
|
442
|
+
step: StepSpec,
|
|
443
|
+
request: TransportRequest,
|
|
444
|
+
attempt: number,
|
|
445
|
+
outcome: TransportOutcome,
|
|
446
|
+
): Promise<TransportOutcome> {
|
|
447
|
+
const reason = await copyClaudeSessionTrace(step, request, attempt);
|
|
448
|
+
if (reason === undefined) return outcome;
|
|
449
|
+
return {
|
|
450
|
+
...outcome,
|
|
451
|
+
stderrTail: `${outcome.stderrTail}\n${claudeTraceCaptureAnnotation(reason)}`,
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
420
455
|
export function isHarnessStderrAnnotation(line: string): boolean {
|
|
421
456
|
const trimmed = line.trim();
|
|
422
457
|
return (
|
|
423
458
|
trimmed === DESTROY_FAILED_ANNOTATION ||
|
|
424
459
|
trimmed === AMBIENT_METERED_ANNOTATION ||
|
|
425
|
-
PROJECTION_WARNING_ANNOTATION.test(trimmed)
|
|
460
|
+
PROJECTION_WARNING_ANNOTATION.test(trimmed) ||
|
|
461
|
+
CLAUDE_TRACE_MISSES.some(
|
|
462
|
+
(reason) => trimmed === claudeTraceCaptureAnnotation(reason),
|
|
463
|
+
)
|
|
426
464
|
);
|
|
427
465
|
}
|
|
428
466
|
|
|
@@ -619,6 +657,22 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
619
657
|
async run(step: StepSpec): Promise<StepResult> {
|
|
620
658
|
let canonicalCwd = step.cwd;
|
|
621
659
|
|
|
660
|
+
// S4: a harness binds ONE transport and credential and runs one model.
|
|
661
|
+
// A step carrying fallbacks belongs to a runner that tries them
|
|
662
|
+
// (runWithFallback, model-fallback.ts), which hands this harness one
|
|
663
|
+
// model at a time. Running only the first here would quietly drop the
|
|
664
|
+
// rest of an explicit list, so the step is refused before any spawn.
|
|
665
|
+
if (step.fallbackRoutes !== undefined && step.fallbackRoutes.length > 0) {
|
|
666
|
+
return {
|
|
667
|
+
name: step.name,
|
|
668
|
+
status: "failed",
|
|
669
|
+
usage: zeroUsage(),
|
|
670
|
+
attempts: 0,
|
|
671
|
+
stderrTail: `Step "${step.name}" lists ${step.fallbackRoutes.length} fallback model(s), and this runner runs one model per step; run it through a runner that tries fallbacks (MultiProviderRunner, ClaudeCodeRunner)`,
|
|
672
|
+
resultText: "",
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
|
|
622
676
|
// Resolve transport for this step
|
|
623
677
|
const effectiveBackend =
|
|
624
678
|
step.route?.backend ?? step.backend ?? "claude-code";
|
|
@@ -1376,7 +1430,14 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
1376
1430
|
finalText: "",
|
|
1377
1431
|
usage: normalizeUnavailableUsage({
|
|
1378
1432
|
wallMs: harnessWatchdogMs ?? 0,
|
|
1379
|
-
|
|
1433
|
+
// A Claude child bills on the credential its env holds, which the run chose; the transport's own
|
|
1434
|
+
// answer reads the engine's startup env and could name a credential the run stripped.
|
|
1435
|
+
billingMode:
|
|
1436
|
+
transport.backend === "claude-code"
|
|
1437
|
+
? envBillsMetered(this.projectedEnv)
|
|
1438
|
+
? "metered"
|
|
1439
|
+
: "subscription"
|
|
1440
|
+
: transport.billingMode,
|
|
1380
1441
|
}),
|
|
1381
1442
|
stderrTail: `Step timed out after ${harnessWatchdogMs}ms`,
|
|
1382
1443
|
timedOut: true,
|
|
@@ -1624,6 +1685,16 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
1624
1685
|
// The transport cause of the most recent failed attempt. Reset by every attempt
|
|
1625
1686
|
// that fails without one, so the step reports only the cause it ended on.
|
|
1626
1687
|
let lastFailureCause: TransportFailureCause | undefined;
|
|
1688
|
+
// The same attempt's cause with harness causes kept (watchdog_timeout,
|
|
1689
|
+
// format_violation): what StepResult.finalCause reports, for the fallback.
|
|
1690
|
+
let lastCause: FailureCause | undefined;
|
|
1691
|
+
// The final attempt was refused by a fenced spend bucket (StepResult.spendFenced).
|
|
1692
|
+
let spendFenced = false;
|
|
1693
|
+
// Attempts earlier models of this step already used (StepSpec.attempt-
|
|
1694
|
+
// Offset). Every per-attempt artifact is named by `attemptOffset +
|
|
1695
|
+
// attempts`, so a fallback model never overwrites the first model's logs
|
|
1696
|
+
// and receipts; `attempts` itself stays this run's own count.
|
|
1697
|
+
const attemptOffset = step.attemptOffset ?? 0;
|
|
1627
1698
|
let cancelHit = false;
|
|
1628
1699
|
// D1-08 PR5b (§9.1): every attempt that reached the reserve step, in
|
|
1629
1700
|
// order, each already finalized to a terminal reservation state by the
|
|
@@ -1666,9 +1737,10 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
1666
1737
|
const kind: "attempt" | "format-retry" =
|
|
1667
1738
|
pendingFormatPrompt === undefined ? "attempt" : "format-retry";
|
|
1668
1739
|
|
|
1740
|
+
const attemptNumber = attemptOffset + attempts;
|
|
1669
1741
|
const request: TransportRequest = {
|
|
1670
|
-
sessionId: `${step.name}-${Date.now()}-${
|
|
1671
|
-
attempt:
|
|
1742
|
+
sessionId: `${step.name}-${Date.now()}-${attemptNumber}`,
|
|
1743
|
+
attempt: attemptNumber,
|
|
1672
1744
|
executionModel: step.model,
|
|
1673
1745
|
effort: step.effort,
|
|
1674
1746
|
route:
|
|
@@ -1726,7 +1798,7 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
1726
1798
|
|
|
1727
1799
|
const attemptResult = await this.runAttempt({
|
|
1728
1800
|
step,
|
|
1729
|
-
attempt:
|
|
1801
|
+
attempt: attemptNumber,
|
|
1730
1802
|
kind,
|
|
1731
1803
|
request,
|
|
1732
1804
|
deadlineMs,
|
|
@@ -1771,6 +1843,17 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
1771
1843
|
isTransportFailureCause(attemptResult.resolution.cause)
|
|
1772
1844
|
? attemptResult.resolution.cause
|
|
1773
1845
|
: undefined;
|
|
1846
|
+
// A fenced attempt never reached the provider, so it has no cause of
|
|
1847
|
+
// its own: finalCause stays the one the last attempt that did reach it
|
|
1848
|
+
// ended on, which is what a fallback decides on.
|
|
1849
|
+
if (attemptResult.fenced === true) {
|
|
1850
|
+
spendFenced = true;
|
|
1851
|
+
} else {
|
|
1852
|
+
lastCause =
|
|
1853
|
+
attemptResult.resolution.kind === "cause"
|
|
1854
|
+
? attemptResult.resolution.cause
|
|
1855
|
+
: undefined;
|
|
1856
|
+
}
|
|
1774
1857
|
if (attemptResult.resolution.kind === "legacy_terminal") {
|
|
1775
1858
|
break;
|
|
1776
1859
|
}
|
|
@@ -1840,7 +1923,7 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
1840
1923
|
// naming attempt0.json, which would be the same lie in a new font.
|
|
1841
1924
|
const receiptPointer =
|
|
1842
1925
|
attempts >= 1
|
|
1843
|
-
? `see ${receiptPathFor(step, attempts)}`
|
|
1926
|
+
? `see ${receiptPathFor(step, attemptOffset + attempts)}`
|
|
1844
1927
|
: "no attempt was admitted, so no receipt was written";
|
|
1845
1928
|
return {
|
|
1846
1929
|
name: step.name,
|
|
@@ -1875,6 +1958,8 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
1875
1958
|
...(lastFailureCause === undefined
|
|
1876
1959
|
? {}
|
|
1877
1960
|
: { failureCause: lastFailureCause }),
|
|
1961
|
+
...(lastCause === undefined ? {} : { finalCause: lastCause }),
|
|
1962
|
+
...(spendFenced ? { spendFenced: true as const } : {}),
|
|
1878
1963
|
...(lastOutcome?.failureDetail === undefined
|
|
1879
1964
|
? {}
|
|
1880
1965
|
: { failureDetail: lastOutcome.failureDetail }),
|
|
@@ -2116,6 +2201,7 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
2116
2201
|
stderrTail: error.message,
|
|
2117
2202
|
},
|
|
2118
2203
|
resolution: { kind: "legacy_terminal" },
|
|
2204
|
+
fenced: true,
|
|
2119
2205
|
};
|
|
2120
2206
|
}
|
|
2121
2207
|
throw error;
|
|
@@ -2453,6 +2539,9 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
2453
2539
|
}
|
|
2454
2540
|
|
|
2455
2541
|
if (execution.cancelled) {
|
|
2542
|
+
// A cancelled attempt has no outcome to carry a warning, but what it did
|
|
2543
|
+
// before the stop is still worth keeping.
|
|
2544
|
+
await copyClaudeSessionTrace(step, request, attempt);
|
|
2456
2545
|
return { kind: "cancelled" };
|
|
2457
2546
|
}
|
|
2458
2547
|
|
|
@@ -2460,7 +2549,12 @@ export class StepExecutionHarness implements StepRunner {
|
|
|
2460
2549
|
// `execution.cancelled` is the only path executeSession takes without
|
|
2461
2550
|
// ever invoking `onData`, and `onData` is what both delivery variants
|
|
2462
2551
|
// above come from.
|
|
2463
|
-
const outcome =
|
|
2552
|
+
const outcome = await withClaudeSessionTrace(
|
|
2553
|
+
step,
|
|
2554
|
+
request,
|
|
2555
|
+
attempt,
|
|
2556
|
+
execution.outcome as TransportOutcome,
|
|
2557
|
+
);
|
|
2464
2558
|
|
|
2465
2559
|
if (execution.delivery?.delivered) {
|
|
2466
2560
|
return { kind: "delivered", outcome, parsed: execution.delivery.parsed };
|
|
@@ -2545,4 +2639,7 @@ type AttemptRunResult =
|
|
|
2545
2639
|
readonly resolution: CauseResolution;
|
|
2546
2640
|
readonly parseError?: string;
|
|
2547
2641
|
readonly reservation?: SpendReservation;
|
|
2642
|
+
// The spend ledger refused the reservation because the bucket is
|
|
2643
|
+
// fenced: the transport was never called.
|
|
2644
|
+
readonly fenced?: true;
|
|
2548
2645
|
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// Fallback models (odd/tasks/role-model-routing.md S4): a step whose role
|
|
2
|
+
// lists several models runs them in order, moving to the next only when the
|
|
3
|
+
// PROVIDER failed the one before. Juanma: move "only on a provider error, a
|
|
4
|
+
// rate limit, no quota or a timeout, never on a bad answer, and record which
|
|
5
|
+
// model actually ran"; and never on context-window, output-limit or
|
|
6
|
+
// safety-refusal errors (L6 item 8).
|
|
7
|
+
//
|
|
8
|
+
// WHY this wraps whole runs and does not live in the harness: the harness
|
|
9
|
+
// binds ONE transport, credential projection and spend bucket per run and
|
|
10
|
+
// retries only on them. A fallback model may sit on another backend and
|
|
11
|
+
// another credential, so each model is its own harness run, with its own
|
|
12
|
+
// retries, its own reservations and its own usage.
|
|
13
|
+
|
|
14
|
+
import type { Effort } from "#model/catalog";
|
|
15
|
+
import type { ModelAttempt, StepResult, StepSpec } from "#review/step-runner";
|
|
16
|
+
import { sumUsage } from "../usage";
|
|
17
|
+
import type { ResolvedModelRoute } from "./contracts";
|
|
18
|
+
import type { FailureCause } from "./failure-policy";
|
|
19
|
+
import {
|
|
20
|
+
type NormalizedUsage,
|
|
21
|
+
projectLegacyUsage,
|
|
22
|
+
sumNormalizedUsage,
|
|
23
|
+
} from "./usage-normalized";
|
|
24
|
+
|
|
25
|
+
// The causes that are the provider's, not the model's answer. An allowlist:
|
|
26
|
+
// anything not named here stops the step on the model it ran. That keeps a
|
|
27
|
+
// bad answer (format_violation), the three L6 item 8 errors (context window,
|
|
28
|
+
// output limit, safety refusal), configuration and protocol conformance
|
|
29
|
+
// failures, cancellations and unconfirmed settlements from ever spending on
|
|
30
|
+
// another model, and it makes a cause added later stop by default.
|
|
31
|
+
const PROVIDER_FAILURES: ReadonlySet<FailureCause> = new Set([
|
|
32
|
+
"rate_limit",
|
|
33
|
+
"quota_exhausted",
|
|
34
|
+
"network_transient",
|
|
35
|
+
"protocol_truncation",
|
|
36
|
+
"watchdog_timeout",
|
|
37
|
+
"model_unavailable",
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
// What a failed model's cause means for the rest of the list.
|
|
41
|
+
// next run the next model;
|
|
42
|
+
// next_credential the login was refused: skip every model on the same
|
|
43
|
+
// credential, then run the next one on another;
|
|
44
|
+
// stop the step ends on this model.
|
|
45
|
+
export type FallbackMove = "next" | "next_credential" | "stop";
|
|
46
|
+
|
|
47
|
+
export function fallbackMove(cause: FailureCause | undefined): FallbackMove {
|
|
48
|
+
if (cause === undefined) return "stop";
|
|
49
|
+
if (cause === "auth_invalid") return "next_credential";
|
|
50
|
+
return PROVIDER_FAILURES.has(cause) ? "next" : "stop";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The route of the model that ran: the last one not skipped. A model that
|
|
54
|
+
// never reached its provider is recorded `skipped`, so it is never named here.
|
|
55
|
+
// Undefined for a step with one model, whose route is the step's own, and for
|
|
56
|
+
// a list none of whose models reached a provider.
|
|
57
|
+
export function ranRoute(
|
|
58
|
+
result: Pick<StepResult, "modelAttempts">,
|
|
59
|
+
): ResolvedModelRoute | undefined {
|
|
60
|
+
return result.modelAttempts?.findLast((entry) => entry.status !== "skipped")
|
|
61
|
+
?.route;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface RunWithFallbackInput {
|
|
65
|
+
readonly step: StepSpec;
|
|
66
|
+
// Runs the step on exactly one route (`step.route`), with its retries.
|
|
67
|
+
readonly runOn: (step: StepSpec) => Promise<StepResult>;
|
|
68
|
+
// The credential a route runs on, as an opaque identity: two routes with the
|
|
69
|
+
// same value share a login. Undefined when the route has no binding.
|
|
70
|
+
readonly credentialOf: (route: ResolvedModelRoute) => string | undefined;
|
|
71
|
+
// True once the run is cancelled: no further model starts.
|
|
72
|
+
readonly cancelled: () => boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function runWithFallback(
|
|
76
|
+
input: RunWithFallbackInput,
|
|
77
|
+
): Promise<StepResult> {
|
|
78
|
+
const { step } = input;
|
|
79
|
+
const fallbacks = step.fallbackRoutes ?? [];
|
|
80
|
+
// A step with one model runs exactly as it did before fallbacks existed:
|
|
81
|
+
// the same call, the same result, nothing added to it.
|
|
82
|
+
if (step.route === undefined || fallbacks.length === 0) {
|
|
83
|
+
return input.runOn(step);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const candidates = [step.route, ...fallbacks];
|
|
87
|
+
// S7: each model runs at its own effort. This used to spread the step into
|
|
88
|
+
// every candidate, so a fallback inherited the FIRST model's effort, which
|
|
89
|
+
// may be that model's own entry effort and none of the fallback's business.
|
|
90
|
+
const effortOf = (index: number): Effort =>
|
|
91
|
+
index === 0
|
|
92
|
+
? step.effort
|
|
93
|
+
: (step.fallbackEfforts?.[index - 1] ?? step.effort);
|
|
94
|
+
const modelAttempts: ModelAttempt[] = [];
|
|
95
|
+
const results: StepResult[] = [];
|
|
96
|
+
const refusedCredentials = new Set<string>();
|
|
97
|
+
let attemptsSoFar = 0;
|
|
98
|
+
|
|
99
|
+
for (const [index, route] of candidates.entries()) {
|
|
100
|
+
if (index > 0 && input.cancelled()) break;
|
|
101
|
+
const credential = input.credentialOf(route);
|
|
102
|
+
if (credential !== undefined && refusedCredentials.has(credential)) {
|
|
103
|
+
modelAttempts.push({
|
|
104
|
+
route,
|
|
105
|
+
status: "skipped",
|
|
106
|
+
attempts: 0,
|
|
107
|
+
effort: effortOf(index),
|
|
108
|
+
cause: "auth_invalid",
|
|
109
|
+
});
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const {
|
|
113
|
+
fallbackRoutes: _list,
|
|
114
|
+
fallbackEfforts: _efforts,
|
|
115
|
+
routeKey: _key,
|
|
116
|
+
...single
|
|
117
|
+
} = step;
|
|
118
|
+
const result = await input.runOn({
|
|
119
|
+
...single,
|
|
120
|
+
route,
|
|
121
|
+
effort: effortOf(index),
|
|
122
|
+
// The first model keeps the caller's frozen route key; a fallback is
|
|
123
|
+
// matched to its own binding by route.
|
|
124
|
+
...(index === 0 && step.routeKey !== undefined
|
|
125
|
+
? { routeKey: step.routeKey }
|
|
126
|
+
: {}),
|
|
127
|
+
...(attemptsSoFar === 0 ? {} : { attemptOffset: attemptsSoFar }),
|
|
128
|
+
// A fallback's request names its own model (attempt evidence records
|
|
129
|
+
// it beside the route); the first keeps the caller's.
|
|
130
|
+
...(index === 0 ? {} : { model: route.modelSnapshot || step.model }),
|
|
131
|
+
});
|
|
132
|
+
const reached = reachedAttempts(result);
|
|
133
|
+
attemptsSoFar += reached;
|
|
134
|
+
results.push(result);
|
|
135
|
+
if (reached === 0) {
|
|
136
|
+
// Never reached its provider: not the model that ran, and not the one
|
|
137
|
+
// whose outcome the step reports.
|
|
138
|
+
modelAttempts.push({
|
|
139
|
+
route,
|
|
140
|
+
status: "skipped",
|
|
141
|
+
attempts: 0,
|
|
142
|
+
effort: effortOf(index),
|
|
143
|
+
});
|
|
144
|
+
// A fenced bucket refuses every model on it at no cost, and another
|
|
145
|
+
// credential may still run. Anything else that stops a model before
|
|
146
|
+
// its first request is not the provider's, so it stops the step.
|
|
147
|
+
if (result.spendFenced === true) continue;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
modelAttempts.push({
|
|
151
|
+
route,
|
|
152
|
+
status: result.status,
|
|
153
|
+
attempts: reached,
|
|
154
|
+
effort: effortOf(index),
|
|
155
|
+
...(result.status === "ok" || result.finalCause === undefined
|
|
156
|
+
? {}
|
|
157
|
+
: { cause: result.finalCause }),
|
|
158
|
+
...(result.usageV2 === undefined ? {} : { usageV2: result.usageV2 }),
|
|
159
|
+
});
|
|
160
|
+
if (result.status === "ok") break;
|
|
161
|
+
const move = fallbackMove(result.finalCause);
|
|
162
|
+
if (move === "stop") break;
|
|
163
|
+
if (move === "next_credential") {
|
|
164
|
+
// Without a credential identity the refusal cannot be scoped, so it
|
|
165
|
+
// stops rather than spend another try on what may be the same login.
|
|
166
|
+
if (credential === undefined) break;
|
|
167
|
+
refusedCredentials.add(credential);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return mergeResults(results, modelAttempts, attemptsSoFar);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The attempts of one model's run that reached its provider. An attempt
|
|
175
|
+
// refused by a fenced bucket is always the run's last (the harness stops on
|
|
176
|
+
// it), never reached the provider and wrote no file, so it takes no number:
|
|
177
|
+
// the next model's attempts follow the ones that did run.
|
|
178
|
+
function reachedAttempts(result: StepResult): number {
|
|
179
|
+
return result.attempts - (result.spendFenced === true ? 1 : 0);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// The step's one result: the outcome of the last model that reached its
|
|
183
|
+
// provider (or the last model, when none did), with what every model spent.
|
|
184
|
+
// Usage and reservations are summed, never replaced, because a failed
|
|
185
|
+
// model's attempts still cost what they cost. Why each later model did not
|
|
186
|
+
// run is kept in the tail, after the reported model's own.
|
|
187
|
+
function mergeResults(
|
|
188
|
+
results: readonly StepResult[],
|
|
189
|
+
modelAttempts: ModelAttempt[],
|
|
190
|
+
attempts: number,
|
|
191
|
+
): StepResult {
|
|
192
|
+
// The first model is always handed to `runOn` (a skip needs a refused
|
|
193
|
+
// login before it), so `results` is never empty.
|
|
194
|
+
const ranIndex = results.findLastIndex(
|
|
195
|
+
(result) => reachedAttempts(result) > 0,
|
|
196
|
+
);
|
|
197
|
+
const reported = ranIndex === -1 ? results.length - 1 : ranIndex;
|
|
198
|
+
// biome-ignore lint/style/noNonNullAssertion: results is never empty (above)
|
|
199
|
+
const last = results[reported]!;
|
|
200
|
+
const notRun = results
|
|
201
|
+
.slice(reported + 1)
|
|
202
|
+
.map((result) => result.stderrTail.trim())
|
|
203
|
+
.filter((tail) => tail.length > 0);
|
|
204
|
+
let usageV2: NormalizedUsage | undefined;
|
|
205
|
+
for (const result of results) {
|
|
206
|
+
if (result.usageV2 === undefined) continue;
|
|
207
|
+
usageV2 =
|
|
208
|
+
usageV2 === undefined
|
|
209
|
+
? result.usageV2
|
|
210
|
+
: sumNormalizedUsage(usageV2, result.usageV2);
|
|
211
|
+
}
|
|
212
|
+
const reservations = results.flatMap((result) => result.reservations ?? []);
|
|
213
|
+
const {
|
|
214
|
+
usageV2: _lastUsage,
|
|
215
|
+
reservations: _lastReservations,
|
|
216
|
+
spendFenced: _lastFenced,
|
|
217
|
+
...outcome
|
|
218
|
+
} = last;
|
|
219
|
+
return {
|
|
220
|
+
...outcome,
|
|
221
|
+
...(notRun.length === 0
|
|
222
|
+
? {}
|
|
223
|
+
: {
|
|
224
|
+
stderrTail: [outcome.stderrTail, ...notRun]
|
|
225
|
+
.filter((tail) => tail.length > 0)
|
|
226
|
+
.join("\n"),
|
|
227
|
+
}),
|
|
228
|
+
// The legacy shape is projected from the normalized one whenever any
|
|
229
|
+
// model reported it, exactly as the harness projects its own attempts.
|
|
230
|
+
usage:
|
|
231
|
+
usageV2 !== undefined
|
|
232
|
+
? projectLegacyUsage(usageV2)
|
|
233
|
+
: results.map((result) => result.usage).reduce(sumUsage),
|
|
234
|
+
...(usageV2 === undefined ? {} : { usageV2 }),
|
|
235
|
+
...(reservations.length === 0 ? {} : { reservations }),
|
|
236
|
+
attempts,
|
|
237
|
+
modelAttempts,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
@@ -52,10 +52,12 @@ export type UsageCostSource =
|
|
|
52
52
|
// (PROJECTION_OWNED_KEYS, harness.ts) because the projection owns the
|
|
53
53
|
// credential, so this predicate reads subscription on that path — which is
|
|
54
54
|
// the truth there, and was not before the strip.
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
55
|
+
// S5 (2026-11-06): in a review run both are never present together. The run env
|
|
56
|
+
// (security/claude-credential.ts) holds only the Claude credential chosen from
|
|
57
|
+
// `credentials.claude`, so this predicate answers metered exactly when the run
|
|
58
|
+
// chose the API key. A caller with its own env that holds both still gets
|
|
59
|
+
// metered, because guessing subscription wrongly reports real money as not
|
|
60
|
+
// charged.
|
|
59
61
|
//
|
|
60
62
|
// Trimming is load-bearing, and it is worth being exact about WHAT it buys,
|
|
61
63
|
// because the sentence it replaces overstated it and #177 is a finding about
|
package/src/home-preflight.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface PrheroLayout {
|
|
|
21
21
|
dir: string;
|
|
22
22
|
// Compiled binaries resolve optional packages from this directory, not
|
|
23
23
|
// from the embedded filesystem. `upgrade --reconcile` installs the
|
|
24
|
-
// OpenCode SDK here when
|
|
24
|
+
// OpenCode SDK here when a configured model runs on OpenCode.
|
|
25
25
|
nodeModulesDir: string;
|
|
26
26
|
reposDir: string;
|
|
27
27
|
// C5: two config files live in this dir and NEITHER of them is called
|
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
|
+
export const ENGINE_VERSION = "0.5.0";
|
|
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
|
package/src/model/catalog.ts
CHANGED
|
@@ -5,9 +5,9 @@ import type { RunnerBackend } from "../execution/contracts";
|
|
|
5
5
|
//
|
|
6
6
|
// WHY it used to hold more, and why that was the last version pin in the
|
|
7
7
|
// system: every alias carried `modelFamily`/`modelSnapshot` (`sonnet` ->
|
|
8
|
-
// `claude-sonnet-5`). That pin never decided what RAN —
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// `claude-sonnet-5`). That pin never decided what RAN — the bare alias reaches
|
|
9
|
+
// `--model` and the Claude CLI resolves it itself (verified live 2026-09-02:
|
|
10
|
+
// `--model sonnet` ran `claude-sonnet-5`).
|
|
11
11
|
// It decided only what we ASSERTED had run, in `ResolvedModelRoute`, the route
|
|
12
12
|
// fingerprint and `pipeline.json`. So the day Anthropic repointed an alias,
|
|
13
13
|
// the CLI would run the new model and our provenance artifact would state the
|
|
@@ -21,10 +21,9 @@ import type { RunnerBackend } from "../execution/contracts";
|
|
|
21
21
|
// name now fails AT THE PROVIDER — an error from the party that knows is more
|
|
22
22
|
// honest than a mapping of ours that pretends to.
|
|
23
23
|
//
|
|
24
|
-
// The operator can still pin:
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// ship.
|
|
24
|
+
// The operator can still pin: `claude:<full model name>` in `models` reaches
|
|
25
|
+
// `--model` as written (model/model-name.ts). Pinning is a decision an operator
|
|
26
|
+
// makes, not a constant we ship. The `-latest` names are these aliases.
|
|
28
27
|
export interface ProviderModelCatalog {
|
|
29
28
|
readonly provider: string;
|
|
30
29
|
readonly defaultBackend?: RunnerBackend;
|
|
@@ -103,7 +102,6 @@ export const MODEL_CATALOG = Object.freeze({
|
|
|
103
102
|
});
|
|
104
103
|
|
|
105
104
|
const aliasIndex = new Map<string, ResolvedCatalogAlias>();
|
|
106
|
-
const canonicalToAlias = new Map<string, string>();
|
|
107
105
|
|
|
108
106
|
for (const catalog of Object.values(PROVIDER_CATALOGS)) {
|
|
109
107
|
for (const alias of catalog.aliases) {
|
|
@@ -111,22 +109,6 @@ for (const catalog of Object.values(PROVIDER_CATALOGS)) {
|
|
|
111
109
|
throw new Error(`model catalog: duplicate alias "${alias}"`);
|
|
112
110
|
}
|
|
113
111
|
const canonical = canonicalIdentity(catalog.provider, alias);
|
|
114
|
-
// The BIJECTION `reverseAliasForCanonical` depends on, asserted where the
|
|
115
|
-
// map is built rather than inferred from `canonicalIdentity`'s current
|
|
116
|
-
// shape — which is exactly the shape #175 changed.
|
|
117
|
-
//
|
|
118
|
-
// Honest about its reach: while canonical is `provider/alias`, the
|
|
119
|
-
// duplicate-alias guard above already makes a collision unreachable, so
|
|
120
|
-
// this throw cannot fire today. It used to be the load-bearing one —
|
|
121
|
-
// canonical was `provider/modelFamily`, and two aliases pinned to one
|
|
122
|
-
// family (a `sonnet` and a `sonnet-latest` both on `claude-sonnet-5`)
|
|
123
|
-
// would have silently made `reverseAliasForCanonical` return whichever
|
|
124
|
-
// won the loop, so `spawnModelForClaudeCli` would send the other alias's
|
|
125
|
-
// name. It stays because the invariant, not the current key formula, is
|
|
126
|
-
// what the reverse lookup is allowed to rely on.
|
|
127
|
-
if (canonicalToAlias.has(canonical)) {
|
|
128
|
-
throw new Error(`model catalog: duplicate canonical "${canonical}"`);
|
|
129
|
-
}
|
|
130
112
|
aliasIndex.set(alias, {
|
|
131
113
|
provider: catalog.provider,
|
|
132
114
|
alias,
|
|
@@ -135,18 +117,22 @@ for (const catalog of Object.values(PROVIDER_CATALOGS)) {
|
|
|
135
117
|
? {}
|
|
136
118
|
: { defaultBackend: catalog.defaultBackend }),
|
|
137
119
|
});
|
|
138
|
-
canonicalToAlias.set(canonical, alias);
|
|
139
120
|
}
|
|
140
121
|
}
|
|
141
122
|
|
|
142
|
-
export type ModelAlias = "sonnet" | "opus" | "haiku";
|
|
123
|
+
export type ModelAlias = "sonnet" | "opus" | "haiku" | "fable";
|
|
143
124
|
|
|
144
125
|
// Unchanged by #175, and the reason it is unchanged is the whole point of the
|
|
145
126
|
// slice: the alias LIST is ours, so a config that drops one still has to fail
|
|
146
127
|
// loud at import. `ModelAlias` is a compile-time union and the JSON is a
|
|
147
128
|
// runtime file; without this loop a deleted alias would typecheck and then
|
|
148
129
|
// throw `unknown alias` deep inside a run.
|
|
149
|
-
const REQUIRED_ALIASES: readonly ModelAlias[] = [
|
|
130
|
+
const REQUIRED_ALIASES: readonly ModelAlias[] = [
|
|
131
|
+
"sonnet",
|
|
132
|
+
"opus",
|
|
133
|
+
"haiku",
|
|
134
|
+
"fable",
|
|
135
|
+
];
|
|
150
136
|
for (const alias of REQUIRED_ALIASES) {
|
|
151
137
|
if (!aliasIndex.has(alias)) {
|
|
152
138
|
throw new Error(`model catalog: missing required alias "${alias}"`);
|
|
@@ -173,16 +159,6 @@ export function aliasCanonical(alias: ModelAlias): string {
|
|
|
173
159
|
return lookupAlias(alias).canonical;
|
|
174
160
|
}
|
|
175
161
|
|
|
176
|
-
// `spawnModelForClaudeCli` depends on this: on a `direct` gateway it turns a
|
|
177
|
-
// canonical identity back into the bare alias so the CLI — not us — resolves
|
|
178
|
-
// the version. Sound because of the bijection asserted above.
|
|
179
|
-
export function reverseAliasForCanonical(
|
|
180
|
-
canonical: string,
|
|
181
|
-
): ModelAlias | undefined {
|
|
182
|
-
const alias = canonicalToAlias.get(canonical);
|
|
183
|
-
return alias === undefined ? undefined : (alias as ModelAlias);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
162
|
// The Claude Code CLI's `--effort` vocabulary, closed. Lives beside
|
|
187
163
|
// `ModelAlias` because the pair is what a step is asked to run as: a model and
|
|
188
164
|
// how hard it works. An unknown level must fail at the frontmatter seam, not
|