@claudexor/orchestrator 3.1.2 → 3.2.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.
Files changed (125) hide show
  1. package/dist/attemptFinalize.d.ts +14 -11
  2. package/dist/attemptFinalize.d.ts.map +1 -1
  3. package/dist/attemptFinalize.js +41 -14
  4. package/dist/attemptFinalize.js.map +1 -1
  5. package/dist/attemptTelemetry.d.ts +7 -0
  6. package/dist/attemptTelemetry.d.ts.map +1 -1
  7. package/dist/attemptTelemetry.js +2 -1
  8. package/dist/attemptTelemetry.js.map +1 -1
  9. package/dist/attemptUsageCost.d.ts +17 -1
  10. package/dist/attemptUsageCost.d.ts.map +1 -1
  11. package/dist/attemptUsageCost.js +11 -1
  12. package/dist/attemptUsageCost.js.map +1 -1
  13. package/dist/budgetFailure.js.map +1 -1
  14. package/dist/credential-profile-rotation.d.ts +145 -0
  15. package/dist/credential-profile-rotation.d.ts.map +1 -0
  16. package/dist/credential-profile-rotation.js +315 -0
  17. package/dist/credential-profile-rotation.js.map +1 -0
  18. package/dist/credential-profiles.d.ts +35 -134
  19. package/dist/credential-profiles.d.ts.map +1 -1
  20. package/dist/credential-profiles.js +73 -295
  21. package/dist/credential-profiles.js.map +1 -1
  22. package/dist/decisionBudget.d.ts +2 -2
  23. package/dist/decisionBudget.d.ts.map +1 -1
  24. package/dist/deepScanReducer.d.ts +14 -44
  25. package/dist/deepScanReducer.d.ts.map +1 -1
  26. package/dist/deepScanReducer.js +240 -128
  27. package/dist/deepScanReducer.js.map +1 -1
  28. package/dist/delegationBudgetAuthority.d.ts.map +1 -1
  29. package/dist/delegationBudgetAuthority.js.map +1 -1
  30. package/dist/delegationFailure.d.ts.map +1 -1
  31. package/dist/git-precondition.d.ts +11 -0
  32. package/dist/git-precondition.d.ts.map +1 -0
  33. package/dist/git-precondition.js +69 -0
  34. package/dist/git-precondition.js.map +1 -0
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/interaction.d.ts +14 -6
  40. package/dist/interaction.d.ts.map +1 -1
  41. package/dist/interaction.js +106 -19
  42. package/dist/interaction.js.map +1 -1
  43. package/dist/orchestrator.d.ts +39 -83
  44. package/dist/orchestrator.d.ts.map +1 -1
  45. package/dist/orchestrator.js +480 -676
  46. package/dist/orchestrator.js.map +1 -1
  47. package/dist/planBrief.d.ts +27 -0
  48. package/dist/planBrief.d.ts.map +1 -0
  49. package/dist/planBrief.js +42 -0
  50. package/dist/planBrief.js.map +1 -0
  51. package/dist/planRun.d.ts +4 -3
  52. package/dist/planRun.d.ts.map +1 -1
  53. package/dist/planRun.js +33 -33
  54. package/dist/planRun.js.map +1 -1
  55. package/dist/plannerAttempt.d.ts +64 -0
  56. package/dist/plannerAttempt.d.ts.map +1 -0
  57. package/dist/plannerAttempt.js +235 -0
  58. package/dist/plannerAttempt.js.map +1 -0
  59. package/dist/policyFindings.js.map +1 -1
  60. package/dist/requestRequirements.d.ts +28 -1
  61. package/dist/requestRequirements.d.ts.map +1 -1
  62. package/dist/requestRequirements.js +89 -10
  63. package/dist/requestRequirements.js.map +1 -1
  64. package/dist/reviewerPanel.js.map +1 -1
  65. package/dist/root-ledger.d.ts.map +1 -1
  66. package/dist/root-ledger.js +2 -0
  67. package/dist/root-ledger.js.map +1 -1
  68. package/dist/run-bounded.d.ts.map +1 -1
  69. package/dist/run-bounded.js +7 -1
  70. package/dist/run-bounded.js.map +1 -1
  71. package/dist/run-input-resolution.d.ts.map +1 -1
  72. package/dist/run-input-resolution.js +26 -8
  73. package/dist/run-input-resolution.js.map +1 -1
  74. package/dist/runEventLog.d.ts +48 -0
  75. package/dist/runEventLog.d.ts.map +1 -0
  76. package/dist/runEventLog.js +63 -0
  77. package/dist/runEventLog.js.map +1 -0
  78. package/dist/runFacts.d.ts +23 -0
  79. package/dist/runFacts.d.ts.map +1 -0
  80. package/dist/runFacts.js +179 -0
  81. package/dist/runFacts.js.map +1 -0
  82. package/dist/runFactsBuilder.d.ts +5 -0
  83. package/dist/runFactsBuilder.d.ts.map +1 -0
  84. package/dist/runFactsBuilder.js +412 -0
  85. package/dist/runFactsBuilder.js.map +1 -0
  86. package/dist/runFactsDeliverable.d.ts +13 -0
  87. package/dist/runFactsDeliverable.d.ts.map +1 -0
  88. package/dist/runFactsDeliverable.js +94 -0
  89. package/dist/runFactsDeliverable.js.map +1 -0
  90. package/dist/runFactsPresentation.d.ts +7 -0
  91. package/dist/runFactsPresentation.d.ts.map +1 -0
  92. package/dist/runFactsPresentation.js +113 -0
  93. package/dist/runFactsPresentation.js.map +1 -0
  94. package/dist/runFactsReview.d.ts +7 -0
  95. package/dist/runFactsReview.d.ts.map +1 -0
  96. package/dist/runFactsReview.js +63 -0
  97. package/dist/runFactsReview.js.map +1 -0
  98. package/dist/runSupport.d.ts +17 -15
  99. package/dist/runSupport.d.ts.map +1 -1
  100. package/dist/runSupport.js +16 -0
  101. package/dist/runSupport.js.map +1 -1
  102. package/dist/runTerminalContext.d.ts +31 -0
  103. package/dist/runTerminalContext.d.ts.map +1 -0
  104. package/dist/runTerminalContext.js +12 -0
  105. package/dist/runTerminalContext.js.map +1 -0
  106. package/dist/runTerminalResults.d.ts +55 -0
  107. package/dist/runTerminalResults.d.ts.map +1 -0
  108. package/dist/runTerminalResults.js +134 -0
  109. package/dist/runTerminalResults.js.map +1 -0
  110. package/dist/runTerminals.d.ts +4 -80
  111. package/dist/runTerminals.d.ts.map +1 -1
  112. package/dist/runTerminals.js +357 -260
  113. package/dist/runTerminals.js.map +1 -1
  114. package/dist/secretDiff.d.ts +3 -0
  115. package/dist/secretDiff.d.ts.map +1 -1
  116. package/dist/secretDiff.js +7 -0
  117. package/dist/secretDiff.js.map +1 -1
  118. package/dist/structuredOutput.d.ts.map +1 -1
  119. package/dist/structuredOutput.js.map +1 -1
  120. package/dist/task-contract-builder.d.ts +35 -0
  121. package/dist/task-contract-builder.d.ts.map +1 -0
  122. package/dist/task-contract-builder.js +114 -0
  123. package/dist/task-contract-builder.js.map +1 -0
  124. package/dist/transientClassify.js.map +1 -1
  125. package/package.json +17 -17
