feat: add optional feature flag for code context (#1165)

* feat: add featureFlag for codebase analysis

* chore: add changeset

* chore: run format
This commit is contained in:
Ralph Khreish
2025-08-29 00:28:00 +02:00
committed by GitHub
parent be0c0f267c
commit c4f92f6a0a
14 changed files with 98 additions and 38 deletions

View File

@@ -72,7 +72,8 @@ const DEFAULTS = {
projectName: 'Task Master',
ollamaBaseURL: 'http://localhost:11434/api',
bedrockBaseURL: 'https://bedrock.us-east-1.amazonaws.com',
responseLanguage: 'English'
responseLanguage: 'English',
enableCodebaseAnalysis: true
},
claudeCode: {}
};
@@ -428,15 +429,56 @@ function getResearchProvider(explicitRoot = null) {
}
/**
* Check if a codebase analysis provider is being used (Claude Code or Gemini CLI)
* Check if codebase analysis feature flag is enabled across all sources
* Priority: .env > MCP env > config.json
* @param {object|null} session - MCP session object (optional)
* @param {string|null} projectRoot - Project root path (optional)
* @returns {boolean} True if codebase analysis is enabled
*/
function isCodebaseAnalysisEnabled(session = null, projectRoot = null) {
// Priority 1: Environment variable
const envFlag = resolveEnvVariable(
'TASKMASTER_ENABLE_CODEBASE_ANALYSIS',
session,
projectRoot
);
if (envFlag !== null && envFlag !== undefined && envFlag !== '') {
return envFlag.toLowerCase() === 'true' || envFlag === '1';
}
// Priority 2: MCP session environment
if (session?.env?.TASKMASTER_ENABLE_CODEBASE_ANALYSIS) {
const mcpFlag = session.env.TASKMASTER_ENABLE_CODEBASE_ANALYSIS;
return mcpFlag.toLowerCase() === 'true' || mcpFlag === '1';
}
// Priority 3: Configuration file
const globalConfig = getGlobalConfig(projectRoot);
return globalConfig.enableCodebaseAnalysis !== false; // Default to true
}
/**
* Check if codebase analysis is available and enabled
* @param {boolean} useResearch - Whether to check research provider or main provider
* @param {string|null} projectRoot - Project root path (optional)
* @returns {boolean} True if a codebase analysis provider is the current provider
* @param {object|null} session - MCP session object (optional)
* @returns {boolean} True if codebase analysis is available and enabled
*/
function hasCodebaseAnalysis(useResearch = false, projectRoot = null) {
function hasCodebaseAnalysis(
useResearch = false,
projectRoot = null,
session = null
) {
// First check if the feature is enabled
if (!isCodebaseAnalysisEnabled(session, projectRoot)) {
return false;
}
// Then check if a codebase analysis provider is configured
const currentProvider = useResearch
? getResearchProvider(projectRoot)
: getMainProvider(projectRoot);
return (
currentProvider === CUSTOM_PROVIDERS.CLAUDE_CODE ||
currentProvider === CUSTOM_PROVIDERS.GEMINI_CLI
@@ -558,6 +600,11 @@ function getResponseLanguage(explicitRoot = null) {
return getGlobalConfig(explicitRoot).responseLanguage;
}
function getCodebaseAnalysisEnabled(explicitRoot = null) {
// Directly return value from config
return getGlobalConfig(explicitRoot).enableCodebaseAnalysis;
}
/**
* Gets model parameters (maxTokens, temperature) for a specific role,
* considering model-specific overrides from supported-models.json.
@@ -1016,6 +1063,8 @@ export {
getAzureBaseURL,
getBedrockBaseURL,
getResponseLanguage,
getCodebaseAnalysisEnabled,
isCodebaseAnalysisEnabled,
getParametersForRole,
getUserId,
// API Key Checkers (still relevant)