@claudexor/orchestrator 3.1.1 → 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.
- package/dist/attemptFinalize.d.ts +14 -11
- package/dist/attemptFinalize.d.ts.map +1 -1
- package/dist/attemptFinalize.js +41 -14
- package/dist/attemptFinalize.js.map +1 -1
- package/dist/attemptTelemetry.d.ts +16 -20
- package/dist/attemptTelemetry.d.ts.map +1 -1
- package/dist/attemptTelemetry.js +38 -70
- package/dist/attemptTelemetry.js.map +1 -1
- package/dist/attemptUsageCost.d.ts +47 -0
- package/dist/attemptUsageCost.d.ts.map +1 -0
- package/dist/attemptUsageCost.js +191 -0
- package/dist/attemptUsageCost.js.map +1 -0
- package/dist/budgetFailure.d.ts +3 -1
- package/dist/budgetFailure.d.ts.map +1 -1
- package/dist/budgetFailure.js.map +1 -1
- package/dist/candidateEvidence.d.ts +5 -0
- package/dist/candidateEvidence.d.ts.map +1 -1
- package/dist/candidateEvidence.js +3 -1
- package/dist/candidateEvidence.js.map +1 -1
- package/dist/candidateOutputs.d.ts +19 -0
- package/dist/candidateOutputs.d.ts.map +1 -1
- package/dist/candidateOutputs.js +201 -67
- package/dist/candidateOutputs.js.map +1 -1
- package/dist/credential-profile-rotation.d.ts +145 -0
- package/dist/credential-profile-rotation.d.ts.map +1 -0
- package/dist/credential-profile-rotation.js +315 -0
- package/dist/credential-profile-rotation.js.map +1 -0
- package/dist/credential-profiles.d.ts +35 -134
- package/dist/credential-profiles.d.ts.map +1 -1
- package/dist/credential-profiles.js +73 -295
- package/dist/credential-profiles.js.map +1 -1
- package/dist/decisionBudget.d.ts +43 -0
- package/dist/decisionBudget.d.ts.map +1 -0
- package/dist/decisionBudget.js +84 -0
- package/dist/decisionBudget.js.map +1 -0
- package/dist/decisionTerminalReconciliation.d.ts +18 -0
- package/dist/decisionTerminalReconciliation.d.ts.map +1 -0
- package/dist/decisionTerminalReconciliation.js +26 -0
- package/dist/decisionTerminalReconciliation.js.map +1 -0
- package/dist/deepScanReducer.d.ts +14 -44
- package/dist/deepScanReducer.d.ts.map +1 -1
- package/dist/deepScanReducer.js +240 -128
- package/dist/deepScanReducer.js.map +1 -1
- package/dist/delegation-parent-activation.d.ts +6 -0
- package/dist/delegation-parent-activation.d.ts.map +1 -0
- package/dist/delegation-parent-activation.js +13 -0
- package/dist/delegation-parent-activation.js.map +1 -0
- package/dist/delegationBudgetAuthority.d.ts +30 -0
- package/dist/delegationBudgetAuthority.d.ts.map +1 -0
- package/dist/delegationBudgetAuthority.js +157 -0
- package/dist/delegationBudgetAuthority.js.map +1 -0
- package/dist/delegationFailure.d.ts +58 -0
- package/dist/delegationFailure.d.ts.map +1 -0
- package/dist/delegationFailure.js +184 -0
- package/dist/delegationFailure.js.map +1 -0
- package/dist/delegationToolEvidence.d.ts +20 -0
- package/dist/delegationToolEvidence.d.ts.map +1 -0
- package/dist/delegationToolEvidence.js +46 -0
- package/dist/delegationToolEvidence.js.map +1 -0
- package/dist/git-precondition.d.ts +11 -0
- package/dist/git-precondition.d.ts.map +1 -0
- package/dist/git-precondition.js +69 -0
- package/dist/git-precondition.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +14 -6
- package/dist/interaction.d.ts.map +1 -1
- package/dist/interaction.js +106 -19
- package/dist/interaction.js.map +1 -1
- package/dist/orchestrator.d.ts +62 -115
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +671 -965
- package/dist/orchestrator.js.map +1 -1
- package/dist/plan-prompt.d.ts +3 -0
- package/dist/plan-prompt.d.ts.map +1 -0
- package/dist/plan-prompt.js +28 -0
- package/dist/plan-prompt.js.map +1 -0
- package/dist/planBrief.d.ts +27 -0
- package/dist/planBrief.d.ts.map +1 -0
- package/dist/planBrief.js +42 -0
- package/dist/planBrief.js.map +1 -0
- package/dist/planRun.d.ts +4 -3
- package/dist/planRun.d.ts.map +1 -1
- package/dist/planRun.js +33 -33
- package/dist/planRun.js.map +1 -1
- package/dist/plannerAttempt.d.ts +64 -0
- package/dist/plannerAttempt.d.ts.map +1 -0
- package/dist/plannerAttempt.js +235 -0
- package/dist/plannerAttempt.js.map +1 -0
- package/dist/policyFindings.js.map +1 -1
- package/dist/requestRequirements.d.ts +45 -1
- package/dist/requestRequirements.d.ts.map +1 -1
- package/dist/requestRequirements.js +158 -11
- package/dist/requestRequirements.js.map +1 -1
- package/dist/reviewerPanel.js.map +1 -1
- package/dist/root-ledger.d.ts +13 -0
- package/dist/root-ledger.d.ts.map +1 -0
- package/dist/root-ledger.js +21 -0
- package/dist/root-ledger.js.map +1 -0
- package/dist/routing-failure.d.ts +6 -0
- package/dist/routing-failure.d.ts.map +1 -0
- package/dist/routing-failure.js +12 -0
- package/dist/routing-failure.js.map +1 -0
- package/dist/run-bounded.d.ts +3 -0
- package/dist/run-bounded.d.ts.map +1 -0
- package/dist/run-bounded.js +23 -0
- package/dist/run-bounded.js.map +1 -0
- package/dist/run-input-resolution.d.ts +10 -0
- package/dist/run-input-resolution.d.ts.map +1 -0
- package/dist/run-input-resolution.js +88 -0
- package/dist/run-input-resolution.js.map +1 -0
- package/dist/runEventLog.d.ts +48 -0
- package/dist/runEventLog.d.ts.map +1 -0
- package/dist/runEventLog.js +63 -0
- package/dist/runEventLog.js.map +1 -0
- package/dist/runFacts.d.ts +23 -0
- package/dist/runFacts.d.ts.map +1 -0
- package/dist/runFacts.js +179 -0
- package/dist/runFacts.js.map +1 -0
- package/dist/runFactsBuilder.d.ts +5 -0
- package/dist/runFactsBuilder.d.ts.map +1 -0
- package/dist/runFactsBuilder.js +412 -0
- package/dist/runFactsBuilder.js.map +1 -0
- package/dist/runFactsDeliverable.d.ts +13 -0
- package/dist/runFactsDeliverable.d.ts.map +1 -0
- package/dist/runFactsDeliverable.js +94 -0
- package/dist/runFactsDeliverable.js.map +1 -0
- package/dist/runFactsPresentation.d.ts +7 -0
- package/dist/runFactsPresentation.d.ts.map +1 -0
- package/dist/runFactsPresentation.js +113 -0
- package/dist/runFactsPresentation.js.map +1 -0
- package/dist/runFactsReview.d.ts +7 -0
- package/dist/runFactsReview.d.ts.map +1 -0
- package/dist/runFactsReview.js +63 -0
- package/dist/runFactsReview.js.map +1 -0
- package/dist/runSupport.d.ts +17 -15
- package/dist/runSupport.d.ts.map +1 -1
- package/dist/runSupport.js +16 -0
- package/dist/runSupport.js.map +1 -1
- package/dist/runTelemetryWriter.d.ts +5 -2
- package/dist/runTelemetryWriter.d.ts.map +1 -1
- package/dist/runTelemetryWriter.js +72 -1
- package/dist/runTelemetryWriter.js.map +1 -1
- package/dist/runTerminalContext.d.ts +31 -0
- package/dist/runTerminalContext.d.ts.map +1 -0
- package/dist/runTerminalContext.js +12 -0
- package/dist/runTerminalContext.js.map +1 -0
- package/dist/runTerminalResults.d.ts +55 -0
- package/dist/runTerminalResults.d.ts.map +1 -0
- package/dist/runTerminalResults.js +134 -0
- package/dist/runTerminalResults.js.map +1 -0
- package/dist/runTerminals.d.ts +8 -57
- package/dist/runTerminals.d.ts.map +1 -1
- package/dist/runTerminals.js +423 -135
- package/dist/runTerminals.js.map +1 -1
- package/dist/secretDiff.d.ts +32 -0
- package/dist/secretDiff.d.ts.map +1 -0
- package/dist/secretDiff.js +140 -0
- package/dist/secretDiff.js.map +1 -0
- package/dist/structuredOutput.d.ts.map +1 -1
- package/dist/structuredOutput.js.map +1 -1
- package/dist/task-contract-builder.d.ts +35 -0
- package/dist/task-contract-builder.d.ts.map +1 -0
- package/dist/task-contract-builder.js +114 -0
- package/dist/task-contract-builder.js.map +1 -0
- package/dist/terminalOutcome.d.ts +22 -0
- package/dist/terminalOutcome.d.ts.map +1 -0
- package/dist/terminalOutcome.js +39 -0
- package/dist/terminalOutcome.js.map +1 -0
- package/dist/transientClassify.js.map +1 -1
- package/package.json +17 -17
|
@@ -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,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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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"credential-profiles.d.ts","sourceRoot":"","sources":["../src/credential-profiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,aAAa,EACd,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,KAAK,aAAa,GACnB,MAAM,kCAAkC,CAAC;AA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