@@ -1,4 +1,6 @@
1
- import type { CredentialProfile, HarnessEvent, HarnessRunSpec, QuotaSnapshot } from "@claudexor/schema";
1
+ import type { AuthPreference, AuthSourceReadiness, CredentialProfile, CredentialProfileStatus, HarnessEvent, QuotaSnapshot } from "@claudexor/schema";
2
+ import { type ProfilePolicy } from "./credential-profile-rotation.js";
3
+ export { nextEligibleProfile, planReactiveRotation, preflightCredentialProfile, preflightDefaultSubject, profileHeadroomBreach, rotateSpecOnTypedLimit, rotationRetryEligible, staticRotationCandidates, type ProfilePolicy, } from "./credential-profile-rotation.js";
2
4
  /**
3
5
  * The ONE resolve owner for credential profiles (INV-135): explicit id →
4
6
  * durable registry entry for exactly this harness. Unknown, disabled, or
@@ -10,58 +12,45 @@ export declare function selectedProfileAvailability(input: {
10
12
  registry: readonly CredentialProfile[];
11
13
  profileId?: string | null;
12
14
  harnessId: string;
13
- probe?: (profile: CredentialProfile) => Promise<{
14
- availability: string;
15
- verification: string;
16
- detail?: string | null;
17
- }>;
15
+ probe?: (profile: CredentialProfile) => Promise<CredentialProfileStatus>;
18
16
  }): Promise<string | null>;
19
- export interface ProfilePolicy {
20
- limit_action: "fail" | "ask" | "rotate";
21
- rotation_eligible: string[];
22
- headroom_threshold: number;
23
- }
24
- /** Typed quota evidence for a profile over its headroom bound (provenance). */
25
- export interface HeadroomBreach {
26
- constraint_id: string;
27
- used_ratio: number;
28
- threshold: number;
29
- resets_at: string | null;
30
- }
31
- /**
32
- * Proactive headroom check (W5.4 `profile_headroom_preflight`): the SELECTED
33
- * profile's freshest snapshot windows against the policy threshold. Unknown
34
- * usage is NOT a breach rotation never triggers on missing data.
35
- */
36
- export declare function profileHeadroomBreach(snapshots: readonly QuotaSnapshot[], harnessId: string, profileId: string | null, threshold: number): HeadroomBreach | null;
37
- /**
38
- * The next rotation target after `currentProfileId` (W5.4): policy order wins
39
- * (`rotation_eligible`), else every enabled profile of the harness in registry
40
- * order. The current profile and disabled/unknown ids never come back; a
41
- * profile already over the headroom bound is skipped (rotating INTO a spent
42
- * subscription is not a failover). Cross-subscription rotation of one vendor
43
- * is allowed by owner decision — but rotation NEVER crosses credential kinds
44
- * (release wave round-16 BLOCK): a subscription→API-key swap silently changes
45
- * the payment model mid-attempt, and the attempt's first-wins auth-route
46
- * receipt (decided once before spawn) would misvalue metered usage as
47
- * subscription entitlement, bypassing a finite cash cap.
48
- */
49
- export declare function nextEligibleProfile(registry: readonly CredentialProfile[], harnessId: string, policy: ProfilePolicy, current: Pick<CredentialProfile, "profile_id" | "credential_kind"> | null, snapshots: readonly QuotaSnapshot[], excluded?: ReadonlySet<string>): CredentialProfile | null;
17
+ /** One readiness predicate shared by run admission and accounts projection. */
18
+ export declare function profileStatusAdmits(profile: Pick<CredentialProfile, "credential_kind">, result: {
19
+ availability: string;
20
+ verification: string;
21
+ }): boolean;
22
+ /** One fail-closed profile doctor wrapper shared by Accounts and runtime
23
+ * selection. Probe failures are readiness facts, never selector exceptions. */
24
+ export declare function probeCredentialProfileStatus(profile: CredentialProfile, probe?: (profile: CredentialProfile) => Promise<CredentialProfileStatus>): Promise<CredentialProfileStatus>;
25
+ /** Same precedence used by run admission: the first explicit route wins;
26
+ * `auto` means fall through rather than shadow a more general setting. */
27
+ export declare function effectiveAuthPreference(...values: Array<AuthPreference | null | undefined>): AuthPreference;
28
+ /** Fresh effective route for the unprofiled/default subject in Accounts. The
29
+ * gateway status proves aggregate intent readiness; the schema auth estimator
30
+ * then chooses the exact usable source under the same configured preference as
31
+ * run admission. Returning the route (not merely a bool) keeps next_up labels
32
+ * truthful when a native-capable harness falls back to an API key. */
33
+ export declare function defaultCredentialRoute(status: {
34
+ status: "ok" | "degraded" | "unavailable";
35
+ routableIntents: readonly unknown[];
36
+ authSources: readonly AuthSourceReadiness[];
37
+ }, requested: AuthPreference): "local_session" | "api_key" | null;
50
38
  /** The informational identity an UNPINNED run of a harness would route to next
51
39
  * (INV-135 `next_up`) — the same routing owner that admits and rotates runs,
52
40
  * exposed for the accounts projection so no surface re-derives it. Never gates
53
41
  * routing: explicit control is a per-run `--profile` / per-thread pin.
54
42
  *
55
43
  * Semantics mirror run-time admission: an unpinned run's default subject is the
56
- * native/CLI login when it participates in the ladder; enabled profiles route
44
+ * unprofiled/default credential when it participates in the ladder; enabled profiles route
57
45
  * only by explicit pin or, under `rotate`, as the quota-failover target when the
58
- * native default is already over headroom. A disabled CLI login leaves an
46
+ * default subject is already over headroom. A disabled default leaves an
59
47
  * unpinned run with nothing routable. */
