mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-19 10:43:08 +00:00
* fix(copilot): correct tool.execution_complete event handling The CopilotProvider was using incorrect event type and data structure for tool execution completion events from the @github/copilot-sdk, causing tool call outputs to be empty. Changes: - Update event type from 'tool.execution_end' to 'tool.execution_complete' - Fix data structure to use nested result.content instead of flat result - Fix error structure to use error.message instead of flat error - Add success field to match SDK event structure - Add tests for empty and missing result handling This aligns with the official @github/copilot-sdk v0.1.16 types defined in session-events.d.ts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test(copilot): add edge case test for error with code field Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(copilot): improve error handling and code quality Code review improvements: - Extract magic string '[ERROR]' to TOOL_ERROR_PREFIX constant - Add null-safe error handling with direct error variable assignment - Include error codes in error messages for better debugging - Add JSDoc documentation for tool.execution_complete handler - Update tests to verify error codes are displayed - Add missing tool_use_id assertion in error test These changes improve: - Code maintainability (no magic strings) - Debugging experience (error codes now visible) - Type safety (explicit null checks) - Test coverage (verify error code formatting) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Changes from fix/bug-fixes-1-0 * test(copilot): add edge case test for error with code field Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Changes from fix/bug-fixes-1-0 * fix: Handle detached HEAD state in worktree discovery and recovery * fix: Remove unused isDevServerStarting prop and md: breakpoint classes * fix: Add missing dependency and sanitize persisted cache data * feat: Ensure NODE_ENV is set to test in vitest configs * feat: Configure Playwright to run only E2E tests * fix: Improve PR tracking and dev server lifecycle management * feat: Add settings-based defaults for planning mode, model config, and custom providers. Fixes #816 * feat: Add worktree and branch selector to graph view * fix: Add timeout and error handling for worktree HEAD ref resolution * fix: use absolute icon path and place icon outside asar on Linux The hicolor icon theme index only lists sizes up to 512x512, so an icon installed only at 1024x1024 is invisible to GNOME/KDE's theme resolver, causing both the app launcher and taskbar to show a generic icon. Additionally, BrowserWindow.icon cannot be read by the window manager when the file is inside app.asar. - extraResources: copy logo_larger.png to resources/ (outside asar) so it lands at /opt/Automaker/resources/logo_larger.png on install - linux.desktop.Icon: set to the absolute resources path, bypassing the hicolor theme lookup and its size constraints entirely - icon-manager.ts: on Linux production use process.resourcesPath so BrowserWindow receives a real filesystem path the WM can read directly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: use linux.desktop.entry for custom desktop Icon field electron-builder v26 rejects arbitrary keys in linux.desktop — the correct schema wraps custom .desktop overrides inside desktop.entry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: set desktop name on Linux so taskbar uses the correct app icon Without app.setDesktopName(), the window manager cannot associate the running Electron process with automaker.desktop. GNOME/KDE fall back to _NET_WM_ICON which defaults to Electron's own bundled icon. Calling app.setDesktopName('automaker.desktop') before any window is created sets the _GTK_APPLICATION_ID hint and XDG app_id so the WM picks up the desktop entry's Icon for the taskbar. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix: memory and context views mobile friendly (#818) * Changes from fix/memory-and-context-mobile-friendly * fix: Improve file extension detection and add path traversal protection * refactor: Extract file extension utilities and add path traversal guards Code review improvements: - Extract isMarkdownFilename and isImageFilename to shared image-utils.ts - Remove duplicated code from context-view.tsx and memory-view.tsx - Add path traversal guard for context fixture utilities (matching memory) - Add 7 new tests for context fixture path traversal protection - Total 61 tests pass Addresses code review feedback from PR #813 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: Add e2e tests for profiles crud and board background persistence * Update apps/ui/playwright.config.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: Add robust test navigation handling and file filtering * fix: Format NODE_OPTIONS configuration on single line * test: Update profiles and board background persistence tests * test: Replace iPhone 13 Pro with Pixel 5 for mobile test consistency * Update apps/ui/src/components/views/context-view.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore: Remove test project directory * feat: Filter context files by type and improve mobile menu visibility --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: Improve test reliability and localhost handling * chore: Use explicit TEST_USE_EXTERNAL_BACKEND env var for server cleanup * feat: Add E2E/CI mock mode for provider factory and auth verification * feat: Add remoteBranch parameter to pull and rebase operations * chore: Enhance E2E testing setup with worker isolation and auth state management - Updated .gitignore to include worker-specific test fixtures. - Modified e2e-tests.yml to implement test sharding for improved CI performance. - Refactored global setup to authenticate once and save session state for reuse across tests. - Introduced worker-isolated fixture paths to prevent conflicts during parallel test execution. - Improved test navigation and loading handling for better reliability. - Updated various test files to utilize new auth state management and fixture paths. * fix: Update Playwright configuration and improve test reliability - Increased the number of workers in Playwright configuration for better parallelism in CI environments. - Enhanced the board background persistence test to ensure dropdown stability by waiting for the list to populate before interaction, improving test reliability. * chore: Simplify E2E test configuration and enhance mock implementations - Updated e2e-tests.yml to run tests in a single shard for streamlined CI execution. - Enhanced unit tests for worktree list handling by introducing a mock for execGitCommand, improving test reliability and coverage. - Refactored setup functions to better manage command mocks for git operations in tests. - Improved error handling in mkdirSafe function to account for undefined stats in certain environments. * refactor: Improve test configurations and enhance error handling - Updated Playwright configuration to clear VITE_SERVER_URL, ensuring the frontend uses the Vite proxy and preventing cookie domain mismatches. - Enhanced MergeRebaseDialog logic to normalize selectedBranch for better handling of various ref formats. - Improved global setup with a more robust backend health check, throwing an error if the backend is not healthy after retries. - Refactored project creation tests to handle file existence checks more reliably. - Added error handling for missing E2E source fixtures to guide setup process. - Enhanced memory navigation to handle sandbox dialog visibility more effectively. * refactor: Enhance Git command execution and improve test configurations - Updated Git command execution to merge environment paths correctly, ensuring proper command execution context. - Refactored the Git initialization process to handle errors more gracefully and ensure user configuration is set before creating the initial commit. - Improved test configurations by updating Playwright test identifiers for better clarity and consistency across different project states. - Enhanced cleanup functions in tests to handle directory removal more robustly, preventing errors during test execution. * fix: Resolve React hooks errors from duplicate instances in dependency tree * style: Format alias configuration for improved readability --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: DhanushSantosh <dhanushsantoshs05@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
351 lines
11 KiB
TypeScript
351 lines
11 KiB
TypeScript
/**
|
|
* Provider Factory - Routes model IDs to the appropriate provider
|
|
*
|
|
* Uses a registry pattern for dynamic provider registration.
|
|
* Providers register themselves on import, making it easy to add new providers.
|
|
*/
|
|
|
|
import { BaseProvider } from './base-provider.js';
|
|
import type { InstallationStatus, ModelDefinition } from './types.js';
|
|
import {
|
|
isCursorModel,
|
|
isCodexModel,
|
|
isOpencodeModel,
|
|
isGeminiModel,
|
|
isCopilotModel,
|
|
type ModelProvider,
|
|
} from '@automaker/types';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
const DISCONNECTED_MARKERS: Record<string, string> = {
|
|
claude: '.claude-disconnected',
|
|
codex: '.codex-disconnected',
|
|
cursor: '.cursor-disconnected',
|
|
opencode: '.opencode-disconnected',
|
|
gemini: '.gemini-disconnected',
|
|
copilot: '.copilot-disconnected',
|
|
};
|
|
|
|
/**
|
|
* Check if a provider CLI is disconnected from the app
|
|
*/
|
|
export function isProviderDisconnected(providerName: string): boolean {
|
|
const markerFile = DISCONNECTED_MARKERS[providerName.toLowerCase()];
|
|
if (!markerFile) return false;
|
|
|
|
const markerPath = path.join(process.cwd(), '.automaker', markerFile);
|
|
return fs.existsSync(markerPath);
|
|
}
|
|
|
|
/**
|
|
* Provider registration entry
|
|
*/
|
|
interface ProviderRegistration {
|
|
/** Factory function to create provider instance */
|
|
factory: () => BaseProvider;
|
|
/** Aliases for this provider (e.g., 'anthropic' for 'claude') */
|
|
aliases?: string[];
|
|
/** Function to check if this provider can handle a model ID */
|
|
canHandleModel?: (modelId: string) => boolean;
|
|
/** Priority for model matching (higher = checked first) */
|
|
priority?: number;
|
|
}
|
|
|
|
/**
|
|
* Provider registry - stores registered providers
|
|
*/
|
|
const providerRegistry = new Map<string, ProviderRegistration>();
|
|
|
|
/**
|
|
* Register a provider with the factory
|
|
*
|
|
* @param name Provider name (e.g., 'claude', 'cursor')
|
|
* @param registration Provider registration config
|
|
*/
|
|
export function registerProvider(name: string, registration: ProviderRegistration): void {
|
|
providerRegistry.set(name.toLowerCase(), registration);
|
|
}
|
|
|
|
/** Cached mock provider instance when AUTOMAKER_MOCK_AGENT is set (E2E/CI). */
|
|
let mockProviderInstance: BaseProvider | null = null;
|
|
|
|
function getMockProvider(): BaseProvider {
|
|
if (!mockProviderInstance) {
|
|
mockProviderInstance = new MockProvider();
|
|
}
|
|
return mockProviderInstance;
|
|
}
|
|
|
|
export class ProviderFactory {
|
|
/**
|
|
* Determine which provider to use for a given model
|
|
*
|
|
* @param model Model identifier
|
|
* @returns Provider name (ModelProvider type)
|
|
*/
|
|
static getProviderNameForModel(model: string): ModelProvider {
|
|
if (process.env.AUTOMAKER_MOCK_AGENT === 'true') {
|
|
return 'claude' as ModelProvider; // Name only; getProviderForModel returns MockProvider
|
|
}
|
|
const lowerModel = model.toLowerCase();
|
|
|
|
// Get all registered providers sorted by priority (descending)
|
|
const registrations = Array.from(providerRegistry.entries()).sort(
|
|
([, a], [, b]) => (b.priority ?? 0) - (a.priority ?? 0)
|
|
);
|
|
|
|
// Check each provider's canHandleModel function
|
|
for (const [name, reg] of registrations) {
|
|
if (reg.canHandleModel?.(lowerModel)) {
|
|
return name as ModelProvider;
|
|
}
|
|
}
|
|
|
|
// Fallback: Check for explicit prefixes
|
|
for (const [name] of registrations) {
|
|
if (lowerModel.startsWith(`${name}-`)) {
|
|
return name as ModelProvider;
|
|
}
|
|
}
|
|
|
|
// Default to claude (first registered provider or claude)
|
|
return 'claude';
|
|
}
|
|
|
|
/**
|
|
* Get the appropriate provider for a given model ID
|
|
*
|
|
* @param modelId Model identifier (e.g., "claude-opus-4-6", "cursor-gpt-4o", "cursor-auto")
|
|
* @param options Optional settings
|
|
* @param options.throwOnDisconnected Throw error if provider is disconnected (default: true)
|
|
* @returns Provider instance for the model
|
|
* @throws Error if provider is disconnected and throwOnDisconnected is true
|
|
*/
|
|
static getProviderForModel(
|
|
modelId: string,
|
|
options: { throwOnDisconnected?: boolean } = {}
|
|
): BaseProvider {
|
|
if (process.env.AUTOMAKER_MOCK_AGENT === 'true') {
|
|
return getMockProvider();
|
|
}
|
|
const { throwOnDisconnected = true } = options;
|
|
const providerName = this.getProviderForModelName(modelId);
|
|
|
|
// Check if provider is disconnected
|
|
if (throwOnDisconnected && isProviderDisconnected(providerName)) {
|
|
throw new Error(
|
|
`${providerName.charAt(0).toUpperCase() + providerName.slice(1)} CLI is disconnected from the app. ` +
|
|
`Please go to Settings > Providers and click "Sign In" to reconnect.`
|
|
);
|
|
}
|
|
|
|
const provider = this.getProviderByName(providerName);
|
|
|
|
if (!provider) {
|
|
// Fallback to claude if provider not found
|
|
const claudeReg = providerRegistry.get('claude');
|
|
if (claudeReg) {
|
|
return claudeReg.factory();
|
|
}
|
|
throw new Error(`No provider found for model: ${modelId}`);
|
|
}
|
|
|
|
return provider;
|
|
}
|
|
|
|
/**
|
|
* Get the provider name for a given model ID (without creating provider instance)
|
|
*/
|
|
static getProviderForModelName(modelId: string): string {
|
|
if (process.env.AUTOMAKER_MOCK_AGENT === 'true') {
|
|
return 'claude';
|
|
}
|
|
const lowerModel = modelId.toLowerCase();
|
|
|
|
// Get all registered providers sorted by priority (descending)
|
|
const registrations = Array.from(providerRegistry.entries()).sort(
|
|
([, a], [, b]) => (b.priority ?? 0) - (a.priority ?? 0)
|
|
);
|
|
|
|
// Check each provider's canHandleModel function
|
|
for (const [name, reg] of registrations) {
|
|
if (reg.canHandleModel?.(lowerModel)) {
|
|
return name;
|
|
}
|
|
}
|
|
|
|
// Fallback: Check for explicit prefixes
|
|
for (const [name] of registrations) {
|
|
if (lowerModel.startsWith(`${name}-`)) {
|
|
return name;
|
|
}
|
|
}
|
|
|
|
// Default to claude (first registered provider or claude)
|
|
return 'claude';
|
|
}
|
|
|
|
/**
|
|
* Get all available providers
|
|
*/
|
|
static getAllProviders(): BaseProvider[] {
|
|
return Array.from(providerRegistry.values()).map((reg) => reg.factory());
|
|
}
|
|
|
|
/**
|
|
* Check installation status for all providers
|
|
*
|
|
* @returns Map of provider name to installation status
|
|
*/
|
|
static async checkAllProviders(): Promise<Record<string, InstallationStatus>> {
|
|
const statuses: Record<string, InstallationStatus> = {};
|
|
|
|
for (const [name, reg] of providerRegistry.entries()) {
|
|
const provider = reg.factory();
|
|
const status = await provider.detectInstallation();
|
|
statuses[name] = status;
|
|
}
|
|
|
|
return statuses;
|
|
}
|
|
|
|
/**
|
|
* Get provider by name (for direct access if needed)
|
|
*
|
|
* @param name Provider name (e.g., "claude", "cursor") or alias (e.g., "anthropic")
|
|
* @returns Provider instance or null if not found
|
|
*/
|
|
static getProviderByName(name: string): BaseProvider | null {
|
|
const lowerName = name.toLowerCase();
|
|
|
|
// Direct lookup
|
|
const directReg = providerRegistry.get(lowerName);
|
|
if (directReg) {
|
|
return directReg.factory();
|
|
}
|
|
|
|
// Check aliases
|
|
for (const [, reg] of providerRegistry.entries()) {
|
|
if (reg.aliases?.includes(lowerName)) {
|
|
return reg.factory();
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get all available models from all providers
|
|
*/
|
|
static getAllAvailableModels(): ModelDefinition[] {
|
|
const providers = this.getAllProviders();
|
|
return providers.flatMap((p) => p.getAvailableModels());
|
|
}
|
|
|
|
/**
|
|
* Get list of registered provider names
|
|
*/
|
|
static getRegisteredProviderNames(): string[] {
|
|
return Array.from(providerRegistry.keys());
|
|
}
|
|
|
|
/**
|
|
* Check if a specific model supports vision/image input
|
|
*
|
|
* @param modelId Model identifier
|
|
* @returns Whether the model supports vision (defaults to true if model not found)
|
|
*/
|
|
static modelSupportsVision(modelId: string): boolean {
|
|
const provider = this.getProviderForModel(modelId);
|
|
const models = provider.getAvailableModels();
|
|
|
|
// Find the model in the available models list
|
|
for (const model of models) {
|
|
if (
|
|
model.id === modelId ||
|
|
model.modelString === modelId ||
|
|
model.id.endsWith(`-${modelId}`) ||
|
|
model.modelString.endsWith(`-${modelId}`) ||
|
|
model.modelString === modelId.replace(/^(claude|cursor|codex|gemini)-/, '') ||
|
|
model.modelString === modelId.replace(/-(claude|cursor|codex|gemini)$/, '')
|
|
) {
|
|
return model.supportsVision ?? true;
|
|
}
|
|
}
|
|
|
|
// Also try exact match with model string from provider's model map
|
|
for (const model of models) {
|
|
if (model.modelString === modelId || model.id === modelId) {
|
|
return model.supportsVision ?? true;
|
|
}
|
|
}
|
|
|
|
// Default to true (Claude SDK supports vision by default)
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// =============================================================================
|
|
// Provider Registrations
|
|
// =============================================================================
|
|
|
|
// Import providers for registration side-effects
|
|
import { MockProvider } from './mock-provider.js';
|
|
import { ClaudeProvider } from './claude-provider.js';
|
|
import { CursorProvider } from './cursor-provider.js';
|
|
import { CodexProvider } from './codex-provider.js';
|
|
import { OpencodeProvider } from './opencode-provider.js';
|
|
import { GeminiProvider } from './gemini-provider.js';
|
|
import { CopilotProvider } from './copilot-provider.js';
|
|
|
|
// Register Claude provider
|
|
registerProvider('claude', {
|
|
factory: () => new ClaudeProvider(),
|
|
aliases: ['anthropic'],
|
|
canHandleModel: (model: string) => {
|
|
return (
|
|
model.startsWith('claude-') || ['opus', 'sonnet', 'haiku'].some((n) => model.includes(n))
|
|
);
|
|
},
|
|
priority: 0, // Default priority
|
|
});
|
|
|
|
// Register Cursor provider
|
|
registerProvider('cursor', {
|
|
factory: () => new CursorProvider(),
|
|
canHandleModel: (model: string) => isCursorModel(model),
|
|
priority: 10, // Higher priority - check Cursor models first
|
|
});
|
|
|
|
// Register Codex provider
|
|
registerProvider('codex', {
|
|
factory: () => new CodexProvider(),
|
|
aliases: ['openai'],
|
|
canHandleModel: (model: string) => isCodexModel(model),
|
|
priority: 5, // Medium priority - check after Cursor but before Claude
|
|
});
|
|
|
|
// Register OpenCode provider
|
|
registerProvider('opencode', {
|
|
factory: () => new OpencodeProvider(),
|
|
canHandleModel: (model: string) => isOpencodeModel(model),
|
|
priority: 3, // Between codex (5) and claude (0)
|
|
});
|
|
|
|
// Register Gemini provider
|
|
registerProvider('gemini', {
|
|
factory: () => new GeminiProvider(),
|
|
aliases: ['google'],
|
|
canHandleModel: (model: string) => isGeminiModel(model),
|
|
priority: 4, // Between opencode (3) and codex (5)
|
|
});
|
|
|
|
// Register Copilot provider (GitHub Copilot SDK)
|
|
registerProvider('copilot', {
|
|
factory: () => new CopilotProvider(),
|
|
aliases: ['github-copilot', 'github'],
|
|
canHandleModel: (model: string) => isCopilotModel(model),
|
|
priority: 6, // High priority - check before Codex since both can handle GPT models
|
|
});
|