@claudexor/orchestrator 3.1.2 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +3 -1
  2. package/dist/attemptFinalize.d.ts +14 -11
  3. package/dist/attemptFinalize.d.ts.map +1 -1
  4. package/dist/attemptFinalize.js +41 -14
  5. package/dist/attemptFinalize.js.map +1 -1
  6. package/dist/attemptTelemetry.d.ts +7 -0
  7. package/dist/attemptTelemetry.d.ts.map +1 -1
  8. package/dist/attemptTelemetry.js +2 -1
  9. package/dist/attemptTelemetry.js.map +1 -1
  10. package/dist/attemptUsageCost.d.ts +17 -1
  11. package/dist/attemptUsageCost.d.ts.map +1 -1
  12. package/dist/attemptUsageCost.js +26 -2
  13. package/dist/attemptUsageCost.js.map +1 -1
  14. package/dist/budgetFailure.js.map +1 -1
  15. package/dist/credential-profile-rotation.d.ts +148 -0
  16. package/dist/credential-profile-rotation.d.ts.map +1 -0
  17. package/dist/credential-profile-rotation.js +322 -0
  18. package/dist/credential-profile-rotation.js.map +1 -0
  19. package/dist/credential-profiles.d.ts +38 -134
  20. package/dist/credential-profiles.d.ts.map +1 -1
  21. package/dist/credential-profiles.js +74 -296
  22. package/dist/credential-profiles.js.map +1 -1
  23. package/dist/decisionBudget.d.ts +2 -2
  24. package/dist/decisionBudget.d.ts.map +1 -1
  25. package/dist/deepScanReducer.d.ts +14 -44
  26. package/dist/deepScanReducer.d.ts.map +1 -1
  27. package/dist/deepScanReducer.js +240 -128
  28. package/dist/deepScanReducer.js.map +1 -1
  29. package/dist/delegationBudgetAuthority.d.ts.map +1 -1
  30. package/dist/delegationBudgetAuthority.js.map +1 -1
  31. package/dist/delegationFailure.d.ts.map +1 -1
  32. package/dist/git-precondition.d.ts +11 -0
  33. package/dist/git-precondition.d.ts.map +1 -0
  34. package/dist/git-precondition.js +69 -0
  35. package/dist/git-precondition.js.map +1 -0
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/interaction.d.ts +14 -6
  41. package/dist/interaction.d.ts.map +1 -1
  42. package/dist/interaction.js +106 -19
  43. package/dist/interaction.js.map +1 -1
  44. package/dist/orchestrator.d.ts +51 -83
  45. package/dist/orchestrator.d.ts.map +1 -1
  46. package/dist/orchestrator.js +558 -704
  47. package/dist/orchestrator.js.map +1 -1
  48. package/dist/planBrief.d.ts +27 -0
  49. package/dist/planBrief.d.ts.map +1 -0
  50. package/dist/planBrief.js +42 -0
  51. package/dist/planBrief.js.map +1 -0
  52. package/dist/planQuestions.js +4 -1
  53. package/dist/planQuestions.js.map +1 -1
  54. package/dist/planRun.d.ts +4 -3
  55. package/dist/planRun.d.ts.map +1 -1
  56. package/dist/planRun.js +33 -33
  57. package/dist/planRun.js.map +1 -1
  58. package/dist/plannerAttempt.d.ts +64 -0
  59. package/dist/plannerAttempt.d.ts.map +1 -0
  60. package/dist/plannerAttempt.js +235 -0
  61. package/dist/plannerAttempt.js.map +1 -0
  62. package/dist/policyFindings.js.map +1 -1
  63. package/dist/requestRequirements.d.ts +28 -1
  64. package/dist/requestRequirements.d.ts.map +1 -1
  65. package/dist/requestRequirements.js +89 -10
  66. package/dist/requestRequirements.js.map +1 -1
  67. package/dist/reviewerPanel.js.map +1 -1
  68. package/dist/root-ledger.d.ts.map +1 -1
  69. package/dist/root-ledger.js +2 -0
  70. package/dist/root-ledger.js.map +1 -1
  71. package/dist/run-bounded.d.ts.map +1 -1
  72. package/dist/run-bounded.js +7 -1
  73. package/dist/run-bounded.js.map +1 -1
  74. package/dist/run-input-resolution.d.ts.map +1 -1
  75. package/dist/run-input-resolution.js +26 -8
  76. package/dist/run-input-resolution.js.map +1 -1
  77. package/dist/runEventLog.d.ts +48 -0
  78. package/dist/runEventLog.d.ts.map +1 -0
  79. package/dist/runEventLog.js +63 -0
  80. package/dist/runEventLog.js.map +1 -0
  81. package/dist/runFacts.d.ts +23 -0
  82. package/dist/runFacts.d.ts.map +1 -0
  83. package/dist/runFacts.js +179 -0
  84. package/dist/runFacts.js.map +1 -0
  85. package/dist/runFactsBuilder.d.ts +5 -0
  86. package/dist/runFactsBuilder.d.ts.map +1 -0
  87. package/dist/runFactsBuilder.js +412 -0
  88. package/dist/runFactsBuilder.js.map +1 -0
  89. package/dist/runFactsDeliverable.d.ts +13 -0
  90. package/dist/runFactsDeliverable.d.ts.map +1 -0
  91. package/dist/runFactsDeliverable.js +94 -0
  92. package/dist/runFactsDeliverable.js.map +1 -0
  93. package/dist/runFactsPresentation.d.ts +7 -0
  94. package/dist/runFactsPresentation.d.ts.map +1 -0
  95. package/dist/runFactsPresentation.js +113 -0
  96. package/dist/runFactsPresentation.js.map +1 -0
  97. package/dist/runFactsReview.d.ts +7 -0
  98. package/dist/runFactsReview.d.ts.map +1 -0
  99. package/dist/runFactsReview.js +63 -0
  100. package/dist/runFactsReview.js.map +1 -0
  101. package/dist/runSupport.d.ts +17 -15
  102. package/dist/runSupport.d.ts.map +1 -1
  103. package/dist/runSupport.js +16 -0
  104. package/dist/runSupport.js.map +1 -1
  105. package/dist/runTerminalContext.d.ts +31 -0
  106. package/dist/runTerminalContext.d.ts.map +1 -0
  107. package/dist/runTerminalContext.js +12 -0
  108. package/dist/runTerminalContext.js.map +1 -0
  109. package/dist/runTerminalResults.d.ts +55 -0
  110. package/dist/runTerminalResults.d.ts.map +1 -0
  111. package/dist/runTerminalResults.js +134 -0
  112. package/dist/runTerminalResults.js.map +1 -0
  113. package/dist/runTerminals.d.ts +4 -80
  114. package/dist/runTerminals.d.ts.map +1 -1
  115. package/dist/runTerminals.js +357 -260
  116. package/dist/runTerminals.js.map +1 -1
  117. package/dist/secretDiff.d.ts +3 -0
  118. package/dist/secretDiff.d.ts.map +1 -1
  119. package/dist/secretDiff.js +7 -0
  120. package/dist/secretDiff.js.map +1 -1
  121. package/dist/structuredOutput.d.ts.map +1 -1
  122. package/dist/structuredOutput.js.map +1 -1
  123. package/dist/task-contract-builder.d.ts +35 -0
  124. package/dist/task-contract-builder.d.ts.map +1 -0
  125. package/dist/task-contract-builder.js +114 -0
  126. package/dist/task-contract-builder.js.map +1 -0
  127. package/dist/transientClassify.js.map +1 -1
  128. package/package.json +17 -17
