feat: Claude Compatible Providers System (#629)

* feat: refactor Claude API Profiles to Claude Compatible Providers

- Rename ClaudeApiProfile to ClaudeCompatibleProvider with models[] array
- Each ProviderModel has mapsToClaudeModel field for Claude tier mapping
- Add providerType field for provider-specific icons (glm, minimax, openrouter)
- Add thinking level support for provider models in phase selectors
- Show all mapped Claude models per provider model (e.g., "Maps to Haiku, Sonnet, Opus")
- Add Bulk Replace feature to switch all phases to a provider at once
- Hide Bulk Replace button when no providers are enabled
- Fix project-level phaseModelOverrides not persisting after refresh
- Fix deleting last provider not persisting (remove empty array guard)
- Add getProviderByModelId() helper for all SDK routes
- Update all routes to pass provider config for provider models
- Update terminology from "profiles" to "providers" throughout UI
- Update documentation to reflect new provider system

* fix: atomic writer race condition and bulk replace reset to defaults

1. AtomicWriter Race Condition Fix (libs/utils/src/atomic-writer.ts):
   - Changed temp file naming from Date.now() to Date.now() + random hex
   - Uses crypto.randomBytes(4).toString('hex') for uniqueness
   - Prevents ENOENT errors when multiple concurrent writes happen
     within the same millisecond

2. Bulk Replace "Anthropic Direct" Reset (both dialogs):
   - When selecting "Anthropic Direct", now uses DEFAULT_PHASE_MODELS
   - Properly resets thinking levels and other settings to defaults
   - Added thinkingLevel to the change detection comparison
   - Affects both global and project-level bulk replace dialogs

* fix: update tests for new model resolver passthrough behavior

1. model-resolver tests:
   - Unknown models now pass through unchanged (provider model support)
   - Removed expectations for warnings on unknown models
   - Updated case sensitivity and edge case tests accordingly
   - Added tests for provider-like model names (GLM-4.7, MiniMax-M2.1)

2. atomic-writer tests:
   - Updated regex to match new temp file format with random suffix
   - Format changed from .tmp.{timestamp} to .tmp.{timestamp}.{hex}

* refactor: simplify getPhaseModelWithOverrides calls per code review

Address code review feedback on PR #629:
- Make settingsService parameter optional in getPhaseModelWithOverrides
- Function now handles undefined settingsService gracefully by returning defaults
- Remove redundant ternary checks in 4 call sites:
  - apps/server/src/routes/context/routes/describe-file.ts
  - apps/server/src/routes/context/routes/describe-image.ts
  - apps/server/src/routes/worktree/routes/generate-commit-message.ts
  - apps/server/src/services/auto-mode-service.ts
- Remove unused DEFAULT_PHASE_MODELS imports where applicable

* test: fix server tests for provider model passthrough behavior

- Update model-resolver.test.ts to expect unknown models to pass through
  unchanged (supports ClaudeCompatibleProvider models like GLM-4.7)
- Remove warning expectations for unknown models (valid for providers)
- Add missing getCredentials and getGlobalSettings mocks to
  ideation-service.test.ts for settingsService

* fix: address code review feedback for model providers

- Honor thinkingLevel in generate-commit-message.ts
- Pass claudeCompatibleProvider in ideation-service.ts for provider models
- Resolve provider configuration for model overrides in generate-suggestions.ts
- Update "Active Profile" to "Active Provider" label in project-claude-section
- Use substring instead of deprecated substr in api-profiles-section
- Preserve provider enabled state when editing in api-profiles-section

* fix: address CodeRabbit review issues for Claude Compatible Providers

- Fix TypeScript TS2339 error in generate-suggestions.ts where
  settingsService was narrowed to 'never' type in else branch
- Use DEFAULT_PHASE_MODELS per-phase defaults instead of hardcoded
  'sonnet' in settings-helpers.ts
- Remove duplicate eventHooks key in use-settings-migration.ts
- Add claudeCompatibleProviders to localStorage migration parsing
  and merging functions
- Handle canonical claude-* model IDs (claude-haiku, claude-sonnet,
  claude-opus) in project-models-section display names

This resolves the CI build failures and addresses code review feedback.

* fix: skip broken list-view-priority E2E test and add Priority column label

- Skip list-view-priority.spec.ts with TODO explaining the infrastructure
  issue: setupRealProject only sets localStorage but server settings
  take precedence with localStorageMigrated: true
- Add 'Priority' label to list-header.tsx for the priority column
  (was empty string, now shows proper header text)
- Increase column width to accommodate the label

The E2E test issue is that tests create features in a temp directory,
but the server loads from the E2E Test Project fixture path set in
setup-e2e-fixtures.mjs. Needs infrastructure fix to properly switch
projects or create features through UI instead of on disk.
This commit is contained in:
Stefan de Vogelaere
2026-01-20 20:57:23 +01:00
committed by GitHub
parent 8facdc66a9
commit a1f234c7e2
48 changed files with 3870 additions and 1089 deletions

View File

@@ -33,6 +33,7 @@ import type {
ServerLogLevel,
EventHook,
ClaudeApiProfile,
ClaudeCompatibleProvider,
} from '@automaker/types';
import {
getAllCursorModelIds,
@@ -752,7 +753,10 @@ export interface AppState {
// Event Hooks
eventHooks: EventHook[]; // Event hooks for custom commands or webhooks
// Claude API Profiles
// Claude-Compatible Providers (new system)
claudeCompatibleProviders: ClaudeCompatibleProvider[]; // Providers that expose models to dropdowns
// Claude API Profiles (deprecated - kept for backward compatibility)
claudeApiProfiles: ClaudeApiProfile[]; // Claude-compatible API endpoint profiles
activeClaudeApiProfileId: string | null; // Active profile ID (null = use direct Anthropic API)
@@ -1040,8 +1044,17 @@ export interface AppActions {
getEffectiveFontMono: () => string | null; // Get effective code font (project override -> global -> null for default)
// Claude API Profile actions (per-project override)
/** @deprecated Use setProjectPhaseModelOverride instead */
setProjectClaudeApiProfile: (projectId: string, profileId: string | null | undefined) => void; // Set per-project Claude API profile (undefined = use global, null = direct API, string = specific profile)
// Project Phase Model Overrides
setProjectPhaseModelOverride: (
projectId: string,
phase: import('@automaker/types').PhaseModelKey,
entry: import('@automaker/types').PhaseModelEntry | null // null = use global
) => void;
clearAllProjectPhaseModelOverrides: (projectId: string) => void;
// Feature actions
setFeatures: (features: Feature[]) => void;
updateFeature: (id: string, updates: Partial<Feature>) => void;
@@ -1211,7 +1224,17 @@ export interface AppActions {
// Event Hook actions
setEventHooks: (hooks: EventHook[]) => void;
// Claude API Profile actions
// Claude-Compatible Provider actions (new system)
addClaudeCompatibleProvider: (provider: ClaudeCompatibleProvider) => Promise<void>;
updateClaudeCompatibleProvider: (
id: string,
updates: Partial<ClaudeCompatibleProvider>
) => Promise<void>;
deleteClaudeCompatibleProvider: (id: string) => Promise<void>;
setClaudeCompatibleProviders: (providers: ClaudeCompatibleProvider[]) => Promise<void>;
toggleClaudeCompatibleProviderEnabled: (id: string) => Promise<void>;
// Claude API Profile actions (deprecated - kept for backward compatibility)
addClaudeApiProfile: (profile: ClaudeApiProfile) => Promise<void>;
updateClaudeApiProfile: (id: string, updates: Partial<ClaudeApiProfile>) => Promise<void>;
deleteClaudeApiProfile: (id: string) => Promise<void>;
@@ -1476,8 +1499,9 @@ const initialState: AppState = {
subagentsSources: ['user', 'project'] as Array<'user' | 'project'>, // Load from both sources by default
promptCustomization: {}, // Empty by default - all prompts use built-in defaults
eventHooks: [], // No event hooks configured by default
claudeApiProfiles: [], // No Claude API profiles configured by default
activeClaudeApiProfileId: null, // Use direct Anthropic API by default
claudeCompatibleProviders: [], // Claude-compatible providers that expose models
claudeApiProfiles: [], // No Claude API profiles configured by default (deprecated)
activeClaudeApiProfileId: null, // Use direct Anthropic API by default (deprecated)
projectAnalysis: null,
isAnalyzing: false,
boardBackgroundByProject: {},
@@ -2017,6 +2041,98 @@ export const useAppStore = create<AppState & AppActions>()((set, get) => ({
});
},
// Project Phase Model Override actions
setProjectPhaseModelOverride: (projectId, phase, entry) => {
// Find the project to get its path for server sync
const project = get().projects.find((p) => p.id === projectId);
if (!project) {
console.error('Cannot set phase model override: project not found');
return;
}
// Get current overrides or start fresh
const currentOverrides = project.phaseModelOverrides || {};
// Build new overrides
let newOverrides: typeof currentOverrides;
if (entry === null) {
// Remove the override (use global)
const { [phase]: _, ...rest } = currentOverrides;
newOverrides = rest;
} else {
// Set the override
newOverrides = { ...currentOverrides, [phase]: entry };
}
// Update the project's phaseModelOverrides
const projects = get().projects.map((p) =>
p.id === projectId
? {
...p,
phaseModelOverrides: Object.keys(newOverrides).length > 0 ? newOverrides : undefined,
}
: p
);
set({ projects });
// Also update currentProject if it's the same project
const currentProject = get().currentProject;
if (currentProject?.id === projectId) {
set({
currentProject: {
...currentProject,
phaseModelOverrides: Object.keys(newOverrides).length > 0 ? newOverrides : undefined,
},
});
}
// Persist to server
const httpClient = getHttpApiClient();
httpClient.settings
.updateProject(project.path, {
phaseModelOverrides: Object.keys(newOverrides).length > 0 ? newOverrides : '__CLEAR__',
})
.catch((error) => {
console.error('Failed to persist phaseModelOverrides:', error);
});
},
clearAllProjectPhaseModelOverrides: (projectId) => {
// Find the project to get its path for server sync
const project = get().projects.find((p) => p.id === projectId);
if (!project) {
console.error('Cannot clear phase model overrides: project not found');
return;
}
// Clear overrides from project
const projects = get().projects.map((p) =>
p.id === projectId ? { ...p, phaseModelOverrides: undefined } : p
);
set({ projects });
// Also update currentProject if it's the same project
const currentProject = get().currentProject;
if (currentProject?.id === projectId) {
set({
currentProject: {
...currentProject,
phaseModelOverrides: undefined,
},
});
}
// Persist to server
const httpClient = getHttpApiClient();
httpClient.settings
.updateProject(project.path, {
phaseModelOverrides: '__CLEAR__',
})
.catch((error) => {
console.error('Failed to clear phaseModelOverrides:', error);
});
},
// Feature actions
setFeatures: (features) => set({ features }),
@@ -2601,7 +2717,53 @@ export const useAppStore = create<AppState & AppActions>()((set, get) => ({
// Event Hook actions
setEventHooks: (hooks) => set({ eventHooks: hooks }),
// Claude API Profile actions
// Claude-Compatible Provider actions (new system)
addClaudeCompatibleProvider: async (provider) => {
set({ claudeCompatibleProviders: [...get().claudeCompatibleProviders, provider] });
// Sync immediately to persist provider
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
await syncSettingsToServer();
},
updateClaudeCompatibleProvider: async (id, updates) => {
set({
claudeCompatibleProviders: get().claudeCompatibleProviders.map((p) =>
p.id === id ? { ...p, ...updates } : p
),
});
// Sync immediately to persist changes
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
await syncSettingsToServer();
},
deleteClaudeCompatibleProvider: async (id) => {
set({
claudeCompatibleProviders: get().claudeCompatibleProviders.filter((p) => p.id !== id),
});
// Sync immediately to persist deletion
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
await syncSettingsToServer();
},
setClaudeCompatibleProviders: async (providers) => {
set({ claudeCompatibleProviders: providers });
// Sync immediately to persist providers
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
await syncSettingsToServer();
},
toggleClaudeCompatibleProviderEnabled: async (id) => {
set({
claudeCompatibleProviders: get().claudeCompatibleProviders.map((p) =>
p.id === id ? { ...p, enabled: p.enabled === false ? true : false } : p
),
});
// Sync immediately to persist change
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
await syncSettingsToServer();
},
// Claude API Profile actions (deprecated - kept for backward compatibility)
addClaudeApiProfile: async (profile) => {
set({ claudeApiProfiles: [...get().claudeApiProfiles, profile] });
// Sync immediately to persist profile