claude-task-master/scripts/modules/config-manager.js

949 lines
30 KiB
JavaScript
Raw Permalink Normal View History

import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import { z } from 'zod';
import { fileURLToPath } from 'url';
import { log, findProjectRoot, resolveEnvVariable, isEmpty } from './utils.js';
2025-05-31 16:21:03 +02:00
import { LEGACY_CONFIG_FILE } from '../../src/constants/paths.js';
import { findConfigPath } from '../../src/utils/path-utils.js';
import {
VALIDATED_PROVIDERS,
CUSTOM_PROVIDERS,
CUSTOM_PROVIDERS_ARRAY,
ALL_PROVIDERS
} from '../../src/constants/providers.js';
import { AI_COMMAND_NAMES } from '../../src/constants/commands.js';
// Calculate __dirname in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load supported models from JSON file using the calculated __dirname
let MODEL_MAP;
try {
const supportedModelsRaw = fs.readFileSync(
path.join(__dirname, 'supported-models.json'),
'utf-8'
);
MODEL_MAP = JSON.parse(supportedModelsRaw);
} catch (error) {
console.error(
chalk.red(
'FATAL ERROR: Could not load supported-models.json. Please ensure the file exists and is valid JSON.'
),
error
);
MODEL_MAP = {}; // Default to empty map on error to avoid crashing, though functionality will be limited
process.exit(1); // Exit if models can't be loaded
}
2025-05-31 16:21:03 +02:00
// Default configuration values (used if config file is missing or incomplete)
const DEFAULTS = {
models: {
main: {
provider: 'anthropic',
modelId: 'claude-3-7-sonnet-20250219',
maxTokens: 64000,
temperature: 0.2
},
research: {
provider: 'perplexity',
modelId: 'sonar-pro',
maxTokens: 8700,
temperature: 0.1
},
fallback: {
// No default fallback provider/model initially
provider: 'anthropic',
modelId: 'claude-3-5-sonnet',
maxTokens: 8192, // Default parameters if fallback IS configured
temperature: 0.2
}
},
global: {
logLevel: 'info',
debug: false,
defaultNumTasks: 10,
defaultSubtasks: 5,
defaultPriority: 'medium',
projectName: 'Task Master',
ollamaBaseURL: 'http://localhost:11434/api',
bedrockBaseURL: 'https://bedrock.us-east-1.amazonaws.com',
responseLanguage: 'English'
},
claudeCode: {}
};
// --- Internal Config Loading ---
let loadedConfig = null;
let loadedConfigRoot = null; // Track which root loaded the config
// Custom Error for configuration issues
class ConfigurationError extends Error {
constructor(message) {
super(message);
this.name = 'ConfigurationError';
}
}
function _loadAndValidateConfig(explicitRoot = null) {
const defaults = DEFAULTS; // Use the defined defaults
let rootToUse = explicitRoot;
let configSource = explicitRoot
? `explicit root (${explicitRoot})`
: 'defaults (no root provided yet)';
// ---> If no explicit root, TRY to find it <---
if (!rootToUse) {
rootToUse = findProjectRoot();
if (rootToUse) {
configSource = `found root (${rootToUse})`;
} else {
// No root found, return defaults immediately
return defaults;
}
}
// ---> End find project root logic <---
2025-05-31 16:21:03 +02:00
// --- Find configuration file using centralized path utility ---
const configPath = findConfigPath(null, { projectRoot: rootToUse });
let config = { ...defaults }; // Start with a deep copy of defaults
let configExists = false;
2025-05-31 16:21:03 +02:00
if (configPath) {
configExists = true;
2025-05-31 16:21:03 +02:00
const isLegacy = configPath.endsWith(LEGACY_CONFIG_FILE);
try {
const rawData = fs.readFileSync(configPath, 'utf-8');
const parsedConfig = JSON.parse(rawData);
// Deep merge parsed config onto defaults
config = {
models: {
main: { ...defaults.models.main, ...parsedConfig?.models?.main },
research: {
...defaults.models.research,
...parsedConfig?.models?.research
},
fallback:
parsedConfig?.models?.fallback?.provider &&
parsedConfig?.models?.fallback?.modelId
? { ...defaults.models.fallback, ...parsedConfig.models.fallback }
: { ...defaults.models.fallback }
},
global: { ...defaults.global, ...parsedConfig?.global },
claudeCode: { ...defaults.claudeCode, ...parsedConfig?.claudeCode }
};
configSource = `file (${configPath})`; // Update source info
2025-05-31 16:21:03 +02:00
// Issue deprecation warning if using legacy config file
if (isLegacy) {
console.warn(
chalk.yellow(
`⚠️ DEPRECATION WARNING: Found configuration in legacy location '${configPath}'. Please migrate to .taskmaster/config.json. Run 'task-master migrate' to automatically migrate your project.`
)
);
}
// --- Validation (Warn if file content is invalid) ---
// Use log.warn for consistency
if (!validateProvider(config.models.main.provider)) {
console.warn(
chalk.yellow(
`Warning: Invalid main provider "${config.models.main.provider}" in ${configPath}. Falling back to default.`
)
);
config.models.main = { ...defaults.models.main };
}
if (!validateProvider(config.models.research.provider)) {
console.warn(
chalk.yellow(
`Warning: Invalid research provider "${config.models.research.provider}" in ${configPath}. Falling back to default.`
)
);
config.models.research = { ...defaults.models.research };
}
if (
config.models.fallback?.provider &&
!validateProvider(config.models.fallback.provider)
) {
console.warn(
chalk.yellow(
`Warning: Invalid fallback provider "${config.models.fallback.provider}" in ${configPath}. Fallback model configuration will be ignored.`
)
);
config.models.fallback.provider = undefined;
config.models.fallback.modelId = undefined;
}
if (config.claudeCode && !isEmpty(config.claudeCode)) {
config.claudeCode = validateClaudeCodeSettings(config.claudeCode);
}
} catch (error) {
// Use console.error for actual errors during parsing
console.error(
chalk.red(
`Error reading or parsing ${configPath}: ${error.message}. Using default configuration.`
)
);
config = { ...defaults }; // Reset to defaults on parse error
configSource = `defaults (parse error at ${configPath})`;
}
} else {
// Config file doesn't exist at the determined rootToUse.
if (explicitRoot) {
// Only warn if an explicit root was *expected*.
console.warn(
chalk.yellow(
2025-05-31 16:21:03 +02:00
`Warning: Configuration file not found at provided project root (${explicitRoot}). Using default configuration. Run 'task-master models --setup' to configure.`
)
);
} else {
console.warn(
chalk.yellow(
2025-05-31 16:21:03 +02:00
`Warning: Configuration file not found at derived root (${rootToUse}). Using defaults.`
)
);
}
// Keep config as defaults
config = { ...defaults };
2025-05-31 16:21:03 +02:00
configSource = `defaults (no config file found at ${rootToUse})`;
}
return config;
}
/**
* Gets the current configuration, loading it if necessary.
* Handles MCP initialization context gracefully.
* @param {string|null} explicitRoot - Optional explicit path to the project root.
* @param {boolean} forceReload - Force reloading the config file.
* @returns {object} The loaded configuration object.
*/
function getConfig(explicitRoot = null, forceReload = false) {
// Determine if a reload is necessary
const needsLoad =
!loadedConfig ||
forceReload ||
(explicitRoot && explicitRoot !== loadedConfigRoot);
if (needsLoad) {
const newConfig = _loadAndValidateConfig(explicitRoot); // _load handles null explicitRoot
// Only update the global cache if loading was forced or if an explicit root
// was provided (meaning we attempted to load a specific project's config).
// We avoid caching the initial default load triggered without an explicitRoot.
if (forceReload || explicitRoot) {
loadedConfig = newConfig;
loadedConfigRoot = explicitRoot; // Store the root used for this loaded config
}
return newConfig; // Return the newly loaded/default config
}
// If no load was needed, return the cached config
return loadedConfig;
}
/**
* Validates if a provider name is supported.
* Custom providers (azure, vertex, bedrock, openrouter, ollama) are always allowed.
* Validated providers must exist in the MODEL_MAP from supported-models.json.
* @param {string} providerName The name of the provider.
* @returns {boolean} True if the provider is valid, false otherwise.
*/
function validateProvider(providerName) {
// Custom providers are always allowed
if (CUSTOM_PROVIDERS_ARRAY.includes(providerName)) {
return true;
}
// Validated providers must exist in MODEL_MAP
if (VALIDATED_PROVIDERS.includes(providerName)) {
return !!(MODEL_MAP && MODEL_MAP[providerName]);
}
// Unknown providers are not allowed
return false;
}
/**
* Optional: Validates if a modelId is known for a given provider based on MODEL_MAP.
* This is a non-strict validation; an unknown model might still be valid.
* @param {string} providerName The name of the provider.
* @param {string} modelId The model ID.
* @returns {boolean} True if the modelId is in the map for the provider, false otherwise.
*/
function validateProviderModelCombination(providerName, modelId) {
// If provider isn't even in our map, we can't validate the model
if (!MODEL_MAP[providerName]) {
return true; // Allow unknown providers or those without specific model lists
}
// If the provider is known, check if the model is in its list OR if the list is empty (meaning accept any)
return (
MODEL_MAP[providerName].length === 0 ||
// Use .some() to check the 'id' property of objects in the array
MODEL_MAP[providerName].some((modelObj) => modelObj.id === modelId)
);
}
/**
* Validates Claude Code AI provider custom settings
* @param {object} settings The settings to validate
* @returns {object} The validated settings
*/
function validateClaudeCodeSettings(settings) {
// Define the base settings schema without commandSpecific first
const BaseSettingsSchema = z.object({
maxTurns: z.number().int().positive().optional(),
customSystemPrompt: z.string().optional(),
appendSystemPrompt: z.string().optional(),
permissionMode: z
.enum(['default', 'acceptEdits', 'plan', 'bypassPermissions'])
.optional(),
allowedTools: z.array(z.string()).optional(),
disallowedTools: z.array(z.string()).optional(),
mcpServers: z
.record(
z.string(),
z.object({
type: z.enum(['stdio', 'sse']).optional(),
command: z.string(),
args: z.array(z.string()).optional(),
env: z.record(z.string()).optional(),
url: z.string().url().optional(),
headers: z.record(z.string()).optional()
})
)
.optional()
});
// Define CommandSpecificSchema using the base schema
const CommandSpecificSchema = z.record(
z.enum(AI_COMMAND_NAMES),
BaseSettingsSchema
);
// Define the full settings schema with commandSpecific
const SettingsSchema = BaseSettingsSchema.extend({
commandSpecific: CommandSpecificSchema.optional()
});
let validatedSettings = {};
try {
validatedSettings = SettingsSchema.parse(settings);
} catch (error) {
console.warn(
chalk.yellow(
`Warning: Invalid Claude Code settings in config: ${error.message}. Falling back to default.`
)
);
validatedSettings = {};
}
return validatedSettings;
}
// --- Claude Code Settings Getters ---
function getClaudeCodeSettings(explicitRoot = null, forceReload = false) {
const config = getConfig(explicitRoot, forceReload);
// Ensure Claude Code defaults are applied if Claude Code section is missing
return { ...DEFAULTS.claudeCode, ...(config?.claudeCode || {}) };
}
function getClaudeCodeSettingsForCommand(
commandName,
explicitRoot = null,
forceReload = false
) {
const settings = getClaudeCodeSettings(explicitRoot, forceReload);
const commandSpecific = settings?.commandSpecific || {};
return { ...settings, ...commandSpecific[commandName] };
}
// --- Role-Specific Getters ---
function getModelConfigForRole(role, explicitRoot = null) {
const config = getConfig(explicitRoot);
const roleConfig = config?.models?.[role];
if (!roleConfig) {
log(
'warn',
`No model configuration found for role: ${role}. Returning default.`
);
return DEFAULTS.models[role] || {};
}
return roleConfig;
}
function getMainProvider(explicitRoot = null) {
return getModelConfigForRole('main', explicitRoot).provider;
}
function getMainModelId(explicitRoot = null) {
return getModelConfigForRole('main', explicitRoot).modelId;
}
function getMainMaxTokens(explicitRoot = null) {
// Directly return value from config (which includes defaults)
return getModelConfigForRole('main', explicitRoot).maxTokens;
}
function getMainTemperature(explicitRoot = null) {
// Directly return value from config
return getModelConfigForRole('main', explicitRoot).temperature;
}
function getResearchProvider(explicitRoot = null) {
return getModelConfigForRole('research', explicitRoot).provider;
}
function getResearchModelId(explicitRoot = null) {
return getModelConfigForRole('research', explicitRoot).modelId;
}
function getResearchMaxTokens(explicitRoot = null) {
// Directly return value from config
return getModelConfigForRole('research', explicitRoot).maxTokens;
}
function getResearchTemperature(explicitRoot = null) {
// Directly return value from config
return getModelConfigForRole('research', explicitRoot).temperature;
}
function getFallbackProvider(explicitRoot = null) {
// Directly return value from config (will be undefined if not set)
return getModelConfigForRole('fallback', explicitRoot).provider;
}
function getFallbackModelId(explicitRoot = null) {
// Directly return value from config
return getModelConfigForRole('fallback', explicitRoot).modelId;
}
function getFallbackMaxTokens(explicitRoot = null) {
// Directly return value from config
return getModelConfigForRole('fallback', explicitRoot).maxTokens;
}
function getFallbackTemperature(explicitRoot = null) {
// Directly return value from config
return getModelConfigForRole('fallback', explicitRoot).temperature;
}
// --- Global Settings Getters ---
function getGlobalConfig(explicitRoot = null) {
const config = getConfig(explicitRoot);
// Ensure global defaults are applied if global section is missing
return { ...DEFAULTS.global, ...(config?.global || {}) };
}
function getLogLevel(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).logLevel.toLowerCase();
}
function getDebugFlag(explicitRoot = null) {
// Directly return value from config, ensure boolean
return getGlobalConfig(explicitRoot).debug === true;
}
function getDefaultSubtasks(explicitRoot = null) {
// Directly return value from config, ensure integer
const val = getGlobalConfig(explicitRoot).defaultSubtasks;
const parsedVal = parseInt(val, 10);
2025-05-31 16:21:03 +02:00
return Number.isNaN(parsedVal) ? DEFAULTS.global.defaultSubtasks : parsedVal;
}
function getDefaultNumTasks(explicitRoot = null) {
const val = getGlobalConfig(explicitRoot).defaultNumTasks;
const parsedVal = parseInt(val, 10);
2025-05-31 16:21:03 +02:00
return Number.isNaN(parsedVal) ? DEFAULTS.global.defaultNumTasks : parsedVal;
}
function getDefaultPriority(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).defaultPriority;
}
function getProjectName(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).projectName;
}
function getOllamaBaseURL(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).ollamaBaseURL;
}
function getAzureBaseURL(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).azureBaseURL;
}
function getBedrockBaseURL(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).bedrockBaseURL;
}
/**
* Gets the Google Cloud project ID for Vertex AI from configuration
* @param {string|null} explicitRoot - Optional explicit path to the project root.
* @returns {string|null} The project ID or null if not configured
*/
function getVertexProjectId(explicitRoot = null) {
// Return value from config
return getGlobalConfig(explicitRoot).vertexProjectId;
}
/**
* Gets the Google Cloud location for Vertex AI from configuration
* @param {string|null} explicitRoot - Optional explicit path to the project root.
* @returns {string} The location or default value of "us-central1"
*/
function getVertexLocation(explicitRoot = null) {
// Return value from config or default
return getGlobalConfig(explicitRoot).vertexLocation || 'us-central1';
}
function getResponseLanguage(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).responseLanguage;
}
/**
* Gets model parameters (maxTokens, temperature) for a specific role,
* considering model-specific overrides from supported-models.json.
* @param {string} role - The role ('main', 'research', 'fallback').
* @param {string|null} explicitRoot - Optional explicit path to the project root.
* @returns {{maxTokens: number, temperature: number}}
*/
function getParametersForRole(role, explicitRoot = null) {
const roleConfig = getModelConfigForRole(role, explicitRoot);
const roleMaxTokens = roleConfig.maxTokens;
const roleTemperature = roleConfig.temperature;
const modelId = roleConfig.modelId;
const providerName = roleConfig.provider;
let effectiveMaxTokens = roleMaxTokens; // Start with the role's default
try {
// Find the model definition in MODEL_MAP
const providerModels = MODEL_MAP[providerName];
if (providerModels && Array.isArray(providerModels)) {
const modelDefinition = providerModels.find((m) => m.id === modelId);
// Check if a model-specific max_tokens is defined and valid
if (
modelDefinition &&
typeof modelDefinition.max_tokens === 'number' &&
modelDefinition.max_tokens > 0
) {
const modelSpecificMaxTokens = modelDefinition.max_tokens;
// Use the minimum of the role default and the model specific limit
effectiveMaxTokens = Math.min(roleMaxTokens, modelSpecificMaxTokens);
log(
'debug',
`Applying model-specific max_tokens (${modelSpecificMaxTokens}) for ${modelId}. Effective limit: ${effectiveMaxTokens}`
);
} else {
log(
'debug',
`No valid model-specific max_tokens override found for ${modelId}. Using role default: ${roleMaxTokens}`
);
}
} else {
log(
'debug',
`No model definitions found for provider ${providerName} in MODEL_MAP. Using role default maxTokens: ${roleMaxTokens}`
);
}
} catch (lookupError) {
log(
'warn',
`Error looking up model-specific max_tokens for ${modelId}: ${lookupError.message}. Using role default: ${roleMaxTokens}`
);
// Fallback to role default on error
effectiveMaxTokens = roleMaxTokens;
}
return {
maxTokens: effectiveMaxTokens,
temperature: roleTemperature
};
}
/**
* Checks if the API key for a given provider is set in the environment.
* Checks process.env first, then session.env if session is provided, then .env file if projectRoot provided.
* @param {string} providerName - The name of the provider (e.g., 'openai', 'anthropic').
* @param {object|null} [session=null] - The MCP session object (optional).
* @param {string|null} [projectRoot=null] - The project root directory (optional, for .env file check).
* @returns {boolean} True if the API key is set, false otherwise.
*/
function isApiKeySet(providerName, session = null, projectRoot = null) {
// Define the expected environment variable name for each provider
// Providers that don't require API keys for authentication
const providersWithoutApiKeys = [
CUSTOM_PROVIDERS.OLLAMA,
feat: Add gemini-cli provider integration for Task Master (#897) * feat: Add gemini-cli provider integration for Task Master This commit adds comprehensive support for the Gemini CLI provider, enabling users to leverage Google's Gemini models through OAuth authentication via the gemini CLI tool. This integration provides a seamless experience for users who prefer using their existing Google account authentication rather than managing API keys. ## Implementation Details ### Provider Class (`src/ai-providers/gemini-cli.js`) - Created GeminiCliProvider extending BaseAIProvider - Implements dual authentication support: - Primary: OAuth authentication via `gemini auth login` (authType: 'oauth-personal') - Secondary: API key authentication for compatibility (authType: 'api-key') - Uses the npm package `ai-sdk-provider-gemini-cli` (v0.0.3) for SDK integration - Properly handles authentication validation without console output ### Model Configuration (`scripts/modules/supported-models.json`) - Added two Gemini models with accurate specifications: - gemini-2.5-pro: 72% SWE score, 65,536 max output tokens - gemini-2.5-flash: 71% SWE score, 65,536 max output tokens - Both models support main, fallback, and research roles - Configured with zero cost (free tier) ### System Integration - Registered provider in PROVIDERS map (`scripts/modules/ai-services-unified.js`) - Added to OPTIONAL_AUTH_PROVIDERS set for flexible authentication - Added GEMINI_CLI constant to provider constants (`src/constants/providers.js`) - Exported GeminiCliProvider from index (`src/ai-providers/index.js`) ### Command Line Support (`scripts/modules/commands.js`) - Added --gemini-cli flag to models command for provider hint - Integrated into model selection logic (setModel function) - Updated error messages to include gemini-cli in provider list - Removed unrelated azure/vertex changes to maintain PR focus ### Documentation (`docs/providers/gemini-cli.md`) - Comprehensive provider documentation emphasizing OAuth-first approach - Clear explanation of why users would choose gemini-cli over standard google provider - Detailed installation, authentication, and configuration instructions - Troubleshooting section with common issues and solutions ### Testing (`tests/unit/ai-providers/gemini-cli.test.js`) - Complete test suite with 12 tests covering all functionality - Tests for both OAuth and API key authentication paths - Error handling and edge case coverage - Updated mocks in ai-services-unified.test.js for integration testing ## Key Design Decisions 1. **OAuth-First Design**: The provider assumes users want to leverage their existing `gemini auth login` credentials, making this the default authentication method. 2. **Authentication Type Mapping**: Discovered through testing that the SDK expects: - 'oauth-personal' for OAuth/CLI authentication (not 'gemini-cli' or 'oauth') - 'api-key' for API key authentication (not 'gemini-api-key') 3. **Silent Operation**: Removed console.log statements from validateAuth to match the pattern used by other providers like claude-code. 4. **Limited Model Support**: Only gemini-2.5-pro and gemini-2.5-flash are available through the CLI, as confirmed by the package author. ## Usage ```bash # Install gemini CLI globally npm install -g @google/gemini-cli # Authenticate with Google account gemini auth login # Configure Task Master to use gemini-cli task-master models --set-main gemini-2.5-pro --gemini-cli # Use Task Master normally task-master new "Create a REST API endpoint" ``` ## Dependencies - Added `ai-sdk-provider-gemini-cli@^0.0.3` to package.json - This package wraps the Google Gemini CLI Core functionality for Vercel AI SDK ## Testing All tests pass (613 total), including the new gemini-cli provider tests. Code has been formatted with biome to maintain consistency. This implementation provides a clean, well-tested integration that follows Task Master's existing patterns while offering users a convenient way to use Gemini models with their existing Google authentication. * feat: implement lazy loading for gemini-cli provider - Move ai-sdk-provider-gemini-cli to optionalDependencies - Implement dynamic import with loadGeminiCliModule() function - Make getClient() async to support lazy loading - Update base-provider to handle async getClient() calls - Update tests to handle async getClient() method This allows the application to start without the gemini-cli package installed, only loading it when actually needed. * feat(gemini-cli): replace regex-based JSON extraction with jsonc-parser - Add jsonc-parser dependency for robust JSON parsing - Replace simple regex approach with progressive parsing strategy: 1. Direct parsing after cleanup 2. Smart boundary detection with single-pass analysis 3. Limited fallback for edge cases - Optimize performance with early termination and strategic sampling - Add comprehensive tests for variable declarations, trailing commas, escaped quotes, nested objects, and performance edge cases - Improve reliability for complex JSON structures that Gemini commonly produces - Fix code formatting with biome This addresses JSON parsing failures in generateObject operations while maintaining backward compatibility and significantly improving performance for large responses. * fix: update package-lock.json and fix formatting for CI/CD - Add jsonc-parser to package-lock.json for proper npm ci compatibility - Fix biome formatting issues in gemini-cli provider and tests - Ensure all CI/CD checks pass * feat(gemini-cli): implement comprehensive JSON output reliability system - Add automatic JSON request detection via content analysis patterns - Implement task-specific prompt simplification for improved AI compliance - Add strict JSON enforcement through enhanced system prompts - Implement response interception with intelligent JSON extraction fallback - Add comprehensive test coverage for all new JSON handling methods - Move debug logging to appropriate level for clean user experience This multi-layered approach addresses gemini-cli's conversational response tendencies, ensuring reliable structured JSON output for task expansion operations. Achieves 100% success rate in end-to-end testing while maintaining full backward compatibility with existing functionality. Technical implementation includes: • JSON detection via user message content analysis • Expand-task prompt simplification with cleaner instructions • System prompt enhancement with strict JSON enforcement • Response processing with jsonc-parser-based extraction • Comprehensive unit test coverage for edge cases • Debug-level logging to prevent user interface clutter Resolves: gemini-cli JSON formatting inconsistencies Tested: All 46 test suites pass, formatting verified * chore: add changeset for gemini-cli provider implementation Adds minor version bump for comprehensive gemini-cli provider with: - Lazy loading and optional dependency management - Advanced JSON parsing with jsonc-parser - Multi-layer reliability system for structured output - Complete test coverage and CI/CD compliance * refactor: consolidate optional auth provider logic - Add gemini-cli to existing providersWithoutApiKeys array in config-manager - Export providersWithoutApiKeys for reuse across modules - Remove duplicate OPTIONAL_AUTH_PROVIDERS Set from ai-services-unified - Update ai-services-unified to import and use centralized array - Fix Jest mock to include new providersWithoutApiKeys export This eliminates code duplication and provides a single source of truth for which providers support optional authentication, addressing PR reviewer feedback about existing similar functionality in src/constants.
2025-07-02 13:46:19 -06:00
CUSTOM_PROVIDERS.BEDROCK,
CUSTOM_PROVIDERS.GEMINI_CLI
];
if (providersWithoutApiKeys.includes(providerName?.toLowerCase())) {
return true; // Indicate key status is effectively "OK"
}
// Claude Code doesn't require an API key
if (providerName?.toLowerCase() === 'claude-code') {
return true; // No API key needed
}
const keyMap = {
openai: 'OPENAI_API_KEY',
anthropic: 'ANTHROPIC_API_KEY',
google: 'GOOGLE_API_KEY',
perplexity: 'PERPLEXITY_API_KEY',
mistral: 'MISTRAL_API_KEY',
azure: 'AZURE_OPENAI_API_KEY',
openrouter: 'OPENROUTER_API_KEY',
xai: 'XAI_API_KEY',
vertex: 'GOOGLE_API_KEY', // Vertex uses the same key as Google
'claude-code': 'CLAUDE_CODE_API_KEY', // Not actually used, but included for consistency
bedrock: 'AWS_ACCESS_KEY_ID' // Bedrock uses AWS credentials
// Add other providers as needed
};
const providerKey = providerName?.toLowerCase();
if (!providerKey || !keyMap[providerKey]) {
log('warn', `Unknown provider name: ${providerName} in isApiKeySet check.`);
return false;
}
const envVarName = keyMap[providerKey];
const apiKeyValue = resolveEnvVariable(envVarName, session, projectRoot);
// Check if the key exists, is not empty, and is not a placeholder
return (
apiKeyValue &&
apiKeyValue.trim() !== '' &&
!/YOUR_.*_API_KEY_HERE/.test(apiKeyValue) && // General placeholder check
!apiKeyValue.includes('KEY_HERE')
); // Another common placeholder pattern
}
/**
* Checks the API key status within .cursor/mcp.json for a given provider.
* Reads the mcp.json file, finds the taskmaster-ai server config, and checks the relevant env var.
* @param {string} providerName The name of the provider.
* @param {string|null} projectRoot - Optional explicit path to the project root.
* @returns {boolean} True if the key exists and is not a placeholder, false otherwise.
*/
function getMcpApiKeyStatus(providerName, projectRoot = null) {
const rootDir = projectRoot || findProjectRoot(); // Use existing root finding
if (!rootDir) {
console.warn(
chalk.yellow('Warning: Could not find project root to check mcp.json.')
);
return false; // Cannot check without root
}
const mcpConfigPath = path.join(rootDir, '.cursor', 'mcp.json');
if (!fs.existsSync(mcpConfigPath)) {
// console.warn(chalk.yellow('Warning: .cursor/mcp.json not found.'));
return false; // File doesn't exist
}
try {
const mcpConfigRaw = fs.readFileSync(mcpConfigPath, 'utf-8');
const mcpConfig = JSON.parse(mcpConfigRaw);
const mcpEnv =
mcpConfig?.mcpServers?.['task-master-ai']?.env ||
mcpConfig?.mcpServers?.['taskmaster-ai']?.env;
if (!mcpEnv) {
return false;
}
let apiKeyToCheck = null;
let placeholderValue = null;
switch (providerName) {
case 'anthropic':
apiKeyToCheck = mcpEnv.ANTHROPIC_API_KEY;
placeholderValue = 'YOUR_ANTHROPIC_API_KEY_HERE';
break;
case 'openai':
apiKeyToCheck = mcpEnv.OPENAI_API_KEY;
placeholderValue = 'YOUR_OPENAI_API_KEY_HERE'; // Assuming placeholder matches OPENAI
break;
docs: Update documentation for new AI/config architecture and finalize cleanup This commit updates all relevant documentation (READMEs, docs/*, .cursor/rules) to accurately reflect the finalized unified AI service architecture and the new configuration system (.taskmasterconfig + .env/mcp.json). It also includes the final code cleanup steps related to the refactoring. Key Changes: 1. **Documentation Updates:** * Revised `README.md`, `README-task-master.md`, `assets/scripts_README.md`, `docs/configuration.md`, and `docs/tutorial.md` to explain the new configuration split (.taskmasterconfig vs .env/mcp.json). * Updated MCP configuration examples in READMEs and tutorials to only include API keys in the `env` block. * Added/updated examples for using the `--research` flag in `docs/command-reference.md`, `docs/examples.md`, and `docs/tutorial.md`. * Updated `.cursor/rules/ai_services.mdc`, `.cursor/rules/architecture.mdc`, `.cursor/rules/dev_workflow.mdc`, `.cursor/rules/mcp.mdc`, `.cursor/rules/taskmaster.mdc`, `.cursor/rules/utilities.mdc`, and `.cursor/rules/new_features.mdc` to align with the new architecture, removing references to old patterns/files. * Removed internal rule links from user-facing rules (`taskmaster.mdc`, `dev_workflow.mdc`, `self_improve.mdc`). * Deleted outdated example file `docs/ai-client-utils-example.md`. 2. **Final Code Refactor & Cleanup:** * Corrected `update-task-by-id.js` by removing the last import from the old `ai-services.js`. * Refactored `update-subtask-by-id.js` to correctly use the unified service and logger patterns. * Removed the obsolete export block from `mcp-server/src/core/task-master-core.js`. * Corrected logger implementation in `update-tasks.js` for CLI context. * Updated API key mapping in `config-manager.js` and `ai-services-unified.js`. 3. **Configuration Files:** * Updated API keys in `.cursor/mcp.json`, replacing `GROK_API_KEY` with `XAI_API_KEY`. * Updated `.env.example` with current API key names. * Added `azureOpenaiBaseUrl` to `.taskmasterconfig` example. 4. **Task Management:** * Marked documentation subtask 61.10 as 'done'. * Includes various other task content/status updates from the diff summary. 5. **Changeset:** * Added `.changeset/cuddly-zebras-matter.md` for user-facing `expand`/`expand-all` improvements. This commit concludes the major architectural refactoring (Task 61) and ensures the documentation accurately reflects the current system.
2025-04-25 14:43:12 -04:00
case 'openrouter':
apiKeyToCheck = mcpEnv.OPENROUTER_API_KEY;
placeholderValue = 'YOUR_OPENROUTER_API_KEY_HERE';
break;
case 'google':
apiKeyToCheck = mcpEnv.GOOGLE_API_KEY;
placeholderValue = 'YOUR_GOOGLE_API_KEY_HERE';
break;
case 'perplexity':
apiKeyToCheck = mcpEnv.PERPLEXITY_API_KEY;
placeholderValue = 'YOUR_PERPLEXITY_API_KEY_HERE';
break;
case 'xai':
docs: Update documentation for new AI/config architecture and finalize cleanup This commit updates all relevant documentation (READMEs, docs/*, .cursor/rules) to accurately reflect the finalized unified AI service architecture and the new configuration system (.taskmasterconfig + .env/mcp.json). It also includes the final code cleanup steps related to the refactoring. Key Changes: 1. **Documentation Updates:** * Revised `README.md`, `README-task-master.md`, `assets/scripts_README.md`, `docs/configuration.md`, and `docs/tutorial.md` to explain the new configuration split (.taskmasterconfig vs .env/mcp.json). * Updated MCP configuration examples in READMEs and tutorials to only include API keys in the `env` block. * Added/updated examples for using the `--research` flag in `docs/command-reference.md`, `docs/examples.md`, and `docs/tutorial.md`. * Updated `.cursor/rules/ai_services.mdc`, `.cursor/rules/architecture.mdc`, `.cursor/rules/dev_workflow.mdc`, `.cursor/rules/mcp.mdc`, `.cursor/rules/taskmaster.mdc`, `.cursor/rules/utilities.mdc`, and `.cursor/rules/new_features.mdc` to align with the new architecture, removing references to old patterns/files. * Removed internal rule links from user-facing rules (`taskmaster.mdc`, `dev_workflow.mdc`, `self_improve.mdc`). * Deleted outdated example file `docs/ai-client-utils-example.md`. 2. **Final Code Refactor & Cleanup:** * Corrected `update-task-by-id.js` by removing the last import from the old `ai-services.js`. * Refactored `update-subtask-by-id.js` to correctly use the unified service and logger patterns. * Removed the obsolete export block from `mcp-server/src/core/task-master-core.js`. * Corrected logger implementation in `update-tasks.js` for CLI context. * Updated API key mapping in `config-manager.js` and `ai-services-unified.js`. 3. **Configuration Files:** * Updated API keys in `.cursor/mcp.json`, replacing `GROK_API_KEY` with `XAI_API_KEY`. * Updated `.env.example` with current API key names. * Added `azureOpenaiBaseUrl` to `.taskmasterconfig` example. 4. **Task Management:** * Marked documentation subtask 61.10 as 'done'. * Includes various other task content/status updates from the diff summary. 5. **Changeset:** * Added `.changeset/cuddly-zebras-matter.md` for user-facing `expand`/`expand-all` improvements. This commit concludes the major architectural refactoring (Task 61) and ensures the documentation accurately reflects the current system.
2025-04-25 14:43:12 -04:00
apiKeyToCheck = mcpEnv.XAI_API_KEY;
placeholderValue = 'YOUR_XAI_API_KEY_HERE';
break;
case 'ollama':
return true; // No key needed
case 'claude-code':
return true; // No key needed
docs: Update documentation for new AI/config architecture and finalize cleanup This commit updates all relevant documentation (READMEs, docs/*, .cursor/rules) to accurately reflect the finalized unified AI service architecture and the new configuration system (.taskmasterconfig + .env/mcp.json). It also includes the final code cleanup steps related to the refactoring. Key Changes: 1. **Documentation Updates:** * Revised `README.md`, `README-task-master.md`, `assets/scripts_README.md`, `docs/configuration.md`, and `docs/tutorial.md` to explain the new configuration split (.taskmasterconfig vs .env/mcp.json). * Updated MCP configuration examples in READMEs and tutorials to only include API keys in the `env` block. * Added/updated examples for using the `--research` flag in `docs/command-reference.md`, `docs/examples.md`, and `docs/tutorial.md`. * Updated `.cursor/rules/ai_services.mdc`, `.cursor/rules/architecture.mdc`, `.cursor/rules/dev_workflow.mdc`, `.cursor/rules/mcp.mdc`, `.cursor/rules/taskmaster.mdc`, `.cursor/rules/utilities.mdc`, and `.cursor/rules/new_features.mdc` to align with the new architecture, removing references to old patterns/files. * Removed internal rule links from user-facing rules (`taskmaster.mdc`, `dev_workflow.mdc`, `self_improve.mdc`). * Deleted outdated example file `docs/ai-client-utils-example.md`. 2. **Final Code Refactor & Cleanup:** * Corrected `update-task-by-id.js` by removing the last import from the old `ai-services.js`. * Refactored `update-subtask-by-id.js` to correctly use the unified service and logger patterns. * Removed the obsolete export block from `mcp-server/src/core/task-master-core.js`. * Corrected logger implementation in `update-tasks.js` for CLI context. * Updated API key mapping in `config-manager.js` and `ai-services-unified.js`. 3. **Configuration Files:** * Updated API keys in `.cursor/mcp.json`, replacing `GROK_API_KEY` with `XAI_API_KEY`. * Updated `.env.example` with current API key names. * Added `azureOpenaiBaseUrl` to `.taskmasterconfig` example. 4. **Task Management:** * Marked documentation subtask 61.10 as 'done'. * Includes various other task content/status updates from the diff summary. 5. **Changeset:** * Added `.changeset/cuddly-zebras-matter.md` for user-facing `expand`/`expand-all` improvements. This commit concludes the major architectural refactoring (Task 61) and ensures the documentation accurately reflects the current system.
2025-04-25 14:43:12 -04:00
case 'mistral':
apiKeyToCheck = mcpEnv.MISTRAL_API_KEY;
placeholderValue = 'YOUR_MISTRAL_API_KEY_HERE';
break;
case 'azure':
apiKeyToCheck = mcpEnv.AZURE_OPENAI_API_KEY;
placeholderValue = 'YOUR_AZURE_OPENAI_API_KEY_HERE';
break;
case 'vertex':
apiKeyToCheck = mcpEnv.GOOGLE_API_KEY; // Vertex uses Google API key
placeholderValue = 'YOUR_GOOGLE_API_KEY_HERE';
break;
case 'bedrock':
apiKeyToCheck = mcpEnv.AWS_ACCESS_KEY_ID; // Bedrock uses AWS credentials
placeholderValue = 'YOUR_AWS_ACCESS_KEY_ID_HERE';
break;
default:
return false; // Unknown provider
}
return !!apiKeyToCheck && !/KEY_HERE$/.test(apiKeyToCheck);
} catch (error) {
console.error(
chalk.red(`Error reading or parsing .cursor/mcp.json: ${error.message}`)
);
return false;
}
}
/**
* Gets a list of available models based on the MODEL_MAP.
* @returns {Array<{id: string, name: string, provider: string, swe_score: number|null, cost_per_1m_tokens: {input: number|null, output: number|null}|null, allowed_roles: string[]}>}
*/
function getAvailableModels() {
const available = [];
for (const [provider, models] of Object.entries(MODEL_MAP)) {
if (models.length > 0) {
models.forEach((modelObj) => {
// Basic name generation - can be improved
const modelId = modelObj.id;
const sweScore = modelObj.swe_score;
const cost = modelObj.cost_per_1m_tokens;
const allowedRoles = modelObj.allowed_roles || ['main', 'fallback'];
const nameParts = modelId
.split('-')
.map((p) => p.charAt(0).toUpperCase() + p.slice(1));
// Handle specific known names better if needed
let name = nameParts.join(' ');
if (modelId === 'claude-3.5-sonnet-20240620')
name = 'Claude 3.5 Sonnet';
if (modelId === 'claude-3-7-sonnet-20250219')
name = 'Claude 3.7 Sonnet';
if (modelId === 'gpt-4o') name = 'GPT-4o';
if (modelId === 'gpt-4-turbo') name = 'GPT-4 Turbo';
if (modelId === 'sonar-pro') name = 'Perplexity Sonar Pro';
if (modelId === 'sonar-mini') name = 'Perplexity Sonar Mini';
available.push({
id: modelId,
name: name,
provider: provider,
swe_score: sweScore,
cost_per_1m_tokens: cost,
allowed_roles: allowedRoles,
max_tokens: modelObj.max_tokens
});
});
} else {
// For providers with empty lists (like ollama), maybe add a placeholder or skip
available.push({
id: `[${provider}-any]`,
name: `Any (${provider})`,
provider: provider
});
}
}
return available;
}
/**
* Writes the configuration object to the file.
* @param {Object} config The configuration object to write.
* @param {string|null} explicitRoot - Optional explicit path to the project root.
* @returns {boolean} True if successful, false otherwise.
*/
function writeConfig(config, explicitRoot = null) {
// ---> Determine root path reliably <---
let rootPath = explicitRoot;
if (explicitRoot === null || explicitRoot === undefined) {
// Logic matching _loadAndValidateConfig
const foundRoot = findProjectRoot(); // *** Explicitly call findProjectRoot ***
if (!foundRoot) {
console.error(
chalk.red(
'Error: Could not determine project root. Configuration not saved.'
)
);
return false;
}
rootPath = foundRoot;
}
// ---> End determine root path logic <---
2025-05-31 16:21:03 +02:00
// Use new config location: .taskmaster/config.json
const taskmasterDir = path.join(rootPath, '.taskmaster');
const configPath = path.join(taskmasterDir, 'config.json');
try {
2025-05-31 16:21:03 +02:00
// Ensure .taskmaster directory exists
if (!fs.existsSync(taskmasterDir)) {
fs.mkdirSync(taskmasterDir, { recursive: true });
}
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
loadedConfig = config; // Update the cache after successful write
return true;
} catch (error) {
console.error(
chalk.red(
`Error writing configuration to ${configPath}: ${error.message}`
)
);
return false;
}
}
/**
2025-05-31 16:21:03 +02:00
* Checks if a configuration file exists at the project root (new or legacy location)
* @param {string|null} explicitRoot - Optional explicit path to the project root
* @returns {boolean} True if the file exists, false otherwise
*/
function isConfigFilePresent(explicitRoot = null) {
2025-05-31 16:21:03 +02:00
return findConfigPath(null, { projectRoot: explicitRoot }) !== null;
}
feat(telemetry): Implement AI usage telemetry pattern and apply to add-task This commit introduces a standardized pattern for capturing and propagating AI usage telemetry (cost, tokens, model used) across the Task Master stack and applies it to the 'add-task' functionality. Key changes include: - **Telemetry Pattern Definition:** - Added defining the integration pattern for core logic, direct functions, MCP tools, and CLI commands. - Updated related rules (, , Usage: mcp [OPTIONS] COMMAND [ARGS]... MCP development tools ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ version Show the MCP version. │ │ dev Run a MCP server with the MCP Inspector. │ │ run Run a MCP server. │ │ install Install a MCP server in the Claude desktop app. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯, , ) to reference the new telemetry rule. - **Core Telemetry Implementation ():** - Refactored the unified AI service to generate and return a object alongside the main AI result. - Fixed an MCP server startup crash by removing redundant local loading of and instead using the imported from for cost calculations. - Added to the object. - ** Integration:** - Modified (core) to receive from the AI service, return it, and call the new UI display function for CLI output. - Updated to receive from the core function and include it in the payload of its response. - Ensured (MCP tool) correctly passes the through via . - Updated to correctly pass context (, ) to the core function and rely on it for CLI telemetry display. - **UI Enhancement:** - Added function to to show telemetry details in the CLI. - **Project Management:** - Added subtasks 77.6 through 77.12 to track the rollout of this telemetry pattern to other AI-powered commands (, , , , , , ). This establishes the foundation for tracking AI usage across the application.
2025-05-07 13:41:25 -04:00
/**
* Gets the user ID from the configuration.
* @param {string|null} explicitRoot - Optional explicit path to the project root.
* @returns {string|null} The user ID or null if not found.
*/
function getUserId(explicitRoot = null) {
const config = getConfig(explicitRoot);
if (!config.global) {
config.global = {}; // Ensure global object exists
}
if (!config.global.userId) {
config.global.userId = '1234567890';
// Attempt to write the updated config.
// It's important that writeConfig correctly resolves the path
// using explicitRoot, similar to how getConfig does.
const success = writeConfig(config, explicitRoot);
if (!success) {
// Log an error or handle the failure to write,
// though for now, we'll proceed with the in-memory default.
log(
'warning',
'Failed to write updated configuration with new userId. Please let the developers know.'
);
}
}
return config.global.userId;
feat(telemetry): Implement AI usage telemetry pattern and apply to add-task This commit introduces a standardized pattern for capturing and propagating AI usage telemetry (cost, tokens, model used) across the Task Master stack and applies it to the 'add-task' functionality. Key changes include: - **Telemetry Pattern Definition:** - Added defining the integration pattern for core logic, direct functions, MCP tools, and CLI commands. - Updated related rules (, , Usage: mcp [OPTIONS] COMMAND [ARGS]... MCP development tools ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ version Show the MCP version. │ │ dev Run a MCP server with the MCP Inspector. │ │ run Run a MCP server. │ │ install Install a MCP server in the Claude desktop app. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯, , ) to reference the new telemetry rule. - **Core Telemetry Implementation ():** - Refactored the unified AI service to generate and return a object alongside the main AI result. - Fixed an MCP server startup crash by removing redundant local loading of and instead using the imported from for cost calculations. - Added to the object. - ** Integration:** - Modified (core) to receive from the AI service, return it, and call the new UI display function for CLI output. - Updated to receive from the core function and include it in the payload of its response. - Ensured (MCP tool) correctly passes the through via . - Updated to correctly pass context (, ) to the core function and rely on it for CLI telemetry display. - **UI Enhancement:** - Added function to to show telemetry details in the CLI. - **Project Management:** - Added subtasks 77.6 through 77.12 to track the rollout of this telemetry pattern to other AI-powered commands (, , , , , , ). This establishes the foundation for tracking AI usage across the application.
2025-05-07 13:41:25 -04:00
}
/**
* Gets a list of all known provider names (both validated and custom).
* @returns {string[]} An array of all provider names.
*/
function getAllProviders() {
return ALL_PROVIDERS;
}
function getBaseUrlForRole(role, explicitRoot = null) {
const roleConfig = getModelConfigForRole(role, explicitRoot);
if (roleConfig && typeof roleConfig.baseURL === 'string') {
return roleConfig.baseURL;
}
const provider = roleConfig?.provider;
if (provider) {
const envVarName = `${provider.toUpperCase()}_BASE_URL`;
return resolveEnvVariable(envVarName, null, explicitRoot);
}
return undefined;
}
feat: Add gemini-cli provider integration for Task Master (#897) * feat: Add gemini-cli provider integration for Task Master This commit adds comprehensive support for the Gemini CLI provider, enabling users to leverage Google's Gemini models through OAuth authentication via the gemini CLI tool. This integration provides a seamless experience for users who prefer using their existing Google account authentication rather than managing API keys. ## Implementation Details ### Provider Class (`src/ai-providers/gemini-cli.js`) - Created GeminiCliProvider extending BaseAIProvider - Implements dual authentication support: - Primary: OAuth authentication via `gemini auth login` (authType: 'oauth-personal') - Secondary: API key authentication for compatibility (authType: 'api-key') - Uses the npm package `ai-sdk-provider-gemini-cli` (v0.0.3) for SDK integration - Properly handles authentication validation without console output ### Model Configuration (`scripts/modules/supported-models.json`) - Added two Gemini models with accurate specifications: - gemini-2.5-pro: 72% SWE score, 65,536 max output tokens - gemini-2.5-flash: 71% SWE score, 65,536 max output tokens - Both models support main, fallback, and research roles - Configured with zero cost (free tier) ### System Integration - Registered provider in PROVIDERS map (`scripts/modules/ai-services-unified.js`) - Added to OPTIONAL_AUTH_PROVIDERS set for flexible authentication - Added GEMINI_CLI constant to provider constants (`src/constants/providers.js`) - Exported GeminiCliProvider from index (`src/ai-providers/index.js`) ### Command Line Support (`scripts/modules/commands.js`) - Added --gemini-cli flag to models command for provider hint - Integrated into model selection logic (setModel function) - Updated error messages to include gemini-cli in provider list - Removed unrelated azure/vertex changes to maintain PR focus ### Documentation (`docs/providers/gemini-cli.md`) - Comprehensive provider documentation emphasizing OAuth-first approach - Clear explanation of why users would choose gemini-cli over standard google provider - Detailed installation, authentication, and configuration instructions - Troubleshooting section with common issues and solutions ### Testing (`tests/unit/ai-providers/gemini-cli.test.js`) - Complete test suite with 12 tests covering all functionality - Tests for both OAuth and API key authentication paths - Error handling and edge case coverage - Updated mocks in ai-services-unified.test.js for integration testing ## Key Design Decisions 1. **OAuth-First Design**: The provider assumes users want to leverage their existing `gemini auth login` credentials, making this the default authentication method. 2. **Authentication Type Mapping**: Discovered through testing that the SDK expects: - 'oauth-personal' for OAuth/CLI authentication (not 'gemini-cli' or 'oauth') - 'api-key' for API key authentication (not 'gemini-api-key') 3. **Silent Operation**: Removed console.log statements from validateAuth to match the pattern used by other providers like claude-code. 4. **Limited Model Support**: Only gemini-2.5-pro and gemini-2.5-flash are available through the CLI, as confirmed by the package author. ## Usage ```bash # Install gemini CLI globally npm install -g @google/gemini-cli # Authenticate with Google account gemini auth login # Configure Task Master to use gemini-cli task-master models --set-main gemini-2.5-pro --gemini-cli # Use Task Master normally task-master new "Create a REST API endpoint" ``` ## Dependencies - Added `ai-sdk-provider-gemini-cli@^0.0.3` to package.json - This package wraps the Google Gemini CLI Core functionality for Vercel AI SDK ## Testing All tests pass (613 total), including the new gemini-cli provider tests. Code has been formatted with biome to maintain consistency. This implementation provides a clean, well-tested integration that follows Task Master's existing patterns while offering users a convenient way to use Gemini models with their existing Google authentication. * feat: implement lazy loading for gemini-cli provider - Move ai-sdk-provider-gemini-cli to optionalDependencies - Implement dynamic import with loadGeminiCliModule() function - Make getClient() async to support lazy loading - Update base-provider to handle async getClient() calls - Update tests to handle async getClient() method This allows the application to start without the gemini-cli package installed, only loading it when actually needed. * feat(gemini-cli): replace regex-based JSON extraction with jsonc-parser - Add jsonc-parser dependency for robust JSON parsing - Replace simple regex approach with progressive parsing strategy: 1. Direct parsing after cleanup 2. Smart boundary detection with single-pass analysis 3. Limited fallback for edge cases - Optimize performance with early termination and strategic sampling - Add comprehensive tests for variable declarations, trailing commas, escaped quotes, nested objects, and performance edge cases - Improve reliability for complex JSON structures that Gemini commonly produces - Fix code formatting with biome This addresses JSON parsing failures in generateObject operations while maintaining backward compatibility and significantly improving performance for large responses. * fix: update package-lock.json and fix formatting for CI/CD - Add jsonc-parser to package-lock.json for proper npm ci compatibility - Fix biome formatting issues in gemini-cli provider and tests - Ensure all CI/CD checks pass * feat(gemini-cli): implement comprehensive JSON output reliability system - Add automatic JSON request detection via content analysis patterns - Implement task-specific prompt simplification for improved AI compliance - Add strict JSON enforcement through enhanced system prompts - Implement response interception with intelligent JSON extraction fallback - Add comprehensive test coverage for all new JSON handling methods - Move debug logging to appropriate level for clean user experience This multi-layered approach addresses gemini-cli's conversational response tendencies, ensuring reliable structured JSON output for task expansion operations. Achieves 100% success rate in end-to-end testing while maintaining full backward compatibility with existing functionality. Technical implementation includes: • JSON detection via user message content analysis • Expand-task prompt simplification with cleaner instructions • System prompt enhancement with strict JSON enforcement • Response processing with jsonc-parser-based extraction • Comprehensive unit test coverage for edge cases • Debug-level logging to prevent user interface clutter Resolves: gemini-cli JSON formatting inconsistencies Tested: All 46 test suites pass, formatting verified * chore: add changeset for gemini-cli provider implementation Adds minor version bump for comprehensive gemini-cli provider with: - Lazy loading and optional dependency management - Advanced JSON parsing with jsonc-parser - Multi-layer reliability system for structured output - Complete test coverage and CI/CD compliance * refactor: consolidate optional auth provider logic - Add gemini-cli to existing providersWithoutApiKeys array in config-manager - Export providersWithoutApiKeys for reuse across modules - Remove duplicate OPTIONAL_AUTH_PROVIDERS Set from ai-services-unified - Update ai-services-unified to import and use centralized array - Fix Jest mock to include new providersWithoutApiKeys export This eliminates code duplication and provides a single source of truth for which providers support optional authentication, addressing PR reviewer feedback about existing similar functionality in src/constants.
2025-07-02 13:46:19 -06:00
// Export the providers without API keys array for use in other modules
export const providersWithoutApiKeys = [
CUSTOM_PROVIDERS.OLLAMA,
CUSTOM_PROVIDERS.BEDROCK,
CUSTOM_PROVIDERS.GEMINI_CLI
];
export {
// Core config access
getConfig,
writeConfig,
ConfigurationError,
isConfigFilePresent,
// Claude Code settings
getClaudeCodeSettings,
getClaudeCodeSettingsForCommand,
// Validation
validateProvider,
validateProviderModelCombination,
validateClaudeCodeSettings,
VALIDATED_PROVIDERS,
CUSTOM_PROVIDERS,
ALL_PROVIDERS,
MODEL_MAP,
getAvailableModels,
// Role-specific getters (No env var overrides)
getMainProvider,
getMainModelId,
getMainMaxTokens,
getMainTemperature,
getResearchProvider,
getResearchModelId,
getResearchMaxTokens,
getResearchTemperature,
getFallbackProvider,
getFallbackModelId,
getFallbackMaxTokens,
getFallbackTemperature,
getBaseUrlForRole,
// Global setting getters (No env var overrides)
getLogLevel,
getDebugFlag,
getDefaultNumTasks,
getDefaultSubtasks,
getDefaultPriority,
getProjectName,
getOllamaBaseURL,
getAzureBaseURL,
getBedrockBaseURL,
getResponseLanguage,
getParametersForRole,
feat(telemetry): Implement AI usage telemetry pattern and apply to add-task This commit introduces a standardized pattern for capturing and propagating AI usage telemetry (cost, tokens, model used) across the Task Master stack and applies it to the 'add-task' functionality. Key changes include: - **Telemetry Pattern Definition:** - Added defining the integration pattern for core logic, direct functions, MCP tools, and CLI commands. - Updated related rules (, , Usage: mcp [OPTIONS] COMMAND [ARGS]... MCP development tools ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ --help Show this message and exit. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ version Show the MCP version. │ │ dev Run a MCP server with the MCP Inspector. │ │ run Run a MCP server. │ │ install Install a MCP server in the Claude desktop app. │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯, , ) to reference the new telemetry rule. - **Core Telemetry Implementation ():** - Refactored the unified AI service to generate and return a object alongside the main AI result. - Fixed an MCP server startup crash by removing redundant local loading of and instead using the imported from for cost calculations. - Added to the object. - ** Integration:** - Modified (core) to receive from the AI service, return it, and call the new UI display function for CLI output. - Updated to receive from the core function and include it in the payload of its response. - Ensured (MCP tool) correctly passes the through via . - Updated to correctly pass context (, ) to the core function and rely on it for CLI telemetry display. - **UI Enhancement:** - Added function to to show telemetry details in the CLI. - **Project Management:** - Added subtasks 77.6 through 77.12 to track the rollout of this telemetry pattern to other AI-powered commands (, , , , , , ). This establishes the foundation for tracking AI usage across the application.
2025-05-07 13:41:25 -04:00
getUserId,
// API Key Checkers (still relevant)
isApiKeySet,
getMcpApiKeyStatus,
// ADD: Function to get all provider names
getAllProviders,
getVertexProjectId,
getVertexLocation
};