@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
@@ -0,0 +1,145 @@
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): 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>): 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
+ emit: EmitFn;
71
+ }): CredentialProfile;
72
+ /**
73
+ * Default-subject start selection (INV-135, owner scope "auto-balance"): when
74
+ * NO profile is pinned, the policy is `rotate`, and the DEFAULT store's own
75
+ * fresh quota window is at/over the headroom bound, pick the first eligible
76
+ * SUBSCRIPTION profile instead of spawning into a near-certain vendor limit.
77
+ * Strictly opt-in: `fail`/`ask` keep today's default-user behavior untouched
78
+ * (the profile engine's fail action governs PINNED profiles only — throwing
79
+ * here would brick every default user at 90% quota). Unknown or stale usage
80
+ * never rotates.
81
+ */
82
+ export declare function preflightDefaultSubject(args: {
83
+ harnessId: string;
84
+ policy: ProfilePolicy;
85
+ registry: readonly CredentialProfile[];
86
+ snapshots: readonly QuotaSnapshot[];
87
+ readyProfileIds: ReadonlySet<string>;
88
+ defaultRoute: "local_session" | "api_key" | null;
89
+ emit: EmitFn;
90
+ }): CredentialProfile | null;
91
+ /**
92
+ * Reactive failover plan (`vendor_limit_rejected`, W5.4): rotation fires ONLY
93
+ * on the typed predicate under a `rotate` policy, marks the current profile
94
+ * tried (at most once per attempt each), and returns the next target with
95
+ * provenance already emitted — or null when the attempt must fail as-is.
96
+ * `currentProfile: null` is the DEFAULT subject: allowed ONLY when the caller
97
+ * proves the attempt's pre-spawn route was vendor_native (a metered default
98
+ * hitting a limit is a budget fact, not a subscription to fail over from).
99
+ */
100
+ export declare function planReactiveRotation(args: {
101
+ currentProfile: CredentialProfile | null;
102
+ defaultRouteWasVendorNative?: boolean;
103
+ harnessId: string;
104
+ attemptId: string;
105
+ policy: ProfilePolicy;
106
+ registry: readonly CredentialProfile[];
107
+ snapshots: readonly QuotaSnapshot[];
108
+ readyProfileIds: ReadonlySet<string>;
109
+ triedProfiles: Set<string>;
110
+ sawTypedLimit: boolean;
111
+ deliverableEmpty: boolean;
112
+ lastLimit: {
113
+ retryDelayMs: number | null;
114
+ resetsAt: string | null;
115
+ } | null;
116
+ emit: EmitFn;
117
+ }): CredentialProfile | null;
118
+ /**
119
+ * Shared reactive-failover step for BOTH lanes: given the attempt's typed
120
+ * evidence, plan a rotation and rebuild the spec on a NEW vendor session
121
+ * under the next profile — or return null when the attempt must fail as-is.
122
+ */
123
+ export declare function rotateSpecOnTypedLimit(args: {
124
+ spec: HarnessRunSpec;
125
+ harnessId: string;
126
+ attemptId: string;
127
+ policy: ProfilePolicy;
128
+ registry: readonly CredentialProfile[];
129
+ snapshots: readonly QuotaSnapshot[];
130
+ readyProfileIds: ReadonlySet<string>;
131
+ triedProfiles: Set<string>;
132
+ sawTypedLimit: boolean;
133
+ deliverableEmpty: boolean;
134
+ lastLimit: {
135
+ retryDelayMs: number | null;
136
+ resetsAt: string | null;
137
+ } | null;
138
+ emit: EmitFn;
139
+ newSessionId: () => string;
140
+ /** Pre-spawn route estimate for a profile-less spec: default-subject
141
+ * rotation is allowed ONLY off a vendor_native attempt. */
142
+ defaultRouteWasVendorNative?: boolean;
143
+ }): HarnessRunSpec | null;
144
+ export {};
145
+ //# 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;AAG1F,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,GAAG,IAAI,CAAC;IAC1E,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAChC,GAAG,iBAAiB,EAAE,CAsBtB;AAED;;;;GAIG;AACH,wBAA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,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,CAuBxB"}
@@ -0,0 +1,315 @@
1
+ import { HarnessRunSpec as HarnessRunSpecSchema } from "@claudexor/schema";
2
+ /**
3
+ * Static rotation candidates, before any credential-backed readiness probe.
4
+ * One owner applies policy order, enabled/harness scope, current identity,
5
+ * already-tried exclusions, and the payment-kind fence. Callers then probe
6
+ * only identities that could actually be selected.
7
+ */
8
+ export function staticRotationCandidates(args) {
9
+ const pool = args.registry.filter((profile) => profile.harness_id === args.harnessId && profile.enabled);
10
+ const ordered = args.policy.rotation_eligible.length > 0
11
+ ? args.policy.rotation_eligible
12
+ .map((id) => pool.find((profile) => profile.profile_id === id))
13
+ .filter((profile) => profile !== undefined)
14
+ : pool;
15
+ const excluded = args.excluded ?? new Set();
16
+ return ordered.filter((candidate) => {
17
+ if (candidate.profile_id === args.current?.profile_id)
18
+ return false;
19
+ if (excluded.has(candidate.profile_id))
20
+ return false;
21
+ if (args.current !== null && candidate.credential_kind !== args.current.credential_kind) {
22
+ return false;
23
+ }
24
+ // The default subject is vendor-native subscription state; it never probes
25
+ // or rotates into a metered API-key identity.
26
+ if (args.current === null && candidate.credential_kind === "api_key")
27
+ return false;
28
+ return true;
29
+ });
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 function profileHeadroomBreach(snapshots, harnessId, profileId, threshold) {
37
+ for (const snapshot of snapshots) {
38
+ // FRESH evidence only (release wave tier1 #3): a stale or unknown reading
39
+ // must never breach headroom, rotate a profile away, or fail selection.
40
+ if (snapshot.freshness !== "fresh")
41
+ continue;
42
+ if (snapshot.subject.harness !== harnessId)
43
+ continue;
44
+ if ((snapshot.subject.subject_id ?? null) !== profileId)
45
+ continue;
46
+ for (const constraint of snapshot.constraints) {
47
+ if (constraint.used_ratio !== null && constraint.used_ratio >= threshold) {
48
+ return {
49
+ constraint_id: constraint.id,
50
+ used_ratio: constraint.used_ratio,
51
+ threshold,
52
+ resets_at: constraint.resets_at,
53
+ };
54
+ }
55
+ }
56
+ }
57
+ return null;
58
+ }
59
+ /**
60
+ * The next rotation target after `currentProfileId` (W5.4): policy order wins
61
+ * (`rotation_eligible`), else every enabled profile of the harness in registry
62
+ * order. The current profile and disabled/unknown ids never come back; a
63
+ * profile already over the headroom bound is skipped (rotating INTO a spent
64
+ * subscription is not a failover). Cross-subscription rotation of one vendor
65
+ * is allowed by owner decision — but rotation NEVER crosses credential kinds
66
+ * (release wave round-16 BLOCK): a subscription→API-key swap silently changes
67
+ * the payment model mid-attempt, and the attempt's first-wins auth-route
68
+ * receipt (decided once before spawn) would misvalue metered usage as
69
+ * subscription entitlement, bypassing a finite cash cap.
70
+ */
71
+ export function nextEligibleProfile(registry, harnessId, policy, current, snapshots, readyProfileIds, excluded = new Set()) {
72
+ for (const candidate of staticRotationCandidates({
73
+ registry,
74
+ harnessId,
75
+ policy,
76
+ current,
77
+ excluded,
78
+ })) {
79
+ if (!readyProfileIds.has(candidate.profile_id))
80
+ continue;
81
+ if (profileHeadroomBreach(snapshots, harnessId, candidate.profile_id, policy.headroom_threshold))
82
+ continue;
83
+ return candidate;
84
+ }
85
+ return null;
86
+ }
87
+ /**
88
+ * `rotation_retry_eligible` (sol #30): a failover retry is allowed ONLY when
89
+ * the attempt saw a TYPED vendor limit AND produced no deliverable and no
90
+ * workspace mutation — a partially-acted attempt never silently reruns.
91
+ */
92
+ export function rotationRetryEligible(input) {
93
+ return input.sawTypedLimit && input.deliverableEmpty;
94
+ }
95
+ function emitRotationExhausted(args) {
96
+ const excluded = args.excluded ?? new Set();
97
+ const candidates = args.registry
98
+ .filter((profile) => profile.harness_id === args.harnessId && profile.enabled)
99
+ .map((profile) => {
100
+ const breach = profileHeadroomBreach(args.snapshots, args.harnessId, profile.profile_id, args.policy.headroom_threshold);
101
+ const rejected = profile.profile_id === args.current?.profile_id
102
+ ? "current"
103
+ : args.policy.rotation_eligible.length > 0 &&
104
+ !args.policy.rotation_eligible.includes(profile.profile_id)
105
+ ? "not_in_rotation_policy"
106
+ : excluded.has(profile.profile_id)
107
+ ? "already_tried"
108
+ : args.current && profile.credential_kind !== args.current.credential_kind
109
+ ? "credential_kind_mismatch"
110
+ : args.current === null && profile.credential_kind === "api_key"
111
+ ? "credential_kind_mismatch"
112
+ : !args.readyProfileIds.has(profile.profile_id)
113
+ ? "not_ready"
114
+ : breach
115
+ ? "headroom_exceeded"
116
+ : "not_selected";
117
+ return {
118
+ profile_id: profile.profile_id,
119
+ credential_kind: profile.credential_kind,
120
+ rejected,
121
+ headroom: breach,
122
+ };
123
+ });
124
+ args.emit("route.profile.rotation_exhausted", {
125
+ harness_id: args.harnessId,
126
+ attempt_id: args.attemptId,
127
+ from_profile_id: args.current?.profile_id ?? null,
128
+ reason: args.reason,
129
+ threshold: args.policy.headroom_threshold,
130
+ candidates,
131
+ });
132
+ }
133
+ /**
134
+ * `profile_headroom_preflight` (W5.4): BEFORE spawn, the selected profile's
135
+ * freshest quota windows are checked against the policy threshold. A breach
136
+ * is always a typed event; `rotate` swaps to the next eligible profile with
137
+ * provenance, `ask`/`fail` proceed on the selected profile — the runtime
138
+ * `vendor_limit_rejected` evidence stays the terminating truth.
139
+ */
140
+ export function preflightCredentialProfile(args) {
141
+ const { profile, harnessId, policy, registry, snapshots, readyProfileIds, emit } = args;
142
+ const breach = profileHeadroomBreach(snapshots, harnessId, profile.profile_id, policy.headroom_threshold);
143
+ if (!breach)
144
+ return profile;
145
+ emit("route.profile.headroom_exceeded", {
146
+ harness_id: harnessId,
147
+ profile_id: profile.profile_id,
148
+ action: policy.limit_action,
149
+ constraint_id: breach.constraint_id,
150
+ used_ratio: breach.used_ratio,
151
+ threshold: breach.threshold,
152
+ resets_at: breach.resets_at,
153
+ });
154
+ if (policy.limit_action === "fail") {
155
+ // The documented FAIL action fails (release wave tier1 #4): a FRESH breach
156
+ // under fail refuses before spawn with the evidence, instead of silently
157
+ // proceeding into a vendor rejection.
158
+ throw new Error(`credential profile "${profile.profile_id}" (${harnessId}) is over its headroom threshold ` +
159
+ `(${breach.constraint_id} at ${Math.round(breach.used_ratio * 100)}% >= ${Math.round(breach.threshold * 100)}%; ` +
160
+ `limit_action=fail${breach.resets_at ? `; resets ${breach.resets_at}` : ""})`);
161
+ }
162
+ if (policy.limit_action !== "rotate")
163
+ return profile;
164
+ const next = nextEligibleProfile(registry, harnessId, policy, profile, snapshots, readyProfileIds);
165
+ if (!next) {
166
+ emitRotationExhausted({
167
+ current: profile,
168
+ harnessId,
169
+ policy,
170
+ registry,
171
+ snapshots,
172
+ readyProfileIds,
173
+ reason: "profile_headroom_preflight",
174
+ emit,
175
+ });
176
+ return profile;
177
+ }
178
+ emit("route.profile.rotated", {
179
+ harness_id: harnessId,
180
+ from_profile_id: profile.profile_id,
181
+ to_profile_id: next.profile_id,
182
+ reason: "profile_headroom_preflight",
183
+ constraint_id: breach.constraint_id,
184
+ used_ratio: breach.used_ratio,
185
+ resets_at: breach.resets_at,
186
+ });
187
+ return next;
188
+ }
189
+ /**
190
+ * Default-subject start selection (INV-135, owner scope "auto-balance"): when
191
+ * NO profile is pinned, the policy is `rotate`, and the DEFAULT store's own
192
+ * fresh quota window is at/over the headroom bound, pick the first eligible
193
+ * SUBSCRIPTION profile instead of spawning into a near-certain vendor limit.
194
+ * Strictly opt-in: `fail`/`ask` keep today's default-user behavior untouched
195
+ * (the profile engine's fail action governs PINNED profiles only — throwing
196
+ * here would brick every default user at 90% quota). Unknown or stale usage
197
+ * never rotates.
198
+ */
199
+ export function preflightDefaultSubject(args) {
200
+ const { harnessId, policy, registry, snapshots, readyProfileIds, defaultRoute, emit } = args;
201
+ if (policy.limit_action !== "rotate" || defaultRoute !== "local_session")
202
+ return null;
203
+ const breach = profileHeadroomBreach(snapshots, harnessId, null, policy.headroom_threshold);
204
+ if (!breach)
205
+ return null;
206
+ emit("route.profile.headroom_exceeded", {
207
+ harness_id: harnessId,
208
+ profile_id: null,
209
+ action: policy.limit_action,
210
+ constraint_id: breach.constraint_id,
211
+ used_ratio: breach.used_ratio,
212
+ threshold: breach.threshold,
213
+ resets_at: breach.resets_at,
214
+ });
215
+ const next = nextEligibleProfile(registry, harnessId, policy, null, snapshots, readyProfileIds);
216
+ if (!next) {
217
+ emitRotationExhausted({
218
+ current: null,
219
+ harnessId,
220
+ policy,
221
+ registry,
222
+ snapshots,
223
+ readyProfileIds,
224
+ reason: "profile_headroom_preflight",
225
+ emit,
226
+ });
227
+ return null;
228
+ }
229
+ emit("route.profile.rotated", {
230
+ harness_id: harnessId,
231
+ from_profile_id: null,
232
+ to_profile_id: next.profile_id,
233
+ reason: "profile_headroom_preflight",
234
+ constraint_id: breach.constraint_id,
235
+ used_ratio: breach.used_ratio,
236
+ resets_at: breach.resets_at,
237
+ });
238
+ return next;
239
+ }
240
+ /**
241
+ * Reactive failover plan (`vendor_limit_rejected`, W5.4): rotation fires ONLY
242
+ * on the typed predicate under a `rotate` policy, marks the current profile
243
+ * tried (at most once per attempt each), and returns the next target with
244
+ * provenance already emitted — or null when the attempt must fail as-is.
245
+ * `currentProfile: null` is the DEFAULT subject: allowed ONLY when the caller
246
+ * proves the attempt's pre-spawn route was vendor_native (a metered default
247
+ * hitting a limit is a budget fact, not a subscription to fail over from).
248
+ */
249
+ export function planReactiveRotation(args) {
250
+ if (!rotationRetryEligible(args))
251
+ return null;
252
+ if (args.policy.limit_action !== "rotate")
253
+ return null;
254
+ if (args.currentProfile === null && args.defaultRouteWasVendorNative !== true)
255
+ return null;
256
+ if (args.currentProfile)
257
+ args.triedProfiles.add(args.currentProfile.profile_id);
258
+ const next = nextEligibleProfile(args.registry, args.harnessId, args.policy, args.currentProfile, args.snapshots, args.readyProfileIds, args.triedProfiles);
259
+ if (!next) {
260
+ emitRotationExhausted({
261
+ current: args.currentProfile,
262
+ harnessId: args.harnessId,
263
+ policy: args.policy,
264
+ registry: args.registry,
265
+ snapshots: args.snapshots,
266
+ readyProfileIds: args.readyProfileIds,
267
+ excluded: args.triedProfiles,
268
+ attemptId: args.attemptId,
269
+ reason: "vendor_limit_rejected",
270
+ emit: args.emit,
271
+ });
272
+ return null;
273
+ }
274
+ args.emit("route.profile.rotated", {
275
+ harness_id: args.harnessId,
276
+ attempt_id: args.attemptId,
277
+ from_profile_id: args.currentProfile?.profile_id ?? null,
278
+ to_profile_id: next.profile_id,
279
+ reason: "vendor_limit_rejected",
280
+ retry_delay_ms: args.lastLimit?.retryDelayMs ?? null,
281
+ resets_at: args.lastLimit?.resetsAt ?? null,
282
+ });
283
+ return next;
284
+ }
285
+ /**
286
+ * Shared reactive-failover step for BOTH lanes: given the attempt's typed
287
+ * evidence, plan a rotation and rebuild the spec on a NEW vendor session
288
+ * under the next profile — or return null when the attempt must fail as-is.
289
+ */
290
+ export function rotateSpecOnTypedLimit(args) {
291
+ const rotation = planReactiveRotation({
292
+ currentProfile: args.spec.credential_profile ?? null,
293
+ defaultRouteWasVendorNative: args.defaultRouteWasVendorNative,
294
+ harnessId: args.harnessId,
295
+ attemptId: args.attemptId,
296
+ policy: args.policy,
297
+ registry: args.registry,
298
+ snapshots: args.snapshots,
299
+ readyProfileIds: args.readyProfileIds,
300
+ triedProfiles: args.triedProfiles,
301
+ sawTypedLimit: args.sawTypedLimit,
302
+ deliverableEmpty: args.deliverableEmpty,
303
+ lastLimit: args.lastLimit,
304
+ emit: args.emit,
305
+ });
306
+ if (!rotation)
307
+ return null;
308
+ return HarnessRunSpecSchema.parse({
309
+ ...args.spec,
310
+ session_id: args.newSessionId(),
311
+ credential_profile: rotation,
312
+ resume_session_id: null,
313
+ });
314
+ }
315
+ //# 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;AAgB3E;;;;;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,OAAO,CAAC,OAAO,CACtE,CAAC;IACF,MAAM,OAAO,GACX,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC;QACtC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB;aAC1B,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;aAC9D,MAAM,CAAC,CAAC,OAAO,EAAgC,EAAE,CAAC,OAAO,KAAK,SAAS,CAAC;QAC7E,CAAC,CAAC,IAAI,CAAC;IACX,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,GAAG,EAAU,CAAC;IACpD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QAClC,IAAI,SAAS,CAAC,UAAU,KAAK,IAAI,CAAC,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