60
48
  export type NextUpIdentity = {
61
49
  kind: "profile";
62
50
  profileId: string;
63
51
  } | {
64
52
  kind: "native";
53
+ route: "local_session" | "api_key";
65
54
  } | {
66
55
  kind: "none";
67
56
  reason: string;
@@ -71,76 +60,14 @@ export declare function nextUpIdentity(args: {
71
60
  harnessId: string;
72
61
  policy: ProfilePolicy;
73
62
  snapshots: readonly QuotaSnapshot[];
74
- nativeEnabled: boolean;
63
+ defaultEnabled: boolean;
64
+ /** Fresh doctor/admission truth for the unprofiled default subject. */
65
+ defaultReady: boolean;
66
+ /** Effective source route of that default subject under configured auth preference. */
67
+ defaultRoute: "local_session" | "api_key" | null;
68
+ /** Profiles admitted by their fresh profile doctor probe in this snapshot. */
69
+ readyProfileIds: ReadonlySet<string>;
75
70
  }): NextUpIdentity;
76
- /**
77
- * `rotation_retry_eligible` (sol #30): a failover retry is allowed ONLY when
78
- * the attempt saw a TYPED vendor limit AND produced no deliverable and no
79
- * workspace mutation — a partially-acted attempt never silently reruns.
80
- */
81
- export declare function rotationRetryEligible(input: {
82
- sawTypedLimit: boolean;
83
- deliverableEmpty: boolean;
84
- }): boolean;
85
- type EmitFn = (type: "route.profile.headroom_exceeded" | "route.profile.rotated" | "route.profile.rotation_exhausted", payload: Record<string, unknown>) => void;
86
- /**
87
- * `profile_headroom_preflight` (W5.4): BEFORE spawn, the selected profile's
88
- * freshest quota windows are checked against the policy threshold. A breach
89
- * is always a typed event; `rotate` swaps to the next eligible profile with
90
- * provenance, `ask`/`fail` proceed on the selected profile — the runtime
91
- * `vendor_limit_rejected` evidence stays the terminating truth.
92
- */
93
- export declare function preflightCredentialProfile(args: {
94
- profile: CredentialProfile;
95
- harnessId: string;
96
- policy: ProfilePolicy;
97
- registry: readonly CredentialProfile[];
98
- snapshots: readonly QuotaSnapshot[];
99
- emit: EmitFn;
100
- }): CredentialProfile;
101
- /**
102
- * Default-subject start selection (INV-135, owner scope "auto-balance"): when
103
- * NO profile is pinned, the policy is `rotate`, and the DEFAULT store's own
104
- * fresh quota window is at/over the headroom bound, pick the first eligible
105
- * SUBSCRIPTION profile instead of spawning into a near-certain vendor limit.
106
- * Strictly opt-in: `fail`/`ask` keep today's default-user behavior untouched
107
- * (the profile engine's fail action governs PINNED profiles only — throwing
108
- * here would brick every default user at 90% quota). Unknown or stale usage
109
- * never rotates.
110
- */
111
- export declare function preflightDefaultSubject(args: {
112
- harnessId: string;
113
- policy: ProfilePolicy;
114
- registry: readonly CredentialProfile[];
115
- snapshots: readonly QuotaSnapshot[];
116
- emit: EmitFn;
117
- }): CredentialProfile | null;
118
- /**
119
- * Reactive failover plan (`vendor_limit_rejected`, W5.4): rotation fires ONLY
120
- * on the typed predicate under a `rotate` policy, marks the current profile
121
- * tried (at most once per attempt each), and returns the next target with
122
- * provenance already emitted — or null when the attempt must fail as-is.
123
- * `currentProfile: null` is the DEFAULT subject: allowed ONLY when the caller
124
- * proves the attempt's pre-spawn route was vendor_native (a metered default
125
- * hitting a limit is a budget fact, not a subscription to fail over from).
126
- */
127
- export declare function planReactiveRotation(args: {
128
- currentProfile: CredentialProfile | null;
129
- defaultRouteWasVendorNative?: boolean;
130
- harnessId: string;
131
- attemptId: string;
132
- policy: ProfilePolicy;
133
- registry: readonly CredentialProfile[];
134
- snapshots: readonly QuotaSnapshot[];
135
- triedProfiles: Set<string>;
136
- sawTypedLimit: boolean;
137
- deliverableEmpty: boolean;
138
- lastLimit: {
139
- retryDelayMs: number | null;
140
- resetsAt: string | null;
141
- } | null;
142
- emit: EmitFn;
143
- }): CredentialProfile | null;
144
71
  /**
145
72
  * INV-135 at the engine boundary: a cached vendor session resumes ONLY under
146
73
  * exactly the profile it was recorded with (null-default equality included) —
@@ -159,30 +86,4 @@ export declare function resumeSessionForProfile(cached: {
159
86
  export declare function observeNativeSessionEvent(input: {
160
87
  onSessionObserved?: (harnessId: string, nativeSessionId: string, observedModel?: string | null, profileId?: string | null) => void;
161
88
  } | undefined, harnessId: string, ev: HarnessEvent): void;
162
- /**
163
- * Shared reactive-failover step for BOTH lanes: given the attempt's typed
164
- * evidence, plan a rotation and rebuild the spec on a NEW vendor session
165
- * under the next profile — or return null when the attempt must fail as-is.
166
- */
167
- export declare function rotateSpecOnTypedLimit(args: {
168
- spec: HarnessRunSpec;
169
- harnessId: string;
170
- attemptId: string;
171
- policy: ProfilePolicy;
172
- registry: readonly CredentialProfile[];
173
- snapshots: readonly QuotaSnapshot[];
174
- triedProfiles: Set<string>;
175
- sawTypedLimit: boolean;
176
- deliverableEmpty: boolean;
177
- lastLimit: {
178
- retryDelayMs: number | null;
179
- resetsAt: string | null;
180
- } | null;
181
- emit: EmitFn;
182
- newSessionId: () => string;
183
- /** Pre-spawn route estimate for a profile-less spec: default-subject
184
- * rotation is allowed ONLY off a vendor_native attempt. */
185
- defaultRouteWasVendorNative?: boolean;
186
- }): HarnessRunSpec | null;
187
- export {};
188
89
  //# sourceMappingURL=credential-profiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"credential-profiles.d.ts","sourceRoot":"","sources":["../src/credential-profiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,aAAa,EACd,MAAM,mBAAmB,CAAC;AAG3B;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,iBAAiB,EAAE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YAAY,GACf,IAAI,CAeN"}
@@ -1,4 +1,8 @@
1
- import { HarnessRunSpec as HarnessRunSpecSchema } from "@claudexor/schema";
1
+ import { CredentialProfileStatus as CredentialProfileStatusSchema } from "@claudexor/schema";
2
+ import { redactSecrets } from "@claudexor/util";
3
+ import { estimateEffectiveAuthRoute } from "@claudexor/schema";
4
+ import { nextEligibleProfile, profileHeadroomBreach, } from "./credential-profile-rotation.js";
5
+ export { nextEligibleProfile, planReactiveRotation, preflightCredentialProfile, preflightDefaultSubject, profileHeadroomBreach, rotateSpecOnTypedLimit, rotationRetryEligible, staticRotationCandidates, } from "./credential-profile-rotation.js";
2
6
  /**
3
7
  * The ONE resolve owner for credential profiles (INV-135): explicit id →
4
8
  * durable registry entry for exactly this harness. Unknown, disabled, or
@@ -27,295 +31,98 @@ export async function selectedProfileAvailability(input) {
27
31
  }
28
32
  if (!input.probe)
29
33
  return `harness "${input.harnessId}" has no profile probe`;
30
- const result = await input.probe(profile);
31
- const verificationAdmits = result.verification === "passed" ||
32
- (profile.credential_kind === "api_key" && result.verification === "not_run");
33
- return result.availability === "available" && verificationAdmits
34
+ const result = await probeCredentialProfileStatus(profile, input.probe);
35
+ return profileStatusAdmits(profile, result)
34
36
  ? "available"
35
37
  : (result.detail ?? `${result.availability}/${result.verification}`);
36
38
  }
37
- /**
38
- * Proactive headroom check (W5.4 `profile_headroom_preflight`): the SELECTED
39
- * profile's freshest snapshot windows against the policy threshold. Unknown
40
- * usage is NOT a breach — rotation never triggers on missing data.
41
- */
42
- export function profileHeadroomBreach(snapshots, harnessId, profileId, threshold) {
43
- for (const snapshot of snapshots) {
44
- // FRESH evidence only (release wave tier1 #3): a stale or unknown reading
45
- // must never breach headroom, rotate a profile away, or fail selection.
46
- if (snapshot.freshness !== "fresh")
47
- continue;
48
- if (snapshot.subject.harness !== harnessId)
49
- continue;
50
- if ((snapshot.subject.subject_id ?? null) !== profileId)
51
- continue;
52
- for (const constraint of snapshot.constraints) {
53
- if (constraint.used_ratio !== null && constraint.used_ratio >= threshold) {
54
- return {
55
- constraint_id: constraint.id,
56
- used_ratio: constraint.used_ratio,
57
- threshold,
58
- resets_at: constraint.resets_at,
59
- };
60
- }
39
+ /** One readiness predicate shared by run admission and accounts projection. */
40
+ export function profileStatusAdmits(profile, result) {
41
+ const verificationAdmits = result.verification === "passed" ||
42
+ (profile.credential_kind === "api_key" && result.verification === "not_run");
43
+ return result.availability === "available" && verificationAdmits;
44
+ }
45
+ /** One fail-closed profile doctor wrapper shared by Accounts and runtime
46
+ * selection. Probe failures are readiness facts, never selector exceptions. */
47
+ export async function probeCredentialProfileStatus(profile, probe) {
48
+ if (!probe) {
49
+ return {
50
+ profile_id: profile.profile_id,
51
+ harness_id: profile.harness_id,
52
+ availability: "unknown",
53
+ verification: "not_run",
54
+ detail: `harness "${profile.harness_id}" has no profile probe`,
55
+ last_verified_at: null,
56
+ };
57
+ }
58
+ try {
59
+ const result = CredentialProfileStatusSchema.parse(await probe(profile));
60
+ if (result.profile_id !== profile.profile_id || result.harness_id !== profile.harness_id) {
61
+ throw new Error("profile readiness probe returned status for a different profile");
61
62
  }
63
+ return {
64
+ ...result,
65
+ ...(result.detail === undefined ? {} : { detail: redactSecrets(result.detail) }),
66
+ };
62
67
  }
63
- return null;
64
- }
65
- /**
66
- * The next rotation target after `currentProfileId` (W5.4): policy order wins
67
- * (`rotation_eligible`), else every enabled profile of the harness in registry
68
- * order. The current profile and disabled/unknown ids never come back; a
69
- * profile already over the headroom bound is skipped (rotating INTO a spent
70
- * subscription is not a failover). Cross-subscription rotation of one vendor
71
- * is allowed by owner decision — but rotation NEVER crosses credential kinds
72
- * (release wave round-16 BLOCK): a subscription→API-key swap silently changes
73
- * the payment model mid-attempt, and the attempt's first-wins auth-route
74
- * receipt (decided once before spawn) would misvalue metered usage as
75
- * subscription entitlement, bypassing a finite cash cap.
76
- */
77
- export function nextEligibleProfile(registry, harnessId, policy, current, snapshots, excluded = new Set()) {
78
- const pool = registry.filter((p) => p.harness_id === harnessId && p.enabled);
79
- const ordered = policy.rotation_eligible.length > 0
80
- ? policy.rotation_eligible
81
- .map((id) => pool.find((p) => p.profile_id === id))
82
- .filter((p) => p !== undefined)
83
- : pool;
84
- for (const candidate of ordered) {
85
- if (candidate.profile_id === current?.profile_id)
86
- continue;
87
- if (excluded.has(candidate.profile_id))
88
- continue;
89
- // Fail-CLOSED kind guard (round-17 hardening of the round-16 BLOCK): the
90
- // kind comes from the TYPED current profile in hand — never re-found in
91
- // a freshly reloaded pool, where a mid-flight disable/remove of the
92
- // current profile would have silently dropped the cross-kind prohibition.
93
- if (current !== null && candidate.credential_kind !== current.credential_kind)
94
- continue;
95
- // `current === null` is the DEFAULT subject (the vendor-native store): the
96
- // same round-16 BLOCK applies — rotating the subscription default INTO an
97
- // api_key profile would silently change the payment model mid-attempt.
98
- if (current === null && candidate.credential_kind === "api_key")
99
- continue;
100
- if (profileHeadroomBreach(snapshots, harnessId, candidate.profile_id, policy.headroom_threshold))
101
- continue;
102
- return candidate;
68
+ catch (error) {
69
+ return {
70
+ profile_id: profile.profile_id,
71
+ harness_id: profile.harness_id,
72
+ availability: "unknown",
73
+ verification: "not_run",
74
+ detail: `profile readiness probe failed: ${redactSecrets(error instanceof Error ? error.message : String(error))}`,
75
+ last_verified_at: null,
76
+ };
103
77
  }
104
- return null;
78
+ }
79
+ /** Same precedence used by run admission: the first explicit route wins;
80
+ * `auto` means fall through rather than shadow a more general setting. */
81
+ export function effectiveAuthPreference(...values) {
82
+ return (values.find((value) => value !== undefined && value !== null && value !== "auto") ?? "auto");
83
+ }
84
+ /** Fresh effective route for the unprofiled/default subject in Accounts. The
85
+ * gateway status proves aggregate intent readiness; the schema auth estimator
86
+ * then chooses the exact usable source under the same configured preference as
87
+ * run admission. Returning the route (not merely a bool) keeps next_up labels
88
+ * truthful when a native-capable harness falls back to an API key. */
89
+ export function defaultCredentialRoute(status, requested) {
90
+ if (status.status !== "ok" || status.routableIntents.length === 0)
91
+ return null;
92
+ return estimateEffectiveAuthRoute(requested, status.authSources);
105
93
  }
106
94
  export function nextUpIdentity(args) {
107
- const { registry, harnessId, policy, snapshots, nativeEnabled } = args;
108
- if (!nativeEnabled) {
95
+ const { registry, harnessId, policy, snapshots, defaultEnabled, defaultReady, defaultRoute, readyProfileIds, } = args;
96
+ if (!defaultEnabled) {
109
97
  return {
110
98
  kind: "none",
111
- reason: "the CLI login is disabled; pin an account per-run (--profile) or per-thread",
99
+ reason: "the default credential is disabled; enable it or pin an account per-run (--profile)",
100
+ };
101
+ }
102
+ if (!defaultReady) {
103
+ return {
104
+ kind: "none",
105
+ reason: "the default credential is not ready; refresh Accounts or run `claudexor doctor`",
112
106
  };
113
107
  }
114
108
  // Under `rotate`, a native/default subject already over its headroom bound
115
109
  // fails over to the next eligible enabled profile BEFORE spawn — that is who
116
110
  // an unpinned run routes to next. `ask`/`fail` proceed on the native default.
117
- if (policy.limit_action === "rotate") {
111
+ if (policy.limit_action === "rotate" && defaultRoute === "local_session") {
118
112
  const breach = profileHeadroomBreach(snapshots, harnessId, null, policy.headroom_threshold);
119
113
  if (breach) {
120
- const next = nextEligibleProfile(registry, harnessId, policy, null, snapshots);
114
+ const next = nextEligibleProfile(registry, harnessId, policy, null, snapshots, readyProfileIds);
121
115
  if (next)
122
116
  return { kind: "profile", profileId: next.profile_id };
123
117
  }
124
118
  }
125
- return { kind: "native" };
126
- }
127
- /**
128
- * `rotation_retry_eligible` (sol #30): a failover retry is allowed ONLY when
129
- * the attempt saw a TYPED vendor limit AND produced no deliverable and no
130
- * workspace mutation — a partially-acted attempt never silently reruns.
131
- */
132
- export function rotationRetryEligible(input) {
133
- return input.sawTypedLimit && input.deliverableEmpty;
134
- }
135
- function emitRotationExhausted(args) {
136
- const excluded = args.excluded ?? new Set();
137
- const candidates = args.registry
138
- .filter((profile) => profile.harness_id === args.harnessId && profile.enabled)
139
- .map((profile) => {
140
- const breach = profileHeadroomBreach(args.snapshots, args.harnessId, profile.profile_id, args.policy.headroom_threshold);
141
- const rejected = profile.profile_id === args.current?.profile_id
142
- ? "current"
143
- : args.policy.rotation_eligible.length > 0 &&
144
- !args.policy.rotation_eligible.includes(profile.profile_id)
145
- ? "not_in_rotation_policy"
146
- : excluded.has(profile.profile_id)
147
- ? "already_tried"
148
- : args.current && profile.credential_kind !== args.current.credential_kind
149
- ? "credential_kind_mismatch"
150
- : args.current === null && profile.credential_kind === "api_key"
151
- ? "credential_kind_mismatch"
152
- : breach
153
- ? "headroom_exceeded"
154
- : "not_selected";
119
+ if (!defaultRoute) {
155
120
  return {
156
- profile_id: profile.profile_id,
157
- credential_kind: profile.credential_kind,
158
- rejected,
159
- headroom: breach,
121
+ kind: "none",
122
+ reason: "the default credential route is unknown; refresh Accounts or run `claudexor doctor`",
160
123
  };
161
- });
162
- args.emit("route.profile.rotation_exhausted", {
163
- harness_id: args.harnessId,
164
- attempt_id: args.attemptId,
165
- from_profile_id: args.current?.profile_id ?? null,
166
- reason: args.reason,
167
- threshold: args.policy.headroom_threshold,
168
- candidates,
169
- });
170
- }
171
- /**
172
- * `profile_headroom_preflight` (W5.4): BEFORE spawn, the selected profile's
173
- * freshest quota windows are checked against the policy threshold. A breach
174
- * is always a typed event; `rotate` swaps to the next eligible profile with
175
- * provenance, `ask`/`fail` proceed on the selected profile — the runtime
176
- * `vendor_limit_rejected` evidence stays the terminating truth.
177
- */
178
- export function preflightCredentialProfile(args) {
179
- const { profile, harnessId, policy, registry, snapshots, emit } = args;
180
- const breach = profileHeadroomBreach(snapshots, harnessId, profile.profile_id, policy.headroom_threshold);
181
- if (!breach)
182
- return profile;
183
- emit("route.profile.headroom_exceeded", {
184
- harness_id: harnessId,
185
- profile_id: profile.profile_id,
186
- action: policy.limit_action,
187
- constraint_id: breach.constraint_id,
188
- used_ratio: breach.used_ratio,
189
- threshold: breach.threshold,
190
- resets_at: breach.resets_at,
191
- });
192
- if (policy.limit_action === "fail") {
193
- // The documented FAIL action fails (release wave tier1 #4): a FRESH breach
194
- // under fail refuses before spawn with the evidence, instead of silently
195
- // proceeding into a vendor rejection.
196
- throw new Error(`credential profile "${profile.profile_id}" (${harnessId}) is over its headroom threshold ` +
197
- `(${breach.constraint_id} at ${Math.round(breach.used_ratio * 100)}% >= ${Math.round(breach.threshold * 100)}%; ` +
198
- `limit_action=fail${breach.resets_at ? `; resets ${breach.resets_at}` : ""})`);
199
- }
200
- if (policy.limit_action !== "rotate")
201
- return profile;
202
- const next = nextEligibleProfile(registry, harnessId, policy, profile, snapshots);
203
- if (!next) {
204
- emitRotationExhausted({
205
- current: profile,
206
- harnessId,
207
- policy,
208
- registry,
209
- snapshots,
210
- reason: "profile_headroom_preflight",
211
- emit,
212
- });
213
- return profile;
214
- }
215
- emit("route.profile.rotated", {
216
- harness_id: harnessId,
217
- from_profile_id: profile.profile_id,
218
- to_profile_id: next.profile_id,
219
- reason: "profile_headroom_preflight",
220
- constraint_id: breach.constraint_id,
221
- used_ratio: breach.used_ratio,
222
- resets_at: breach.resets_at,
223
- });
224
- return next;
225
- }
226
- /**
227
- * Default-subject start selection (INV-135, owner scope "auto-balance"): when
228
- * NO profile is pinned, the policy is `rotate`, and the DEFAULT store's own
229
- * fresh quota window is at/over the headroom bound, pick the first eligible
230
- * SUBSCRIPTION profile instead of spawning into a near-certain vendor limit.
231
- * Strictly opt-in: `fail`/`ask` keep today's default-user behavior untouched
232
- * (the profile engine's fail action governs PINNED profiles only — throwing
233
- * here would brick every default user at 90% quota). Unknown or stale usage
234
- * never rotates.
235
- */
236
- export function preflightDefaultSubject(args) {
237
- const { harnessId, policy, registry, snapshots, emit } = args;
238
- if (policy.limit_action !== "rotate")
239
- return null;
240
- const breach = profileHeadroomBreach(snapshots, harnessId, null, policy.headroom_threshold);
241
- if (!breach)
242
- return null;
243
- emit("route.profile.headroom_exceeded", {
244
- harness_id: harnessId,
245
- profile_id: null,
246
- action: policy.limit_action,
247
- constraint_id: breach.constraint_id,
248
- used_ratio: breach.used_ratio,
249
- threshold: breach.threshold,
250
- resets_at: breach.resets_at,
251
- });
252
- const next = nextEligibleProfile(registry, harnessId, policy, null, snapshots);
253
- if (!next) {
254
- emitRotationExhausted({
255
- current: null,
256
- harnessId,
257
- policy,
258
- registry,
259
- snapshots,
260
- reason: "profile_headroom_preflight",
261
- emit,
262
- });
263
- return null;
264
- }
265
- emit("route.profile.rotated", {
266
- harness_id: harnessId,
267
- from_profile_id: null,
268
- to_profile_id: next.profile_id,
269
- reason: "profile_headroom_preflight",
270
- constraint_id: breach.constraint_id,
271
- used_ratio: breach.used_ratio,
272
- resets_at: breach.resets_at,
273
- });
274
- return next;
275
- }
276
- /**
277
- * Reactive failover plan (`vendor_limit_rejected`, W5.4): rotation fires ONLY
278
- * on the typed predicate under a `rotate` policy, marks the current profile
279
- * tried (at most once per attempt each), and returns the next target with
280
- * provenance already emitted — or null when the attempt must fail as-is.
281
- * `currentProfile: null` is the DEFAULT subject: allowed ONLY when the caller
282
- * proves the attempt's pre-spawn route was vendor_native (a metered default
283
- * hitting a limit is a budget fact, not a subscription to fail over from).
284
- */
285
- export function planReactiveRotation(args) {
286
- if (!rotationRetryEligible(args))
287
- return null;
288
- if (args.policy.limit_action !== "rotate")
289
- return null;
290
- if (args.currentProfile === null && args.defaultRouteWasVendorNative !== true)
291
- return null;
292
- if (args.currentProfile)
293
- args.triedProfiles.add(args.currentProfile.profile_id);
294
- const next = nextEligibleProfile(args.registry, args.harnessId, args.policy, args.currentProfile, args.snapshots, args.triedProfiles);
295
- if (!next) {
296
- emitRotationExhausted({
297
- current: args.currentProfile,
298
- harnessId: args.harnessId,
299
- policy: args.policy,
300
- registry: args.registry,
301
- snapshots: args.snapshots,
302
- excluded: args.triedProfiles,
303
- attemptId: args.attemptId,
304
- reason: "vendor_limit_rejected",
305
- emit: args.emit,
306
- });
307
- return null;
308
124
  }
309
- args.emit("route.profile.rotated", {
310
- harness_id: args.harnessId,
311
- attempt_id: args.attemptId,
312
- from_profile_id: args.currentProfile?.profile_id ?? null,
313
- to_profile_id: next.profile_id,
314
- reason: "vendor_limit_rejected",
315
- retry_delay_ms: args.lastLimit?.retryDelayMs ?? null,
316
- resets_at: args.lastLimit?.resetsAt ?? null,
317
- });
318
- return next;
125
+ return { kind: "native", route: defaultRoute };
319
126
  }
320
127
  /**
321
128
  * INV-135 at the engine boundary: a cached vendor session resumes ONLY under
@@ -346,33 +153,4 @@ export function observeNativeSessionEvent(input, harnessId, ev) {
346
153
  }
347
154
  }
348
155
  }
349
- /**
350
- * Shared reactive-failover step for BOTH lanes: given the attempt's typed
351
- * evidence, plan a rotation and rebuild the spec on a NEW vendor session
352
- * under the next profile — or return null when the attempt must fail as-is.
353
- */
354
- export function rotateSpecOnTypedLimit(args) {
355
- const rotation = planReactiveRotation({
356
- currentProfile: args.spec.credential_profile ?? null,
357
- defaultRouteWasVendorNative: args.defaultRouteWasVendorNative,
358
- harnessId: args.harnessId,
359
- attemptId: args.attemptId,
360
- policy: args.policy,
361
- registry: args.registry,
362
- snapshots: args.snapshots,
363
- triedProfiles: args.triedProfiles,
364
- sawTypedLimit: args.sawTypedLimit,
365
- deliverableEmpty: args.deliverableEmpty,
366
- lastLimit: args.lastLimit,
367
- emit: args.emit,
368
- });
369
- if (!rotation)
370
- return null;
371
- return HarnessRunSpecSchema.parse({
372
- ...args.spec,
373
- session_id: args.newSessionId(),
374
- credential_profile: rotation,
375
- resume_session_id: null,
376
- });
377
- }
378
156
  //# sourceMappingURL=credential-profiles.js.map