-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-config.ts
More file actions
291 lines (261 loc) · 7.83 KB
/
Copy pathsimple-config.ts
File metadata and controls
291 lines (261 loc) · 7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/**
* Simple Configuration Manager
* Inspired by Claude Flow's configuration system but lightweight
* Manages basic settings and user preferences
*/
import fs from 'fs-extra';
import path from 'path';
import os from 'os';
export interface AgentConfig {
name: string;
enabled: boolean;
confidence: number;
specialization: string;
}
export interface ConductorConfig {
version: string;
initialized: boolean;
user: {
name?: string;
email?: string;
experience: 'beginner' | 'intermediate' | 'expert';
preferredFramework?: string;
};
agents: AgentConfig[];
settings: {
autoLaunch: boolean;
verboseOutput: boolean;
enableHooks: boolean;
theme: 'default' | 'minimal' | 'detailed';
responseStyle: 'concise' | 'detailed' | 'conversational';
};
project: {
type?: 'react' | 'nextjs' | 'vue' | 'nodejs' | 'python' | 'other';
name?: string;
description?: string;
lastModified: string;
};
history: {
totalQuestions: number;
lastUsed: string;
favoriteAgents: string[];
};
}
export class SimpleConfigManager {
private configPath: string;
private config: ConductorConfig;
constructor() {
this.configPath = path.join(os.homedir(), '.conductor', 'config.json');
this.config = this.getDefaultConfig();
}
/**
* Get default configuration
*/
private getDefaultConfig(): ConductorConfig {
return {
version: '1.0.0',
initialized: false,
user: {
experience: 'beginner',
},
agents: [
{ name: 'pm', enabled: true, confidence: 85, specialization: 'Product Management' },
{ name: 'design', enabled: true, confidence: 80, specialization: 'UX/UI Design' },
{ name: 'frontend', enabled: true, confidence: 90, specialization: 'Frontend Development' },
{ name: 'backend', enabled: true, confidence: 85, specialization: 'Backend Development' },
{ name: 'qa', enabled: true, confidence: 75, specialization: 'Quality Assurance' },
{ name: 'devops', enabled: true, confidence: 70, specialization: 'DevOps & Deployment' },
{ name: 'reviewer', enabled: true, confidence: 85, specialization: 'Code Review' },
{ name: 'security', enabled: true, confidence: 80, specialization: 'Security' },
],
settings: {
autoLaunch: false,
verboseOutput: false,
enableHooks: false,
theme: 'default',
responseStyle: 'concise',
},
project: {
lastModified: new Date().toISOString(),
},
history: {
totalQuestions: 0,
lastUsed: new Date().toISOString(),
favoriteAgents: [],
},
};
}
/**
* Initialize configuration
*/
async initialize(): Promise<void> {
try {
// Ensure .conductor directory exists
const configDir = path.dirname(this.configPath);
await fs.ensureDir(configDir);
// Load existing config or create default
await this.load();
this.config.initialized = true;
this.config.history.lastUsed = new Date().toISOString();
await this.save();
console.log('🎯 Conductor configuration initialized!');
} catch (error) {
console.warn('⚠️ Could not initialize configuration:', error);
}
}
/**
* Load configuration from file
*/
async load(): Promise<void> {
try {
if (await fs.pathExists(this.configPath)) {
const fileContent = await fs.readFile(this.configPath, 'utf8');
const loadedConfig = JSON.parse(fileContent);
// Merge with defaults to ensure all properties exist
this.config = { ...this.getDefaultConfig(), ...loadedConfig };
console.log('📖 Configuration loaded successfully');
} else {
console.log('📝 Using default configuration');
}
} catch (error) {
console.warn('⚠️ Could not load configuration, using defaults');
this.config = this.getDefaultConfig();
}
}
/**
* Save configuration to file
*/
async save(): Promise<void> {
try {
const configDir = path.dirname(this.configPath);
await fs.ensureDir(configDir);
await fs.writeFile(this.configPath, JSON.stringify(this.config, null, 2));
console.log('💾 Configuration saved successfully');
} catch (error) {
console.warn('⚠️ Could not save configuration:', error);
}
}
/**
* Get current configuration
*/
getConfig(): ConductorConfig {
return { ...this.config };
}
/**
* Update user preferences
*/
async updateUser(updates: Partial<ConductorConfig['user']>): Promise<void> {
this.config.user = { ...this.config.user, ...updates };
await this.save();
}
/**
* Update project information
*/
async updateProject(updates: Partial<ConductorConfig['project']>): Promise<void> {
this.config.project = {
...this.config.project,
...updates,
lastModified: new Date().toISOString()
};
await this.save();
}
/**
* Update settings
*/
async updateSettings(updates: Partial<ConductorConfig['settings']>): Promise<void> {
this.config.settings = { ...this.config.settings, ...updates };
await this.save();
}
/**
* Enable/disable agent
*/
async toggleAgent(agentName: string, enabled: boolean): Promise<boolean> {
const agent = this.config.agents.find(a => a.name === agentName);
if (!agent) return false;
agent.enabled = enabled;
await this.save();
return true;
}
/**
* Get enabled agents
*/
getEnabledAgents(): AgentConfig[] {
return this.config.agents.filter(agent => agent.enabled);
}
/**
* Update agent confidence
*/
async updateAgentConfidence(agentName: string, confidence: number): Promise<boolean> {
const agent = this.config.agents.find(a => a.name === agentName);
if (!agent) return false;
agent.confidence = Math.max(0, Math.min(100, confidence));
await this.save();
return true;
}
/**
* Record a question in history
*/
async recordQuestion(agentUsed?: string): Promise<void> {
this.config.history.totalQuestions++;
this.config.history.lastUsed = new Date().toISOString();
if (agentUsed && !this.config.history.favoriteAgents.includes(agentUsed)) {
this.config.history.favoriteAgents.push(agentUsed);
// Keep only top 5 favorites
if (this.config.history.favoriteAgents.length > 5) {
this.config.history.favoriteAgents = this.config.history.favoriteAgents.slice(-5);
}
}
await this.save();
}
/**
* Get configuration summary for display
*/
getSummary(): {
initialized: boolean;
agents: number;
enabledAgents: number;
totalQuestions: number;
experience: string;
projectType?: string;
} {
return {
initialized: this.config.initialized,
agents: this.config.agents.length,
enabledAgents: this.getEnabledAgents().length,
totalQuestions: this.config.history.totalQuestions,
experience: this.config.user.experience,
projectType: this.config.project.type,
};
}
/**
* Reset configuration to defaults
*/
async reset(): Promise<void> {
this.config = this.getDefaultConfig();
await this.save();
console.log('🔄 Configuration reset to defaults');
}
/**
* Export configuration for backup
*/
exportConfig(): string {
return JSON.stringify(this.config, null, 2);
}
/**
* Import configuration from backup
*/
async importConfig(configJson: string): Promise<boolean> {
try {
const importedConfig = JSON.parse(configJson);
this.config = { ...this.getDefaultConfig(), ...importedConfig };
await this.save();
console.log('📥 Configuration imported successfully');
return true;
} catch (error) {
console.warn('⚠️ Could not import configuration:', error);
return false;
}
}
}
// Export singleton instance
export const config = new SimpleConfigManager();