@@ -0,0 +1,148 @@
1
+ import type { CredentialProfile, HarnessRunSpec, QuotaSnapshot } from "@claudexor/schema";
2
+ export interface ProfilePolicy {
3
+ limit_action: "fail" | "ask" | "rotate";
4
+ rotation_eligible: string[];
5
+ headroom_threshold: number;
6
+ }
7
+ /** Typed quota evidence for a profile over its headroom bound (provenance). */
8
+ export interface HeadroomBreach {
9
+ constraint_id: string;
10
+ used_ratio: number;
11
+ threshold: number;
12
+ resets_at: string | null;
13
+ }
14
+ /**
15
+ * Static rotation candidates, before any credential-backed readiness probe.
16
+ * One owner applies policy order, enabled/harness scope, current identity,
17
+ * already-tried exclusions, and the payment-kind fence. Callers then probe
18
+ * only identities that could actually be selected.
19
+ */
20
+ export declare function staticRotationCandidates(args: {
21
+ registry: readonly CredentialProfile[];
22
+ harnessId: string;
23
+ policy: ProfilePolicy;
24
+ current: Pick<CredentialProfile, "profile_id" | "credential_kind"> | null;
25
+ excluded?: ReadonlySet<string>;
26
+ }): CredentialProfile[];
27
+ /**
28
+ * Proactive headroom check (W5.4 `profile_headroom_preflight`): the SELECTED
29
+ * profile's freshest snapshot windows against the policy threshold. Unknown
30
+ * usage is NOT a breach — rotation never triggers on missing data.
31
+ */
32
+ export declare function profileHeadroomBreach(snapshots: readonly QuotaSnapshot[], harnessId: string, profileId: string | null, threshold: number, model?: string | null): HeadroomBreach | null;
33
+ /**
34
+ * The next rotation target after `currentProfileId` (W5.4): policy order wins
35
+ * (`rotation_eligible`), else every enabled profile of the harness in registry
36
+ * order. The current profile and disabled/unknown ids never come back; a
37
+ * profile already over the headroom bound is skipped (rotating INTO a spent
38
+ * subscription is not a failover). Cross-subscription rotation of one vendor
39
+ * is allowed by owner decision — but rotation NEVER crosses credential kinds
40
+ * (release wave round-16 BLOCK): a subscription→API-key swap silently changes
41
+ * the payment model mid-attempt, and the attempt's first-wins auth-route
42
+ * receipt (decided once before spawn) would misvalue metered usage as
43
+ * subscription entitlement, bypassing a finite cash cap.
44
+ */
45
+ export declare function nextEligibleProfile(registry: readonly CredentialProfile[], harnessId: string, policy: ProfilePolicy, current: Pick<CredentialProfile, "profile_id" | "credential_kind"> | null, snapshots: readonly QuotaSnapshot[], readyProfileIds: ReadonlySet<string>, excluded?: ReadonlySet<string>, model?: string | null): CredentialProfile | null;
46
+ /**
47
+ * `rotation_retry_eligible` (sol #30): a failover retry is allowed ONLY when
48
+ * the attempt saw a TYPED vendor limit AND produced no deliverable and no
49
+ * workspace mutation — a partially-acted attempt never silently reruns.
50
+ */
51
+ export declare function rotationRetryEligible(input: {
52
+ sawTypedLimit: boolean;
53
+ deliverableEmpty: boolean;
54
+ }): boolean;
55
+ type EmitFn = (type: "route.profile.headroom_exceeded" | "route.profile.rotated" | "route.profile.rotation_exhausted", payload: Record<string, unknown>) => void;
56
+ /**
57
+ * `profile_headroom_preflight` (W5.4): BEFORE spawn, the selected profile's
58
+ * freshest quota windows are checked against the policy threshold. A breach
59
+ * is always a typed event; `rotate` swaps to the next eligible profile with
60
+ * provenance, `ask`/`fail` proceed on the selected profile — the runtime
61
+ * `vendor_limit_rejected` evidence stays the terminating truth.
62
+ */
63
+ export declare function preflightCredentialProfile(args: {
64
+ profile: CredentialProfile;
65
+ harnessId: string;
66
+ policy: ProfilePolicy;
67
+ registry: readonly CredentialProfile[];
68
+ snapshots: readonly QuotaSnapshot[];
69
+ readyProfileIds: ReadonlySet<string>;
70
+ model?: string | null;
71
+ emit: EmitFn;
72
+ }): CredentialProfile;
73
+ /**
74
+ * Default-subject start selection (INV-135, owner scope "auto-balance"): when
75
+ * NO profile is pinned, the policy is `rotate`, and the DEFAULT store's own
76
+ * fresh quota window is at/over the headroom bound, pick the first eligible
77
+ * SUBSCRIPTION profile instead of spawning into a near-certain vendor limit.
78
+ * Strictly opt-in: `fail`/`ask` keep today's default-user behavior untouched
79
+ * (the profile engine's fail action governs PINNED profiles only — throwing
80
+ * here would brick every default user at 90% quota). Unknown or stale usage
81
+ * never rotates.
82
+ */
83
+ export declare function preflightDefaultSubject(args: {
84
+ harnessId: string;
85
+ policy: ProfilePolicy;
86
+ registry: readonly CredentialProfile[];
87
+ snapshots: readonly QuotaSnapshot[];
88
+ readyProfileIds: ReadonlySet<string>;
89
+ defaultRoute: "local_session" | "api_key" | null;
90
+ model?: string | null;
91
+ emit: EmitFn;
92
+ }): CredentialProfile | null;
93
+ /**
94
+ * Reactive failover plan (`vendor_limit_rejected`, W5.4): rotation fires ONLY
95
+ * on the typed predicate under a `rotate` policy, marks the current profile
96
+ * tried (at most once per attempt each), and returns the next target with
97
+ * provenance already emitted — or null when the attempt must fail as-is.
98
+ * `currentProfile: null` is the DEFAULT subject: allowed ONLY when the caller
99
+ * proves the attempt's pre-spawn route was vendor_native (a metered default
100
+ * hitting a limit is a budget fact, not a subscription to fail over from).
101
+ */
102
+ export declare function planReactiveRotation(args: {
103
+ currentProfile: CredentialProfile | null;
104
+ defaultRouteWasVendorNative?: boolean;
105
+ harnessId: string;
106
+ attemptId: string;
107
+ policy: ProfilePolicy;
108
+ registry: readonly CredentialProfile[];
109
+ snapshots: readonly QuotaSnapshot[];
110
+ readyProfileIds: ReadonlySet<string>;
111
+ triedProfiles: Set<string>;
112
+ sawTypedLimit: boolean;
113
+ deliverableEmpty: boolean;
114
+ lastLimit: {
115
+ retryDelayMs: number | null;
116
+ resetsAt: string | null;
117
+ } | null;
118
+ model?: string | null;
119
+ emit: EmitFn;
120
+ }): CredentialProfile | null;
121
+ /**
122
+ * Shared reactive-failover step for BOTH lanes: given the attempt's typed
123
+ * evidence, plan a rotation and rebuild the spec on a NEW vendor session
124
+ * under the next profile — or return null when the attempt must fail as-is.
125
+ */
126
+ export declare function rotateSpecOnTypedLimit(args: {
127
+ spec: HarnessRunSpec;
128
+ harnessId: string;
129
+ attemptId: string;
130
+ policy: ProfilePolicy;
131
+ registry: readonly CredentialProfile[];
132
+ snapshots: readonly QuotaSnapshot[];
133
+ readyProfileIds: ReadonlySet<string>;
134
+ triedProfiles: Set<string>;
135
+ sawTypedLimit: boolean;
136
+ deliverableEmpty: boolean;
137
+ lastLimit: {
138
+ retryDelayMs: number | null;
139
+ resetsAt: string | null;
140
+ } | null;
141
+ emit: EmitFn;
142
+ newSessionId: () => string;
143
+ /** Pre-spawn route estimate for a profile-less spec: default-subject
144
+ * rotation is allowed ONLY off a vendor_native attempt. */
145
+ defaultRouteWasVendorNative?: boolean;
146
+ }): HarnessRunSpec | null;
147
+ export {};
148
+ //# sourceMappingURL=credential-profile-rotation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-profile-rotation.d.ts","sourceRoot":"","sources":["../src/credential-profile-rotation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAI1F,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IACxC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,+EAA+E;AAC/E,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC7C,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,iBAAiB,CAAC,GAA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,IAAI,CAAC;IAC3E,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,iBAAiB,GAAG,IAAI,CAyC3B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,IAAI,EAAE,cAAc,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACvC,SAAS,EAAE,SAAS,aAAa,EAAE,CAAC;IACpC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B;+DAC2D;IAC3D,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACvC,GAAG,cAAc,GAAG,IAAI,CAwBxB"}
@@ -0,0 +1,322 @@
1
+ import { HarnessRunSpec as HarnessRunSpecSchema } from "@claudexor/schema";
2
+ import { quotaConstraintAppliesToModel } from "@claudexor/budget";
3
+ /**
4
+ * Static rotation candidates, before any credential-backed readiness probe.
5
+ * One owner applies policy order, enabled/harness scope, current identity,
6
+ * already-tried exclusions, and the payment-kind fence. Callers then probe
7
+ * only identities that could actually be selected.
8
+ */
9
+ export function staticRotationCandidates(args) {
10
+ const pool = args.registry.filter((profile) => profile.harness_id === args.harnessId && profile.enabled);
11
+ const ordered = args.policy.rotation_eligible.length > 0
12
+ ? args.policy.rotation_eligible
13
+ .map((id) => pool.find((profile) => profile.profile_id === id))
14
+ .filter((profile) => profile !== undefined)
15
+ : pool;
16
+ const excluded = args.excluded ?? new Set();
17
+ return ordered.filter((candidate) => {
18
+ if (candidate.profile_id === args.current?.profile_id)
19
+ return false;
20
+ if (excluded.has(candidate.profile_id))
21
+ return false;
22
+ if (args.current !== null && candidate.credential_kind !== args.current.credential_kind) {
23
+ return false;
24
+ }
25
+ // The default subject is vendor-native subscription state; it never probes
26
+ // or rotates into a metered API-key identity.
27
+ if (args.current === null && candidate.credential_kind === "api_key")
28
+ return false;
29
+ return true;
30
+ });
31
+ }
32
+ /**
33
+ * Proactive headroom check (W5.4 `profile_headroom_preflight`): the SELECTED
34
+ * profile's freshest snapshot windows against the policy threshold. Unknown
35
+ * usage is NOT a breach — rotation never triggers on missing data.
36
+ */
37
+ export function profileHeadroomBreach(snapshots, harnessId, profileId, threshold, model) {
38
+ for (const snapshot of snapshots) {
39
+ // FRESH evidence only (release wave tier1 #3): a stale or unknown reading
40
+ // must never breach headroom, rotate a profile away, or fail selection.
41
+ if (snapshot.freshness !== "fresh")
42
+ continue;
43
+ if (snapshot.subject.harness !== harnessId)
44
+ continue;
45
+ if ((snapshot.subject.subject_id ?? null) !== profileId)
46
+ continue;
47
+ for (const constraint of snapshot.constraints) {
48
+ if (!quotaConstraintAppliesToModel(constraint, model))
49
+ continue;
50
+ if (constraint.used_ratio !== null && constraint.used_ratio >= threshold) {
51
+ return {
52
+ constraint_id: constraint.id,
53
+ used_ratio: constraint.used_ratio,
54
+ threshold,
55
+ resets_at: constraint.resets_at,
56
+ };
57
+ }
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ /**
63
+ * The next rotation target after `currentProfileId` (W5.4): policy order wins
64
+ * (`rotation_eligible`), else every enabled profile of the harness in registry
65
+ * order. The current profile and disabled/unknown ids never come back; a
66
+ * profile already over the headroom bound is skipped (rotating INTO a spent
67
+ * subscription is not a failover). Cross-subscription rotation of one vendor
68
+ * is allowed by owner decision — but rotation NEVER crosses credential kinds
69
+ * (release wave round-16 BLOCK): a subscription→API-key swap silently changes
70
+ * the payment model mid-attempt, and the attempt's first-wins auth-route
71
+ * receipt (decided once before spawn) would misvalue metered usage as
72
+ * subscription entitlement, bypassing a finite cash cap.
73
+ */
74
+ export function nextEligibleProfile(registry, harnessId, policy, current, snapshots, readyProfileIds, excluded = new Set(), model) {
75
+ for (const candidate of staticRotationCandidates({
76
+ registry,
77
+ harnessId,
78
+ policy,
79
+ current,
80
+ excluded,
81
+ })) {
82
+ if (!readyProfileIds.has(candidate.profile_id))
83
+ continue;
84
+ if (profileHeadroomBreach(snapshots, harnessId, candidate.profile_id, policy.headroom_threshold, model))
85
+ continue;
86
+ return candidate;
87
+ }
88
+ return null;
89
+ }
90
+ /**
91
+ * `rotation_retry_eligible` (sol #30): a failover retry is allowed ONLY when
92
+ * the attempt saw a TYPED vendor limit AND produced no deliverable and no
93
+ * workspace mutation — a partially-acted attempt never silently reruns.
94
+ */
95
+ export function rotationRetryEligible(input) {
96
+ return input.sawTypedLimit && input.deliverableEmpty;
97
+ }
98
+ function emitRotationExhausted(args) {
99
+ const excluded = args.excluded ?? new Set();
100
+ const candidates = args.registry
101
+ .filter((profile) => profile.harness_id === args.harnessId && profile.enabled)
102
+ .map((profile) => {
103
+ const breach = profileHeadroomBreach(args.snapshots, args.harnessId, profile.profile_id, args.policy.headroom_threshold, args.model);
104
+ const rejected = profile.profile_id === args.current?.profile_id
105
+ ? "current"
106
+ : args.policy.rotation_eligible.length > 0 &&
107
+ !args.policy.rotation_eligible.includes(profile.profile_id)
108
+ ? "not_in_rotation_policy"
109
+ : excluded.has(profile.profile_id)
110
+ ? "already_tried"
111
+ : args.current && profile.credential_kind !== args.current.credential_kind
112
+ ? "credential_kind_mismatch"
113
+ : args.current === null && profile.credential_kind === "api_key"
114
+ ? "credential_kind_mismatch"
115
+ : !args.readyProfileIds.has(profile.profile_id)
116
+ ? "not_ready"
117
+ : breach
118
+ ? "headroom_exceeded"
119
+ : "not_selected";
120
+ return {
121
+ profile_id: profile.profile_id,
122
+ credential_kind: profile.credential_kind,
123
+ rejected,
124
+ headroom: breach,
125
+ };
126
+ });
127
+ args.emit("route.profile.rotation_exhausted", {
128
+ harness_id: args.harnessId,
129
+ attempt_id: args.attemptId,
130
+ from_profile_id: args.current?.profile_id ?? null,
131
+ reason: args.reason,
132
+ threshold: args.policy.headroom_threshold,
133
+ candidates,
134
+ });
135
+ }
136
+ /**
137
+ * `profile_headroom_preflight` (W5.4): BEFORE spawn, the selected profile's
138
+ * freshest quota windows are checked against the policy threshold. A breach
139
+ * is always a typed event; `rotate` swaps to the next eligible profile with
140
+ * provenance, `ask`/`fail` proceed on the selected profile — the runtime
141
+ * `vendor_limit_rejected` evidence stays the terminating truth.
142
+ */
143
+ export function preflightCredentialProfile(args) {
144
+ const { profile, harnessId, policy, registry, snapshots, readyProfileIds, model, emit } = args;
145
+ const breach = profileHeadroomBreach(snapshots, harnessId, profile.profile_id, policy.headroom_threshold, model);
146
+ if (!breach)
147
+ return profile;
148
+ emit("route.profile.headroom_exceeded", {
149
+ harness_id: harnessId,
150
+ profile_id: profile.profile_id,
151
+ action: policy.limit_action,
152
+ constraint_id: breach.constraint_id,
153
+ used_ratio: breach.used_ratio,
154
+ threshold: breach.threshold,
155
+ resets_at: breach.resets_at,
156
+ });
157
+ if (policy.limit_action === "fail") {
158
+ // The documented FAIL action fails (release wave tier1 #4): a FRESH breach
159
+ // under fail refuses before spawn with the evidence, instead of silently
160
+ // proceeding into a vendor rejection.
161
+ throw new Error(`credential profile "${profile.profile_id}" (${harnessId}) is over its headroom threshold ` +
162
+ `(${breach.constraint_id} at ${Math.round(breach.used_ratio * 100)}% >= ${Math.round(breach.threshold * 100)}%; ` +
163
+ `limit_action=fail${breach.resets_at ? `; resets ${breach.resets_at}` : ""})`);
164
+ }
165
+ if (policy.limit_action !== "rotate")
166
+ return profile;
167
+ const next = nextEligibleProfile(registry, harnessId, policy, profile, snapshots, readyProfileIds, new Set(), model);
168
+ if (!next) {
169
+ emitRotationExhausted({
170
+ current: profile,
171
+ harnessId,
172
+ policy,
173
+ registry,
174
+ snapshots,
175
+ readyProfileIds,
176
+ model,
177
+ reason: "profile_headroom_preflight",
178
+ emit,
179
+ });
180
+ return profile;
181
+ }
182
+ emit("route.profile.rotated", {
183
+ harness_id: harnessId,
184
+ from_profile_id: profile.profile_id,
185
+ to_profile_id: next.profile_id,
186
+ reason: "profile_headroom_preflight",
187
+ constraint_id: breach.constraint_id,
188
+ used_ratio: breach.used_ratio,
189
+ resets_at: breach.resets_at,
190
+ });
191
+ return next;
192
+ }
193
+ /**
194
+ * Default-subject start selection (INV-135, owner scope "auto-balance"): when
195
+ * NO profile is pinned, the policy is `rotate`, and the DEFAULT store's own
196
+ * fresh quota window is at/over the headroom bound, pick the first eligible
197
+ * SUBSCRIPTION profile instead of spawning into a near-certain vendor limit.
198
+ * Strictly opt-in: `fail`/`ask` keep today's default-user behavior untouched
199
+ * (the profile engine's fail action governs PINNED profiles only — throwing
200
+ * here would brick every default user at 90% quota). Unknown or stale usage
201
+ * never rotates.
202
+ */
203
+ export function preflightDefaultSubject(args) {
204
+ const { harnessId, policy, registry, snapshots, readyProfileIds, defaultRoute, model, emit } = args;
205
+ if (policy.limit_action !== "rotate" || defaultRoute !== "local_session")
206
+ return null;
207
+ const breach = profileHeadroomBreach(snapshots, harnessId, null, policy.headroom_threshold, model);
208
+ if (!breach)
209
+ return null;
210
+ emit("route.profile.headroom_exceeded", {
211
+ harness_id: harnessId,
212
+ profile_id: null,
213
+ action: policy.limit_action,
214
+ constraint_id: breach.constraint_id,
215
+ used_ratio: breach.used_ratio,
216
+ threshold: breach.threshold,
217
+ resets_at: breach.resets_at,
218
+ });
219
+ const next = nextEligibleProfile(registry, harnessId, policy, null, snapshots, readyProfileIds, new Set(), model);
220
+ if (!next) {
221
+ emitRotationExhausted({
222
+ current: null,
223
+ harnessId,
224
+ policy,
225
+ registry,
226
+ snapshots,
227
+ readyProfileIds,
228
+ model,
229
+ reason: "profile_headroom_preflight",
230
+ emit,
231
+ });
232
+ return null;
233
+ }
234
+ emit("route.profile.rotated", {
235
+ harness_id: harnessId,
236
+ from_profile_id: null,
237
+ to_profile_id: next.profile_id,
238
+ reason: "profile_headroom_preflight",
239
+ constraint_id: breach.constraint_id,
240
+ used_ratio: breach.used_ratio,
241
+ resets_at: breach.resets_at,
242
+ });
243
+ return next;
244
+ }
245
+ /**
246
+ * Reactive failover plan (`vendor_limit_rejected`, W5.4): rotation fires ONLY
247
+ * on the typed predicate under a `rotate` policy, marks the current profile
248
+ * tried (at most once per attempt each), and returns the next target with
249
+ * provenance already emitted — or null when the attempt must fail as-is.
250
+ * `currentProfile: null` is the DEFAULT subject: allowed ONLY when the caller
251
+ * proves the attempt's pre-spawn route was vendor_native (a metered default
252
+ * hitting a limit is a budget fact, not a subscription to fail over from).
253
+ */
254
+ export function planReactiveRotation(args) {
255
+ if (!rotationRetryEligible(args))
256
+ return null;
257
+ if (args.policy.limit_action !== "rotate")
258
+ return null;
259
+ if (args.currentProfile === null && args.defaultRouteWasVendorNative !== true)
260
+ return null;
261
+ if (args.currentProfile)
262
+ args.triedProfiles.add(args.currentProfile.profile_id);
263
+ const next = nextEligibleProfile(args.registry, args.harnessId, args.policy, args.currentProfile, args.snapshots, args.readyProfileIds, args.triedProfiles, args.model);
264
+ if (!next) {
265
+ emitRotationExhausted({
266
+ current: args.currentProfile,
267
+ harnessId: args.harnessId,
268
+ policy: args.policy,
269
+ registry: args.registry,
270
+ snapshots: args.snapshots,
271
+ readyProfileIds: args.readyProfileIds,
272
+ excluded: args.triedProfiles,
273
+ attemptId: args.attemptId,
274
+ model: args.model,
275
+ reason: "vendor_limit_rejected",
276
+ emit: args.emit,
277
+ });
278
+ return null;
279
+ }
280
+ args.emit("route.profile.rotated", {
281
+ harness_id: args.harnessId,
282
+ attempt_id: args.attemptId,
283
+ from_profile_id: args.currentProfile?.profile_id ?? null,
284
+ to_profile_id: next.profile_id,
285
+ reason: "vendor_limit_rejected",
286
+ retry_delay_ms: args.lastLimit?.retryDelayMs ?? null,
287
+ resets_at: args.lastLimit?.resetsAt ?? null,
288
+ });
289
+ return next;
290
+ }
291
+ /**
292
+ * Shared reactive-failover step for BOTH lanes: given the attempt's typed
293
+ * evidence, plan a rotation and rebuild the spec on a NEW vendor session
294
+ * under the next profile — or return null when the attempt must fail as-is.
295
+ */
296
+ export function rotateSpecOnTypedLimit(args) {
297
+ const rotation = planReactiveRotation({
298
+ currentProfile: args.spec.credential_profile ?? null,
299
+ defaultRouteWasVendorNative: args.defaultRouteWasVendorNative,
300
+ harnessId: args.harnessId,
301
+ attemptId: args.attemptId,
302
+ policy: args.policy,
303
+ registry: args.registry,
304
+ snapshots: args.snapshots,
305
+ readyProfileIds: args.readyProfileIds,
306
+ triedProfiles: args.triedProfiles,
307
+ sawTypedLimit: args.sawTypedLimit,
308
+ deliverableEmpty: args.deliverableEmpty,
309
+ lastLimit: args.lastLimit,
310
+ model: args.spec.model_hint,
311
+ emit: args.emit,
312
+ });
313
+ if (!rotation)
314
+ return null;
315
+ return HarnessRunSpecSchema.parse({
316
+ ...args.spec,
317
+ session_id: args.newSessionId(),
318
+ credential_profile: rotation,
319
+ resume_session_id: null,
320
+ });
321
+ }
322
+ //# sourceMappingURL=credential-profile-rotation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-profile-rotation.js","sourceRoot":"","sources":["../src/credential-profile-rotation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAgBlE;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAMxC;IACC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAC/B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,KAAK,IAAI,CAAC,SAAS,IAAI,O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