feat(config): Restructure .taskmasterconfig and enhance gateway integration

Config Structure Changes and Gateway Integration

## Configuration Structure Changes
- Restructured .taskmasterconfig to use 'account' section for user settings
- Moved userId, userEmail, mode, telemetryEnabled from global to account section
- API keys remain isolated in .env file (not accessible to AI)
- Enhanced getUserId() to always return value, never null (sets default '1234567890')

## Gateway Integration Enhancements
- Updated registerUserWithGateway() to accept both email and userId parameters
- Enhanced /auth/init endpoint integration for existing user validation
- API key updates automatically written to .env during registration process
- Improved user identification and validation flow

## Code Updates for New Structure
- Fixed config-manager.js getter functions for account section access
- Updated user-management.js to use config.account.userId/mode
- Modified telemetry-submission.js to read from account section
- Added getTelemetryEnabled() function with proper account section access
- Enhanced telemetry configuration reading with new structure

## Comprehensive Test Updates
- Updated integration tests (init-config.test.js) for new config structure
- Fixed unit tests (config-manager.test.js) with updated default config
- Updated telemetry tests (telemetry-submission.test.js) for account structure
- Added missing getTelemetryEnabled mock to ai-services-unified.test.js
- Fixed all test expectations to use config.account.* instead of config.global.*
- Removed references to deprecated config.subscription object

## Configuration Access Consistency
- Standardized configuration access patterns across entire codebase
- Clean separation: user settings in account, API keys in .env, models/global in respective sections
- All tests passing with new configuration structure
- Maintained backward compatibility during transition

Changes support enhanced telemetry system with proper user management and gateway integration while maintaining security through API key isolation.
This commit is contained in:
Eyal Toledano
2025-05-30 18:53:16 -04:00
parent e573db3b3b
commit 4e9d58a1b0
18 changed files with 1900 additions and 1609 deletions

View File

@@ -77,14 +77,14 @@ function updateUserConfig(userId, token, mode, explicitRoot = null) {
try {
const config = getConfig(explicitRoot);
// Ensure global section exists
if (!config.global) {
config.global = {};
// Ensure account section exists
if (!config.account) {
config.account = {};
}
// Update user configuration
config.global.userId = userId;
config.global.mode = mode; // 'byok' or 'hosted'
// Update user configuration in account section
config.account.userId = userId;
config.account.mode = mode; // 'byok' or 'hosted'
// Write API token to .env file (not config)
if (token) {
@@ -169,7 +169,7 @@ function writeApiKeyToEnv(token, explicitRoot = null) {
function getUserMode(explicitRoot = null) {
try {
const config = getConfig(explicitRoot);
return config?.global?.mode || "unknown";
return config?.account?.mode || "unknown";
} catch (error) {
log("error", `Error getting user mode: ${error.message}`);
return "unknown";