refactor: Standardize configuration and environment variable access
This commit centralizes configuration and environment variable access across various modules by consistently utilizing getters from scripts/modules/config-manager.js. This replaces direct access to process.env and the global CONFIG object, leading to improved consistency, maintainability, testability, and better handling of session-specific configurations within the MCP context.
Key changes include:
- Centralized Getters: Replaced numerous instances of process.env.* and CONFIG.* with corresponding getter functions (e.g., getLogLevel, getMainModelId, getResearchMaxTokens, getMainTemperature, isApiKeySet, getDebugFlag, getDefaultSubtasks).
- Session Awareness: Ensured that the session object is passed to config getters where necessary, particularly within AI service calls (ai-services.js, add-task.js) and error handling (ai-services.js), allowing for session-specific environment overrides.
- API Key Checks: Standardized API key availability checks using isApiKeySet() instead of directly checking process.env.* (e.g., for Perplexity in commands.js and ai-services.js).
- Client Instantiation Cleanup: Removed now-redundant/obsolete local client instantiation functions (getAnthropicClient, getPerplexityClient) from ai-services.js and the global Anthropic client initialization from dependency-manager.js. Client creation should now rely on the config manager and factory patterns.
- Consistent Debug Flag Usage: Standardized calls to getDebugFlag() in commands.js, removing potentially unnecessary null arguments.
- Accurate Progress Calculation: Updated AI stream progress reporting (ai-services.js, add-task.js) to use getMainMaxTokens(session) for more accurate calculations.
- Minor Cleanup: Removed unused import from scripts/modules/commands.js.
Specific module updates:
- :
- Uses getLogLevel() instead of process.env.LOG_LEVEL.
- :
- Replaced direct env/config access for model IDs, tokens, temperature, API keys, and default subtasks with appropriate getters.
- Passed session to handleClaudeError.
- Removed local getPerplexityClient and getAnthropicClient functions.
- Updated progress calculations to use getMainMaxTokens(session).
- :
- Uses isApiKeySet('perplexity') for API key checks.
- Uses getDebugFlag() consistently for debug checks.
- Removed unused import.
- :
- Removed global Anthropic client initialization.
- :
- Uses config getters (getResearch..., getMain...) for Perplexity and Claude API call parameters, preserving customEnv override logic.
This refactoring also resolves a potential SyntaxError: Identifier 'getPerplexityClient' has already been declared by removing the duplicated/obsolete function definition previously present in ai-services.js.
This commit is contained in:
@@ -19,7 +19,16 @@ import {
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { findNextTask, analyzeTaskComplexity } from './task-manager.js';
|
||||
import { getProjectName, getDefaultSubtasks } from './config-manager.js';
|
||||
import {
|
||||
getProjectName,
|
||||
getDefaultSubtasks,
|
||||
getMainModelId,
|
||||
getMainMaxTokens,
|
||||
getMainTemperature,
|
||||
getDebugFlag,
|
||||
getLogLevel,
|
||||
getDefaultPriority
|
||||
} from './config-manager.js';
|
||||
|
||||
// Create a color gradient for the banner
|
||||
const coolGradient = gradient(['#00b4d8', '#0077b6', '#03045e']);
|
||||
@@ -591,17 +600,17 @@ function displayHelp() {
|
||||
[
|
||||
`${chalk.yellow('MODEL')}${chalk.reset('')}`,
|
||||
`${chalk.white('Claude model to use')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.model}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getMainModelId()}`)}${chalk.reset('')}`
|
||||
],
|
||||
[
|
||||
`${chalk.yellow('MAX_TOKENS')}${chalk.reset('')}`,
|
||||
`${chalk.white('Maximum tokens for responses')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.maxTokens}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getMainMaxTokens()}`)}${chalk.reset('')}`
|
||||
],
|
||||
[
|
||||
`${chalk.yellow('TEMPERATURE')}${chalk.reset('')}`,
|
||||
`${chalk.white('Temperature for model responses')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.temperature}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getMainTemperature()}`)}${chalk.reset('')}`
|
||||
],
|
||||
[
|
||||
`${chalk.yellow('PERPLEXITY_API_KEY')}${chalk.reset('')}`,
|
||||
@@ -616,27 +625,27 @@ function displayHelp() {
|
||||
[
|
||||
`${chalk.yellow('DEBUG')}${chalk.reset('')}`,
|
||||
`${chalk.white('Enable debug logging')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.debug}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getDebugFlag()}`)}${chalk.reset('')}`
|
||||
],
|
||||
[
|
||||
`${chalk.yellow('LOG_LEVEL')}${chalk.reset('')}`,
|
||||
`${chalk.white('Console output level (debug,info,warn,error)')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.logLevel}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getLogLevel()}`)}${chalk.reset('')}`
|
||||
],
|
||||
[
|
||||
`${chalk.yellow('DEFAULT_SUBTASKS')}${chalk.reset('')}`,
|
||||
`${chalk.white('Default number of subtasks to generate')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.defaultSubtasks}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getDefaultSubtasks()}`)}${chalk.reset('')}`
|
||||
],
|
||||
[
|
||||
`${chalk.yellow('DEFAULT_PRIORITY')}${chalk.reset('')}`,
|
||||
`${chalk.white('Default task priority')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.defaultPriority}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getDefaultPriority()}`)}${chalk.reset('')}`
|
||||
],
|
||||
[
|
||||
`${chalk.yellow('PROJECT_NAME')}${chalk.reset('')}`,
|
||||
`${chalk.white('Project name displayed in UI')}${chalk.reset('')}`,
|
||||
`${chalk.dim(`Default: ${CONFIG.projectName}`)}${chalk.reset('')}`
|
||||
`${chalk.dim(`Default: ${getProjectName()}`)}${chalk.reset('')}`
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user