refactor: introduce AgentTriggerReason type union as SSOT for error reason strings
Replace scattered reason string literals with a centralized type hierarchy: - AgentTriggerReason: all possible trigger reasons - ClaudeRotationReason, CodexRotationReason, NoFallbackCooldownReason: derived subtypes for specific contexts - AgentErrorClassification, FallbackTriggerResult, CodexRotationTriggerResult: discriminated unions for compile-time narrowing Remove dead export isUsageExhausted() (superseded by isPrimaryNoFallbackCooldownActive). Replace NO_FALLBACK_COOLDOWN_REASONS Set with isNoFallbackCooldownReason() type guard. Add tests for agent-error-detection and provider-retry (423 total passing). Known limitation: 6 `as CodexRotationReason` casts in Codex rotation paths where streamed trigger reason is AgentTriggerReason but runtime value is always CodexRotationReason-compatible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import path from 'path';
|
||||
import {
|
||||
classifyAgentError,
|
||||
classifyCodexAuthError,
|
||||
type CodexRotationReason,
|
||||
} from './agent-error-detection.js';
|
||||
import { DATA_DIR } from './config.js';
|
||||
import { logger } from './logger.js';
|
||||
@@ -42,10 +43,15 @@ interface CodexAccount {
|
||||
resetD7At?: string;
|
||||
}
|
||||
|
||||
export interface CodexRotationTriggerResult {
|
||||
shouldRotate: boolean;
|
||||
reason: string;
|
||||
}
|
||||
export type CodexRotationTriggerResult =
|
||||
| {
|
||||
shouldRotate: false;
|
||||
reason: '';
|
||||
}
|
||||
| {
|
||||
shouldRotate: true;
|
||||
reason: CodexRotationReason;
|
||||
};
|
||||
|
||||
function parseJwtAuth(idToken: string): {
|
||||
planType: string;
|
||||
|
||||
Reference in New Issue
Block a user